fsl_adc16.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*
  2. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  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 the copyright holder 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. #ifndef _FSL_ADC16_H_
  31. #define _FSL_ADC16_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup adc16
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. /*! @brief ADC16 driver version 2.0.0. */
  43. #define FSL_ADC16_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  44. /*@}*/
  45. /*!
  46. * @brief Channel status flags.
  47. */
  48. enum _adc16_channel_status_flags
  49. {
  50. kADC16_ChannelConversionDoneFlag = ADC_SC1_COCO_MASK, /*!< Conversion done. */
  51. };
  52. /*!
  53. * @brief Converter status flags.
  54. */
  55. enum _adc16_status_flags
  56. {
  57. kADC16_ActiveFlag = ADC_SC2_ADACT_MASK, /*!< Converter is active. */
  58. #if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
  59. kADC16_CalibrationFailedFlag = ADC_SC3_CALF_MASK, /*!< Calibration is failed. */
  60. #endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
  61. };
  62. #if defined(FSL_FEATURE_ADC16_HAS_MUX_SELECT) && FSL_FEATURE_ADC16_HAS_MUX_SELECT
  63. /*!
  64. * @brief Channel multiplexer mode for each channel.
  65. *
  66. * For some ADC16 channels, there are two pin selections in channel multiplexer. For example, ADC0_SE4a and ADC0_SE4b
  67. * are the different channels that share the same channel number.
  68. */
  69. typedef enum _adc_channel_mux_mode
  70. {
  71. kADC16_ChannelMuxA = 0U, /*!< For channel with channel mux a. */
  72. kADC16_ChannelMuxB = 1U, /*!< For channel with channel mux b. */
  73. } adc16_channel_mux_mode_t;
  74. #endif /* FSL_FEATURE_ADC16_HAS_MUX_SELECT */
  75. /*!
  76. * @brief Clock divider for the converter.
  77. */
  78. typedef enum _adc16_clock_divider
  79. {
  80. kADC16_ClockDivider1 = 0U, /*!< For divider 1 from the input clock to the module. */
  81. kADC16_ClockDivider2 = 1U, /*!< For divider 2 from the input clock to the module. */
  82. kADC16_ClockDivider4 = 2U, /*!< For divider 4 from the input clock to the module. */
  83. kADC16_ClockDivider8 = 3U, /*!< For divider 8 from the input clock to the module. */
  84. } adc16_clock_divider_t;
  85. /*!
  86. *@brief Converter's resolution.
  87. */
  88. typedef enum _adc16_resolution
  89. {
  90. /* This group of enumeration is for internal use which is related to register setting. */
  91. kADC16_Resolution8or9Bit = 0U, /*!< Single End 8-bit or Differential Sample 9-bit. */
  92. kADC16_Resolution12or13Bit = 1U, /*!< Single End 12-bit or Differential Sample 13-bit. */
  93. kADC16_Resolution10or11Bit = 2U, /*!< Single End 10-bit or Differential Sample 11-bit. */
  94. /* This group of enumeration is for a public user. */
  95. kADC16_ResolutionSE8Bit = kADC16_Resolution8or9Bit, /*!< Single End 8-bit. */
  96. kADC16_ResolutionSE12Bit = kADC16_Resolution12or13Bit, /*!< Single End 12-bit. */
  97. kADC16_ResolutionSE10Bit = kADC16_Resolution10or11Bit, /*!< Single End 10-bit. */
  98. #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
  99. kADC16_ResolutionDF9Bit = kADC16_Resolution8or9Bit, /*!< Differential Sample 9-bit. */
  100. kADC16_ResolutionDF13Bit = kADC16_Resolution12or13Bit, /*!< Differential Sample 13-bit. */
  101. kADC16_ResolutionDF11Bit = kADC16_Resolution10or11Bit, /*!< Differential Sample 11-bit. */
  102. #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
  103. #if defined(FSL_FEATURE_ADC16_MAX_RESOLUTION) && (FSL_FEATURE_ADC16_MAX_RESOLUTION >= 16U)
  104. /* 16-bit is supported by default. */
  105. kADC16_Resolution16Bit = 3U, /*!< Single End 16-bit or Differential Sample 16-bit. */
  106. kADC16_ResolutionSE16Bit = kADC16_Resolution16Bit, /*!< Single End 16-bit. */
  107. #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
  108. kADC16_ResolutionDF16Bit = kADC16_Resolution16Bit, /*!< Differential Sample 16-bit. */
  109. #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
  110. #endif /* FSL_FEATURE_ADC16_MAX_RESOLUTION >= 16U */
  111. } adc16_resolution_t;
  112. /*!
  113. * @brief Clock source.
  114. */
  115. typedef enum _adc16_clock_source
  116. {
  117. kADC16_ClockSourceAlt0 = 0U, /*!< Selection 0 of the clock source. */
  118. kADC16_ClockSourceAlt1 = 1U, /*!< Selection 1 of the clock source. */
  119. kADC16_ClockSourceAlt2 = 2U, /*!< Selection 2 of the clock source. */
  120. kADC16_ClockSourceAlt3 = 3U, /*!< Selection 3 of the clock source. */
  121. /* Chip defined clock source */
  122. kADC16_ClockSourceAsynchronousClock = kADC16_ClockSourceAlt3, /*!< Using internal asynchronous clock. */
  123. } adc16_clock_source_t;
  124. /*!
  125. * @brief Long sample mode.
  126. */
  127. typedef enum _adc16_long_sample_mode
  128. {
  129. kADC16_LongSampleCycle24 = 0U, /*!< 20 extra ADCK cycles, 24 ADCK cycles total. */
  130. kADC16_LongSampleCycle16 = 1U, /*!< 12 extra ADCK cycles, 16 ADCK cycles total. */
  131. kADC16_LongSampleCycle10 = 2U, /*!< 6 extra ADCK cycles, 10 ADCK cycles total. */
  132. kADC16_LongSampleCycle6 = 3U, /*!< 2 extra ADCK cycles, 6 ADCK cycles total. */
  133. kADC16_LongSampleDisabled = 4U, /*!< Disable the long sample feature. */
  134. } adc16_long_sample_mode_t;
  135. /*!
  136. * @brief Reference voltage source.
  137. */
  138. typedef enum _adc16_reference_voltage_source
  139. {
  140. kADC16_ReferenceVoltageSourceVref = 0U, /*!< For external pins pair of VrefH and VrefL. */
  141. kADC16_ReferenceVoltageSourceValt = 1U, /*!< For alternate reference pair of ValtH and ValtL. */
  142. } adc16_reference_voltage_source_t;
  143. #if defined(FSL_FEATURE_ADC16_HAS_HW_AVERAGE) && FSL_FEATURE_ADC16_HAS_HW_AVERAGE
  144. /*!
  145. * @brief Hardware average mode.
  146. */
  147. typedef enum _adc16_hardware_average_mode
  148. {
  149. kADC16_HardwareAverageCount4 = 0U, /*!< For hardware average with 4 samples. */
  150. kADC16_HardwareAverageCount8 = 1U, /*!< For hardware average with 8 samples. */
  151. kADC16_HardwareAverageCount16 = 2U, /*!< For hardware average with 16 samples. */
  152. kADC16_HardwareAverageCount32 = 3U, /*!< For hardware average with 32 samples. */
  153. kADC16_HardwareAverageDisabled = 4U, /*!< Disable the hardware average feature.*/
  154. } adc16_hardware_average_mode_t;
  155. #endif /* FSL_FEATURE_ADC16_HAS_HW_AVERAGE */
  156. /*!
  157. * @brief Hardware compare mode.
  158. */
  159. typedef enum _adc16_hardware_compare_mode
  160. {
  161. kADC16_HardwareCompareMode0 = 0U, /*!< x < value1. */
  162. kADC16_HardwareCompareMode1 = 1U, /*!< x > value1. */
  163. kADC16_HardwareCompareMode2 = 2U, /*!< if value1 <= value2, then x < value1 || x > value2;
  164. else, value1 > x > value2. */
  165. kADC16_HardwareCompareMode3 = 3U, /*!< if value1 <= value2, then value1 <= x <= value2;
  166. else x >= value1 || x <= value2. */
  167. } adc16_hardware_compare_mode_t;
  168. #if defined(FSL_FEATURE_ADC16_HAS_PGA) && FSL_FEATURE_ADC16_HAS_PGA
  169. /*!
  170. * @brief PGA's Gain mode.
  171. */
  172. typedef enum _adc16_pga_gain
  173. {
  174. kADC16_PGAGainValueOf1 = 0U, /*!< For amplifier gain of 1. */
  175. kADC16_PGAGainValueOf2 = 1U, /*!< For amplifier gain of 2. */
  176. kADC16_PGAGainValueOf4 = 2U, /*!< For amplifier gain of 4. */
  177. kADC16_PGAGainValueOf8 = 3U, /*!< For amplifier gain of 8. */
  178. kADC16_PGAGainValueOf16 = 4U, /*!< For amplifier gain of 16. */
  179. kADC16_PGAGainValueOf32 = 5U, /*!< For amplifier gain of 32. */
  180. kADC16_PGAGainValueOf64 = 6U, /*!< For amplifier gain of 64. */
  181. } adc16_pga_gain_t;
  182. #endif /* FSL_FEATURE_ADC16_HAS_PGA */
  183. /*!
  184. * @brief ADC16 converter configuration.
  185. */
  186. typedef struct _adc16_config
  187. {
  188. adc16_reference_voltage_source_t referenceVoltageSource; /*!< Select the reference voltage source. */
  189. adc16_clock_source_t clockSource; /*!< Select the input clock source to converter. */
  190. bool enableAsynchronousClock; /*!< Enable the asynchronous clock output. */
  191. adc16_clock_divider_t clockDivider; /*!< Select the divider of input clock source. */
  192. adc16_resolution_t resolution; /*!< Select the sample resolution mode. */
  193. adc16_long_sample_mode_t longSampleMode; /*!< Select the long sample mode. */
  194. bool enableHighSpeed; /*!< Enable the high-speed mode. */
  195. bool enableLowPower; /*!< Enable low power. */
  196. bool enableContinuousConversion; /*!< Enable continuous conversion mode. */
  197. } adc16_config_t;
  198. /*!
  199. * @brief ADC16 Hardware comparison configuration.
  200. */
  201. typedef struct _adc16_hardware_compare_config
  202. {
  203. adc16_hardware_compare_mode_t hardwareCompareMode; /*!< Select the hardware compare mode.
  204. See "adc16_hardware_compare_mode_t". */
  205. int16_t value1; /*!< Setting value1 for hardware compare mode. */
  206. int16_t value2; /*!< Setting value2 for hardware compare mode. */
  207. } adc16_hardware_compare_config_t;
  208. /*!
  209. * @brief ADC16 channel conversion configuration.
  210. */
  211. typedef struct _adc16_channel_config
  212. {
  213. uint32_t channelNumber; /*!< Setting the conversion channel number. The available range is 0-31.
  214. See channel connection information for each chip in Reference
  215. Manual document. */
  216. bool enableInterruptOnConversionCompleted; /*!< Generate an interrupt request once the conversion is completed. */
  217. #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE
  218. bool enableDifferentialConversion; /*!< Using Differential sample mode. */
  219. #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */
  220. } adc16_channel_config_t;
  221. #if defined(FSL_FEATURE_ADC16_HAS_PGA) && FSL_FEATURE_ADC16_HAS_PGA
  222. /*!
  223. * @brief ADC16 programmable gain amplifier configuration.
  224. */
  225. typedef struct _adc16_pga_config
  226. {
  227. adc16_pga_gain_t pgaGain; /*!< Setting PGA gain. */
  228. bool enableRunInNormalMode; /*!< Enable PGA working in normal mode, or low power mode by default. */
  229. #if defined(FSL_FEATURE_ADC16_HAS_PGA_CHOPPING) && FSL_FEATURE_ADC16_HAS_PGA_CHOPPING
  230. bool disablePgaChopping; /*!< Disable the PGA chopping function.
  231. The PGA employs chopping to remove/reduce offset and 1/f noise and offers
  232. an offset measurement configuration that aids the offset calibration. */
  233. #endif /* FSL_FEATURE_ADC16_HAS_PGA_CHOPPING */
  234. #if defined(FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT) && FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT
  235. bool enableRunInOffsetMeasurement; /*!< Enable the PGA working in offset measurement mode.
  236. When this feature is enabled, the PGA disconnects itself from the external
  237. inputs and auto-configures into offset measurement mode. With this field
  238. set, run the ADC in the recommended settings and enable the maximum hardware
  239. averaging to get the PGA offset number. The output is the
  240. (PGA offset * (64+1)) for the given PGA setting. */
  241. #endif /* FSL_FEATURE_ADC16_HAS_PGA_OFFSET_MEASUREMENT */
  242. } adc16_pga_config_t;
  243. #endif /* FSL_FEATURE_ADC16_HAS_PGA */
  244. #if defined(__cplusplus)
  245. extern "C" {
  246. #endif
  247. /*******************************************************************************
  248. * API
  249. ******************************************************************************/
  250. /*!
  251. * @name Initialization
  252. * @{
  253. */
  254. /*!
  255. * @brief Initializes the ADC16 module.
  256. *
  257. * @param base ADC16 peripheral base address.
  258. * @param config Pointer to configuration structure. See "adc16_config_t".
  259. */
  260. void ADC16_Init(ADC_Type *base, const adc16_config_t *config);
  261. /*!
  262. * @brief De-initializes the ADC16 module.
  263. *
  264. * @param base ADC16 peripheral base address.
  265. */
  266. void ADC16_Deinit(ADC_Type *base);
  267. /*!
  268. * @brief Gets an available pre-defined settings for the converter's configuration.
  269. *
  270. * This function initializes the converter configuration structure with available settings. The default values are as follows.
  271. * @code
  272. * config->referenceVoltageSource = kADC16_ReferenceVoltageSourceVref;
  273. * config->clockSource = kADC16_ClockSourceAsynchronousClock;
  274. * config->enableAsynchronousClock = true;
  275. * config->clockDivider = kADC16_ClockDivider8;
  276. * config->resolution = kADC16_ResolutionSE12Bit;
  277. * config->longSampleMode = kADC16_LongSampleDisabled;
  278. * config->enableHighSpeed = false;
  279. * config->enableLowPower = false;
  280. * config->enableContinuousConversion = false;
  281. * @endcode
  282. * @param config Pointer to the configuration structure.
  283. */
  284. void ADC16_GetDefaultConfig(adc16_config_t *config);
  285. #if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
  286. /*!
  287. * @brief Automates the hardware calibration.
  288. *
  289. * This auto calibration helps to adjust the plus/minus side gain automatically.
  290. * Execute the calibration before using the converter. Note that the hardware trigger should be used
  291. * during the calibration.
  292. *
  293. * @param base ADC16 peripheral base address.
  294. *
  295. * @return Execution status.
  296. * @retval kStatus_Success Calibration is done successfully.
  297. * @retval kStatus_Fail Calibration has failed.
  298. */
  299. status_t ADC16_DoAutoCalibration(ADC_Type *base);
  300. #endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
  301. #if defined(FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION) && FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION
  302. /*!
  303. * @brief Sets the offset value for the conversion result.
  304. *
  305. * This offset value takes effect on the conversion result. If the offset value is not zero, the reading result
  306. * is subtracted by it. Note, the hardware calibration fills the offset value automatically.
  307. *
  308. * @param base ADC16 peripheral base address.
  309. * @param value Setting offset value.
  310. */
  311. static inline void ADC16_SetOffsetValue(ADC_Type *base, int16_t value)
  312. {
  313. base->OFS = (uint32_t)(value);
  314. }
  315. #endif /* FSL_FEATURE_ADC16_HAS_OFFSET_CORRECTION */
  316. /* @} */
  317. /*!
  318. * @name Advanced Features
  319. * @{
  320. */
  321. #if defined(FSL_FEATURE_ADC16_HAS_DMA) && FSL_FEATURE_ADC16_HAS_DMA
  322. /*!
  323. * @brief Enables generating the DMA trigger when the conversion is complete.
  324. *
  325. * @param base ADC16 peripheral base address.
  326. * @param enable Switcher of the DMA feature. "true" means enabled, "false" means not enabled.
  327. */
  328. static inline void ADC16_EnableDMA(ADC_Type *base, bool enable)
  329. {
  330. if (enable)
  331. {
  332. base->SC2 |= ADC_SC2_DMAEN_MASK;
  333. }
  334. else
  335. {
  336. base->SC2 &= ~ADC_SC2_DMAEN_MASK;
  337. }
  338. }
  339. #endif /* FSL_FEATURE_ADC16_HAS_DMA */
  340. /*!
  341. * @brief Enables the hardware trigger mode.
  342. *
  343. * @param base ADC16 peripheral base address.
  344. * @param enable Switcher of the hardware trigger feature. "true" means enabled, "false" means not enabled.
  345. */
  346. static inline void ADC16_EnableHardwareTrigger(ADC_Type *base, bool enable)
  347. {
  348. if (enable)
  349. {
  350. base->SC2 |= ADC_SC2_ADTRG_MASK;
  351. }
  352. else
  353. {
  354. base->SC2 &= ~ADC_SC2_ADTRG_MASK;
  355. }
  356. }
  357. #if defined(FSL_FEATURE_ADC16_HAS_MUX_SELECT) && FSL_FEATURE_ADC16_HAS_MUX_SELECT
  358. /*!
  359. * @brief Sets the channel mux mode.
  360. *
  361. * Some sample pins share the same channel index. The channel mux mode decides which pin is used for an
  362. * indicated channel.
  363. *
  364. * @param base ADC16 peripheral base address.
  365. * @param mode Setting channel mux mode. See "adc16_channel_mux_mode_t".
  366. */
  367. void ADC16_SetChannelMuxMode(ADC_Type *base, adc16_channel_mux_mode_t mode);
  368. #endif /* FSL_FEATURE_ADC16_HAS_MUX_SELECT */
  369. /*!
  370. * @brief Configures the hardware compare mode.
  371. *
  372. * The hardware compare mode provides a way to process the conversion result automatically by using hardware. Only the result
  373. * in the compare range is available. To compare the range, see "adc16_hardware_compare_mode_t" or the appopriate reference
  374. * manual for more information.
  375. *
  376. * @param base ADC16 peripheral base address.
  377. * @param config Pointer to the "adc16_hardware_compare_config_t" structure. Passing "NULL" disables the feature.
  378. */
  379. void ADC16_SetHardwareCompareConfig(ADC_Type *base, const adc16_hardware_compare_config_t *config);
  380. #if defined(FSL_FEATURE_ADC16_HAS_HW_AVERAGE) && FSL_FEATURE_ADC16_HAS_HW_AVERAGE
  381. /*!
  382. * @brief Sets the hardware average mode.
  383. *
  384. * The hardware average mode provides a way to process the conversion result automatically by using hardware. The multiple
  385. * conversion results are accumulated and averaged internally making them easier to read.
  386. *
  387. * @param base ADC16 peripheral base address.
  388. * @param mode Setting the hardware average mode. See "adc16_hardware_average_mode_t".
  389. */
  390. void ADC16_SetHardwareAverage(ADC_Type *base, adc16_hardware_average_mode_t mode);
  391. #endif /* FSL_FEATURE_ADC16_HAS_HW_AVERAGE */
  392. #if defined(FSL_FEATURE_ADC16_HAS_PGA) && FSL_FEATURE_ADC16_HAS_PGA
  393. /*!
  394. * @brief Configures the PGA for the converter's front end.
  395. *
  396. * @param base ADC16 peripheral base address.
  397. * @param config Pointer to the "adc16_pga_config_t" structure. Passing "NULL" disables the feature.
  398. */
  399. void ADC16_SetPGAConfig(ADC_Type *base, const adc16_pga_config_t *config);
  400. #endif /* FSL_FEATURE_ADC16_HAS_PGA */
  401. /*!
  402. * @brief Gets the status flags of the converter.
  403. *
  404. * @param base ADC16 peripheral base address.
  405. *
  406. * @return Flags' mask if indicated flags are asserted. See "_adc16_status_flags".
  407. */
  408. uint32_t ADC16_GetStatusFlags(ADC_Type *base);
  409. /*!
  410. * @brief Clears the status flags of the converter.
  411. *
  412. * @param base ADC16 peripheral base address.
  413. * @param mask Mask value for the cleared flags. See "_adc16_status_flags".
  414. */
  415. void ADC16_ClearStatusFlags(ADC_Type *base, uint32_t mask);
  416. /* @} */
  417. /*!
  418. * @name Conversion Channel
  419. * @{
  420. */
  421. /*!
  422. * @brief Configures the conversion channel.
  423. *
  424. * This operation triggers the conversion when in software trigger mode. When in hardware trigger mode, this API
  425. * configures the channel while the external trigger source helps to trigger the conversion.
  426. *
  427. * Note that the "Channel Group" has a detailed description.
  428. * To allow sequential conversions of the ADC to be triggered by internal peripherals, the ADC has more than one
  429. * group of status and control registers, one for each conversion. The channel group parameter indicates which group of
  430. * registers are used, for example, channel group 0 is for Group A registers and channel group 1 is for Group B registers. The
  431. * channel groups are used in a "ping-pong" approach to control the ADC operation. At any point, only one of
  432. * the channel groups is actively controlling ADC conversions. The channel group 0 is used for both software and hardware
  433. * trigger modes. Channel group 1 and greater indicates multiple channel group registers for
  434. * use only in hardware trigger mode. See the chip configuration information in the appropriate MCU reference manual for the
  435. * number of SC1n registers (channel groups) specific to this device. Channel group 1 or greater are not used
  436. * for software trigger operation. Therefore, writing to these channel groups does not initiate a new conversion.
  437. * Updating the channel group 0 while a different channel group is actively controlling a conversion is allowed and
  438. * vice versa. Writing any of the channel group registers while that specific channel group is actively controlling a
  439. * conversion aborts the current conversion.
  440. *
  441. * @param base ADC16 peripheral base address.
  442. * @param channelGroup Channel group index.
  443. * @param config Pointer to the "adc16_channel_config_t" structure for the conversion channel.
  444. */
  445. void ADC16_SetChannelConfig(ADC_Type *base, uint32_t channelGroup, const adc16_channel_config_t *config);
  446. /*!
  447. * @brief Gets the conversion value.
  448. *
  449. * @param base ADC16 peripheral base address.
  450. * @param channelGroup Channel group index.
  451. *
  452. * @return Conversion value.
  453. */
  454. static inline uint32_t ADC16_GetChannelConversionValue(ADC_Type *base, uint32_t channelGroup)
  455. {
  456. assert(channelGroup < ADC_R_COUNT);
  457. return base->R[channelGroup];
  458. }
  459. /*!
  460. * @brief Gets the status flags of channel.
  461. *
  462. * @param base ADC16 peripheral base address.
  463. * @param channelGroup Channel group index.
  464. *
  465. * @return Flags' mask if indicated flags are asserted. See "_adc16_channel_status_flags".
  466. */
  467. uint32_t ADC16_GetChannelStatusFlags(ADC_Type *base, uint32_t channelGroup);
  468. /* @} */
  469. #if defined(__cplusplus)
  470. }
  471. #endif
  472. /*!
  473. * @}
  474. */
  475. #endif /* _FSL_ADC16_H_ */