Skip to content

Commit 0b145fd

Browse files
miketeachmandpgeorge
authored andcommitted
esp32/machine_i2s: Integrate new I2S IDF driver.
The legacy I2S "shim" is removed and replaced by the new I2S driver. The new driver fixes a bug where mono audio plays only in one channel. Application code size is reduced by 2672 bytes with this change. Tested on ESP32, ESP32+spiram, ESP32-S3 using example code from https://github.com/miketeachman/micropython-i2s-examples Signed-off-by: Mike Teachman <[email protected]>
1 parent 4dc262c commit 0b145fd

File tree

4 files changed

+150
-162
lines changed

4 files changed

+150
-162
lines changed

extmod/machine_i2s.c

+5-20
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ static mp_uint_t machine_i2s_stream_write(mp_obj_t self_in, const void *buf_in,
608608
#else
609609
uint32_t num_bytes_written = copy_appbuf_to_dma(self, &appbuf);
610610
#endif
611+
611612
return num_bytes_written;
612613
}
613614
}
@@ -632,16 +633,8 @@ static mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
632633
ret |= MP_STREAM_POLL_RD;
633634
}
634635
#else
635-
// check event queue to determine if a DMA buffer has been filled
636-
// (which is an indication that at least one DMA buffer is available to be read)
637-
// note: timeout = 0 so the call is non-blocking
638-
i2s_event_t i2s_event;
639-
if (xQueueReceive(self->i2s_event_queue, &i2s_event, 0)) {
640-
if (i2s_event.type == I2S_EVENT_RX_DONE) {
641-
// getting here means that at least one DMA buffer is now full
642-
// indicating that audio samples can be read from the I2S object
643-
ret |= MP_STREAM_POLL_RD;
644-
}
636+
if (self->dma_buffer_status == DMA_MEMORY_NOT_EMPTY) {
637+
ret |= MP_STREAM_POLL_RD;
645638
}
646639
#endif
647640
}
@@ -657,16 +650,8 @@ static mp_uint_t machine_i2s_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_
657650
ret |= MP_STREAM_POLL_WR;
658651
}
659652
#else
660-
// check event queue to determine if a DMA buffer has been emptied
661-
// (which is an indication that at least one DMA buffer is available to be written)
662-
// note: timeout = 0 so the call is non-blocking
663-
i2s_event_t i2s_event;
664-
if (xQueueReceive(self->i2s_event_queue, &i2s_event, 0)) {
665-
if (i2s_event.type == I2S_EVENT_TX_DONE) {
666-
// getting here means that at least one DMA buffer is now empty
667-
// indicating that audio samples can be written to the I2S object
668-
ret |= MP_STREAM_POLL_WR;
669-
}
653+
if (self->dma_buffer_status == DMA_MEMORY_NOT_FULL) {
654+
ret |= MP_STREAM_POLL_WR;
670655
}
671656
#endif
672657
}

ports/esp32/boards/sdkconfig.base

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ CONFIG_UART_ISR_IN_IRAM=y
112112
# IDF 5 deprecated
113113
CONFIG_ADC_SUPPRESS_DEPRECATE_WARN=y
114114
CONFIG_RMT_SUPPRESS_DEPRECATE_WARN=y
115-
CONFIG_I2S_SUPPRESS_DEPRECATE_WARN=y
116115

117116
CONFIG_ETH_USE_SPI_ETHERNET=y
118117
CONFIG_ETH_SPI_ETHERNET_W5500=y

0 commit comments

Comments
 (0)