The MCUXpresso SDK provides a peripheral driver for the Digital-to-Analog Converter (DAC) module of MCUXpresso SDK devices.
The DAC driver includes a basic DAC module (converter) and a DAC buffer.
The basic DAC module supports operations unique to the DAC converter in each DAC instance. The APIs in this section are used in the initialization phase, which enables the DAC module in the application. The APIs enable/disable the clock, enable/disable the module, and configure the converter. Call the initial APIs to prepare the DAC module for the application.
The DAC buffer operates the DAC hardware buffer. The DAC module supports a hardware buffer to keep a group of DAC values to be converted. This feature supports updating the DAC output value automatically by triggering the buffer read pointer to move in the buffer. Use the APIs to configure the hardware buffer's trigger mode, watermark, work mode, and use size. Additionally, the APIs operate the DMA, interrupts, flags, the pointer (the index of the buffer), item values, and so on.
Note that the most functional features are designed for the DAC hardware buffer.
Typical use case
Working as a basic DAC without the hardware buffer feature
DAC_Init(DEMO_DAC_INSTANCE, &dacConfigStruct);
Working with the hardware buffer
EnableIRQ(DEMO_DAC_IRQ_ID);
DAC_Init(DEMO_DAC_INSTANCE, &dacConfigStruct);
for (index = 0U, dacValue = 0; index < DEMO_DAC_USED_BUFFER_SIZE; index++, dacValue += (0xFFFU / DEMO_DAC_USED_BUFFER_SIZE))
{
}
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
g_DacBufferWatermarkInterruptFlag = false;
#endif // FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
g_DacBufferReadPointerTopPositionInterruptFlag = false;
g_DacBufferReadPointerBottomPositionInterruptFlag = false;
mask = 0U;
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
#endif // FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
void DEMO_DAC_IRQ_HANDLER_FUNC(void)
{
#if defined(FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION) && FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
{
g_DacBufferWatermarkInterruptFlag = true;
}
#endif // FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
{
g_DacBufferReadPointerTopPositionInterruptFlag = true;
}
{
g_DacBufferReadPointerBottomPositionInterruptFlag = true;
}
}
|
enum | _dac_buffer_status_flags {
kDAC_BufferWatermarkFlag = DAC_SR_DACBFWMF_MASK,
kDAC_BufferReadPointerTopPositionFlag = DAC_SR_DACBFRPTF_MASK,
kDAC_BufferReadPointerBottomPositionFlag = DAC_SR_DACBFRPBF_MASK
} |
| DAC buffer flags. More...
|
|
enum | _dac_buffer_interrupt_enable {
kDAC_BufferWatermarkInterruptEnable = DAC_C0_DACBWIEN_MASK,
kDAC_BufferReadPointerTopInterruptEnable = DAC_C0_DACBTIEN_MASK,
kDAC_BufferReadPointerBottomInterruptEnable = DAC_C0_DACBBIEN_MASK
} |
| DAC buffer interrupts. More...
|
|
enum | dac_reference_voltage_source_t {
kDAC_ReferenceVoltageSourceVref1 = 0U,
kDAC_ReferenceVoltageSourceVref2 = 1U
} |
| DAC reference voltage source. More...
|
|
enum | dac_buffer_trigger_mode_t {
kDAC_BufferTriggerByHardwareMode = 0U,
kDAC_BufferTriggerBySoftwareMode = 1U
} |
| DAC buffer trigger mode. More...
|
|
enum | dac_buffer_watermark_t {
kDAC_BufferWatermark1Word = 0U,
kDAC_BufferWatermark2Word = 1U,
kDAC_BufferWatermark3Word = 2U,
kDAC_BufferWatermark4Word = 3U
} |
| DAC buffer watermark. More...
|
|
enum | dac_buffer_work_mode_t {
kDAC_BufferWorkAsNormalMode = 0U,
kDAC_BufferWorkAsSwingMode,
kDAC_BufferWorkAsOneTimeScanMode,
kDAC_BufferWorkAsFIFOMode
} |
| DAC buffer work mode. More...
|
|
bool dac_config_t::enableLowPowerMode |
struct dac_buffer_config_t |
uint8_t dac_buffer_config_t::upperLimit |
Normally, 0-15 is available for a buffer with 16 items.
Enumerator |
---|
kDAC_BufferWatermarkFlag |
DAC Buffer Watermark Flag.
|
kDAC_BufferReadPointerTopPositionFlag |
DAC Buffer Read Pointer Top Position Flag.
|
kDAC_BufferReadPointerBottomPositionFlag |
DAC Buffer Read Pointer Bottom Position Flag.
|
Enumerator |
---|
kDAC_BufferWatermarkInterruptEnable |
DAC Buffer Watermark Interrupt Enable.
|
kDAC_BufferReadPointerTopInterruptEnable |
DAC Buffer Read Pointer Top Flag Interrupt Enable.
|
kDAC_BufferReadPointerBottomInterruptEnable |
DAC Buffer Read Pointer Bottom Flag Interrupt Enable.
|
Enumerator |
---|
kDAC_ReferenceVoltageSourceVref1 |
The DAC selects DACREF_1 as the reference voltage.
|
kDAC_ReferenceVoltageSourceVref2 |
The DAC selects DACREF_2 as the reference voltage.
|
Enumerator |
---|
kDAC_BufferTriggerByHardwareMode |
The DAC hardware trigger is selected.
|
kDAC_BufferTriggerBySoftwareMode |
The DAC software trigger is selected.
|
Enumerator |
---|
kDAC_BufferWatermark1Word |
1 word away from the upper limit.
|
kDAC_BufferWatermark2Word |
2 words away from the upper limit.
|
kDAC_BufferWatermark3Word |
3 words away from the upper limit.
|
kDAC_BufferWatermark4Word |
4 words away from the upper limit.
|
Enumerator |
---|
kDAC_BufferWorkAsNormalMode |
Normal mode.
|
kDAC_BufferWorkAsSwingMode |
Swing mode.
|
kDAC_BufferWorkAsOneTimeScanMode |
One-Time Scan mode.
|
kDAC_BufferWorkAsFIFOMode |
FIFO mode.
|
void DAC_Init |
( |
DAC_Type * |
base, |
|
|
const dac_config_t * |
config |
|
) |
| |
This function initializes the DAC module including the following operations.
- Enabling the clock for DAC module.
- Configuring the DAC converter with a user configuration.
- Enabling the DAC module.
- Parameters
-
base | DAC peripheral base address. |
config | Pointer to the configuration structure. See "dac_config_t". |
void DAC_Deinit |
( |
DAC_Type * |
base | ) |
|
This function de-initializes the DAC module including the following operations.
- Disabling the DAC module.
- Disabling the clock for the DAC module.
- Parameters
-
base | DAC peripheral base address. |
This function initializes the user configuration structure to a default value. The default values are as follows.
* config->enableLowPowerMode = false;
*
- Parameters
-
config | Pointer to the configuration structure. See "dac_config_t". |
static void DAC_Enable |
( |
DAC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
enable | Enables or disables the feature. |
static void DAC_EnableBuffer |
( |
DAC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
enable | Enables or disables the feature. |
- Parameters
-
base | DAC peripheral base address. |
config | Pointer to the configuration structure. See "dac_buffer_config_t". |
This function initializes the DAC buffer configuration structure to default values. The default values are as follows.
* config->upperLimit = DAC_DATL_COUNT - 1U;
*
- Parameters
-
config | Pointer to the configuration structure. See "dac_buffer_config_t". |
static void DAC_EnableBufferDMA |
( |
DAC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
enable | Enables or disables the feature. |
void DAC_SetBufferValue |
( |
DAC_Type * |
base, |
|
|
uint8_t |
index, |
|
|
uint16_t |
value |
|
) |
| |
- Parameters
-
base | DAC peripheral base address. |
index | Setting the index for items in the buffer. The available index should not exceed the size of the DAC buffer. |
value | Setting the value for items in the buffer. 12-bits are available. |
static void DAC_DoSoftwareTriggerBuffer |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
This function triggers the function using software. The read pointer of the DAC buffer is updated with one step after this function is called. Changing the read pointer depends on the buffer's work mode.
- Parameters
-
base | DAC peripheral base address. |
static uint8_t DAC_GetBufferReadPointer |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
This function gets the current read pointer of the DAC buffer. The current output value depends on the item indexed by the read pointer. It is updated either by a software trigger or a hardware trigger.
- Parameters
-
base | DAC peripheral base address. |
- Returns
- The current read pointer of the DAC buffer.
void DAC_SetBufferReadPointer |
( |
DAC_Type * |
base, |
|
|
uint8_t |
index |
|
) |
| |
This function sets the current read pointer of the DAC buffer. The current output value depends on the item indexed by the read pointer. It is updated either by a software trigger or a hardware trigger. After the read pointer changes, the DAC output value also changes.
- Parameters
-
base | DAC peripheral base address. |
index | Setting an index value for the pointer. |
void DAC_EnableBufferInterrupts |
( |
DAC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | DAC peripheral base address. |
mask | Mask value for interrupts. See "_dac_buffer_interrupt_enable". |
void DAC_DisableBufferInterrupts |
( |
DAC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | DAC peripheral base address. |
mask | Mask value for interrupts. See "_dac_buffer_interrupt_enable". |
uint32_t DAC_GetBufferStatusFlags |
( |
DAC_Type * |
base | ) |
|
- Parameters
-
base | DAC peripheral base address. |
- Returns
- Mask value for the asserted flags. See "_dac_buffer_status_flags".
void DAC_ClearBufferStatusFlags |
( |
DAC_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
- Parameters
-
base | DAC peripheral base address. |
mask | Mask value for flags. See "_dac_buffer_status_flags_t". |