HAL_adc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. /**
  2. ******************************************************************************
  3. * @file HAL_adc.h
  4. * @author AE Team
  5. * @version V2.0.0
  6. * @date 22/08/2017
  7. * @brief This file contains all the functions prototypes for the ADC firmware
  8. * library.
  9. ******************************************************************************
  10. * @copy
  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, MindMotion 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 2017 MindMotion</center></h2>
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __HAL_ADC_H
  23. #define __HAL_ADC_H
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "HAL_device.h"
  26. /** @addtogroup StdPeriph_Driver
  27. * @{
  28. */
  29. /** @addtogroup ADC
  30. * @{
  31. */
  32. /** @defgroup ADC_Exported_Types
  33. * @{
  34. */
  35. /**
  36. * @brief ADC Init structure definition
  37. */
  38. /*
  39. typedef struct
  40. {
  41. uint32_t ADC_Mode;
  42. FunctionalState ADC_ScanConvMode;
  43. FunctionalState ADC_ContinuousConvMode;
  44. uint32_t ADC_ExternalTrigConv;
  45. uint32_t ADC_DataAlign;
  46. uint8_t ADC_NbrOfChannel;
  47. }ADC_InitTypeDef;
  48. */
  49. typedef struct
  50. {
  51. uint32_t ADC_Resolution;
  52. uint32_t ADC_PRESCARE;
  53. uint32_t ADC_Mode;
  54. FunctionalState ADC_ContinuousConvMode;
  55. uint32_t ADC_TRGEN;
  56. uint32_t ADC_ExternalTrigConv;
  57. uint32_t ADC_DataAlign;
  58. }ADC_InitTypeDef;
  59. /**
  60. * @}
  61. */
  62. /** @defgroup ADC_Exported_Constants
  63. * @{
  64. */
  65. #define IS_ADC_ALL_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == ADC1_BASE) || \
  66. ((*(uint32_t*)&(PERIPH)) == ADC2_BASE))
  67. #define IS_ADC_DMA_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == ADC1_BASE) || \
  68. ((*(uint32_t*)&(PERIPH)) == ADC2_BASE))
  69. /** @defgroup ADC_Resolution
  70. * @{
  71. */
  72. #define ADC_Resolution_12b ((uint32_t)0x00000000)
  73. #define ADC_Resolution_11b ((uint32_t)0x00000080)
  74. #define ADC_Resolution_10b ((uint32_t)0x00000100)
  75. #define ADC_Resolution_9b ((uint32_t)0x00000180)
  76. #define ADC_Resolution_8b ((uint32_t)0x00000200)
  77. #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_Resolution_12b) || \
  78. ((RESOLUTION) == ADC_Resolution_10b) || \
  79. ((RESOLUTION) == ADC_Resolution_8b) || \
  80. ((RESOLUTION) == ADC_Resolution_6b))
  81. /**
  82. * @brief for ADC1, ADC2
  83. */
  84. #define ADC_PCLK2_PRESCARE_2 ((uint32_t)0x00000000)
  85. #define ADC_PCLK2_PRESCARE_4 ((uint32_t)0x00000010)
  86. #define ADC_PCLK2_PRESCARE_6 ((uint32_t)0x00000020)
  87. #define ADC_PCLK2_PRESCARE_8 ((uint32_t)0x00000030)
  88. #define ADC_PCLK2_PRESCARE_10 ((uint32_t)0x00000040)
  89. #define ADC_PCLK2_PRESCARE_12 ((uint32_t)0x00000050)
  90. #define ADC_PCLK2_PRESCARE_14 ((uint32_t)0x00000060)
  91. #define ADC_PCLK2_PRESCARE_16 ((uint32_t)0x00000070)
  92. /** @defgroup ADC_dual_mode
  93. * @{
  94. */
  95. #define ADC_Mode_Single ((uint32_t)0x00000000)
  96. #define ADC_Mode_Single_Period ((uint32_t)0x00000200)
  97. #define ADC_Mode_Continuous_Scan ((uint32_t)0x00000400)
  98. #define IS_ADC_MODE(MODE) (((MODE) == ADC_Mode_Single) || \
  99. ((MODE) == ADC_Mode_Single_Period) || \
  100. ((MODE) == ADC_Mode_Continuous_Scan))
  101. /**
  102. * @}
  103. */
  104. #define ADC_TRG_Disable ((uint32_t)0xfffffffB)
  105. #define ADC_TRG_Enable ((uint32_t)0x00000004)
  106. /** @defgroup ADC_extrenal_trigger_sources_for_regular_channels_conversion
  107. * @{
  108. */
  109. /**
  110. * @brief for ADC1
  111. */
  112. #define ADC_ExternalTrigConv_T1_CC1 ((uint32_t)0x00000000)
  113. #define ADC_ExternalTrigConv_T1_CC2 ((uint32_t)0x00000010)
  114. #define ADC_ExternalTrigConv_T1_CC3 ((uint32_t)0x00000020)
  115. #define ADC_ExternalTrigConv_T2_CC2 ((uint32_t)0x00000030)
  116. #define ADC_ExternalTrigConv_T3_TRGO ((uint32_t)0x00000040)
  117. #define ADC_ExternalTrigConv_T3_CC1 ((uint32_t)0x00000060)
  118. #define ADC_ExternalTrigConv_EXTI_11 ((uint32_t)0x00000070)
  119. #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_ExternalTrigConv_T1_CC1) || \
  120. ((REGTRIG) == ADC_ExternalTrigConv_T1_CC2) || \
  121. ((REGTRIG) == ADC_ExternalTrigConv_T1_CC3) || \
  122. ((REGTRIG) == ADC_ExternalTrigConv_T2_CC2) || \
  123. ((REGTRIG) == ADC_ExternalTrigConv_T3_TRGO) || \
  124. ((REGTRIG) == ADC_ExternalTrigConv_T4_CC4) || \
  125. ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \
  126. ((REGTRIG) == ADC_ExternalTrigConv_EXTI_11) || \
  127. ((REGTRIG) == ADC_ExternalTrigConv_T1_TRGO) || \
  128. ((REGTRIG) == ADC_ExternalTrigConv_T1_CC4) || \
  129. ((REGTRIG) == ADC_ExternalTrigConv_T2_TRGO) || \
  130. ((REGTRIG) == ADC_ExternalTrigConv_T2_CC1) || \
  131. ((REGTRIG) == ADC_ExternalTrigConv_T3_CC4) || \
  132. ((REGTRIG) == ADC_ExternalTrigConv_T4_TRGO) || \
  133. ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \
  134. ((REGTRIG) == ADC_ExternalTrigConv_EXTI_15))
  135. /**
  136. * @}
  137. */
  138. /** @defgroup ADC_data_align
  139. * @{
  140. */
  141. #define ADC_DataAlign_Right ((uint32_t)0x00000000)
  142. #define ADC_DataAlign_Left ((uint32_t)0x00000800)
  143. #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \
  144. ((ALIGN) == ADC_DataAlign_Left))
  145. /**
  146. * @}
  147. */
  148. /** @defgroup ADC_channels
  149. * @{
  150. */
  151. #define ADC_Channel_0 ((uint8_t)0x00)
  152. #define ADC_Channel_1 ((uint8_t)0x01)
  153. #define ADC_Channel_2 ((uint8_t)0x02)
  154. #define ADC_Channel_3 ((uint8_t)0x03)
  155. #define ADC_Channel_4 ((uint8_t)0x04)
  156. #define ADC_Channel_5 ((uint8_t)0x05)
  157. #define ADC_Channel_6 ((uint8_t)0x06)
  158. #define ADC_Channel_7 ((uint8_t)0x07)
  159. #define ADC_Channel_8 ((uint8_t)0x08)
  160. #define ADC_Channel_9 ((uint8_t)0x09)
  161. #define ADC_Channel_10 ((uint8_t)0x0A) //tempsensor
  162. #define ADC_Channel_11 ((uint8_t)0x0B)//vref 1.2V
  163. #define ADC_Channel_All ((uint8_t)0x0f)
  164. #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_Channel_0) || ((CHANNEL) == ADC_Channel_1) || \
  165. ((CHANNEL) == ADC_Channel_2) || ((CHANNEL) == ADC_Channel_3) || \
  166. ((CHANNEL) == ADC_Channel_4) || ((CHANNEL) == ADC_Channel_5) || \
  167. ((CHANNEL) == ADC_Channel_6) || ((CHANNEL) == ADC_Channel_7) || \
  168. ((CHANNEL) == ADC_Channel_8) || ((CHANNEL) == ADC_Channel_All))
  169. /** @defgroup ADC_sampling_times
  170. * @{
  171. */
  172. #define ADC_SampleTime_1_5Cycles ((uint8_t)0x00)
  173. #define ADC_SampleTime_7_5Cycles ((uint8_t)0x01)
  174. #define ADC_SampleTime_13_5Cycles ((uint8_t)0x02)
  175. #define ADC_SampleTime_28_5Cycles ((uint8_t)0x03)
  176. #define ADC_SampleTime_41_5Cycles ((uint8_t)0x04)
  177. #define ADC_SampleTime_55_5Cycles ((uint8_t)0x05)
  178. #define ADC_SampleTime_71_5Cycles ((uint8_t)0x06)
  179. #define ADC_SampleTime_239_5Cycles ((uint8_t)0x07)
  180. #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SampleTime_1_5Cycles) || \
  181. ((TIME) == ADC_SampleTime_7_5Cycles) || \
  182. ((TIME) == ADC_SampleTime_13_5Cycles) || \
  183. ((TIME) == ADC_SampleTime_28_5Cycles) || \
  184. ((TIME) == ADC_SampleTime_41_5Cycles) || \
  185. ((TIME) == ADC_SampleTime_55_5Cycles) || \
  186. ((TIME) == ADC_SampleTime_71_5Cycles) || \
  187. ((TIME) == ADC_SampleTime_239_5Cycles))
  188. /** @defgroup ADC_analog_watchdog_selection
  189. * @{
  190. */
  191. #define ADC_AnalogWatchdog_SingleRegEnable ((uint32_t)0x00000002)
  192. #define ADC_AnalogWatchdog_None ((uint32_t)0x00000000)
  193. #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_AnalogWatchdog_SingleRegEnable) || \
  194. ((WATCHDOG) == ADC_AnalogWatchdog_None))
  195. /**
  196. * @}
  197. */
  198. /** @defgroup ADC_interrupts_definition
  199. * @{
  200. */
  201. #define ADC_IT_EOC ((uint16_t)0x0001)
  202. #define ADC_IT_AWD ((uint16_t)0x0002)
  203. #define IS_ADC_IT(IT) ((((IT) & (uint16_t)0xFFFC) == 0x00) && ((IT) != 0x00))
  204. #define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD))
  205. /**
  206. * @}
  207. */
  208. /** @defgroup ADC_flags_definition
  209. * @{
  210. */
  211. #define ADC_FLAG_AWD ((uint8_t)0x02) //ADWIF ±È½Ï±ê־λ
  212. #define ADC_FLAG_EOC ((uint8_t)0x01) //ADIF ת»»½áÊø±ê־λ
  213. #define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xF0) == 0x00) && ((FLAG) != 0x00))
  214. #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_AWD) || ((FLAG) == ADC_FLAG_EOC))
  215. /**
  216. * @}
  217. */
  218. /** @defgroup ADC_Exported_Functions
  219. * @{
  220. */
  221. void ADC_DeInit(ADC_TypeDef* ADCx);
  222. void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
  223. void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
  224. void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  225. void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  226. void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState);
  227. void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  228. FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx);
  229. void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
  230. void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  231. uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);
  232. void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv);
  233. void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  234. void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  235. void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx,FunctionalState NewState);
  236. void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
  237. void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel);
  238. void ADC_TempSensorCmd(FunctionalState NewState);
  239. void ADC_VrefintCmd(FunctionalState NewState);
  240. FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
  241. void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
  242. ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT);
  243. void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT);
  244. #endif /*__HAL_ADC_H */
  245. /**
  246. * @}
  247. */
  248. /**
  249. * @}
  250. */
  251. /**
  252. * @}
  253. */
  254. /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/