Skip to content

daisy::DacHandle

Module: LIBDAISY / PERIPHERAL / ANALOG

DAC handle for Built-in DAC Peripheral. More...

#include <dac.h>

Public Classes

Name
struct Config

Public Types

Name
enum class Result
enum class Channel
enum class Mode
enum class BitDepth
enum class BufferState
typedef void(*)(uint16_t **out, size_t size) DacCallback

Public Functions

Name
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)

Detailed Description

class daisy::DacHandle;

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

Public Types Documentation

enum Result

Enumerator Value Description
OK
ERR

Return Values for the DacHandle class

enum Channel

Enumerator Value Description
ONE
TWO
BOTH

Selects which channel(s) will be configured for use.

enum Mode

Enumerator Value Description
POLLING
DMA

Sets the Mode for the DAC channels.

Polling mode uses the blocking mode to transmit a single value at a time.

DMA mode uses a buffer, and periodically transmits it triggering a callback to fill the buffer when it is ready for more samples.

enum BitDepth

Enumerator Value Description
BITS_8
BITS_12

Sets the number of bits per sample transmitted out of the DAC. The output range will be: 0V - VDDA The resolution will be roughly: bitdepth / (VDDA - 0V)

enum BufferState

Enumerator Value Description
ENABLED
DISABLED

Sets whether the DAC output is buffered for higher drive ability.

typedef DacCallback

typedef void(* daisy::DacHandle::DacCallback) (uint16_t **out, size_t size);

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} }

Public Functions Documentation

function DacHandle

inline DacHandle()

function DacHandle

DacHandle(
    const DacHandle & other
) =default

function operator=

DacHandle & operator=(
    const DacHandle & other
) =default

function Init

Result Init(
    const Config & config
)

Initialize the DAC Peripheral


function GetConfig

const Config & GetConfig() const

function Start

Result 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.


function Start

Result 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.


function Stop

Result Stop()

Stops the DAC channel(s).


function WriteValue

Result WriteValue(
    Channel chn,
    uint16_t val
)

Sets and Writes value in Polling Mode Has no effect in DMA mode.

---

Updated on 2024-01-03 at 19:41:01 +0000