stm32f0xx_hal_adc.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file containing functions prototypes of ADC HAL library.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32F0xx_HAL_ADC_H
  20. #define STM32F0xx_HAL_ADC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f0xx_hal_def.h"
  26. /** @addtogroup STM32F0xx_HAL_Driver
  27. * @{
  28. */
  29. /** @addtogroup ADC
  30. * @{
  31. */
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @defgroup ADC_Exported_Types ADC Exported Types
  34. * @{
  35. */
  36. /**
  37. * @brief Structure definition of ADC initialization and regular group
  38. * @note The setting of these parameters with function HAL_ADC_Init() is conditioned to ADC state.
  39. * ADC state can be either:
  40. * - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'ClockPrescaler')
  41. * - For all parameters except 'ClockPrescaler' and 'resolution': ADC enabled without conversion on going on regular group.
  42. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  43. * without error reporting (as it can be the expected behaviour in case of intended action to update another parameter (which fulfills the ADC state condition) on the fly).
  44. */
  45. typedef struct
  46. {
  47. uint32_t ClockPrescaler; /*!< Select ADC clock source (synchronous clock derived from APB clock or asynchronous clock derived from ADC dedicated HSI RC oscillator 14MHz) and clock prescaler.
  48. This parameter can be a value of @ref ADC_ClockPrescaler
  49. Note: In case of usage of the ADC dedicated HSI RC oscillator, it must be preliminarily enabled at RCC top level.
  50. Note: This parameter can be modified only if the ADC is disabled */
  51. uint32_t Resolution; /*!< Configures the ADC resolution.
  52. This parameter can be a value of @ref ADC_Resolution */
  53. uint32_t DataAlign; /*!< Specifies whether the ADC data alignment is left or right.
  54. This parameter can be a value of @ref ADC_Data_align */
  55. uint32_t ScanConvMode; /*!< Configures the sequencer of regular group.
  56. This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
  57. Sequencer is automatically enabled if several channels are set (sequencer cannot be disabled, as it can be the case on other STM32 devices):
  58. If only 1 channel is set: Conversion is performed in single mode.
  59. If several channels are set: Conversions are performed in sequence mode (ranks defined by each channel number: channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  60. Scan direction can be set to forward (from channel 0 to channel 18) or backward (from channel 18 to channel 0).
  61. This parameter can be a value of @ref ADC_Scan_mode */
  62. uint32_t EOCSelection; /*!< Specifies what EOC (End Of Conversion) flag is used for conversion by polling and interruption: end of conversion of each rank or complete sequence.
  63. This parameter can be a value of @ref ADC_EOCSelection. */
  64. FunctionalState LowPowerAutoWait; /*!< Selects the dynamic low power Auto Delay: new conversion start only when the previous
  65. conversion (for regular group) has been treated by user software, using function HAL_ADC_GetValue().
  66. This feature automatically adapts the ADC conversions trigs to the speed of the system that reads the data. Moreover, this avoids risk of overrun for low frequency applications.
  67. This parameter can be set to ENABLE or DISABLE.
  68. Note: Do not use with interruption or DMA (HAL_ADC_Start_IT(), HAL_ADC_Start_DMA()) since they have to clear immediately the EOC flag to free the IRQ vector sequencer.
  69. Do use with polling: 1. Start conversion with HAL_ADC_Start(), 2. Later on, when conversion data is needed: use HAL_ADC_PollForConversion() to ensure that conversion is completed
  70. and use HAL_ADC_GetValue() to retrieve conversion result and trig another conversion. */
  71. FunctionalState LowPowerAutoPowerOff; /*!< Selects the auto-off mode: the ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered (with startup time between trigger and start of sampling).
  72. This feature can be combined with automatic wait mode (parameter 'LowPowerAutoWait').
  73. This parameter can be set to ENABLE or DISABLE.
  74. Note: If enabled, this feature also turns off the ADC dedicated 14 MHz RC oscillator (HSI14) */
  75. FunctionalState ContinuousConvMode; /*!< Specifies whether the conversion is performed in single mode (one conversion) or continuous mode for regular group,
  76. after the selected trigger occurred (software start or external trigger).
  77. This parameter can be set to ENABLE or DISABLE. */
  78. FunctionalState DiscontinuousConvMode; /*!< Specifies whether the conversions sequence of regular group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
  79. Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
  80. Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
  81. This parameter can be set to ENABLE or DISABLE
  82. Note: Number of discontinuous ranks increment is fixed to one-by-one. */
  83. uint32_t ExternalTrigConv; /*!< Selects the external event used to trigger the conversion start of regular group.
  84. If set to ADC_SOFTWARE_START, external triggers are disabled.
  85. This parameter can be a value of @ref ADC_External_trigger_source_Regular */
  86. uint32_t ExternalTrigConvEdge; /*!< Selects the external trigger edge of regular group.
  87. If trigger is set to ADC_SOFTWARE_START, this parameter is discarded.
  88. This parameter can be a value of @ref ADC_External_trigger_edge_Regular */
  89. FunctionalState DMAContinuousRequests; /*!< Specifies whether the DMA requests are performed in one shot mode (DMA transfer stop when number of conversions is reached)
  90. or in Continuous mode (DMA transfer unlimited, whatever number of conversions).
  91. Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached.
  92. This parameter can be set to ENABLE or DISABLE. */
  93. uint32_t Overrun; /*!< Select the behaviour in case of overrun: data preserved or overwritten
  94. This parameter has an effect on regular group only, including in DMA mode.
  95. This parameter can be a value of @ref ADC_Overrun */
  96. uint32_t SamplingTimeCommon; /*!< Sampling time value to be set for the selected channel.
  97. Unit: ADC clock cycles
  98. Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits, 10.5 cycles at 10 bits, 8.5 cycles at 8 bits, 6.5 cycles at 6 bits).
  99. Note: On STM32F0 devices, the sampling time setting is common to all channels. On some other STM32 devices, this parameter in channel wise and is located into ADC channel initialization structure.
  100. This parameter can be a value of @ref ADC_sampling_times
  101. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
  102. sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
  103. Refer to device datasheet for timings values, parameters TS_vrefint, TS_vbat, TS_temp (values rough order: 5us to 17us). */
  104. }ADC_InitTypeDef;
  105. /**
  106. * @brief Structure definition of ADC channel for regular group
  107. * @note The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned to ADC state.
  108. * ADC state can be either:
  109. * - For all parameters: ADC disabled or enabled without conversion on going on regular group.
  110. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  111. * without error reporting (as it can be the expected behaviour in case of intended action to update another parameter (which fulfills the ADC state condition) on the fly).
  112. */
  113. typedef struct
  114. {
  115. uint32_t Channel; /*!< Specifies the channel to configure into ADC regular group.
  116. This parameter can be a value of @ref ADC_channels
  117. Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability. */
  118. uint32_t Rank; /*!< Add or remove the channel from ADC regular group sequencer.
  119. On STM32F0 devices, number of ranks in the sequence is defined by number of channels enabled, rank of each channel is defined by channel number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...)..
  120. Despite the channel rank is fixed, this parameter allow an additional possibility: to remove the selected rank (selected channel) from sequencer.
  121. This parameter can be a value of @ref ADC_rank */
  122. uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel.
  123. Unit: ADC clock cycles
  124. Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits, 10.5 cycles at 10 bits, 8.5 cycles at 8 bits, 6.5 cycles at 6 bits).
  125. This parameter can be a value of @ref ADC_sampling_times
  126. Caution: this setting impacts the entire regular group. Therefore, call of HAL_ADC_ConfigChannel() to configure a channel can impact the configuration of other channels previously set.
  127. Caution: Obsolete parameter. Use parameter "SamplingTimeCommon" in ADC initialization structure.
  128. If parameter "SamplingTimeCommon" is set to a valid sampling time, parameter "SamplingTime" is discarded.
  129. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
  130. sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
  131. Refer to device datasheet for timings values, parameters TS_vrefint, TS_vbat, TS_temp (values rough order: 5us to 17us). */
  132. }ADC_ChannelConfTypeDef;
  133. /**
  134. * @brief Structure definition of ADC analog watchdog
  135. * @note The setting of these parameters with function HAL_ADC_AnalogWDGConfig() is conditioned to ADC state.
  136. * ADC state can be either: ADC disabled or ADC enabled without conversion on going on regular group.
  137. */
  138. typedef struct
  139. {
  140. uint32_t WatchdogMode; /*!< Configures the ADC analog watchdog mode: single/all/none channels.
  141. This parameter can be a value of @ref ADC_analog_watchdog_mode. */
  142. uint32_t Channel; /*!< Selects which ADC channel to monitor by analog watchdog.
  143. This parameter has an effect only if parameter 'WatchdogMode' is configured on single channel. Only 1 channel can be monitored.
  144. This parameter can be a value of @ref ADC_channels. */
  145. FunctionalState ITMode; /*!< Specifies whether the analog watchdog is configured in interrupt or polling mode.
  146. This parameter can be set to ENABLE or DISABLE */
  147. uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value.
  148. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
  149. uint32_t LowThreshold; /*!< Configures the ADC analog watchdog High threshold value.
  150. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
  151. }ADC_AnalogWDGConfTypeDef;
  152. /**
  153. * @brief HAL ADC state machine: ADC states definition (bitfields)
  154. * @note ADC state machine is managed by bitfields, state must be compared
  155. * with bit by bit.
  156. * For example:
  157. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
  158. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) "
  159. */
  160. /* States of ADC global scope */
  161. #define HAL_ADC_STATE_RESET (0x00000000U) /*!< ADC not yet initialized or disabled */
  162. #define HAL_ADC_STATE_READY (0x00000001U) /*!< ADC peripheral ready for use */
  163. #define HAL_ADC_STATE_BUSY_INTERNAL (0x00000002U) /*!< ADC is busy to internal process (initialization, calibration) */
  164. #define HAL_ADC_STATE_TIMEOUT (0x00000004U) /*!< TimeOut occurrence */
  165. /* States of ADC errors */
  166. #define HAL_ADC_STATE_ERROR_INTERNAL (0x00000010U) /*!< Internal error occurrence */
  167. #define HAL_ADC_STATE_ERROR_CONFIG (0x00000020U) /*!< Configuration error occurrence */
  168. #define HAL_ADC_STATE_ERROR_DMA (0x00000040U) /*!< DMA error occurrence */
  169. /* States of ADC group regular */
  170. #define HAL_ADC_STATE_REG_BUSY (0x00000100U) /*!< A conversion on group regular is ongoing or can occur (either by continuous mode,
  171. external trigger, low power auto power-on, multimode ADC master control) */
  172. #define HAL_ADC_STATE_REG_EOC (0x00000200U) /*!< Conversion data available on group regular */
  173. #define HAL_ADC_STATE_REG_OVR (0x00000400U) /*!< Overrun occurrence */
  174. #define HAL_ADC_STATE_REG_EOSMP (0x00000800U) /*!< Not available on STM32F0 device: End Of Sampling flag raised */
  175. /* States of ADC group injected */
  176. #define HAL_ADC_STATE_INJ_BUSY (0x00001000U) /*!< Not available on STM32F0 device: A conversion on group injected is ongoing or can occur (either by auto-injection mode,
  177. external trigger, low power auto power-on, multimode ADC master control) */
  178. #define HAL_ADC_STATE_INJ_EOC (0x00002000U) /*!< Not available on STM32F0 device: Conversion data available on group injected */
  179. #define HAL_ADC_STATE_INJ_JQOVF (0x00004000U) /*!< Not available on STM32F0 device: Not available on STM32F0 device: Injected queue overflow occurrence */
  180. /* States of ADC analog watchdogs */
  181. #define HAL_ADC_STATE_AWD1 (0x00010000U) /*!< Out-of-window occurrence of analog watchdog 1 */
  182. #define HAL_ADC_STATE_AWD2 (0x00020000U) /*!< Not available on STM32F0 device: Out-of-window occurrence of analog watchdog 2 */
  183. #define HAL_ADC_STATE_AWD3 (0x00040000U) /*!< Not available on STM32F0 device: Out-of-window occurrence of analog watchdog 3 */
  184. /* States of ADC multi-mode */
  185. #define HAL_ADC_STATE_MULTIMODE_SLAVE (0x00100000U) /*!< Not available on STM32F0 device: ADC in multimode slave state, controlled by another ADC master ( */
  186. /**
  187. * @brief ADC handle Structure definition
  188. */
  189. typedef struct __ADC_HandleTypeDef
  190. {
  191. ADC_TypeDef *Instance; /*!< Register base address */
  192. ADC_InitTypeDef Init; /*!< ADC required parameters */
  193. DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
  194. HAL_LockTypeDef Lock; /*!< ADC locking object */
  195. __IO uint32_t State; /*!< ADC communication state (bitmap of ADC states) */
  196. __IO uint32_t ErrorCode; /*!< ADC Error code */
  197. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  198. void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion complete callback */
  199. void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion DMA half-transfer callback */
  200. void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 1 callback */
  201. void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC error callback */
  202. void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp Init callback */
  203. void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp DeInit callback */
  204. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  205. }ADC_HandleTypeDef;
  206. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  207. /**
  208. * @brief HAL ADC Callback ID enumeration definition
  209. */
  210. typedef enum
  211. {
  212. HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U, /*!< ADC conversion complete callback ID */
  213. HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U, /*!< ADC conversion DMA half-transfer callback ID */
  214. HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U, /*!< ADC analog watchdog 1 callback ID */
  215. HAL_ADC_ERROR_CB_ID = 0x03U, /*!< ADC error callback ID */
  216. HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U, /*!< ADC group injected conversion complete callback ID */
  217. HAL_ADC_MSPINIT_CB_ID = 0x09U, /*!< ADC Msp Init callback ID */
  218. HAL_ADC_MSPDEINIT_CB_ID = 0x0AU /*!< ADC Msp DeInit callback ID */
  219. } HAL_ADC_CallbackIDTypeDef;
  220. /**
  221. * @brief HAL ADC Callback pointer definition
  222. */
  223. typedef void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
  224. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  225. /**
  226. * @}
  227. */
  228. /* Exported constants --------------------------------------------------------*/
  229. /** @defgroup ADC_Exported_Constants ADC Exported Constants
  230. * @{
  231. */
  232. /** @defgroup ADC_Error_Code ADC Error Code
  233. * @{
  234. */
  235. #define HAL_ADC_ERROR_NONE (0x00U) /*!< No error */
  236. #define HAL_ADC_ERROR_INTERNAL (0x01U) /*!< ADC IP internal error: if problem of clocking,
  237. enable/disable, erroneous state */
  238. #define HAL_ADC_ERROR_OVR (0x02U) /*!< Overrun error */
  239. #define HAL_ADC_ERROR_DMA (0x04U) /*!< DMA transfer error */
  240. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  241. #define HAL_ADC_ERROR_INVALID_CALLBACK (0x10U) /*!< Invalid Callback error */
  242. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  243. /**
  244. * @}
  245. */
  246. /** @defgroup ADC_ClockPrescaler ADC ClockPrescaler
  247. * @{
  248. */
  249. #define ADC_CLOCK_ASYNC_DIV1 (0x00000000U) /*!< ADC asynchronous clock derived from ADC dedicated HSI */
  250. #define ADC_CLOCK_SYNC_PCLK_DIV2 ((uint32_t)ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock divided by a prescaler of 2 */
  251. #define ADC_CLOCK_SYNC_PCLK_DIV4 ((uint32_t)ADC_CFGR2_CKMODE_1) /*!< ADC synchronous clock derived from AHB clock divided by a prescaler of 4 */
  252. /**
  253. * @}
  254. */
  255. /** @defgroup ADC_Resolution ADC Resolution
  256. * @{
  257. */
  258. #define ADC_RESOLUTION_12B (0x00000000U) /*!< ADC 12-bit resolution */
  259. #define ADC_RESOLUTION_10B ((uint32_t)ADC_CFGR1_RES_0) /*!< ADC 10-bit resolution */
  260. #define ADC_RESOLUTION_8B ((uint32_t)ADC_CFGR1_RES_1) /*!< ADC 8-bit resolution */
  261. #define ADC_RESOLUTION_6B ((uint32_t)ADC_CFGR1_RES) /*!< ADC 6-bit resolution */
  262. /**
  263. * @}
  264. */
  265. /** @defgroup ADC_Data_align ADC Data_align
  266. * @{
  267. */
  268. #define ADC_DATAALIGN_RIGHT (0x00000000U)
  269. #define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CFGR1_ALIGN)
  270. /**
  271. * @}
  272. */
  273. /** @defgroup ADC_Scan_mode ADC Scan mode
  274. * @{
  275. */
  276. /* Note: Scan mode values must be compatible with other STM32 devices having */
  277. /* a configurable sequencer. */
  278. /* Scan direction setting values are defined by taking in account */
  279. /* already defined values for other STM32 devices: */
  280. /* ADC_SCAN_DISABLE (0x00000000U) */
  281. /* ADC_SCAN_ENABLE (0x00000001U) */
  282. /* Scan direction forward is considered as default setting equivalent */
  283. /* to scan enable. */
  284. /* Scan direction backward is considered as additional setting. */
  285. /* In case of migration from another STM32 device, the user will be */
  286. /* warned of change of setting choices with assert check. */
  287. #define ADC_SCAN_DIRECTION_FORWARD (0x00000001U) /*!< Scan direction forward: from channel 0 to channel 18 */
  288. #define ADC_SCAN_DIRECTION_BACKWARD (0x00000002U) /*!< Scan direction backward: from channel 18 to channel 0 */
  289. #define ADC_SCAN_ENABLE ADC_SCAN_DIRECTION_FORWARD /* For compatibility with other STM32 devices */
  290. /**
  291. * @}
  292. */
  293. /** @defgroup ADC_External_trigger_edge_Regular ADC External trigger edge Regular
  294. * @{
  295. */
  296. #define ADC_EXTERNALTRIGCONVEDGE_NONE (0x00000000U)
  297. #define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CFGR1_EXTEN_0)
  298. #define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CFGR1_EXTEN_1)
  299. #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CFGR1_EXTEN)
  300. /**
  301. * @}
  302. */
  303. /** @defgroup ADC_EOCSelection ADC EOCSelection
  304. * @{
  305. */
  306. #define ADC_EOC_SINGLE_CONV ((uint32_t) ADC_ISR_EOC)
  307. #define ADC_EOC_SEQ_CONV ((uint32_t) ADC_ISR_EOS)
  308. /**
  309. * @}
  310. */
  311. /** @defgroup ADC_Overrun ADC Overrun
  312. * @{
  313. */
  314. #define ADC_OVR_DATA_OVERWRITTEN (0x00000000U)
  315. #define ADC_OVR_DATA_PRESERVED (0x00000001U)
  316. /**
  317. * @}
  318. */
  319. /** @defgroup ADC_rank ADC rank
  320. * @{
  321. */
  322. #define ADC_RANK_CHANNEL_NUMBER (0x00001000U) /*!< Enable the rank of the selected channels. Number of ranks in the sequence is defined by number of channels enabled, rank of each channel is defined by channel number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...) */
  323. #define ADC_RANK_NONE (0x00001001U) /*!< Disable the selected rank (selected channel) from sequencer */
  324. /**
  325. * @}
  326. */
  327. /** @defgroup ADC_sampling_times ADC sampling times
  328. * @{
  329. */
  330. /* Note: Parameter "ADC_SAMPLETIME_1CYCLE_5" defined with a dummy bit */
  331. /* to distinguish this parameter versus reset value 0x00000000, */
  332. /* in the context of management of parameters "SamplingTimeCommon" */
  333. /* and "SamplingTime" (obsolete)). */
  334. #define ADC_SAMPLETIME_1CYCLE_5 (0x10000000U) /*!< Sampling time 1.5 ADC clock cycle */
  335. #define ADC_SAMPLETIME_7CYCLES_5 ((uint32_t) ADC_SMPR_SMP_0) /*!< Sampling time 7.5 ADC clock cycles */
  336. #define ADC_SAMPLETIME_13CYCLES_5 ((uint32_t) ADC_SMPR_SMP_1) /*!< Sampling time 13.5 ADC clock cycles */
  337. #define ADC_SAMPLETIME_28CYCLES_5 ((uint32_t)(ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0)) /*!< Sampling time 28.5 ADC clock cycles */
  338. #define ADC_SAMPLETIME_41CYCLES_5 ((uint32_t) ADC_SMPR_SMP_2) /*!< Sampling time 41.5 ADC clock cycles */
  339. #define ADC_SAMPLETIME_55CYCLES_5 ((uint32_t)(ADC_SMPR_SMP_2 | ADC_SMPR_SMP_0)) /*!< Sampling time 55.5 ADC clock cycles */
  340. #define ADC_SAMPLETIME_71CYCLES_5 ((uint32_t)(ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1)) /*!< Sampling time 71.5 ADC clock cycles */
  341. #define ADC_SAMPLETIME_239CYCLES_5 ((uint32_t) ADC_SMPR_SMP) /*!< Sampling time 239.5 ADC clock cycles */
  342. /**
  343. * @}
  344. */
  345. /** @defgroup ADC_analog_watchdog_mode ADC analog watchdog mode
  346. * @{
  347. */
  348. #define ADC_ANALOGWATCHDOG_NONE ( 0x00000000U)
  349. #define ADC_ANALOGWATCHDOG_SINGLE_REG ((uint32_t)(ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN))
  350. #define ADC_ANALOGWATCHDOG_ALL_REG ((uint32_t) ADC_CFGR1_AWDEN)
  351. /**
  352. * @}
  353. */
  354. /** @defgroup ADC_Event_type ADC Event type
  355. * @{
  356. */
  357. #define ADC_AWD_EVENT ((uint32_t)ADC_FLAG_AWD) /*!< ADC Analog watchdog 1 event */
  358. #define ADC_OVR_EVENT ((uint32_t)ADC_FLAG_OVR) /*!< ADC overrun event */
  359. /**
  360. * @}
  361. */
  362. /** @defgroup ADC_interrupts_definition ADC interrupts definition
  363. * @{
  364. */
  365. #define ADC_IT_AWD ADC_IER_AWDIE /*!< ADC Analog watchdog interrupt source */
  366. #define ADC_IT_OVR ADC_IER_OVRIE /*!< ADC overrun interrupt source */
  367. #define ADC_IT_EOS ADC_IER_EOSEQIE /*!< ADC End of Regular sequence of Conversions interrupt source */
  368. #define ADC_IT_EOC ADC_IER_EOCIE /*!< ADC End of Regular Conversion interrupt source */
  369. #define ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC End of Sampling interrupt source */
  370. #define ADC_IT_RDY ADC_IER_ADRDYIE /*!< ADC Ready interrupt source */
  371. /**
  372. * @}
  373. */
  374. /** @defgroup ADC_flags_definition ADC flags definition
  375. * @{
  376. */
  377. #define ADC_FLAG_AWD ADC_ISR_AWD /*!< ADC Analog watchdog flag */
  378. #define ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC overrun flag */
  379. #define ADC_FLAG_EOS ADC_ISR_EOSEQ /*!< ADC End of Regular sequence of Conversions flag */
  380. #define ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC End of Regular Conversion flag */
  381. #define ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC End of Sampling flag */
  382. #define ADC_FLAG_RDY ADC_ISR_ADRDY /*!< ADC Ready flag */
  383. /**
  384. * @}
  385. */
  386. /**
  387. * @}
  388. */
  389. /* Private constants ---------------------------------------------------------*/
  390. /** @addtogroup ADC_Private_Constants ADC Private Constants
  391. * @{
  392. */
  393. /** @defgroup ADC_Internal_HAL_driver_Ext_trig_src_Regular ADC Internal HAL driver Ext trig src Regular
  394. * @{
  395. */
  396. /* List of external triggers of regular group for ADC1: */
  397. /* (used internally by HAL driver. To not use into HAL structure parameters) */
  398. #define ADC1_2_EXTERNALTRIG_T1_TRGO (0x00000000U)
  399. #define ADC1_2_EXTERNALTRIG_T1_CC4 ((uint32_t)ADC_CFGR1_EXTSEL_0)
  400. #define ADC1_2_EXTERNALTRIG_T2_TRGO ((uint32_t)ADC_CFGR1_EXTSEL_1)
  401. #define ADC1_2_EXTERNALTRIG_T3_TRGO ((uint32_t)(ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_0))
  402. #define ADC1_2_EXTERNALTRIG_T15_TRGO ((uint32_t)ADC_CFGR1_EXTSEL_2)
  403. /**
  404. * @}
  405. */
  406. /* Combination of all post-conversion flags bits: EOC/EOS, OVR, AWD */
  407. #define ADC_FLAG_POSTCONV_ALL (ADC_FLAG_AWD | ADC_FLAG_OVR | ADC_FLAG_EOS | ADC_FLAG_EOC)
  408. /**
  409. * @}
  410. */
  411. /* Exported macro ------------------------------------------------------------*/
  412. /** @defgroup ADC_Exported_Macros ADC Exported Macros
  413. * @{
  414. */
  415. /* Macro for internal HAL driver usage, and possibly can be used into code of */
  416. /* final user. */
  417. /**
  418. * @brief Enable the ADC peripheral
  419. * @param __HANDLE__ ADC handle
  420. * @retval None
  421. */
  422. #define __HAL_ADC_ENABLE(__HANDLE__) \
  423. ((__HANDLE__)->Instance->CR |= ADC_CR_ADEN)
  424. /**
  425. * @brief Disable the ADC peripheral
  426. * @param __HANDLE__ ADC handle
  427. * @retval None
  428. */
  429. #define __HAL_ADC_DISABLE(__HANDLE__) \
  430. do{ \
  431. (__HANDLE__)->Instance->CR |= ADC_CR_ADDIS; \
  432. __HAL_ADC_CLEAR_FLAG((__HANDLE__), (ADC_FLAG_EOSMP | ADC_FLAG_RDY)); \
  433. } while(0)
  434. /**
  435. * @brief Enable the ADC end of conversion interrupt.
  436. * @param __HANDLE__ ADC handle
  437. * @param __INTERRUPT__ ADC Interrupt
  438. * This parameter can be any combination of the following values:
  439. * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
  440. * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
  441. * @arg ADC_IT_AWD: ADC Analog watchdog interrupt source
  442. * @arg ADC_IT_OVR: ADC overrun interrupt source
  443. * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
  444. * @arg ADC_IT_RDY: ADC Ready interrupt source
  445. * @retval None
  446. */
  447. #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
  448. (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
  449. /**
  450. * @brief Disable the ADC end of conversion interrupt.
  451. * @param __HANDLE__ ADC handle
  452. * @param __INTERRUPT__ ADC Interrupt
  453. * This parameter can be any combination of the following values:
  454. * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
  455. * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
  456. * @arg ADC_IT_AWD: ADC Analog watchdog interrupt source
  457. * @arg ADC_IT_OVR: ADC overrun interrupt source
  458. * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
  459. * @arg ADC_IT_RDY: ADC Ready interrupt source
  460. * @retval None
  461. */
  462. #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
  463. (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
  464. /** @brief Checks if the specified ADC interrupt source is enabled or disabled.
  465. * @param __HANDLE__ ADC handle
  466. * @param __INTERRUPT__ ADC interrupt source to check
  467. * This parameter can be any combination of the following values:
  468. * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
  469. * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
  470. * @arg ADC_IT_AWD: ADC Analog watchdog interrupt source
  471. * @arg ADC_IT_OVR: ADC overrun interrupt source
  472. * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
  473. * @arg ADC_IT_RDY: ADC Ready interrupt source
  474. * @retval State ofinterruption (SET or RESET)
  475. */
  476. #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
  477. (((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__))
  478. /**
  479. * @brief Get the selected ADC's flag status.
  480. * @param __HANDLE__ ADC handle
  481. * @param __FLAG__ ADC flag
  482. * This parameter can be any combination of the following values:
  483. * @arg ADC_FLAG_EOC: ADC End of Regular conversion flag
  484. * @arg ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
  485. * @arg ADC_FLAG_AWD: ADC Analog watchdog flag
  486. * @arg ADC_FLAG_OVR: ADC overrun flag
  487. * @arg ADC_FLAG_EOSMP: ADC End of Sampling flag
  488. * @arg ADC_FLAG_RDY: ADC Ready flag
  489. * @retval None
  490. */
  491. #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) \
  492. ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
  493. /**
  494. * @brief Clear the ADC's pending flags
  495. * @param __HANDLE__ ADC handle
  496. * @param __FLAG__ ADC flag
  497. * This parameter can be any combination of the following values:
  498. * @arg ADC_FLAG_EOC: ADC End of Regular conversion flag
  499. * @arg ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
  500. * @arg ADC_FLAG_AWD: ADC Analog watchdog flag
  501. * @arg ADC_FLAG_OVR: ADC overrun flag
  502. * @arg ADC_FLAG_EOSMP: ADC End of Sampling flag
  503. * @arg ADC_FLAG_RDY: ADC Ready flag
  504. * @retval None
  505. */
  506. /* Note: bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR) */
  507. #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) \
  508. (((__HANDLE__)->Instance->ISR) = (__FLAG__))
  509. /** @brief Reset ADC handle state
  510. * @param __HANDLE__ ADC handle
  511. * @retval None
  512. */
  513. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  514. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  515. do{ \
  516. (__HANDLE__)->State = HAL_ADC_STATE_RESET; \
  517. (__HANDLE__)->MspInitCallback = NULL; \
  518. (__HANDLE__)->MspDeInitCallback = NULL; \
  519. } while(0)
  520. #else
  521. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  522. ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  523. #endif
  524. /**
  525. * @}
  526. */
  527. /* Private macro -------------------------------------------------------------*/
  528. /** @defgroup ADC_Private_Macros ADC Private Macros
  529. * @{
  530. */
  531. /* Macro reserved for internal HAL driver usage, not intended to be used in */
  532. /* code of final user. */
  533. /**
  534. * @brief Verification of hardware constraints before ADC can be enabled
  535. * @param __HANDLE__ ADC handle
  536. * @retval SET (ADC can be enabled) or RESET (ADC cannot be enabled)
  537. */
  538. #define ADC_ENABLING_CONDITIONS(__HANDLE__) \
  539. (( ( ((__HANDLE__)->Instance->CR) & \
  540. (ADC_CR_ADCAL | ADC_CR_ADSTP | ADC_CR_ADSTART | ADC_CR_ADDIS | ADC_CR_ADEN) \
  541. ) == RESET \
  542. ) ? SET : RESET)
  543. /**
  544. * @brief Verification of hardware constraints before ADC can be disabled
  545. * @param __HANDLE__ ADC handle
  546. * @retval SET (ADC can be disabled) or RESET (ADC cannot be disabled)
  547. */
  548. #define ADC_DISABLING_CONDITIONS(__HANDLE__) \
  549. (( ( ((__HANDLE__)->Instance->CR) & \
  550. (ADC_CR_ADSTART | ADC_CR_ADEN)) == ADC_CR_ADEN \
  551. ) ? SET : RESET)
  552. /**
  553. * @brief Verification of ADC state: enabled or disabled
  554. * @param __HANDLE__ ADC handle
  555. * @retval SET (ADC enabled) or RESET (ADC disabled)
  556. */
  557. /* Note: If low power mode AutoPowerOff is enabled, power-on/off phases are */
  558. /* performed automatically by hardware and flag ADC_FLAG_RDY is not */
  559. /* set. */
  560. #define ADC_IS_ENABLE(__HANDLE__) \
  561. (( ((((__HANDLE__)->Instance->CR) & (ADC_CR_ADEN | ADC_CR_ADDIS)) == ADC_CR_ADEN) && \
  562. (((((__HANDLE__)->Instance->ISR) & ADC_FLAG_RDY) == ADC_FLAG_RDY) || \
  563. ((((__HANDLE__)->Instance->CFGR1) & ADC_CFGR1_AUTOFF) == ADC_CFGR1_AUTOFF) ) \
  564. ) ? SET : RESET)
  565. /**
  566. * @brief Test if conversion trigger of regular group is software start
  567. * or external trigger.
  568. * @param __HANDLE__ ADC handle
  569. * @retval SET (software start) or RESET (external trigger)
  570. */
  571. #define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__) \
  572. (((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_EXTEN) == RESET)
  573. /**
  574. * @brief Check if no conversion on going on regular group
  575. * @param __HANDLE__ ADC handle
  576. * @retval SET (conversion is on going) or RESET (no conversion is on going)
  577. */
  578. #define ADC_IS_CONVERSION_ONGOING_REGULAR(__HANDLE__) \
  579. (( (((__HANDLE__)->Instance->CR) & ADC_CR_ADSTART) == RESET \
  580. ) ? RESET : SET)
  581. /**
  582. * @brief Returns resolution bits in CFGR1 register: RES[1:0].
  583. * Returned value is among parameters to @ref ADC_Resolution.
  584. * @param __HANDLE__ ADC handle
  585. * @retval None
  586. */
  587. #define ADC_GET_RESOLUTION(__HANDLE__) \
  588. (((__HANDLE__)->Instance->CFGR1) & ADC_CFGR1_RES)
  589. /**
  590. * @brief Returns ADC sample time bits in SMPR register: SMP[2:0].
  591. * Returned value is among parameters to @ref ADC_Resolution.
  592. * @param __HANDLE__ ADC handle
  593. * @retval None
  594. */
  595. #define ADC_GET_SAMPLINGTIME(__HANDLE__) \
  596. (((__HANDLE__)->Instance->SMPR) & ADC_SMPR_SMP)
  597. /**
  598. * @brief Simultaneously clears and sets specific bits of the handle State
  599. * @note: ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
  600. * the first parameter is the ADC handle State, the second parameter is the
  601. * bit field to clear, the third and last parameter is the bit field to set.
  602. * @retval None
  603. */
  604. #define ADC_STATE_CLR_SET MODIFY_REG
  605. /**
  606. * @brief Clear ADC error code (set it to error code: "no error")
  607. * @param __HANDLE__ ADC handle
  608. * @retval None
  609. */
  610. #define ADC_CLEAR_ERRORCODE(__HANDLE__) \
  611. ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
  612. /**
  613. * @brief Configure the channel number into channel selection register
  614. * @param _CHANNEL_ ADC Channel
  615. * @retval None
  616. */
  617. /* This function converts ADC channels from numbers (see defgroup ADC_channels)
  618. to bitfields, to get the equivalence of CMSIS channels:
  619. ADC_CHANNEL_0 ((uint32_t) ADC_CHSELR_CHSEL0)
  620. ADC_CHANNEL_1 ((uint32_t) ADC_CHSELR_CHSEL1)
  621. ADC_CHANNEL_2 ((uint32_t) ADC_CHSELR_CHSEL2)
  622. ADC_CHANNEL_3 ((uint32_t) ADC_CHSELR_CHSEL3)
  623. ADC_CHANNEL_4 ((uint32_t) ADC_CHSELR_CHSEL4)
  624. ADC_CHANNEL_5 ((uint32_t) ADC_CHSELR_CHSEL5)
  625. ADC_CHANNEL_6 ((uint32_t) ADC_CHSELR_CHSEL6)
  626. ADC_CHANNEL_7 ((uint32_t) ADC_CHSELR_CHSEL7)
  627. ADC_CHANNEL_8 ((uint32_t) ADC_CHSELR_CHSEL8)
  628. ADC_CHANNEL_9 ((uint32_t) ADC_CHSELR_CHSEL9)
  629. ADC_CHANNEL_10 ((uint32_t) ADC_CHSELR_CHSEL10)
  630. ADC_CHANNEL_11 ((uint32_t) ADC_CHSELR_CHSEL11)
  631. ADC_CHANNEL_12 ((uint32_t) ADC_CHSELR_CHSEL12)
  632. ADC_CHANNEL_13 ((uint32_t) ADC_CHSELR_CHSEL13)
  633. ADC_CHANNEL_14 ((uint32_t) ADC_CHSELR_CHSEL14)
  634. ADC_CHANNEL_15 ((uint32_t) ADC_CHSELR_CHSEL15)
  635. ADC_CHANNEL_16 ((uint32_t) ADC_CHSELR_CHSEL16)
  636. ADC_CHANNEL_17 ((uint32_t) ADC_CHSELR_CHSEL17)
  637. ADC_CHANNEL_18 ((uint32_t) ADC_CHSELR_CHSEL18)
  638. */
  639. #define ADC_CHSELR_CHANNEL(_CHANNEL_) \
  640. ( 1U << (_CHANNEL_))
  641. /**
  642. * @brief Set the ADC's sample time
  643. * @param _SAMPLETIME_ Sample time parameter.
  644. * @retval None
  645. */
  646. /* Note: ADC sampling time set using mask ADC_SMPR_SMP due to parameter */
  647. /* "ADC_SAMPLETIME_1CYCLE_5" defined with a dummy bit (bit used to */
  648. /* distinguish this parameter versus reset value 0x00000000, */
  649. /* in the context of management of parameters "SamplingTimeCommon" */
  650. /* and "SamplingTime" (obsolete)). */
  651. #define ADC_SMPR_SET(_SAMPLETIME_) \
  652. ((_SAMPLETIME_) & (ADC_SMPR_SMP))
  653. /**
  654. * @brief Set the Analog Watchdog 1 channel.
  655. * @param _CHANNEL_ channel to be monitored by Analog Watchdog 1.
  656. * @retval None
  657. */
  658. #define ADC_CFGR_AWDCH(_CHANNEL_) \
  659. ((_CHANNEL_) << 26U)
  660. /**
  661. * @brief Enable ADC discontinuous conversion mode for regular group
  662. * @param _REG_DISCONTINUOUS_MODE_ Regular discontinuous mode.
  663. * @retval None
  664. */
  665. #define ADC_CFGR1_REG_DISCCONTINUOUS(_REG_DISCONTINUOUS_MODE_) \
  666. ((_REG_DISCONTINUOUS_MODE_) << 16U)
  667. /**
  668. * @brief Enable the ADC auto off mode.
  669. * @param _AUTOOFF_ Auto off bit enable or disable.
  670. * @retval None
  671. */
  672. #define ADC_CFGR1_AUTOOFF(_AUTOOFF_) \
  673. ((_AUTOOFF_) << 15U)
  674. /**
  675. * @brief Enable the ADC auto delay mode.
  676. * @param _AUTOWAIT_ Auto delay bit enable or disable.
  677. * @retval None
  678. */
  679. #define ADC_CFGR1_AUTOWAIT(_AUTOWAIT_) \
  680. ((_AUTOWAIT_) << 14U)
  681. /**
  682. * @brief Enable ADC continuous conversion mode.
  683. * @param _CONTINUOUS_MODE_ Continuous mode.
  684. * @retval None
  685. */
  686. #define ADC_CFGR1_CONTINUOUS(_CONTINUOUS_MODE_) \
  687. ((_CONTINUOUS_MODE_) << 13U)
  688. /**
  689. * @brief Enable ADC overrun mode.
  690. * @param _OVERRUN_MODE_ Overrun mode.
  691. * @retval Overrun bit setting to be programmed into CFGR register
  692. */
  693. /* Note: Bit ADC_CFGR1_OVRMOD not used directly in constant */
  694. /* "ADC_OVR_DATA_OVERWRITTEN" to have this case defined to 0x00, to set it */
  695. /* as the default case to be compliant with other STM32 devices. */
  696. #define ADC_CFGR1_OVERRUN(_OVERRUN_MODE_) \
  697. ( ( (_OVERRUN_MODE_) != (ADC_OVR_DATA_PRESERVED) \
  698. )? (ADC_CFGR1_OVRMOD) : (0x00000000) \
  699. )
  700. /**
  701. * @brief Enable ADC scan mode to convert multiple ranks with sequencer.
  702. * @param _SCAN_MODE_ Scan conversion mode.
  703. * @retval None
  704. */
  705. /* Note: Scan mode set using this macro (instead of parameter direct set) */
  706. /* due to different modes on other STM32 devices: to avoid any */
  707. /* unwanted setting, the exact parameter corresponding to the device */
  708. /* must be passed to this macro. */
  709. #define ADC_SCANDIR(_SCAN_MODE_) \
  710. ( ( (_SCAN_MODE_) == (ADC_SCAN_DIRECTION_BACKWARD) \
  711. )? (ADC_CFGR1_SCANDIR) : (0x00000000) \
  712. )
  713. /**
  714. * @brief Enable the ADC DMA continuous request.
  715. * @param _DMACONTREQ_MODE_ DMA continuous request mode.
  716. * @retval None
  717. */
  718. #define ADC_CFGR1_DMACONTREQ(_DMACONTREQ_MODE_) \
  719. ((_DMACONTREQ_MODE_) << 1U)
  720. /**
  721. * @brief Configure the analog watchdog high threshold into register TR.
  722. * @param _Threshold_ Threshold value
  723. * @retval None
  724. */
  725. #define ADC_TRX_HIGHTHRESHOLD(_Threshold_) \
  726. ((_Threshold_) << 16U)
  727. /**
  728. * @brief Shift the AWD threshold in function of the selected ADC resolution.
  729. * Thresholds have to be left-aligned on bit 11, the LSB (right bits) are set to 0.
  730. * If resolution 12 bits, no shift.
  731. * If resolution 10 bits, shift of 2 ranks on the left.
  732. * If resolution 8 bits, shift of 4 ranks on the left.
  733. * If resolution 6 bits, shift of 6 ranks on the left.
  734. * therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2))
  735. * @param __HANDLE__ ADC handle
  736. * @param _Threshold_ Value to be shifted
  737. * @retval None
  738. */
  739. #define ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(__HANDLE__, _Threshold_) \
  740. ((_Threshold_) << ((((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_RES) >> 3U)*2))
  741. #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV1) || \
  742. ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
  743. ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) )
  744. #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_12B) || \
  745. ((RESOLUTION) == ADC_RESOLUTION_10B) || \
  746. ((RESOLUTION) == ADC_RESOLUTION_8B) || \
  747. ((RESOLUTION) == ADC_RESOLUTION_6B) )
  748. #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
  749. ((ALIGN) == ADC_DATAALIGN_LEFT) )
  750. #define IS_ADC_SCAN_MODE(SCAN_MODE) (((SCAN_MODE) == ADC_SCAN_DIRECTION_FORWARD) || \
  751. ((SCAN_MODE) == ADC_SCAN_DIRECTION_BACKWARD) )
  752. #define IS_ADC_EXTTRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
  753. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
  754. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
  755. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING) )
  756. #define IS_ADC_EOC_SELECTION(EOC_SELECTION) (((EOC_SELECTION) == ADC_EOC_SINGLE_CONV) || \
  757. ((EOC_SELECTION) == ADC_EOC_SEQ_CONV) )
  758. #define IS_ADC_OVERRUN(OVR) (((OVR) == ADC_OVR_DATA_PRESERVED) || \
  759. ((OVR) == ADC_OVR_DATA_OVERWRITTEN) )
  760. #define IS_ADC_RANK(WATCHDOG) (((WATCHDOG) == ADC_RANK_CHANNEL_NUMBER) || \
  761. ((WATCHDOG) == ADC_RANK_NONE) )
  762. #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_1CYCLE_5) || \
  763. ((TIME) == ADC_SAMPLETIME_7CYCLES_5) || \
  764. ((TIME) == ADC_SAMPLETIME_13CYCLES_5) || \
  765. ((TIME) == ADC_SAMPLETIME_28CYCLES_5) || \
  766. ((TIME) == ADC_SAMPLETIME_41CYCLES_5) || \
  767. ((TIME) == ADC_SAMPLETIME_55CYCLES_5) || \
  768. ((TIME) == ADC_SAMPLETIME_71CYCLES_5) || \
  769. ((TIME) == ADC_SAMPLETIME_239CYCLES_5) )
  770. #define IS_ADC_ANALOG_WATCHDOG_MODE(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE) || \
  771. ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \
  772. ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG) )
  773. #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == ADC_AWD_EVENT) || \
  774. ((EVENT) == ADC_OVR_EVENT) )
  775. /** @defgroup ADC_range_verification ADC range verification
  776. * in function of ADC resolution selected (12, 10, 8 or 6 bits)
  777. * @{
  778. */
  779. #define IS_ADC_RANGE(RESOLUTION, ADC_VALUE) \
  780. ((((RESOLUTION) == ADC_RESOLUTION_12B) && ((ADC_VALUE) <= (0x0FFFU))) || \
  781. (((RESOLUTION) == ADC_RESOLUTION_10B) && ((ADC_VALUE) <= (0x03FFU))) || \
  782. (((RESOLUTION) == ADC_RESOLUTION_8B) && ((ADC_VALUE) <= (0x00FFU))) || \
  783. (((RESOLUTION) == ADC_RESOLUTION_6B) && ((ADC_VALUE) <= (0x003FU))) )
  784. /**
  785. * @}
  786. */
  787. /** @defgroup ADC_regular_rank_verification ADC regular rank verification
  788. * @{
  789. */
  790. #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= (1U)) && ((RANK) <= (16U)))
  791. /**
  792. * @}
  793. */
  794. /**
  795. * @}
  796. */
  797. /* Include ADC HAL Extension module */
  798. #include "stm32f0xx_hal_adc_ex.h"
  799. /* Exported functions --------------------------------------------------------*/
  800. /** @addtogroup ADC_Exported_Functions
  801. * @{
  802. */
  803. /** @addtogroup ADC_Exported_Functions_Group1
  804. * @{
  805. */
  806. /* Initialization and de-initialization functions **********************************/
  807. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
  808. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  809. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
  810. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
  811. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  812. /* Callbacks Register/UnRegister functions ***********************************/
  813. HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback);
  814. HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
  815. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  816. /**
  817. * @}
  818. */
  819. /* IO operation functions *****************************************************/
  820. /** @addtogroup ADC_Exported_Functions_Group2
  821. * @{
  822. */
  823. /* Blocking mode: Polling */
  824. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
  825. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
  826. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  827. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
  828. /* Non-blocking mode: Interruption */
  829. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
  830. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
  831. /* Non-blocking mode: DMA */
  832. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
  833. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
  834. /* ADC retrieve conversion value intended to be used with polling or interruption */
  835. uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
  836. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
  837. void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
  838. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
  839. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
  840. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
  841. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  842. /**
  843. * @}
  844. */
  845. /* Peripheral Control functions ***********************************************/
  846. /** @addtogroup ADC_Exported_Functions_Group3
  847. * @{
  848. */
  849. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
  850. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
  851. /**
  852. * @}
  853. */
  854. /* Peripheral State functions *************************************************/
  855. /** @addtogroup ADC_Exported_Functions_Group4
  856. * @{
  857. */
  858. uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
  859. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
  860. /**
  861. * @}
  862. */
  863. /**
  864. * @}
  865. */
  866. /**
  867. * @}
  868. */
  869. /**
  870. * @}
  871. */
  872. #ifdef __cplusplus
  873. }
  874. #endif
  875. #endif /* STM32F0xx_HAL_ADC_H */