Skip to content

Class daisy::DacHandle

ClassList > daisy > DacHandle

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

  • #include <dac.h>

Classes

Type Name
struct Config

Public Types

Type Name
enum BitDepth
enum BufferState
enum Channel
typedef void(* DacCallback
enum Mode
enum Result

Public Functions

Type Name
DacHandle ()
DacHandle (const DacHandle & other) = default
const Config & GetConfig () const
Result Init (const Config & config)
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)
DacHandle & operator= (const DacHandle & other) = default

Detailed Description

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 BitDepth

enum daisy::DacHandle::BitDepth {
    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

enum daisy::DacHandle::BufferState {
    ENABLED,
    DISABLED
};

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


enum Channel

enum daisy::DacHandle::Channel {
    ONE,
    TWO,
    BOTH
};

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


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


enum Mode

enum daisy::DacHandle::Mode {
    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 Result

enum daisy::DacHandle::Result {
    OK,
    ERR
};

Return Values for the DacHandle class


Public Functions Documentation

function DacHandle [½]

inline daisy::DacHandle::DacHandle () 

function DacHandle [2/2]

daisy::DacHandle::DacHandle (
    const  DacHandle & other
) = default

function GetConfig

const  Config & daisy::DacHandle::GetConfig () const

function Init

Result daisy::DacHandle::Init (
    const  Config & config
) 

Initialize the DAC Peripheral


function Start [½]

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.


function Start [2/2]

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.


function Stop

Result daisy::DacHandle::Stop () 

Stops the DAC channel(s).


function WriteValue

Result daisy::DacHandle::WriteValue (
    Channel chn,
    uint16_t val
) 

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


function operator=

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


The documentation for this class was generated from the following file external-docs/libDaisy/src/per/dac.h