stm32f2xx_adc.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. ******************************************************************************
  3. * @file stm32f2xx_adc.h
  4. * @author MCD Application Team
  5. * @version V1.1.3
  6. * @date 31-December-2021
  7. * @brief This file contains all the functions prototypes for the ADC firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * Copyright (c) 2012 STMicroelectronics.
  13. * All rights reserved.
  14. *
  15. * This software is licensed under terms that can be found in the LICENSE file
  16. * in the root directory of this software component.
  17. * If no LICENSE file comes with this software, it is provided AS-IS.
  18. *
  19. ******************************************************************************
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __STM32F2xx_ADC_H
  23. #define __STM32F2xx_ADC_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32f2xx.h"
  29. /** @addtogroup STM32F2xx_StdPeriph_Driver
  30. * @{
  31. */
  32. /** @addtogroup ADC
  33. * @{
  34. */
  35. /* Exported types ------------------------------------------------------------*/
  36. /**
  37. * @brief ADC Init structure definition
  38. */
  39. typedef struct
  40. {
  41. uint32_t ADC_Resolution; /*!< Configures the ADC resolution dual mode.
  42. This parameter can be a value of @ref ADC_resolution */
  43. FunctionalState ADC_ScanConvMode; /*!< Specifies whether the conversion
  44. is performed in Scan (multichannels)
  45. or Single (one channel) mode.
  46. This parameter can be set to ENABLE or DISABLE */
  47. FunctionalState ADC_ContinuousConvMode; /*!< Specifies whether the conversion
  48. is performed in Continuous or Single mode.
  49. This parameter can be set to ENABLE or DISABLE. */
  50. uint32_t ADC_ExternalTrigConvEdge; /*!< Select the external trigger edge and
  51. enable the trigger of a regular group.
  52. This parameter can be a value of
  53. @ref ADC_external_trigger_edge_for_regular_channels_conversion */
  54. uint32_t ADC_ExternalTrigConv; /*!< Select the external event used to trigger
  55. the start of conversion of a regular group.
  56. This parameter can be a value of
  57. @ref ADC_extrenal_trigger_sources_for_regular_channels_conversion */
  58. uint32_t ADC_DataAlign; /*!< Specifies whether the ADC data alignment
  59. is left or right. This parameter can be
  60. a value of @ref ADC_data_align */
  61. uint8_t ADC_NbrOfConversion; /*!< Specifies the number of ADC conversions
  62. that will be done using the sequencer for
  63. regular channel group.
  64. This parameter must range from 1 to 16. */
  65. }ADC_InitTypeDef;
  66. /**
  67. * @brief ADC Common Init structure definition
  68. */
  69. typedef struct
  70. {
  71. uint32_t ADC_Mode; /*!< Configures the ADC to operate in
  72. independent or multi mode.
  73. This parameter can be a value of @ref ADC_Common_mode */
  74. uint32_t ADC_Prescaler; /*!< Select the frequency of the clock
  75. to the ADC. The clock is common for all the ADCs.
  76. This parameter can be a value of @ref ADC_Prescaler */
  77. uint32_t ADC_DMAAccessMode; /*!< Configures the Direct memory access
  78. mode for multi ADC mode.
  79. This parameter can be a value of
  80. @ref ADC_Direct_memory_access_mode_for_multi_mode */
  81. uint32_t ADC_TwoSamplingDelay; /*!< Configures the Delay between 2 sampling phases.
  82. This parameter can be a value of
  83. @ref ADC_delay_between_2_sampling_phases */
  84. }ADC_CommonInitTypeDef;
  85. /* Exported constants --------------------------------------------------------*/
  86. /** @defgroup ADC_Exported_Constants
  87. * @{
  88. */
  89. #define IS_ADC_ALL_PERIPH(PERIPH) (((PERIPH) == ADC1) || \
  90. ((PERIPH) == ADC2) || \
  91. ((PERIPH) == ADC3))
  92. /** @defgroup ADC_Common_mode
  93. * @{
  94. */
  95. #define ADC_Mode_Independent ((uint32_t)0x00000000)
  96. #define ADC_DualMode_RegSimult_InjecSimult ((uint32_t)0x00000001)
  97. #define ADC_DualMode_RegSimult_AlterTrig ((uint32_t)0x00000002)
  98. #define ADC_DualMode_InjecSimult ((uint32_t)0x00000005)
  99. #define ADC_DualMode_RegSimult ((uint32_t)0x00000006)
  100. #define ADC_DualMode_Interl ((uint32_t)0x00000007)
  101. #define ADC_DualMode_AlterTrig ((uint32_t)0x00000009)
  102. #define ADC_TripleMode_RegSimult_InjecSimult ((uint32_t)0x00000011)
  103. #define ADC_TripleMode_RegSimult_AlterTrig ((uint32_t)0x00000012)
  104. #define ADC_TripleMode_InjecSimult ((uint32_t)0x00000015)
  105. #define ADC_TripleMode_RegSimult ((uint32_t)0x00000016)
  106. #define ADC_TripleMode_Interl ((uint32_t)0x00000017)
  107. #define ADC_TripleMode_AlterTrig ((uint32_t)0x00000019)
  108. #define IS_ADC_MODE(MODE) (((MODE) == ADC_Mode_Independent) || \
  109. ((MODE) == ADC_DualMode_RegSimult_InjecSimult) || \
  110. ((MODE) == ADC_DualMode_RegSimult_AlterTrig) || \
  111. ((MODE) == ADC_DualMode_InjecSimult) || \
  112. ((MODE) == ADC_DualMode_RegSimult) || \
  113. ((MODE) == ADC_DualMode_Interl) || \
  114. ((MODE) == ADC_DualMode_AlterTrig) || \
  115. ((MODE) == ADC_TripleMode_RegSimult_InjecSimult) || \
  116. ((MODE) == ADC_TripleMode_RegSimult_AlterTrig) || \
  117. ((MODE) == ADC_TripleMode_InjecSimult) || \
  118. ((MODE) == ADC_TripleMode_RegSimult) || \
  119. ((MODE) == ADC_TripleMode_Interl) || \
  120. ((MODE) == ADC_TripleMode_AlterTrig))
  121. /**
  122. * @}
  123. */
  124. /** @defgroup ADC_Prescaler
  125. * @{
  126. */
  127. #define ADC_Prescaler_Div2 ((uint32_t)0x00000000)
  128. #define ADC_Prescaler_Div4 ((uint32_t)0x00010000)
  129. #define ADC_Prescaler_Div6 ((uint32_t)0x00020000)
  130. #define ADC_Prescaler_Div8 ((uint32_t)0x00030000)
  131. #define IS_ADC_PRESCALER(PRESCALER) (((PRESCALER) == ADC_Prescaler_Div2) || \
  132. ((PRESCALER) == ADC_Prescaler_Div4) || \
  133. ((PRESCALER) == ADC_Prescaler_Div6) || \
  134. ((PRESCALER) == ADC_Prescaler_Div8))
  135. /**
  136. * @}
  137. */
  138. /** @defgroup ADC_Direct_memory_access_mode_for_multi_mode
  139. * @{
  140. */
  141. #define ADC_DMAAccessMode_Disabled ((uint32_t)0x00000000) /* DMA mode disabled */
  142. #define ADC_DMAAccessMode_1 ((uint32_t)0x00004000) /* DMA mode 1 enabled (2 / 3 half-words one by one - 1 then 2 then 3)*/
  143. #define ADC_DMAAccessMode_2 ((uint32_t)0x00008000) /* DMA mode 2 enabled (2 / 3 half-words by pairs - 2&1 then 1&3 then 3&2)*/
  144. #define ADC_DMAAccessMode_3 ((uint32_t)0x0000C000) /* DMA mode 3 enabled (2 / 3 bytes by pairs - 2&1 then 1&3 then 3&2) */
  145. #define IS_ADC_DMA_ACCESS_MODE(MODE) (((MODE) == ADC_DMAAccessMode_Disabled) || \
  146. ((MODE) == ADC_DMAAccessMode_1) || \
  147. ((MODE) == ADC_DMAAccessMode_2) || \
  148. ((MODE) == ADC_DMAAccessMode_3))
  149. /**
  150. * @}
  151. */
  152. /** @defgroup ADC_delay_between_2_sampling_phases
  153. * @{
  154. */
  155. #define ADC_TwoSamplingDelay_5Cycles ((uint32_t)0x00000000)
  156. #define ADC_TwoSamplingDelay_6Cycles ((uint32_t)0x00000100)
  157. #define ADC_TwoSamplingDelay_7Cycles ((uint32_t)0x00000200)
  158. #define ADC_TwoSamplingDelay_8Cycles ((uint32_t)0x00000300)
  159. #define ADC_TwoSamplingDelay_9Cycles ((uint32_t)0x00000400)
  160. #define ADC_TwoSamplingDelay_10Cycles ((uint32_t)0x00000500)
  161. #define ADC_TwoSamplingDelay_11Cycles ((uint32_t)0x00000600)
  162. #define ADC_TwoSamplingDelay_12Cycles ((uint32_t)0x00000700)
  163. #define ADC_TwoSamplingDelay_13Cycles ((uint32_t)0x00000800)
  164. #define ADC_TwoSamplingDelay_14Cycles ((uint32_t)0x00000900)
  165. #define ADC_TwoSamplingDelay_15Cycles ((uint32_t)0x00000A00)
  166. #define ADC_TwoSamplingDelay_16Cycles ((uint32_t)0x00000B00)
  167. #define ADC_TwoSamplingDelay_17Cycles ((uint32_t)0x00000C00)
  168. #define ADC_TwoSamplingDelay_18Cycles ((uint32_t)0x00000D00)
  169. #define ADC_TwoSamplingDelay_19Cycles ((uint32_t)0x00000E00)
  170. #define ADC_TwoSamplingDelay_20Cycles ((uint32_t)0x00000F00)
  171. #define IS_ADC_SAMPLING_DELAY(DELAY) (((DELAY) == ADC_TwoSamplingDelay_5Cycles) || \
  172. ((DELAY) == ADC_TwoSamplingDelay_6Cycles) || \
  173. ((DELAY) == ADC_TwoSamplingDelay_7Cycles) || \
  174. ((DELAY) == ADC_TwoSamplingDelay_8Cycles) || \
  175. ((DELAY) == ADC_TwoSamplingDelay_9Cycles) || \
  176. ((DELAY) == ADC_TwoSamplingDelay_10Cycles) || \
  177. ((DELAY) == ADC_TwoSamplingDelay_11Cycles) || \
  178. ((DELAY) == ADC_TwoSamplingDelay_12Cycles) || \
  179. ((DELAY) == ADC_TwoSamplingDelay_13Cycles) || \
  180. ((DELAY) == ADC_TwoSamplingDelay_14Cycles) || \
  181. ((DELAY) == ADC_TwoSamplingDelay_15Cycles) || \
  182. ((DELAY) == ADC_TwoSamplingDelay_16Cycles) || \
  183. ((DELAY) == ADC_TwoSamplingDelay_17Cycles) || \
  184. ((DELAY) == ADC_TwoSamplingDelay_18Cycles) || \
  185. ((DELAY) == ADC_TwoSamplingDelay_19Cycles) || \
  186. ((DELAY) == ADC_TwoSamplingDelay_20Cycles))
  187. /**
  188. * @}
  189. */
  190. /** @defgroup ADC_resolution
  191. * @{
  192. */
  193. #define ADC_Resolution_12b ((uint32_t)0x00000000)
  194. #define ADC_Resolution_10b ((uint32_t)0x01000000)
  195. #define ADC_Resolution_8b ((uint32_t)0x02000000)
  196. #define ADC_Resolution_6b ((uint32_t)0x03000000)
  197. #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_Resolution_12b) || \
  198. ((RESOLUTION) == ADC_Resolution_10b) || \
  199. ((RESOLUTION) == ADC_Resolution_8b) || \
  200. ((RESOLUTION) == ADC_Resolution_6b))
  201. /**
  202. * @}
  203. */
  204. /** @defgroup ADC_external_trigger_edge_for_regular_channels_conversion
  205. * @{
  206. */
  207. #define ADC_ExternalTrigConvEdge_None ((uint32_t)0x00000000)
  208. #define ADC_ExternalTrigConvEdge_Rising ((uint32_t)0x10000000)
  209. #define ADC_ExternalTrigConvEdge_Falling ((uint32_t)0x20000000)
  210. #define ADC_ExternalTrigConvEdge_RisingFalling ((uint32_t)0x30000000)
  211. #define IS_ADC_EXT_TRIG_EDGE(EDGE) (((EDGE) == ADC_ExternalTrigConvEdge_None) || \
  212. ((EDGE) == ADC_ExternalTrigConvEdge_Rising) || \
  213. ((EDGE) == ADC_ExternalTrigConvEdge_Falling) || \
  214. ((EDGE) == ADC_ExternalTrigConvEdge_RisingFalling))
  215. /**
  216. * @}
  217. */
  218. /** @defgroup ADC_extrenal_trigger_sources_for_regular_channels_conversion
  219. * @{
  220. */
  221. #define ADC_ExternalTrigConv_T1_CC1 ((uint32_t)0x00000000)
  222. #define ADC_ExternalTrigConv_T1_CC2 ((uint32_t)0x01000000)
  223. #define ADC_ExternalTrigConv_T1_CC3 ((uint32_t)0x02000000)
  224. #define ADC_ExternalTrigConv_T2_CC2 ((uint32_t)0x03000000)
  225. #define ADC_ExternalTrigConv_T2_CC3 ((uint32_t)0x04000000)
  226. #define ADC_ExternalTrigConv_T2_CC4 ((uint32_t)0x05000000)
  227. #define ADC_ExternalTrigConv_T2_TRGO ((uint32_t)0x06000000)
  228. #define ADC_ExternalTrigConv_T3_CC1 ((uint32_t)0x07000000)
  229. #define ADC_ExternalTrigConv_T3_TRGO ((uint32_t)0x08000000)
  230. #define ADC_ExternalTrigConv_T4_CC4 ((uint32_t)0x09000000)
  231. #define ADC_ExternalTrigConv_T5_CC1 ((uint32_t)0x0A000000)
  232. #define ADC_ExternalTrigConv_T5_CC2 ((uint32_t)0x0B000000)
  233. #define ADC_ExternalTrigConv_T5_CC3 ((uint32_t)0x0C000000)
  234. #define ADC_ExternalTrigConv_T8_CC1 ((uint32_t)0x0D000000)
  235. #define ADC_ExternalTrigConv_T8_TRGO ((uint32_t)0x0E000000)
  236. #define ADC_ExternalTrigConv_Ext_IT11 ((uint32_t)0x0F000000)
  237. #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_ExternalTrigConv_T1_CC1) || \
  238. ((REGTRIG) == ADC_ExternalTrigConv_T1_CC2) || \
  239. ((REGTRIG) == ADC_ExternalTrigConv_T1_CC3) || \
  240. ((REGTRIG) == ADC_ExternalTrigConv_T2_CC2) || \
  241. ((REGTRIG) == ADC_ExternalTrigConv_T2_CC3) || \
  242. ((REGTRIG) == ADC_ExternalTrigConv_T2_CC4) || \
  243. ((REGTRIG) == ADC_ExternalTrigConv_T2_TRGO) || \
  244. ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \
  245. ((REGTRIG) == ADC_ExternalTrigConv_T3_TRGO) || \
  246. ((REGTRIG) == ADC_ExternalTrigConv_T4_CC4) || \
  247. ((REGTRIG) == ADC_ExternalTrigConv_T5_CC1) || \
  248. ((REGTRIG) == ADC_ExternalTrigConv_T5_CC2) || \
  249. ((REGTRIG) == ADC_ExternalTrigConv_T5_CC3) || \
  250. ((REGTRIG) == ADC_ExternalTrigConv_T8_CC1) || \
  251. ((REGTRIG) == ADC_ExternalTrigConv_T8_TRGO) || \
  252. ((REGTRIG) == ADC_ExternalTrigConv_Ext_IT11))
  253. /**
  254. * @}
  255. */
  256. /** @defgroup ADC_data_align
  257. * @{
  258. */
  259. #define ADC_DataAlign_Right ((uint32_t)0x00000000)
  260. #define ADC_DataAlign_Left ((uint32_t)0x00000800)
  261. #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \
  262. ((ALIGN) == ADC_DataAlign_Left))
  263. /**
  264. * @}
  265. */
  266. /** @defgroup ADC_channels
  267. * @{
  268. */
  269. #define ADC_Channel_0 ((uint8_t)0x00)
  270. #define ADC_Channel_1 ((uint8_t)0x01)
  271. #define ADC_Channel_2 ((uint8_t)0x02)
  272. #define ADC_Channel_3 ((uint8_t)0x03)
  273. #define ADC_Channel_4 ((uint8_t)0x04)
  274. #define ADC_Channel_5 ((uint8_t)0x05)
  275. #define ADC_Channel_6 ((uint8_t)0x06)
  276. #define ADC_Channel_7 ((uint8_t)0x07)
  277. #define ADC_Channel_8 ((uint8_t)0x08)
  278. #define ADC_Channel_9 ((uint8_t)0x09)
  279. #define ADC_Channel_10 ((uint8_t)0x0A)
  280. #define ADC_Channel_11 ((uint8_t)0x0B)
  281. #define ADC_Channel_12 ((uint8_t)0x0C)
  282. #define ADC_Channel_13 ((uint8_t)0x0D)
  283. #define ADC_Channel_14 ((uint8_t)0x0E)
  284. #define ADC_Channel_15 ((uint8_t)0x0F)
  285. #define ADC_Channel_16 ((uint8_t)0x10)
  286. #define ADC_Channel_17 ((uint8_t)0x11)
  287. #define ADC_Channel_18 ((uint8_t)0x12)
  288. #define ADC_Channel_TempSensor ((uint8_t)ADC_Channel_16)
  289. #define ADC_Channel_Vrefint ((uint8_t)ADC_Channel_17)
  290. #define ADC_Channel_Vbat ((uint8_t)ADC_Channel_18)
  291. #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_Channel_0) || \
  292. ((CHANNEL) == ADC_Channel_1) || \
  293. ((CHANNEL) == ADC_Channel_2) || \
  294. ((CHANNEL) == ADC_Channel_3) || \
  295. ((CHANNEL) == ADC_Channel_4) || \
  296. ((CHANNEL) == ADC_Channel_5) || \
  297. ((CHANNEL) == ADC_Channel_6) || \
  298. ((CHANNEL) == ADC_Channel_7) || \
  299. ((CHANNEL) == ADC_Channel_8) || \
  300. ((CHANNEL) == ADC_Channel_9) || \
  301. ((CHANNEL) == ADC_Channel_10) || \
  302. ((CHANNEL) == ADC_Channel_11) || \
  303. ((CHANNEL) == ADC_Channel_12) || \
  304. ((CHANNEL) == ADC_Channel_13) || \
  305. ((CHANNEL) == ADC_Channel_14) || \
  306. ((CHANNEL) == ADC_Channel_15) || \
  307. ((CHANNEL) == ADC_Channel_16) || \
  308. ((CHANNEL) == ADC_Channel_17) || \
  309. ((CHANNEL) == ADC_Channel_18))
  310. /**
  311. * @}
  312. */
  313. /** @defgroup ADC_sampling_times
  314. * @{
  315. */
  316. #define ADC_SampleTime_3Cycles ((uint8_t)0x00)
  317. #define ADC_SampleTime_15Cycles ((uint8_t)0x01)
  318. #define ADC_SampleTime_28Cycles ((uint8_t)0x02)
  319. #define ADC_SampleTime_56Cycles ((uint8_t)0x03)
  320. #define ADC_SampleTime_84Cycles ((uint8_t)0x04)
  321. #define ADC_SampleTime_112Cycles ((uint8_t)0x05)
  322. #define ADC_SampleTime_144Cycles ((uint8_t)0x06)
  323. #define ADC_SampleTime_480Cycles ((uint8_t)0x07)
  324. #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SampleTime_3Cycles) || \
  325. ((TIME) == ADC_SampleTime_15Cycles) || \
  326. ((TIME) == ADC_SampleTime_28Cycles) || \
  327. ((TIME) == ADC_SampleTime_56Cycles) || \
  328. ((TIME) == ADC_SampleTime_84Cycles) || \
  329. ((TIME) == ADC_SampleTime_112Cycles) || \
  330. ((TIME) == ADC_SampleTime_144Cycles) || \
  331. ((TIME) == ADC_SampleTime_480Cycles))
  332. /**
  333. * @}
  334. */
  335. /** @defgroup ADC_external_trigger_edge_for_injected_channels_conversion
  336. * @{
  337. */
  338. #define ADC_ExternalTrigInjecConvEdge_None ((uint32_t)0x00000000)
  339. #define ADC_ExternalTrigInjecConvEdge_Rising ((uint32_t)0x00100000)
  340. #define ADC_ExternalTrigInjecConvEdge_Falling ((uint32_t)0x00200000)
  341. #define ADC_ExternalTrigInjecConvEdge_RisingFalling ((uint32_t)0x00300000)
  342. #define IS_ADC_EXT_INJEC_TRIG_EDGE(EDGE) (((EDGE) == ADC_ExternalTrigInjecConvEdge_None) || \
  343. ((EDGE) == ADC_ExternalTrigInjecConvEdge_Rising) || \
  344. ((EDGE) == ADC_ExternalTrigInjecConvEdge_Falling) || \
  345. ((EDGE) == ADC_ExternalTrigInjecConvEdge_RisingFalling))
  346. /**
  347. * @}
  348. */
  349. /** @defgroup ADC_extrenal_trigger_sources_for_injected_channels_conversion
  350. * @{
  351. */
  352. #define ADC_ExternalTrigInjecConv_T1_CC4 ((uint32_t)0x00000000)
  353. #define ADC_ExternalTrigInjecConv_T1_TRGO ((uint32_t)0x00010000)
  354. #define ADC_ExternalTrigInjecConv_T2_CC1 ((uint32_t)0x00020000)
  355. #define ADC_ExternalTrigInjecConv_T2_TRGO ((uint32_t)0x00030000)
  356. #define ADC_ExternalTrigInjecConv_T3_CC2 ((uint32_t)0x00040000)
  357. #define ADC_ExternalTrigInjecConv_T3_CC4 ((uint32_t)0x00050000)
  358. #define ADC_ExternalTrigInjecConv_T4_CC1 ((uint32_t)0x00060000)
  359. #define ADC_ExternalTrigInjecConv_T4_CC2 ((uint32_t)0x00070000)
  360. #define ADC_ExternalTrigInjecConv_T4_CC3 ((uint32_t)0x00080000)
  361. #define ADC_ExternalTrigInjecConv_T4_TRGO ((uint32_t)0x00090000)
  362. #define ADC_ExternalTrigInjecConv_T5_CC4 ((uint32_t)0x000A0000)
  363. #define ADC_ExternalTrigInjecConv_T5_TRGO ((uint32_t)0x000B0000)
  364. #define ADC_ExternalTrigInjecConv_T8_CC2 ((uint32_t)0x000C0000)
  365. #define ADC_ExternalTrigInjecConv_T8_CC3 ((uint32_t)0x000D0000)
  366. #define ADC_ExternalTrigInjecConv_T8_CC4 ((uint32_t)0x000E0000)
  367. #define ADC_ExternalTrigInjecConv_Ext_IT15 ((uint32_t)0x000F0000)
  368. #define IS_ADC_EXT_INJEC_TRIG(INJTRIG) (((INJTRIG) == ADC_ExternalTrigInjecConv_T1_CC4) || \
  369. ((INJTRIG) == ADC_ExternalTrigInjecConv_T1_TRGO) || \
  370. ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_CC1) || \
  371. ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_TRGO) || \
  372. ((INJTRIG) == ADC_ExternalTrigInjecConv_T3_CC2) || \
  373. ((INJTRIG) == ADC_ExternalTrigInjecConv_T3_CC4) || \
  374. ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_CC1) || \
  375. ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_CC2) || \
  376. ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_CC3) || \
  377. ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_TRGO) || \
  378. ((INJTRIG) == ADC_ExternalTrigInjecConv_T5_CC4) || \
  379. ((INJTRIG) == ADC_ExternalTrigInjecConv_T5_TRGO) || \
  380. ((INJTRIG) == ADC_ExternalTrigInjecConv_T8_CC2) || \
  381. ((INJTRIG) == ADC_ExternalTrigInjecConv_T8_CC3) || \
  382. ((INJTRIG) == ADC_ExternalTrigInjecConv_T8_CC4) || \
  383. ((INJTRIG) == ADC_ExternalTrigInjecConv_Ext_IT15))
  384. /**
  385. * @}
  386. */
  387. /** @defgroup ADC_injected_channel_selection
  388. * @{
  389. */
  390. #define ADC_InjectedChannel_1 ((uint8_t)0x14)
  391. #define ADC_InjectedChannel_2 ((uint8_t)0x18)
  392. #define ADC_InjectedChannel_3 ((uint8_t)0x1C)
  393. #define ADC_InjectedChannel_4 ((uint8_t)0x20)
  394. #define IS_ADC_INJECTED_CHANNEL(CHANNEL) (((CHANNEL) == ADC_InjectedChannel_1) || \
  395. ((CHANNEL) == ADC_InjectedChannel_2) || \
  396. ((CHANNEL) == ADC_InjectedChannel_3) || \
  397. ((CHANNEL) == ADC_InjectedChannel_4))
  398. /**
  399. * @}
  400. */
  401. /** @defgroup ADC_analog_watchdog_selection
  402. * @{
  403. */
  404. #define ADC_AnalogWatchdog_SingleRegEnable ((uint32_t)0x00800200)
  405. #define ADC_AnalogWatchdog_SingleInjecEnable ((uint32_t)0x00400200)
  406. #define ADC_AnalogWatchdog_SingleRegOrInjecEnable ((uint32_t)0x00C00200)
  407. #define ADC_AnalogWatchdog_AllRegEnable ((uint32_t)0x00800000)
  408. #define ADC_AnalogWatchdog_AllInjecEnable ((uint32_t)0x00400000)
  409. #define ADC_AnalogWatchdog_AllRegAllInjecEnable ((uint32_t)0x00C00000)
  410. #define ADC_AnalogWatchdog_None ((uint32_t)0x00000000)
  411. #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_AnalogWatchdog_SingleRegEnable) || \
  412. ((WATCHDOG) == ADC_AnalogWatchdog_SingleInjecEnable) || \
  413. ((WATCHDOG) == ADC_AnalogWatchdog_SingleRegOrInjecEnable) || \
  414. ((WATCHDOG) == ADC_AnalogWatchdog_AllRegEnable) || \
  415. ((WATCHDOG) == ADC_AnalogWatchdog_AllInjecEnable) || \
  416. ((WATCHDOG) == ADC_AnalogWatchdog_AllRegAllInjecEnable) || \
  417. ((WATCHDOG) == ADC_AnalogWatchdog_None))
  418. /**
  419. * @}
  420. */
  421. /** @defgroup ADC_interrupts_definition
  422. * @{
  423. */
  424. #define ADC_IT_EOC ((uint16_t)0x0205)
  425. #define ADC_IT_AWD ((uint16_t)0x0106)
  426. #define ADC_IT_JEOC ((uint16_t)0x0407)
  427. #define ADC_IT_OVR ((uint16_t)0x201A)
  428. #define IS_ADC_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD) || \
  429. ((IT) == ADC_IT_JEOC)|| ((IT) == ADC_IT_OVR))
  430. /**
  431. * @}
  432. */
  433. /** @defgroup ADC_flags_definition
  434. * @{
  435. */
  436. #define ADC_FLAG_AWD ((uint8_t)0x01)
  437. #define ADC_FLAG_EOC ((uint8_t)0x02)
  438. #define ADC_FLAG_JEOC ((uint8_t)0x04)
  439. #define ADC_FLAG_JSTRT ((uint8_t)0x08)
  440. #define ADC_FLAG_STRT ((uint8_t)0x10)
  441. #define ADC_FLAG_OVR ((uint8_t)0x20)
  442. #define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xC0) == 0x00) && ((FLAG) != 0x00))
  443. #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_AWD) || \
  444. ((FLAG) == ADC_FLAG_EOC) || \
  445. ((FLAG) == ADC_FLAG_JEOC) || \
  446. ((FLAG)== ADC_FLAG_JSTRT) || \
  447. ((FLAG) == ADC_FLAG_STRT) || \
  448. ((FLAG)== ADC_FLAG_OVR))
  449. /**
  450. * @}
  451. */
  452. /** @defgroup ADC_thresholds
  453. * @{
  454. */
  455. #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF)
  456. /**
  457. * @}
  458. */
  459. /** @defgroup ADC_injected_offset
  460. * @{
  461. */
  462. #define IS_ADC_OFFSET(OFFSET) ((OFFSET) <= 0xFFF)
  463. /**
  464. * @}
  465. */
  466. /** @defgroup ADC_injected_length
  467. * @{
  468. */
  469. #define IS_ADC_INJECTED_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x4))
  470. /**
  471. * @}
  472. */
  473. /** @defgroup ADC_injected_rank
  474. * @{
  475. */
  476. #define IS_ADC_INJECTED_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x4))
  477. /**
  478. * @}
  479. */
  480. /** @defgroup ADC_regular_length
  481. * @{
  482. */
  483. #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x10))
  484. /**
  485. * @}
  486. */
  487. /** @defgroup ADC_regular_rank
  488. * @{
  489. */
  490. #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x10))
  491. /**
  492. * @}
  493. */
  494. /** @defgroup ADC_regular_discontinuous_mode_number
  495. * @{
  496. */
  497. #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 0x1) && ((NUMBER) <= 0x8))
  498. /**
  499. * @}
  500. */
  501. /**
  502. * @}
  503. */
  504. /* Exported macro ------------------------------------------------------------*/
  505. /* Exported functions --------------------------------------------------------*/
  506. /* Function used to set the ADC configuration to the default reset state *****/
  507. void ADC_DeInit(void);
  508. /* Initialization and Configuration functions *********************************/
  509. void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
  510. void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
  511. void ADC_CommonInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct);
  512. void ADC_CommonStructInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct);
  513. void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  514. /* Analog Watchdog configuration functions ************************************/
  515. void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog);
  516. void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,uint16_t LowThreshold);
  517. void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel);
  518. /* Temperature Sensor, Vrefint and VBAT management functions ******************/
  519. void ADC_TempSensorVrefintCmd(FunctionalState NewState);
  520. void ADC_VBATCmd(FunctionalState NewState);
  521. /* Regular Channels Configuration functions ***********************************/
  522. void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  523. void ADC_SoftwareStartConv(ADC_TypeDef* ADCx);
  524. FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx);
  525. void ADC_EOCOnEachRegularChannelCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  526. void ADC_ContinuousModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  527. void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number);
  528. void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  529. uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);
  530. uint32_t ADC_GetMultiModeConversionValue(void);
  531. /* Regular Channels DMA Configuration functions *******************************/
  532. void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  533. void ADC_DMARequestAfterLastTransferCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  534. void ADC_MultiModeDMARequestAfterLastTransferCmd(FunctionalState NewState);
  535. /* Injected channels Configuration functions **********************************/
  536. void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  537. void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length);
  538. void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset);
  539. void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv);
  540. void ADC_ExternalTrigInjectedConvEdgeConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConvEdge);
  541. void ADC_SoftwareStartInjectedConv(ADC_TypeDef* ADCx);
  542. FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx);
  543. void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  544. void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  545. uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel);
  546. /* Interrupts and flags management functions **********************************/
  547. void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState);
  548. FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
  549. void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
  550. ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT);
  551. void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT);
  552. #ifdef __cplusplus
  553. }
  554. #endif
  555. #endif /*__STM32F2xx_ADC_H */
  556. /**
  557. * @}
  558. */
  559. /**
  560. * @}
  561. */