Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
The Digital To Analog Converter (DAC) is used to drive a speaker or headphones. It uses the DAC peripheral. The peripheral can be used a few different ways, but this project uses DMA to output a continuous, arbitrary signal.
This component is initialized by initDac() with a fnDacCallback_t callback which will request DAC samples from the application when required. Sample requests come from the DAC peripheral in an interrupt and are queued to be serviced out of the interrupt. This queue is checked in dacPoll(). Spending time to generate samples in an interrupt isn't a good idea.
You don't need to call initDac() or deinitDac(). The system does at the appropriate times.
The system will also automatically call dacStart(), though the Swadge mode can later call dacStop() or dacStart() when the DAC needs to be used. Stopping the DAC when not in use can save some processing cycles, but stopping it abruptly may cause unwanted clicks or pops on the speaker.
dacPoll() is called automatically by the system while the DAC is running. By default, samples are requested from sngPlayerFillBuffer(). Swadge modes may override this by providing a non-NULL function pointer for swadgeMode_t.fnDacCb.
Go to the source code of this file.
Macros | |
#define | DAC_SAMPLE_RATE_HZ 16384 |
The sample rate for the DAC. | |
#define | DAC_BUF_SIZE 512 |
Typedefs | |
typedef void(* | fnDacCallback_t) (uint8_t *samples, int16_t len) |
A callback which requests DAC samples from the application. | |
Functions | |
void | initDac (dac_channel_mask_t channel, gpio_num_t shdn_gpio, fnDacCallback_t cb) |
Initialize the DAC. | |
void | deinitDac (void) |
Deinitialize the DAC and free memory. | |
void | dacPoll (void) |
Poll the queue to see if any buffers need to be filled with audio samples. | |
void | dacStart (void) |
Start the DAC. This will cause samples to be requested from the application. | |
void | dacStop (void) |
Stop the DAC. | |
void | setDacShutdown (bool shutdown) |
Set the shutdown state of the DAC. | |
#define DAC_SAMPLE_RATE_HZ 16384 |
The sample rate for the DAC.
#define DAC_BUF_SIZE 512 |
The size of each buffer to fill with DAC samples
typedef void(* fnDacCallback_t) (uint8_t *samples, int16_t len) |
A callback which requests DAC samples from the application.
samples | A buffer to fill with 8 bit unsigned DAC samples |
len | The length of the buffer to fill |
void initDac | ( | dac_channel_mask_t | channel, |
gpio_num_t | shdn_gpio, | ||
fnDacCallback_t | cb ) |
Initialize the DAC.
channel | The output channel (pin) for the ADC |
shdn_gpio | The GPIO that controls the amplifier's shutdown |
cb | A callback function which will be called to request samples from the application |
void deinitDac | ( | void | ) |
Deinitialize the DAC and free memory.
void dacPoll | ( | void | ) |
Poll the queue to see if any buffers need to be filled with audio samples.
void dacStart | ( | void | ) |
Start the DAC. This will cause samples to be requested from the application.
void dacStop | ( | void | ) |
Stop the DAC.
void setDacShutdown | ( | bool | shutdown | ) |
Set the shutdown state of the DAC.
shutdown | true to shut down the DAC, false to enable it |