stm32f2xx_adc.h 31 KB

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