Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

573 lines
35 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_hal_adc_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC HAL Extension module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32L1xx_HAL_ADC_EX_H
  21. #define __STM32L1xx_HAL_ADC_EX_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx_hal_def.h"
  27. /** @addtogroup STM32L1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup ADCEx
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup ADCEx_Exported_Types ADCEx Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief ADC Configuration injected Channel structure definition
  39. * @note Parameters of this structure are shared within 2 scopes:
  40. * - Scope channel: InjectedChannel, InjectedRank, InjectedSamplingTime, InjectedOffset
  41. * - Scope injected group (affects all channels of injected group): InjectedNbrOfConversion, InjectedDiscontinuousConvMode,
  42. * AutoInjectedConv, ExternalTrigInjecConvEdge, ExternalTrigInjecConv.
  43. * @note The setting of these parameters with function HAL_ADCEx_InjectedConfigChannel() is conditioned to ADC state.
  44. * ADC state can be either:
  45. * - For all parameters: ADC disabled
  46. * - For all except parameters 'InjectedDiscontinuousConvMode' and 'AutoInjectedConv': ADC enabled without conversion on going on injected group.
  47. * - For parameters 'ExternalTrigInjecConv' and 'ExternalTrigInjecConvEdge': ADC enabled, even with conversion on going on injected group.
  48. */
  49. typedef struct
  50. {
  51. uint32_t InjectedChannel; /*!< Selection of ADC channel to configure
  52. This parameter can be a value of @ref ADC_channels
  53. Note: Depending on devices, some channels may not be available on package pins. Refer to device datasheet for channels availability. */
  54. uint32_t InjectedRank; /*!< Rank in the injected group sequencer
  55. This parameter must be a value of @ref ADCEx_injected_rank
  56. Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel setting (or parameter number of conversions can be adjusted) */
  57. uint32_t InjectedSamplingTime; /*!< Sampling time value to be set for the selected channel.
  58. Unit: ADC clock cycles
  59. Conversion time is the addition of sampling time and processing time (12 ADC clock cycles at ADC resolution 12 bits, 11 cycles at 10 bits, 9 cycles at 8 bits, 7 cycles at 6 bits).
  60. This parameter can be a value of @ref ADC_sampling_times
  61. Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups.
  62. If this same channel has been previously configured in the other group (regular/injected), it will be updated to last setting.
  63. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
  64. sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
  65. Refer to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 4us min). */
  66. uint32_t InjectedOffset; /*!< Defines the offset to be subtracted from the raw converted data (for channels set on injected group only).
  67. Offset value must be a positive number.
  68. Depending of ADC resolution selected (12, 10, 8 or 6 bits),
  69. this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. */
  70. uint32_t InjectedNbrOfConversion; /*!< Specifies the number of ranks that will be converted within the injected group sequencer.
  71. To use the injected group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
  72. This parameter must be a number between Min_Data = 1 and Max_Data = 4.
  73. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  74. configure a channel on injected group can impact the configuration of other channels previously set. */
  75. FunctionalState InjectedDiscontinuousConvMode; /*!< Specifies whether the conversions sequence of injected group is performed in Complete-sequence/Discontinuous-sequence (main sequence subdivided in successive parts).
  76. Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
  77. Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
  78. This parameter can be set to ENABLE or DISABLE.
  79. Note: For injected group, number of discontinuous ranks increment is fixed to one-by-one.
  80. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  81. configure a channel on injected group can impact the configuration of other channels previously set. */
  82. FunctionalState AutoInjectedConv; /*!< Enables or disables the selected ADC automatic injected group conversion after regular one
  83. This parameter can be set to ENABLE or DISABLE.
  84. Note: To use Automatic injected conversion, discontinuous mode must be disabled ('DiscontinuousConvMode' and 'InjectedDiscontinuousConvMode' set to DISABLE)
  85. Note: To use Automatic injected conversion, injected group external triggers must be disabled ('ExternalTrigInjecConv' set to ADC_SOFTWARE_START)
  86. Note: In case of DMA used with regular group: if DMA configured in normal mode (single shot) JAUTO will be stopped upon DMA transfer complete.
  87. To maintain JAUTO always enabled, DMA must be configured in circular mode.
  88. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  89. configure a channel on injected group can impact the configuration of other channels previously set. */
  90. uint32_t ExternalTrigInjecConv; /*!< Selects the external event used to trigger the conversion start of injected group.
  91. If set to ADC_INJECTED_SOFTWARE_START, external triggers are disabled.
  92. If set to external trigger source, triggering is on event rising edge.
  93. This parameter can be a value of @ref ADCEx_External_trigger_source_Injected
  94. Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
  95. If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behaviour in case of another parameter update on the fly)
  96. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  97. configure a channel on injected group can impact the configuration of other channels previously set. */
  98. uint32_t ExternalTrigInjecConvEdge; /*!< Selects the external trigger edge of injected group.
  99. This parameter can be a value of @ref ADCEx_External_trigger_edge_Injected.
  100. If trigger is set to ADC_INJECTED_SOFTWARE_START, this parameter is discarded.
  101. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  102. configure a channel on injected group can impact the configuration of other channels previously set. */
  103. }ADC_InjectionConfTypeDef;
  104. /**
  105. * @}
  106. */
  107. /* Exported constants --------------------------------------------------------*/
  108. /** @defgroup ADCEx_Exported_Constants ADCEx Exported Constants
  109. * @{
  110. */
  111. /** @defgroup ADCEx_injected_rank ADCEx rank into injected group
  112. * @{
  113. */
  114. #define ADC_INJECTED_RANK_1 (0x00000001U)
  115. #define ADC_INJECTED_RANK_2 (0x00000002U)
  116. #define ADC_INJECTED_RANK_3 (0x00000003U)
  117. #define ADC_INJECTED_RANK_4 (0x00000004U)
  118. /**
  119. * @}
  120. */
  121. /** @defgroup ADCEx_External_trigger_edge_Injected ADCEx external trigger enable for injected group
  122. * @{
  123. */
  124. #define ADC_EXTERNALTRIGINJECCONV_EDGE_NONE (0x00000000U)
  125. #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISING ((uint32_t)ADC_CR2_JEXTEN_0)
  126. #define ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING ((uint32_t)ADC_CR2_JEXTEN_1)
  127. #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING ((uint32_t)ADC_CR2_JEXTEN)
  128. /**
  129. * @}
  130. */
  131. /** @defgroup ADCEx_External_trigger_source_Injected ADCEx External trigger source Injected
  132. * @{
  133. */
  134. /* External triggers for injected groups of ADC1 */
  135. #define ADC_EXTERNALTRIGINJECCONV_T2_CC1 ADC_EXTERNALTRIGINJEC_T2_CC1
  136. #define ADC_EXTERNALTRIGINJECCONV_T2_TRGO ADC_EXTERNALTRIGINJEC_T2_TRGO
  137. #define ADC_EXTERNALTRIGINJECCONV_T3_CC4 ADC_EXTERNALTRIGINJEC_T3_CC4
  138. #define ADC_EXTERNALTRIGINJECCONV_T4_TRGO ADC_EXTERNALTRIGINJEC_T4_TRGO
  139. #define ADC_EXTERNALTRIGINJECCONV_T4_CC1 ADC_EXTERNALTRIGINJEC_T4_CC1
  140. #define ADC_EXTERNALTRIGINJECCONV_T4_CC2 ADC_EXTERNALTRIGINJEC_T4_CC2
  141. #define ADC_EXTERNALTRIGINJECCONV_T4_CC3 ADC_EXTERNALTRIGINJEC_T4_CC3
  142. #define ADC_EXTERNALTRIGINJECCONV_T7_TRGO ADC_EXTERNALTRIGINJEC_T7_TRGO
  143. #define ADC_EXTERNALTRIGINJECCONV_T9_CC1 ADC_EXTERNALTRIGINJEC_T9_CC1
  144. #define ADC_EXTERNALTRIGINJECCONV_T9_TRGO ADC_EXTERNALTRIGINJEC_T9_TRGO
  145. #define ADC_EXTERNALTRIGINJECCONV_T10_CC1 ADC_EXTERNALTRIGINJEC_T10_CC1
  146. #define ADC_EXTERNALTRIGINJECCONV_EXT_IT15 ADC_EXTERNALTRIGINJEC_EXT_IT15
  147. #define ADC_INJECTED_SOFTWARE_START (0x00000010U)
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /* Private constants ---------------------------------------------------------*/
  155. /** @addtogroup ADCEx_Private_Constants ADCEx Private Constants
  156. * @{
  157. */
  158. /** @defgroup ADCEx_Internal_HAL_driver_Ext_trig_src_Injected ADCEx Internal HAL driver Ext trig src Injected
  159. * @{
  160. */
  161. /* List of external triggers of injected group for ADC1: */
  162. /* (used internally by HAL driver. To not use into HAL structure parameters) */
  163. #define ADC_EXTERNALTRIGINJEC_T9_CC1 (0x00000000U)
  164. #define ADC_EXTERNALTRIGINJEC_T9_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_0))
  165. #define ADC_EXTERNALTRIGINJEC_T2_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_1 ))
  166. #define ADC_EXTERNALTRIGINJEC_T2_CC1 ((uint32_t)( ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
  167. #define ADC_EXTERNALTRIGINJEC_T3_CC4 ((uint32_t)( ADC_CR2_JEXTSEL_2 ))
  168. #define ADC_EXTERNALTRIGINJEC_T4_TRGO ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_0))
  169. #define ADC_EXTERNALTRIGINJEC_T4_CC1 ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 ))
  170. #define ADC_EXTERNALTRIGINJEC_T4_CC2 ((uint32_t)( ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
  171. #define ADC_EXTERNALTRIGINJEC_T4_CC3 ((uint32_t)(ADC_CR2_JEXTSEL_3 ))
  172. #define ADC_EXTERNALTRIGINJEC_T10_CC1 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_0))
  173. #define ADC_EXTERNALTRIGINJEC_T7_TRGO ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_1 ))
  174. #define ADC_EXTERNALTRIGINJEC_EXT_IT15 ((uint32_t)(ADC_CR2_JEXTSEL_3 | ADC_CR2_JEXTSEL_2 | ADC_CR2_JEXTSEL_1 | ADC_CR2_JEXTSEL_0))
  175. /**
  176. * @}
  177. */
  178. /**
  179. * @}
  180. */
  181. /* Exported macro ------------------------------------------------------------*/
  182. /** @defgroup ADCEx_Exported_Macros ADCEx Exported Macros
  183. * @{
  184. */
  185. /* Macro for internal HAL driver usage, and possibly can be used into code of */
  186. /* final user. */
  187. /**
  188. * @brief Selection of channels bank.
  189. * Note: Banks availability depends on devices categories.
  190. * This macro is intended to change bank selection quickly on the fly,
  191. * without going through ADC init structure update and execution of function
  192. * 'HAL_ADC_Init()'.
  193. * @param __HANDLE__: ADC handle
  194. * @param __BANK__: Bank selection. This parameter can be a value of @ref ADC_ChannelsBank.
  195. * @retval None
  196. */
  197. #define __HAL_ADC_CHANNELS_BANK(__HANDLE__, __BANK__) \
  198. MODIFY_REG((__HANDLE__)->Instance->CR2, ADC_CR2_CFG, (__BANK__))
  199. #if defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  200. /**
  201. * @brief Configures the ADC channels speed.
  202. * Limited to channels 3, 8, 13 and to devices category Cat.3, Cat.4, Cat.5.
  203. * - For ADC_CHANNEL_3: Used as ADC direct channel (fast channel) if OPAMP1 is
  204. * in power down mode.
  205. * - For ADC_CHANNEL_8: Used as ADC direct channel (fast channel) if OPAMP2 is
  206. * in power down mode.
  207. * - For ADC_CHANNEL_13: Used as ADC re-routed channel if OPAMP3 is in
  208. * power down mode. Otherwise, channel 13 is connected to OPAMP3 output and
  209. * routed through switches COMP1_SW1 and VCOMP to ADC switch matrix.
  210. * (Note: OPAMP3 is available on STM32L1 Cat.4 only).
  211. * @param __CHANNEL__: ADC channel
  212. * This parameter can be one of the following values:
  213. * @arg ADC_CHANNEL_3: Channel 3 is selected.
  214. * @arg ADC_CHANNEL_8: Channel 8 is selected.
  215. * @arg ADC_CHANNEL_13: Channel 13 is selected.
  216. * @retval None
  217. */
  218. #define __HAL_ADC_CHANNEL_SPEED_FAST(__CHANNEL__) \
  219. ( ( ((__CHANNEL__) == ADC_CHANNEL_3) \
  220. )? \
  221. (SET_BIT(COMP->CSR, COMP_CSR_FCH3)) \
  222. : \
  223. ( ( ((__CHANNEL__) == ADC_CHANNEL_8) \
  224. )? \
  225. (SET_BIT(COMP->CSR, COMP_CSR_FCH8)) \
  226. : \
  227. ( ( ((__CHANNEL__) == ADC_CHANNEL_13) \
  228. )? \
  229. (SET_BIT(COMP->CSR, COMP_CSR_RCH13)) \
  230. : \
  231. (SET_BIT(COMP->CSR, 0x00000000)) \
  232. ) \
  233. ) \
  234. )
  235. #define __HAL_ADC_CHANNEL_SPEED_SLOW(__CHANNEL__) \
  236. ( ( ((__CHANNEL__) == ADC_CHANNEL_3) \
  237. )? \
  238. (CLEAR_BIT(COMP->CSR, COMP_CSR_FCH3)) \
  239. : \
  240. ( ( ((__CHANNEL__) == ADC_CHANNEL_8) \
  241. )? \
  242. (CLEAR_BIT(COMP->CSR, COMP_CSR_FCH8)) \
  243. : \
  244. ( ( ((__CHANNEL__) == ADC_CHANNEL_13) \
  245. )? \
  246. (CLEAR_BIT(COMP->CSR, COMP_CSR_RCH13)) \
  247. : \
  248. (SET_BIT(COMP->CSR, 0x00000000)) \
  249. ) \
  250. ) \
  251. )
  252. #endif /* STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  253. /**
  254. * @}
  255. */
  256. /* Private macro ------------------------------------------------------------*/
  257. /** @defgroup ADCEx_Private_Macro ADCEx Private Macro
  258. * @{
  259. */
  260. /* Macro reserved for internal HAL driver usage, not intended to be used in */
  261. /* code of final user. */
  262. /**
  263. * @brief Set ADC ranks available in register SQR1.
  264. * Register SQR1 bits availability depends on device category.
  265. * @param _NbrOfConversion_: Regular channel sequence length
  266. * @retval None
  267. */
  268. #if defined(STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  269. #define __ADC_SQR1_SQXX (ADC_SQR1_SQ28 | ADC_SQR1_SQ27 | ADC_SQR1_SQ26 | ADC_SQR1_SQ25)
  270. #else
  271. #define __ADC_SQR1_SQXX (ADC_SQR1_SQ27 | ADC_SQR1_SQ26 | ADC_SQR1_SQ25)
  272. #endif /* STM32L100xC || STM32L151xC || STM32L152xC || STM32L162xC || STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  273. /**
  274. * @brief Set the ADC's sample time for channel numbers between 30 and 31.
  275. * Register SMPR0 availability depends on device category. If register is not
  276. * available on the current device, this macro does nothing.
  277. * @retval None
  278. * @param _SAMPLETIME_: Sample time parameter.
  279. * @param _CHANNELNB_: Channel number.
  280. * @retval None
  281. */
  282. #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  283. #define ADC_SMPR0(_SAMPLETIME_, _CHANNELNB_) \
  284. ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 30)))
  285. #else
  286. #define ADC_SMPR0(_SAMPLETIME_, _CHANNELNB_) \
  287. (0x00000000U)
  288. #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  289. #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  290. /**
  291. * @brief Set the ADC's sample time for channel numbers between 20 and 29.
  292. * @param _SAMPLETIME_: Sample time parameter.
  293. * @param _CHANNELNB_: Channel number.
  294. * @retval None
  295. */
  296. #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) \
  297. ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 20)))
  298. #else
  299. /**
  300. * @brief Set the ADC's sample time for channel numbers between 20 and 26.
  301. * @param _SAMPLETIME_: Sample time parameter.
  302. * @param _CHANNELNB_: Channel number.
  303. * @retval None
  304. */
  305. #define ADC_SMPR1(_SAMPLETIME_, _CHANNELNB_) \
  306. ((_SAMPLETIME_) << (3 * ((_CHANNELNB_) - 20)))
  307. #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  308. /**
  309. * @brief Defines the highest channel available in register SMPR1. Channels
  310. * availability depends on device category:
  311. * Highest channel in register SMPR1 is channel 26 for devices Cat.1, Cat.2, Cat.3
  312. * Highest channel in register SMPR1 is channel 29 for devices Cat.4, Cat.5
  313. * @param None
  314. * @retval None
  315. */
  316. #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  317. #define ADC_SMPR1_CHANNEL_MAX ADC_CHANNEL_29
  318. #else
  319. #define ADC_SMPR1_CHANNEL_MAX ADC_CHANNEL_26
  320. #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  321. /**
  322. * @brief Define mask of configuration bits of ADC and regular group in
  323. * register CR2 (bits of ADC enable, conversion start and injected group are
  324. * excluded of this mask).
  325. * @retval None
  326. */
  327. #if defined (STM32L100xC) || defined (STM32L151xC) || defined (STM32L152xC) || defined (STM32L162xC) || defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  328. #define ADC_CR2_MASK_ADCINIT() \
  329. (ADC_CR2_EXTEN | ADC_CR2_EXTSEL | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | ADC_CR2_DELS | ADC_CR2_CFG | ADC_CR2_CONT)
  330. #else
  331. #define ADC_CR2_MASK_ADCINIT() \
  332. (ADC_CR2_EXTEN | ADC_CR2_EXTSEL | ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | ADC_CR2_DELS | ADC_CR2_CONT)
  333. #endif
  334. /**
  335. * @brief Get the maximum ADC conversion cycles on all channels.
  336. * Returns the selected sampling time + conversion time (12.5 ADC clock cycles)
  337. * Approximation of sampling time within 2 ranges, returns the highest value:
  338. * below 24 cycles {4 cycles; 9 cycles; 16 cycles; 24 cycles}
  339. * between 48 cycles and 384 cycles {48 cycles; 96 cycles; 192 cycles; 384 cycles}
  340. * Unit: ADC clock cycles
  341. * @param __HANDLE__: ADC handle
  342. * @retval ADC conversion cycles on all channels
  343. */
  344. #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  345. #define ADC_CONVCYCLES_MAX_RANGE(__HANDLE__) \
  346. (( (((__HANDLE__)->Instance->SMPR3 & ADC_SAMPLETIME_ALLCHANNELS_SMPR3BIT2) == RESET) && \
  347. (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2) == RESET) && \
  348. (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2) == RESET) && \
  349. (((__HANDLE__)->Instance->SMPR0 & ADC_SAMPLETIME_ALLCHANNELS_SMPR0BIT2) == RESET) ) ? \
  350. \
  351. ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES \
  352. )
  353. #else
  354. #define ADC_CONVCYCLES_MAX_RANGE(__HANDLE__) \
  355. (( (((__HANDLE__)->Instance->SMPR3 & ADC_SAMPLETIME_ALLCHANNELS_SMPR3BIT2) == RESET) && \
  356. (((__HANDLE__)->Instance->SMPR2 & ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2) == RESET) && \
  357. (((__HANDLE__)->Instance->SMPR1 & ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2) == RESET) ) ? \
  358. \
  359. ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_24CYCLES : ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_384CYCLES \
  360. )
  361. #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  362. /**
  363. * @brief Get the ADC clock prescaler from ADC common control register
  364. * and convert it to its decimal number setting (refer to reference manual)
  365. * @retval None
  366. */
  367. #define ADC_GET_CLOCK_PRESCALER_DECIMAL(__HANDLE__) \
  368. ((0x01) << ((ADC->CCR & ADC_CCR_ADCPRE) >> POSITION_VAL(ADC_CCR_ADCPRE)))
  369. /**
  370. * @brief Clear register SMPR0.
  371. * Register SMPR0 availability depends on device category. If register is not
  372. * available on the current device, this macro performs no action.
  373. * @param __HANDLE__: ADC handle
  374. * @retval None
  375. */
  376. #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  377. #define ADC_SMPR1_CLEAR(__HANDLE__) \
  378. CLEAR_BIT((__HANDLE__)->Instance->SMPR1, (ADC_SMPR1_SMP29 | ADC_SMPR1_SMP28 | ADC_SMPR1_SMP27 | \
  379. ADC_SMPR1_SMP26 | ADC_SMPR1_SMP25 | ADC_SMPR1_SMP24 | \
  380. ADC_SMPR1_SMP23 | ADC_SMPR1_SMP22 | ADC_SMPR1_SMP21 | \
  381. ADC_SMPR1_SMP20 ))
  382. #define ADC_SMPR0_CLEAR(__HANDLE__) \
  383. (CLEAR_BIT((__HANDLE__)->Instance->SMPR0, (ADC_SMPR0_SMP31 | ADC_SMPR0_SMP30)))
  384. #else
  385. #define ADC_SMPR1_CLEAR(__HANDLE__) \
  386. CLEAR_BIT((__HANDLE__)->Instance->SMPR1, (ADC_SMPR1_SMP26 | ADC_SMPR1_SMP25 | ADC_SMPR1_SMP24 | \
  387. ADC_SMPR1_SMP23 | ADC_SMPR1_SMP22 | ADC_SMPR1_SMP21 | \
  388. ADC_SMPR1_SMP20 ))
  389. #define ADC_SMPR0_CLEAR(__HANDLE__) __NOP()
  390. #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  391. /**
  392. * @brief Clear register CR2.
  393. * @param __HANDLE__: ADC handle
  394. * @retval None
  395. */
  396. #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  397. #define ADC_CR2_CLEAR(__HANDLE__) \
  398. (CLEAR_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTEN | ADC_CR2_EXTSEL | \
  399. ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL | \
  400. ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | \
  401. ADC_CR2_DMA | ADC_CR2_DELS | ADC_CR2_CFG | \
  402. ADC_CR2_CONT | ADC_CR2_ADON )) \
  403. )
  404. #else
  405. #define ADC_CR2_CLEAR(__HANDLE__) \
  406. (CLEAR_BIT((__HANDLE__)->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTEN | ADC_CR2_EXTSEL | \
  407. ADC_CR2_JSWSTART | ADC_CR2_JEXTEN | ADC_CR2_JEXTSEL | \
  408. ADC_CR2_ALIGN | ADC_CR2_EOCS | ADC_CR2_DDS | \
  409. ADC_CR2_DMA | ADC_CR2_DELS | \
  410. ADC_CR2_CONT | ADC_CR2_ADON )) \
  411. )
  412. #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  413. /**
  414. * @brief Set the sampling time of selected channel on register SMPR0
  415. * Register SMPR0 availability depends on device category. If register is not
  416. * available on the current device, this macro performs no action.
  417. * @param __HANDLE__: ADC handle
  418. * @param _SAMPLETIME_: Sample time parameter.
  419. * @param __CHANNEL__: Channel number.
  420. * @retval None
  421. */
  422. #if defined(STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX)
  423. #define ADC_SMPR0_CHANNEL_SET(__HANDLE__, _SAMPLETIME_, __CHANNEL__) \
  424. MODIFY_REG((__HANDLE__)->Instance->SMPR0, \
  425. ADC_SMPR0(ADC_SMPR0_SMP30, (__CHANNEL__)), \
  426. ADC_SMPR0((_SAMPLETIME_), (__CHANNEL__)) )
  427. #else
  428. #define ADC_SMPR0_CHANNEL_SET(__HANDLE__, _SAMPLETIME_, __CHANNEL__) __NOP()
  429. #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX */
  430. #define IS_ADC_INJECTED_RANK(CHANNEL) (((CHANNEL) == ADC_INJECTED_RANK_1) || \
  431. ((CHANNEL) == ADC_INJECTED_RANK_2) || \
  432. ((CHANNEL) == ADC_INJECTED_RANK_3) || \
  433. ((CHANNEL) == ADC_INJECTED_RANK_4) )
  434. #define IS_ADC_EXTTRIGINJEC_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE) || \
  435. ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISING) || \
  436. ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING) || \
  437. ((EDGE) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING) )
  438. #define IS_ADC_EXTTRIGINJEC(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_CC1) || \
  439. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T2_TRGO) || \
  440. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T3_CC4) || \
  441. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_TRGO) || \
  442. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC1) || \
  443. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC2) || \
  444. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T4_CC3) || \
  445. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T7_TRGO) || \
  446. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T9_CC1) || \
  447. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T9_TRGO) || \
  448. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_T10_CC1) || \
  449. ((REGTRIG) == ADC_EXTERNALTRIGINJECCONV_EXT_IT15) || \
  450. ((REGTRIG) == ADC_SOFTWARE_START) )
  451. /** @defgroup ADCEx_injected_nb_conv_verification ADCEx injected nb conv verification
  452. * @{
  453. */
  454. #define IS_ADC_INJECTED_NB_CONV(LENGTH) (((LENGTH) >= (1U)) && ((LENGTH) <= (4U)))
  455. /**
  456. * @}
  457. */
  458. /**
  459. * @}
  460. */
  461. /* Exported functions --------------------------------------------------------*/
  462. /** @addtogroup ADCEx_Exported_Functions
  463. * @{
  464. */
  465. /* IO operation functions *****************************************************/
  466. /** @addtogroup ADCEx_Exported_Functions_Group1
  467. * @{
  468. */
  469. /* Blocking mode: Polling */
  470. HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc);
  471. HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc);
  472. HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  473. /* Non-blocking mode: Interruption */
  474. HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc);
  475. HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc);
  476. /* ADC retrieve conversion value intended to be used with polling or interruption */
  477. uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank);
  478. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption) */
  479. void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc);
  480. /**
  481. * @}
  482. */
  483. /* Peripheral Control functions ***********************************************/
  484. /** @addtogroup ADCEx_Exported_Functions_Group2
  485. * @{
  486. */
  487. HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected);
  488. /**
  489. * @}
  490. */
  491. /**
  492. * @}
  493. */
  494. /**
  495. * @}
  496. */
  497. /**
  498. * @}
  499. */
  500. #ifdef __cplusplus
  501. }
  502. #endif
  503. #endif /* __STM32L1xx_HAL_ADC_EX_H */
  504. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/