2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
11 * o Redistributions in binary form must reproduce the above copyright notice, this
12 * list of conditions and the following disclaimer in the documentation and/or
13 * other materials provided with the distribution.
15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef __FSL_DAC_HAL_H__
32 #define __FSL_DAC_HAL_H__
37 #include "fsl_device_registers.h"
38 #include "fsl_dac_features.h"
45 /******************************************************************************
47 *****************************************************************************/
50 * @brief DAC status return codes.
52 typedef enum _dac_status
54 kStatus_DAC_Success
= 0U, /*!< Success. */
55 kStatus_DAC_InvalidArgument
= 1U, /*!< Invalid argument existed. */
56 kStatus_DAC_Failed
= 2U /*!< Execution failed. */
60 * @brief Defines the type of selection for DAC module's reference voltage source.
62 * See the appropriate SoC Reference Manual for actual connections.
64 typedef enum _dac_ref_volt_src_mode
66 kDacRefVoltSrcOfVref1
= 0U, /*!< Select DACREF_1 as the reference voltage. */
67 kDacRefVoltSrcOfVref2
= 1U, /*!< Select DACREF_2 as the reference voltage. */
68 } dac_ref_volt_src_mode_t
;
71 * @brief Defines the type of selection for DAC module trigger mode.
73 typedef enum _dac_trigger_mode
75 kDacTriggerByHardware
= 0U, /*!< Select hardware trigger. */
76 kDacTriggerBySoftware
= 1U /*!< Select software trigger. */
80 * @brief Defines the type of selection for buffer watermark mode.
82 * If the buffer feature for DAC module is enabled, a watermark event will
83 * occur when the buffer index hits the watermark.
85 typedef enum _dac_buff_watermark_mode
87 kDacBuffWatermarkFromUpperAs1Word
= 0U, /*!< Select 1 word away from the upper of buffer. */
88 kDacBuffWatermarkFromUpperAs2Word
= 1U, /*!< Select 2 word away from the upper of buffer. */
89 kDacBuffWatermarkFromUpperAs3Word
= 2U, /*!< Select 3 word away from the upper of buffer. */
90 kDacBuffWatermarkFromUpperAs4Word
= 3U, /*!< Select 4 word away from the upper of buffer. */
91 } dac_buff_watermark_mode_t
;
94 * @brief Defines the type of selection for buffer work mode.
96 * There are three kinds of work modes when the DAC buffer is enabled.
97 * Normal mode - When the buffer index hits the upper level, it
98 * starts (0) on the next trigger.
99 * Swing mode - When the buffer index hits the upper level, it goes backward to
100 * the start and is reduced one-by-one on the next trigger. When the buffer index
101 * hits the start, it goes backward to the upper level and increases one-by-one
102 * on the next trigger.
103 * One-Time-Scan mode - The buffer index can only be increased on the next trigger.
104 * When the buffer index hits the upper level, it is not updated by the trigger.
107 typedef enum _dac_buff_work_mode
109 kDacBuffWorkAsNormalMode
= 0U, /*!< Buffer works as Normal. */
110 kDacBuffWorkAsSwingMode
= 1U, /*!< Buffer works as swing. */
111 kDacBuffWorkAsOneTimeScanMode
= 2U, /*!< Buffer works as one time scan.*/
112 kDacBuffWorkAsFIFOMode
= 3U /*!< Buffer works as FIFO.*/
113 } dac_buff_work_mode_t
;
115 #if defined(__cplusplus)
119 /*******************************************************************************
121 ******************************************************************************/
124 * @brief Resets all configurable registers to be in the reset state for DAC.
126 * This function resets all configurable registers to be in the reset state for DAC.
127 * It should be called before configuring the DAC module.
129 * @param baseAddr The DAC peripheral base address.
131 void DAC_HAL_Init(uint32_t baseAddr
);
134 * @brief Sets the 12-bit value for the DAC items in the buffer.
136 * This function sets the value assembled by the low 8 bits and high 4
137 * bits of 12-bit DAC item in the buffer.
139 * @param baseAddr The DAC peripheral base address.
140 * @param index Buffer index.
141 * @param value Setting value.
143 void DAC_HAL_SetBuffValue(uint32_t baseAddr
, uint8_t index
, uint16_t value
);
146 * @brief Gets the 12-bit value from the DAC item in the buffer.
148 * This function gets the value assembled by the low 8 bits and high 4
149 * bits of 12-bit DAC item in the buffer.
151 * @param baseAddr The DAC peripheral base address.
152 * @param index Buffer index.
153 * @return Current setting value.
155 uint16_t DAC_HAL_GetBuffValue(uint32_t baseAddr
, uint8_t index
);
158 * @brief Clears the flag of the DAC buffer read pointer.
160 * This function clears the flag of the DAC buffer read pointer when it hits the
163 * @param baseAddr The DAC peripheral base address.
165 static inline void DAC_HAL_ClearBuffIndexUpperFlag(uint32_t baseAddr
)
167 BW_DAC_SR_DACBFRPBF(baseAddr
, 0U);
171 * @brief Gets the flag of DAC buffer read pointer when it hits the bottom position.
173 * This function gets the flag of DAC buffer read pointer when it hits the
176 * @param baseAddr The DAC peripheral base address.
177 * @return Assertion of indicated event.
179 static inline bool DAC_HAL_GetBuffIndexUpperFlag(uint32_t baseAddr
)
181 return ( 1U == BR_DAC_SR_DACBFRPBF(baseAddr
) );
185 * @brief Clears the flag of the DAC buffer read pointer when it hits the top position.
187 * This function clears the flag of the DAC buffer read pointer when it hits the
190 * @param baseAddr The DAC peripheral base address.
192 static inline void DAC_HAL_ClearBuffIndexStartFlag(uint32_t baseAddr
)
194 BW_DAC_SR_DACBFRPTF(baseAddr
, 0U);
198 * @brief Gets the flag of the DAC buffer read pointer when it hits the top position.
200 * This function gets the flag of the DAC buffer read pointer when it hits the
203 * @param baseAddr The DAC peripheral base address.
204 * @return Assertion of indicated event.
206 static inline bool DAC_HAL_GetBuffIndexStartFlag(uint32_t baseAddr
)
208 return ( 1U == BR_DAC_SR_DACBFRPTF(baseAddr
) );
211 #if FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
214 * @brief Gets the flag of the DAC buffer read pointer when it hits the watermark position.
216 * This function gets the flag of the DAC buffer read pointer when it hits the
217 * watermark position.
219 * @param baseAddr The DAC peripheral base address.
220 * @return Assertion of indicated event.
222 static inline bool DAC_HAL_GetBuffIndexWatermarkFlag(uint32_t baseAddr
)
224 return ( 1U == BR_DAC_SR_DACBFWMF(baseAddr
) );
228 * @brief Clears the flag of the DAC buffer read pointer when it hits the watermark position.
230 * This function clears the flag of the DAC buffer read pointer when it hits the
231 * watermark position.
233 * @param baseAddr The DAC peripheral base address.
234 * @return Assertion of indicated event.
236 static inline void DAC_HAL_ClearBuffIndexWatermarkFlag(uint32_t baseAddr
)
238 BW_DAC_SR_DACBFWMF(baseAddr
, 0U);
240 #endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
243 * @brief Enables the Programmable Reference Generator.
245 * This function enables the Programmable Reference Generator. Then the
246 * DAC system is enabled.
248 * @param baseAddr The DAC peripheral base address.
250 static inline void DAC_HAL_Enable(uint32_t baseAddr
)
252 BW_DAC_C0_DACEN(baseAddr
, 1U);
256 * @brief Disables the Programmable Reference Generator.
258 * This function disables the Programmable Reference Generator. Then the
259 * DAC system is disabled.
261 * @param baseAddr The DAC peripheral base address.
263 static inline void DAC_HAL_Disable(uint32_t baseAddr
)
265 BW_DAC_C0_DACEN(baseAddr
, 0U);
269 * @brief Sets the reference voltage source mode for the DAC module.
271 * This function sets the reference voltage source mode for the DAC module.
273 * @param baseAddr The DAC peripheral base address.
274 * @param mode Selection of enumeration mode. See to "dac_ref_volt_src_mode_t".
276 static inline void DAC_HAL_SetRefVoltSrcMode(uint32_t baseAddr
, dac_ref_volt_src_mode_t mode
)
278 BW_DAC_C0_DACRFS(baseAddr
, ((kDacRefVoltSrcOfVref1
==mode
)?0U:1U) );
282 * @brief Sets the trigger mode for the DAC module.
284 * This function sets the trigger mode for the DAC module.
286 * @param baseAddr The DAC peripheral base address.
287 * @param mode Selection of enumeration mode. See to "dac_trigger_mode_t".
289 static inline void DAC_HAL_SetTriggerMode(uint32_t baseAddr
, dac_trigger_mode_t mode
)
291 BW_DAC_C0_DACTRGSEL(baseAddr
, ((kDacTriggerByHardware
==mode
)?0U:1U) );
295 * @brief Triggers the converter with software.
297 * This function triggers the converter with software. If the DAC software
298 * trigger is selected and buffer enabled, calling this API advances the
299 * buffer read pointer once.
301 * @param baseAddr The DAC peripheral base address.
303 static inline void DAC_HAL_SetSoftTriggerCmd(uint32_t baseAddr
)
305 BW_DAC_C0_DACSWTRG(baseAddr
, 1U);
309 * @brief Switches to enable working in low power mode for the DAC module.
311 * This function switches to enable working in low power mode for the DAC module.
313 * @param baseAddr The DAC peripheral base address.
314 * @param enable Switcher to assert the feature.
316 static inline void DAC_HAL_SetLowPowerCmd(uint32_t baseAddr
, bool enable
)
318 BW_DAC_C0_LPEN(baseAddr
, (enable
?1U:0U) );
321 #if FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
323 * @brief Switches to enable the interrupt when buffer read pointer hits the watermark position.
325 * This function switches to enable the interrupt when the buffer read pointer hits
326 * the watermark position.
328 * @param baseAddr The DAC peripheral base address.
329 * @param enable Switcher to assert the feature.
331 static inline void DAC_HAL_SetBuffIndexWatermarkIntCmd(uint32_t baseAddr
, bool enable
)
333 BW_DAC_C0_DACBWIEN(baseAddr
, (enable
?1U:0U) );
335 #endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
338 * @brief Switches to enable the interrupt when the buffer read pointer hits the top position.
340 * This function switches to enable the interrupt when the buffer read pointer hits
343 * @param baseAddr The DAC peripheral base address.
344 * @param enable Switcher to assert the feature.
346 static inline void DAC_HAL_SetBuffIndexStartIntCmd(uint32_t baseAddr
, bool enable
)
348 BW_DAC_C0_DACBTIEN(baseAddr
, (enable
?1U:0U) );
352 * @brief Switches to enable the interrupt when the buffer read pointer hits the bottom position.
354 * This function switches to enable the interrupt when the buffer read pointer hits
355 * the bottom position.
357 * @param baseAddr The DAC peripheral base address.
358 * @param enable Switcher to assert the feature.
360 static inline void DAC_HAL_SetBuffIndexUpperIntCmd(uint32_t baseAddr
, bool enable
)
362 BW_DAC_C0_DACBBIEN(baseAddr
, (enable
?1U:0U) );
366 * @brief Switches to enable the DMA for DAC.
368 * This function switches to enable the DMA for the DAC module. When the DMA is enabled,
369 * DMA request is generated by the original interrupts, which are
370 * not presented on this module at the same time.
372 * @param baseAddr The DAC peripheral base address.
373 * @param enable Switcher to assert the feature.
375 static inline void DAC_HAL_SetDmaCmd(uint32_t baseAddr
, bool enable
)
377 BW_DAC_C1_DMAEN(baseAddr
, (enable
?1U:0U) );
380 #if FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION
382 * @brief Sets the watermark mode of the buffer for the DAC module.
384 * This function sets the watermark mode of the buffer for the DAC module.
386 * @param baseAddr The DAC peripheral base address.
387 * @param mode Selection of enumeration mode. See to "dac_buff_watermark_mode_t".
389 static inline void DAC_HAL_SetBuffWatermarkMode(uint32_t baseAddr
, dac_buff_watermark_mode_t mode
)
391 BW_DAC_C1_DACBFWM(baseAddr
, (uint8_t)mode
);
393 #endif /* FSL_FEATURE_DAC_HAS_WATERMARK_DETECTION */
396 * @brief Sets the work mode of the buffer for the DAC module.
398 * This function sets the work mode of the buffer for the DAC module.
400 * @param baseAddr The DAC peripheral base address.
401 * @param mode Selection of enumeration mode. See to "dac_buff_work_mode_t".
403 static inline void DAC_HAL_SetBuffWorkMode(uint32_t baseAddr
, dac_buff_work_mode_t mode
)
405 BW_DAC_C1_DACBFMD(baseAddr
, (uint8_t)mode
);
409 * @brief Switches to enable the buffer for the DAC module.
411 * This function switches to enable the buffer for the DAC module.
413 * @param baseAddr The DAC peripheral base address.
414 * @param enable Switcher to assert the feature.
416 static inline void DAC_HAL_SetBuffCmd(uint32_t baseAddr
, bool enable
)
418 BW_DAC_C1_DACBFEN(baseAddr
, (enable
?1U:0U) );
422 * @brief Gets the buffer index upper limitation for the DAC module.
424 * This function gets the upper buffer index upper limitation for the DAC module.
426 * @param baseAddr The DAC peripheral base address.
427 * @return Value of buffer index upper limitation.
429 static inline uint8_t DAC_HAL_GetBuffUpperIndex(uint32_t baseAddr
)
431 return BR_DAC_C2_DACBFUP(baseAddr
);
435 * @brief Sets the buffer index upper limitation for the DAC module.
437 * This function sets the upper buffer index upper limitation for the DAC module.
439 * @param baseAddr The DAC peripheral base address.
440 * @param index Setting value of upper limitation for buffer index.
442 static inline void DAC_HAL_SetBuffUpperIndex(uint32_t baseAddr
, uint8_t index
)
444 assert(index
< HW_DAC_DATnL_COUNT
);
445 BW_DAC_C2_DACBFUP(baseAddr
, index
);
449 * @brief Gets the current buffer index upper limitation for the DAC module.
451 * This function gets the current buffer index for the DAC module.
453 * @param baseAddr The DAC peripheral base address.
454 * @return Value of current buffer index.
456 static inline uint8_t DAC_HAL_GetBuffCurrentIndex(uint32_t baseAddr
)
458 return BR_DAC_C2_DACBFRP(baseAddr
);
462 * @brief Sets the buffer index for the DAC module.
464 * This function sets the upper buffer index for the DAC module.
466 * @param baseAddr the DAC peripheral base address.
467 * @param index Setting value for buffer index.
469 static inline void DAC_HAL_SetBuffCurrentIndex(uint32_t baseAddr
, uint8_t index
)
471 assert(index
< HW_DAC_DATnL_COUNT
);
472 BW_DAC_C2_DACBFRP(baseAddr
, index
);
475 #if defined(__cplusplus)
483 #endif /* __FSL_DAC_HAL_H__ */
485 /******************************************************************************
487 *****************************************************************************/