The MCUXpresso SDK provides a driver for the Digital Analog Converter (DAC) module of MCUXpreeso SDK devices.
Based on the features of the DAC module, the DAC driver is divided into serval function groups.
Module Initialization Interfaces
The functions in this group can be used to initialize or de-initialize the DAC module. To initialize the DAC module, the function DAC_GetDefaultConfig() can be invoked to get the module's default configuration.
Channels Control Interfaces
This function group contains channel control APIs. To configure the channels' all options directly at one time, the function DAC_SetChannelConfig() is provided, this function takes the pointer to structure that in the type of dac_channel_config_t as the parameter. All channel-related options are covered in this structure type. To set some specific options of channels, some low-level APIs also provided in this function group. All APIs in this function group take channelMask as the parameter, it means the mask of channel ID. If both channel A and channel B are aimed to set the same options, then users just need to invoke related APIs once with the channelMask set as the OR'ed value of channel A and channel B.
Triangle Waveform Configuration Interface
There is only one API in this function group, it is DAC_SetTriangleConfig() function. This function is used to configure the triangle waveform when channel A's wave type is selected as the triangle type.
Interrupts Control Interfaces.
The APIs in this function group can be used to enable/disable interrupts.
Status Flags Control Interfaces
The APIs in this function group can be used to get/clear status flags.
|
struct | dac_config_t |
| The structure of dac module basic configuration, including conversion rate, output range, and reference voltage source. More...
|
|
struct | dac_channel_config_t |
| The structure of dac channel configuration, such as trigger type, wave type, timing mode, and so on. More...
|
|
struct | dac_triangle_config_t |
| The structure of triangle waveform, including maximum value, minimum value, step size, and so on. More...
|
|
|
enum | _dac_interrupt_enable {
kDAC_ChannelAReadyInterruptEnable = DAC_IMR_A_RDY_INT_MSK_MASK,
kDAC_ChannelBReadyInterruptEnable = DAC_IMR_B_RDY_INT_MSK_MASK,
kDAC_ChannelATimeoutInterruptEnable = DAC_IMR_A_TO_INT_MSK_MASK,
kDAC_ChannelBTimeoutInterruptEnable = DAC_IMR_B_TO_INT_MSK_MASK,
kDAC_TriangleOverflowInterruptEnable = DAC_IMR_TRIA_OVFL_INT_MSK_MASK
} |
| The enumeration of interrupts that DAC support. More...
|
|
enum | _dac_status_flags {
kDAC_ChannelADataReadyInterruptFlag = DAC_ISR_A_RDY_INT_MASK,
kDAC_ChannelBDataReadyInterruptFlag = DAC_ISR_B_RDY_INT_MASK,
kDAC_ChannelATimeoutInterruptFlag = DAC_ISR_A_TO_INT_MASK,
kDAC_ChannelBTimeoutInterruptFlag = DAC_ISR_B_TO_INT_MASK,
kDAC_TriangleOverflowInterruptFlag = DAC_ISR_TRIA_OVFL_INT_MASK,
kDAC_RawChannelADataReadyFlag = DAC_IRSR_A_RDY_INT_RAW_MASK << 5UL,
kDAC_RawChannelBDataReadyFlag = DAC_IRSR_B_RDY_INT_RAW_MASK << 5UL,
kDAC_RawChannelATimeoutFlag = DAC_IRSR_A_TO_INT_RAW_MASK << 5UL,
kDAC_RawChannelBTimeoutFlag = DAC_IRSR_B_TO_INT_RAW_MASK << 5UL,
kDAC_RawTriangleOverflowFlag = DAC_IRSR_TRIA_OVFL_INT_RAW_MASK << 5UL,
kDAC_ChannelAConversionCompleteFlag = DAC_STATUS_A_DV_MASK << 10UL,
kDAC_ChannelBConversionCompleteFlag = DAC_STATUS_B_DV_MASK << 10UL
} |
| The enumeration of DAC status flags, including interrupt status flags, raw status flags, and conversion status flags. More...
|
|
enum | dac_channel_id_t |
| The enumeration of dac channels, including channel A and channel B.
|
|
enum | dac_conversion_rate_t {
kDAC_ConversionRate62P5KHZ = 0U,
kDAC_ConversionRate125KHZ,
kDAC_ConversionRate250KHZ,
kDAC_ConversionRate500KHZ
} |
| The enumeration of dac converion rate, including 62.5 KHz, 125 KHz, 250 KHz, and 500 KHz. More...
|
|
enum | dac_reference_voltage_source_t {
kDAC_ReferenceInternalVoltageSource = 0U,
kDAC_ReferenceExternalVoltageSource
} |
| The enumeration of dac reference voltage source. More...
|
|
enum | dac_output_voltage_range_t {
kDAC_RangeSmall = 0U,
kDAC_RangeMiddle = 1U,
kDAC_RangeLarge = 3U
} |
| The enumeration of dac output voltage range. More...
|
|
enum | dac_channel_output_t {
kDAC_ChannelOutputInternal = 0U,
kDAC_ChannelOutputPAD
} |
| The enumeration of dac channel's output mode. More...
|
|
enum | dac_channel_trigger_type_t {
kDAC_RisingEdgeTrigger = 1U,
kDAC_FallingEdgeTrigger = 2U,
kDAC_BothEdgeTrigger = 3U
} |
| The enumeration of dac channel's trigger type, including rising edge trigger, falling edge trigger, and both edge triggers. More...
|
|
enum | dac_channel_trigger_source_t {
kDAC_GPT2Trigger = 0U,
kDAC_GPT3Trigger = 1U,
kDAC_GPIO45Trigger = 2U,
kDAC_GPIO44Trigger = 3U
} |
| The enumeration of dac channel trigger source. More...
|
|
enum | dac_channel_timing_mode_t {
kDAC_NonTimingCorrelated = 0U,
kDAC_TimingCorrelated
} |
| The enumeration of dac channel timing mode. More...
|
|
enum | dac_channel_wave_type_t {
kDAC_WaveNormal = 0U,
kDAC_WaveTriangle = 1U,
kDAC_WaveSine = 2U,
kDAC_WaveNoiseDifferential = 3U
} |
| The enumerator of channel output wave type, please note that not all wave types are effective to A and B channel. More...
|
|
enum | dac_triangle_mamp_t {
kDAC_TriangleAmplitude63 = 0U,
kDAC_TriangleAmplitude127,
kDAC_TriangleAmplitude191,
kDAC_TriangleAmplitude255,
kDAC_TriangleAmplitude319,
kDAC_TriangleAmplitude383,
kDAC_TriangleAmplitude447,
kDAC_TriangleAmplitude511,
kDAC_TriangleAmplitude575,
kDAC_TriangleAmplitude639,
kDAC_TriangleAmplitude703,
kDAC_TriangleAmplitude767,
kDAC_TriangleAmplitude831,
kDAC_TriangleAmplitude895,
kDAC_TriangleAmplitude959,
kDAC_TriangleAmplitude1023
} |
| DAC triangle maximum amplitude type. More...
|
|
enum | dac_triangle_step_size_t {
kDAC_TriangleStepSize1 = 0U,
kDAC_TriangleStepSize3,
kDAC_TriangleStepSize15,
kDAC_TriangleStepSize511
} |
| DAC triangle step size type. More...
|
|
enum | dac_triangle_waveform_type_t {
kDAC_TriangleFull = 0U,
kDAC_TriangleHalf
} |
| DAC triangle waveform type. More...
|
|
|
void | DAC_Init (DAC_Type *base, const dac_config_t *config) |
| Initializes DAC module, including set reference voltage source, set conversion range, and set output voltage range. More...
|
|
void | DAC_GetDefaultConfig (dac_config_t *config) |
| Gets the default configurations of DAC module. More...
|
|
void | DAC_Deinit (DAC_Type *base) |
| De-initializes the DAC module, including reset clock divider, reset each channel, and so on. More...
|
|
|
void | DAC_SetChannelConfig (DAC_Type *base, uint32_t channelMask, const dac_channel_config_t *channelConfig) |
| Configures the DAC channels, including enable channel conversion, set wave type, set timing mode, and so on. More...
|
|
static void | DAC_ResetChannel (DAC_Type *base, uint32_t channelMask) |
| Does software reset for the selected DAC channels. More...
|
|
static void | DAC_EnableChannelConversion (DAC_Type *base, uint32_t channelMask, bool enable) |
| Enables/Disables selected channel conversion. More...
|
|
static void | DAC_SetChannelOutMode (DAC_Type *base, uint32_t channelMask, dac_channel_output_t outMode) |
| Sets channels out mode, including kDAC_ChannelOutputInternal and kDAC_ChannelOutputPad. More...
|
|
static void | DAC_EnableChannelTriggerMode (DAC_Type *base, uint32_t channelMask, bool enable) |
| Enables/Disables channels trigger mode. More...
|
|
static void | DAC_SetChannelTrigSource (DAC_Type *base, uint32_t channelMask, dac_channel_trigger_source_t trigSource) |
| Sets channels trigger source. More...
|
|
static void | DAC_SetChannelTrigType (DAC_Type *base, uint32_t channelMask, dac_channel_trigger_type_t trigType) |
| Sets channels trigger type, such as rising edge trigger, falling edge trigger, or both edge trigger. More...
|
|
static void | DAC_SetChannelTimingMode (DAC_Type *base, uint32_t channelMask, dac_channel_timing_mode_t timingMode) |
| Sets channels timing mode, including not-timing related or timing related. More...
|
|
static void | DAC_EnableChannelDMA (DAC_Type *base, uint32_t channelMask, bool enable) |
| Enables/Disables channels DMA. More...
|
|
static void | DAC_SetChannelWaveType (DAC_Type *base, uint32_t channelMask, dac_channel_wave_type_t waveType) |
| Sets channels wave type, such as sine, noise, or triangle. More...
|
|
static void | DAC_SetChannelData (DAC_Type *base, uint32_t channelMask, uint16_t data) |
| Sets DAC channels data. More...
|
|
|
static void | DAC_EnableInterrupts (DAC_Type *base, uint32_t interruptMask) |
| Enables interrupts, such as channel A data ready interupt, channel A timeout interrupt, and so on. More...
|
|
static void | DAC_DisableInterrupts (DAC_Type *base, uint32_t interruptMask) |
| Disables interrupts, such as channel B data ready interrupt, channel B timeout interrupt, and so on. More...
|
|
|
static uint32_t | DAC_GetStatusFlags (DAC_Type *base) |
| Gets the status flags, including interrupt status flags, raw status flags, and conversion status flags. More...
|
|
static void | DAC_ClearStatusFlags (DAC_Type *base, uint32_t statusFlagsMask) |
| Clears the interrups status flags, such as channel A data ready interrupt flag, channel B data ready interrupt flag, and so on. More...
|
|
struct dac_channel_config_t |
bool dac_channel_config_t::enableConversion |
- true Enable selected channel's conversion.
- false Disable selected channel's conversion.
bool dac_channel_config_t::enableDMA |
- true DMA data transfer enabled.
- false DMA data transfer disabled.
bool dac_channel_config_t::enableTrigger |
struct dac_triangle_config_t |
uint32_t dac_triangle_config_t::triangleBase |
Enumerator |
---|
kDAC_ChannelAReadyInterruptEnable |
Enable channel A data ready interrupt.
|
kDAC_ChannelBReadyInterruptEnable |
Enable channel B data ready interrupt.
|
kDAC_ChannelATimeoutInterruptEnable |
Enable channel A time out interrupt.
|
kDAC_ChannelBTimeoutInterruptEnable |
Enable channel B time out interrupt.
|
kDAC_TriangleOverflowInterruptEnable |
Enable triangle overflow interrupt.
|
- Note
- The interrupt status flags can only be asserted upon both enabling and happening of related interrupts. Comparatively, the raw status flags will be asserted as long as related events happen regardless of whether related interrupts are enabled or not.
-
Only interrupt status flags can be cleared mannually.
Enumerator |
---|
kDAC_ChannelADataReadyInterruptFlag |
Channel A data ready.
|
kDAC_ChannelBDataReadyInterruptFlag |
Channel B data ready.
|
kDAC_ChannelATimeoutInterruptFlag |
Channel A time out.
|
kDAC_ChannelBTimeoutInterruptFlag |
Channel B time out.
|
kDAC_TriangleOverflowInterruptFlag |
Triangle overflow.
|
kDAC_RawChannelADataReadyFlag |
Channel A data ready raw.
|
kDAC_RawChannelBDataReadyFlag |
Channel B data ready raw.
|
kDAC_RawChannelATimeoutFlag |
Channel A timeout raw.
|
kDAC_RawChannelBTimeoutFlag |
Channel B timeout raw.
|
kDAC_RawTriangleOverflowFlag |
Triangle overflow raw.
|
kDAC_ChannelAConversionCompleteFlag |
Channel A conversion complete.
|
kDAC_ChannelBConversionCompleteFlag |
Channel B conversion complete.
|
Enumerator |
---|
kDAC_ConversionRate62P5KHZ |
DAC Conversion Rate selects as 62.5 KHz.
|
kDAC_ConversionRate125KHZ |
DAC Conversion Rate selects as 125 KHz.
|
kDAC_ConversionRate250KHZ |
DAC Conversion Rate selects as 250 KHz.
|
kDAC_ConversionRate500KHZ |
DAC Conversion Rate selects as 500 KHz.
|
Enumerator |
---|
kDAC_ReferenceInternalVoltageSource |
Select internal voltage reference.
|
kDAC_ReferenceExternalVoltageSource |
Select external voltage reference.
|
Enumerator |
---|
kDAC_RangeSmall |
DAC output small range.
|
kDAC_RangeMiddle |
DAC output middle range.
|
kDAC_RangeLarge |
DAC output large range.
|
Enumerator |
---|
kDAC_ChannelOutputInternal |
Enable internal output but disable output to pad.
|
kDAC_ChannelOutputPAD |
Enable output to pad but disable internal output.
|
Enumerator |
---|
kDAC_RisingEdgeTrigger |
Rising edge trigger.
|
kDAC_FallingEdgeTrigger |
Failing edge trigger.
|
kDAC_BothEdgeTrigger |
Rising and Failing edge trigger.
|
Enumerator |
---|
kDAC_GPT2Trigger |
GPT2 trigger source.
|
kDAC_GPT3Trigger |
GPT3 trigger source.
|
kDAC_GPIO45Trigger |
GPIO45 trigger source.
|
kDAC_GPIO44Trigger |
GPIO44 trigger source.
|
Enumerator |
---|
kDAC_NonTimingCorrelated |
DAC non-timing-correlated mode.
|
kDAC_TimingCorrelated |
DAC timing-correlated mode.
|
Enumerator |
---|
kDAC_WaveNormal |
No predefined waveform, effective to A or B channel.
|
kDAC_WaveTriangle |
Triangle wave, effective only to A channel.
|
kDAC_WaveSine |
Sine wave, effective only to A channel.
|
kDAC_WaveNoiseDifferential |
Noise wave, effective only to A channel; Differential mode, one's complemental code from A data, effective only to B channel.
|
Enumerator |
---|
kDAC_TriangleAmplitude63 |
DAC triangle amplitude 63 lsb.
|
kDAC_TriangleAmplitude127 |
DAC triangle amplitude 127 lsb.
|
kDAC_TriangleAmplitude191 |
DAC triangle amplitude 191 lsb.
|
kDAC_TriangleAmplitude255 |
DAC triangle amplitude 255 lsb.
|
kDAC_TriangleAmplitude319 |
DAC triangle amplitude 319 lsb.
|
kDAC_TriangleAmplitude383 |
DAC triangle amplitude 383 lsb.
|
kDAC_TriangleAmplitude447 |
DAC triangle amplitude 447 lsb.
|
kDAC_TriangleAmplitude511 |
DAC triangle amplitude 511 lsb.
|
kDAC_TriangleAmplitude575 |
DAC triangle amplitude 575 lsb.
|
kDAC_TriangleAmplitude639 |
DAC triangle amplitude 639 lsb.
|
kDAC_TriangleAmplitude703 |
DAC triangle amplitude 703 lsb.
|
kDAC_TriangleAmplitude767 |
DAC triangle amplitude 767 lsb.
|
kDAC_TriangleAmplitude831 |
DAC triangle amplitude 831 lsb.
|
kDAC_TriangleAmplitude895 |
DAC triangle amplitude 895 lsb.
|
kDAC_TriangleAmplitude959 |
DAC triangle amplitude 959 lsb.
|
kDAC_TriangleAmplitude1023 |
DAC triangle amplitude 1023 lsb.
|
Enumerator |
---|
kDAC_TriangleStepSize1 |
DAC triangle step size 1 lsb.
|
kDAC_TriangleStepSize3 |
DAC triangle step size 3 lsb.
|
kDAC_TriangleStepSize15 |
DAC triangle step size 15 lsb.
|
kDAC_TriangleStepSize511 |
DAC triangle step size 511 lsb.
|
Enumerator |
---|
kDAC_TriangleFull |
DAC full triangle waveform.
|
kDAC_TriangleHalf |
DAC half triangle waveform.
|
void DAC_Init |
( |
DAC_Type * |
base, |
|
|
const dac_config_t * |
config |
|
) |
| |
- Parameters
-
base | DAC peripheral base address. |
config | Pointer to the structure which in type of dac_config_t. |
- Parameters
-
config | Pointer to the structure which in the type of dac_config_t. |
void DAC_Deinit |
( |
DAC_Type * |
base | ) |
|
- Parameters
-
base | DAC peripheral base address. |
void DAC_SetChannelConfig |
( |
DAC_Type * |
base, |
|
|
uint32_t |
channelMask, |
|
|
const dac_channel_config_t * |
channelConfig |
|
) |
| |
- Parameters
-
base | DAC peripheral base address. |
channelMask | The mask of channel, can be the OR'ed value of dac_channel_id_t. |
channelConfig | The pointer of structure which in the type of dac_channel_config_t. |
static void DAC_ResetChannel |
( |
DAC_Type * |
base, |
|
|
uint32_t |
channelMask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
channelMask | The mask of channel to be reset, should be the OR'ed value of dac_channel_id_t. |
static void DAC_EnableChannelConversion |
( |
DAC_Type * |
base, |
|
|
uint32_t |
channelMask, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Note
- To enable/disable the conversions of both channels, invoking this API with the parameter channelMask set as kDAC_ChannelA|kDAC_ChannelB .
- Parameters
-
base | DAC peripheral base address. |
channelMask | The mask of channel to be reset, can be the OR'ed value of dac_channel_id_t. |
enable | Enable/Disable channel conversion.
- true Enable selected channels' conversion.
- false Disable selected channels' conversion.
|
static void DAC_SetChannelOutMode |
( |
DAC_Type * |
base, |
|
|
uint32_t |
channelMask, |
|
|
dac_channel_output_t |
outMode |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
channelMask | The mask of channel, can be the OR'ed value of dac_channel_id_t. |
outMode | The out mode of selected channels, please refer to dac_channel_output_t for details. |
static void DAC_EnableChannelTriggerMode |
( |
DAC_Type * |
base, |
|
|
uint32_t |
channelMask, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Note
- To enable/disable the trigger mode of both two channels, invoking this API with the parameter channelMask set as kDAC_ChannelA|kDAC_ChannelB .
- Parameters
-
base | DAC peripheral base address. |
channelMask | The mask of channel, can be the OR'ed value of dac_channel_id_t. |
enable | Enable/Disable channel trigger mode.
- true Channels' conversion triggered by external event enabled.
- false Channels' conversion trigged by external event disabled.
|
- Note
- To set the same trigger source to both two channels, invoking this API with the parameter channelMask set as kDAC_ChannelA|kDAC_ChannelB .
- Parameters
-
- Note
- To set the same trigger type to both two channels, invoking this API with the parameter channelMask set as kDAC_ChannelA|kDAC_ChannelB .
- Parameters
-
- Note
- To the same timing mode to both two channels, invoking this API with the parameter channelMask set as kDAC_ChannelA|kDAC_ChannelB .
- Parameters
-
static void DAC_EnableChannelDMA |
( |
DAC_Type * |
base, |
|
|
uint32_t |
channelMask, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
channelMask | The mask of channel, can be the OR'ed value of dac_channel_id_t. |
enable | Enable/Disable channel DMA data transfer.
- true DMA data transfer enabled.
- false DMA data transfer disabled.
|
- Note
- To set the same wave type to both channel, invoking this API with the parameter channelMask set as kDAC_ChannelA|kDAC_ChannelB .
- Parameters
-
static void DAC_SetChannelData |
( |
DAC_Type * |
base, |
|
|
uint32_t |
channelMask, |
|
|
uint16_t |
data |
|
) |
| |
|
inlinestatic |
- Note
- To set the same data to both channel, invoking this API with the parameter channelMask set as kDAC_ChannelA|kDAC_ChannelB .
- Parameters
-
base | DAC peripheral base address. |
channelMask | The mask of channel, can be the OR'ed value of dac_channel_id_t. |
data | |
- Note
- This API should be invoked to set the options of triangle waveform when channel A's output wave type is selected as kDAC_WaveTriangle.
- Parameters
-
base | DAC peripheral base address. |
triangleConfig | The pointer of structure which in the type of dac_triangle_config_t. |
static void DAC_EnableInterrupts |
( |
DAC_Type * |
base, |
|
|
uint32_t |
interruptMask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
interruptMask | The or'ed value of the interrupts to be enabled, please refer to _dac_interrupt_enable. |
static void DAC_DisableInterrupts |
( |
DAC_Type * |
base, |
|
|
uint32_t |
interruptMask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
interruptMask | The or'ed value of the interrupts to be disabled, please refer to _dac_interrupt_enable. |
static uint32_t DAC_GetStatusFlags |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
- Returns
- The mask of status flags, please refer to _dac_status_flags.
static void DAC_ClearStatusFlags |
( |
DAC_Type * |
base, |
|
|
uint32_t |
statusFlagsMask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
statusFlagsMask | The mask of the status flags to be cleared, please refer to _dac_status_flags. |