You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32f4xx_hal_adc.h 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file containing functions prototypes of ADC HAL library.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32F4xx_ADC_H
  21. #define __STM32F4xx_ADC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx_hal_def.h"
  27. /** @addtogroup STM32F4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup ADC
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup ADC_Exported_Types ADC Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief Structure definition of ADC and regular group initialization
  39. * @note Parameters of this structure are shared within 2 scopes:
  40. * - Scope entire ADC (affects regular and injected groups): ClockPrescaler, Resolution, ScanConvMode, DataAlign, ScanConvMode, EOCSelection, LowPowerAutoWait, LowPowerAutoPowerOff, ChannelsBank.
  41. * - Scope regular group: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, NbrOfDiscConversion, ExternalTrigConvEdge, ExternalTrigConv.
  42. * @note The setting of these parameters with function HAL_ADC_Init() is conditioned to ADC state.
  43. * ADC state can be either:
  44. * - For all parameters: ADC disabled
  45. * - For all parameters except 'Resolution', 'ScanConvMode', 'DiscontinuousConvMode', 'NbrOfDiscConversion' : ADC enabled without conversion on going on regular group.
  46. * - For parameters 'ExternalTrigConv' and 'ExternalTrigConvEdge': ADC enabled, even with conversion on going.
  47. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  48. * 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).
  49. */
  50. typedef struct
  51. {
  52. uint32_t ClockPrescaler; /*!< Select ADC clock prescaler. The clock is common for
  53. all the ADCs.
  54. This parameter can be a value of @ref ADC_ClockPrescaler */
  55. uint32_t Resolution; /*!< Configures the ADC resolution.
  56. This parameter can be a value of @ref ADC_Resolution */
  57. uint32_t DataAlign; /*!< Specifies ADC data alignment to right (MSB on register bit 11 and LSB on register bit 0) (default setting)
  58. or to left (if regular group: MSB on register bit 15 and LSB on register bit 4, if injected group (MSB kept as signed value due to potential negative value after offset application): MSB on register bit 14 and LSB on register bit 3).
  59. This parameter can be a value of @ref ADC_Data_align */
  60. uint32_t ScanConvMode; /*!< Configures the sequencer of regular and injected groups.
  61. This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
  62. If disabled: Conversion is performed in single mode (one channel converted, the one defined in rank 1).
  63. Parameters 'NbrOfConversion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1).
  64. If enabled: Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion'/'InjectedNbrOfConversion' and each channel rank).
  65. Scan direction is upward: from rank1 to rank 'n'.
  66. This parameter can be set to ENABLE or DISABLE */
  67. 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.
  68. This parameter can be a value of @ref ADC_EOCSelection.
  69. Note: For injected group, end of conversion (flag&IT) is raised only at the end of the sequence.
  70. Therefore, if end of conversion is set to end of each conversion, injected group should not be used with interruption (HAL_ADCEx_InjectedStart_IT)
  71. or polling (HAL_ADCEx_InjectedStart and HAL_ADCEx_InjectedPollForConversion). By the way, polling is still possible since driver will use an estimated timing for end of injected conversion.
  72. Note: If overrun feature is intended to be used, use ADC in mode 'interruption' (function HAL_ADC_Start_IT() ) with parameter EOCSelection set to end of each conversion or in mode 'transfer by DMA' (function HAL_ADC_Start_DMA()).
  73. If overrun feature is intended to be bypassed, use ADC in mode 'polling' or 'interruption' with parameter EOCSelection must be set to end of sequence */
  74. FunctionalState ContinuousConvMode; /*!< Specifies whether the conversion is performed in single mode (one conversion) or continuous mode for regular group,
  75. after the selected trigger occurred (software start or external trigger).
  76. This parameter can be set to ENABLE or DISABLE. */
  77. uint32_t NbrOfConversion; /*!< Specifies the number of ranks that will be converted within the regular group sequencer.
  78. To use regular group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
  79. This parameter must be a number between Min_Data = 1 and Max_Data = 16. */
  80. FunctionalState DiscontinuousConvMode; /*!< Specifies whether the conversions sequence of regular group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
  81. Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
  82. Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
  83. This parameter can be set to ENABLE or DISABLE. */
  84. uint32_t NbrOfDiscConversion; /*!< Specifies the number of discontinuous conversions in which the main sequence of regular group (parameter NbrOfConversion) will be subdivided.
  85. If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded.
  86. This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
  87. uint32_t ExternalTrigConv; /*!< Selects the external event used to trigger the conversion start of regular group.
  88. If set to ADC_SOFTWARE_START, external triggers are disabled.
  89. If set to external trigger source, triggering is on event rising edge by default.
  90. This parameter can be a value of @ref ADC_External_trigger_Source_Regular */
  91. uint32_t ExternalTrigConvEdge; /*!< Selects the external trigger edge of regular group.
  92. If trigger is set to ADC_SOFTWARE_START, this parameter is discarded.
  93. This parameter can be a value of @ref ADC_External_trigger_edge_Regular */
  94. FunctionalState DMAContinuousRequests; /*!< Specifies whether the DMA requests are performed in one shot mode (DMA transfer stop when number of conversions is reached)
  95. or in Continuous mode (DMA transfer unlimited, whatever number of conversions).
  96. Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached.
  97. Note: This parameter must be modified when no conversion is on going on both regular and injected groups (ADC disabled, or ADC enabled without continuous mode or external trigger that could launch a conversion).
  98. This parameter can be set to ENABLE or DISABLE. */
  99. }ADC_InitTypeDef;
  100. /**
  101. * @brief Structure definition of ADC channel for regular group
  102. * @note The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned to ADC state.
  103. * ADC can be either disabled or enabled without conversion on going on regular group.
  104. */
  105. typedef struct
  106. {
  107. uint32_t Channel; /*!< Specifies the channel to configure into ADC regular group.
  108. This parameter can be a value of @ref ADC_channels */
  109. uint32_t Rank; /*!< Specifies the rank in the regular group sequencer.
  110. This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
  111. uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel.
  112. Unit: ADC clock cycles
  113. Conversion time is the addition of sampling time and processing time (12 ADC clock cycles at ADC resolution 12 bits, 11 cycles at 10 bits, 9 cycles at 8 bits, 7 cycles at 6 bits).
  114. This parameter can be a value of @ref ADC_sampling_times
  115. Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups.
  116. If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting.
  117. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
  118. sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
  119. Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 4us min). */
  120. uint32_t Offset; /*!< Reserved for future use, can be set to 0 */
  121. }ADC_ChannelConfTypeDef;
  122. /**
  123. * @brief ADC Configuration multi-mode structure definition
  124. */
  125. typedef struct
  126. {
  127. uint32_t WatchdogMode; /*!< Configures the ADC analog watchdog mode.
  128. This parameter can be a value of @ref ADC_analog_watchdog_selection */
  129. uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value.
  130. This parameter must be a 12-bit value. */
  131. uint32_t LowThreshold; /*!< Configures the ADC analog watchdog High threshold value.
  132. This parameter must be a 12-bit value. */
  133. uint32_t Channel; /*!< Configures ADC channel for the analog watchdog.
  134. This parameter has an effect only if watchdog mode is configured on single channel
  135. This parameter can be a value of @ref ADC_channels */
  136. FunctionalState ITMode; /*!< Specifies whether the analog watchdog is configured
  137. is interrupt mode or in polling mode.
  138. This parameter can be set to ENABLE or DISABLE */
  139. uint32_t WatchdogNumber; /*!< Reserved for future use, can be set to 0 */
  140. }ADC_AnalogWDGConfTypeDef;
  141. /**
  142. * @brief HAL ADC state machine: ADC states definition (bitfields)
  143. */
  144. /* States of ADC global scope */
  145. #define HAL_ADC_STATE_RESET 0x00000000U /*!< ADC not yet initialized or disabled */
  146. #define HAL_ADC_STATE_READY 0x00000001U /*!< ADC peripheral ready for use */
  147. #define HAL_ADC_STATE_BUSY_INTERNAL 0x00000002U /*!< ADC is busy to internal process (initialization, calibration) */
  148. #define HAL_ADC_STATE_TIMEOUT 0x00000004U /*!< TimeOut occurrence */
  149. /* States of ADC errors */
  150. #define HAL_ADC_STATE_ERROR_INTERNAL 0x00000010U /*!< Internal error occurrence */
  151. #define HAL_ADC_STATE_ERROR_CONFIG 0x00000020U /*!< Configuration error occurrence */
  152. #define HAL_ADC_STATE_ERROR_DMA 0x00000040U /*!< DMA error occurrence */
  153. /* States of ADC group regular */
  154. #define HAL_ADC_STATE_REG_BUSY 0x00000100U /*!< A conversion on group regular is ongoing or can occur (either by continuous mode,
  155. external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
  156. #define HAL_ADC_STATE_REG_EOC 0x00000200U /*!< Conversion data available on group regular */
  157. #define HAL_ADC_STATE_REG_OVR 0x00000400U /*!< Overrun occurrence */
  158. /* States of ADC group injected */
  159. #define HAL_ADC_STATE_INJ_BUSY 0x00001000U /*!< A conversion on group injected is ongoing or can occur (either by auto-injection mode,
  160. external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
  161. #define HAL_ADC_STATE_INJ_EOC 0x00002000U /*!< Conversion data available on group injected */
  162. /* States of ADC analog watchdogs */
  163. #define HAL_ADC_STATE_AWD1 0x00010000U /*!< Out-of-window occurrence of analog watchdog 1 */
  164. #define HAL_ADC_STATE_AWD2 0x00020000U /*!< Not available on STM32F4 device: Out-of-window occurrence of analog watchdog 2 */
  165. #define HAL_ADC_STATE_AWD3 0x00040000U /*!< Not available on STM32F4 device: Out-of-window occurrence of analog watchdog 3 */
  166. /* States of ADC multi-mode */
  167. #define HAL_ADC_STATE_MULTIMODE_SLAVE 0x00100000U /*!< Not available on STM32F4 device: ADC in multimode slave state, controlled by another ADC master ( */
  168. /**
  169. * @brief ADC handle Structure definition
  170. */
  171. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  172. typedef struct __ADC_HandleTypeDef
  173. #else
  174. typedef struct
  175. #endif
  176. {
  177. ADC_TypeDef *Instance; /*!< Register base address */
  178. ADC_InitTypeDef Init; /*!< ADC required parameters */
  179. __IO uint32_t NbrOfCurrentConversionRank; /*!< ADC number of current conversion rank */
  180. DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
  181. HAL_LockTypeDef Lock; /*!< ADC locking object */
  182. __IO uint32_t State; /*!< ADC communication state */
  183. __IO uint32_t ErrorCode; /*!< ADC Error code */
  184. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  185. void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion complete callback */
  186. void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion DMA half-transfer callback */
  187. void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 1 callback */
  188. void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC error callback */
  189. void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC group injected conversion complete callback */
  190. void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp Init callback */
  191. void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp DeInit callback */
  192. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  193. }ADC_HandleTypeDef;
  194. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  195. /**
  196. * @brief HAL ADC Callback ID enumeration definition
  197. */
  198. typedef enum
  199. {
  200. HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U, /*!< ADC conversion complete callback ID */
  201. HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U, /*!< ADC conversion DMA half-transfer callback ID */
  202. HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U, /*!< ADC analog watchdog 1 callback ID */
  203. HAL_ADC_ERROR_CB_ID = 0x03U, /*!< ADC error callback ID */
  204. HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U, /*!< ADC group injected conversion complete callback ID */
  205. HAL_ADC_MSPINIT_CB_ID = 0x05U, /*!< ADC Msp Init callback ID */
  206. HAL_ADC_MSPDEINIT_CB_ID = 0x06U /*!< ADC Msp DeInit callback ID */
  207. } HAL_ADC_CallbackIDTypeDef;
  208. /**
  209. * @brief HAL ADC Callback pointer definition
  210. */
  211. typedef void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
  212. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  213. /**
  214. * @}
  215. */
  216. /* Exported constants --------------------------------------------------------*/
  217. /** @defgroup ADC_Exported_Constants ADC Exported Constants
  218. * @{
  219. */
  220. /** @defgroup ADC_Error_Code ADC Error Code
  221. * @{
  222. */
  223. #define HAL_ADC_ERROR_NONE 0x00U /*!< No error */
  224. #define HAL_ADC_ERROR_INTERNAL 0x01U /*!< ADC IP internal error: if problem of clocking,
  225. enable/disable, erroneous state */
  226. #define HAL_ADC_ERROR_OVR 0x02U /*!< Overrun error */
  227. #define HAL_ADC_ERROR_DMA 0x04U /*!< DMA transfer error */
  228. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  229. #define HAL_ADC_ERROR_INVALID_CALLBACK (0x10U) /*!< Invalid Callback error */
  230. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  231. /**
  232. * @}
  233. */
  234. /** @defgroup ADC_ClockPrescaler ADC Clock Prescaler
  235. * @{
  236. */
  237. #define ADC_CLOCK_SYNC_PCLK_DIV2 0x00000000U
  238. #define ADC_CLOCK_SYNC_PCLK_DIV4 ((uint32_t)ADC_CCR_ADCPRE_0)
  239. #define ADC_CLOCK_SYNC_PCLK_DIV6 ((uint32_t)ADC_CCR_ADCPRE_1)
  240. #define ADC_CLOCK_SYNC_PCLK_DIV8 ((uint32_t)ADC_CCR_ADCPRE)
  241. /**
  242. * @}
  243. */
  244. /** @defgroup ADC_delay_between_2_sampling_phases ADC Delay Between 2 Sampling Phases
  245. * @{
  246. */
  247. #define ADC_TWOSAMPLINGDELAY_5CYCLES 0x00000000U
  248. #define ADC_TWOSAMPLINGDELAY_6CYCLES ((uint32_t)ADC_CCR_DELAY_0)
  249. #define ADC_TWOSAMPLINGDELAY_7CYCLES ((uint32_t)ADC_CCR_DELAY_1)
  250. #define ADC_TWOSAMPLINGDELAY_8CYCLES ((uint32_t)(ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
  251. #define ADC_TWOSAMPLINGDELAY_9CYCLES ((uint32_t)ADC_CCR_DELAY_2)
  252. #define ADC_TWOSAMPLINGDELAY_10CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0))
  253. #define ADC_TWOSAMPLINGDELAY_11CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1))
  254. #define ADC_TWOSAMPLINGDELAY_12CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
  255. #define ADC_TWOSAMPLINGDELAY_13CYCLES ((uint32_t)ADC_CCR_DELAY_3)
  256. #define ADC_TWOSAMPLINGDELAY_14CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_0))
  257. #define ADC_TWOSAMPLINGDELAY_15CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1))
  258. #define ADC_TWOSAMPLINGDELAY_16CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
  259. #define ADC_TWOSAMPLINGDELAY_17CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2))
  260. #define ADC_TWOSAMPLINGDELAY_18CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0))
  261. #define ADC_TWOSAMPLINGDELAY_19CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1))
  262. #define ADC_TWOSAMPLINGDELAY_20CYCLES ((uint32_t)ADC_CCR_DELAY)
  263. /**
  264. * @}
  265. */
  266. /** @defgroup ADC_Resolution ADC Resolution
  267. * @{
  268. */
  269. #define ADC_RESOLUTION_12B 0x00000000U
  270. #define ADC_RESOLUTION_10B ((uint32_t)ADC_CR1_RES_0)
  271. #define ADC_RESOLUTION_8B ((uint32_t)ADC_CR1_RES_1)
  272. #define ADC_RESOLUTION_6B ((uint32_t)ADC_CR1_RES)
  273. /**
  274. * @}
  275. */
  276. /** @defgroup ADC_External_trigger_edge_Regular ADC External Trigger Edge Regular
  277. * @{
  278. */
  279. #define ADC_EXTERNALTRIGCONVEDGE_NONE 0x00000000U
  280. #define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CR2_EXTEN_0)
  281. #define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CR2_EXTEN_1)
  282. #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CR2_EXTEN)
  283. /**
  284. * @}
  285. */
  286. /** @defgroup ADC_External_trigger_Source_Regular ADC External Trigger Source Regular
  287. * @{
  288. */
  289. /* Note: Parameter ADC_SOFTWARE_START is a software parameter used for */
  290. /* compatibility with other STM32 devices. */
  291. #define ADC_EXTERNALTRIGCONV_T1_CC1 0x00000000U
  292. #define ADC_EXTERNALTRIGCONV_T1_CC2 ((uint32_t)ADC_CR2_EXTSEL_0)
  293. #define ADC_EXTERNALTRIGCONV_T1_CC3 ((uint32_t)ADC_CR2_EXTSEL_1)
  294. #define ADC_EXTERNALTRIGCONV_T2_CC2 ((uint32_t)(ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
  295. #define ADC_EXTERNALTRIGCONV_T2_CC3 ((uint32_t)ADC_CR2_EXTSEL_2)
  296. #define ADC_EXTERNALTRIGCONV_T2_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
  297. #define ADC_EXTERNALTRIGCONV_T2_TRGO ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))
  298. #define ADC_EXTERNALTRIGCONV_T3_CC1 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
  299. #define ADC_EXTERNALTRIGCONV_T3_TRGO ((uint32_t)ADC_CR2_EXTSEL_3)
  300. #define ADC_EXTERNALTRIGCONV_T4_CC4 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_0))
  301. #define ADC_EXTERNALTRIGCONV_T5_CC1 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1))
  302. #define ADC_EXTERNALTRIGCONV_T5_CC2 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
  303. #define ADC_EXTERNALTRIGCONV_T5_CC3 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2))
  304. #define ADC_EXTERNALTRIGCONV_T8_CC1 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
  305. #define ADC_EXTERNALTRIGCONV_T8_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))
  306. #define ADC_EXTERNALTRIGCONV_Ext_IT11 ((uint32_t)ADC_CR2_EXTSEL)
  307. #define ADC_SOFTWARE_START ((uint32_t)ADC_CR2_EXTSEL + 1U)
  308. /**
  309. * @}
  310. */
  311. /** @defgroup ADC_Data_align ADC Data Align
  312. * @{
  313. */
  314. #define ADC_DATAALIGN_RIGHT 0x00000000U
  315. #define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CR2_ALIGN)
  316. /**
  317. * @}
  318. */
  319. /** @defgroup ADC_channels ADC Common Channels
  320. * @{
  321. */
  322. #define ADC_CHANNEL_0 0x00000000U
  323. #define ADC_CHANNEL_1 ((uint32_t)ADC_CR1_AWDCH_0)
  324. #define ADC_CHANNEL_2 ((uint32_t)ADC_CR1_AWDCH_1)
  325. #define ADC_CHANNEL_3 ((uint32_t)(ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  326. #define ADC_CHANNEL_4 ((uint32_t)ADC_CR1_AWDCH_2)
  327. #define ADC_CHANNEL_5 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
  328. #define ADC_CHANNEL_6 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
  329. #define ADC_CHANNEL_7 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  330. #define ADC_CHANNEL_8 ((uint32_t)ADC_CR1_AWDCH_3)
  331. #define ADC_CHANNEL_9 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_0))
  332. #define ADC_CHANNEL_10 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1))
  333. #define ADC_CHANNEL_11 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  334. #define ADC_CHANNEL_12 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2))
  335. #define ADC_CHANNEL_13 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
  336. #define ADC_CHANNEL_14 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
  337. #define ADC_CHANNEL_15 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  338. #define ADC_CHANNEL_16 ((uint32_t)ADC_CR1_AWDCH_4)
  339. #define ADC_CHANNEL_17 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_0))
  340. #define ADC_CHANNEL_18 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_1))
  341. #define ADC_CHANNEL_VREFINT ((uint32_t)ADC_CHANNEL_17)
  342. #define ADC_CHANNEL_VBAT ((uint32_t)ADC_CHANNEL_18)
  343. /**
  344. * @}
  345. */
  346. /** @defgroup ADC_sampling_times ADC Sampling Times
  347. * @{
  348. */
  349. #define ADC_SAMPLETIME_3CYCLES 0x00000000U
  350. #define ADC_SAMPLETIME_15CYCLES ((uint32_t)ADC_SMPR1_SMP10_0)
  351. #define ADC_SAMPLETIME_28CYCLES ((uint32_t)ADC_SMPR1_SMP10_1)
  352. #define ADC_SAMPLETIME_56CYCLES ((uint32_t)(ADC_SMPR1_SMP10_1 | ADC_SMPR1_SMP10_0))
  353. #define ADC_SAMPLETIME_84CYCLES ((uint32_t)ADC_SMPR1_SMP10_2)
  354. #define ADC_SAMPLETIME_112CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_0))
  355. #define ADC_SAMPLETIME_144CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_1))
  356. #define ADC_SAMPLETIME_480CYCLES ((uint32_t)ADC_SMPR1_SMP10)
  357. /**
  358. * @}
  359. */
  360. /** @defgroup ADC_EOCSelection ADC EOC Selection
  361. * @{
  362. */
  363. #define ADC_EOC_SEQ_CONV 0x00000000U
  364. #define ADC_EOC_SINGLE_CONV 0x00000001U
  365. #define ADC_EOC_SINGLE_SEQ_CONV 0x00000002U /*!< reserved for future use */
  366. /**
  367. * @}
  368. */
  369. /** @defgroup ADC_Event_type ADC Event Type
  370. * @{
  371. */
  372. #define ADC_AWD_EVENT ((uint32_t)ADC_FLAG_AWD)
  373. #define ADC_OVR_EVENT ((uint32_t)ADC_FLAG_OVR)
  374. /**
  375. * @}
  376. */
  377. /** @defgroup ADC_analog_watchdog_selection ADC Analog Watchdog Selection
  378. * @{
  379. */
  380. #define ADC_ANALOGWATCHDOG_SINGLE_REG ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN))
  381. #define ADC_ANALOGWATCHDOG_SINGLE_INJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN))
  382. #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
  383. #define ADC_ANALOGWATCHDOG_ALL_REG ((uint32_t)ADC_CR1_AWDEN)
  384. #define ADC_ANALOGWATCHDOG_ALL_INJEC ((uint32_t)ADC_CR1_JAWDEN)
  385. #define ADC_ANALOGWATCHDOG_ALL_REGINJEC ((uint32_t)(ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
  386. #define ADC_ANALOGWATCHDOG_NONE 0x00000000U
  387. /**
  388. * @}
  389. */
  390. /** @defgroup ADC_interrupts_definition ADC Interrupts Definition
  391. * @{
  392. */
  393. #define ADC_IT_EOC ((uint32_t)ADC_CR1_EOCIE)
  394. #define ADC_IT_AWD ((uint32_t)ADC_CR1_AWDIE)
  395. #define ADC_IT_JEOC ((uint32_t)ADC_CR1_JEOCIE)
  396. #define ADC_IT_OVR ((uint32_t)ADC_CR1_OVRIE)
  397. /**
  398. * @}
  399. */
  400. /** @defgroup ADC_flags_definition ADC Flags Definition
  401. * @{
  402. */
  403. #define ADC_FLAG_AWD ((uint32_t)ADC_SR_AWD)
  404. #define ADC_FLAG_EOC ((uint32_t)ADC_SR_EOC)
  405. #define ADC_FLAG_JEOC ((uint32_t)ADC_SR_JEOC)
  406. #define ADC_FLAG_JSTRT ((uint32_t)ADC_SR_JSTRT)
  407. #define ADC_FLAG_STRT ((uint32_t)ADC_SR_STRT)
  408. #define ADC_FLAG_OVR ((uint32_t)ADC_SR_OVR)
  409. /**
  410. * @}
  411. */
  412. /** @defgroup ADC_channels_type ADC Channels Type
  413. * @{
  414. */
  415. #define ADC_ALL_CHANNELS 0x00000001U
  416. #define ADC_REGULAR_CHANNELS 0x00000002U /*!< reserved for future use */
  417. #define ADC_INJECTED_CHANNELS 0x00000003U /*!< reserved for future use */
  418. /**
  419. * @}
  420. */
  421. /**
  422. * @}
  423. */
  424. /* Exported macro ------------------------------------------------------------*/
  425. /** @defgroup ADC_Exported_Macros ADC Exported Macros
  426. * @{
  427. */
  428. /** @brief Reset ADC handle state
  429. * @param __HANDLE__ ADC handle
  430. * @retval None
  431. */
  432. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  433. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  434. do{ \
  435. (__HANDLE__)->State = HAL_ADC_STATE_RESET; \
  436. (__HANDLE__)->MspInitCallback = NULL; \
  437. (__HANDLE__)->MspDeInitCallback = NULL; \
  438. } while(0)
  439. #else
  440. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  441. ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  442. #endif
  443. /**
  444. * @brief Enable the ADC peripheral.
  445. * @param __HANDLE__ ADC handle
  446. * @retval None
  447. */
  448. #define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 |= ADC_CR2_ADON)
  449. /**
  450. * @brief Disable the ADC peripheral.
  451. * @param __HANDLE__ ADC handle
  452. * @retval None
  453. */
  454. #define __HAL_ADC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= ~ADC_CR2_ADON)
  455. /**
  456. * @brief Enable the ADC end of conversion interrupt.
  457. * @param __HANDLE__ specifies the ADC Handle.
  458. * @param __INTERRUPT__ ADC Interrupt.
  459. * @retval None
  460. */
  461. #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) |= (__INTERRUPT__))
  462. /**
  463. * @brief Disable the ADC end of conversion interrupt.
  464. * @param __HANDLE__ specifies the ADC Handle.
  465. * @param __INTERRUPT__ ADC interrupt.
  466. * @retval None
  467. */
  468. #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) &= ~(__INTERRUPT__))
  469. /** @brief Check if the specified ADC interrupt source is enabled or disabled.
  470. * @param __HANDLE__ specifies the ADC Handle.
  471. * @param __INTERRUPT__ specifies the ADC interrupt source to check.
  472. * @retval The new state of __IT__ (TRUE or FALSE).
  473. */
  474. #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__))
  475. /**
  476. * @brief Clear the ADC's pending flags.
  477. * @param __HANDLE__ specifies the ADC Handle.
  478. * @param __FLAG__ ADC flag.
  479. * @retval None
  480. */
  481. #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = ~(__FLAG__))
  482. /**
  483. * @brief Get the selected ADC's flag status.
  484. * @param __HANDLE__ specifies the ADC Handle.
  485. * @param __FLAG__ ADC flag.
  486. * @retval None
  487. */
  488. #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  489. /**
  490. * @}
  491. */
  492. /* Include ADC HAL Extension module */
  493. #include "stm32f4xx_hal_adc_ex.h"
  494. /* Exported functions --------------------------------------------------------*/
  495. /** @addtogroup ADC_Exported_Functions
  496. * @{
  497. */
  498. /** @addtogroup ADC_Exported_Functions_Group1
  499. * @{
  500. */
  501. /* Initialization/de-initialization functions ***********************************/
  502. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
  503. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  504. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
  505. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
  506. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  507. /* Callbacks Register/UnRegister functions ***********************************/
  508. HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback);
  509. HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
  510. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  511. /**
  512. * @}
  513. */
  514. /** @addtogroup ADC_Exported_Functions_Group2
  515. * @{
  516. */
  517. /* I/O operation functions ******************************************************/
  518. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
  519. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
  520. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  521. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
  522. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
  523. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
  524. void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
  525. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
  526. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
  527. uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
  528. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
  529. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
  530. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
  531. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  532. /**
  533. * @}
  534. */
  535. /** @addtogroup ADC_Exported_Functions_Group3
  536. * @{
  537. */
  538. /* Peripheral Control functions *************************************************/
  539. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
  540. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
  541. /**
  542. * @}
  543. */
  544. /** @addtogroup ADC_Exported_Functions_Group4
  545. * @{
  546. */
  547. /* Peripheral State functions ***************************************************/
  548. uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
  549. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
  550. /**
  551. * @}
  552. */
  553. /**
  554. * @}
  555. */
  556. /* Private types -------------------------------------------------------------*/
  557. /* Private variables ---------------------------------------------------------*/
  558. /* Private constants ---------------------------------------------------------*/
  559. /** @defgroup ADC_Private_Constants ADC Private Constants
  560. * @{
  561. */
  562. /* Delay for ADC stabilization time. */
  563. /* Maximum delay is 1us (refer to device datasheet, parameter tSTAB). */
  564. /* Unit: us */
  565. #define ADC_STAB_DELAY_US 3U
  566. /* Delay for temperature sensor stabilization time. */
  567. /* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */
  568. /* Unit: us */
  569. #define ADC_TEMPSENSOR_DELAY_US 10U
  570. /**
  571. * @}
  572. */
  573. /* Private macro ------------------------------------------------------------*/
  574. /** @defgroup ADC_Private_Macros ADC Private Macros
  575. * @{
  576. */
  577. /* Macro reserved for internal HAL driver usage, not intended to be used in
  578. code of final user */
  579. /**
  580. * @brief Verification of ADC state: enabled or disabled
  581. * @param __HANDLE__ ADC handle
  582. * @retval SET (ADC enabled) or RESET (ADC disabled)
  583. */
  584. #define ADC_IS_ENABLE(__HANDLE__) \
  585. ((( ((__HANDLE__)->Instance->SR & ADC_SR_ADONS) == ADC_SR_ADONS ) \
  586. ) ? SET : RESET)
  587. /**
  588. * @brief Test if conversion trigger of regular group is software start
  589. * or external trigger.
  590. * @param __HANDLE__ ADC handle
  591. * @retval SET (software start) or RESET (external trigger)
  592. */
  593. #define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__) \
  594. (((__HANDLE__)->Instance->CR2 & ADC_CR2_EXTEN) == RESET)
  595. /**
  596. * @brief Test if conversion trigger of injected group is software start
  597. * or external trigger.
  598. * @param __HANDLE__ ADC handle
  599. * @retval SET (software start) or RESET (external trigger)
  600. */
  601. #define ADC_IS_SOFTWARE_START_INJECTED(__HANDLE__) \
  602. (((__HANDLE__)->Instance->CR2 & ADC_CR2_JEXTEN) == RESET)
  603. /**
  604. * @brief Simultaneously clears and sets specific bits of the handle State
  605. * @note: ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
  606. * the first parameter is the ADC handle State, the second parameter is the
  607. * bit field to clear, the third and last parameter is the bit field to set.
  608. * @retval None
  609. */
  610. #define ADC_STATE_CLR_SET MODIFY_REG
  611. /**
  612. * @brief Clear ADC error code (set it to error code: "no error")
  613. * @param __HANDLE__ ADC handle
  614. * @retval None
  615. */
  616. #define ADC_CLEAR_ERRORCODE(__HANDLE__) \
  617. ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
  618. #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
  619. ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) || \
  620. ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV6) || \
  621. ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV8))
  622. #define IS_ADC_SAMPLING_DELAY(DELAY) (((DELAY) == ADC_TWOSAMPLINGDELAY_5CYCLES) || \
  623. ((DELAY) == ADC_TWOSAMPLINGDELAY_6CYCLES) || \
  624. ((DELAY) == ADC_TWOSAMPLINGDELAY_7CYCLES) || \
  625. ((DELAY) == ADC_TWOSAMPLINGDELAY_8CYCLES) || \
  626. ((DELAY) == ADC_TWOSAMPLINGDELAY_9CYCLES) || \
  627. ((DELAY) == ADC_TWOSAMPLINGDELAY_10CYCLES) || \
  628. ((DELAY) == ADC_TWOSAMPLINGDELAY_11CYCLES) || \
  629. ((DELAY) == ADC_TWOSAMPLINGDELAY_12CYCLES) || \
  630. ((DELAY) == ADC_TWOSAMPLINGDELAY_13CYCLES) || \
  631. ((DELAY) == ADC_TWOSAMPLINGDELAY_14CYCLES) || \
  632. ((DELAY) == ADC_TWOSAMPLINGDELAY_15CYCLES) || \
  633. ((DELAY) == ADC_TWOSAMPLINGDELAY_16CYCLES) || \
  634. ((DELAY) == ADC_TWOSAMPLINGDELAY_17CYCLES) || \
  635. ((DELAY) == ADC_TWOSAMPLINGDELAY_18CYCLES) || \
  636. ((DELAY) == ADC_TWOSAMPLINGDELAY_19CYCLES) || \
  637. ((DELAY) == ADC_TWOSAMPLINGDELAY_20CYCLES))
  638. #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_12B) || \
  639. ((RESOLUTION) == ADC_RESOLUTION_10B) || \
  640. ((RESOLUTION) == ADC_RESOLUTION_8B) || \
  641. ((RESOLUTION) == ADC_RESOLUTION_6B))
  642. #define IS_ADC_EXT_TRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
  643. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
  644. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
  645. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING))
  646. #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC1) || \
  647. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC2) || \
  648. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T1_CC3) || \
  649. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC2) || \
  650. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC3) || \
  651. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_CC4) || \
  652. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \
  653. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_CC1) || \
  654. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T3_TRGO) || \
  655. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T4_CC4) || \
  656. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC1) || \
  657. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC2) || \
  658. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T5_CC3) || \
  659. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_CC1) || \
  660. ((REGTRIG) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \
  661. ((REGTRIG) == ADC_EXTERNALTRIGCONV_Ext_IT11)|| \
  662. ((REGTRIG) == ADC_SOFTWARE_START))
  663. #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
  664. ((ALIGN) == ADC_DATAALIGN_LEFT))
  665. #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_3CYCLES) || \
  666. ((TIME) == ADC_SAMPLETIME_15CYCLES) || \
  667. ((TIME) == ADC_SAMPLETIME_28CYCLES) || \
  668. ((TIME) == ADC_SAMPLETIME_56CYCLES) || \
  669. ((TIME) == ADC_SAMPLETIME_84CYCLES) || \
  670. ((TIME) == ADC_SAMPLETIME_112CYCLES) || \
  671. ((TIME) == ADC_SAMPLETIME_144CYCLES) || \
  672. ((TIME) == ADC_SAMPLETIME_480CYCLES))
  673. #define IS_ADC_EOCSelection(EOCSelection) (((EOCSelection) == ADC_EOC_SINGLE_CONV) || \
  674. ((EOCSelection) == ADC_EOC_SEQ_CONV) || \
  675. ((EOCSelection) == ADC_EOC_SINGLE_SEQ_CONV))
  676. #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == ADC_AWD_EVENT) || \
  677. ((EVENT) == ADC_OVR_EVENT))
  678. #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \
  679. ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_INJEC) || \
  680. ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC) || \
  681. ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG) || \
  682. ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_INJEC) || \
  683. ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REGINJEC) || \
  684. ((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE))
  685. #define IS_ADC_CHANNELS_TYPE(CHANNEL_TYPE) (((CHANNEL_TYPE) == ADC_ALL_CHANNELS) || \
  686. ((CHANNEL_TYPE) == ADC_REGULAR_CHANNELS) || \
  687. ((CHANNEL_TYPE) == ADC_INJECTED_CHANNELS))
  688. #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFFU)
  689. #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 1U) && ((LENGTH) <= 16U))
  690. #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 1U) && ((RANK) <= (16U)))
  691. #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 1U) && ((NUMBER) <= 8U))
  692. #define IS_ADC_RANGE(RESOLUTION, ADC_VALUE) \
  693. ((((RESOLUTION) == ADC_RESOLUTION_12B) && ((ADC_VALUE) <= 0x0FFFU)) || \
  694. (((RESOLUTION) == ADC_RESOLUTION_10B) && ((ADC_VALUE) <= 0x03FFU)) || \
  695. (((RESOLUTION) == ADC_RESOLUTION_8B) && ((ADC_VALUE) <= 0x00FFU)) || \
  696. (((RESOLUTION) == ADC_RESOLUTION_6B) && ((ADC_VALUE) <= 0x003FU)))
  697. /**
  698. * @brief Set ADC Regular channel sequence length.
  699. * @param _NbrOfConversion_ Regular channel sequence length.
  700. * @retval None
  701. */
  702. #define ADC_SQR1(_NbrOfConversion_) (((_NbrOfConversion_) - (uint8_t)1U) << 20U)
  703. /**
  704. * @brief Set the ADC's sample time for channel numbers between 10 and 18.
  705. * @param _SAMPLETIME_ Sample time parameter.
  706. * @param _CHANNELNB_ Channel number.
  707. * @retval None
  708. */
  709. #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3U * (((uint32_t)((uint16_t)(_CHANNELNB_))) - 10U)))
  710. /**
  711. * @brief Set the ADC's sample time for channel numbers between 0 and 9.
  712. * @param _SAMPLETIME_ Sample time parameter.
  713. * @param _CHANNELNB_ Channel number.
  714. * @retval None
  715. */
  716. #define ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3U * ((uint32_t)((uint16_t)(_CHANNELNB_)))))
  717. /**
  718. * @brief Set the selected regular channel rank for rank between 1 and 6.
  719. * @param _CHANNELNB_ Channel number.
  720. * @param _RANKNB_ Rank number.
  721. * @retval None
  722. */
  723. #define ADC_SQR3_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 1U)))
  724. /**
  725. * @brief Set the selected regular channel rank for rank between 7 and 12.
  726. * @param _CHANNELNB_ Channel number.
  727. * @param _RANKNB_ Rank number.
  728. * @retval None
  729. */
  730. #define ADC_SQR2_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 7U)))
  731. /**
  732. * @brief Set the selected regular channel rank for rank between 13 and 16.
  733. * @param _CHANNELNB_ Channel number.
  734. * @param _RANKNB_ Rank number.
  735. * @retval None
  736. */
  737. #define ADC_SQR1_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5U * ((_RANKNB_) - 13U)))
  738. /**
  739. * @brief Enable ADC continuous conversion mode.
  740. * @param _CONTINUOUS_MODE_ Continuous mode.
  741. * @retval None
  742. */
  743. #define ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 1U)
  744. /**
  745. * @brief Configures the number of discontinuous conversions for the regular group channels.
  746. * @param _NBR_DISCONTINUOUSCONV_ Number of discontinuous conversions.
  747. * @retval None
  748. */
  749. #define ADC_CR1_DISCONTINUOUS(_NBR_DISCONTINUOUSCONV_) (((_NBR_DISCONTINUOUSCONV_) - 1U) << ADC_CR1_DISCNUM_Pos)
  750. /**
  751. * @brief Enable ADC scan mode.
  752. * @param _SCANCONV_MODE_ Scan conversion mode.
  753. * @retval None
  754. */
  755. #define ADC_CR1_SCANCONV(_SCANCONV_MODE_) ((_SCANCONV_MODE_) << 8U)
  756. /**
  757. * @brief Enable the ADC end of conversion selection.
  758. * @param _EOCSelection_MODE_ End of conversion selection mode.
  759. * @retval None
  760. */
  761. #define ADC_CR2_EOCSelection(_EOCSelection_MODE_) ((_EOCSelection_MODE_) << 10U)
  762. /**
  763. * @brief Enable the ADC DMA continuous request.
  764. * @param _DMAContReq_MODE_ DMA continuous request mode.
  765. * @retval None
  766. */
  767. #define ADC_CR2_DMAContReq(_DMAContReq_MODE_) ((_DMAContReq_MODE_) << 9U)
  768. /**
  769. * @brief Return resolution bits in CR1 register.
  770. * @param __HANDLE__ ADC handle
  771. * @retval None
  772. */
  773. #define ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CR1) & ADC_CR1_RES)
  774. /**
  775. * @}
  776. */
  777. /* Private functions ---------------------------------------------------------*/
  778. /** @defgroup ADC_Private_Functions ADC Private Functions
  779. * @{
  780. */
  781. /**
  782. * @}
  783. */
  784. /**
  785. * @}
  786. */
  787. /**
  788. * @}
  789. */
  790. #ifdef __cplusplus
  791. }
  792. #endif
  793. #endif /*__STM32F4xx_ADC_H */
  794. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/