![]() |
Core2 for AWS IoT EduKit BSP 1.5.1
|
This library provides convenience functions to interact with the on-board speaker to play audio at 44100Hz sample rate at 16-bit depth on a mono (right) channel. The NS4168 amplifier powers the on-board speaker and communicates with the ESP32-D0WD microcontroller over I2S. The I2S bus requires that the initialization and use of the peripheral on the bus is assigned to a dedicated core. The reason for this is that I2S and I2C attaches an interrupt to one of 32 interrupt vectors available per core. Attempting to initialize or access the peripheral without affinity to a specific core will most likely cause a hard fault almost immediately or at some point in time. The amplifier and the microphone share a GPIO and therefore, only one of them can be used at one time. You must de-initialize one if you intend to use the other.
To enable this feature using KConfig, use the command pio run --environment core2foraws --target menuconfig from within the root of the project directory in your PlatformIO terminal window and go to the menu Component Config --> Core2 for AWS features to set the features you want to enable.
The following example creates a FreeRTOS task that's pinned to Core 1, which intializes and enables the speaker and plays 32 bytes of a 16-bit 44100Hz sound buffer. Once done playing the very brief sound, it deinitializes and disables the speaker. The size of the sound buffer is too short to be recognized by human ears.