-
Notifications
You must be signed in to change notification settings - Fork 1.3k
esp32s2: Add I2SAudioOut #3733
New issue
Have a question about this project? Sign up for a free GitHub account to open 8000 an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp32s2: Add I2SAudioOut #3733
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions. Thanks for adding this!
@microdev1 @UnexpectedMaker if either of you have a chance to test this for functionality that would be great! |
@jepler I would love to test this but I don't have the proper audio hardware at the moment. |
@jepler I could test this but I see there are a few unresolved code suggestions to do first. |
(note that the before and after files both lack trailing newlines; this is how the esp-idf do) OPTIMIZATION_DEFAULT is -Og, which enables optimizations that do not interfere with the debugger: ``` elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT) list(APPEND compile_options "-Og") ```
this is an exception class for "generic" IDF errors that don't have their own exception type.
By surrounding most ESP-IDF API calls with this new macro, their failure will result in a CircuitPython exception.
9146e4f
to
a754259
Compare
This can be useful so that e.g., on a Kaluga when programming via the FTDI chip, you can override the variable to specify "--after=hard_reset" to automatically return to running CircuitPython, choose a different baud rate (921600 is about 2s faster than 460800), etc: make BOARD=espressif_kaluga_1 ESPTOOL_FLAGS="-b 921600 --before=default_reset --after=hard_reset"
Test program: mixing mono RawSamples to stereo:
|
.. and other housekeeping when starting to play a sample
.. it's not clear that there was a problem with i2s_zero_dma_buffer, but just in case.
At this point, RawSamples seem to function properly. However, WaveFiles don't work right -- each one plays a different characteristic tone, which may be the first 256 or 512 bytes of the sample. I haven't gotten good debug information via serial prints yet, but it almost looks as though the background task stops getting called. This could be related to how |
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.
.. otherwise, the background callback to load the I2S fifos does not get run. (I'm not sure this is _correct_ behavior of sleep + background tasks, but it is the current behavior)
Suggested by @tannewt, thanks!
Originally, I believed the implementation might be shared with AudioOut, as on the ESP32 (non-S2) the I2S peripheral was also used to drive the DAC. However, this is not the case on ESP32-S2 and appears it will not be the case with the ESP32-S3 or -C3, to the extent that there's skeletal support for either of them in esp-idf master branch. However, it could still be shared by I2SIn or PDMIn (the latter being hypothetically implemented as I2SIn + digital postprocessing like we did in the atmel-sam port, to my understanding), so I moved it to the common-hal folder.
Some ports need an extra operation to ensure that the main task is awoken so that a queued background task will execute during an ongoing light sleep. This removes the need to enable supervisor ticks while I2SOut is operating. Closes: adafruit#3952
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thank you!
FYI: This needs a translation update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thank you!
Fixes #3882.
Testing I performed:
My test program for wave files, plus some example files:
esp32s2-i2sout-test.zip