The KSDK provides a peripheral driver for the Digital-to-Analog Converter (DAC) module of Kinetis devices.
#Overview
The DAC driver includes a basic DAC module (converter) and DAC buffer.
The basic DAC module supports operations unique to the DAC converter in each DAC instance. The APIs in this part are used in the initialization phase, which is necessary for enabling 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 (index of buffer), item values, and so on.
The DAC buffer plays a major part when using the DAC module, as 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
mask |= kDAC_BufferWatermarkInterruptEnable;
#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
if (kDAC_BufferWatermarkFlag == (kDAC_BufferWatermarkFlag & flags))
{
g_DacBufferWatermarkInterruptFlag = true;
}
#endif // FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
{
g_DacBufferReadPointerTopPositionInterruptFlag = true;
}
{
g_DacBufferReadPointerBottomPositionInterruptFlag = true;
}
bool dac_config_t::enableLowPowerMode |
struct dac_buffer_config_t |
uint8_t dac_buffer_config_t::upperLimit |
Normally, 0-15 is available for buffer with 16 item.
Enumerator |
---|
kDAC_BufferReadPointerTopPositionFlag |
DAC Buffer Read Pointer Top Position Flag.
|
kDAC_BufferReadPointerBottomPositionFlag |
DAC Buffer Read Pointer Bottom Position Flag.
|
Enumerator |
---|
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_BufferWorkAsNormalMode |
Normal mode.
|
kDAC_BufferWorkAsOneTimeScanMode |
One-Time Scan mode.
|
void DAC_Init |
( |
DAC_Type * |
base, |
|
|
const dac_config_t * |
config |
|
) |
| |
This function initializes the DAC module, including:
- 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:
- 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:
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 the feature or not. |
static void DAC_EnableBuffer |
( |
DAC_Type * |
base, |
|
|
bool |
enable |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | DAC peripheral base address. |
enable | Enables the feature or not. |
- 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 a default value. The default values are:
config->watermark = kDAC_BufferWatermark1Word;
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 the feature or not. |
void DAC_SetBufferValue |
( |
DAC_Type * |
base, |
|
|
uint8_t |
index, |
|
|
uint16_t |
value |
|
) |
| |
- Parameters
-
base | DAC peripheral base address. |
index | Setting index for items in the buffer. The available index should not exceed the size of the DAC buffer. |
value | Setting value for items in the buffer. 12-bits are available. |
static void DAC_DoSoftwareTriggerBuffer |
( |
DAC_Type * |
base | ) |
|
|
inlinestatic |
This function triggers the function by 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 by software trigger or hardware trigger.
- Parameters
-
base | DAC peripheral base address. |
- Returns
- Current read pointer of 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 by software trigger or hardware trigger. After the read pointer changes, the DAC output value also changes.
- Parameters
-
base | DAC peripheral base address. |
index | Setting 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". |