You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

330 lines
16 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of ADC HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_ADC_EX_H
  39. #define __STM32F7xx_ADC_EX_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup ADCEx
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup ADCEx_Exported_Types ADC Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief ADC Configuration injected Channel structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t InjectedChannel; /*!< Configure the ADC injected channel.
  61. This parameter can be a value of @ref ADC_channels */
  62. uint32_t InjectedRank; /*!< The rank in the injected group sequencer
  63. This parameter must be a number between Min_Data = 1 and Max_Data = 4. */
  64. uint32_t InjectedSamplingTime; /*!< The sample time value to be set for the selected channel.
  65. This parameter can be a value of @ref ADC_sampling_times */
  66. uint32_t InjectedOffset; /*!< Defines the offset to be subtracted from the raw converted data when convert injected channels.
  67. This parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF. */
  68. uint32_t InjectedNbrOfConversion; /*!< Specifies the number of ADC conversions that will be done using the sequencer for
  69. injected channel group.
  70. This parameter must be a number between Min_Data = 1 and Max_Data = 4. */
  71. uint32_t AutoInjectedConv; /*!< Enables or disables the selected ADC automatic injected group
  72. conversion after regular one */
  73. uint32_t InjectedDiscontinuousConvMode; /*!< Specifies whether the conversion is performed in Discontinuous mode or not for injected channels.
  74. This parameter can be set to ENABLE or DISABLE. */
  75. uint32_t ExternalTrigInjecConvEdge; /*!< Select the external trigger edge and enable the trigger of an injected channels.
  76. This parameter can be a value of @ref ADCEx_External_trigger_edge_Injected */
  77. uint32_t ExternalTrigInjecConv; /*!< Select the external event used to trigger the start of conversion of a injected channels.
  78. This parameter can be a value of @ref ADCEx_External_trigger_Source_Injected */
  79. }ADC_InjectionConfTypeDef;
  80. /**
  81. * @brief ADC Configuration multi-mode structure definition
  82. */
  83. typedef struct
  84. {
  85. uint32_t Mode; /*!< Configures the ADC to operate in independent or multi mode.
  86. This parameter can be a value of @ref ADCEx_Common_mode */
  87. uint32_t DMAAccessMode; /*!< Configures the Direct memory access mode for multi ADC mode.
  88. This parameter can be a value of @ref ADCEx_Direct_memory_access_mode_for_multi_mode */
  89. uint32_t TwoSamplingDelay; /*!< Configures the Delay between 2 sampling phases.
  90. This parameter can be a value of @ref ADC_delay_between_2_sampling_phases */
  91. }ADC_MultiModeTypeDef;
  92. /**
  93. * @}
  94. */
  95. /* Exported constants --------------------------------------------------------*/
  96. /** @defgroup ADCEx_Exported_Constants ADC Exported Constants
  97. * @{
  98. */
  99. /** @defgroup ADCEx_Common_mode ADC Common Mode
  100. * @{
  101. */
  102. #define ADC_MODE_INDEPENDENT ((uint32_t)0x00000000)
  103. #define ADC_DUALMODE_REGSIMULT_INJECSIMULT ((uint32_t)ADC_CCR_MULTI_0)
  104. #define ADC_DUALMODE_REGSIMULT_ALTERTRIG ((uint32_t)ADC_CCR_MULTI_1)
  105. #define ADC_DUALMODE_INJECSIMULT ((uint32_t)(ADC_CCR_MULTI_2 | ADC_CCR_MULTI_0))
  106. #define ADC_DUALMODE_REGSIMULT ((uint32_t)(ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1))
  107. #define ADC_DUALMODE_INTERL ((uint32_t)(ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1 | ADC_CCR_MULTI_0))
  108. #define ADC_DUALMODE_ALTERTRIG ((uint32_t)(ADC_CCR_MULTI_3 | ADC_CCR_MULTI_0))
  109. #define ADC_TRIPLEMODE_REGSIMULT_INJECSIMULT ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_0))
  110. #define ADC_TRIPLEMODE_REGSIMULT_AlterTrig ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_1))
  111. #define ADC_TRIPLEMODE_INJECSIMULT ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_2 | ADC_CCR_MULTI_0))
  112. #define ADC_TRIPLEMODE_REGSIMULT ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1))
  113. #define ADC_TRIPLEMODE_INTERL ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_2 | ADC_CCR_MULTI_1 | ADC_CCR_MULTI_0))
  114. #define ADC_TRIPLEMODE_ALTERTRIG ((uint32_t)(ADC_CCR_MULTI_4 | ADC_CCR_MULTI_3 | ADC_CCR_MULTI_0))
  115. /**
  116. * @}
  117. */
  118. /** @defgroup ADCEx_Direct_memory_access_mode_for_multi_mode ADC Direct Memory Access Mode For Multi Mode
  119. * @{
  120. */
  121. #define ADC_DMAACCESSMODE_DISABLED ((uint32_t)0x00000000) /*!< DMA mode disabled */
  122. #define ADC_DMAACCESSMODE_1 ((uint32_t)ADC_CCR_DMA_0) /*!< DMA mode 1 enabled (2 / 3 half-words one by one - 1 then 2 then 3)*/
  123. #define ADC_DMAACCESSMODE_2 ((uint32_t)ADC_CCR_DMA_1) /*!< DMA mode 2 enabled (2 / 3 half-words by pairs - 2&1 then 1&3 then 3&2)*/
  124. #define ADC_DMAACCESSMODE_3 ((uint32_t)ADC_CCR_DMA) /*!< DMA mode 3 enabled (2 / 3 bytes by pairs - 2&1 then 1&3 then 3&2) */
  125. /**
  126. * @}
  127. */
  128. /** @defgroup ADCEx_External_trigger_edge_Injected ADC External Trigger Edge Injected
  129. * @{
  130. */
  131. #define ADC_EXTERNALTRIGINJECCONVEDGE_NONE ((uint32_t)0x00000000)
  132. #define ADC_EXTERNALTRIGINJECCONVEDGE_RISING ((uint32_t)ADC_CR2_JEXTEN_0)
  133. #define ADC_EXTERNALTRIGINJECCONVEDGE_FALLING ((uint32_t)ADC_CR2_JEXTEN_1)
  134. #define ADC_EXTERNALTRIGINJECCONVEDGE_RISINGFALLING ((uint32_t)ADC_CR2_JEXTEN)
  135. /**
  136. * @}
  137. */
  138. /** @defgroup ADCEx_External_trigger_Source_Injected ADC External Trigger Source Injected
  139. * @{
  140. */
  141. #define ADC_EXTERNALTRIGINJECCONV_T1_TRGO ((uint32_t)0x00000000)
  142. #define ADC_EXTERNALTRIGINJECCONV_T1_CC4 ((uint32_t)ADC_CR2_JEXTSEL_0)
  143. #define ADC_EXTERNALTRIGINJECCONV_T2_TRGO ((uint32_t)ADC_CR2_JEXTSEL_1)
  144. #define ADC_EXTERNALTRIGINJECCONV_T2_CC1 ((uint32_t)(ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
  145. #define ADC_EXTERNALTRIGINJECCONV_T3_CC4 ((uint32_t)ADC_CR2_JEXTSEL_2)
  146. #define ADC_EXTERNALTRIGINJECCONV_T4_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0))
  147. #define ADC_EXTERNALTRIGINJECCONV_T8_CC4 ((uint32_t)(ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
  148. #define ADC_EXTERNALTRIGINJECCONV_T1_TRGO2 ((uint32_t)ADC_CR2_JEXTSEL_3)
  149. #define ADC_EXTERNALTRIGINJECCONV_T8_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_0))
  150. #define ADC_EXTERNALTRIGINJECCONV_T8_TRGO2 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_1))
  151. #define ADC_EXTERNALTRIGINJECCONV_T3_CC3 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
  152. #define ADC_EXTERNALTRIGINJECCONV_T5_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2))
  153. #define ADC_EXTERNALTRIGINJECCONV_T3_CC1 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0))
  154. #define ADC_EXTERNALTRIGINJECCONV_T6_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1))
  155. /**
  156. * @}
  157. */
  158. /** @defgroup ADCEx_injected_channel_selection ADC Injected Channel Selection
  159. * @{
  160. */
  161. #define ADC_INJECTED_RANK_1 ((uint32_t)0x00000001)
  162. #define ADC_INJECTED_RANK_2 ((uint32_t)0x00000002)
  163. #define ADC_INJECTED_RANK_3 ((uint32_t)0x00000003)
  164. #define ADC_INJECTED_RANK_4 ((uint32_t)0x00000004)
  165. /**
  166. * @}
  167. */
  168. /** @defgroup ADCEx_channels ADC Specific Channels
  169. * @{
  170. */
  171. #define ADC_CHANNEL_TEMPSENSOR ((uint32_t)ADC_CHANNEL_16)
  172. /**
  173. * @}
  174. */
  175. /**
  176. * @}
  177. */
  178. /* Exported macro ------------------------------------------------------------*/
  179. /** @defgroup ADC_Exported_Macros ADC Exported Macros
  180. * @{
  181. */
  182. /**
  183. * @}
  184. */
  185. /* Exported functions --------------------------------------------------------*/
  186. /** @addtogroup ADCEx_Exported_Functions
  187. * @{
  188. */
  189. /** @addtogroup ADCEx_Exported_Functions_Group1
  190. * @{
  191. */
  192. /* I/O operation functions ******************************************************/
  193. HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc);
  194. HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc);
  195. HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  196. HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc);
  197. HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc);
  198. uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank);
  199. HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
  200. HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc);
  201. uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc);
  202. void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc);
  203. /* Peripheral Control functions *************************************************/
  204. HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected);
  205. HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode);
  206. /**
  207. * @}
  208. */
  209. /**
  210. * @}
  211. */
  212. /* Private types -------------------------------------------------------------*/
  213. /* Private variables ---------------------------------------------------------*/
  214. /* Private constants ---------------------------------------------------------*/
  215. /** @defgroup ADCEx_Private_Constants ADC Private Constants
  216. * @{
  217. */
  218. /**
  219. * @}
  220. */
  221. /* Private macros ------------------------------------------------------------*/
  222. /** @defgroup ADCEx_Private_Macros ADC Private Macros
  223. * @{
  224. */
  225. #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) <= ADC_CHANNEL_18) || \
  226. ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR))
  227. #define IS_ADC_MODE(__MODE__) (((__MODE__) == ADC_MODE_INDEPENDENT) || \
  228. ((__MODE__) == ADC_DUALMODE_REGSIMULT_INJECSIMULT) || \
  229. ((__MODE__) == ADC_DUALMODE_REGSIMULT_ALTERTRIG) || \
  230. ((__MODE__) == ADC_DUALMODE_INJECSIMULT) || \
  231. ((__MODE__) == ADC_DUALMODE_REGSIMULT) || \
  232. ((__MODE__) == ADC_DUALMODE_INTERL) || \
  233. ((__MODE__) == ADC_DUALMODE_ALTERTRIG) || \
  234. ((__MODE__) == ADC_TRIPLEMODE_REGSIMULT_INJECSIMULT) || \
  235. ((__MODE__) == ADC_TRIPLEMODE_REGSIMULT_AlterTrig) || \
  236. ((__MODE__) == ADC_TRIPLEMODE_INJECSIMULT) || \
  237. ((__MODE__) == ADC_TRIPLEMODE_REGSIMULT) || \
  238. ((__MODE__) == ADC_TRIPLEMODE_INTERL) || \
  239. ((__MODE__) == ADC_TRIPLEMODE_ALTERTRIG))
  240. #define IS_ADC_DMA_ACCESS_MODE(__MODE__) (((__MODE__) == ADC_DMAACCESSMODE_DISABLED) || \
  241. ((__MODE__) == ADC_DMAACCESSMODE_1) || \
  242. ((__MODE__) == ADC_DMAACCESSMODE_2) || \
  243. ((__MODE__) == ADC_DMAACCESSMODE_3))
  244. #define IS_ADC_EXT_INJEC_TRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_NONE) || \
  245. ((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_RISING) || \
  246. ((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_FALLING) || \
  247. ((__EDGE__) == ADC_EXTERNALTRIGINJECCONVEDGE_RISINGFALLING))
  248. #define IS_ADC_EXT_INJEC_TRIG(__INJTRIG__) (((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO) || \
  249. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T1_CC4) || \
  250. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \
  251. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \
  252. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \
  253. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \
  254. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T8_CC4) || \
  255. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T1_TRGO2) || \
  256. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T8_TRGO) || \
  257. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T8_TRGO2) || \
  258. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T3_CC3) || \
  259. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T5_TRGO) || \
  260. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T3_CC1) || \
  261. ((__INJTRIG__) == ADC_EXTERNALTRIGINJECCONV_T6_TRGO))
  262. #define IS_ADC_INJECTED_LENGTH(__LENGTH__) (((__LENGTH__) >= ((uint32_t)1)) && ((__LENGTH__) <= ((uint32_t)4)))
  263. #define IS_ADC_INJECTED_RANK(__RANK__) (((__RANK__) >= ((uint32_t)1)) && ((__RANK__) <= ((uint32_t)4)))
  264. /**
  265. * @brief Set the selected injected Channel rank.
  266. * @param _CHANNELNB_: Channel number.
  267. * @param _RANKNB_: Rank number.
  268. * @param _JSQR_JL_: Sequence length.
  269. * @retval None
  270. */
  271. #define ADC_JSQR(_CHANNELNB_, _RANKNB_,_JSQR_JL_) (((uint32_t)((uint16_t)(_CHANNELNB_))) << (5 * (uint8_t)(((_RANKNB_) + 3) - (_JSQR_JL_))))
  272. /**
  273. * @}
  274. */
  275. /* Private functions ---------------------------------------------------------*/
  276. /** @defgroup ADCEx_Private_Functions ADC Private Functions
  277. * @{
  278. */
  279. /**
  280. * @}
  281. */
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. #ifdef __cplusplus
  289. }
  290. #endif
  291. #endif /*__STM32F7xx_ADC_EX_H */
  292. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/