@@ -263,13 +263,22 @@ STATIC uint32_t fill_appbuf_from_dma(machine_i2s_obj_t *self, mp_buffer_info_t *
263263 delay = portMAX_DELAY ; // block until supplied buffer is filled
264264 }
265265
266- // read a chunk of audio samples from DMA memory
267- check_esp_err (i2s_read (
266+ esp_err_t ret = i2s_read (
268267 self -> port ,
269268 self -> transform_buffer ,
270269 num_bytes_requested_from_dma ,
271270 & num_bytes_received_from_dma ,
272- delay ));
271+ delay );
272+
273+ // the following is a workaround for a bug in ESP-IDF v4.4
274+ // https://github.com/espressif/esp-idf/issues/8121
275+ #if (ESP_IDF_VERSION_MAJOR == 4 ) && (ESP_IDF_VERSION_MINOR >= 4 )
276+ if ((delay != portMAX_DELAY ) && (ret == ESP_ERR_TIMEOUT )) {
277+ ret = ESP_OK ;
278+ }
279+ #endif
280+
281+ check_esp_err (ret );
273282
274283 // process the transform buffer one frame at a time.
275284 // copy selected bytes from the transform buffer into the user supplied appbuf.
@@ -324,7 +333,17 @@ STATIC size_t copy_appbuf_to_dma(machine_i2s_obj_t *self, mp_buffer_info_t *appb
324333 delay = portMAX_DELAY ; // block until supplied buffer is emptied
325334 }
326335
327- check_esp_err (i2s_write (self -> port , appbuf -> buf , appbuf -> len , & num_bytes_written , delay ));
336+ esp_err_t ret = i2s_write (self -> port , appbuf -> buf , appbuf -> len , & num_bytes_written , delay );
337+
338+ // the following is a workaround for a bug in ESP-IDF v4.4
339+ // https://github.com/espressif/esp-idf/issues/8121
340+ #if (ESP_IDF_VERSION_MAJOR == 4 ) && (ESP_IDF_VERSION_MINOR >= 4 )
341+ if ((delay != portMAX_DELAY ) && (ret == ESP_ERR_TIMEOUT )) {
342+ ret = ESP_OK ;
343+ }
344+ #endif
345+
346+ check_esp_err (ret );
328347
329348 if ((self -> io_mode == UASYNCIO ) && (num_bytes_written < appbuf -> len )) {
330349 // Unable to empty the entire app buffer into DMA memory. This indicates all DMA TX buffers are full.
@@ -447,6 +466,11 @@ STATIC void machine_i2s_init_helper(machine_i2s_obj_t *self, size_t n_pos_args,
447466 i2s_config .dma_buf_len = DMA_BUF_LEN_IN_I2S_FRAMES ;
448467 i2s_config .use_apll = false;
449468 i2s_config .tx_desc_auto_clear = true;
469+ i2s_config .fixed_mclk = 0 ;
470+ #if (ESP_IDF_VERSION_MAJOR == 4 ) && (ESP_IDF_VERSION_MINOR >= 4 )
471+ i2s_config .mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT ;
472+ i2s_config .bits_per_chan = 0 ;
473+ #endif
450474
451475 // I2S queue size equals the number of DMA buffers
452476 check_esp_err (i2s_driver_install (self -> port , & i2s_config , i2s_config .dma_buf_count , & self -> i2s_event_queue ));
@@ -463,14 +487,17 @@ STATIC void machine_i2s_init_helper(machine_i2s_obj_t *self, size_t n_pos_args,
463487 #endif
464488
465489 i2s_pin_config_t pin_config ;
490+ #if (ESP_IDF_VERSION_MAJOR == 4 ) && (ESP_IDF_VERSION_MINOR >= 4 )
491+ pin_config .mck_io_num = I2S_PIN_NO_CHANGE ;
492+ #endif
466493 pin_config .bck_io_num = self -> sck ;
467494 pin_config .ws_io_num = self -> ws ;
468495
469496 if (mode == (I2S_MODE_MASTER | I2S_MODE_RX )) {
470497 pin_config .data_in_num = self -> sd ;
471- pin_config .data_out_num = -1 ;
498+ pin_config .data_out_num = I2S_PIN_NO_CHANGE ;
472499 } else { // TX
473- pin_config .data_in_num = -1 ;
500+ pin_config .data_in_num = I2S_PIN_NO_CHANGE ;
474501 pin_config .data_out_num = self -> sd ;
475502 }
476503
0 commit comments