Loading...
Searching...
No Matches

DAC peripheral driver interface. More...

Detailed Description

DAC peripheral driver interface.

Similar to the ADC driver interface (ADC), the DAC interface uses the concept of lines, corresponds to a tuple of a DAC device and a DAC output channel.

The DAC interface expects data to be served as a 16-bit unsigned integer, independent of the actual resolution of the hardware device. It is up to the DAC driver, to scale the given value to the maximal width that can be handled. The device driver should, on the other hand, implement the DAC in a way, that it will use the bit width, that comes closest to 16-bit.

This kind of 'auto-scaling' is quite sufficient for this interface, as standard DAC peripherals use a fixed conversion resolution internally anyway, so that any particular bit-width configuration on this driver level would not have much effect...

(Low-) Power Implications

The configured DAC peripherals are active (and consume power) from the point of initialization. When calling dac_poweroff(), the implementation should disable the given DAC line and put the DAC peripheral to sleep (e.g. through peripheral clock gating). When woken up again through dac_poweron(), the given DAC line should transparently continue it's previous operation.

The DAC driver implementation may need to block (and free) certain power modes in the driver's dac_init(), dac_poweron(), and the dac_poweroff() functions.

Topics

 DAC Direct Digital Synthesis
 

Files

file  dac_dds_params.h
 Default configuration for the DAC DDS driver.
 
file  dac.h
 DAC peripheral driver interface definition.
 

Macros

#define DAC_UNDEF   (UINT_FAST8_MAX)
 Default DAC undefined value.
 
#define DAC_LINE(x)
 Default DAC access macro.
 

Typedefs

typedef uint_fast8_t dac_t
 Define default DAC type identifier.
 
typedef void(* dma_cb_t) (void *arg)
 Signature of event callback functions triggered from interrupts.
 

Enumerations

enum  { DAC_OK = 0 , DAC_NOLINE = -1 }
 Return codes used by the DAC driver interface. More...
 

Functions

int8_t dac_init (dac_t line)
 Initialize the given DAC line.
 
void dac_set (dac_t line, uint16_t value)
 Write a value onto DAC Device on a given Channel.
 
void dac_poweron (dac_t line)
 Enable the given DAC line.
 
void dac_poweroff (dac_t line)
 Disable the given DAC line.
 
uint32_t dac_get_freq (void)
 Get the sample rate of the DAC in Hz.
 
int dac_play_setup (dac_t line, dma_cb_t cb, void *arg)
 Configure DAC line for playing sample buffer.
 
void dac_play (dac_t line, const uint16_t *buf, size_t len, uint8_t flags)
 Start playing sample buffer.
 
void dac_play_teardown (dac_t line)
 Release DAC line.
 
#define DAC_PLAY_LOOPED   (1 << 0)
 Options for dac_play.
 

Macro Definition Documentation

◆ DAC_LINE

#define DAC_LINE ( x)
Value:
(x)

Default DAC access macro.

Definition at line 86 of file dac.h.

◆ DAC_PLAY_LOOPED

#define DAC_PLAY_LOOPED   (1 << 0)

Options for dac_play.

keep playing the sample buffer in a loop

Definition at line 142 of file dac.h.

◆ DAC_UNDEF

#define DAC_UNDEF   (UINT_FAST8_MAX)

Default DAC undefined value.

Definition at line 79 of file dac.h.

Typedef Documentation

◆ dac_t

typedef uint_fast8_t dac_t

Define default DAC type identifier.

Definition at line 64 of file dac.h.

◆ dma_cb_t

typedef void(* dma_cb_t) (void *arg)

Signature of event callback functions triggered from interrupts.

Parameters
[in]argoptional context for the callback

Definition at line 150 of file dac.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Return codes used by the DAC driver interface.

Definition at line 70 of file dac.h.

Function Documentation

◆ dac_get_freq()

uint32_t dac_get_freq ( void )

Get the sample rate of the DAC in Hz.

Note
this requires the periph_dac_play feature
Returns
Sampling Rate in Hz

◆ dac_init()

int8_t dac_init ( dac_t line)

Initialize the given DAC line.

After initialization, the corresponding DAC line is active and its output is set to 0.

Parameters
[in]lineDAC line to initialize
Returns
DAC_OK on success
DAC_NOLINE on invalid DAC line

◆ dac_play()

void dac_play ( dac_t line,
const uint16_t * buf,
size_t len,
uint8_t flags )

Start playing sample buffer.

Note
this requires the periph_dac_play feature
Parameters
[in]lineDAC line to user for playing
[in]bufSample buffer to play
[in]lenNumber of samples to play
[in]flagsPlayback options

◆ dac_play_setup()

int dac_play_setup ( dac_t line,
dma_cb_t cb,
void * arg )

Configure DAC line for playing sample buffer.

Note
this requires the periph_dac_play feature
Parameters
[in]lineDAC line to configure
[in]cbCallback to be executed when the current sample buffer is done. If DAC_PLAY_LOOPED is set in dac_play(), the callback will not be executed, the current sample buffer will be played again. Will be executed in interrupt context. May be NULL.
[in]argCallback argument
Return values
0Success
-EEXISTLine has already been configured
-ENOMEMCan't allocate resources for playback

◆ dac_play_teardown()

void dac_play_teardown ( dac_t line)

Release DAC line.

Note
this requires the periph_dac_play feature
Parameters
[in]lineDAC line to release

◆ dac_poweroff()

void dac_poweroff ( dac_t line)

Disable the given DAC line.

Parameters
[in]lineDAC line to power off

◆ dac_poweron()

void dac_poweron ( dac_t line)

Enable the given DAC line.

Parameters
[in]lineDAC line to power on

◆ dac_set()

void dac_set ( dac_t line,
uint16_t value )

Write a value onto DAC Device on a given Channel.

The value is always given as 16-bit value and is internally scaled to the actual resolution that the DAC unit provides (e.g. 12-bit). So to get the maximum output voltage, this function has to be called with value set to 65535 (UINT16_MAX).

Parameters
[in]lineDAC line to set
[in]valuevalue to set line to