stm32f4xx_adc.h 31 KB

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