DAC handle for Built-in DAC Peripheral. More...
DAC handle for Built-in DAC Peripheral.
For now only Normal Mode is supported, Sample and hold mode provides reduced power consumption, but requires a bit more setup.
For now connecting the DAC through other internal peripherals is also not supported.
Since the DAC channels have dedicated pins we don't need to pass in a pin config like with other modules. However, it is still important to not try to use the DAC pins for anything else. DAC Channel 1 is on PA4, and DAC Channel 2 is on PA5
#include <dac.h>
Classes | |
struct | Config |
Public Types | |
enum class | Result { OK , ERR } |
enum class | Channel { ONE , TWO , BOTH } |
enum class | Mode { POLLING , DMA } |
enum class | BitDepth { BITS_8 , BITS_12 } |
enum class | BufferState { ENABLED , DISABLED } |
typedef void(* | DacCallback) (uint16_t **out, size_t size) |
Public Member Functions | |
DacHandle () | |
DacHandle (const DacHandle &other)=default | |
DacHandle & | operator= (const DacHandle &other)=default |
Result | Init (const Config &config) |
const Config & | GetConfig () const |
Result | Start (uint16_t *buffer, size_t size, DacCallback cb) |
Result | Start (uint16_t *buffer_1, uint16_t *buffer_2, size_t size, DacCallback cb) |
Result | Stop () |
Result | WriteValue (Channel chn, uint16_t val) |
Callback for DMA transfers. This is called every time half of the samples of the buffer are transmitted, and the buffer is ready to be filled again.
The data is organized in arrays per channel, for example if both channels are in use: { {ch1-0, ch1-1, ch1-2 . . . ch1-N}, {ch2-0, ch2-1, ch2-2 . . . ch2–N} }
|
strong |
|
strong |
|
strong |
|
strong |
Return Values for the DacHandle class
Enumerator | |
---|---|
OK | |
ERR |
|
inline |
Result daisy::DacHandle::Start | ( | uint16_t * | buffer, |
size_t | size, | ||
DacCallback | cb | ||
) |
Starts the DAC conversion on the DMA calling the user callback whenever new samples are ready to be filled.
This will return Result::ERR if used when configured to BOTH channels.
Result daisy::DacHandle::Start | ( | uint16_t * | buffer_1, |
uint16_t * | buffer_2, | ||
size_t | size, | ||
DacCallback | cb | ||
) |
If using both channels, use this function to start the DMA transfer for both. The callback will provide an array per-channel to fill.
Result daisy::DacHandle::Stop | ( | ) |
Stops the DAC channel(s).
Sets and Writes value in Polling Mode Has no effect in DMA mode.