Firmware SDK
twr_dac

Driver for DAC. More...

Data Structures

struct  twr_dac_config_t
 DAC channel event. More...
 

Enumerations

enum  twr_dac_channel_t {
  TWR_DAC_DAC0 = 0 ,
  TWR_DAC_DAC1 = 1
}
 DAC channel. More...
 
enum  twr_dac_format_t {
  TWR_DAC_FORMAT_8_BIT = 0 ,
  TWR_DAC_FORMAT_16_BIT = 1 ,
  TWR_DAC_FORMAT_VOLTAGE = 2
}
 Raw value format. More...
 
enum  twr_dac_sample_rate_t {
  TWR_DAC_SAMPLE_RATE_8K = 0 ,
  TWR_DAC_SAMPLE_RATE_16K = 1
}
 Sample rate. More...
 
enum  twr_dac_data_size_t {
  TWR_DAC_DATA_SIZE_8 = 0 ,
  TWR_DAC_DATA_SIZE_16 = 1
}
 Data size. More...
 
enum  twr_dac_mode_t {
  TWR_DAC_MODE_SINGLE = 0 ,
  TWR_DAC_MODE_CIRCULAR = 1
}
 Mode. More...
 
enum  twr_dac_event_t {
  TWR_DAC_EVENT_HALF_DONE = 0 ,
  TWR_DAC_EVENT_DONE = 1
}
 DAC channel event. More...
 

Functions

void twr_dac_init (twr_dac_channel_t channel)
 Initialize DAC channel. More...
 
void twr_dac_deinit (twr_dac_channel_t channel)
 Deitialize DAC channel. More...
 
void twr_dac_set_output (twr_dac_channel_t channel, const void *raw, twr_dac_format_t format)
 Set DAC channel output as raw value. More...
 
void twr_dac_set_event_handler (twr_dac_channel_t channel, void(*event_handler)(twr_dac_channel_t, twr_dac_event_t, void *), void *event_param)
 Set callback function. More...
 
bool twr_dac_async_config (twr_dac_channel_t channel, twr_dac_config_t *config)
 Configure image of DAC DMA channel. More...
 
bool twr_dac_async_run (twr_dac_channel_t channel)
 Start asynchronous DAC channel operation. More...
 
void twr_dac_async_stop (twr_dac_channel_t channel)
 Stop asynchronous DAC channel operation. More...
 

Detailed Description

Driver for DAC.

Enumeration Type Documentation

◆ twr_dac_channel_t

DAC channel.

Enumerator
TWR_DAC_DAC0 

DAC channel DAC0.

TWR_DAC_DAC1 

DAC channel DAC1.

Definition at line 13 of file twr_dac.h.

◆ twr_dac_data_size_t

Data size.

Enumerator
TWR_DAC_DATA_SIZE_8 

Data size is 8b.

TWR_DAC_DATA_SIZE_16 

Data size is 16b.

Definition at line 52 of file twr_dac.h.

◆ twr_dac_event_t

DAC channel event.

Enumerator
TWR_DAC_EVENT_HALF_DONE 

Event is done.

TWR_DAC_EVENT_DONE 

Event is done.

Definition at line 76 of file twr_dac.h.

◆ twr_dac_format_t

Raw value format.

Enumerator
TWR_DAC_FORMAT_8_BIT 

Raw value format is 8-bit.

TWR_DAC_FORMAT_16_BIT 

Raw value format is 16-bit.

TWR_DAC_FORMAT_VOLTAGE 

Raw value format is float.

Definition at line 25 of file twr_dac.h.

◆ twr_dac_mode_t

Mode.

Enumerator
TWR_DAC_MODE_SINGLE 

Mode single.

TWR_DAC_MODE_CIRCULAR 

Mode circular (repeate playing buffer)

Definition at line 64 of file twr_dac.h.

◆ twr_dac_sample_rate_t

Sample rate.

Enumerator
TWR_DAC_SAMPLE_RATE_8K 

Data sample-rate is 8kHz.

TWR_DAC_SAMPLE_RATE_16K 

Data sample-rate is 16kHz.

Definition at line 40 of file twr_dac.h.

Function Documentation

◆ twr_dac_async_config()

bool twr_dac_async_config ( twr_dac_channel_t  channel,
twr_dac_config_t config 
)

Configure image of DAC DMA channel.

Parameters
[in]channelDMA channel
[in]bufferData buffer
[in]lengthData buffer length
[in]sample_rateData sample rate
[in]modeDAC channel DMA mode
Returns
true On success
false On failure (if DAC channel operation is in progress)

Definition at line 143 of file twr_dac.c.

◆ twr_dac_async_run()

bool twr_dac_async_run ( twr_dac_channel_t  channel)

Start asynchronous DAC channel operation.

Parameters
[in]channelDAC channel
Returns
true On success
false On failure

Definition at line 191 of file twr_dac.c.

Here is the call graph for this function:

◆ twr_dac_async_stop()

void twr_dac_async_stop ( twr_dac_channel_t  channel)

Stop asynchronous DAC channel operation.

Parameters
[in]channelDAC channel

Definition at line 264 of file twr_dac.c.

Referenced by twr_dac_deinit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ twr_dac_deinit()

void twr_dac_deinit ( twr_dac_channel_t  channel)

Deitialize DAC channel.

Parameters
[in]channelDAC channel

Definition at line 73 of file twr_dac.c.

Here is the call graph for this function:

◆ twr_dac_init()

void twr_dac_init ( twr_dac_channel_t  channel)

Initialize DAC channel.

Parameters
[in]channelDAC channel

Definition at line 43 of file twr_dac.c.

◆ twr_dac_set_event_handler()

void twr_dac_set_event_handler ( twr_dac_channel_t  channel,
void(*)(twr_dac_channel_t, twr_dac_event_t, void *)  event_handler,
void *  event_param 
)

Set callback function.

Parameters
[in]channelDAC channel
[in]event_handlerFunction address
[in]event_paramOptional event parameter (can be NULL)

Definition at line 137 of file twr_dac.c.

◆ twr_dac_set_output()

void twr_dac_set_output ( twr_dac_channel_t  channel,
const void *  raw,
twr_dac_format_t  format 
)

Set DAC channel output as raw value.

Parameters
[in]channelDAC channel
[out]rawPointer to desired raw value
[in]formatDesired raw value format

Definition at line 104 of file twr_dac.c.