stm32l4xx_hal_adc_ex.h 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_adc_ex.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC HAL extended module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_ADC_EX_H
  37. #define __STM32L4xx_HAL_ADC_EX_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l4xx_hal_def.h"
  43. /** @addtogroup STM32L4xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup ADCEx
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup ADCEx_Exported_Types ADC Extended Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief ADC Injected Conversion Oversampling structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t Ratio; /*!< Configures the oversampling ratio.
  59. This parameter can be a value of @ref ADC_HAL_EC_OVS_RATIO */
  60. uint32_t RightBitShift; /*!< Configures the division coefficient for the Oversampler.
  61. This parameter can be a value of @ref ADC_HAL_EC_OVS_SHIFT */
  62. }ADC_InjOversamplingTypeDef;
  63. /**
  64. * @brief Structure definition of ADC group injected and ADC channel affected to ADC group injected
  65. * @note Parameters of this structure are shared within 2 scopes:
  66. * - Scope channel: InjectedChannel, InjectedRank, InjectedSamplingTime , InjectedSingleDiff, InjectedOffsetNumber, InjectedOffset
  67. * - Scope ADC group injected (affects all channels of injected group): InjectedNbrOfConversion, InjectedDiscontinuousConvMode,
  68. * AutoInjectedConv, QueueInjectedContext, ExternalTrigInjecConv, ExternalTrigInjecConvEdge, InjecOversamplingMode, InjecOversampling.
  69. * @note The setting of these parameters by function HAL_ADCEx_InjectedConfigChannel() is conditioned to ADC state.
  70. * ADC state can be either:
  71. * - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'InjectedSingleDiff')
  72. * - For parameters 'InjectedDiscontinuousConvMode', 'QueueInjectedContext', 'InjecOversampling': ADC enabled without conversion on going on injected group.
  73. * - For parameters 'InjectedSamplingTime', 'InjectedOffset', 'InjectedOffsetNumber', 'AutoInjectedConv': ADC enabled without conversion on going on regular and injected groups.
  74. * - For parameters 'InjectedChannel', 'InjectedRank', 'InjectedNbrOfConversion', 'ExternalTrigInjecConv', 'ExternalTrigInjecConvEdge': ADC enabled and while conversion on going
  75. * on ADC groups regular and injected.
  76. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  77. * without error reporting (as it can be the expected behavior in case of intended action to update another parameter (which fulfills the ADC state condition) on the fly).
  78. */
  79. typedef struct
  80. {
  81. uint32_t InjectedChannel; /*!< Specifies the channel to configure into ADC group injected.
  82. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL
  83. Note: Depending on devices and ADC instances, some channels may not be available on device package pins. Refer to device datasheet for channels availability. */
  84. uint32_t InjectedRank; /*!< Specifies the rank in the ADC group injected sequencer.
  85. This parameter must be a value of @ref ADC_LL_EC_INJ_SEQ_RANKS.
  86. Note: to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by
  87. the new channel setting (or parameter number of conversions adjusted) */
  88. uint32_t InjectedSamplingTime; /*!< Sampling time value to be set for the selected channel.
  89. Unit: ADC clock cycles.
  90. Conversion time is the addition of sampling time and processing time
  91. (12.5 ADC clock cycles at ADC resolution 12 bits, 10.5 cycles at 10 bits, 8.5 cycles at 8 bits, 6.5 cycles at 6 bits).
  92. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL_SAMPLINGTIME.
  93. Caution: This parameter applies to a channel that can be used in a regular and/or injected group.
  94. It overwrites the last setting.
  95. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
  96. sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
  97. Refer to device datasheet for timings values. */
  98. uint32_t InjectedSingleDiff; /*!< Selection of single-ended or differential input.
  99. In differential mode: Differential measurement is between the selected channel 'i' (positive input) and channel 'i+1' (negative input).
  100. Only channel 'i' has to be configured, channel 'i+1' is configured automatically.
  101. This parameter must be a value of @ref ADC_HAL_EC_CHANNEL_SINGLE_DIFF_ENDING.
  102. Caution: This parameter applies to a channel that can be used in a regular and/or injected group.
  103. It overwrites the last setting.
  104. Note: Refer to Reference Manual to ensure the selected channel is available in differential mode.
  105. Note: When configuring a channel 'i' in differential mode, the channel 'i+1' is not usable separately.
  106. Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
  107. If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behavior in case
  108. of another parameter update on the fly) */
  109. uint32_t InjectedOffsetNumber; /*!< Selects the offset number.
  110. This parameter can be a value of @ref ADC_HAL_EC_OFFSET_NB.
  111. Caution: Only one offset is allowed per channel. This parameter overwrites the last setting. */
  112. uint32_t InjectedOffset; /*!< Defines the offset to be subtracted from the raw converted data.
  113. Offset value must be a positive number.
  114. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number
  115. between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively.
  116. Note: This parameter must be modified when no conversion is on going on both regular and injected groups (ADC disabled, or ADC enabled
  117. without continuous mode or external trigger that could launch a conversion). */
  118. uint32_t InjectedNbrOfConversion; /*!< Specifies the number of ranks that will be converted within the ADC group injected sequencer.
  119. To use the injected group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
  120. This parameter must be a number between Min_Data = 1 and Max_Data = 4.
  121. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  122. configure a channel on injected group can impact the configuration of other channels previously set. */
  123. uint32_t InjectedDiscontinuousConvMode; /*!< Specifies whether the conversions sequence of ADC group injected is performed in Complete-sequence/Discontinuous-sequence
  124. (main sequence subdivided in successive parts).
  125. Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
  126. Discontinuous mode can be enabled only if continuous mode is disabled.
  127. This parameter can be set to ENABLE or DISABLE.
  128. Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
  129. Note: For injected group, discontinuous mode converts the sequence channel by channel (discontinuous length fixed to 1 rank).
  130. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  131. configure a channel on injected group can impact the configuration of other channels previously set. */
  132. uint32_t AutoInjectedConv; /*!< Enables or disables the selected ADC group injected automatic conversion after regular one
  133. This parameter can be set to ENABLE or DISABLE.
  134. Note: To use Automatic injected conversion, discontinuous mode must be disabled ('DiscontinuousConvMode' and 'InjectedDiscontinuousConvMode' set to DISABLE)
  135. Note: To use Automatic injected conversion, injected group external triggers must be disabled ('ExternalTrigInjecConv' set to ADC_INJECTED_SOFTWARE_START)
  136. 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.
  137. To maintain JAUTO always enabled, DMA must be configured in circular mode.
  138. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  139. configure a channel on injected group can impact the configuration of other channels previously set. */
  140. uint32_t QueueInjectedContext; /*!< Specifies whether the context queue feature is enabled.
  141. This parameter can be set to ENABLE or DISABLE.
  142. If context queue is enabled, injected sequencer&channels configurations are queued on up to 2 contexts. If a
  143. new injected context is set when queue is full, error is triggered by interruption and through function
  144. 'HAL_ADCEx_InjectedQueueOverflowCallback'.
  145. Caution: This feature request that the sequence is fully configured before injected conversion start.
  146. Therefore, configure channels with as many calls to HAL_ADCEx_InjectedConfigChannel() as the 'InjectedNbrOfConversion' parameter.
  147. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  148. configure a channel on injected group can impact the configuration of other channels previously set.
  149. Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion). */
  150. uint32_t ExternalTrigInjecConv; /*!< Selects the external event used to trigger the conversion start of injected group.
  151. If set to ADC_INJECTED_SOFTWARE_START, external triggers are disabled and software trigger is used instead.
  152. This parameter can be a value of @ref ADC_injected_external_trigger_source.
  153. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  154. configure a channel on injected group can impact the configuration of other channels previously set. */
  155. uint32_t ExternalTrigInjecConvEdge; /*!< Selects the external trigger edge of injected group.
  156. This parameter can be a value of @ref ADC_injected_external_trigger_edge.
  157. If trigger source is set to ADC_INJECTED_SOFTWARE_START, this parameter is discarded.
  158. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to
  159. configure a channel on injected group can impact the configuration of other channels previously set. */
  160. uint32_t InjecOversamplingMode; /*!< Specifies whether the oversampling feature is enabled or disabled.
  161. This parameter can be set to ENABLE or DISABLE.
  162. Note: This parameter can be modified only if there is no conversion is ongoing (both ADSTART and JADSTART cleared). */
  163. ADC_InjOversamplingTypeDef InjecOversampling; /*!< Specifies the Oversampling parameters.
  164. Caution: this setting overwrites the previous oversampling configuration if oversampling already enabled.
  165. Note: This parameter can be modified only if there is no conversion is ongoing (both ADSTART and JADSTART cleared). */
  166. }ADC_InjectionConfTypeDef;
  167. #if defined(ADC_MULTIMODE_SUPPORT)
  168. /**
  169. * @brief Structure definition of ADC multimode
  170. * @note The setting of these parameters by function HAL_ADCEx_MultiModeConfigChannel() is conditioned by ADCs state (both Master and Slave ADCs).
  171. * Both Master and Slave ADCs must be disabled.
  172. */
  173. typedef struct
  174. {
  175. uint32_t Mode; /*!< Configures the ADC to operate in independent or multimode.
  176. This parameter can be a value of @ref ADC_HAL_EC_MULTI_MODE. */
  177. uint32_t DMAAccessMode; /*!< Configures the DMA mode for multimode ADC:
  178. selection whether 2 DMA channels (each ADC uses its own DMA channel) or 1 DMA channel (one DMA channel for both ADC, DMA of ADC master)
  179. This parameter can be a value of @ref ADC_HAL_EC_MULTI_DMA_TRANSFER_RESOLUTION. */
  180. uint32_t TwoSamplingDelay; /*!< Configures the Delay between 2 sampling phases.
  181. This parameter can be a value of @ref ADC_HAL_EC_MULTI_TWOSMP_DELAY.
  182. Delay range depends on selected resolution:
  183. from 1 to 12 clock cycles for 12 bits, from 1 to 10 clock cycles for 10 bits,
  184. from 1 to 8 clock cycles for 8 bits, from 1 to 6 clock cycles for 6 bits. */
  185. }ADC_MultiModeTypeDef;
  186. #endif /* ADC_MULTIMODE_SUPPORT */
  187. /**
  188. * @}
  189. */
  190. /* Exported constants --------------------------------------------------------*/
  191. /** @defgroup ADCEx_Exported_Constants ADC Extended Exported Constants
  192. * @{
  193. */
  194. /** @defgroup ADC_injected_external_trigger_source ADC group injected trigger source
  195. * @{
  196. */
  197. /* ADC group regular trigger sources for all ADC instances */
  198. #define ADC_INJECTED_SOFTWARE_START (LL_ADC_INJ_TRIG_SOFTWARE) /*!< Software triggers injected group conversion start */
  199. #define ADC_EXTERNALTRIGINJEC_T1_TRGO (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) /*!< ADC group injected conversion trigger from external IP: TIM1 TRGO. Trigger edge set to rising edge (default setting). */
  200. #define ADC_EXTERNALTRIGINJEC_T1_TRGO2 (LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) /*!< ADC group injected conversion trigger from external IP: TIM1 TRGO2. Trigger edge set to rising edge (default setting). */
  201. #define ADC_EXTERNALTRIGINJEC_T1_CC4 (LL_ADC_INJ_TRIG_EXT_TIM1_CH4) /*!< ADC group injected conversion trigger from external IP: TIM1 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  202. #define ADC_EXTERNALTRIGINJEC_T2_TRGO (LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) /*!< ADC group injected conversion trigger from external IP: TIM2 TRGO. Trigger edge set to rising edge (default setting). */
  203. #define ADC_EXTERNALTRIGINJEC_T2_CC1 (LL_ADC_INJ_TRIG_EXT_TIM2_CH1) /*!< ADC group injected conversion trigger from external IP: TIM2 channel 1 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  204. #define ADC_EXTERNALTRIGINJEC_T3_TRGO (LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) /*!< ADC group injected conversion trigger from external IP: TIM3 TRGO. Trigger edge set to rising edge (default setting). */
  205. #define ADC_EXTERNALTRIGINJEC_T3_CC1 (LL_ADC_INJ_TRIG_EXT_TIM3_CH1) /*!< ADC group injected conversion trigger from external IP: TIM3 channel 1 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  206. #define ADC_EXTERNALTRIGINJEC_T3_CC3 (LL_ADC_INJ_TRIG_EXT_TIM3_CH3) /*!< ADC group injected conversion trigger from external IP: TIM3 channel 3 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  207. #define ADC_EXTERNALTRIGINJEC_T3_CC4 (LL_ADC_INJ_TRIG_EXT_TIM3_CH4) /*!< ADC group injected conversion trigger from external IP: TIM3 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  208. #define ADC_EXTERNALTRIGINJEC_T4_TRGO (LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) /*!< ADC group injected conversion trigger from external IP: TIM4 TRGO. Trigger edge set to rising edge (default setting). */
  209. #define ADC_EXTERNALTRIGINJEC_T6_TRGO (LL_ADC_INJ_TRIG_EXT_TIM6_TRGO) /*!< ADC group injected conversion trigger from external IP: TIM6 TRGO. Trigger edge set to rising edge (default setting). */
  210. #define ADC_EXTERNALTRIGINJEC_T8_CC4 (LL_ADC_INJ_TRIG_EXT_TIM8_CH4) /*!< ADC group injected conversion trigger from external IP: TIM8 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  211. #define ADC_EXTERNALTRIGINJEC_T8_TRGO (LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) /*!< ADC group injected conversion trigger from external IP: TIM8 TRGO. Trigger edge set to rising edge (default setting). */
  212. #define ADC_EXTERNALTRIGINJEC_T8_TRGO2 (LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) /*!< ADC group injected conversion trigger from external IP: TIM8 TRGO2. Trigger edge set to rising edge (default setting). */
  213. #define ADC_EXTERNALTRIGINJEC_T15_TRGO (LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) /*!< ADC group injected conversion trigger from external IP: TIM15 TRGO. Trigger edge set to rising edge (default setting). */
  214. #define ADC_EXTERNALTRIGINJEC_EXT_IT15 (LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) /*!< ADC group injected conversion trigger from external IP: external interrupt line 15. Trigger edge set to rising edge (default setting). */
  215. /**
  216. * @}
  217. */
  218. /** @defgroup ADC_injected_external_trigger_edge ADC group injected trigger edge (when external trigger is selected)
  219. * @{
  220. */
  221. #define ADC_EXTERNALTRIGINJECCONV_EDGE_NONE (0x00000000U) /*!< Injected conversions hardware trigger detection disabled */
  222. #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISING (ADC_JSQR_JEXTEN_0) /*!< Injected conversions hardware trigger detection on the rising edge */
  223. #define ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING (ADC_JSQR_JEXTEN_1) /*!< Injected conversions hardware trigger detection on the falling edge */
  224. #define ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING (ADC_JSQR_JEXTEN) /*!< Injected conversions hardware trigger detection on both the rising and falling edges */
  225. /**
  226. * @}
  227. */
  228. /** @defgroup ADC_HAL_EC_CHANNEL_SINGLE_DIFF_ENDING Channel - Single or differential ending
  229. * @{
  230. */
  231. #define ADC_SINGLE_ENDED (LL_ADC_SINGLE_ENDED) /*!< ADC channel ending set to single ended (literal also used to set calibration mode) */
  232. #define ADC_DIFFERENTIAL_ENDED (LL_ADC_DIFFERENTIAL_ENDED) /*!< ADC channel ending set to differential (literal also used to set calibration mode) */
  233. /**
  234. * @}
  235. */
  236. /** @defgroup ADC_HAL_EC_OFFSET_NB ADC instance - Offset number
  237. * @{
  238. */
  239. #define ADC_OFFSET_NONE (ADC_OFFSET_4 + 1U) /*!< ADC offset disabled: no offset correction for the selected ADC channel */
  240. #define ADC_OFFSET_1 (LL_ADC_OFFSET_1) /*!< ADC offset number 1: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  241. #define ADC_OFFSET_2 (LL_ADC_OFFSET_2) /*!< ADC offset number 2: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  242. #define ADC_OFFSET_3 (LL_ADC_OFFSET_3) /*!< ADC offset number 3: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  243. #define ADC_OFFSET_4 (LL_ADC_OFFSET_4) /*!< ADC offset number 4: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  244. /**
  245. * @}
  246. */
  247. /** @defgroup ADC_LL_EC_INJ_SEQ_RANKS ADC group injected - Sequencer ranks
  248. * @{
  249. */
  250. #define ADC_INJECTED_RANK_1 (LL_ADC_INJ_RANK_1) /*!< ADC group injected sequencer rank 1 */
  251. #define ADC_INJECTED_RANK_2 (LL_ADC_INJ_RANK_2) /*!< ADC group injected sequencer rank 2 */
  252. #define ADC_INJECTED_RANK_3 (LL_ADC_INJ_RANK_3) /*!< ADC group injected sequencer rank 3 */
  253. #define ADC_INJECTED_RANK_4 (LL_ADC_INJ_RANK_4) /*!< ADC group injected sequencer rank 4 */
  254. /**
  255. * @}
  256. */
  257. #if defined(ADC_MULTIMODE_SUPPORT)
  258. /** @defgroup ADC_HAL_EC_MULTI_MODE Multimode - Mode
  259. * @{
  260. */
  261. #define ADC_MODE_INDEPENDENT (LL_ADC_MULTI_INDEPENDENT) /*!< ADC dual mode disabled (ADC independent mode) */
  262. #define ADC_DUALMODE_REGSIMULT (LL_ADC_MULTI_DUAL_REG_SIMULT) /*!< ADC dual mode enabled: group regular simultaneous */
  263. #define ADC_DUALMODE_INTERL (LL_ADC_MULTI_DUAL_REG_INTERL) /*!< ADC dual mode enabled: Combined group regular interleaved */
  264. #define ADC_DUALMODE_INJECSIMULT (LL_ADC_MULTI_DUAL_INJ_SIMULT) /*!< ADC dual mode enabled: group injected simultaneous */
  265. #define ADC_DUALMODE_ALTERTRIG (LL_ADC_MULTI_DUAL_INJ_ALTERN) /*!< ADC dual mode enabled: group injected alternate trigger. Works only with external triggers (not internal SW start) */
  266. #define ADC_DUALMODE_REGSIMULT_INJECSIMULT (LL_ADC_MULTI_DUAL_REG_SIM_INJ_SIM) /*!< ADC dual mode enabled: Combined group regular simultaneous + group injected simultaneous */
  267. #define ADC_DUALMODE_REGSIMULT_ALTERTRIG (LL_ADC_MULTI_DUAL_REG_SIM_INJ_ALT) /*!< ADC dual mode enabled: Combined group regular simultaneous + group injected alternate trigger */
  268. #define ADC_DUALMODE_REGINTERL_INJECSIMULT (LL_ADC_MULTI_DUAL_REG_INT_INJ_SIM) /*!< ADC dual mode enabled: Combined group regular interleaved + group injected simultaneous */
  269. /** @defgroup ADC_HAL_EC_MULTI_DMA_TRANSFER_RESOLUTION Multimode - DMA transfer mode depending on ADC resolution
  270. * @{
  271. */
  272. #define ADC_DMAACCESSMODE_DISABLED (0x00000000U) /*!< DMA multimode disabled: each ADC uses its own DMA channel */
  273. #define ADC_DMAACCESSMODE_12_10_BITS (ADC_CCR_MDMA_1) /*!< DMA multimode enabled (one DMA channel for both ADC, DMA of ADC master) for 12 and 10 bits resolution */
  274. #define ADC_DMAACCESSMODE_8_6_BITS (ADC_CCR_MDMA) /*!< DMA multimode enabled (one DMA channel for both ADC, DMA of ADC master) for 8 and 6 bits resolution */
  275. /**
  276. * @}
  277. */
  278. /** @defgroup ADC_HAL_EC_MULTI_TWOSMP_DELAY Multimode - Delay between two sampling phases
  279. * @{
  280. */
  281. #define ADC_TWOSAMPLINGDELAY_1CYCLE (LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE) /*!< ADC multimode delay between two sampling phases: 1 ADC clock cycle */
  282. #define ADC_TWOSAMPLINGDELAY_2CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_2CYCLES) /*!< ADC multimode delay between two sampling phases: 2 ADC clock cycles */
  283. #define ADC_TWOSAMPLINGDELAY_3CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_3CYCLES) /*!< ADC multimode delay between two sampling phases: 3 ADC clock cycles */
  284. #define ADC_TWOSAMPLINGDELAY_4CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_4CYCLES) /*!< ADC multimode delay between two sampling phases: 4 ADC clock cycles */
  285. #define ADC_TWOSAMPLINGDELAY_5CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_5CYCLES) /*!< ADC multimode delay between two sampling phases: 5 ADC clock cycles */
  286. #define ADC_TWOSAMPLINGDELAY_6CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_6CYCLES) /*!< ADC multimode delay between two sampling phases: 6 ADC clock cycles */
  287. #define ADC_TWOSAMPLINGDELAY_7CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_7CYCLES) /*!< ADC multimode delay between two sampling phases: 7 ADC clock cycles */
  288. #define ADC_TWOSAMPLINGDELAY_8CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_8CYCLES) /*!< ADC multimode delay between two sampling phases: 8 ADC clock cycles */
  289. #define ADC_TWOSAMPLINGDELAY_9CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_9CYCLES) /*!< ADC multimode delay between two sampling phases: 9 ADC clock cycles */
  290. #define ADC_TWOSAMPLINGDELAY_10CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_10CYCLES) /*!< ADC multimode delay between two sampling phases: 10 ADC clock cycles */
  291. #define ADC_TWOSAMPLINGDELAY_11CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_11CYCLES) /*!< ADC multimode delay between two sampling phases: 11 ADC clock cycles */
  292. #define ADC_TWOSAMPLINGDELAY_12CYCLES (LL_ADC_MULTI_TWOSMP_DELAY_12CYCLES) /*!< ADC multimode delay between two sampling phases: 12 ADC clock cycles */
  293. /**
  294. * @}
  295. */
  296. /**
  297. * @}
  298. */
  299. #endif /* ADC_MULTIMODE_SUPPORT */
  300. /** @defgroup ADC_HAL_EC_GROUPS ADC instance - Groups
  301. * @{
  302. */
  303. #define ADC_REGULAR_GROUP (LL_ADC_GROUP_REGULAR) /*!< ADC group regular (available on all STM32 devices) */
  304. #define ADC_INJECTED_GROUP (LL_ADC_GROUP_INJECTED) /*!< ADC group injected (not available on all STM32 devices)*/
  305. #define ADC_REGULAR_INJECTED_GROUP (LL_ADC_GROUP_REGULAR_INJECTED) /*!< ADC both groups regular and injected */
  306. /**
  307. * @}
  308. */
  309. /** @defgroup ADC_CFGR_fields ADCx CFGR fields
  310. * @{
  311. */
  312. #if defined(ADC_CFGR_DFSDMCFG) &&defined(DFSDM1_Channel0)
  313. #define ADC_CFGR_FIELDS (ADC_CFGR_AWD1CH | ADC_CFGR_JAUTO | ADC_CFGR_JAWD1EN |\
  314. ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL | ADC_CFGR_JQM |\
  315. ADC_CFGR_JDISCEN | ADC_CFGR_DISCNUM | ADC_CFGR_DISCEN |\
  316. ADC_CFGR_AUTDLY | ADC_CFGR_CONT | ADC_CFGR_OVRMOD |\
  317. ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL | ADC_CFGR_ALIGN |\
  318. ADC_CFGR_RES | ADC_CFGR_DFSDMCFG | ADC_CFGR_DMACFG | ADC_CFGR_DMAEN)
  319. #else
  320. #define ADC_CFGR_FIELDS (ADC_CFGR_AWD1CH | ADC_CFGR_JAUTO | ADC_CFGR_JAWD1EN |\
  321. ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL | ADC_CFGR_JQM |\
  322. ADC_CFGR_JDISCEN | ADC_CFGR_DISCNUM | ADC_CFGR_DISCEN |\
  323. ADC_CFGR_AUTDLY | ADC_CFGR_CONT | ADC_CFGR_OVRMOD |\
  324. ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL | ADC_CFGR_ALIGN |\
  325. ADC_CFGR_RES | ADC_CFGR_DMACFG | ADC_CFGR_DMAEN )
  326. #endif
  327. /**
  328. * @}
  329. */
  330. /** @defgroup ADC_SMPR1_fields ADCx SMPR1 fields
  331. * @{
  332. */
  333. #if defined(ADC_SMPR1_SMPPLUS)
  334. #define ADC_SMPR1_FIELDS (ADC_SMPR1_SMP9 | ADC_SMPR1_SMP8 | ADC_SMPR1_SMP7 |\
  335. ADC_SMPR1_SMP6 | ADC_SMPR1_SMP5 | ADC_SMPR1_SMP4 |\
  336. ADC_SMPR1_SMP3 | ADC_SMPR1_SMP2 | ADC_SMPR1_SMP1 |\
  337. ADC_SMPR1_SMP0 | ADC_SMPR1_SMPPLUS)
  338. #else
  339. #define ADC_SMPR1_FIELDS (ADC_SMPR1_SMP9 | ADC_SMPR1_SMP8 | ADC_SMPR1_SMP7 |\
  340. ADC_SMPR1_SMP6 | ADC_SMPR1_SMP5 | ADC_SMPR1_SMP4 |\
  341. ADC_SMPR1_SMP3 | ADC_SMPR1_SMP2 | ADC_SMPR1_SMP1 |\
  342. ADC_SMPR1_SMP0)
  343. #endif
  344. /**
  345. * @}
  346. */
  347. /** @defgroup ADC_CFGR_fields_2 ADCx CFGR sub fields
  348. * @{
  349. */
  350. /* ADC_CFGR fields of parameters that can be updated when no conversion
  351. (neither regular nor injected) is on-going */
  352. #if defined(ADC_CFGR_DFSDMCFG) &&defined(DFSDM1_Channel0)
  353. #define ADC_CFGR_FIELDS_2 ((ADC_CFGR_DMACFG | ADC_CFGR_AUTDLY | ADC_CFGR_DFSDMCFG))
  354. #else
  355. #define ADC_CFGR_FIELDS_2 ((ADC_CFGR_DMACFG | ADC_CFGR_AUTDLY))
  356. #endif
  357. /**
  358. * @}
  359. */
  360. #if defined(ADC_CFGR_DFSDMCFG) &&defined(DFSDM1_Channel0)
  361. /** @defgroup ADC_HAL_EC_REG_DFSDM_TRANSFER ADC group regular - DFSDM transfer of ADC conversion data
  362. * @{
  363. */
  364. #define ADC_DFSDM_MODE_DISABLE (0x00000000U) /*!< ADC conversions are not transferred by DFSDM. */
  365. #define ADC_DFSDM_MODE_ENABLE (LL_ADC_REG_DFSDM_TRANSFER_ENABLE) /*!< ADC conversion data are transfered to DFSDM for post processing. The ADC conversion data format must be 16-bit signed and right aligned, refer to reference manual. DFSDM transfer cannot be used if DMA transfer is enabled. */
  366. /**
  367. * @}
  368. */
  369. #endif
  370. /**
  371. * @}
  372. */
  373. /* Exported macros -----------------------------------------------------------*/
  374. #if defined(ADC_MULTIMODE_SUPPORT)
  375. /** @defgroup ADCEx_Exported_Macro ADC Extended Exported Macros
  376. * @{
  377. */
  378. /** @brief Force ADC instance in multimode mode independant (multimode disable).
  379. * @note This macro must be used only in case of transition from multimode
  380. * to mode independent and in case of unknown previous state,
  381. * to ensure ADC configuration is in mode independent.
  382. * @note Standard way of multimode configuration change is done from
  383. * HAL ADC handle of ADC master using function
  384. * "HAL_ADCEx_MultiModeConfigChannel(..., ADC_MODE_INDEPENDENT)" )".
  385. * Usage of this macro is not the Standard way of multimode
  386. * configuration and can lead to have HAL ADC handles status
  387. * misaligned. Usage of this macro must be limited to cases
  388. * mentionned above.
  389. * @param __HANDLE__ ADC handle.
  390. * @retval None
  391. */
  392. #define ADC_FORCE_MODE_INDEPENDENT(__HANDLE__) \
  393. LL_ADC_SetMultimode(__LL_ADC_COMMON_INSTANCE((__HANDLE__)->Instance), LL_ADC_MULTI_INDEPENDENT)
  394. /**
  395. * @}
  396. */
  397. #endif /* ADC_MULTIMODE_SUPPORT */
  398. /* Private macros ------------------------------------------------------------*/
  399. /** @defgroup ADCEx_Private_Macro_internal_HAL_driver ADC Extended Private Macros
  400. * @{
  401. */
  402. /* Macro reserved for internal HAL driver usage, not intended to be used in */
  403. /* code of final user. */
  404. /**
  405. * @brief Test if conversion trigger of injected group is software start
  406. * or external trigger.
  407. * @param __HANDLE__ ADC handle.
  408. * @retval SET (software start) or RESET (external trigger).
  409. */
  410. #define ADC_IS_SOFTWARE_START_INJECTED(__HANDLE__) \
  411. (((__HANDLE__)->Instance->JSQR & ADC_JSQR_JEXTEN) == RESET)
  412. /**
  413. * @brief Check if conversion is on going on regular or injected groups.
  414. * @param __HANDLE__ ADC handle.
  415. * @retval SET (conversion is on going) or RESET (no conversion is on going).
  416. */
  417. #define ADC_IS_CONVERSION_ONGOING_REGULAR_INJECTED(__HANDLE__) \
  418. (( (((__HANDLE__)->Instance->CR) & (ADC_CR_ADSTART | ADC_CR_JADSTART)) == RESET \
  419. ) ? RESET : SET)
  420. /**
  421. * @brief Check if conversion is on going on injected group.
  422. * @param __HANDLE__ ADC handle.
  423. * @retval SET (conversion is on going) or RESET (no conversion is on going).
  424. */
  425. #define ADC_IS_CONVERSION_ONGOING_INJECTED(__HANDLE__) \
  426. (LL_ADC_INJ_IsConversionOngoing((__HANDLE__)->Instance))
  427. /**
  428. * @brief Check whether or not ADC is independent.
  429. * @param __HANDLE__ ADC handle.
  430. * @note When multimode feature is not available, the macro always returns SET.
  431. * @retval SET (ADC is independent) or RESET (ADC is not).
  432. */
  433. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  434. #define ADC_IS_INDEPENDENT(__HANDLE__) \
  435. ( ( ( ((__HANDLE__)->Instance) == ADC3) \
  436. )? \
  437. SET \
  438. : \
  439. RESET \
  440. )
  441. #elif defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  442. #define ADC_IS_INDEPENDENT(__HANDLE__) (SET)
  443. #endif
  444. /**
  445. * @brief Set the selected injected Channel rank.
  446. * @param __CHANNELNB__ Channel number.
  447. * @param __RANKNB__ Rank number.
  448. * @retval None
  449. */
  450. #define ADC_JSQR_RK(__CHANNELNB__, __RANKNB__) ((((__CHANNELNB__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << ((__RANKNB__) & ADC_INJ_RANK_ID_JSQR_MASK))
  451. /**
  452. * @brief Configure ADC injected context queue
  453. * @param __INJECT_CONTEXT_QUEUE_MODE__ Injected context queue mode.
  454. * @retval None
  455. */
  456. #define ADC_CFGR_INJECT_CONTEXT_QUEUE(__INJECT_CONTEXT_QUEUE_MODE__) ((__INJECT_CONTEXT_QUEUE_MODE__) << ADC_CFGR_JQM_Pos)
  457. /**
  458. * @brief Configure ADC discontinuous conversion mode for injected group
  459. * @param __INJECT_DISCONTINUOUS_MODE__ Injected discontinuous mode.
  460. * @retval None
  461. */
  462. #define ADC_CFGR_INJECT_DISCCONTINUOUS(__INJECT_DISCONTINUOUS_MODE__) ((__INJECT_DISCONTINUOUS_MODE__) << ADC_CFGR_JDISCEN_Pos)
  463. /**
  464. * @brief Configure ADC discontinuous conversion mode for regular group
  465. * @param __REG_DISCONTINUOUS_MODE__ Regular discontinuous mode.
  466. * @retval None
  467. */
  468. #define ADC_CFGR_REG_DISCONTINUOUS(__REG_DISCONTINUOUS_MODE__) ((__REG_DISCONTINUOUS_MODE__) << ADC_CFGR_DISCEN_Pos)
  469. /**
  470. * @brief Configure the number of discontinuous conversions for regular group.
  471. * @param __NBR_DISCONTINUOUS_CONV__ Number of discontinuous conversions.
  472. * @retval None
  473. */
  474. #define ADC_CFGR_DISCONTINUOUS_NUM(__NBR_DISCONTINUOUS_CONV__) (((__NBR_DISCONTINUOUS_CONV__) - 1) << ADC_CFGR_DISCNUM_Pos)
  475. /**
  476. * @brief Configure the ADC auto delay mode.
  477. * @param __AUTOWAIT__ Auto delay bit enable or disable.
  478. * @retval None
  479. */
  480. #define ADC_CFGR_AUTOWAIT(__AUTOWAIT__) ((__AUTOWAIT__) << ADC_CFGR_AUTDLY_Pos)
  481. /**
  482. * @brief Configure ADC continuous conversion mode.
  483. * @param __CONTINUOUS_MODE__ Continuous mode.
  484. * @retval None
  485. */
  486. #define ADC_CFGR_CONTINUOUS(__CONTINUOUS_MODE__) ((__CONTINUOUS_MODE__) << ADC_CFGR_CONT_Pos)
  487. /**
  488. * @brief Configure the ADC DMA continuous request.
  489. * @param __DMACONTREQ_MODE__ DMA continuous request mode.
  490. * @retval None
  491. */
  492. #define ADC_CFGR_DMACONTREQ(__DMACONTREQ_MODE__) ((__DMACONTREQ_MODE__) << ADC_CFGR_DMACFG_Pos)
  493. /**
  494. * @brief Configure the channel number into offset OFRx register.
  495. * @param __CHANNEL__ ADC Channel.
  496. * @retval None
  497. */
  498. #define ADC_OFR_CHANNEL(__CHANNEL__) ((__CHANNEL__) << ADC_OFR1_OFFSET1_CH_Pos)
  499. /**
  500. * @brief Configure the channel number into differential mode selection register.
  501. * @param __CHANNEL__ ADC Channel.
  502. * @retval None
  503. */
  504. #define ADC_DIFSEL_CHANNEL(__CHANNEL__) (1U << (__CHANNEL__))
  505. /**
  506. * @brief Configure calibration factor in differential mode to be set into calibration register.
  507. * @param __CALIBRATION_FACTOR__ Calibration factor value.
  508. * @retval None
  509. */
  510. #define ADC_CALFACT_DIFF_SET(__CALIBRATION_FACTOR__) (((__CALIBRATION_FACTOR__) & (ADC_CALFACT_CALFACT_D_Pos >> ADC_CALFACT_CALFACT_D_Pos) ) << ADC_CALFACT_CALFACT_D_Pos)
  511. /**
  512. * @brief Calibration factor in differential mode to be retrieved from calibration register.
  513. * @param __CALIBRATION_FACTOR__ Calibration factor value.
  514. * @retval None
  515. */
  516. #define ADC_CALFACT_DIFF_GET(__CALIBRATION_FACTOR__) ((__CALIBRATION_FACTOR__) >> ADC_CALFACT_CALFACT_D_Pos)
  517. /**
  518. * @brief Configure the analog watchdog high threshold into registers TR1, TR2 or TR3.
  519. * @param __THRESHOLD__ Threshold value.
  520. * @retval None
  521. */
  522. #define ADC_TRX_HIGHTHRESHOLD(__THRESHOLD__) ((__THRESHOLD__) << 16)
  523. #if defined(ADC_MULTIMODE_SUPPORT)
  524. /**
  525. * @brief Configure the ADC DMA continuous request for ADC multimode.
  526. * @param __DMACONTREQ_MODE__ DMA continuous request mode.
  527. * @retval None
  528. */
  529. #define ADC_CCR_MULTI_DMACONTREQ(__DMACONTREQ_MODE__) ((__DMACONTREQ_MODE__) << ADC_CCR_DMACFG_Pos)
  530. #endif /* ADC_MULTIMODE_SUPPORT */
  531. /**
  532. * @brief Enable the ADC peripheral.
  533. * @param __HANDLE__ ADC handle.
  534. * @retval None
  535. */
  536. #define ADC_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= ADC_CR_ADEN)
  537. /**
  538. * @brief Verification of hardware constraints before ADC can be enabled.
  539. * @param __HANDLE__ ADC handle.
  540. * @retval SET (ADC can be enabled) or RESET (ADC cannot be enabled)
  541. */
  542. #define ADC_ENABLING_CONDITIONS(__HANDLE__) \
  543. (( ( ((__HANDLE__)->Instance->CR) & \
  544. (ADC_CR_ADCAL | ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | \
  545. ADC_CR_ADSTART | ADC_CR_ADDIS | ADC_CR_ADEN ) \
  546. ) == RESET \
  547. ) ? SET : RESET)
  548. /**
  549. * @brief Disable the ADC peripheral.
  550. * @param __HANDLE__ ADC handle.
  551. * @retval None
  552. */
  553. #define ADC_DISABLE(__HANDLE__) \
  554. do{ \
  555. (__HANDLE__)->Instance->CR |= ADC_CR_ADDIS; \
  556. __HAL_ADC_CLEAR_FLAG((__HANDLE__), (ADC_FLAG_EOSMP | ADC_FLAG_RDY)); \
  557. } while(0)
  558. /**
  559. * @brief Verification of hardware constraints before ADC can be disabled.
  560. * @param __HANDLE__ ADC handle.
  561. * @retval SET (ADC can be disabled) or RESET (ADC cannot be disabled)
  562. */
  563. #define ADC_DISABLING_CONDITIONS(__HANDLE__) \
  564. (( ( ((__HANDLE__)->Instance->CR) & \
  565. (ADC_CR_JADSTART | ADC_CR_ADSTART | ADC_CR_ADEN)) == ADC_CR_ADEN \
  566. ) ? SET : RESET)
  567. /**
  568. * @brief Shift the offset with respect to the selected ADC resolution.
  569. * @note Offset has to be left-aligned on bit 11, the LSB (right bits) are set to 0.
  570. * If resolution 12 bits, no shift.
  571. * If resolution 10 bits, shift of 2 ranks on the left.
  572. * If resolution 8 bits, shift of 4 ranks on the left.
  573. * If resolution 6 bits, shift of 6 ranks on the left.
  574. * Therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2)).
  575. * @param __HANDLE__ ADC handle
  576. * @param __OFFSET__ Value to be shifted
  577. * @retval None
  578. */
  579. #define ADC_OFFSET_SHIFT_RESOLUTION(__HANDLE__, __OFFSET__) \
  580. ((__OFFSET__) << ((((__HANDLE__)->Instance->CFGR & ADC_CFGR_RES) >> 3)*2))
  581. /**
  582. * @brief Shift the AWD1 threshold with respect to the selected ADC resolution.
  583. * @note Thresholds have to be left-aligned on bit 11, the LSB (right bits) are set to 0.
  584. * If resolution 12 bits, no shift.
  585. * If resolution 10 bits, shift of 2 ranks on the left.
  586. * If resolution 8 bits, shift of 4 ranks on the left.
  587. * If resolution 6 bits, shift of 6 ranks on the left.
  588. * Therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2)).
  589. * @param __HANDLE__ ADC handle
  590. * @param __THRESHOLD__ Value to be shifted
  591. * @retval None
  592. */
  593. #define ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(__HANDLE__, __THRESHOLD__) \
  594. ((__THRESHOLD__) << ((((__HANDLE__)->Instance->CFGR & ADC_CFGR_RES) >> 3)*2))
  595. /**
  596. * @brief Shift the AWD2 and AWD3 threshold with respect to the selected ADC resolution.
  597. * @note Thresholds have to be left-aligned on bit 7.
  598. * If resolution 12 bits, shift of 4 ranks on the right (the 4 LSB are discarded).
  599. * If resolution 10 bits, shift of 2 ranks on the right (the 2 LSB are discarded).
  600. * If resolution 8 bits, no shift.
  601. * If resolution 6 bits, shift of 2 ranks on the left (the 2 LSB are set to 0).
  602. * @param __HANDLE__ ADC handle
  603. * @param __THRESHOLD__ Value to be shifted
  604. * @retval None
  605. */
  606. #define ADC_AWD23THRESHOLD_SHIFT_RESOLUTION(__HANDLE__, __THRESHOLD__) \
  607. ( ((__HANDLE__)->Instance->CFGR & ADC_CFGR_RES) != (ADC_CFGR_RES_1 | ADC_CFGR_RES_0) ? \
  608. ((__THRESHOLD__) >> (4- ((((__HANDLE__)->Instance->CFGR & ADC_CFGR_RES) >> 3)*2))) : \
  609. (__THRESHOLD__) << 2 )
  610. /**
  611. * @brief Report Master Instance.
  612. * @param __HANDLE__ ADC handle.
  613. * @note Return same instance if ADC of input handle is independent ADC or if
  614. * multimode feature is not available.
  615. * @retval Master Instance
  616. */
  617. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  618. #define ADC_MASTER_REGISTER(__HANDLE__) \
  619. ( ( ((((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC3)) \
  620. )? \
  621. ((__HANDLE__)->Instance) \
  622. : \
  623. (ADC1) \
  624. )
  625. #elif defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  626. #define ADC_MASTER_REGISTER(__HANDLE__) ((__HANDLE__)->Instance)
  627. #endif
  628. /**
  629. * @brief Clear Common Control Register.
  630. * @param __HANDLE__ ADC handle.
  631. * @retval None
  632. */
  633. #if defined(ADC_MULTIMODE_SUPPORT)
  634. #define ADC_CLEAR_COMMON_CONTROL_REGISTER(__HANDLE__) CLEAR_BIT(__LL_ADC_COMMON_INSTANCE((__HANDLE__)->Instance)->CCR, ADC_CCR_CKMODE | \
  635. ADC_CCR_PRESC | \
  636. ADC_CCR_VBATEN | \
  637. ADC_CCR_TSEN | \
  638. ADC_CCR_VREFEN | \
  639. ADC_CCR_MDMA | \
  640. ADC_CCR_DMACFG | \
  641. ADC_CCR_DELAY | \
  642. ADC_CCR_DUAL )
  643. #else
  644. #define ADC_CLEAR_COMMON_CONTROL_REGISTER(__HANDLE__) CLEAR_BIT(__LL_ADC_COMMON_INSTANCE((__HANDLE__)->Instance)->CCR, ADC_CCR_CKMODE | \
  645. ADC_CCR_PRESC | \
  646. ADC_CCR_VBATEN | \
  647. ADC_CCR_TSEN | \
  648. ADC_CCR_VREFEN )
  649. #endif /* ADC_MULTIMODE_SUPPORT */
  650. /**
  651. * @brief Check whether or not dual conversions are enabled.
  652. * @param __HANDLE__ ADC handle.
  653. * @note Return RESET if ADC of input handle is independent ADC or if multimode feature is not available.
  654. * @retval SET (dual regular conversions are enabled) or RESET (ADC is independent or no dual regular conversions are enabled)
  655. */
  656. #if defined(ADC_MULTIMODE_SUPPORT)
  657. #define ADC_IS_DUAL_CONVERSION_ENABLE(__HANDLE__) \
  658. ( ( ((((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC2)) \
  659. )? \
  660. ( ((ADC123_COMMON->CCR & ADC_CCR_DUAL) != ADC_MODE_INDEPENDENT) ) \
  661. : \
  662. RESET \
  663. )
  664. #else
  665. #define ADC_IS_DUAL_CONVERSION_ENABLE(__HANDLE__) (RESET)
  666. #endif
  667. /**
  668. * @brief Check whether or not dual regular conversions are enabled.
  669. * @param __HANDLE__ ADC handle.
  670. * @note Return RESET if ADC of input handle is independent ADC or if multimode feature is not available.
  671. * @retval SET (dual regular conversions are enabled) or RESET (ADC is independent or no dual regular conversions are enabled)
  672. */
  673. #if defined(ADC_MULTIMODE_SUPPORT)
  674. #define ADC_IS_DUAL_REGULAR_CONVERSION_ENABLE(__HANDLE__) \
  675. ( ( ((((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC2)) \
  676. )? \
  677. ( (((__LL_ADC_COMMON_INSTANCE((__HANDLE__)->Instance))->CCR & ADC_CCR_DUAL) != ADC_MODE_INDEPENDENT) && \
  678. (((__LL_ADC_COMMON_INSTANCE((__HANDLE__)->Instance))->CCR & ADC_CCR_DUAL) != ADC_DUALMODE_INJECSIMULT) && \
  679. (((__LL_ADC_COMMON_INSTANCE((__HANDLE__)->Instance))->CCR & ADC_CCR_DUAL) != ADC_DUALMODE_ALTERTRIG) ) \
  680. : \
  681. RESET \
  682. )
  683. #else
  684. #define ADC_IS_DUAL_REGULAR_CONVERSION_ENABLE(__HANDLE__) (RESET)
  685. #endif
  686. /**
  687. * @brief Verification of condition for ADC start conversion: ADC must be in non-multimode or multimode with handle of ADC master.
  688. * @param __HANDLE__ ADC handle.
  689. * @note Return SET if multimode feature is not available.
  690. * @retval SET (non-multimode or Master handle) or RESET (handle of Slave ADC in multimode)
  691. */
  692. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  693. #define ADC_NONMULTIMODE_OR_MULTIMODEMASTER(__HANDLE__) \
  694. ( ( ((__HANDLE__)->Instance == ADC1) || ((__HANDLE__)->Instance == ADC3) \
  695. )? \
  696. SET \
  697. : \
  698. ((ADC123_COMMON->CCR & ADC_CCR_DUAL) == RESET) \
  699. )
  700. #elif defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  701. #define ADC_NONMULTIMODE_OR_MULTIMODEMASTER(__HANDLE__) (SET)
  702. #endif
  703. /**
  704. * @brief Ensure ADC Instance is Independent or Master, or is not Slave ADC with dual regular conversions enabled.
  705. * @param __HANDLE__ ADC handle.
  706. * @note Return SET if multimode feature is not available.
  707. * @retval SET (Independent or Master, or Slave without dual regular conversions enabled) or RESET (Slave ADC with dual regular conversions enabled)
  708. */
  709. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  710. #define ADC_INDEPENDENT_OR_NONMULTIMODEREGULAR_SLAVE(__HANDLE__) \
  711. ( ( ((__HANDLE__)->Instance == ADC1) || ((__HANDLE__)->Instance == ADC3) \
  712. )? \
  713. SET \
  714. : \
  715. ( ((ADC123_COMMON->CCR & ADC_CCR_DUAL) == ADC_MODE_INDEPENDENT) || \
  716. ((ADC123_COMMON->CCR & ADC_CCR_DUAL) == ADC_DUALMODE_INJECSIMULT) || \
  717. ((ADC123_COMMON->CCR & ADC_CCR_DUAL) == ADC_DUALMODE_ALTERTRIG) ))
  718. #elif defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined( STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  719. #define ADC_INDEPENDENT_OR_NONMULTIMODEREGULAR_SLAVE(__HANDLE__) (SET)
  720. #endif
  721. /**
  722. * @brief Ensure ADC Instance is Independent or Master, or is not Slave ADC with dual injected conversions enabled.
  723. * @param __HANDLE__ ADC handle.
  724. * @note Return SET if multimode feature is not available.
  725. * @retval SET (non-multimode or Master, or Slave without dual injected conversions enabled) or RESET (Slave ADC with dual injected conversions enabled)
  726. */
  727. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  728. #define ADC_INDEPENDENT_OR_NONMULTIMODEINJECTED_SLAVE(__HANDLE__) \
  729. ( ( ((__HANDLE__)->Instance == ADC1) || ((__HANDLE__)->Instance == ADC3) \
  730. )? \
  731. SET \
  732. : \
  733. ( ((ADC123_COMMON->CCR & ADC_CCR_DUAL) == ADC_MODE_INDEPENDENT) || \
  734. ((ADC123_COMMON->CCR & ADC_CCR_DUAL) == ADC_DUALMODE_REGSIMULT) || \
  735. ((ADC123_COMMON->CCR & ADC_CCR_DUAL) == ADC_DUALMODE_INTERL) ))
  736. #elif defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  737. #define ADC_INDEPENDENT_OR_NONMULTIMODEINJECTED_SLAVE(__HANDLE__) (SET)
  738. #endif
  739. /**
  740. * @brief Verification of ADC state: enabled or disabled, directly checked on instance as input parameter.
  741. * @param __INSTANCE__ ADC instance.
  742. * @retval SET (ADC enabled) or RESET (ADC disabled)
  743. */
  744. #define ADC_INSTANCE_IS_ENABLED(__INSTANCE__) \
  745. (( ((((__INSTANCE__)->CR) & (ADC_CR_ADEN | ADC_CR_ADDIS)) == ADC_CR_ADEN) && \
  746. ((((__INSTANCE__)->ISR) & ADC_FLAG_RDY) == ADC_FLAG_RDY) \
  747. ) ? SET : RESET)
  748. /**
  749. * @brief Verification of enabled/disabled status of ADCs other than that associated to the input parameter handle.
  750. * @param __HANDLE__ ADC handle.
  751. * @retval SET (at least one other ADC is enabled) or RESET (no other ADC is enabled, all other ADCs are disabled)
  752. */
  753. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  754. #define ADC_ANY_OTHER_ENABLED(__HANDLE__) \
  755. ( ( ((__HANDLE__)->Instance == ADC1) \
  756. )? \
  757. (ADC_INSTANCE_IS_ENABLED(ADC2)) || (ADC_INSTANCE_IS_ENABLED(ADC3)) \
  758. : \
  759. ( ( ((__HANDLE__)->Instance == ADC2) \
  760. )? \
  761. (ADC_INSTANCE_IS_ENABLED(ADC1)) || (ADC_INSTANCE_IS_ENABLED(ADC3)) \
  762. : \
  763. ADC_INSTANCE_IS_ENABLED(ADC1)) || (ADC_INSTANCE_IS_ENABLED(ADC2)) \
  764. )
  765. #elif defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  766. #define ADC_ANY_OTHER_ENABLED(__HANDLE__) (RESET)
  767. #endif
  768. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  769. /**
  770. * @brief Set handle instance of the ADC slave associated to the ADC master.
  771. * @param __HANDLE_MASTER__ ADC master handle.
  772. * @param __HANDLE_SLAVE__ ADC slave handle.
  773. * @note if __HANDLE_MASTER__ is the handle of a slave ADC or an independent ADC, __HANDLE_SLAVE__ instance is set to NULL.
  774. * @retval None
  775. */
  776. #define ADC_MULTI_SLAVE(__HANDLE_MASTER__, __HANDLE_SLAVE__) \
  777. ( (((__HANDLE_MASTER__)->Instance == ADC1)) ? ((__HANDLE_SLAVE__)->Instance = ADC2) : ((__HANDLE_SLAVE__)->Instance = NULL) )
  778. #endif /* defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) */
  779. /**
  780. * @brief Check whether or not multimode is configured in DMA mode.
  781. * @param __HANDLE__ ADC handle.
  782. * @note Return RESET if multimode feature is not available.
  783. * @retval SET (multimode is configured in DMA mode) or RESET (DMA multimode is disabled)
  784. */
  785. #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  786. #define ADC_MULTIMODE_DMA_ENABLED(__HANDLE__) \
  787. ((READ_BIT(ADC123_COMMON->CCR, ADC_CCR_MDMA) == ADC_DMAACCESSMODE_12_10_BITS) \
  788. || (READ_BIT(ADC123_COMMON->CCR, ADC_CCR_MDMA) == ADC_DMAACCESSMODE_8_6_BITS))
  789. #elif defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  790. #define ADC_MULTIMODE_DMA_ENABLED(__HANDLE__) (RESET)
  791. #endif
  792. /**
  793. * @brief Verify the ADC instance connected to the temperature sensor.
  794. * @param __HANDLE__ ADC handle.
  795. * @retval SET (ADC instance is valid) or RESET (ADC instance is invalid)
  796. */
  797. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  798. /* The temperature sensor measurement path (channel 17) is available on ADC1 */
  799. #define ADC_TEMPERATURE_SENSOR_INSTANCE(__HANDLE__) (((__HANDLE__)->Instance) == ADC1)
  800. #elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  801. /* The temperature sensor measurement path (channel 17) is available on ADC1 and ADC3 */
  802. #define ADC_TEMPERATURE_SENSOR_INSTANCE(__HANDLE__) ((((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC3))
  803. #endif
  804. /**
  805. * @brief Verify the ADC instance connected to the battery voltage VBAT.
  806. * @param __HANDLE__ ADC handle.
  807. * @retval SET (ADC instance is valid) or RESET (ADC instance is invalid)
  808. */
  809. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  810. /* The battery voltage measurement path (channel 18) is available on ADC1 */
  811. #define ADC_BATTERY_VOLTAGE_INSTANCE(__HANDLE__) (((__HANDLE__)->Instance) == ADC1)
  812. #elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  813. /* The battery voltage measurement path (channel 18) is available on ADC1 and ADC3 */
  814. #define ADC_BATTERY_VOLTAGE_INSTANCE(__HANDLE__) ((((__HANDLE__)->Instance) == ADC1) || (((__HANDLE__)->Instance) == ADC3))
  815. #endif
  816. /**
  817. * @brief Verify the ADC instance connected to the internal voltage reference VREFINT.
  818. * @param __HANDLE__ ADC handle.
  819. * @retval SET (ADC instance is valid) or RESET (ADC instance is invalid)
  820. */
  821. /* The internal voltage reference VREFINT measurement path (channel 0) is available on ADC1 */
  822. #define ADC_VREFINT_INSTANCE(__HANDLE__) (((__HANDLE__)->Instance) == ADC1)
  823. /**
  824. * @brief Verify the length of scheduled injected conversions group.
  825. * @param __LENGTH__ number of programmed conversions.
  826. * @retval SET (__LENGTH__ is within the maximum number of possible programmable injected conversions) or RESET (__LENGTH__ is null or too large)
  827. */
  828. #define IS_ADC_INJECTED_NB_CONV(__LENGTH__) (((__LENGTH__) >= (1U)) && ((__LENGTH__) <= (4U)))
  829. /**
  830. * @brief Calibration factor size verification (7 bits maximum).
  831. * @param __CALIBRATION_FACTOR__ Calibration factor value.
  832. * @retval SET (__CALIBRATION_FACTOR__ is within the authorized size) or RESET (__CALIBRATION_FACTOR__ is too large)
  833. */
  834. #define IS_ADC_CALFACT(__CALIBRATION_FACTOR__) ((__CALIBRATION_FACTOR__) <= (0x7FU))
  835. /**
  836. * @brief Verify the ADC channel setting.
  837. * @param __HANDLE__ ADC handle.
  838. * @param __CHANNEL__ programmed ADC channel.
  839. * @retval SET (__CHANNEL__ is valid) or RESET (__CHANNEL__ is invalid)
  840. */
  841. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  842. #define IS_ADC_CHANNEL(__HANDLE__, __CHANNEL__) ((((__HANDLE__)->Instance) == ADC1) && \
  843. (((__CHANNEL__) == ADC_CHANNEL_1) || \
  844. ((__CHANNEL__) == ADC_CHANNEL_2) || \
  845. ((__CHANNEL__) == ADC_CHANNEL_3) || \
  846. ((__CHANNEL__) == ADC_CHANNEL_4) || \
  847. ((__CHANNEL__) == ADC_CHANNEL_5) || \
  848. ((__CHANNEL__) == ADC_CHANNEL_6) || \
  849. ((__CHANNEL__) == ADC_CHANNEL_7) || \
  850. ((__CHANNEL__) == ADC_CHANNEL_8) || \
  851. ((__CHANNEL__) == ADC_CHANNEL_9) || \
  852. ((__CHANNEL__) == ADC_CHANNEL_10) || \
  853. ((__CHANNEL__) == ADC_CHANNEL_11) || \
  854. ((__CHANNEL__) == ADC_CHANNEL_12) || \
  855. ((__CHANNEL__) == ADC_CHANNEL_13) || \
  856. ((__CHANNEL__) == ADC_CHANNEL_14) || \
  857. ((__CHANNEL__) == ADC_CHANNEL_15) || \
  858. ((__CHANNEL__) == ADC_CHANNEL_16) || \
  859. ((__CHANNEL__) == ADC_CHANNEL_17) || \
  860. ((__CHANNEL__) == ADC_CHANNEL_18) || \
  861. ((__CHANNEL__) == ADC_CHANNEL_VREFINT) || \
  862. ((__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR) || \
  863. ((__CHANNEL__) == ADC_CHANNEL_VBAT) || \
  864. ((__CHANNEL__) == ADC_CHANNEL_DAC1CH1) || \
  865. ((__CHANNEL__) == ADC_CHANNEL_DAC1CH2)))
  866. #elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  867. #define IS_ADC_CHANNEL(__HANDLE__, __CHANNEL__) (((((__HANDLE__)->Instance) == ADC1) && \
  868. (((__CHANNEL__) == ADC_CHANNEL_1) || \
  869. ((__CHANNEL__) == ADC_CHANNEL_2) || \
  870. ((__CHANNEL__) == ADC_CHANNEL_3) || \
  871. ((__CHANNEL__) == ADC_CHANNEL_4) || \
  872. ((__CHANNEL__) == ADC_CHANNEL_5) || \
  873. ((__CHANNEL__) == ADC_CHANNEL_6) || \
  874. ((__CHANNEL__) == ADC_CHANNEL_7) || \
  875. ((__CHANNEL__) == ADC_CHANNEL_8) || \
  876. ((__CHANNEL__) == ADC_CHANNEL_9) || \
  877. ((__CHANNEL__) == ADC_CHANNEL_10) || \
  878. ((__CHANNEL__) == ADC_CHANNEL_11) || \
  879. ((__CHANNEL__) == ADC_CHANNEL_12) || \
  880. ((__CHANNEL__) == ADC_CHANNEL_13) || \
  881. ((__CHANNEL__) == ADC_CHANNEL_14) || \
  882. ((__CHANNEL__) == ADC_CHANNEL_15) || \
  883. ((__CHANNEL__) == ADC_CHANNEL_16) || \
  884. ((__CHANNEL__) == ADC_CHANNEL_VREFINT) || \
  885. ((__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR) || \
  886. ((__CHANNEL__) == ADC_CHANNEL_VBAT))) || \
  887. ((((__HANDLE__)->Instance) == ADC2) && \
  888. (((__CHANNEL__) == ADC_CHANNEL_1) || \
  889. ((__CHANNEL__) == ADC_CHANNEL_2) || \
  890. ((__CHANNEL__) == ADC_CHANNEL_3) || \
  891. ((__CHANNEL__) == ADC_CHANNEL_4) || \
  892. ((__CHANNEL__) == ADC_CHANNEL_5) || \
  893. ((__CHANNEL__) == ADC_CHANNEL_6) || \
  894. ((__CHANNEL__) == ADC_CHANNEL_7) || \
  895. ((__CHANNEL__) == ADC_CHANNEL_8) || \
  896. ((__CHANNEL__) == ADC_CHANNEL_9) || \
  897. ((__CHANNEL__) == ADC_CHANNEL_10) || \
  898. ((__CHANNEL__) == ADC_CHANNEL_11) || \
  899. ((__CHANNEL__) == ADC_CHANNEL_12) || \
  900. ((__CHANNEL__) == ADC_CHANNEL_13) || \
  901. ((__CHANNEL__) == ADC_CHANNEL_14) || \
  902. ((__CHANNEL__) == ADC_CHANNEL_15) || \
  903. ((__CHANNEL__) == ADC_CHANNEL_16) || \
  904. ((__CHANNEL__) == ADC_CHANNEL_17) || \
  905. ((__CHANNEL__) == ADC_CHANNEL_18) || \
  906. ((__CHANNEL__) == ADC_CHANNEL_DAC1CH1_ADC2) || \
  907. ((__CHANNEL__) == ADC_CHANNEL_DAC1CH2_ADC2))) || \
  908. ((((__HANDLE__)->Instance) == ADC3) && \
  909. (((__CHANNEL__) == ADC_CHANNEL_1) || \
  910. ((__CHANNEL__) == ADC_CHANNEL_2) || \
  911. ((__CHANNEL__) == ADC_CHANNEL_3) || \
  912. ((__CHANNEL__) == ADC_CHANNEL_4) || \
  913. ((__CHANNEL__) == ADC_CHANNEL_6) || \
  914. ((__CHANNEL__) == ADC_CHANNEL_7) || \
  915. ((__CHANNEL__) == ADC_CHANNEL_8) || \
  916. ((__CHANNEL__) == ADC_CHANNEL_9) || \
  917. ((__CHANNEL__) == ADC_CHANNEL_10) || \
  918. ((__CHANNEL__) == ADC_CHANNEL_11) || \
  919. ((__CHANNEL__) == ADC_CHANNEL_12) || \
  920. ((__CHANNEL__) == ADC_CHANNEL_13) || \
  921. ((__CHANNEL__) == ADC_CHANNEL_14) || \
  922. ((__CHANNEL__) == ADC_CHANNEL_15) || \
  923. ((__CHANNEL__) == ADC_CHANNEL_TEMPSENSOR) || \
  924. ((__CHANNEL__) == ADC_CHANNEL_VBAT) || \
  925. ((__CHANNEL__) == ADC_CHANNEL_DAC1CH1_ADC3) || \
  926. ((__CHANNEL__) == ADC_CHANNEL_DAC1CH2_ADC3) )))
  927. #endif
  928. /**
  929. * @brief Verify the ADC channel setting in differential mode.
  930. * @param __HANDLE__ ADC handle.
  931. * @param __CHANNEL__ programmed ADC channel.
  932. * @retval SET (__CHANNEL__ is valid) or RESET (__CHANNEL__ is invalid)
  933. */
  934. #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
  935. #define IS_ADC_DIFF_CHANNEL(__HANDLE__, __CHANNEL__) (((__CHANNEL__) == ADC_CHANNEL_1) || \
  936. ((__CHANNEL__) == ADC_CHANNEL_2) || \
  937. ((__CHANNEL__) == ADC_CHANNEL_3) || \
  938. ((__CHANNEL__) == ADC_CHANNEL_4) || \
  939. ((__CHANNEL__) == ADC_CHANNEL_5) || \
  940. ((__CHANNEL__) == ADC_CHANNEL_6) || \
  941. ((__CHANNEL__) == ADC_CHANNEL_7) || \
  942. ((__CHANNEL__) == ADC_CHANNEL_8) || \
  943. ((__CHANNEL__) == ADC_CHANNEL_9) || \
  944. ((__CHANNEL__) == ADC_CHANNEL_10) || \
  945. ((__CHANNEL__) == ADC_CHANNEL_11) || \
  946. ((__CHANNEL__) == ADC_CHANNEL_12) || \
  947. ((__CHANNEL__) == ADC_CHANNEL_13) || \
  948. ((__CHANNEL__) == ADC_CHANNEL_14) || \
  949. ((__CHANNEL__) == ADC_CHANNEL_15) )
  950. #elif defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
  951. /* For ADC1 and ADC2, channels 1 to 15 are available in differential mode,
  952. channels 0, 16 to 18 can be only used in single-ended mode.
  953. For ADC3, channels 1 to 3 and 6 to 12 are available in differential mode,
  954. channels 4, 5 and 13 to 18 can only be used in single-ended mode. */
  955. #define IS_ADC_DIFF_CHANNEL(__HANDLE__, __CHANNEL__) ((((((__HANDLE__)->Instance) == ADC1) || \
  956. (((__HANDLE__)->Instance) == ADC2)) && \
  957. (((__CHANNEL__) == ADC_CHANNEL_1) || \
  958. ((__CHANNEL__) == ADC_CHANNEL_2) || \
  959. ((__CHANNEL__) == ADC_CHANNEL_3) || \
  960. ((__CHANNEL__) == ADC_CHANNEL_4) || \
  961. ((__CHANNEL__) == ADC_CHANNEL_5) || \
  962. ((__CHANNEL__) == ADC_CHANNEL_6) || \
  963. ((__CHANNEL__) == ADC_CHANNEL_7) || \
  964. ((__CHANNEL__) == ADC_CHANNEL_8) || \
  965. ((__CHANNEL__) == ADC_CHANNEL_9) || \
  966. ((__CHANNEL__) == ADC_CHANNEL_10) || \
  967. ((__CHANNEL__) == ADC_CHANNEL_11) || \
  968. ((__CHANNEL__) == ADC_CHANNEL_12) || \
  969. ((__CHANNEL__) == ADC_CHANNEL_13) || \
  970. ((__CHANNEL__) == ADC_CHANNEL_14) || \
  971. ((__CHANNEL__) == ADC_CHANNEL_15))) || \
  972. ((((__HANDLE__)->Instance) == ADC3) && \
  973. (((__CHANNEL__) == ADC_CHANNEL_1) || \
  974. ((__CHANNEL__) == ADC_CHANNEL_2) || \
  975. ((__CHANNEL__) == ADC_CHANNEL_3) || \
  976. ((__CHANNEL__) == ADC_CHANNEL_6) || \
  977. ((__CHANNEL__) == ADC_CHANNEL_7) || \
  978. ((__CHANNEL__) == ADC_CHANNEL_8) || \
  979. ((__CHANNEL__) == ADC_CHANNEL_9) || \
  980. ((__CHANNEL__) == ADC_CHANNEL_10) || \
  981. ((__CHANNEL__) == ADC_CHANNEL_11) || \
  982. ((__CHANNEL__) == ADC_CHANNEL_12) )))
  983. #endif
  984. /**
  985. * @brief Verify the ADC single-ended input or differential mode setting.
  986. * @param __SING_DIFF__ programmed channel setting.
  987. * @retval SET (__SING_DIFF__ is valid) or RESET (__SING_DIFF__ is invalid)
  988. */
  989. #define IS_ADC_SINGLE_DIFFERENTIAL(__SING_DIFF__) (((__SING_DIFF__) == ADC_SINGLE_ENDED) || \
  990. ((__SING_DIFF__) == ADC_DIFFERENTIAL_ENDED) )
  991. /**
  992. * @brief Verify the ADC offset management setting.
  993. * @param __OFFSET_NUMBER__ ADC offset management.
  994. * @retval SET (__OFFSET_NUMBER__ is valid) or RESET (__OFFSET_NUMBER__ is invalid)
  995. */
  996. #define IS_ADC_OFFSET_NUMBER(__OFFSET_NUMBER__) (((__OFFSET_NUMBER__) == ADC_OFFSET_NONE) || \
  997. ((__OFFSET_NUMBER__) == ADC_OFFSET_1) || \
  998. ((__OFFSET_NUMBER__) == ADC_OFFSET_2) || \
  999. ((__OFFSET_NUMBER__) == ADC_OFFSET_3) || \
  1000. ((__OFFSET_NUMBER__) == ADC_OFFSET_4) )
  1001. /**
  1002. * @brief Verify the ADC injected channel setting.
  1003. * @param __CHANNEL__ programmed ADC injected channel.
  1004. * @retval SET (__CHANNEL__ is valid) or RESET (__CHANNEL__ is invalid)
  1005. */
  1006. #define IS_ADC_INJECTED_RANK(__CHANNEL__) (((__CHANNEL__) == ADC_INJECTED_RANK_1) || \
  1007. ((__CHANNEL__) == ADC_INJECTED_RANK_2) || \
  1008. ((__CHANNEL__) == ADC_INJECTED_RANK_3) || \
  1009. ((__CHANNEL__) == ADC_INJECTED_RANK_4) )
  1010. /**
  1011. * @brief Verify the ADC injected conversions external trigger.
  1012. * @param __HANDLE__ ADC handle.
  1013. * @param __INJTRIG__ programmed ADC injected conversions external trigger.
  1014. * @retval SET (__INJTRIG__ is a valid value) or RESET (__INJTRIG__ is invalid)
  1015. */
  1016. #define IS_ADC_EXTTRIGINJEC(__HANDLE__, __INJTRIG__) (((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T1_TRGO) || \
  1017. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T1_CC4) || \
  1018. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T2_TRGO) || \
  1019. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T2_CC1) || \
  1020. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T3_CC4) || \
  1021. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T4_TRGO) || \
  1022. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_EXT_IT15) || \
  1023. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T8_CC4) || \
  1024. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T1_TRGO2) || \
  1025. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T8_TRGO) || \
  1026. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T8_TRGO2) || \
  1027. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T3_CC3) || \
  1028. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T3_TRGO) || \
  1029. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T3_CC1) || \
  1030. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T6_TRGO) || \
  1031. ((__INJTRIG__) == ADC_EXTERNALTRIGINJEC_T15_TRGO) || \
  1032. ((__INJTRIG__) == ADC_INJECTED_SOFTWARE_START) )
  1033. /**
  1034. * @brief Verify the ADC edge trigger setting for injected group.
  1035. * @param __EDGE__ programmed ADC edge trigger setting.
  1036. * @retval SET (__EDGE__ is a valid value) or RESET (__EDGE__ is invalid)
  1037. */
  1038. #define IS_ADC_EXTTRIGINJEC_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGINJECCONV_EDGE_NONE) || \
  1039. ((__EDGE__) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISING) || \
  1040. ((__EDGE__) == ADC_EXTERNALTRIGINJECCONV_EDGE_FALLING) || \
  1041. ((__EDGE__) == ADC_EXTERNALTRIGINJECCONV_EDGE_RISINGFALLING) )
  1042. #if defined(ADC_MULTIMODE_SUPPORT)
  1043. /**
  1044. * @brief Verify the ADC multimode setting.
  1045. * @param __MODE__ programmed ADC multimode setting.
  1046. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  1047. */
  1048. #define IS_ADC_MULTIMODE(__MODE__) (((__MODE__) == ADC_MODE_INDEPENDENT) || \
  1049. ((__MODE__) == ADC_DUALMODE_REGSIMULT_INJECSIMULT) || \
  1050. ((__MODE__) == ADC_DUALMODE_REGSIMULT_ALTERTRIG) || \
  1051. ((__MODE__) == ADC_DUALMODE_REGINTERL_INJECSIMULT) || \
  1052. ((__MODE__) == ADC_DUALMODE_INJECSIMULT) || \
  1053. ((__MODE__) == ADC_DUALMODE_REGSIMULT) || \
  1054. ((__MODE__) == ADC_DUALMODE_INTERL) || \
  1055. ((__MODE__) == ADC_DUALMODE_ALTERTRIG) )
  1056. /**
  1057. * @brief Verify the ADC multimode DMA access setting.
  1058. * @param __MODE__ programmed ADC multimode DMA access setting.
  1059. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  1060. */
  1061. #define IS_ADC_DMA_ACCESS_MULTIMODE(__MODE__) (((__MODE__) == ADC_DMAACCESSMODE_DISABLED) || \
  1062. ((__MODE__) == ADC_DMAACCESSMODE_12_10_BITS) || \
  1063. ((__MODE__) == ADC_DMAACCESSMODE_8_6_BITS) )
  1064. /**
  1065. * @brief Verify the ADC multimode delay setting.
  1066. * @param __DELAY__ programmed ADC multimode delay setting.
  1067. * @retval SET (__DELAY__ is a valid value) or RESET (__DELAY__ is invalid)
  1068. */
  1069. #define IS_ADC_SAMPLING_DELAY(__DELAY__) (((__DELAY__) == ADC_TWOSAMPLINGDELAY_1CYCLE) || \
  1070. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_2CYCLES) || \
  1071. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_3CYCLES) || \
  1072. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_4CYCLES) || \
  1073. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_5CYCLES) || \
  1074. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_6CYCLES) || \
  1075. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_7CYCLES) || \
  1076. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_8CYCLES) || \
  1077. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_9CYCLES) || \
  1078. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_10CYCLES) || \
  1079. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_11CYCLES) || \
  1080. ((__DELAY__) == ADC_TWOSAMPLINGDELAY_12CYCLES) )
  1081. #endif /* ADC_MULTIMODE_SUPPORT */
  1082. /**
  1083. * @brief Verify the ADC analog watchdog setting.
  1084. * @param __WATCHDOG__ programmed ADC analog watchdog setting.
  1085. * @retval SET (__WATCHDOG__ is valid) or RESET (__WATCHDOG__ is invalid)
  1086. */
  1087. #define IS_ADC_ANALOG_WATCHDOG_NUMBER(__WATCHDOG__) (((__WATCHDOG__) == ADC_ANALOGWATCHDOG_1) || \
  1088. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_2) || \
  1089. ((__WATCHDOG__) == ADC_ANALOGWATCHDOG_3) )
  1090. /**
  1091. * @brief Verify the ADC analog watchdog mode setting.
  1092. * @param __WATCHDOG_MODE__ programmed ADC analog watchdog mode setting.
  1093. * @retval SET (__WATCHDOG_MODE__ is valid) or RESET (__WATCHDOG_MODE__ is invalid)
  1094. */
  1095. #define IS_ADC_ANALOG_WATCHDOG_MODE(__WATCHDOG_MODE__) (((__WATCHDOG_MODE__) == ADC_ANALOGWATCHDOG_NONE) || \
  1096. ((__WATCHDOG_MODE__) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \
  1097. ((__WATCHDOG_MODE__) == ADC_ANALOGWATCHDOG_SINGLE_INJEC) || \
  1098. ((__WATCHDOG_MODE__) == ADC_ANALOGWATCHDOG_SINGLE_REGINJEC) || \
  1099. ((__WATCHDOG_MODE__) == ADC_ANALOGWATCHDOG_ALL_REG) || \
  1100. ((__WATCHDOG_MODE__) == ADC_ANALOGWATCHDOG_ALL_INJEC) || \
  1101. ((__WATCHDOG_MODE__) == ADC_ANALOGWATCHDOG_ALL_REGINJEC) )
  1102. /**
  1103. * @brief Verify the ADC conversion (regular or injected or both).
  1104. * @param __CONVERSION__ ADC conversion group.
  1105. * @retval SET (__CONVERSION__ is valid) or RESET (__CONVERSION__ is invalid)
  1106. */
  1107. #define IS_ADC_CONVERSION_GROUP(__CONVERSION__) (((__CONVERSION__) == ADC_REGULAR_GROUP) || \
  1108. ((__CONVERSION__) == ADC_INJECTED_GROUP) || \
  1109. ((__CONVERSION__) == ADC_REGULAR_INJECTED_GROUP) )
  1110. /**
  1111. * @brief Verify the ADC event type.
  1112. * @param __EVENT__ ADC event.
  1113. * @retval SET (__EVENT__ is valid) or RESET (__EVENT__ is invalid)
  1114. */
  1115. #define IS_ADC_EVENT_TYPE(__EVENT__) (((__EVENT__) == ADC_EOSMP_EVENT) || \
  1116. ((__EVENT__) == ADC_AWD_EVENT) || \
  1117. ((__EVENT__) == ADC_AWD2_EVENT) || \
  1118. ((__EVENT__) == ADC_AWD3_EVENT) || \
  1119. ((__EVENT__) == ADC_OVR_EVENT) || \
  1120. ((__EVENT__) == ADC_JQOVF_EVENT) )
  1121. /**
  1122. * @brief Verify the ADC oversampling ratio.
  1123. * @param __RATIO__ programmed ADC oversampling ratio.
  1124. * @retval SET (__RATIO__ is a valid value) or RESET (__RATIO__ is invalid)
  1125. */
  1126. #define IS_ADC_OVERSAMPLING_RATIO(__RATIO__) (((__RATIO__) == ADC_OVERSAMPLING_RATIO_2 ) || \
  1127. ((__RATIO__) == ADC_OVERSAMPLING_RATIO_4 ) || \
  1128. ((__RATIO__) == ADC_OVERSAMPLING_RATIO_8 ) || \
  1129. ((__RATIO__) == ADC_OVERSAMPLING_RATIO_16 ) || \
  1130. ((__RATIO__) == ADC_OVERSAMPLING_RATIO_32 ) || \
  1131. ((__RATIO__) == ADC_OVERSAMPLING_RATIO_64 ) || \
  1132. ((__RATIO__) == ADC_OVERSAMPLING_RATIO_128 ) || \
  1133. ((__RATIO__) == ADC_OVERSAMPLING_RATIO_256 ))
  1134. /**
  1135. * @brief Verify the ADC oversampling shift.
  1136. * @param __SHIFT__ programmed ADC oversampling shift.
  1137. * @retval SET (__SHIFT__ is a valid value) or RESET (__SHIFT__ is invalid)
  1138. */
  1139. #define IS_ADC_RIGHT_BIT_SHIFT(__SHIFT__) (((__SHIFT__) == ADC_RIGHTBITSHIFT_NONE) || \
  1140. ((__SHIFT__) == ADC_RIGHTBITSHIFT_1 ) || \
  1141. ((__SHIFT__) == ADC_RIGHTBITSHIFT_2 ) || \
  1142. ((__SHIFT__) == ADC_RIGHTBITSHIFT_3 ) || \
  1143. ((__SHIFT__) == ADC_RIGHTBITSHIFT_4 ) || \
  1144. ((__SHIFT__) == ADC_RIGHTBITSHIFT_5 ) || \
  1145. ((__SHIFT__) == ADC_RIGHTBITSHIFT_6 ) || \
  1146. ((__SHIFT__) == ADC_RIGHTBITSHIFT_7 ) || \
  1147. ((__SHIFT__) == ADC_RIGHTBITSHIFT_8 ))
  1148. /**
  1149. * @brief Verify the ADC oversampling triggered mode.
  1150. * @param __MODE__ programmed ADC oversampling triggered mode.
  1151. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  1152. */
  1153. #define IS_ADC_TRIGGERED_OVERSAMPLING_MODE(__MODE__) (((__MODE__) == ADC_TRIGGEREDMODE_SINGLE_TRIGGER) || \
  1154. ((__MODE__) == ADC_TRIGGEREDMODE_MULTI_TRIGGER) )
  1155. /**
  1156. * @brief Verify the ADC oversampling regular conversion resumed or continued mode.
  1157. * @param __MODE__ programmed ADC oversampling regular conversion resumed or continued mode.
  1158. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  1159. */
  1160. #define IS_ADC_REGOVERSAMPLING_MODE(__MODE__) (((__MODE__) == ADC_REGOVERSAMPLING_CONTINUED_MODE) || \
  1161. ((__MODE__) == ADC_REGOVERSAMPLING_RESUMED_MODE) )
  1162. /**
  1163. * @brief Verify the DFSDM mode configuration.
  1164. * @param __HANDLE__ ADC handle.
  1165. * @note When DMSDFM configuration is not supported, the macro systematically reports SET. For
  1166. * this reason, the input parameter is the ADC handle and not the configuration parameter
  1167. * directly.
  1168. * @retval SET (DFSDM mode configuration is valid) or RESET (DFSDM mode configuration is invalid)
  1169. */
  1170. #if defined(ADC_CFGR_DFSDMCFG) &&defined(DFSDM1_Channel0)
  1171. #define IS_ADC_DFSDMCFG_MODE(__HANDLE__) (((__HANDLE__)->Init.DFSDMConfig == ADC_DFSDM_MODE_DISABLE) || \
  1172. ((__HANDLE__)->Init.DFSDMConfig == ADC_DFSDM_MODE_ENABLE) )
  1173. #else
  1174. #define IS_ADC_DFSDMCFG_MODE(__HANDLE__) (SET)
  1175. #endif
  1176. /**
  1177. * @brief Return the DFSDM configuration mode.
  1178. * @param __HANDLE__ ADC handle.
  1179. * @note When DMSDFM configuration is not supported, the macro systematically reports 0x0 (i.e disabled).
  1180. * For this reason, the input parameter is the ADC handle and not the configuration parameter
  1181. * directly.
  1182. * @retval DFSDM configuration mode
  1183. */
  1184. #if defined(ADC_CFGR_DFSDMCFG) &&defined(DFSDM1_Channel0)
  1185. #define ADC_CFGR_DFSDM(__HANDLE__) ((__HANDLE__)->Init.DFSDMConfig)
  1186. #else
  1187. #define ADC_CFGR_DFSDM(__HANDLE__) (0x0)
  1188. #endif
  1189. /**
  1190. * @}
  1191. */
  1192. /* Exported functions --------------------------------------------------------*/
  1193. /** @addtogroup ADCEx_Exported_Functions
  1194. * @{
  1195. */
  1196. /** @addtogroup ADCEx_Exported_Functions_Group1
  1197. * @{
  1198. */
  1199. /* IO operation functions *****************************************************/
  1200. /* ADC calibration */
  1201. HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc, uint32_t SingleDiff);
  1202. uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff);
  1203. HAL_StatusTypeDef HAL_ADCEx_Calibration_SetValue(ADC_HandleTypeDef *hadc, uint32_t SingleDiff, uint32_t CalibrationFactor);
  1204. /* Blocking mode: Polling */
  1205. HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc);
  1206. HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc);
  1207. HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  1208. /* Non-blocking mode: Interruption */
  1209. HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc);
  1210. HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc);
  1211. #if defined(ADC_MULTIMODE_SUPPORT)
  1212. /* ADC multimode */
  1213. HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);
  1214. HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc);
  1215. uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc);
  1216. #endif /* ADC_MULTIMODE_SUPPORT */
  1217. /* ADC retrieve conversion value intended to be used with polling or interruption */
  1218. uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank);
  1219. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption) */
  1220. void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc);
  1221. void HAL_ADCEx_InjectedQueueOverflowCallback(ADC_HandleTypeDef* hadc);
  1222. void HAL_ADCEx_LevelOutOfWindow2Callback(ADC_HandleTypeDef* hadc);
  1223. void HAL_ADCEx_LevelOutOfWindow3Callback(ADC_HandleTypeDef* hadc);
  1224. void HAL_ADCEx_EndOfSamplingCallback(ADC_HandleTypeDef* hadc);
  1225. /* ADC group regular conversions stop */
  1226. HAL_StatusTypeDef HAL_ADCEx_RegularStop(ADC_HandleTypeDef* hadc);
  1227. HAL_StatusTypeDef HAL_ADCEx_RegularStop_IT(ADC_HandleTypeDef* hadc);
  1228. HAL_StatusTypeDef HAL_ADCEx_RegularStop_DMA(ADC_HandleTypeDef* hadc);
  1229. #if defined(ADC_MULTIMODE_SUPPORT)
  1230. HAL_StatusTypeDef HAL_ADCEx_RegularMultiModeStop_DMA(ADC_HandleTypeDef* hadc);
  1231. #endif /* ADC_MULTIMODE_SUPPORT */
  1232. /**
  1233. * @}
  1234. */
  1235. /** @addtogroup ADCEx_Exported_Functions_Group2
  1236. * @{
  1237. */
  1238. /* Peripheral Control functions ***********************************************/
  1239. HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc,ADC_InjectionConfTypeDef* sConfigInjected);
  1240. #if defined(ADC_MULTIMODE_SUPPORT)
  1241. HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode);
  1242. #endif /* ADC_MULTIMODE_SUPPORT */
  1243. HAL_StatusTypeDef HAL_ADCEx_EnableInjectedQueue(ADC_HandleTypeDef* hadc);
  1244. HAL_StatusTypeDef HAL_ADCEx_DisableInjectedQueue(ADC_HandleTypeDef* hadc);
  1245. HAL_StatusTypeDef HAL_ADCEx_DisableVoltageRegulator(ADC_HandleTypeDef* hadc);
  1246. HAL_StatusTypeDef HAL_ADCEx_EnterADCDeepPowerDownMode(ADC_HandleTypeDef* hadc);
  1247. /**
  1248. * @}
  1249. */
  1250. /**
  1251. * @}
  1252. */
  1253. /**
  1254. * @}
  1255. */
  1256. /**
  1257. * @}
  1258. */
  1259. #ifdef __cplusplus
  1260. }
  1261. #endif
  1262. #endif /* __STM32L4xx_HAL_ADC_EX_H */
  1263. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/