1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
10 *
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.
14 *
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.
18 *
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.
29 */
30
31 #ifndef __ADC_IMX7D_H__
32 #define __ADC_IMX7D_H__
33
34 #include <stdint.h>
35 #include <stdbool.h>
36 #include <assert.h>
37 #include "device_imx.h"
38
39 /*!
40 * @addtogroup adc_imx7d_driver
41 * @{
42 */
43
44 /*******************************************************************************
45 * Definitions
46 ******************************************************************************/
47
48 /*! @brief ADC module initialization structure. */
49 typedef struct _adc_init_config
50 {
51 uint32_t sampleRate; /*!< The desired ADC sample rate.*/
52 bool levelShifterEnable; /*!< The level shifter module configuration(Enable to power on ADC module).*/
53 } adc_init_config_t;
54
55 /*! @brief ADC logic channel initialization structure. */
56 typedef struct _adc_logic_ch_init_config
57 {
58 uint32_t convertRate; /*!< The continuous rate when continuous sample enabled.*/
59 uint8_t inputChannel; /*!< The logic channel to be set.*/
60 uint8_t averageNumber; /*!< The average number for hardware average function.*/
61 bool coutinuousEnable; /*!< Continuous sample mode enable configuration.*/
62 bool averageEnable; /*!< Hardware average enable configuration.*/
63 } adc_logic_ch_init_config_t;
64
65 /*! @brief ADC logic channel selection enumeration. */
66 enum _adc_logic_ch_selection
67 {
68 adcLogicChA = 0x0, /*!< ADC Logic Channel A.*/
69 adcLogicChB = 0x1, /*!< ADC Logic Channel B.*/
70 adcLogicChC = 0x2, /*!< ADC Logic Channel C.*/
71 adcLogicChD = 0x3, /*!< ADC Logic Channel D.*/
72 adcLogicChSW = 0x4, /*!< ADC Logic Channel Software.*/
73 };
74
75 /*! @brief ADC hardware average number enumeration. */
76 enum _adc_average_number
77 {
78 adcAvgNum4 = 0x0, /*!< ADC Hardware Average Number is set to 4.*/
79 adcAvgNum8 = 0x1, /*!< ADC Hardware Average Number is set to 8.*/
80 adcAvgNum16 = 0x2, /*!< ADC Hardware Average Number is set to 16.*/
81 adcAvgNum32 = 0x3, /*!< ADC Hardware Average Number is set to 32.*/
82 };
83
84 /*! @brief ADC build-in comparer work mode configuration enumeration. */
85 enum _adc_compare_mode
86 {
87 adcCmpModeDisable = 0x0, /*!< ADC build-in comparator is disabled.*/
88 adcCmpModeGreaterThanLow = 0x1, /*!< ADC build-in comparator is triggered when sample value greater than low threshold.*/
89 adcCmpModeLessThanLow = 0x2, /*!< ADC build-in comparator is triggered when sample value less than low threshold.*/
90 adcCmpModeInInterval = 0x3, /*!< ADC build-in comparator is triggered when sample value in interval between low and high threshold.*/
91 adcCmpModeGreaterThanHigh = 0x5, /*!< ADC build-in comparator is triggered when sample value greater than high threshold.*/
92 adcCmpModeLessThanHigh = 0x6, /*!< ADC build-in comparator is triggered when sample value less than high threshold.*/
93 adcCmpModeOutOffInterval = 0x7, /*!< ADC build-in comparator is triggered when sample value out of interval between low and high threshold.*/
94 };
95
96 /*! @brief This enumeration contains the settings for all of the ADC interrupt configurations. */
97 enum _adc_interrupt
98 {
99 adcIntLastFifoDataRead = ADC_INT_EN_LAST_FIFO_DATA_READ_EN_MASK, /*!< Last FIFO Data Read Interrupt Enable.*/
100 adcIntConvertTimeoutChSw = ADC_INT_EN_SW_CH_COV_TO_INT_EN_MASK, /*!< Software Channel Conversion Time Out Interrupt Enable.*/
101 adcIntConvertTimeoutChD = ADC_INT_EN_CHD_COV_TO_INT_EN_MASK, /*!< Channel D Conversion Time Out Interrupt Enable.*/
102 adcIntConvertTimeoutChC = ADC_INT_EN_CHC_COV_TO_INT_EN_MASK, /*!< Channel C Conversion Time Out Interrupt Enable.*/
103 adcIntConvertTimeoutChB = ADC_INT_EN_CHB_COV_TO_INT_EN_MASK, /*!< Channel B Conversion Time Out Interrupt Enable.*/
104 adcIntConvertTimeoutChA = ADC_INT_EN_CHA_COV_TO_INT_EN_MASK, /*!< Channel A Conversion Time Out Interrupt Enable.*/
105 adcIntConvertChSw = ADC_INT_EN_SW_CH_COV_INT_EN_MASK, /*!< Software Channel Conversion Interrupt Enable.*/
106 adcIntConvertChD = ADC_INT_EN_CHD_COV_INT_EN_MASK, /*!< Channel D Conversion Interrupt Enable.*/
107 adcIntConvertChC = ADC_INT_EN_CHC_COV_INT_EN_MASK, /*!< Channel C Conversion Interrupt Enable.*/
108 adcIntConvertChB = ADC_INT_EN_CHB_COV_INT_EN_MASK, /*!< Channel B Conversion Interrupt Enable.*/
109 adcIntConvertChA = ADC_INT_EN_CHA_COV_INT_EN_MASK, /*!< Channel A Conversion Interrupt Enable.*/
110 adcIntFifoOverrun = ADC_INT_EN_FIFO_OVERRUN_INT_EN_MASK, /*!< FIFO overrun Interrupt Enable.*/
111 adcIntFifoUnderrun = ADC_INT_EN_FIFO_UNDERRUN_INT_EN_MASK, /*!< FIFO underrun Interrupt Enable.*/
112 adcIntDmaReachWatermark = ADC_INT_EN_DMA_REACH_WM_INT_EN_MASK, /*!< DMA Reach Watermark Level Interrupt Enable.*/
113 adcIntCmpChD = ADC_INT_EN_CHD_CMP_INT_EN_MASK, /*!< Channel D Compare Interrupt Enable.*/
114 adcIntCmpChC = ADC_INT_EN_CHC_CMP_INT_EN_MASK, /*!< Channel C Compare Interrupt Enable.*/
115 adcIntCmpChB = ADC_INT_EN_CHB_CMP_INT_EN_MASK, /*!< Channel B Compare Interrupt Enable.*/
116 adcIntCmpChA = ADC_INT_EN_CHA_CMP_INT_EN_MASK, /*!< Channel A Compare Interrupt Enable.*/
117 };
118
119 /*! @brief Flag for ADC interrupt/DMA status check or polling status. */
120 enum _adc_status_flag
121 {
122 adcStatusLastFifoDataRead = ADC_INT_STATUS_LAST_FIFO_DATA_READ_MASK, /*!< Last FIFO Data Read status flag.*/
123 adcStatusConvertTimeoutChSw = ADC_INT_STATUS_SW_CH_COV_TO_MASK, /*!< Software Channel Conversion Time Out status flag.*/
124 adcStatusConvertTimeoutChD = ADC_INT_STATUS_CHD_COV_TO_MASK, /*!< Channel D Conversion Time Out status flag.*/
125 adcStatusConvertTimeoutChC = ADC_INT_STATUS_CHC_COV_TO_MASK, /*!< Channel C Conversion Time Out status flag.*/
126 adcStatusConvertTimeoutChB = ADC_INT_STATUS_CHB_COV_TO_MASK, /*!< Channel B Conversion Time Out status flag.*/
127 adcStatusConvertTimeoutChA = ADC_INT_STATUS_CHA_COV_TO_MASK, /*!< Channel A Conversion Time Out status flag.*/
128 adcStatusConvertChSw = ADC_INT_STATUS_SW_CH_COV_MASK, /*!< Software Channel Conversion status flag.*/
129 adcStatusConvertChD = ADC_INT_STATUS_CHD_COV_MASK, /*!< Channel D Conversion status flag.*/
130 adcStatusConvertChC = ADC_INT_STATUS_CHC_COV_MASK, /*!< Channel C Conversion status flag.*/
131 adcStatusConvertChB = ADC_INT_STATUS_CHB_COV_MASK, /*!< Channel B Conversion status flag.*/
132 adcStatusConvertChA = ADC_INT_STATUS_CHA_COV_MASK, /*!< Channel A Conversion status flag.*/
133 adcStatusFifoOverrun = ADC_INT_STATUS_FIFO_OVERRUN_MASK, /*!< FIFO Overrun status flag.*/
134 adcStatusFifoUnderrun = ADC_INT_STATUS_FIFO_UNDERRUN_MASK, /*!< FIFO Underrun status flag.*/
135 adcStatusDmaReachWatermark = ADC_INT_STATUS_DMA_REACH_WM_MASK, /*!< DMA Reach Watermark Level status flag.*/
136 adcStatusCmpChD = ADC_INT_STATUS_CHD_CMP_MASK, /*!< Channel D Compare status flag.*/
137 adcStatusCmpChC = ADC_INT_STATUS_CHC_CMP_MASK, /*!< Channel C Compare status flag.*/
138 adcStatusCmpChB = ADC_INT_STATUS_CHB_CMP_MASK, /*!< Channel B Compare status flag.*/
139 adcStatusCmpChA = ADC_INT_STATUS_CHA_CMP_MASK, /*!< Channel A Compare status flag.*/
140 };
141
142 /*******************************************************************************
143 * API
144 ******************************************************************************/
145
146 #if defined(__cplusplus)
147 extern "C" {
148 #endif
149
150 /*!
151 * @name ADC Module Initialization and Configuration functions.
152 * @{
153 */
154
155 /*!
156 * @brief Initialize ADC to reset state and initialize with initialization structure.
157 *
158 * @param base ADC base pointer.
159 * @param initConfig ADC initialization structure.
160 */
161 void ADC_Init(ADC_Type* base, const adc_init_config_t* initConfig);
162
163 /*!
164 * @brief This function reset ADC module register content to its default value.
165 *
166 * @param base ADC base pointer.
167 */
168 void ADC_Deinit(ADC_Type* base);
169
170 /*!
171 * @brief This function Enable ADC module build-in Level Shifter.
172 * For i.MX 7Dual, Level Shifter should always be enabled.
173 * User can disable Level Shifter to save power.
174 *
175 * @param base ADC base pointer.
176 */
ADC_LevelShifterEnable(ADC_Type * base)177 static inline void ADC_LevelShifterEnable(ADC_Type* base)
178 {
179 ADC_ADC_CFG_REG(base) |= ADC_ADC_CFG_ADC_EN_MASK;
180 }
181
182 /*!
183 * @brief This function Disable ADC module build-in Level Shifter
184 * to save power.
185 *
186 * @param base ADC base pointer.
187 */
ADC_LevelShifterDisable(ADC_Type * base)188 static inline void ADC_LevelShifterDisable(ADC_Type* base)
189 {
190 ADC_ADC_CFG_REG(base) &= ~ADC_ADC_CFG_ADC_EN_MASK;
191 }
192
193 /*!
194 * @brief This function is used to set ADC module sample rate.
195 *
196 * @param base ADC base pointer.
197 * @param sampleRate Desired ADC sample rate.
198 */
199 void ADC_SetSampleRate(ADC_Type* base, uint32_t sampleRate);
200
201 /*@}*/
202
203 /*!
204 * @name ADC Low power control functions.
205 * @{
206 */
207
208 /*!
209 * @brief This function is used to stop all digital part power.
210 *
211 * @param base ADC base pointer.
212 * @param clockDown Stop all ADC digital part or not.
213 * - true: Clock down.
214 * - false: Clock running.
215 */
216 void ADC_SetClockDownCmd(ADC_Type* base, bool clockDown);
217
218 /*!
219 * @brief This function is used to power down ADC analogue core.
220 * Before entering into stop-mode, power down ADC analogue core first.
221 * @param base ADC base pointer.
222 * @param powerDown Power down ADC analogue core or not.
223 * - true: Power down the ADC analogue core.
224 * - false: Do not power down the ADC analogue core.
225 */
226 void ADC_SetPowerDownCmd(ADC_Type* base, bool powerDown);
227
228 /*@}*/
229
230 /*!
231 * @name ADC Convert Channel Initialization and Configuration functions.
232 * @{
233 */
234
235 /*!
236 * @brief Initialize ADC Logic channel with initialization structure.
237 *
238 * @param base ADC base pointer.
239 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
240 * @param chInitConfig ADC logic channel initialization structure.
241 */
242 void ADC_LogicChInit(ADC_Type* base, uint8_t logicCh, const adc_logic_ch_init_config_t* chInitConfig);
243
244 /*!
245 * @brief Reset target ADC logic channel registers to default value.
246 *
247 * @param base ADC base pointer.
248 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
249 */
250 void ADC_LogicChDeinit(ADC_Type* base, uint8_t logicCh);
251
252 /*!
253 * @brief Select input channel for target logic channel.
254 *
255 * @param base ADC base pointer.
256 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
257 * @param inputCh Input channel selection for target logic channel(vary from 0 to 15).
258 */
259 void ADC_SelectInputCh(ADC_Type* base, uint8_t logicCh, uint8_t inputCh);
260
261 /*!
262 * @brief Set ADC conversion rate of target logic channel.
263 *
264 * @param base ADC base pointer.
265 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
266 * @param convertRate ADC conversion rate in Hz.
267 */
268 void ADC_SetConvertRate(ADC_Type* base, uint8_t logicCh, uint32_t convertRate);
269
270 /*!
271 * @brief Set work state of hardware average feature of target logic channel.
272 *
273 * @param base ADC base pointer.
274 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
275 * @param enable Enable/Disable hardware average
276 * - true: Enable hardware average of given logic channel.
277 * - false: Disable hardware average of given logic channel.
278 */
279 void ADC_SetAverageCmd(ADC_Type* base, uint8_t logicCh, bool enable);
280
281 /*!
282 * @brief Set hardware average number of target logic channel.
283 *
284 * @param base ADC base pointer.
285 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
286 * @param avgNum hardware average number(should select from @ref _adc_average_number enumeration).
287 */
288 void ADC_SetAverageNum(ADC_Type* base, uint8_t logicCh, uint8_t avgNum);
289
290 /*@}*/
291
292 /*!
293 * @name ADC Conversion Control functions.
294 * @{
295 */
296
297 /*!
298 * @brief Set continuous convert work mode of target logic channel.
299 *
300 * @param base ADC base pointer.
301 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
302 * @param enable Enable/Disable continuous convertion.
303 * - true: Enable continuous convertion.
304 * - false: Disable continuous convertion.
305 */
306 void ADC_SetConvertCmd(ADC_Type* base, uint8_t logicCh, bool enable);
307
308 /*!
309 * @brief Trigger single time convert on target logic channel.
310 *
311 * @param base ADC base pointer.
312 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
313 */
314 void ADC_TriggerSingleConvert(ADC_Type* base, uint8_t logicCh);
315
316 /*!
317 * @brief Stop current convert on target logic channel.
318 * For logic channel A ~ D, current conversion stops immediately.
319 * For Software channel, this function is waited until current conversion is finished.
320 * @param base ADC base pointer.
321 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
322 */
323 void ADC_StopConvert(ADC_Type* base, uint8_t logicCh);
324
325 /*!
326 * @brief Get 12-bit length right aligned convert result.
327 *
328 * @param base ADC base pointer.
329 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
330 * @return convert result on target logic channel.
331 */
332 uint16_t ADC_GetConvertResult(ADC_Type* base, uint8_t logicCh);
333
334 /*@}*/
335
336 /*!
337 * @name ADC Comparer Control functions.
338 * @{
339 */
340
341 /*!
342 * @brief Set the work mode of ADC module build-in comparer on target logic channel.
343 *
344 * @param base ADC base pointer.
345 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
346 * @param cmpMode Comparer work mode selected from @ref _adc_compare_mode enumeration.
347 */
348 void ADC_SetCmpMode(ADC_Type* base, uint8_t logicCh, uint8_t cmpMode);
349
350 /*!
351 * @brief Set ADC module build-in comparer high threshold on target logic channel.
352 *
353 * @param base ADC base pointer.
354 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
355 * @param threshold Comparer threshold in 12-bit unsigned int formate.
356 */
357 void ADC_SetCmpHighThres(ADC_Type* base, uint8_t logicCh, uint16_t threshold);
358
359 /*!
360 * @brief Set ADC module build-in comparer low threshold on target logic channel.
361 *
362 * @param base ADC base pointer.
363 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
364 * @param threshold Comparer threshold in 12-bit unsigned int formate.
365 */
366 void ADC_SetCmpLowThres(ADC_Type* base, uint8_t logicCh, uint16_t threshold);
367
368 /*!
369 * @brief Set the working mode of ADC module auto disable feature on target logic channel.
370 * This feature can disable continuous conversion when CMP condition matched.
371 *
372 * @param base ADC base pointer.
373 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
374 * @param enable Enable/Disable Auto Disable feature.
375 * - true: Enable Auto Disable feature.
376 * - false: Disable Auto Disable feature.
377 */
378 void ADC_SetAutoDisableCmd(ADC_Type* base, uint8_t logicCh, bool enable);
379
380 /*@}*/
381
382 /*!
383 * @name Interrupt and Flag control functions.
384 * @{
385 */
386
387 /*!
388 * @brief Enables or disables ADC interrupt requests.
389 *
390 * @param base ADC base pointer.
391 * @param intSource ADC interrupt sources to configuration.
392 * @param enable Enable/Disable given ADC interrupt.
393 * - true: Enable given ADC interrupt.
394 * - false: Disable given ADC interrupt.
395 */
396 void ADC_SetIntCmd(ADC_Type* base, uint32_t intSource, bool enable);
397
398 /*!
399 * @brief Enables or disables ADC interrupt flag when interrupt condition met.
400 *
401 * @param base ADC base pointer.
402 * @param intSignal ADC interrupt signals to configuration (see @ref _adc_interrupt enumeration).
403 * @param enable Enable/Disable given ADC interrupt flags.
404 * - true: Enable given ADC interrupt flags.
405 * - false: Disable given ADC interrupt flags.
406 */
407 void ADC_SetIntSigCmd(ADC_Type* base, uint32_t intSignal, bool enable);
408
409 /*!
410 * @brief Gets the ADC status flag state.
411 *
412 * @param base ADC base pointer.
413 * @param flags ADC status flag mask defined in @ref _adc_status_flag enumeration.
414 * @return ADC status, each bit represents one status flag
415 */
ADC_GetStatusFlag(ADC_Type * base,uint32_t flags)416 static inline uint32_t ADC_GetStatusFlag(ADC_Type* base, uint32_t flags)
417 {
418 return (ADC_INT_STATUS_REG(base) & flags);
419 }
420
421 /*!
422 * @brief Clear one or more ADC status flag state.
423 *
424 * @param base ADC base pointer.
425 * @param flags ADC status flag mask defined in @ref _adc_status_flag enumeration.
426 */
ADC_ClearStatusFlag(ADC_Type * base,uint32_t flags)427 static inline void ADC_ClearStatusFlag(ADC_Type* base, uint32_t flags)
428 {
429 ADC_INT_STATUS_REG(base) &= ~flags;
430 }
431
432 /*@}*/
433
434 /*!
435 * @name DMA & FIFO control functions.
436 * @{
437 */
438
439 /*!
440 * @brief Set the reset state of ADC internal DMA part.
441 *
442 * @param base ADC base pointer.
443 * @param active Reset DMA & DMA FIFO or not.
444 * - true: Reset the DMA and DMA FIFO return to its reset value.
445 * - false: Do not reset DMA and DMA FIFO.
446 */
447 void ADC_SetDmaReset(ADC_Type* base, bool active);
448
449 /*!
450 * @brief Set the work mode of ADC DMA part.
451 *
452 * @param base ADC base pointer.
453 * @param enable Enable/Disable ADC DMA part.
454 * - true: Enable DMA, the data in DMA FIFO should move by SDMA.
455 * - false: Disable DMA, the data in DMA FIFO can only move by CPU.
456 */
457 void ADC_SetDmaCmd(ADC_Type* base, bool enable);
458
459 /*!
460 * @brief Set the work mode of ADC DMA FIFO part.
461 *
462 * @param base ADC base pointer.
463 * @param enable Enable/Disable DMA FIFO.
464 * - true: Enable DMA FIFO.
465 * - false: Disable DMA FIFO.
466 */
467 void ADC_SetDmaFifoCmd(ADC_Type* base, bool enable);
468
469 /*!
470 * @brief Select the logic channel that uses the DMA transfer.
471 *
472 * @param base ADC base pointer.
473 * @param logicCh ADC module logic channel selection (see @ref _adc_logic_ch_selection enumeration).
474 */
ADC_SetDmaCh(ADC_Type * base,uint32_t logicCh)475 static inline void ADC_SetDmaCh(ADC_Type* base, uint32_t logicCh)
476 {
477 assert(logicCh <= adcLogicChD);
478 ADC_DMA_FIFO_REG(base) = (ADC_DMA_FIFO_REG(base) & ~ADC_DMA_FIFO_DMA_CH_SEL_MASK) | \
479 ADC_DMA_FIFO_DMA_CH_SEL(logicCh);
480 }
481
482 /*!
483 * @brief Set the DMA request trigger watermark.
484 *
485 * @param base ADC base pointer.
486 * @param watermark DMA request trigger watermark.
487 */
ADC_SetDmaWatermark(ADC_Type * base,uint32_t watermark)488 static inline void ADC_SetDmaWatermark(ADC_Type* base, uint32_t watermark)
489 {
490 assert(watermark <= 0x1FF);
491 ADC_DMA_FIFO_REG(base) = (ADC_DMA_FIFO_REG(base) & ~ADC_DMA_FIFO_DMA_WM_LVL_MASK) | \
492 ADC_DMA_FIFO_DMA_WM_LVL(watermark);
493 }
494
495 /*!
496 * @brief Get the convert result from DMA FIFO.
497 * Data position:
498 * DMA_FIFO_DATA1(27~16bits)
499 * DMA_FIFO_DATA0(11~0bits)
500 *
501 * @param base ADC base pointer.
502 * @return Get 2 ADC transfer result from DMA FIFO.
503 */
ADC_GetFifoData(ADC_Type * base)504 static inline uint32_t ADC_GetFifoData(ADC_Type* base)
505 {
506 return ADC_DMA_FIFO_DAT_REG(base);
507 }
508
509 /*!
510 * @brief Get the DMA FIFO full status
511 *
512 * @param base ADC base pointer.
513 * @retval true: DMA FIFO full.
514 * @retval false: DMA FIFO not full.
515 */
ADC_IsFifoFull(ADC_Type * base)516 static inline bool ADC_IsFifoFull(ADC_Type* base)
517 {
518 return (bool)(ADC_FIFO_STATUS_REG(base) & ADC_FIFO_STATUS_FIFO_FULL_MASK);
519 }
520
521 /*!
522 * @brief Get the DMA FIFO empty status
523 *
524 * @param base ADC base pointer.
525 * @retval true: DMA FIFO is empty.
526 * @retval false: DMA FIFO is not empty.
527 */
ADC_IsFifoEmpty(ADC_Type * base)528 static inline bool ADC_IsFifoEmpty(ADC_Type* base)
529 {
530 return (bool)(ADC_FIFO_STATUS_REG(base) & ADC_FIFO_STATUS_FIFO_EMPTY_MASK);
531 }
532
533 /*!
534 * @brief Get the entries number in DMA FIFO.
535 *
536 * @param base ADC base pointer.
537 * @return The numbers of data in DMA FIFO.
538 */
ADC_GetFifoEntries(ADC_Type * base)539 static inline uint8_t ADC_GetFifoEntries(ADC_Type* base)
540 {
541 return ADC_FIFO_STATUS_REG(base) & ADC_FIFO_STATUS_FIFO_ENTRIES_MASK;
542 }
543
544 /*@}*/
545
546 #ifdef __cplusplus
547 }
548 #endif
549
550 /*! @}*/
551
552 #endif /* __ADC_IMX7D_H__ */
553 /*******************************************************************************
554 * EOF
555 ******************************************************************************/
556