stm32f3xx_hal_adc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file containing functions prototypes of ADC HAL library.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef __STM32F3xx_ADC_H
  20. #define __STM32F3xx_ADC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f3xx_hal_def.h"
  26. /* Include ADC HAL Extended module */
  27. /* (include on top of file since ADC structures are defined in extended file) */
  28. #include "stm32f3xx_hal_adc_ex.h"
  29. /** @addtogroup STM32F3xx_HAL_Driver
  30. * @{
  31. */
  32. /** @addtogroup ADC
  33. * @{
  34. */
  35. /* Exported types ------------------------------------------------------------*/
  36. /** @defgroup ADC_Exported_Types ADC Exported Types
  37. * @{
  38. */
  39. /**
  40. * @brief HAL ADC state machine: ADC states definition (bitfields)
  41. * @note ADC state machine is managed by bitfields, state must be compared
  42. * with bit by bit.
  43. * For example:
  44. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_REG_BUSY)) "
  45. * " if (HAL_IS_BIT_SET(HAL_ADC_GetState(hadc1), HAL_ADC_STATE_AWD1) ) "
  46. */
  47. /* States of ADC global scope */
  48. #define HAL_ADC_STATE_RESET (0x00000000U) /*!< ADC not yet initialized or disabled */
  49. #define HAL_ADC_STATE_READY (0x00000001U) /*!< ADC peripheral ready for use */
  50. #define HAL_ADC_STATE_BUSY_INTERNAL (0x00000002U) /*!< ADC is busy to internal process (initialization, calibration) */
  51. #define HAL_ADC_STATE_TIMEOUT (0x00000004U) /*!< TimeOut occurrence */
  52. /* States of ADC errors */
  53. #define HAL_ADC_STATE_ERROR_INTERNAL (0x00000010U) /*!< Internal error occurrence */
  54. #define HAL_ADC_STATE_ERROR_CONFIG (0x00000020U) /*!< Configuration error occurrence */
  55. #define HAL_ADC_STATE_ERROR_DMA (0x00000040U) /*!< DMA error occurrence */
  56. /* States of ADC group regular */
  57. #define HAL_ADC_STATE_REG_BUSY (0x00000100U) /*!< A conversion on group regular is ongoing or can occur (either by continuous mode,
  58. external trigger, low power auto power-on, multimode ADC master control) */
  59. #define HAL_ADC_STATE_REG_EOC (0x00000200U) /*!< Conversion data available on group regular */
  60. #define HAL_ADC_STATE_REG_OVR (0x00000400U) /*!< Overrun occurrence */
  61. #define HAL_ADC_STATE_REG_EOSMP (0x00000800U) /*!< End Of Sampling flag raised */
  62. /* States of ADC group injected */
  63. #define HAL_ADC_STATE_INJ_BUSY (0x00001000U) /*!< A conversion on group injected is ongoing or can occur (either by auto-injection mode,
  64. external trigger, low power auto power-on, multimode ADC master control) */
  65. #define HAL_ADC_STATE_INJ_EOC (0x00002000U) /*!< Conversion data available on group injected */
  66. #define HAL_ADC_STATE_INJ_JQOVF (0x00004000U) /*!< Injected queue overflow occurrence */
  67. /* States of ADC analog watchdogs */
  68. #define HAL_ADC_STATE_AWD1 (0x00010000U) /*!< Out-of-window occurrence of analog watchdog 1 */
  69. #define HAL_ADC_STATE_AWD2 (0x00020000U) /*!< Out-of-window occurrence of analog watchdog 2 */
  70. #define HAL_ADC_STATE_AWD3 (0x00040000U) /*!< Out-of-window occurrence of analog watchdog 3 */
  71. /* States of ADC multi-mode */
  72. #define HAL_ADC_STATE_MULTIMODE_SLAVE (0x00100000U) /*!< ADC in multimode slave state, controlled by another ADC master ( */
  73. /**
  74. * @brief ADC handle Structure definition
  75. */
  76. typedef struct __ADC_HandleTypeDef
  77. {
  78. ADC_TypeDef *Instance; /*!< Register base address */
  79. ADC_InitTypeDef Init; /*!< ADC required parameters */
  80. DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
  81. HAL_LockTypeDef Lock; /*!< ADC locking object */
  82. __IO uint32_t State; /*!< ADC communication state (bitmap of ADC states) */
  83. __IO uint32_t ErrorCode; /*!< ADC Error code */
  84. #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
  85. defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
  86. defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
  87. defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  88. ADC_InjectionConfigTypeDef InjectionConfig ; /*!< ADC injected channel configuration build-up structure */
  89. #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
  90. /* STM32F302xC || STM32F303xC || STM32F358xx || */
  91. /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
  92. /* STM32F301x8 || STM32F302x8 || STM32F318xx */
  93. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  94. void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion complete callback */
  95. void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion DMA half-transfer callback */
  96. void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 1 callback */
  97. void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC error callback */
  98. void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC group injected conversion complete callback */ /*!< ADC end of sampling callback */
  99. void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp Init callback */
  100. void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp DeInit callback */
  101. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  102. }ADC_HandleTypeDef;
  103. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  104. /**
  105. * @brief HAL ADC Callback ID enumeration definition
  106. */
  107. typedef enum
  108. {
  109. HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U, /*!< ADC conversion complete callback ID */
  110. HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U, /*!< ADC conversion DMA half-transfer callback ID */
  111. HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U, /*!< ADC analog watchdog 1 callback ID */
  112. HAL_ADC_ERROR_CB_ID = 0x03U, /*!< ADC error callback ID */
  113. HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U, /*!< ADC group injected conversion complete callback ID */
  114. HAL_ADC_MSPINIT_CB_ID = 0x09U, /*!< ADC Msp Init callback ID */
  115. HAL_ADC_MSPDEINIT_CB_ID = 0x0AU /*!< ADC Msp DeInit callback ID */
  116. } HAL_ADC_CallbackIDTypeDef;
  117. /**
  118. * @brief HAL ADC Callback pointer definition
  119. */
  120. typedef void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
  121. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  122. /**
  123. * @}
  124. */
  125. /* Exported constants --------------------------------------------------------*/
  126. /* Exported macros -----------------------------------------------------------*/
  127. /** @defgroup ADC_Exported_Macro ADC Exported Macros
  128. * @{
  129. */
  130. /** @brief Reset ADC handle state
  131. * @param __HANDLE__ ADC handle
  132. * @retval None
  133. */
  134. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  135. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  136. do{ \
  137. (__HANDLE__)->State = HAL_ADC_STATE_RESET; \
  138. (__HANDLE__)->MspInitCallback = NULL; \
  139. (__HANDLE__)->MspDeInitCallback = NULL; \
  140. } while(0)
  141. #else
  142. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  143. ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  144. #endif
  145. /**
  146. * @}
  147. */
  148. /* Exported functions --------------------------------------------------------*/
  149. /** @addtogroup ADC_Exported_Functions ADC Exported Functions
  150. * @{
  151. */
  152. /** @addtogroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
  153. * @{
  154. */
  155. /* Initialization and de-initialization functions **********************************/
  156. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
  157. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  158. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
  159. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
  160. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  161. /* Callbacks Register/UnRegister functions ***********************************/
  162. HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, pADC_CallbackTypeDef pCallback);
  163. HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
  164. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  165. /**
  166. * @}
  167. */
  168. /** @addtogroup ADC_Exported_Functions_Group2 Input and Output operation functions
  169. * @{
  170. */
  171. /* Blocking mode: Polling */
  172. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
  173. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
  174. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  175. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
  176. /* Non-blocking mode: Interruption */
  177. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
  178. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
  179. /* Non-blocking mode: DMA */
  180. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
  181. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
  182. /* ADC retrieve conversion value intended to be used with polling or interruption */
  183. uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
  184. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
  185. void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
  186. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
  187. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
  188. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
  189. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  190. /**
  191. * @}
  192. */
  193. /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions
  194. * @{
  195. */
  196. /* Peripheral Control functions ***********************************************/
  197. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
  198. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
  199. /**
  200. * @}
  201. */
  202. /** @defgroup ADC_Exported_Functions_Group4 Peripheral State functions
  203. * @brief ADC Peripheral State functions
  204. * @{
  205. */
  206. /* Peripheral State functions *************************************************/
  207. uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
  208. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */
  215. /**
  216. * @}
  217. */
  218. /**
  219. * @}
  220. */
  221. #ifdef __cplusplus
  222. }
  223. #endif
  224. #endif /*__STM32F3xx_ADC_H */