fsl_adc16.h 22 KB

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