libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::DacHandle Class Reference

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

Detailed Description

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
 
DacHandleoperator= (const DacHandle &other)=default
 
Result Init (const Config &config)
 
const ConfigGetConfig () 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)
 

Member Typedef Documentation

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

Member Enumeration Documentation

◆ BitDepth

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)

Enumerator
BITS_8 
BITS_12 

◆ BufferState

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

Enumerator
ENABLED 
DISABLED 

◆ Channel

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

Enumerator
ONE 
TWO 
BOTH 

◆ Mode

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.

Enumerator
POLLING 
DMA 

◆ Result

Return Values for the DacHandle class

Enumerator
OK 
ERR 

Constructor & Destructor Documentation

◆ DacHandle() [1/2]

daisy::DacHandle::DacHandle ( )
inline

◆ DacHandle() [2/2]

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

Member Function Documentation

◆ GetConfig()

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

◆ Init()

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

Initialize the DAC Peripheral

◆ operator=()

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

◆ Start() [1/2]

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.

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

◆ Stop()

Result daisy::DacHandle::Stop ( )

Stops the DAC channel(s).

◆ WriteValue()

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

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


The documentation for this class was generated from the following file: