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.
 
 
 

766 lines
35 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of ADC HAL extension module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_ADC_H
  39. #define __STM32F7xx_ADC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup ADC
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup ADC_Exported_Types ADC Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief HAL State structures definition
  57. */
  58. typedef enum
  59. {
  60. HAL_ADC_STATE_RESET = 0x00, /*!< ADC not yet initialized or disabled */
  61. HAL_ADC_STATE_READY = 0x01, /*!< ADC peripheral ready for use */
  62. HAL_ADC_STATE_BUSY = 0x02, /*!< An internal process is ongoing */
  63. HAL_ADC_STATE_BUSY_REG = 0x12, /*!< Regular conversion is ongoing */
  64. HAL_ADC_STATE_BUSY_INJ = 0x22, /*!< Injected conversion is ongoing */
  65. HAL_ADC_STATE_BUSY_INJ_REG = 0x32, /*!< Injected and regular conversion are ongoing */
  66. HAL_ADC_STATE_TIMEOUT = 0x03, /*!< Timeout state */
  67. HAL_ADC_STATE_ERROR = 0x04, /*!< ADC state error */
  68. HAL_ADC_STATE_EOC = 0x05, /*!< Conversion is completed */
  69. HAL_ADC_STATE_EOC_REG = 0x15, /*!< Regular conversion is completed */
  70. HAL_ADC_STATE_EOC_INJ = 0x25, /*!< Injected conversion is completed */
  71. HAL_ADC_STATE_EOC_INJ_REG = 0x35, /*!< Injected and regular conversion are completed */
  72. HAL_ADC_STATE_AWD = 0x06 /*!< ADC state analog watchdog */
  73. }HAL_ADC_StateTypeDef;
  74. /**
  75. * @brief ADC Init structure definition
  76. */
  77. typedef struct
  78. {
  79. uint32_t ClockPrescaler; /*!< Select the frequency of the clock to the ADC. The clock is common for
  80. all the ADCs.
  81. This parameter can be a value of @ref ADC_ClockPrescaler */
  82. uint32_t Resolution; /*!< Configures the ADC resolution dual mode.
  83. This parameter can be a value of @ref ADC_Resolution */
  84. uint32_t DataAlign; /*!< Specifies whether the ADC data alignment is left or right.
  85. This parameter can be a value of @ref ADC_data_align */
  86. uint32_t ScanConvMode; /*!< Specifies whether the conversion is performed in Scan (multi channels) or
  87. Single (one channel) mode.
  88. This parameter can be set to ENABLE or DISABLE */
  89. uint32_t EOCSelection; /*!< Specifies whether the EOC flag is set
  90. at the end of single channel conversion or at the end of all conversions.
  91. This parameter can be a value of @ref ADC_EOCSelection */
  92. uint32_t ContinuousConvMode; /*!< Specifies whether the conversion is performed in Continuous or Single mode.
  93. This parameter can be set to ENABLE or DISABLE. */
  94. uint32_t DMAContinuousRequests; /*!< Specifies whether the DMA requests is performed in Continuous or in Single mode.
  95. This parameter can be set to ENABLE or DISABLE. */
  96. uint32_t NbrOfConversion; /*!< Specifies the number of ADC conversions that will be done using the sequencer for
  97. regular channel group.
  98. This parameter must be a number between Min_Data = 1 and Max_Data = 16. */
  99. uint32_t DiscontinuousConvMode; /*!< Specifies whether the conversion is performed in Discontinuous or not
  100. for regular channels.
  101. This parameter can be set to ENABLE or DISABLE. */
  102. uint32_t NbrOfDiscConversion; /*!< Specifies the number of ADC discontinuous conversions that will be done
  103. using the sequencer for regular channel group.
  104. This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
  105. uint32_t ExternalTrigConv; /*!< Selects the external event used to trigger the conversion start of regular group.
  106. If set to ADC_SOFTWARE_START, external triggers are disabled.
  107. This parameter can be a value of @ref ADC_External_trigger_Source_Regular
  108. Note: This parameter can be modified only if there is no conversion is ongoing. */
  109. uint32_t ExternalTrigConvEdge; /*!< Selects the external trigger edge of regular group.
  110. If trigger is set to ADC_SOFTWARE_START, this parameter is discarded.
  111. This parameter can be a value of @ref ADC_External_trigger_edge_Regular
  112. Note: This parameter can be modified only if there is no conversion is ongoing. */
  113. }ADC_InitTypeDef;
  114. /**
  115. * @brief ADC handle Structure definition
  116. */
  117. typedef struct
  118. {
  119. ADC_TypeDef *Instance; /*!< Register base address */
  120. ADC_InitTypeDef Init; /*!< ADC required parameters */
  121. __IO uint32_t NbrOfCurrentConversionRank; /*!< ADC number of current conversion rank */
  122. DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
  123. HAL_LockTypeDef Lock; /*!< ADC locking object */
  124. __IO HAL_ADC_StateTypeDef State; /*!< ADC communication state */
  125. __IO uint32_t ErrorCode; /*!< ADC Error code */
  126. }ADC_HandleTypeDef;
  127. /**
  128. * @brief ADC Configuration regular Channel structure definition
  129. */
  130. typedef struct
  131. {
  132. uint32_t Channel; /*!< The ADC channel to configure.
  133. This parameter can be a value of @ref ADC_channels */
  134. uint32_t Rank; /*!< The rank in the regular group sequencer.
  135. This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
  136. uint32_t SamplingTime; /*!< The sample time value to be set for the selected channel.
  137. This parameter can be a value of @ref ADC_sampling_times */
  138. uint32_t Offset; /*!< Reserved for future use, can be set to 0 */
  139. }ADC_ChannelConfTypeDef;
  140. /**
  141. * @brief ADC Configuration multi-mode structure definition
  142. */
  143. typedef struct
  144. {
  145. uint32_t WatchdogMode; /*!< Configures the ADC analog watchdog mode.
  146. This parameter can be a value of @ref ADC_analog_watchdog_selection */
  147. uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value.
  148. This parameter must be a 12-bit value. */
  149. uint32_t LowThreshold; /*!< Configures the ADC analog watchdog High threshold value.
  150. This parameter must be a 12-bit value. */
  151. uint32_t Channel; /*!< Configures ADC channel for the analog watchdog.
  152. This parameter has an effect only if watchdog mode is configured on single channel
  153. This parameter can be a value of @ref ADC_channels */
  154. uint32_t ITMode; /*!< Specifies whether the analog watchdog is configured
  155. is interrupt mode or in polling mode.
  156. This parameter can be set to ENABLE or DISABLE */
  157. uint32_t WatchdogNumber; /*!< Reserved for future use, can be set to 0 */
  158. }ADC_AnalogWDGConfTypeDef;
  159. /**
  160. * @}
  161. */
  162. /* Exported constants --------------------------------------------------------*/
  163. /** @defgroup ADC_Exported_Constants ADC Exported Constants
  164. * @{
  165. */
  166. /** @defgroup ADC_Error_Code ADC Error Code
  167. * @{
  168. */
  169. #define HAL_ADC_ERROR_NONE ((uint32_t)0x00) /*!< No error */
  170. #define HAL_ADC_ERROR_OVR ((uint32_t)0x01) /*!< OVR error */
  171. #define HAL_ADC_ERROR_DMA ((uint32_t)0x02) /*!< DMA transfer error */
  172. /**
  173. * @}
  174. */
  175. /** @defgroup ADC_ClockPrescaler ADC Clock Prescaler
  176. * @{
  177. */
  178. #define ADC_CLOCK_SYNC_PCLK_DIV2 ((uint32_t)0x00000000)
  179. #define ADC_CLOCK_SYNC_PCLK_DIV4 ((uint32_t)ADC_CCR_ADCPRE_0)
  180. #define ADC_CLOCK_SYNC_PCLK_DIV6 ((uint32_t)ADC_CCR_ADCPRE_1)
  181. #define ADC_CLOCK_SYNC_PCLK_DIV8 ((uint32_t)ADC_CCR_ADCPRE)
  182. /**
  183. * @}
  184. */
  185. /** @defgroup ADC_delay_between_2_sampling_phases ADC Delay Between 2 Sampling Phases
  186. * @{
  187. */
  188. #define ADC_TWOSAMPLINGDELAY_5CYCLES ((uint32_t)0x00000000)
  189. #define ADC_TWOSAMPLINGDELAY_6CYCLES ((uint32_t)ADC_CCR_DELAY_0)
  190. #define ADC_TWOSAMPLINGDELAY_7CYCLES ((uint32_t)ADC_CCR_DELAY_1)
  191. #define ADC_TWOSAMPLINGDELAY_8CYCLES ((uint32_t)(ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
  192. #define ADC_TWOSAMPLINGDELAY_9CYCLES ((uint32_t)ADC_CCR_DELAY_2)
  193. #define ADC_TWOSAMPLINGDELAY_10CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0))
  194. #define ADC_TWOSAMPLINGDELAY_11CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1))
  195. #define ADC_TWOSAMPLINGDELAY_12CYCLES ((uint32_t)(ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
  196. #define ADC_TWOSAMPLINGDELAY_13CYCLES ((uint32_t)ADC_CCR_DELAY_3)
  197. #define ADC_TWOSAMPLINGDELAY_14CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_0))
  198. #define ADC_TWOSAMPLINGDELAY_15CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1))
  199. #define ADC_TWOSAMPLINGDELAY_16CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_1 | ADC_CCR_DELAY_0))
  200. #define ADC_TWOSAMPLINGDELAY_17CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2))
  201. #define ADC_TWOSAMPLINGDELAY_18CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_0))
  202. #define ADC_TWOSAMPLINGDELAY_19CYCLES ((uint32_t)(ADC_CCR_DELAY_3 | ADC_CCR_DELAY_2 | ADC_CCR_DELAY_1))
  203. #define ADC_TWOSAMPLINGDELAY_20CYCLES ((uint32_t)ADC_CCR_DELAY)
  204. /**
  205. * @}
  206. */
  207. /** @defgroup ADC_Resolution ADC Resolution
  208. * @{
  209. */
  210. #define ADC_RESOLUTION_12B ((uint32_t)0x00000000)
  211. #define ADC_RESOLUTION_10B ((uint32_t)ADC_CR1_RES_0)
  212. #define ADC_RESOLUTION_8B ((uint32_t)ADC_CR1_RES_1)
  213. #define ADC_RESOLUTION_6B ((uint32_t)ADC_CR1_RES)
  214. /**
  215. * @}
  216. */
  217. /** @defgroup ADC_External_trigger_edge_Regular ADC External Trigger Edge Regular
  218. * @{
  219. */
  220. #define ADC_EXTERNALTRIGCONVEDGE_NONE ((uint32_t)0x00000000)
  221. #define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CR2_EXTEN_0)
  222. #define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CR2_EXTEN_1)
  223. #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CR2_EXTEN)
  224. /**
  225. * @}
  226. */
  227. /** @defgroup ADC_External_trigger_Source_Regular ADC External Trigger Source Regular
  228. * @{
  229. */
  230. /* Note: Parameter ADC_SOFTWARE_START is a software parameter used for */
  231. /* compatibility with other STM32 devices. */
  232. #define ADC_EXTERNALTRIGCONV_T1_CC1 ((uint32_t)0x00000000)
  233. #define ADC_EXTERNALTRIGCONV_T1_CC2 ((uint32_t)ADC_CR2_EXTSEL_0)
  234. #define ADC_EXTERNALTRIGCONV_T1_CC3 ((uint32_t)ADC_CR2_EXTSEL_1)
  235. #define ADC_EXTERNALTRIGCONV_T2_CC2 ((uint32_t)(ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
  236. #define ADC_EXTERNALTRIGCONV_T5_TRGO ((uint32_t)ADC_CR2_EXTSEL_2)
  237. #define ADC_EXTERNALTRIGCONV_T4_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
  238. #define ADC_EXTERNALTRIGCONV_T3_CC4 ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1))
  239. #define ADC_EXTERNALTRIGCONV_T8_TRGO ((uint32_t)(ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
  240. #define ADC_EXTERNALTRIGCONV_T8_TRGO2 ((uint32_t)ADC_CR2_EXTSEL_3)
  241. #define ADC_EXTERNALTRIGCONV_T1_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_0))
  242. #define ADC_EXTERNALTRIGCONV_T1_TRGO2 ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1))
  243. #define ADC_EXTERNALTRIGCONV_T2_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_1 | ADC_CR2_EXTSEL_0))
  244. #define ADC_EXTERNALTRIGCONV_T4_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2))
  245. #define ADC_EXTERNALTRIGCONV_T6_TRGO ((uint32_t)(ADC_CR2_EXTSEL_3 | ADC_CR2_EXTSEL_2 | ADC_CR2_EXTSEL_0))
  246. #define ADC_EXTERNALTRIGCONV_EXT_IT11 ((uint32_t)ADC_CR2_EXTSEL)
  247. #define ADC_SOFTWARE_START ((uint32_t)ADC_CR2_EXTSEL + 1)
  248. /**
  249. * @}
  250. */
  251. /** @defgroup ADC_data_align ADC Data Align
  252. * @{
  253. */
  254. #define ADC_DATAALIGN_RIGHT ((uint32_t)0x00000000)
  255. #define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CR2_ALIGN)
  256. /**
  257. * @}
  258. */
  259. /** @defgroup ADC_channels ADC Common Channels
  260. * @{
  261. */
  262. #define ADC_CHANNEL_0 ((uint32_t)0x00000000)
  263. #define ADC_CHANNEL_1 ((uint32_t)ADC_CR1_AWDCH_0)
  264. #define ADC_CHANNEL_2 ((uint32_t)ADC_CR1_AWDCH_1)
  265. #define ADC_CHANNEL_3 ((uint32_t)(ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  266. #define ADC_CHANNEL_4 ((uint32_t)ADC_CR1_AWDCH_2)
  267. #define ADC_CHANNEL_5 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
  268. #define ADC_CHANNEL_6 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
  269. #define ADC_CHANNEL_7 ((uint32_t)(ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  270. #define ADC_CHANNEL_8 ((uint32_t)ADC_CR1_AWDCH_3)
  271. #define ADC_CHANNEL_9 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_0))
  272. #define ADC_CHANNEL_10 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1))
  273. #define ADC_CHANNEL_11 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  274. #define ADC_CHANNEL_12 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2))
  275. #define ADC_CHANNEL_13 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_0))
  276. #define ADC_CHANNEL_14 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1))
  277. #define ADC_CHANNEL_15 ((uint32_t)(ADC_CR1_AWDCH_3 | ADC_CR1_AWDCH_2 | ADC_CR1_AWDCH_1 | ADC_CR1_AWDCH_0))
  278. #define ADC_CHANNEL_16 ((uint32_t)ADC_CR1_AWDCH_4)
  279. #define ADC_CHANNEL_17 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_0))
  280. #define ADC_CHANNEL_18 ((uint32_t)(ADC_CR1_AWDCH_4 | ADC_CR1_AWDCH_1))
  281. #define ADC_CHANNEL_VREFINT ((uint32_t)ADC_CHANNEL_17)
  282. #define ADC_CHANNEL_VBAT ((uint32_t)ADC_CHANNEL_18)
  283. /**
  284. * @}
  285. */
  286. /** @defgroup ADC_sampling_times ADC Sampling Times
  287. * @{
  288. */
  289. #define ADC_SAMPLETIME_3CYCLES ((uint32_t)0x00000000)
  290. #define ADC_SAMPLETIME_15CYCLES ((uint32_t)ADC_SMPR1_SMP10_0)
  291. #define ADC_SAMPLETIME_28CYCLES ((uint32_t)ADC_SMPR1_SMP10_1)
  292. #define ADC_SAMPLETIME_56CYCLES ((uint32_t)(ADC_SMPR1_SMP10_1 | ADC_SMPR1_SMP10_0))
  293. #define ADC_SAMPLETIME_84CYCLES ((uint32_t)ADC_SMPR1_SMP10_2)
  294. #define ADC_SAMPLETIME_112CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_0))
  295. #define ADC_SAMPLETIME_144CYCLES ((uint32_t)(ADC_SMPR1_SMP10_2 | ADC_SMPR1_SMP10_1))
  296. #define ADC_SAMPLETIME_480CYCLES ((uint32_t)ADC_SMPR1_SMP10)
  297. /**
  298. * @}
  299. */
  300. /** @defgroup ADC_EOCSelection ADC EOC Selection
  301. * @{
  302. */
  303. #define ADC_EOC_SEQ_CONV ((uint32_t)0x00000000)
  304. #define ADC_EOC_SINGLE_CONV ((uint32_t)0x00000001)
  305. #define ADC_EOC_SINGLE_SEQ_CONV ((uint32_t)0x00000002) /*!< reserved for future use */
  306. /**
  307. * @}
  308. */
  309. /** @defgroup ADC_Event_type ADC Event Type
  310. * @{
  311. */
  312. #define ADC_AWD_EVENT ((uint32_t)ADC_FLAG_AWD)
  313. #define ADC_OVR_EVENT ((uint32_t)ADC_FLAG_OVR)
  314. /**
  315. * @}
  316. */
  317. /** @defgroup ADC_analog_watchdog_selection ADC Analog Watchdog Selection
  318. * @{
  319. */
  320. #define ADC_ANALOGWATCHDOG_SINGLE_REG ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN))
  321. #define ADC_ANALOGWATCHDOG_SINGLE_INJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_JAWDEN))
  322. #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC ((uint32_t)(ADC_CR1_AWDSGL | ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
  323. #define ADC_ANALOGWATCHDOG_ALL_REG ((uint32_t)ADC_CR1_AWDEN)
  324. #define ADC_ANALOGWATCHDOG_ALL_INJEC ((uint32_t)ADC_CR1_JAWDEN)
  325. #define ADC_ANALOGWATCHDOG_ALL_REGINJEC ((uint32_t)(ADC_CR1_AWDEN | ADC_CR1_JAWDEN))
  326. #define ADC_ANALOGWATCHDOG_NONE ((uint32_t)0x00000000)
  327. /**
  328. * @}
  329. */
  330. /** @defgroup ADC_interrupts_definition ADC Interrupts Definition
  331. * @{
  332. */
  333. #define ADC_IT_EOC ((uint32_t)ADC_CR1_EOCIE)
  334. #define ADC_IT_AWD ((uint32_t)ADC_CR1_AWDIE)
  335. #define ADC_IT_JEOC ((uint32_t)ADC_CR1_JEOCIE)
  336. #define ADC_IT_OVR ((uint32_t)ADC_CR1_OVRIE)
  337. /**
  338. * @}
  339. */
  340. /** @defgroup ADC_flags_definition ADC Flags Definition
  341. * @{
  342. */
  343. #define ADC_FLAG_AWD ((uint32_t)ADC_SR_AWD)
  344. #define ADC_FLAG_EOC ((uint32_t)ADC_SR_EOC)
  345. #define ADC_FLAG_JEOC ((uint32_t)ADC_SR_JEOC)
  346. #define ADC_FLAG_JSTRT ((uint32_t)ADC_SR_JSTRT)
  347. #define ADC_FLAG_STRT ((uint32_t)ADC_SR_STRT)
  348. #define ADC_FLAG_OVR ((uint32_t)ADC_SR_OVR)
  349. /**
  350. * @}
  351. */
  352. /** @defgroup ADC_channels_type ADC Channels Type
  353. * @{
  354. */
  355. #define ADC_ALL_CHANNELS ((uint32_t)0x00000001)
  356. #define ADC_REGULAR_CHANNELS ((uint32_t)0x00000002) /*!< reserved for future use */
  357. #define ADC_INJECTED_CHANNELS ((uint32_t)0x00000003) /*!< reserved for future use */
  358. /**
  359. * @}
  360. */
  361. /**
  362. * @}
  363. */
  364. /* Exported macro ------------------------------------------------------------*/
  365. /** @defgroup ADC_Exported_Macros ADC Exported Macros
  366. * @{
  367. */
  368. /** @brief Reset ADC handle state
  369. * @param __HANDLE__: ADC handle
  370. * @retval None
  371. */
  372. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  373. /**
  374. * @brief Enable the ADC peripheral.
  375. * @param __HANDLE__: ADC handle
  376. * @retval None
  377. */
  378. #define __HAL_ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 |= ADC_CR2_ADON)
  379. /**
  380. * @brief Disable the ADC peripheral.
  381. * @param __HANDLE__: ADC handle
  382. * @retval None
  383. */
  384. #define __HAL_ADC_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR2 &= ~ADC_CR2_ADON)
  385. /**
  386. * @brief Enable the ADC end of conversion interrupt.
  387. * @param __HANDLE__: specifies the ADC Handle.
  388. * @param __INTERRUPT__: ADC Interrupt.
  389. * @retval None
  390. */
  391. #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) |= (__INTERRUPT__))
  392. /**
  393. * @brief Disable the ADC end of conversion interrupt.
  394. * @param __HANDLE__: specifies the ADC Handle.
  395. * @param __INTERRUPT__: ADC interrupt.
  396. * @retval None
  397. */
  398. #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1) &= ~(__INTERRUPT__))
  399. /** @brief Check if the specified ADC interrupt source is enabled or disabled.
  400. * @param __HANDLE__: specifies the ADC Handle.
  401. * @param __INTERRUPT__: specifies the ADC interrupt source to check.
  402. * @retval The new state of __IT__ (TRUE or FALSE).
  403. */
  404. #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->CR1 & (__INTERRUPT__)) == (__INTERRUPT__))
  405. /**
  406. * @brief Clear the ADC's pending flags.
  407. * @param __HANDLE__: specifies the ADC Handle.
  408. * @param __FLAG__: ADC flag.
  409. * @retval None
  410. */
  411. #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR) = ~(__FLAG__))
  412. /**
  413. * @brief Get the selected ADC's flag status.
  414. * @param __HANDLE__: specifies the ADC Handle.
  415. * @param __FLAG__: ADC flag.
  416. * @retval None
  417. */
  418. #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
  419. /**
  420. * @}
  421. */
  422. /* Include ADC HAL Extension module */
  423. #include "stm32f7xx_hal_adc_ex.h"
  424. /* Exported functions --------------------------------------------------------*/
  425. /** @addtogroup ADC_Exported_Functions
  426. * @{
  427. */
  428. /** @addtogroup ADC_Exported_Functions_Group1
  429. * @{
  430. */
  431. /* Initialization/de-initialization functions ***********************************/
  432. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
  433. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  434. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
  435. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
  436. /**
  437. * @}
  438. */
  439. /** @addtogroup ADC_Exported_Functions_Group2
  440. * @{
  441. */
  442. /* I/O operation functions ******************************************************/
  443. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
  444. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
  445. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  446. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
  447. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
  448. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
  449. void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
  450. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
  451. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
  452. uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
  453. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
  454. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
  455. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
  456. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  457. /**
  458. * @}
  459. */
  460. /** @addtogroup ADC_Exported_Functions_Group3
  461. * @{
  462. */
  463. /* Peripheral Control functions *************************************************/
  464. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
  465. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
  466. /**
  467. * @}
  468. */
  469. /** @addtogroup ADC_Exported_Functions_Group4
  470. * @{
  471. */
  472. /* Peripheral State functions ***************************************************/
  473. HAL_ADC_StateTypeDef HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
  474. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
  475. /**
  476. * @}
  477. */
  478. /**
  479. * @}
  480. */
  481. /* Private types -------------------------------------------------------------*/
  482. /* Private variables ---------------------------------------------------------*/
  483. /* Private constants ---------------------------------------------------------*/
  484. /** @defgroup ADC_Private_Constants ADC Private Constants
  485. * @{
  486. */
  487. /* Delay for ADC stabilization time. */
  488. /* Maximum delay is 1us (refer to device datasheet, parameter tSTAB). */
  489. /* Unit: us */
  490. #define ADC_STAB_DELAY_US ((uint32_t) 3)
  491. /* Delay for temperature sensor stabilization time. */
  492. /* Maximum delay is 10us (refer to device datasheet, parameter tSTART). */
  493. /* Unit: us */
  494. #define ADC_TEMPSENSOR_DELAY_US ((uint32_t) 10)
  495. /**
  496. * @}
  497. */
  498. /* Private macros ------------------------------------------------------------*/
  499. /** @defgroup ADC_Private_Macros ADC Private Macros
  500. * @{
  501. */
  502. #define IS_ADC_CLOCKPRESCALER(__ADC_CLOCK__) (((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
  503. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV4) || \
  504. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV6) || \
  505. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV8))
  506. #define IS_ADC_SAMPLING_DELAY(__DELAY__) (((__DELAY__) == ADC_TWOSAMPLINGDELAY_5CYCLES) || \
  507. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_6CYCLES) || \
  508. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_7CYCLES) || \
  509. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_8CYCLES) || \
  510. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_9CYCLES) || \
  511. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_10CYCLES) || \
  512. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_11CYCLES) || \
  513. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_12CYCLES) || \
  514. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_13CYCLES) || \
  515. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_14CYCLES) || \
  516. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_15CYCLES) || \
  517. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_16CYCLES) || \
  518. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_17CYCLES) || \
  519. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_18CYCLES) || \
  520. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_19CYCLES) || \
  521. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_20CYCLES))
  522. #define IS_ADC_RESOLUTION(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_12B) || \
  523. ((__RESOLUTION__) == ADC_RESOLUTION_10B) || \
  524. ((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
  525. ((__RESOLUTION__) == ADC_RESOLUTION_6B))
  526. #define IS_ADC_EXT_TRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
  527. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
  528. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
  529. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING))
  530. #define IS_ADC_EXT_TRIG(__REGTRIG__) (((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_CC1) || \
  531. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_CC2) || \
  532. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_CC3) || \
  533. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T2_CC2) || \
  534. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T5_TRGO) || \
  535. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T4_CC4) || \
  536. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T3_CC4) || \
  537. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T8_TRGO) || \
  538. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T8_TRGO2) || \
  539. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_TRGO) || \
  540. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T1_TRGO2) || \
  541. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T2_TRGO) || \
  542. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T4_TRGO) || \
  543. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_T6_TRGO) || \
  544. ((__REGTRIG__) == ADC_EXTERNALTRIGCONV_EXT_IT11) || \
  545. ((__REGTRIG__) == ADC_SOFTWARE_START))
  546. #define IS_ADC_DATA_ALIGN(__ALIGN__) (((__ALIGN__) == ADC_DATAALIGN_RIGHT) || \
  547. ((__ALIGN__) == ADC_DATAALIGN_LEFT))
  548. #define IS_ADC_SAMPLE_TIME(__TIME__) (((__TIME__) == ADC_SAMPLETIME_3CYCLES) || \
  549. ((__TIME__) == ADC_SAMPLETIME_15CYCLES) || \
  550. ((__TIME__) == ADC_SAMPLETIME_28CYCLES) || \
  551. ((__TIME__) == ADC_SAMPLETIME_56CYCLES) || \
  552. ((__TIME__) == ADC_SAMPLETIME_84CYCLES) || \
  553. ((__TIME__) == ADC_SAMPLETIME_112CYCLES) || \
  554. ((__TIME__) == ADC_SAMPLETIME_144CYCLES) || \
  555. ((__TIME__) == ADC_SAMPLETIME_480CYCLES))
  556. #define IS_ADC_EOCSelection(__EOCSelection__) (((__EOCSelection__) == ADC_EOC_SINGLE_CONV) || \
  557. ((__EOCSelection__) == ADC_EOC_SEQ_CONV) || \
  558. ((__EOCSelection__) == ADC_EOC_SINGLE_SEQ_CONV))
  559. #define IS_ADC_EVENT_TYPE(__EVENT__) (((__EVENT__) == ADC_AWD_EVENT) || \
  560. ((__EVENT__) == ADC_OVR_EVENT))
  561. #define IS_ADC_ANALOG_WATCHDOG(__WATCHDOG__) (((__WATCHDOG__) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \
  562. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_SINGLE_INJEC) || \
  563. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC) || \
  564. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_ALL_REG) || \
  565. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_ALL_INJEC) || \
  566. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_ALL_REGINJEC) || \
  567. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_NONE))
  568. #define IS_ADC_CHANNELS_TYPE(CHANNEL_TYPE) (((CHANNEL_TYPE) == ADC_ALL_CHANNELS) || \
  569. ((CHANNEL_TYPE) == ADC_REGULAR_CHANNELS) || \
  570. ((CHANNEL_TYPE) == ADC_INJECTED_CHANNELS))
  571. #define IS_ADC_THRESHOLD(__THRESHOLD__) ((__THRESHOLD__) <= ((uint32_t)0xFFF))
  572. #define IS_ADC_REGULAR_LENGTH(__LENGTH__) (((__LENGTH__) >= ((uint32_t)1)) && ((__LENGTH__) <= ((uint32_t)16)))
  573. #define IS_ADC_REGULAR_RANK(__RANK__) (((__RANK__) >= ((uint32_t)1)) && ((__RANK__) <= ((uint32_t)16)))
  574. #define IS_ADC_REGULAR_DISC_NUMBER(__NUMBER__) (((__NUMBER__) >= ((uint32_t)1)) && ((__NUMBER__) <= ((uint32_t)8)))
  575. #define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \
  576. ((((__RESOLUTION__) == ADC_RESOLUTION_12B) && ((__ADC_VALUE__) <= ((uint32_t)0x0FFF))) || \
  577. (((__RESOLUTION__) == ADC_RESOLUTION_10B) && ((__ADC_VALUE__) <= ((uint32_t)0x03FF))) || \
  578. (((__RESOLUTION__) == ADC_RESOLUTION_8B) && ((__ADC_VALUE__) <= ((uint32_t)0x00FF))) || \
  579. (((__RESOLUTION__) == ADC_RESOLUTION_6B) && ((__ADC_VALUE__) <= ((uint32_t)0x003F))))
  580. /**
  581. * @brief Set ADC Regular channel sequence length.
  582. * @param _NbrOfConversion_: Regular channel sequence length.
  583. * @retval None
  584. */
  585. #define ADC_SQR1(_NbrOfConversion_) (((_NbrOfConversion_) - (uint8_t)1) << 20)
  586. /**
  587. * @brief Set the ADC's sample time for channel numbers between 10 and 18.
  588. * @param _SAMPLETIME_: Sample time parameter.
  589. * @param _CHANNELNB_: Channel number.
  590. * @retval None
  591. */
  592. #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * (((uint32_t)((uint16_t)(_CHANNELNB_))) - 10)))
  593. /**
  594. * @brief Set the ADC's sample time for channel numbers between 0 and 9.
  595. * @param _SAMPLETIME_: Sample time parameter.
  596. * @param _CHANNELNB_: Channel number.
  597. * @retval None
  598. */
  599. #define ADC_SMPR2(_SAMPLETIME_, _CHANNELNB_) ((_SAMPLETIME_) << (3 * ((uint32_t)((uint16_t)(_CHANNELNB_)))))
  600. /**
  601. * @brief Set the selected regular channel rank for rank between 1 and 6.
  602. * @param _CHANNELNB_: Channel number.
  603. * @param _RANKNB_: Rank number.
  604. * @retval None
  605. */
  606. #define ADC_SQR3_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * ((_RANKNB_) - 1)))
  607. /**
  608. * @brief Set the selected regular channel rank for rank between 7 and 12.
  609. * @param _CHANNELNB_: Channel number.
  610. * @param _RANKNB_: Rank number.
  611. * @retval None
  612. */
  613. #define ADC_SQR2_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * ((_RANKNB_) - 7)))
  614. /**
  615. * @brief Set the selected regular channel rank for rank between 13 and 16.
  616. * @param _CHANNELNB_: Channel number.
  617. * @param _RANKNB_: Rank number.
  618. * @retval None
  619. */
  620. #define ADC_SQR1_RK(_CHANNELNB_, _RANKNB_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * ((_RANKNB_) - 13)))
  621. /**
  622. * @brief Enable ADC continuous conversion mode.
  623. * @param _CONTINUOUS_MODE_: Continuous mode.
  624. * @retval None
  625. */
  626. #define ADC_CR2_CONTINUOUS(_CONTINUOUS_MODE_) ((_CONTINUOUS_MODE_) << 1)
  627. /**
  628. * @brief Configures the number of discontinuous conversions for the regular group channels.
  629. * @param _NBR_DISCONTINUOUSCONV_: Number of discontinuous conversions.
  630. * @retval None
  631. */
  632. #define ADC_CR1_DISCONTINUOUS(_NBR_DISCONTINUOUSCONV_) (((_NBR_DISCONTINUOUSCONV_) - 1) << POSITION_VAL(ADC_CR1_DISCNUM))
  633. /**
  634. * @brief Enable ADC scan mode.
  635. * @param _SCANCONV_MODE_: Scan conversion mode.
  636. * @retval None
  637. */
  638. #define ADC_CR1_SCANCONV(_SCANCONV_MODE_) ((_SCANCONV_MODE_) << 8)
  639. /**
  640. * @brief Enable the ADC end of conversion selection.
  641. * @param _EOCSelection_MODE_: End of conversion selection mode.
  642. * @retval None
  643. */
  644. #define ADC_CR2_EOCSelection(_EOCSelection_MODE_) ((_EOCSelection_MODE_) << 10)
  645. /**
  646. * @brief Enable the ADC DMA continuous request.
  647. * @param _DMAContReq_MODE_: DMA continuous request mode.
  648. * @retval None
  649. */
  650. #define ADC_CR2_DMAContReq(_DMAContReq_MODE_) ((_DMAContReq_MODE_) << 9)
  651. /**
  652. * @brief Return resolution bits in CR1 register.
  653. * @param __HANDLE__: ADC handle
  654. * @retval None
  655. */
  656. #define ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CR1) & ADC_CR1_RES)
  657. /**
  658. * @}
  659. */
  660. /* Private functions ---------------------------------------------------------*/
  661. /** @defgroup ADC_Private_Functions ADC Private Functions
  662. * @{
  663. */
  664. /**
  665. * @}
  666. */
  667. /**
  668. * @}
  669. */
  670. /**
  671. * @}
  672. */
  673. #ifdef __cplusplus
  674. }
  675. #endif
  676. #endif /*__STM32F7xx_ADC_H */
  677. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/