From 430bcdb59d47fc89c7788aeb300027bcf4e00bf2 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 8 Jan 2021 08:49:25 -0600 Subject: [PATCH] port_i2s_play: fill the initial buffer via background callback There were _possibly_ problems where this routine was being entered by direct call AND by background callback. Schedule the work here, and it will be done almost immediately, without worry about interference. I don't know if this is strictly necessary, but it doesn't hurt. Since the I2S clock is being run all the time, we have to enter the background task to fill the FIFO with zeros constantly anyway. --- ports/esp32s2/i2s_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/esp32s2/i2s_common.c b/ports/esp32s2/i2s_common.c index a948ee0f5a..552fe7424c 100644 --- a/ports/esp32s2/i2s_common.c +++ b/ports/esp32s2/i2s_common.c @@ -211,7 +211,8 @@ void port_i2s_play(i2s_t *self, mp_obj_t sample, bool loop) { audiosample_reset_buffer(self->sample, false, 0); ESP_CALL_RAISE(i2s_set_sample_rates(self->instance, audiosample_sample_rate(sample))); - i2s_fill_buffer(self); + + background_callback_add(&self->callback, i2s_callback_fun, self); } bool port_i2s_playing(i2s_t *self) {