stm32g0xx_hal_adc.h 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32G0xx_HAL_ADC_H
  20. #define STM32G0xx_HAL_ADC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g0xx_hal_def.h"
  26. /* Include low level driver */
  27. #include "stm32g0xx_ll_adc.h"
  28. /** @addtogroup STM32G0xx_HAL_Driver
  29. * @{
  30. */
  31. /** @addtogroup ADC
  32. * @{
  33. */
  34. /* Exported types ------------------------------------------------------------*/
  35. /** @defgroup ADC_Exported_Types ADC Exported Types
  36. * @{
  37. */
  38. /**
  39. * @brief ADC group regular oversampling structure definition
  40. */
  41. typedef struct
  42. {
  43. uint32_t Ratio; /*!< Configures the oversampling ratio.
  44. This parameter can be a value of @ref ADC_HAL_EC_OVS_RATIO */
  45. uint32_t RightBitShift; /*!< Configures the division coefficient for the Oversampler.
  46. This parameter can be a value of @ref ADC_HAL_EC_OVS_SHIFT */
  47. uint32_t TriggeredMode; /*!< Selects the regular triggered oversampling mode.
  48. This parameter can be a value of @ref ADC_HAL_EC_OVS_DISCONT_MODE */
  49. } ADC_OversamplingTypeDef;
  50. /**
  51. * @brief Structure definition of ADC instance and ADC group regular.
  52. * @note Parameters of this structure are shared within 2 scopes:
  53. * - Scope entire ADC (differentiation done for compatibility with some other STM32 series featuring ADC
  54. * groups regular and injected): ClockPrescaler, Resolution, DataAlign,
  55. * ScanConvMode, EOCSelection, LowPowerAutoWait.
  56. * - Scope ADC group regular: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode,
  57. * ExternalTrigConv, ExternalTrigConvEdge, DMAContinuousRequests, Overrun, OversamplingMode, Oversampling.
  58. * @note The setting of these parameters by function HAL_ADC_Init() is conditioned to ADC state.
  59. * ADC state can be either:
  60. * - For all parameters: ADC disabled
  61. * - For all parameters except 'ClockPrescaler' and 'Resolution': ADC enabled without conversion on going on
  62. * group regular.
  63. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  64. * without error reporting (as it can be the expected behavior in case of intended action to update another
  65. * parameter (which fulfills the ADC state condition) on the fly).
  66. */
  67. typedef struct
  68. {
  69. uint32_t ClockPrescaler; /*!< Select ADC clock source (synchronous clock derived from APB clock or asynchronous
  70. clock derived from system clock or PLL (Refer to reference manual for list of
  71. clocks available)) and clock prescaler.
  72. This parameter can be a value of @ref ADC_HAL_EC_COMMON_CLOCK_SOURCE.
  73. Note: The ADC clock configuration is common to all ADC instances.
  74. Note: In case of synchronous clock mode based on HCLK/1, the configuration must
  75. be enabled only if the system clock has a 50% duty clock cycle (APB
  76. prescaler configured inside RCC must be bypassed and PCLK clock must have
  77. 50% duty cycle). Refer to reference manual for details.
  78. Note: In case of usage of asynchronous clock, the selected clock must be
  79. preliminarily enabled at RCC top level.
  80. Note: This parameter can be modified only if all ADC instances are disabled. */
  81. uint32_t Resolution; /*!< Configure the ADC resolution.
  82. This parameter can be a value of @ref ADC_HAL_EC_RESOLUTION */
  83. uint32_t DataAlign; /*!< Specify ADC data alignment in conversion data register (right or left).
  84. Refer to reference manual for alignments formats versus resolutions.
  85. This parameter can be a value of @ref ADC_HAL_EC_DATA_ALIGN */
  86. uint32_t ScanConvMode; /*!< Configure the sequencer of ADC group regular.
  87. On this STM32 series, ADC group regular sequencer both modes "fully configurable"
  88. or "not fully configurable" are available:
  89. - sequencer configured to fully configurable:
  90. sequencer length and each rank affectation to a channel are configurable.
  91. - Sequence length: Set number of ranks in the scan sequence.
  92. - Sequence direction: Unless specified in parameters, sequencer
  93. scan direction is forward (from rank 1 to rank n).
  94. - sequencer configured to not fully configurable:
  95. sequencer length and each rank affectation to a channel are fixed by channel
  96. HW number.
  97. - Sequence length: Number of ranks in the scan sequence is
  98. defined by number of channels set in the sequence,
  99. rank of each channel is fixed by channel HW number.
  100. (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  101. - Sequence direction: Unless specified in parameters, sequencer
  102. scan direction is forward (from lowest channel number to
  103. highest channel number).
  104. This parameter can be associated to parameter 'DiscontinuousConvMode' to have
  105. main sequence subdivided in successive parts. Sequencer is automatically enabled
  106. if several channels are set (sequencer cannot be disabled, as it can be the case
  107. on other STM32 devices):
  108. If only 1 channel is set: Conversion is performed in single mode.
  109. If several channels are set: Conversions are performed in sequence mode.
  110. This parameter can be a value of @ref ADC_Scan_mode */
  111. uint32_t EOCSelection; /*!< Specify which EOC (End Of Conversion) flag is used for conversion by polling and
  112. interruption: end of unitary conversion or end of sequence conversions.
  113. This parameter can be a value of @ref ADC_EOCSelection. */
  114. FunctionalState LowPowerAutoWait; /*!< Select the dynamic low power Auto Delay: new conversion start only when the
  115. previous conversion (for ADC group regular) has been retrieved by user software,
  116. using function HAL_ADC_GetValue().
  117. This feature automatically adapts the frequency of ADC conversions triggers to
  118. the speed of the system that reads the data. Moreover, this avoids risk of
  119. overrun for low frequency applications.
  120. This parameter can be set to ENABLE or DISABLE.
  121. Note: It is not recommended to use with interruption or DMA (HAL_ADC_Start_IT(),
  122. HAL_ADC_Start_DMA()) since these modes have to clear immediately the EOC
  123. flag (by CPU to free the IRQ pending event or by DMA).
  124. Auto wait will work but fort a very short time, discarding its intended
  125. benefit (except specific case of high load of CPU or DMA transfers which
  126. can justify usage of auto wait).
  127. Do use with polling: 1. Start conversion with HAL_ADC_Start(), 2. Later on,
  128. when ADC conversion data is needed:
  129. use HAL_ADC_PollForConversion() to ensure that conversion is completed and
  130. HAL_ADC_GetValue() to retrieve conversion result and trig another
  131. conversion start. */
  132. FunctionalState LowPowerAutoPowerOff; /*!< Select the auto-off mode: the ADC automatically powers-off after a
  133. conversion and automatically wakes-up when a new conversion is triggered
  134. (with startup time between trigger and start of sampling).
  135. This feature can be combined with automatic wait mode
  136. (parameter 'LowPowerAutoWait').
  137. This parameter can be set to ENABLE or DISABLE. */
  138. FunctionalState ContinuousConvMode; /*!< Specify whether the conversion is performed in single mode (one conversion)
  139. or continuous mode for ADC group regular, after the first ADC conversion
  140. start trigger occurred (software start or external trigger). This parameter
  141. can be set to ENABLE or DISABLE. */
  142. uint32_t NbrOfConversion; /*!< Specify the number of ranks that will be converted within the regular group
  143. sequencer.
  144. This parameter is dependent on ScanConvMode:
  145. - sequencer configured to fully configurable:
  146. Number of ranks in the scan sequence is configurable using this parameter.
  147. Note: After the first call of 'HAL_ADC_Init()', each rank corresponding to
  148. parameter "NbrOfConversion" must be set using 'HAL_ADC_ConfigChannel()'.
  149. Afterwards, when all needed sequencer ranks are set, parameter
  150. 'NbrOfConversion' can be updated without modifying configuration of
  151. sequencer ranks (sequencer ranks above 'NbrOfConversion' are discarded).
  152. - sequencer configured to not fully configurable:
  153. Number of ranks in the scan sequence is defined by number of channels set in
  154. the sequence. This parameter is discarded.
  155. This parameter must be a number between Min_Data = 1 and Max_Data = 8.
  156. Note: This parameter must be modified when no conversion is on going on regular
  157. group (ADC disabled, or ADC enabled without continuous mode or external
  158. trigger that could launch a conversion). */
  159. FunctionalState DiscontinuousConvMode; /*!< Specify whether the conversions sequence of ADC group regular is performed
  160. in Complete-sequence/Discontinuous-sequence (main sequence subdivided in
  161. successive parts).
  162. Discontinuous mode is used only if sequencer is enabled (parameter
  163. 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
  164. Discontinuous mode can be enabled only if continuous mode is disabled.
  165. If continuous mode is enabled, this parameter setting is discarded.
  166. This parameter can be set to ENABLE or DISABLE.
  167. Note: On this STM32 series, ADC group regular number of discontinuous
  168. ranks increment is fixed to one-by-one. */
  169. uint32_t ExternalTrigConv; /*!< Select the external event source used to trigger ADC group regular conversion
  170. start.
  171. If set to ADC_SOFTWARE_START, external triggers are disabled and software trigger
  172. is used instead.
  173. This parameter can be a value of @ref ADC_regular_external_trigger_source.
  174. Caution: external trigger source is common to all ADC instances. */
  175. uint32_t ExternalTrigConvEdge; /*!< Select the external event edge used to trigger ADC group regular conversion start
  176. If trigger source is set to ADC_SOFTWARE_START, this parameter is discarded.
  177. This parameter can be a value of @ref ADC_regular_external_trigger_edge */
  178. FunctionalState DMAContinuousRequests; /*!< Specify whether the DMA requests are performed in one shot mode (DMA
  179. transfer stops when number of conversions is reached) or in continuous
  180. mode (DMA transfer unlimited, whatever number of conversions).
  181. This parameter can be set to ENABLE or DISABLE.
  182. Note: In continuous mode, DMA must be configured in circular mode.
  183. Otherwise an overrun will be triggered when DMA buffer maximum
  184. pointer is reached. */
  185. uint32_t Overrun; /*!< Select the behavior in case of overrun: data overwritten or preserved (default).
  186. This parameter can be a value of @ref ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR.
  187. Note: In case of overrun set to data preserved and usage with programming model
  188. with interruption (HAL_Start_IT()): ADC IRQ handler has to clear end of
  189. conversion flags, this induces the release of the preserved data. If
  190. needed, this data can be saved in function HAL_ADC_ConvCpltCallback(),
  191. placed in user program code (called before end of conversion flags clear)
  192. Note: Error reporting with respect to the conversion mode:
  193. - Usage with ADC conversion by polling for event or interruption: Error is
  194. reported only if overrun is set to data preserved. If overrun is set to
  195. data overwritten, user can willingly not read all the converted data,
  196. this is not considered as an erroneous case.
  197. - Usage with ADC conversion by DMA: Error is reported whatever overrun
  198. setting (DMA is expected to process all data from data register). */
  199. uint32_t SamplingTimeCommon1; /*!< Set sampling time common to a group of channels.
  200. Unit: ADC clock cycles
  201. Conversion time is the addition of sampling time and processing time
  202. (12.5 ADC clock cycles at ADC resolution 12 bits,
  203. 10.5 cycles at 10 bits,
  204. 8.5 cycles at 8 bits,
  205. 6.5 cycles at 6 bits).
  206. Note: On this STM32 family, two different sampling time settings are available,
  207. each channel can use one of these two settings. On some other STM32 devices
  208. this parameter in channel wise and is located into ADC channel
  209. initialization structure.
  210. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL_SAMPLINGTIME
  211. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor)
  212. sampling time constraints must be respected (sampling time can be adjusted
  213. in function of ADC clock frequency and sampling time setting)
  214. Refer to device datasheet for timings values, parameters TS_vrefint,
  215. TS_vbat, TS_temp (values rough order: few tens of microseconds). */
  216. uint32_t SamplingTimeCommon2; /*!< Set sampling time common to a group of channels, second common setting possible.
  217. Unit: ADC clock cycles
  218. Conversion time is the addition of sampling time and processing time
  219. (12.5 ADC clock cycles at ADC resolution 12 bits,
  220. 10.5 cycles at 10 bits,
  221. 8.5 cycles at 8 bits,
  222. 6.5 cycles at 6 bits).
  223. Note: On this STM32 family, two different sampling time settings are available,
  224. each channel can use one of these two settings. On some other STM32 devices
  225. this parameter in channel wise and is located into ADC channel
  226. initialization structure.
  227. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL_SAMPLINGTIME
  228. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor)
  229. sampling time constraints must be respected (sampling time can be adjusted
  230. in function of ADC clock frequency and sampling time setting)
  231. Refer to device datasheet for timings values, parameters TS_vrefint,
  232. TS_vbat, TS_temp (values rough order: few tens of microseconds). */
  233. FunctionalState OversamplingMode; /*!< Specify whether the oversampling feature is enabled or disabled.
  234. This parameter can be set to ENABLE or DISABLE.
  235. Note: This parameter can be modified only if there is no conversion is
  236. ongoing on ADC group regular. */
  237. ADC_OversamplingTypeDef Oversampling; /*!< Specify the Oversampling parameters.
  238. Caution: this setting overwrites the previous oversampling configuration
  239. if oversampling is already enabled. */
  240. uint32_t TriggerFrequencyMode; /*!< Set ADC trigger frequency mode.
  241. This parameter can be a value of @ref ADC_HAL_EC_REG_TRIGGER_FREQ.
  242. Note: ADC trigger frequency mode must be set to low frequency when
  243. a duration is exceeded before ADC conversion start trigger event
  244. (between ADC enable and ADC conversion start trigger event
  245. or between two ADC conversion start trigger event).
  246. Duration value: Refer to device datasheet, parameter "tIdle".
  247. Note: When ADC trigger frequency mode is set to low frequency,
  248. some rearm cycles are inserted before performing ADC conversion
  249. start, inducing a delay of 2 ADC clock cycles. */
  250. } ADC_InitTypeDef;
  251. /**
  252. * @brief Structure definition of ADC channel for regular group
  253. * @note The setting of these parameters by function HAL_ADC_ConfigChannel() is conditioned to ADC state.
  254. * ADC state can be either:
  255. * - For all parameters: ADC disabled or enabled without conversion on going on regular group.
  256. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  257. * without error reporting (as it can be the expected behavior in case of intended action to update another
  258. * parameter (which fulfills the ADC state condition) on the fly).
  259. */
  260. typedef struct
  261. {
  262. uint32_t Channel; /*!< Specify the channel to configure into ADC regular group.
  263. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL
  264. Note: Depending on devices and ADC instances, some channels may not be available
  265. on device package pins. Refer to device datasheet for channels
  266. availability. */
  267. uint32_t Rank; /*!< Add or remove the channel from ADC regular group sequencer and specify its
  268. conversion rank.
  269. This parameter is dependent on ScanConvMode:
  270. - sequencer configured to fully configurable:
  271. Channels ordering into each rank of scan sequence:
  272. whatever channel can be placed into whatever rank.
  273. - sequencer configured to not fully configurable:
  274. rank of each channel is fixed by channel HW number.
  275. (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  276. Despite the channel rank is fixed, this parameter allow an additional
  277. possibility: to remove the selected rank (selected channel) from sequencer.
  278. This parameter can be a value of @ref ADC_HAL_EC_REG_SEQ_RANKS */
  279. uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel.
  280. Unit: ADC clock cycles
  281. Conversion time is the addition of sampling time and processing time
  282. (12.5 ADC clock cycles at ADC resolution 12 bits,
  283. 10.5 cycles at 10 bits,
  284. 8.5 cycles at 8 bits,
  285. 6.5 cycles at 6 bits).
  286. This parameter can be a value of @ref ADC_HAL_EC_SAMPLINGTIME_COMMON
  287. Note: On this STM32 family, two different sampling time settings are available
  288. (refer to parameters "SamplingTimeCommon1" and "SamplingTimeCommon2"),
  289. each channel can use one of these two settings.
  290. Note: In case of usage of internal measurement channels (VrefInt/Vbat/
  291. TempSensor), sampling time constraints must be respected (sampling time
  292. can be adjusted in function of ADC clock frequency and sampling time
  293. setting)
  294. Refer to device datasheet for timings values. */
  295. } ADC_ChannelConfTypeDef;
  296. /**
  297. * @brief Structure definition of ADC analog watchdog
  298. * @note The setting of these parameters by function HAL_ADC_AnalogWDGConfig() is conditioned to ADC state.
  299. * ADC state can be either:
  300. * - For all parameters except 'HighThreshold', 'LowThreshold': ADC disabled or ADC enabled without conversion
  301. on going on ADC groups regular.
  302. * - For parameters 'HighThreshold', 'LowThreshold': ADC enabled with conversion on going on regular.
  303. */
  304. typedef struct
  305. {
  306. uint32_t WatchdogNumber; /*!< Select which ADC analog watchdog is monitoring the selected channel.
  307. For Analog Watchdog 1: Only 1 channel can be monitored (or overall group of channels
  308. by setting parameter 'WatchdogMode')
  309. For Analog Watchdog 2 and 3: Several channels can be monitored (by successive calls
  310. of 'HAL_ADC_AnalogWDGConfig()' for each channel)
  311. This parameter can be a value of @ref ADC_HAL_EC_AWD_NUMBER. */
  312. uint32_t WatchdogMode; /*!< Configure the ADC analog watchdog mode: single/all/none channels.
  313. For Analog Watchdog 1: Configure the ADC analog watchdog mode: single channel or all
  314. channels, ADC group regular.
  315. For Analog Watchdog 2 and 3: Several channels can be monitored by applying
  316. successively the AWD init structure.
  317. This parameter can be a value of @ref ADC_analog_watchdog_mode. */
  318. uint32_t Channel; /*!< Select which ADC channel to monitor by analog watchdog.
  319. For Analog Watchdog 1: this parameter has an effect only if parameter 'WatchdogMode'
  320. is configured on single channel (only 1 channel can be
  321. monitored).
  322. For Analog Watchdog 2 and 3: Several channels can be monitored. To use this feature,
  323. call successively the function HAL_ADC_AnalogWDGConfig()
  324. for each channel to be added (or removed with value
  325. 'ADC_ANALOGWATCHDOG_NONE').
  326. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL. */
  327. FunctionalState ITMode; /*!< Specify whether the analog watchdog is configured in interrupt or polling mode.
  328. This parameter can be set to ENABLE or DISABLE */
  329. uint32_t HighThreshold; /*!< Configure the ADC analog watchdog High threshold value.
  330. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a
  331. number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F
  332. respectively.
  333. Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC
  334. resolution is 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits the 2
  335. LSB are ignored.
  336. Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are
  337. impacted: the comparison of analog watchdog thresholds is done on
  338. oversampling final computation (after ratio and shift application):
  339. ADC data register bitfield [15:4] (12 most significant bits). */
  340. uint32_t LowThreshold; /*!< Configures the ADC analog watchdog Low threshold value.
  341. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a
  342. number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F
  343. respectively.
  344. Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC
  345. resolution is 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits the 2
  346. LSB are ignored.
  347. Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are
  348. impacted: the comparison of analog watchdog thresholds is done on
  349. oversampling final computation (after ratio and shift application):
  350. ADC data register bitfield [15:4] (12 most significant bits).*/
  351. } ADC_AnalogWDGConfTypeDef;
  352. /** @defgroup ADC_States ADC States
  353. * @{
  354. */
  355. /**
  356. * @brief HAL ADC state machine: ADC states definition (bitfields)
  357. * @note ADC state machine is managed by bitfields, state must be compared
  358. * with bit by bit.
  359. * For example:
  360. * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_REG_BUSY) != 0UL) "
  361. * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD1) != 0UL) "
  362. */
  363. /* States of ADC global scope */
  364. #define HAL_ADC_STATE_RESET (0x00000000UL) /*!< ADC not yet initialized or disabled */
  365. #define HAL_ADC_STATE_READY (0x00000001UL) /*!< ADC peripheral ready for use */
  366. #define HAL_ADC_STATE_BUSY_INTERNAL (0x00000002UL) /*!< ADC is busy from internal process (ex : calibration, ...) */
  367. #define HAL_ADC_STATE_TIMEOUT (0x00000004UL) /*!< TimeOut occurrence */
  368. /* States of ADC errors */
  369. #define HAL_ADC_STATE_ERROR_INTERNAL (0x00000010UL) /*!< Internal error occurrence */
  370. #define HAL_ADC_STATE_ERROR_CONFIG (0x00000020UL) /*!< Configuration error occurrence */
  371. #define HAL_ADC_STATE_ERROR_DMA (0x00000040UL) /*!< DMA error occurrence */
  372. /* States of ADC group regular */
  373. #define HAL_ADC_STATE_REG_BUSY (0x00000100UL) /*!< A conversion on ADC group regular is ongoing or can occur
  374. (either by continuous mode, external trigger, low power
  375. auto power-on (if feature available), multimode ADC master
  376. control (if feature available)) */
  377. #define HAL_ADC_STATE_REG_EOC (0x00000200UL) /*!< Conversion data available on group regular */
  378. #define HAL_ADC_STATE_REG_OVR (0x00000400UL) /*!< Overrun occurrence */
  379. #define HAL_ADC_STATE_REG_EOSMP (0x00000800UL) /*!< Not available on this STM32 series: End Of Sampling flag
  380. raised */
  381. /* States of ADC group injected */
  382. #define HAL_ADC_STATE_INJ_BUSY (0x00001000UL) /*!< Not available on this STM32 series: A conversion on group
  383. injected is ongoing or can occur (either by auto-injection
  384. mode, external trigger, low power auto power-on (if feature
  385. available), multimode ADC master control (if feature
  386. available))*/
  387. #define HAL_ADC_STATE_INJ_EOC (0x00002000UL) /*!< Not available on this STM32 series: Conversion data
  388. available on group injected */
  389. #define HAL_ADC_STATE_INJ_JQOVF (0x00004000UL) /*!< Not available on this STM32 series: Injected queue overflow
  390. occurrence */
  391. /* States of ADC analog watchdogs */
  392. #define HAL_ADC_STATE_AWD1 (0x00010000UL) /*!< Out-of-window occurrence of ADC analog watchdog 1 */
  393. #define HAL_ADC_STATE_AWD2 (0x00020000UL) /*!< Out-of-window occurrence of ADC analog watchdog 2 */
  394. #define HAL_ADC_STATE_AWD3 (0x00040000UL) /*!< Out-of-window occurrence of ADC analog watchdog 3 */
  395. /* States of ADC multi-mode */
  396. #define HAL_ADC_STATE_MULTIMODE_SLAVE (0x00100000UL) /*!< Not available on this STM32 series: ADC in multimode slave
  397. state, controlled by another ADC master (when feature
  398. available) */
  399. /**
  400. * @}
  401. */
  402. /**
  403. * @brief ADC handle Structure definition
  404. */
  405. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  406. typedef struct __ADC_HandleTypeDef
  407. #else
  408. typedef struct
  409. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  410. {
  411. ADC_TypeDef *Instance; /*!< Register base address */
  412. ADC_InitTypeDef Init; /*!< ADC initialization parameters and regular conversions setting */
  413. DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
  414. HAL_LockTypeDef Lock; /*!< ADC locking object */
  415. __IO uint32_t State; /*!< ADC communication state (bitmap of ADC states) */
  416. __IO uint32_t ErrorCode; /*!< ADC Error code */
  417. uint32_t ADCGroupRegularSequencerRanks; /*!< ADC group regular sequencer memorization of ranks
  418. setting, used in mode "fully configurable" (refer to
  419. parameter 'ScanConvMode') */
  420. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  421. void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion complete callback */
  422. void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion DMA half-transfer
  423. callback */
  424. void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 1 callback */
  425. void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC error callback */
  426. void (* LevelOutOfWindow2Callback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 2 callback */
  427. void (* LevelOutOfWindow3Callback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 3 callback */
  428. void (* EndOfSamplingCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC end of sampling callback */
  429. void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp Init callback */
  430. void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp DeInit callback */
  431. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  432. } ADC_HandleTypeDef;
  433. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  434. /**
  435. * @brief HAL ADC Callback ID enumeration definition
  436. */
  437. typedef enum
  438. {
  439. HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U, /*!< ADC conversion complete callback ID */
  440. HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U, /*!< ADC conversion DMA half-transfer callback ID */
  441. HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U, /*!< ADC analog watchdog 1 callback ID */
  442. HAL_ADC_ERROR_CB_ID = 0x03U, /*!< ADC error callback ID */
  443. HAL_ADC_LEVEL_OUT_OF_WINDOW_2_CB_ID = 0x06U, /*!< ADC analog watchdog 2 callback ID */
  444. HAL_ADC_LEVEL_OUT_OF_WINDOW_3_CB_ID = 0x07U, /*!< ADC analog watchdog 3 callback ID */
  445. HAL_ADC_END_OF_SAMPLING_CB_ID = 0x08U, /*!< ADC end of sampling callback ID */
  446. HAL_ADC_MSPINIT_CB_ID = 0x09U, /*!< ADC Msp Init callback ID */
  447. HAL_ADC_MSPDEINIT_CB_ID = 0x0AU /*!< ADC Msp DeInit callback ID */
  448. } HAL_ADC_CallbackIDTypeDef;
  449. /**
  450. * @brief HAL ADC Callback pointer definition
  451. */
  452. typedef void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
  453. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  454. /**
  455. * @}
  456. */
  457. /* Exported constants --------------------------------------------------------*/
  458. /** @defgroup ADC_Exported_Constants ADC Exported Constants
  459. * @{
  460. */
  461. /** @defgroup ADC_Error_Code ADC Error Code
  462. * @{
  463. */
  464. #define HAL_ADC_ERROR_NONE (0x00U) /*!< No error */
  465. #define HAL_ADC_ERROR_INTERNAL (0x01U) /*!< ADC peripheral internal error (problem of clocking,
  466. enable/disable, erroneous state, ...) */
  467. #define HAL_ADC_ERROR_OVR (0x02U) /*!< Overrun error */
  468. #define HAL_ADC_ERROR_DMA (0x04U) /*!< DMA transfer error */
  469. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  470. #define HAL_ADC_ERROR_INVALID_CALLBACK (0x10U) /*!< Invalid Callback error */
  471. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  472. /**
  473. * @}
  474. */
  475. /** @defgroup ADC_HAL_EC_COMMON_CLOCK_SOURCE ADC common - Clock source
  476. * @{
  477. */
  478. #define ADC_CLOCK_SYNC_PCLK_DIV1 (LL_ADC_CLOCK_SYNC_PCLK_DIV1) /*!< ADC synchronous clock from AHB clock
  479. without prescaler. This configuration must be enabled only if PCLK has
  480. a 50% duty clock cycle (APB prescaler configured inside the RCC must
  481. be bypassed and the system clock must by 50% duty cycle) */
  482. #define ADC_CLOCK_SYNC_PCLK_DIV2 (LL_ADC_CLOCK_SYNC_PCLK_DIV2) /*!< ADC synchronous clock from AHB clock
  483. with prescaler division by 2 */
  484. #define ADC_CLOCK_SYNC_PCLK_DIV4 (LL_ADC_CLOCK_SYNC_PCLK_DIV4) /*!< ADC synchronous clock from AHB clock
  485. with prescaler division by 4 */
  486. #define ADC_CLOCK_ASYNC_DIV1 (LL_ADC_CLOCK_ASYNC_DIV1) /*!< ADC asynchronous clock without
  487. prescaler */
  488. #define ADC_CLOCK_ASYNC_DIV2 (LL_ADC_CLOCK_ASYNC_DIV2) /*!< ADC asynchronous clock with prescaler
  489. division by 2 */
  490. #define ADC_CLOCK_ASYNC_DIV4 (LL_ADC_CLOCK_ASYNC_DIV4) /*!< ADC asynchronous clock with prescaler
  491. division by 4 */
  492. #define ADC_CLOCK_ASYNC_DIV6 (LL_ADC_CLOCK_ASYNC_DIV6) /*!< ADC asynchronous clock with prescaler
  493. division by 6 */
  494. #define ADC_CLOCK_ASYNC_DIV8 (LL_ADC_CLOCK_ASYNC_DIV8) /*!< ADC asynchronous clock with prescaler
  495. division by 8 */
  496. #define ADC_CLOCK_ASYNC_DIV10 (LL_ADC_CLOCK_ASYNC_DIV10) /*!< ADC asynchronous clock with prescaler
  497. division by 10 */
  498. #define ADC_CLOCK_ASYNC_DIV12 (LL_ADC_CLOCK_ASYNC_DIV12) /*!< ADC asynchronous clock with prescaler
  499. division by 12 */
  500. #define ADC_CLOCK_ASYNC_DIV16 (LL_ADC_CLOCK_ASYNC_DIV16) /*!< ADC asynchronous clock with prescaler
  501. division by 16 */
  502. #define ADC_CLOCK_ASYNC_DIV32 (LL_ADC_CLOCK_ASYNC_DIV32) /*!< ADC asynchronous clock with prescaler
  503. division by 32 */
  504. #define ADC_CLOCK_ASYNC_DIV64 (LL_ADC_CLOCK_ASYNC_DIV64) /*!< ADC asynchronous clock with prescaler
  505. division by 64 */
  506. #define ADC_CLOCK_ASYNC_DIV128 (LL_ADC_CLOCK_ASYNC_DIV128) /*!< ADC asynchronous clock with prescaler
  507. division by 128 */
  508. #define ADC_CLOCK_ASYNC_DIV256 (LL_ADC_CLOCK_ASYNC_DIV256) /*!< ADC asynchronous clock with prescaler
  509. division by 256 */
  510. /**
  511. * @}
  512. */
  513. /** @defgroup ADC_HAL_EC_RESOLUTION ADC instance - Resolution
  514. * @{
  515. */
  516. #define ADC_RESOLUTION_12B (LL_ADC_RESOLUTION_12B) /*!< ADC resolution 12 bits */
  517. #define ADC_RESOLUTION_10B (LL_ADC_RESOLUTION_10B) /*!< ADC resolution 10 bits */
  518. #define ADC_RESOLUTION_8B (LL_ADC_RESOLUTION_8B) /*!< ADC resolution 8 bits */
  519. #define ADC_RESOLUTION_6B (LL_ADC_RESOLUTION_6B) /*!< ADC resolution 6 bits */
  520. /**
  521. * @}
  522. */
  523. /** @defgroup ADC_HAL_EC_DATA_ALIGN ADC conversion data alignment
  524. * @{
  525. */
  526. #define ADC_DATAALIGN_RIGHT (LL_ADC_DATA_ALIGN_RIGHT) /*!< ADC conversion data alignment: right aligned
  527. (alignment on data register LSB bit 0)*/
  528. #define ADC_DATAALIGN_LEFT (LL_ADC_DATA_ALIGN_LEFT) /*!< ADC conversion data alignment: left aligned
  529. (alignment on data register MSB bit 15)*/
  530. /**
  531. * @}
  532. */
  533. /** @defgroup ADC_Scan_mode ADC sequencer scan mode
  534. * @{
  535. */
  536. /* Note: On this STM32 family, ADC group regular sequencer both modes */
  537. /* "fully configurable" or "not fully configurable" are */
  538. /* available. */
  539. /* Scan mode values must be compatible with other STM32 devices having */
  540. /* a configurable sequencer. */
  541. /* Scan direction setting values are defined by taking in account */
  542. /* already defined values for other STM32 devices: */
  543. /* ADC_SCAN_DISABLE (0x00000000UL) */
  544. /* ADC_SCAN_ENABLE (0x00000001UL) */
  545. /* Sequencer fully configurable with only rank 1 enabled is considered */
  546. /* as default setting equivalent to scan enable. */
  547. /* In case of migration from another STM32 device, the user will be */
  548. /* warned of change of setting choices with assert check. */
  549. /* Sequencer set to fully configurable */
  550. #define ADC_SCAN_DISABLE (0x00000000UL) /*!< Sequencer set to fully configurable:
  551. only the rank 1 is enabled (no scan sequence on several ranks) */
  552. #define ADC_SCAN_ENABLE (ADC_CFGR1_CHSELRMOD) /*!< Sequencer set to fully configurable:
  553. sequencer length and each rank affectation to a channel are configurable. */
  554. /* Sequencer set to not fully configurable */
  555. #define ADC_SCAN_SEQ_FIXED (ADC_SCAN_SEQ_FIXED_INT) /*!< Sequencer set to not fully configurable:
  556. sequencer length and each rank affectation to a channel are fixed by
  557. channel HW number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  558. Scan direction forward: from channel 0 to channel 18 */
  559. #define ADC_SCAN_SEQ_FIXED_BACKWARD (ADC_SCAN_SEQ_FIXED_INT \
  560. | ADC_CFGR1_SCANDIR) /*!< Sequencer set to not fully configurable:
  561. sequencer length and each rank affectation to a channel are fixed by
  562. channel HW number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  563. Scan direction backward: from channel 18 to channel 0 */
  564. #define ADC_SCAN_DIRECTION_FORWARD (ADC_SCAN_SEQ_FIXED) /* For compatibility with other STM32 series */
  565. #define ADC_SCAN_DIRECTION_BACKWARD (ADC_SCAN_SEQ_FIXED_BACKWARD) /* For compatibility with other STM32 series */
  566. /**
  567. * @}
  568. */
  569. /** @defgroup ADC_regular_external_trigger_source ADC group regular trigger source
  570. * @{
  571. */
  572. /* ADC group regular trigger sources for all ADC instances */
  573. #define ADC_SOFTWARE_START (LL_ADC_REG_TRIG_SOFTWARE) /*!< ADC group regular conversion
  574. trigger software start */
  575. #define ADC_EXTERNALTRIG_T1_TRGO2 (LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) /*!< ADC group regular conversion
  576. trigger from external peripheral: TIM1 TRGO. */
  577. #define ADC_EXTERNALTRIG_T1_CC4 (LL_ADC_REG_TRIG_EXT_TIM1_CH4) /*!< ADC group regular conversion
  578. trigger from external peripheral: TIM1 channel 4 event (capture compare). */
  579. #if defined(TIM2)
  580. #define ADC_EXTERNALTRIG_T2_TRGO (LL_ADC_REG_TRIG_EXT_TIM2_TRGO) /*!< ADC group regular conversion
  581. trigger from external peripheral: TIM2 TRGO. */
  582. #endif /* TIM2 */
  583. #define ADC_EXTERNALTRIG_T3_TRGO (LL_ADC_REG_TRIG_EXT_TIM3_TRGO) /*!< ADC group regular conversion
  584. trigger from external peripheral: TIM3 TRGO. */
  585. #if defined(TIM4)
  586. #define ADC_EXTERNALTRIG_T4_TRGO (LL_ADC_REG_TRIG_EXT_TIM4_TRGO) /*!< ADC group regular conversion
  587. trigger from external peripheral: TIM4 TRGO. */
  588. #endif /* TIM4 */
  589. #if defined(TIM6)
  590. #define ADC_EXTERNALTRIG_T6_TRGO (LL_ADC_REG_TRIG_EXT_TIM6_TRGO) /*!< ADC group regular conversion
  591. trigger from external peripheral: TIM6 TRGO. */
  592. #endif /* TIM6 */
  593. #if defined(TIM15)
  594. #define ADC_EXTERNALTRIG_T15_TRGO (LL_ADC_REG_TRIG_EXT_TIM15_TRGO) /*!< ADC group regular conversion
  595. trigger from external peripheral: TIM15 TRGO. */
  596. #endif /* TIM15 */
  597. #define ADC_EXTERNALTRIG_EXT_IT11 (LL_ADC_REG_TRIG_EXT_EXTI_LINE11) /*!< ADC group regular conversion
  598. trigger from external peripheral: external interrupt line 11. */
  599. /**
  600. * @}
  601. */
  602. /** @defgroup ADC_regular_external_trigger_edge ADC group regular trigger edge (when external trigger is selected)
  603. * @{
  604. */
  605. #define ADC_EXTERNALTRIGCONVEDGE_NONE (0x00000000UL) /*!< ADC group regular trigger
  606. disabled (SW start)*/
  607. #define ADC_EXTERNALTRIGCONVEDGE_RISING (LL_ADC_REG_TRIG_EXT_RISING) /*!< ADC group regular conversion
  608. trigger polarity set to rising edge */
  609. #define ADC_EXTERNALTRIGCONVEDGE_FALLING (LL_ADC_REG_TRIG_EXT_FALLING) /*!< ADC group regular conversion
  610. trigger polarity set to falling edge */
  611. #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING (LL_ADC_REG_TRIG_EXT_RISINGFALLING) /*!< ADC group regular conversion
  612. trigger polarity set to both rising and falling edges */
  613. /**
  614. * @}
  615. */
  616. /** @defgroup ADC_EOCSelection ADC sequencer end of unitary conversion or sequence conversions
  617. * @{
  618. */
  619. #define ADC_EOC_SINGLE_CONV (ADC_ISR_EOC) /*!< End of unitary conversion flag */
  620. #define ADC_EOC_SEQ_CONV (ADC_ISR_EOS) /*!< End of sequence conversions flag */
  621. /**
  622. * @}
  623. */
  624. /** @defgroup ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data
  625. * @{
  626. */
  627. #define ADC_OVR_DATA_PRESERVED (LL_ADC_REG_OVR_DATA_PRESERVED) /*!< ADC group regular behavior in case
  628. of overrun: data preserved */
  629. #define ADC_OVR_DATA_OVERWRITTEN (LL_ADC_REG_OVR_DATA_OVERWRITTEN) /*!< ADC group regular behavior in case
  630. of overrun: data overwritten */
  631. /**
  632. * @}
  633. */
  634. /** @defgroup ADC_HAL_EC_REG_SEQ_RANKS ADC group regular - Sequencer ranks
  635. * @{
  636. */
  637. #define ADC_RANK_CHANNEL_NUMBER (0x00000001U) /*!< Enable the rank of the selected channels. Number of
  638. ranks in the sequence is defined by number of channels enabled, rank of
  639. each channel is defined by channel number (channel 0 fixed on rank 0,
  640. channel 1 fixed on rank1, ...).
  641. Setting relevant if parameter "ScanConvMode" is set to sequencer not fully
  642. configurable. */
  643. #define ADC_RANK_NONE (0x00000002U) /*!< Disable the selected rank (selected channel) from
  644. sequencer.
  645. Setting relevant if parameter "ScanConvMode" is set to sequencer not fully
  646. configurable. */
  647. #define ADC_REGULAR_RANK_1 (LL_ADC_REG_RANK_1) /*!< ADC group regular sequencer rank 1 */
  648. #define ADC_REGULAR_RANK_2 (LL_ADC_REG_RANK_2) /*!< ADC group regular sequencer rank 2 */
  649. #define ADC_REGULAR_RANK_3 (LL_ADC_REG_RANK_3) /*!< ADC group regular sequencer rank 3 */
  650. #define ADC_REGULAR_RANK_4 (LL_ADC_REG_RANK_4) /*!< ADC group regular sequencer rank 4 */
  651. #define ADC_REGULAR_RANK_5 (LL_ADC_REG_RANK_5) /*!< ADC group regular sequencer rank 5 */
  652. #define ADC_REGULAR_RANK_6 (LL_ADC_REG_RANK_6) /*!< ADC group regular sequencer rank 6 */
  653. #define ADC_REGULAR_RANK_7 (LL_ADC_REG_RANK_7) /*!< ADC group regular sequencer rank 7 */
  654. #define ADC_REGULAR_RANK_8 (LL_ADC_REG_RANK_8) /*!< ADC group regular sequencer rank 8 */
  655. /**
  656. * @}
  657. */
  658. /** @defgroup ADC_HAL_EC_SAMPLINGTIME_COMMON ADC instance - Sampling time common to a group of channels
  659. * @{
  660. */
  661. #define ADC_SAMPLINGTIME_COMMON_1 (LL_ADC_SAMPLINGTIME_COMMON_1) /*!< Set sampling time common to a group of
  662. channels: sampling time nb 1 */
  663. #define ADC_SAMPLINGTIME_COMMON_2 (LL_ADC_SAMPLINGTIME_COMMON_2) /*!< Set sampling time common to a group of
  664. channels: sampling time nb 2 */
  665. /**
  666. * @}
  667. */
  668. /** @defgroup ADC_HAL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time
  669. * @{
  670. */
  671. #define ADC_SAMPLETIME_1CYCLE_5 (LL_ADC_SAMPLINGTIME_1CYCLE_5) /*!< Sampling time 1.5 ADC clock cycle */
  672. #define ADC_SAMPLETIME_3CYCLES_5 (LL_ADC_SAMPLINGTIME_3CYCLES_5) /*!< Sampling time 3.5 ADC clock cycles */
  673. #define ADC_SAMPLETIME_7CYCLES_5 (LL_ADC_SAMPLINGTIME_7CYCLES_5) /*!< Sampling time 7.5 ADC clock cycles */
  674. #define ADC_SAMPLETIME_12CYCLES_5 (LL_ADC_SAMPLINGTIME_12CYCLES_5) /*!< Sampling time 12.5 ADC clock cycles */
  675. #define ADC_SAMPLETIME_19CYCLES_5 (LL_ADC_SAMPLINGTIME_19CYCLES_5) /*!< Sampling time 19.5 ADC clock cycles */
  676. #define ADC_SAMPLETIME_39CYCLES_5 (LL_ADC_SAMPLINGTIME_39CYCLES_5) /*!< Sampling time 39.5 ADC clock cycles */
  677. #define ADC_SAMPLETIME_79CYCLES_5 (LL_ADC_SAMPLINGTIME_79CYCLES_5) /*!< Sampling time 79.5 ADC clock cycles */
  678. #define ADC_SAMPLETIME_160CYCLES_5 (LL_ADC_SAMPLINGTIME_160CYCLES_5) /*!< Sampling time 160.5 ADC clock cycles */
  679. /**
  680. * @}
  681. */
  682. /** @defgroup ADC_HAL_EC_CHANNEL ADC instance - Channel number
  683. * @{
  684. */
  685. #define ADC_CHANNEL_0 (LL_ADC_CHANNEL_0) /*!< External channel (GPIO pin) ADCx_IN0 */
  686. #define ADC_CHANNEL_1 (LL_ADC_CHANNEL_1) /*!< External channel (GPIO pin) ADCx_IN1 */
  687. #define ADC_CHANNEL_2 (LL_ADC_CHANNEL_2) /*!< External channel (GPIO pin) ADCx_IN2 */
  688. #define ADC_CHANNEL_3 (LL_ADC_CHANNEL_3) /*!< External channel (GPIO pin) ADCx_IN3 */
  689. #define ADC_CHANNEL_4 (LL_ADC_CHANNEL_4) /*!< External channel (GPIO pin) ADCx_IN4 */
  690. #define ADC_CHANNEL_5 (LL_ADC_CHANNEL_5) /*!< External channel (GPIO pin) ADCx_IN5 */
  691. #define ADC_CHANNEL_6 (LL_ADC_CHANNEL_6) /*!< External channel (GPIO pin) ADCx_IN6 */
  692. #define ADC_CHANNEL_7 (LL_ADC_CHANNEL_7) /*!< External channel (GPIO pin) ADCx_IN7 */
  693. #define ADC_CHANNEL_8 (LL_ADC_CHANNEL_8) /*!< External channel (GPIO pin) ADCx_IN8 */
  694. #define ADC_CHANNEL_9 (LL_ADC_CHANNEL_9) /*!< External channel (GPIO pin) ADCx_IN9 */
  695. #define ADC_CHANNEL_10 (LL_ADC_CHANNEL_10) /*!< External channel (GPIO pin) ADCx_IN10 */
  696. #define ADC_CHANNEL_11 (LL_ADC_CHANNEL_11) /*!< External channel (GPIO pin) ADCx_IN11 */
  697. #define ADC_CHANNEL_12 (LL_ADC_CHANNEL_12) /*!< External channel (GPIO pin) ADCx_IN12 */
  698. #define ADC_CHANNEL_13 (LL_ADC_CHANNEL_13) /*!< External channel (GPIO pin) ADCx_IN13 */
  699. #define ADC_CHANNEL_14 (LL_ADC_CHANNEL_14) /*!< External channel (GPIO pin) ADCx_IN14 */
  700. #define ADC_CHANNEL_15 (LL_ADC_CHANNEL_15) /*!< External channel (GPIO pin) ADCx_IN15 */
  701. #define ADC_CHANNEL_16 (LL_ADC_CHANNEL_16) /*!< External channel (GPIO pin) ADCx_IN16 */
  702. #define ADC_CHANNEL_17 (LL_ADC_CHANNEL_17) /*!< External channel (GPIO pin) ADCx_IN17 */
  703. #define ADC_CHANNEL_18 (LL_ADC_CHANNEL_18) /*!< External channel (GPIO pin) ADCx_IN18 */
  704. #define ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_VREFINT) /*!< Internal channel VrefInt: Internal
  705. voltage reference. */
  706. #define ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_TEMPSENSOR) /*!< Internal channel Temperature sensor. */
  707. #define ADC_CHANNEL_VBAT (LL_ADC_CHANNEL_VBAT) /*!< Internal channel Vbat/3: Vbat voltage
  708. through a divider ladder of factor 1/3 to have channel voltage always below
  709. Vdda. */
  710. /**
  711. * @}
  712. */
  713. /** @defgroup ADC_HAL_EC_AWD_NUMBER Analog watchdog - ADC analog watchdog (AWD) number
  714. * @{
  715. */
  716. #define ADC_ANALOGWATCHDOG_1 (LL_ADC_AWD1) /*!< ADC analog watchdog number 1 */
  717. #define ADC_ANALOGWATCHDOG_2 (LL_ADC_AWD2) /*!< ADC analog watchdog number 2 */
  718. #define ADC_ANALOGWATCHDOG_3 (LL_ADC_AWD3) /*!< ADC analog watchdog number 3 */
  719. /**
  720. * @}
  721. */
  722. /** @defgroup ADC_analog_watchdog_mode ADC analog watchdog (AWD) mode
  723. * @{
  724. */
  725. #define ADC_ANALOGWATCHDOG_NONE (0x00000000UL) /*!< ADC AWD not selected */
  726. #define ADC_ANALOGWATCHDOG_SINGLE_REG (ADC_CFGR1_AWD1SGL | ADC_CFGR1_AWD1EN) /*!< ADC AWD applied to a regular
  727. group single channel */
  728. #define ADC_ANALOGWATCHDOG_ALL_REG (ADC_CFGR1_AWD1EN) /*!< ADC AWD applied to regular
  729. group all channels */
  730. /**
  731. * @}
  732. */
  733. /** @defgroup ADC_HAL_EC_OVS_RATIO Oversampling - Ratio
  734. * @{
  735. */
  736. /**
  737. * @note The oversampling ratio is the number of ADC conversions performed, sum of these conversions data is computed
  738. * to result as the ADC oversampling conversion data (before potential shift)
  739. */
  740. #define ADC_OVERSAMPLING_RATIO_2 (LL_ADC_OVS_RATIO_2) /*!< ADC oversampling ratio 2 */
  741. #define ADC_OVERSAMPLING_RATIO_4 (LL_ADC_OVS_RATIO_4) /*!< ADC oversampling ratio 4 */
  742. #define ADC_OVERSAMPLING_RATIO_8 (LL_ADC_OVS_RATIO_8) /*!< ADC oversampling ratio 8 */
  743. #define ADC_OVERSAMPLING_RATIO_16 (LL_ADC_OVS_RATIO_16) /*!< ADC oversampling ratio 16 */
  744. #define ADC_OVERSAMPLING_RATIO_32 (LL_ADC_OVS_RATIO_32) /*!< ADC oversampling ratio 32 */
  745. #define ADC_OVERSAMPLING_RATIO_64 (LL_ADC_OVS_RATIO_64) /*!< ADC oversampling ratio 64 */
  746. #define ADC_OVERSAMPLING_RATIO_128 (LL_ADC_OVS_RATIO_128) /*!< ADC oversampling ratio 128 */
  747. #define ADC_OVERSAMPLING_RATIO_256 (LL_ADC_OVS_RATIO_256) /*!< ADC oversampling ratio 256 */
  748. /**
  749. * @}
  750. */
  751. /** @defgroup ADC_HAL_EC_OVS_SHIFT Oversampling - Data shift
  752. * @{
  753. */
  754. /**
  755. * @note The sum of the ADC conversions data is divided by "Rightbitshift" number to result as the ADC oversampling
  756. * conversion data)
  757. */
  758. #define ADC_RIGHTBITSHIFT_NONE (LL_ADC_OVS_SHIFT_NONE) /*!< ADC oversampling no shift */
  759. #define ADC_RIGHTBITSHIFT_1 (LL_ADC_OVS_SHIFT_RIGHT_1) /*!< ADC oversampling right shift of 1 ranks */
  760. #define ADC_RIGHTBITSHIFT_2 (LL_ADC_OVS_SHIFT_RIGHT_2) /*!< ADC oversampling right shift of 2 ranks */
  761. #define ADC_RIGHTBITSHIFT_3 (LL_ADC_OVS_SHIFT_RIGHT_3) /*!< ADC oversampling right shift of 3 ranks */
  762. #define ADC_RIGHTBITSHIFT_4 (LL_ADC_OVS_SHIFT_RIGHT_4) /*!< ADC oversampling right shift of 4 ranks */
  763. #define ADC_RIGHTBITSHIFT_5 (LL_ADC_OVS_SHIFT_RIGHT_5) /*!< ADC oversampling right shift of 5 ranks */
  764. #define ADC_RIGHTBITSHIFT_6 (LL_ADC_OVS_SHIFT_RIGHT_6) /*!< ADC oversampling right shift of 6 ranks */
  765. #define ADC_RIGHTBITSHIFT_7 (LL_ADC_OVS_SHIFT_RIGHT_7) /*!< ADC oversampling right shift of 7 ranks */
  766. #define ADC_RIGHTBITSHIFT_8 (LL_ADC_OVS_SHIFT_RIGHT_8) /*!< ADC oversampling right shift of 8 ranks */
  767. /**
  768. * @}
  769. */
  770. /** @defgroup ADC_HAL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode
  771. * @{
  772. */
  773. #define ADC_TRIGGEREDMODE_SINGLE_TRIGGER (LL_ADC_OVS_REG_CONT) /*!< ADC oversampling discontinuous mode:
  774. continuous mode (all conversions of OVS ratio are done from 1 trigger) */
  775. #define ADC_TRIGGEREDMODE_MULTI_TRIGGER (LL_ADC_OVS_REG_DISCONT) /*!< ADC oversampling discontinuous mode:
  776. discontinuous mode (each conversion of OVS ratio needs a trigger) */
  777. /**
  778. * @}
  779. */
  780. /** @defgroup ADC_HAL_EC_REG_TRIGGER_FREQ ADC group regular - Trigger frequency mode
  781. * @{
  782. */
  783. /**
  784. * @note ADC trigger frequency mode must be set to low frequency when a duration is exceeded before ADC conversion
  785. * start trigger event (between ADC enable and ADC conversion start trigger event or between two ADC conversion
  786. * start trigger event).
  787. * Duration value: Refer to device datasheet, parameter "tIdle".
  788. */
  789. #define ADC_TRIGGER_FREQ_HIGH (LL_ADC_TRIGGER_FREQ_HIGH) /*!< Trigger frequency mode set to high frequency. */
  790. #define ADC_TRIGGER_FREQ_LOW (LL_ADC_TRIGGER_FREQ_LOW) /*!< Trigger frequency mode set to low frequency. */
  791. /**
  792. * @}
  793. */
  794. /** @defgroup ADC_Event_type ADC Event type
  795. * @{
  796. */
  797. /**
  798. * @note Analog watchdog 1 is available on all stm32 series
  799. * Analog watchdog 2 and 3 are not available on all series
  800. */
  801. #define ADC_EOSMP_EVENT (ADC_FLAG_EOSMP) /*!< ADC End of Sampling event */
  802. #define ADC_AWD1_EVENT (ADC_FLAG_AWD1) /*!< ADC Analog watchdog 1 event (main analog watchdog) */
  803. #define ADC_AWD2_EVENT (ADC_FLAG_AWD2) /*!< ADC Analog watchdog 2 event (additional analog watchdog) */
  804. #define ADC_AWD3_EVENT (ADC_FLAG_AWD3) /*!< ADC Analog watchdog 3 event (additional analog watchdog) */
  805. #define ADC_OVR_EVENT (ADC_FLAG_OVR) /*!< ADC overrun event */
  806. /**
  807. * @}
  808. */
  809. #define ADC_AWD_EVENT ADC_AWD1_EVENT /*!< ADC Analog watchdog 1 event: Naming for compatibility
  810. with other STM32 devices having only one analog watchdog */
  811. /** @defgroup ADC_interrupts_definition ADC interrupts definition
  812. * @{
  813. */
  814. #define ADC_IT_RDY ADC_IER_ADRDYIE /*!< ADC Ready interrupt source */
  815. #define ADC_IT_CCRDY ADC_IER_CCRDYIE /*!< ADC channel configuration ready interrupt source */
  816. #define ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC End of sampling interrupt source */
  817. #define ADC_IT_EOC ADC_IER_EOCIE /*!< ADC End of regular conversion interrupt source */
  818. #define ADC_IT_EOS ADC_IER_EOSIE /*!< ADC End of regular sequence of conversions interrupt source */
  819. #define ADC_IT_OVR ADC_IER_OVRIE /*!< ADC overrun interrupt source */
  820. #define ADC_IT_AWD1 ADC_IER_AWD1IE /*!< ADC Analog watchdog 1 interrupt source (main analog watchdog) */
  821. #define ADC_IT_AWD2 ADC_IER_AWD2IE /*!< ADC Analog watchdog 2 interrupt source (additional analog
  822. watchdog) */
  823. #define ADC_IT_AWD3 ADC_IER_AWD3IE /*!< ADC Analog watchdog 3 interrupt source (additional analog
  824. watchdog) */
  825. /**
  826. * @}
  827. */
  828. /** @defgroup ADC_flags_definition ADC flags definition
  829. * @{
  830. */
  831. #define ADC_FLAG_RDY ADC_ISR_ADRDY /*!< ADC Ready flag */
  832. #define ADC_FLAG_CCRDY ADC_ISR_CCRDY /*!< ADC channel configuration ready flag */
  833. #define ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC End of Sampling flag */
  834. #define ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC End of Regular Conversion flag */
  835. #define ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC End of Regular sequence of Conversions flag */
  836. #define ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC overrun flag */
  837. #define ADC_FLAG_AWD1 ADC_ISR_AWD1 /*!< ADC Analog watchdog 1 flag (main analog watchdog) */
  838. #define ADC_FLAG_AWD2 ADC_ISR_AWD2 /*!< ADC Analog watchdog 2 flag (additional analog watchdog) */
  839. #define ADC_FLAG_AWD3 ADC_ISR_AWD3 /*!< ADC Analog watchdog 3 flag (additional analog watchdog) */
  840. /**
  841. * @}
  842. */
  843. /**
  844. * @}
  845. */
  846. /* Private macro -------------------------------------------------------------*/
  847. /** @defgroup ADC_Private_Macros ADC Private Macros
  848. * @{
  849. */
  850. /* Macro reserved for internal HAL driver usage, not intended to be used in */
  851. /* code of final user. */
  852. /**
  853. * @brief Test if conversion trigger of regular group is software start
  854. * or external trigger.
  855. * @param __HANDLE__ ADC handle
  856. * @retval SET (software start) or RESET (external trigger)
  857. */
  858. #define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__) \
  859. (((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_EXTEN) == 0UL)
  860. /**
  861. * @brief Return resolution bits in CFGR1 register RES[1:0] field.
  862. * @param __HANDLE__ ADC handle
  863. * @retval Value of bitfield RES in CFGR1 register.
  864. */
  865. #define ADC_GET_RESOLUTION(__HANDLE__) \
  866. (LL_ADC_GetResolution((__HANDLE__)->Instance))
  867. /**
  868. * @brief Clear ADC error code (set it to no error code "HAL_ADC_ERROR_NONE").
  869. * @param __HANDLE__ ADC handle
  870. * @retval None
  871. */
  872. #define ADC_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
  873. /**
  874. * @brief Simultaneously clear and set specific bits of the handle State.
  875. * @note ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
  876. * the first parameter is the ADC handle State, the second parameter is the
  877. * bit field to clear, the third and last parameter is the bit field to set.
  878. * @retval None
  879. */
  880. #define ADC_STATE_CLR_SET MODIFY_REG
  881. /**
  882. * @brief Enable ADC discontinuous conversion mode for regular group
  883. * @param _REG_DISCONTINUOUS_MODE_: Regular discontinuous mode.
  884. * @retval None
  885. */
  886. #define ADC_CFGR1_REG_DISCCONTINUOUS(_REG_DISCONTINUOUS_MODE_) \
  887. ((_REG_DISCONTINUOUS_MODE_) << 16U)
  888. /**
  889. * @brief Enable the ADC auto off mode.
  890. * @param _AUTOOFF_ Auto off bit enable or disable.
  891. * @retval None
  892. */
  893. #define ADC_CFGR1_AUTOOFF(_AUTOOFF_) \
  894. ((_AUTOOFF_) << 15U)
  895. /**
  896. * @brief Enable the ADC auto delay mode.
  897. * @param _AUTOWAIT_ Auto delay bit enable or disable.
  898. * @retval None
  899. */
  900. #define ADC_CFGR1_AUTOWAIT(_AUTOWAIT_) \
  901. ((_AUTOWAIT_) << 14U)
  902. /**
  903. * @brief Enable ADC continuous conversion mode.
  904. * @param _CONTINUOUS_MODE_ Continuous mode.
  905. * @retval None
  906. */
  907. #define ADC_CFGR1_CONTINUOUS(_CONTINUOUS_MODE_) \
  908. ((_CONTINUOUS_MODE_) << 13U)
  909. /**
  910. * @brief Enable ADC overrun mode.
  911. * @param _OVERRUN_MODE_ Overrun mode.
  912. * @retval Overrun bit setting to be programmed into CFGR register
  913. */
  914. /* Note: Bit ADC_CFGR1_OVRMOD not used directly in constant */
  915. /* "ADC_OVR_DATA_OVERWRITTEN" to have this case defined to 0x00, to set it */
  916. /* as the default case to be compliant with other STM32 devices. */
  917. #define ADC_CFGR1_OVERRUN(_OVERRUN_MODE_) \
  918. ( ( (_OVERRUN_MODE_) != (ADC_OVR_DATA_PRESERVED) \
  919. )? (ADC_CFGR1_OVRMOD) : (0x00000000UL) \
  920. )
  921. /**
  922. * @brief Set ADC scan mode with differentiation of sequencer setting
  923. * fixed or configurable
  924. * @param _SCAN_MODE_ Scan conversion mode.
  925. * @retval None
  926. */
  927. /* Note: Scan mode set using this macro (instead of parameter direct set) */
  928. /* due to different modes on other STM32 devices: */
  929. /* if scan mode is disabled, sequencer is set to fully configurable */
  930. /* with setting of only rank 1 enabled afterwards. */
  931. #define ADC_SCAN_SEQ_MODE(_SCAN_MODE_) \
  932. ( (((_SCAN_MODE_) & ADC_SCAN_SEQ_FIXED_INT) != 0UL \
  933. )? \
  934. ((_SCAN_MODE_) & (~ADC_SCAN_SEQ_FIXED_INT)) \
  935. : \
  936. (ADC_CFGR1_CHSELRMOD) \
  937. )
  938. /**
  939. * @brief Enable the ADC DMA continuous request.
  940. * @param _DMACONTREQ_MODE_: DMA continuous request mode.
  941. * @retval None
  942. */
  943. #define ADC_CFGR1_DMACONTREQ(_DMACONTREQ_MODE_) \
  944. ((_DMACONTREQ_MODE_) << 1U)
  945. /**
  946. * @brief Shift the AWD threshold in function of the selected ADC resolution.
  947. * Thresholds have to be left-aligned on bit 11, the LSB (right bits) are set to 0.
  948. * If resolution 12 bits, no shift.
  949. * If resolution 10 bits, shift of 2 ranks on the left.
  950. * If resolution 8 bits, shift of 4 ranks on the left.
  951. * If resolution 6 bits, shift of 6 ranks on the left.
  952. * therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2))
  953. * @param __HANDLE__ ADC handle
  954. * @param _Threshold_ Value to be shifted
  955. * @retval None
  956. */
  957. #define ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(__HANDLE__, _Threshold_) \
  958. ((_Threshold_) << ((((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_RES) >> 3U)*2U))
  959. #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV1) ||\
  960. ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) ||\
  961. ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) ||\
  962. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV1 ) ||\
  963. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV2 ) ||\
  964. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV4 ) ||\
  965. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV6 ) ||\
  966. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV8 ) ||\
  967. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV10 ) ||\
  968. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV12 ) ||\
  969. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV16 ) ||\
  970. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV32 ) ||\
  971. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV64 ) ||\
  972. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV128 ) ||\
  973. ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV256))
  974. #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_12B) || \
  975. ((RESOLUTION) == ADC_RESOLUTION_10B) || \
  976. ((RESOLUTION) == ADC_RESOLUTION_8B) || \
  977. ((RESOLUTION) == ADC_RESOLUTION_6B) )
  978. #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \
  979. ((ALIGN) == ADC_DATAALIGN_LEFT) )
  980. #define IS_ADC_SCAN_MODE(SCAN_MODE) (((SCAN_MODE) == ADC_SCAN_DISABLE) || \
  981. ((SCAN_MODE) == ADC_SCAN_ENABLE) || \
  982. ((SCAN_MODE) == ADC_SCAN_SEQ_FIXED) || \
  983. ((SCAN_MODE) == ADC_SCAN_SEQ_FIXED_BACKWARD) )
  984. #define IS_ADC_EXTTRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
  985. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
  986. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
  987. ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING) )
  988. #if defined(TIM15) && defined(TIM6) && defined(TIM2)
  989. #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIG_T1_TRGO2) || \
  990. ((REGTRIG) == ADC_EXTERNALTRIG_T1_CC4) || \
  991. ((REGTRIG) == ADC_EXTERNALTRIG_T2_TRGO) || \
  992. ((REGTRIG) == ADC_EXTERNALTRIG_T3_TRGO) || \
  993. ((REGTRIG) == ADC_EXTERNALTRIG_T6_TRGO) || \
  994. ((REGTRIG) == ADC_EXTERNALTRIG_T15_TRGO) || \
  995. ((REGTRIG) == ADC_EXTERNALTRIG_EXT_IT11) || \
  996. ((REGTRIG) == ADC_SOFTWARE_START) )
  997. #elif defined(TIM15) && defined(TIM6)
  998. #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIG_T1_TRGO2) || \
  999. ((REGTRIG) == ADC_EXTERNALTRIG_T1_CC4) || \
  1000. ((REGTRIG) == ADC_EXTERNALTRIG_T3_TRGO) || \
  1001. ((REGTRIG) == ADC_EXTERNALTRIG_T6_TRGO) || \
  1002. ((REGTRIG) == ADC_EXTERNALTRIG_T15_TRGO) || \
  1003. ((REGTRIG) == ADC_EXTERNALTRIG_EXT_IT11) || \
  1004. ((REGTRIG) == ADC_SOFTWARE_START) )
  1005. #elif defined(TIM2)
  1006. #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIG_T1_TRGO2) || \
  1007. ((REGTRIG) == ADC_EXTERNALTRIG_T1_CC4) || \
  1008. ((REGTRIG) == ADC_EXTERNALTRIG_T2_TRGO) || \
  1009. ((REGTRIG) == ADC_EXTERNALTRIG_T3_TRGO) || \
  1010. ((REGTRIG) == ADC_EXTERNALTRIG_EXT_IT11) || \
  1011. ((REGTRIG) == ADC_SOFTWARE_START) )
  1012. #else
  1013. #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIG_T1_TRGO2) || \
  1014. ((REGTRIG) == ADC_EXTERNALTRIG_T1_CC4) || \
  1015. ((REGTRIG) == ADC_EXTERNALTRIG_T3_TRGO) || \
  1016. ((REGTRIG) == ADC_EXTERNALTRIG_EXT_IT11) || \
  1017. ((REGTRIG) == ADC_SOFTWARE_START) )
  1018. #endif /* TIM15 && TIM6 && TIM2 */
  1019. #define IS_ADC_EOC_SELECTION(EOC_SELECTION) (((EOC_SELECTION) == ADC_EOC_SINGLE_CONV) || \
  1020. ((EOC_SELECTION) == ADC_EOC_SEQ_CONV))
  1021. #define IS_ADC_OVERRUN(OVR) (((OVR) == ADC_OVR_DATA_PRESERVED) || \
  1022. ((OVR) == ADC_OVR_DATA_OVERWRITTEN) )
  1023. #define IS_ADC_REGULAR_RANK_SEQ_FIXED(RANK) (((RANK) == ADC_RANK_CHANNEL_NUMBER) || \
  1024. ((RANK) == ADC_RANK_NONE) )
  1025. #define IS_ADC_REGULAR_RANK(RANK) (((RANK) == ADC_REGULAR_RANK_1 ) || \
  1026. ((RANK) == ADC_REGULAR_RANK_2 ) || \
  1027. ((RANK) == ADC_REGULAR_RANK_3 ) || \
  1028. ((RANK) == ADC_REGULAR_RANK_4 ) || \
  1029. ((RANK) == ADC_REGULAR_RANK_5 ) || \
  1030. ((RANK) == ADC_REGULAR_RANK_6 ) || \
  1031. ((RANK) == ADC_REGULAR_RANK_7 ) || \
  1032. ((RANK) == ADC_REGULAR_RANK_8 ) )
  1033. #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \
  1034. ((CHANNEL) == ADC_CHANNEL_1) || \
  1035. ((CHANNEL) == ADC_CHANNEL_2) || \
  1036. ((CHANNEL) == ADC_CHANNEL_3) || \
  1037. ((CHANNEL) == ADC_CHANNEL_4) || \
  1038. ((CHANNEL) == ADC_CHANNEL_5) || \
  1039. ((CHANNEL) == ADC_CHANNEL_6) || \
  1040. ((CHANNEL) == ADC_CHANNEL_7) || \
  1041. ((CHANNEL) == ADC_CHANNEL_8) || \
  1042. ((CHANNEL) == ADC_CHANNEL_9) || \
  1043. ((CHANNEL) == ADC_CHANNEL_10) || \
  1044. ((CHANNEL) == ADC_CHANNEL_11) || \
  1045. ((CHANNEL) == ADC_CHANNEL_12) || \
  1046. ((CHANNEL) == ADC_CHANNEL_13) || \
  1047. ((CHANNEL) == ADC_CHANNEL_14) || \
  1048. ((CHANNEL) == ADC_CHANNEL_15) || \
  1049. ((CHANNEL) == ADC_CHANNEL_16) || \
  1050. ((CHANNEL) == ADC_CHANNEL_17) || \
  1051. ((CHANNEL) == ADC_CHANNEL_18) || \
  1052. ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR) || \
  1053. ((CHANNEL) == ADC_CHANNEL_VREFINT) || \
  1054. ((CHANNEL) == ADC_CHANNEL_VBAT) )
  1055. #define IS_ADC_SAMPLING_TIME_COMMON(SAMPLING_TIME_COMMON) (((SAMPLING_TIME_COMMON) == ADC_SAMPLINGTIME_COMMON_1) || \
  1056. ((SAMPLING_TIME_COMMON) == ADC_SAMPLINGTIME_COMMON_2) )
  1057. #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_1CYCLE_5) || \
  1058. ((TIME) == ADC_SAMPLETIME_3CYCLES_5) || \
  1059. ((TIME) == ADC_SAMPLETIME_7CYCLES_5) || \
  1060. ((TIME) == ADC_SAMPLETIME_12CYCLES_5) || \
  1061. ((TIME) == ADC_SAMPLETIME_19CYCLES_5) || \
  1062. ((TIME) == ADC_SAMPLETIME_39CYCLES_5) || \
  1063. ((TIME) == ADC_SAMPLETIME_79CYCLES_5) || \
  1064. ((TIME) == ADC_SAMPLETIME_160CYCLES_5) )
  1065. #define IS_ADC_ANALOG_WATCHDOG_NUMBER(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_1) || \
  1066. ((WATCHDOG) == ADC_ANALOGWATCHDOG_2) || \
  1067. ((WATCHDOG) == ADC_ANALOGWATCHDOG_3) )
  1068. #define IS_ADC_ANALOG_WATCHDOG_MODE(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE) || \
  1069. ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \
  1070. ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG) )
  1071. #define IS_ADC_TRIGGER_FREQ(TRIGGER_FREQ) (((TRIGGER_FREQ) == LL_ADC_TRIGGER_FREQ_HIGH) || \
  1072. ((TRIGGER_FREQ) == LL_ADC_TRIGGER_FREQ_LOW) )
  1073. #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == ADC_EOSMP_EVENT) || \
  1074. ((EVENT) == ADC_AWD1_EVENT) || \
  1075. ((EVENT) == ADC_AWD2_EVENT) || \
  1076. ((EVENT) == ADC_AWD3_EVENT) || \
  1077. ((EVENT) == ADC_OVR_EVENT) )
  1078. /**
  1079. * @brief Verify that a given value is aligned with the ADC resolution range.
  1080. * @param __RESOLUTION__ ADC resolution (12, 10, 8 or 6 bits).
  1081. * @param __ADC_VALUE__ value checked against the resolution.
  1082. * @retval SET (__ADC_VALUE__ in line with __RESOLUTION__) or RESET (__ADC_VALUE__ not in line with __RESOLUTION__)
  1083. */
  1084. #define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \
  1085. ((__ADC_VALUE__) <= __LL_ADC_DIGITAL_SCALE(__RESOLUTION__))
  1086. /** @defgroup ADC_regular_nb_conv_verification ADC Regular Conversion Number Verification
  1087. * @{
  1088. */
  1089. #define IS_ADC_REGULAR_NB_CONV(LENGTH) (((LENGTH) >= 1UL) && ((LENGTH) <= 8UL))
  1090. /**
  1091. * @}
  1092. */
  1093. /* Private constants ---------------------------------------------------------*/
  1094. /** @defgroup ADC_Private_Constants ADC Private Constants
  1095. * @{
  1096. */
  1097. /* Combination of all post-conversion flags bits: EOC/EOS, OVR, AWD */
  1098. #define ADC_FLAG_POSTCONV_ALL (ADC_FLAG_AWD | ADC_FLAG_OVR | ADC_FLAG_EOS | ADC_FLAG_EOC)
  1099. /* Internal definition to differentiate sequencer setting fixed or configurable */
  1100. #define ADC_SCAN_SEQ_FIXED_INT 0x80000000U
  1101. /**
  1102. * @}
  1103. */
  1104. /* Exported macro ------------------------------------------------------------*/
  1105. /** @defgroup ADC_Exported_Macros ADC Exported Macros
  1106. * @{
  1107. */
  1108. /* Macro for internal HAL driver usage, and possibly can be used into code of */
  1109. /* final user. */
  1110. /** @defgroup ADC_HAL_EM_HANDLE_IT_FLAG HAL ADC macro to manage HAL ADC handle, IT and flags.
  1111. * @{
  1112. */
  1113. /** @brief Reset ADC handle state.
  1114. * @param __HANDLE__ ADC handle
  1115. * @retval None
  1116. */
  1117. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  1118. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  1119. do{ \
  1120. (__HANDLE__)->State = HAL_ADC_STATE_RESET; \
  1121. (__HANDLE__)->MspInitCallback = NULL; \
  1122. (__HANDLE__)->MspDeInitCallback = NULL; \
  1123. } while(0)
  1124. #else
  1125. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  1126. ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  1127. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  1128. /**
  1129. * @brief Enable ADC interrupt.
  1130. * @param __HANDLE__ ADC handle
  1131. * @param __INTERRUPT__ ADC Interrupt
  1132. * This parameter can be one of the following values:
  1133. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  1134. * @arg @ref ADC_IT_CCRDY ADC channel configuration ready interrupt source
  1135. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  1136. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  1137. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  1138. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  1139. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  1140. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  1141. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  1142. * @retval None
  1143. */
  1144. #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
  1145. (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
  1146. /**
  1147. * @brief Disable ADC interrupt.
  1148. * @param __HANDLE__ ADC handle
  1149. * @param __INTERRUPT__ ADC Interrupt
  1150. * This parameter can be one of the following values:
  1151. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  1152. * @arg @ref ADC_IT_CCRDY ADC channel configuration ready interrupt source
  1153. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  1154. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  1155. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  1156. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  1157. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  1158. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  1159. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  1160. * @retval None
  1161. */
  1162. #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
  1163. (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
  1164. /** @brief Checks if the specified ADC interrupt source is enabled or disabled.
  1165. * @param __HANDLE__ ADC handle
  1166. * @param __INTERRUPT__ ADC interrupt source to check
  1167. * This parameter can be one of the following values:
  1168. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  1169. * @arg @ref ADC_IT_CCRDY ADC channel configuration ready interrupt source
  1170. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  1171. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  1172. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  1173. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  1174. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  1175. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  1176. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  1177. * @retval State of interruption (SET or RESET)
  1178. */
  1179. #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
  1180. (((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__))
  1181. /**
  1182. * @brief Check whether the specified ADC flag is set or not.
  1183. * @param __HANDLE__ ADC handle
  1184. * @param __FLAG__ ADC flag
  1185. * This parameter can be one of the following values:
  1186. * @arg @ref ADC_FLAG_RDY ADC Ready flag
  1187. * @arg @ref ADC_FLAG_CCRDY ADC channel configuration ready flag
  1188. * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag
  1189. * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag
  1190. * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag
  1191. * @arg @ref ADC_FLAG_OVR ADC overrun flag
  1192. * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog)
  1193. * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog)
  1194. * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog)
  1195. * @retval State of flag (TRUE or FALSE).
  1196. */
  1197. #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) \
  1198. ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
  1199. /**
  1200. * @brief Clear the specified ADC flag.
  1201. * @param __HANDLE__ ADC handle
  1202. * @param __FLAG__ ADC flag
  1203. * This parameter can be one of the following values:
  1204. * @arg @ref ADC_FLAG_RDY ADC Ready flag
  1205. * @arg @ref ADC_FLAG_CCRDY ADC channel configuration ready flag
  1206. * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag
  1207. * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag
  1208. * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag
  1209. * @arg @ref ADC_FLAG_OVR ADC overrun flag
  1210. * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog)
  1211. * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog)
  1212. * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog)
  1213. * @retval None
  1214. */
  1215. /* Note: bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR) */
  1216. #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) \
  1217. (((__HANDLE__)->Instance->ISR) = (__FLAG__))
  1218. /**
  1219. * @}
  1220. */
  1221. /** @defgroup ADC_HAL_EM_HELPER_MACRO HAL ADC helper macro
  1222. * @{
  1223. */
  1224. /**
  1225. * @brief Helper macro to get ADC channel number in decimal format
  1226. * from literals ADC_CHANNEL_x.
  1227. * @note Example:
  1228. * __HAL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_4)
  1229. * will return decimal number "4".
  1230. * @note The input can be a value from functions where a channel
  1231. * number is returned, either defined with number
  1232. * or with bitfield (only one bit must be set).
  1233. * @param __CHANNEL__ This parameter can be one of the following values:
  1234. * @arg @ref ADC_CHANNEL_0
  1235. * @arg @ref ADC_CHANNEL_1
  1236. * @arg @ref ADC_CHANNEL_2
  1237. * @arg @ref ADC_CHANNEL_3
  1238. * @arg @ref ADC_CHANNEL_4
  1239. * @arg @ref ADC_CHANNEL_5
  1240. * @arg @ref ADC_CHANNEL_6
  1241. * @arg @ref ADC_CHANNEL_7
  1242. * @arg @ref ADC_CHANNEL_8
  1243. * @arg @ref ADC_CHANNEL_9
  1244. * @arg @ref ADC_CHANNEL_10
  1245. * @arg @ref ADC_CHANNEL_11
  1246. * @arg @ref ADC_CHANNEL_12
  1247. * @arg @ref ADC_CHANNEL_13
  1248. * @arg @ref ADC_CHANNEL_14
  1249. * @arg @ref ADC_CHANNEL_15 (1)
  1250. * @arg @ref ADC_CHANNEL_16 (1)
  1251. * @arg @ref ADC_CHANNEL_17 (1)
  1252. * @arg @ref ADC_CHANNEL_18
  1253. * @arg @ref ADC_CHANNEL_VREFINT
  1254. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1255. * @arg @ref ADC_CHANNEL_VBAT
  1256. *
  1257. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1258. * only if sequencer is set in mode "not fully configurable",
  1259. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  1260. * @retval Value between Min_Data=0 and Max_Data=18
  1261. */
  1262. #define __HAL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  1263. __LL_ADC_CHANNEL_TO_DECIMAL_NB((__CHANNEL__))
  1264. /**
  1265. * @brief Helper macro to get ADC channel in literal format ADC_CHANNEL_x
  1266. * from number in decimal format.
  1267. * @note Example:
  1268. * __HAL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  1269. * will return a data equivalent to "ADC_CHANNEL_4".
  1270. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
  1271. * @retval Returned value can be one of the following values:
  1272. * @arg @ref ADC_CHANNEL_0
  1273. * @arg @ref ADC_CHANNEL_1
  1274. * @arg @ref ADC_CHANNEL_2
  1275. * @arg @ref ADC_CHANNEL_3
  1276. * @arg @ref ADC_CHANNEL_4
  1277. * @arg @ref ADC_CHANNEL_5
  1278. * @arg @ref ADC_CHANNEL_6
  1279. * @arg @ref ADC_CHANNEL_7
  1280. * @arg @ref ADC_CHANNEL_8
  1281. * @arg @ref ADC_CHANNEL_9
  1282. * @arg @ref ADC_CHANNEL_10
  1283. * @arg @ref ADC_CHANNEL_11
  1284. * @arg @ref ADC_CHANNEL_12
  1285. * @arg @ref ADC_CHANNEL_13
  1286. * @arg @ref ADC_CHANNEL_14
  1287. * @arg @ref ADC_CHANNEL_15 (1)
  1288. * @arg @ref ADC_CHANNEL_16 (1)
  1289. * @arg @ref ADC_CHANNEL_17 (1)
  1290. * @arg @ref ADC_CHANNEL_18
  1291. * @arg @ref ADC_CHANNEL_VREFINT (2)
  1292. * @arg @ref ADC_CHANNEL_TEMPSENSOR (2)
  1293. * @arg @ref ADC_CHANNEL_VBAT (2)
  1294. *
  1295. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1296. * only if sequencer is set in mode "not fully configurable",
  1297. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().\n
  1298. * (2) For ADC channel read back from ADC register,
  1299. * comparison with internal channel parameter to be done
  1300. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1301. */
  1302. #define __HAL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  1303. __LL_ADC_DECIMAL_NB_TO_CHANNEL((__DECIMAL_NB__))
  1304. /**
  1305. * @brief Helper macro to determine whether the selected channel
  1306. * corresponds to literal definitions of driver.
  1307. * @note The different literal definitions of ADC channels are:
  1308. * - ADC internal channel:
  1309. * ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...
  1310. * - ADC external channel (channel connected to a GPIO pin):
  1311. * ADC_CHANNEL_1, ADC_CHANNEL_2, ...
  1312. * @note The channel parameter must be a value defined from literal
  1313. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1314. * ADC_CHANNEL_TEMPSENSOR, ...),
  1315. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...),
  1316. * must not be a value from functions where a channel number is
  1317. * returned from ADC registers,
  1318. * because internal and external channels share the same channel
  1319. * number in ADC registers. The differentiation is made only with
  1320. * parameters definitions of driver.
  1321. * @param __CHANNEL__ This parameter can be one of the following values:
  1322. * @arg @ref ADC_CHANNEL_0
  1323. * @arg @ref ADC_CHANNEL_1
  1324. * @arg @ref ADC_CHANNEL_2
  1325. * @arg @ref ADC_CHANNEL_3
  1326. * @arg @ref ADC_CHANNEL_4
  1327. * @arg @ref ADC_CHANNEL_5
  1328. * @arg @ref ADC_CHANNEL_6
  1329. * @arg @ref ADC_CHANNEL_7
  1330. * @arg @ref ADC_CHANNEL_8
  1331. * @arg @ref ADC_CHANNEL_9
  1332. * @arg @ref ADC_CHANNEL_10
  1333. * @arg @ref ADC_CHANNEL_11
  1334. * @arg @ref ADC_CHANNEL_12
  1335. * @arg @ref ADC_CHANNEL_13
  1336. * @arg @ref ADC_CHANNEL_14
  1337. * @arg @ref ADC_CHANNEL_15 (1)
  1338. * @arg @ref ADC_CHANNEL_16 (1)
  1339. * @arg @ref ADC_CHANNEL_17 (1)
  1340. * @arg @ref ADC_CHANNEL_18
  1341. * @arg @ref ADC_CHANNEL_VREFINT
  1342. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1343. * @arg @ref ADC_CHANNEL_VBAT
  1344. *
  1345. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1346. * only if sequencer is set in mode "not fully configurable",
  1347. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  1348. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel
  1349. * (channel connected to a GPIO pin).
  1350. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  1351. */
  1352. #define __HAL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  1353. __LL_ADC_IS_CHANNEL_INTERNAL((__CHANNEL__))
  1354. /**
  1355. * @brief Helper macro to convert a channel defined from parameter
  1356. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1357. * ADC_CHANNEL_TEMPSENSOR, ...),
  1358. * to its equivalent parameter definition of a ADC external channel
  1359. * (ADC_CHANNEL_1, ADC_CHANNEL_2, ...).
  1360. * @note The channel parameter can be, additionally to a value
  1361. * defined from parameter definition of a ADC internal channel
  1362. * (ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...),
  1363. * a value defined from parameter definition of
  1364. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
  1365. * or a value from functions where a channel number is returned
  1366. * from ADC registers.
  1367. * @param __CHANNEL__ This parameter can be one of the following values:
  1368. * @arg @ref ADC_CHANNEL_0
  1369. * @arg @ref ADC_CHANNEL_1
  1370. * @arg @ref ADC_CHANNEL_2
  1371. * @arg @ref ADC_CHANNEL_3
  1372. * @arg @ref ADC_CHANNEL_4
  1373. * @arg @ref ADC_CHANNEL_5
  1374. * @arg @ref ADC_CHANNEL_6
  1375. * @arg @ref ADC_CHANNEL_7
  1376. * @arg @ref ADC_CHANNEL_8
  1377. * @arg @ref ADC_CHANNEL_9
  1378. * @arg @ref ADC_CHANNEL_10
  1379. * @arg @ref ADC_CHANNEL_11
  1380. * @arg @ref ADC_CHANNEL_12
  1381. * @arg @ref ADC_CHANNEL_13
  1382. * @arg @ref ADC_CHANNEL_14
  1383. * @arg @ref ADC_CHANNEL_15 (1)
  1384. * @arg @ref ADC_CHANNEL_16 (1)
  1385. * @arg @ref ADC_CHANNEL_17 (1)
  1386. * @arg @ref ADC_CHANNEL_18
  1387. * @arg @ref ADC_CHANNEL_VREFINT
  1388. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1389. * @arg @ref ADC_CHANNEL_VBAT
  1390. *
  1391. * (1) On STM32G0, parameter can be set in ADC group sequencer
  1392. * only if sequencer is set in mode "not fully configurable",
  1393. * refer to function @ref LL_ADC_REG_SetSequencerConfigurable().
  1394. * @retval Returned value can be one of the following values:
  1395. * @arg @ref ADC_CHANNEL_0
  1396. * @arg @ref ADC_CHANNEL_1
  1397. * @arg @ref ADC_CHANNEL_2
  1398. * @arg @ref ADC_CHANNEL_3
  1399. * @arg @ref ADC_CHANNEL_4
  1400. * @arg @ref ADC_CHANNEL_5
  1401. * @arg @ref ADC_CHANNEL_6
  1402. * @arg @ref ADC_CHANNEL_7
  1403. * @arg @ref ADC_CHANNEL_8
  1404. * @arg @ref ADC_CHANNEL_9
  1405. * @arg @ref ADC_CHANNEL_10
  1406. * @arg @ref ADC_CHANNEL_11
  1407. * @arg @ref ADC_CHANNEL_12
  1408. * @arg @ref ADC_CHANNEL_13
  1409. * @arg @ref ADC_CHANNEL_14
  1410. * @arg @ref ADC_CHANNEL_15
  1411. * @arg @ref ADC_CHANNEL_16
  1412. * @arg @ref ADC_CHANNEL_17
  1413. * @arg @ref ADC_CHANNEL_18
  1414. */
  1415. #define __HAL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  1416. __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL((__CHANNEL__))
  1417. /**
  1418. * @brief Helper macro to determine whether the internal channel
  1419. * selected is available on the ADC instance selected.
  1420. * @note The channel parameter must be a value defined from parameter
  1421. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1422. * ADC_CHANNEL_TEMPSENSOR, ...),
  1423. * must not be a value defined from parameter definition of
  1424. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
  1425. * or a value from functions where a channel number is
  1426. * returned from ADC registers,
  1427. * because internal and external channels share the same channel
  1428. * number in ADC registers. The differentiation is made only with
  1429. * parameters definitions of driver.
  1430. * @param __ADC_INSTANCE__ ADC instance
  1431. * @param __CHANNEL__ This parameter can be one of the following values:
  1432. * @arg @ref ADC_CHANNEL_VREFINT
  1433. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1434. * @arg @ref ADC_CHANNEL_VBAT
  1435. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  1436. * Value "1" if the internal channel selected is available on the ADC instance selected.
  1437. */
  1438. #define __HAL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1439. __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE((__ADC_INSTANCE__), (__CHANNEL__))
  1440. /**
  1441. * @brief Helper macro to select the ADC common instance
  1442. * to which is belonging the selected ADC instance.
  1443. * @note ADC common register instance can be used for:
  1444. * - Set parameters common to several ADC instances
  1445. * - Multimode (for devices with several ADC instances)
  1446. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1447. * @param __ADCx__ ADC instance
  1448. * @retval ADC common register instance
  1449. */
  1450. #define __HAL_ADC_COMMON_INSTANCE(__ADCx__) \
  1451. __LL_ADC_COMMON_INSTANCE((__ADCx__))
  1452. /**
  1453. * @brief Helper macro to check if all ADC instances sharing the same
  1454. * ADC common instance are disabled.
  1455. * @note This check is required by functions with setting conditioned to
  1456. * ADC state:
  1457. * All ADC instances of the ADC common group must be disabled.
  1458. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1459. * @note On devices with only 1 ADC common instance, parameter of this macro
  1460. * is useless and can be ignored (parameter kept for compatibility
  1461. * with devices featuring several ADC common instances).
  1462. * @param __ADCXY_COMMON__ ADC common instance
  1463. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1464. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  1465. * are disabled.
  1466. * Value "1" if at least one ADC instance sharing the same ADC common instance
  1467. * is enabled.
  1468. */
  1469. #define __HAL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1470. __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE((__ADCXY_COMMON__))
  1471. /**
  1472. * @brief Helper macro to define the ADC conversion data full-scale digital
  1473. * value corresponding to the selected ADC resolution.
  1474. * @note ADC conversion data full-scale corresponds to voltage range
  1475. * determined by analog voltage references Vref+ and Vref-
  1476. * (refer to reference manual).
  1477. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1478. * @arg @ref ADC_RESOLUTION_12B
  1479. * @arg @ref ADC_RESOLUTION_10B
  1480. * @arg @ref ADC_RESOLUTION_8B
  1481. * @arg @ref ADC_RESOLUTION_6B
  1482. * @retval ADC conversion data full-scale digital value
  1483. */
  1484. #define __HAL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1485. __LL_ADC_DIGITAL_SCALE((__ADC_RESOLUTION__))
  1486. /**
  1487. * @brief Helper macro to convert the ADC conversion data from
  1488. * a resolution to another resolution.
  1489. * @param __DATA__ ADC conversion data to be converted
  1490. * @param __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted
  1491. * This parameter can be one of the following values:
  1492. * @arg @ref ADC_RESOLUTION_12B
  1493. * @arg @ref ADC_RESOLUTION_10B
  1494. * @arg @ref ADC_RESOLUTION_8B
  1495. * @arg @ref ADC_RESOLUTION_6B
  1496. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  1497. * This parameter can be one of the following values:
  1498. * @arg @ref ADC_RESOLUTION_12B
  1499. * @arg @ref ADC_RESOLUTION_10B
  1500. * @arg @ref ADC_RESOLUTION_8B
  1501. * @arg @ref ADC_RESOLUTION_6B
  1502. * @retval ADC conversion data to the requested resolution
  1503. */
  1504. #define __HAL_ADC_CONVERT_DATA_RESOLUTION(__DATA__,\
  1505. __ADC_RESOLUTION_CURRENT__,\
  1506. __ADC_RESOLUTION_TARGET__) \
  1507. __LL_ADC_CONVERT_DATA_RESOLUTION((__DATA__),\
  1508. (__ADC_RESOLUTION_CURRENT__),\
  1509. (__ADC_RESOLUTION_TARGET__))
  1510. /**
  1511. * @brief Helper macro to calculate the voltage (unit: mVolt)
  1512. * corresponding to a ADC conversion data (unit: digital value).
  1513. * @note Analog reference voltage (Vref+) must be either known from
  1514. * user board environment or can be calculated using ADC measurement
  1515. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1516. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1517. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  1518. * (unit: digital value).
  1519. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1520. * @arg @ref ADC_RESOLUTION_12B
  1521. * @arg @ref ADC_RESOLUTION_10B
  1522. * @arg @ref ADC_RESOLUTION_8B
  1523. * @arg @ref ADC_RESOLUTION_6B
  1524. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1525. */
  1526. #define __HAL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
  1527. __ADC_DATA__,\
  1528. __ADC_RESOLUTION__) \
  1529. __LL_ADC_CALC_DATA_TO_VOLTAGE((__VREFANALOG_VOLTAGE__),\
  1530. (__ADC_DATA__),\
  1531. (__ADC_RESOLUTION__))
  1532. /**
  1533. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1534. * (unit: mVolt) from ADC conversion data of internal voltage
  1535. * reference VrefInt.
  1536. * @note Computation is using VrefInt calibration value
  1537. * stored in system memory for each device during production.
  1538. * @note This voltage depends on user board environment: voltage level
  1539. * connected to pin Vref+.
  1540. * On devices with small package, the pin Vref+ is not present
  1541. * and internally bonded to pin Vdda.
  1542. * @note On this STM32 series, calibration data of internal voltage reference
  1543. * VrefInt corresponds to a resolution of 12 bits,
  1544. * this is the recommended ADC resolution to convert voltage of
  1545. * internal voltage reference VrefInt.
  1546. * Otherwise, this macro performs the processing to scale
  1547. * ADC conversion data to 12 bits.
  1548. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1549. * of internal voltage reference VrefInt (unit: digital value).
  1550. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1551. * @arg @ref ADC_RESOLUTION_12B
  1552. * @arg @ref ADC_RESOLUTION_10B
  1553. * @arg @ref ADC_RESOLUTION_8B
  1554. * @arg @ref ADC_RESOLUTION_6B
  1555. * @retval Analog reference voltage (unit: mV)
  1556. */
  1557. #define __HAL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
  1558. __ADC_RESOLUTION__) \
  1559. __LL_ADC_CALC_VREFANALOG_VOLTAGE((__VREFINT_ADC_DATA__),\
  1560. (__ADC_RESOLUTION__))
  1561. /**
  1562. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1563. * from ADC conversion data of internal temperature sensor.
  1564. * @note Computation is using temperature sensor calibration values
  1565. * stored in system memory for each device during production.
  1566. * @note Calculation formula:
  1567. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1568. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1569. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1570. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1571. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1572. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1573. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1574. * TEMP_DEGC_CAL1 (calibrated in factory)
  1575. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1576. * TEMP_DEGC_CAL2 (calibrated in factory)
  1577. * Caution: Calculation relevancy under reserve that calibration
  1578. * parameters are correct (address and data).
  1579. * To calculate temperature using temperature sensor
  1580. * datasheet typical values (generic values less, therefore
  1581. * less accurate than calibrated values),
  1582. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1583. * @note As calculation input, the analog reference voltage (Vref+) must be
  1584. * defined as it impacts the ADC LSB equivalent voltage.
  1585. * @note Analog reference voltage (Vref+) must be either known from
  1586. * user board environment or can be calculated using ADC measurement
  1587. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1588. * @note On this STM32 series, calibration data of temperature sensor
  1589. * corresponds to a resolution of 12 bits,
  1590. * this is the recommended ADC resolution to convert voltage of
  1591. * temperature sensor.
  1592. * Otherwise, this macro performs the processing to scale
  1593. * ADC conversion data to 12 bits.
  1594. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1595. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1596. * temperature sensor (unit: digital value).
  1597. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1598. * sensor voltage has been measured.
  1599. * This parameter can be one of the following values:
  1600. * @arg @ref ADC_RESOLUTION_12B
  1601. * @arg @ref ADC_RESOLUTION_10B
  1602. * @arg @ref ADC_RESOLUTION_8B
  1603. * @arg @ref ADC_RESOLUTION_6B
  1604. * @retval Temperature (unit: degree Celsius)
  1605. */
  1606. #define __HAL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1607. __TEMPSENSOR_ADC_DATA__,\
  1608. __ADC_RESOLUTION__) \
  1609. __LL_ADC_CALC_TEMPERATURE((__VREFANALOG_VOLTAGE__),\
  1610. (__TEMPSENSOR_ADC_DATA__),\
  1611. (__ADC_RESOLUTION__))
  1612. /**
  1613. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1614. * from ADC conversion data of internal temperature sensor.
  1615. * @note Computation is using temperature sensor typical values
  1616. * (refer to device datasheet).
  1617. * @note Calculation formula:
  1618. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1619. * / Avg_Slope + CALx_TEMP
  1620. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1621. * (unit: digital value)
  1622. * Avg_Slope = temperature sensor slope
  1623. * (unit: uV/Degree Celsius)
  1624. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1625. * temperature CALx_TEMP (unit: mV)
  1626. * Caution: Calculation relevancy under reserve the temperature sensor
  1627. * of the current device has characteristics in line with
  1628. * datasheet typical values.
  1629. * If temperature sensor calibration values are available on
  1630. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1631. * temperature calculation will be more accurate using
  1632. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1633. * @note As calculation input, the analog reference voltage (Vref+) must be
  1634. * defined as it impacts the ADC LSB equivalent voltage.
  1635. * @note Analog reference voltage (Vref+) must be either known from
  1636. * user board environment or can be calculated using ADC measurement
  1637. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1638. * @note ADC measurement data must correspond to a resolution of 12bits
  1639. * (full scale digital value 4095). If not the case, the data must be
  1640. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1641. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value
  1642. (unit: uV/DegCelsius).
  1643. * On STM32G0, refer to device datasheet parameter "Avg_Slope".
  1644. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at
  1645. temperature and Vref+ defined in parameters below) (unit: mV).
  1646. * On STM32G0, refer to device datasheet parameter "V30"
  1647. (corresponding to TS_CAL1).
  1648. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see
  1649. parameter above) is corresponding (unit: mV)
  1650. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1651. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1652. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1653. * This parameter can be one of the following values:
  1654. * @arg @ref ADC_RESOLUTION_12B
  1655. * @arg @ref ADC_RESOLUTION_10B
  1656. * @arg @ref ADC_RESOLUTION_8B
  1657. * @arg @ref ADC_RESOLUTION_6B
  1658. * @retval Temperature (unit: degree Celsius)
  1659. */
  1660. #define __HAL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1661. __TEMPSENSOR_TYP_CALX_V__,\
  1662. __TEMPSENSOR_CALX_TEMP__,\
  1663. __VREFANALOG_VOLTAGE__,\
  1664. __TEMPSENSOR_ADC_DATA__,\
  1665. __ADC_RESOLUTION__) \
  1666. __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS((__TEMPSENSOR_TYP_AVGSLOPE__),\
  1667. (__TEMPSENSOR_TYP_CALX_V__),\
  1668. (__TEMPSENSOR_CALX_TEMP__),\
  1669. (__VREFANALOG_VOLTAGE__),\
  1670. (__TEMPSENSOR_ADC_DATA__),\
  1671. (__ADC_RESOLUTION__))
  1672. /**
  1673. * @}
  1674. */
  1675. /**
  1676. * @}
  1677. */
  1678. /* Include ADC HAL Extended module */
  1679. #include "stm32g0xx_hal_adc_ex.h"
  1680. /* Exported functions --------------------------------------------------------*/
  1681. /** @addtogroup ADC_Exported_Functions
  1682. * @{
  1683. */
  1684. /** @addtogroup ADC_Exported_Functions_Group1
  1685. * @brief Initialization and Configuration functions
  1686. * @{
  1687. */
  1688. /* Initialization and de-initialization functions ****************************/
  1689. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef *hadc);
  1690. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  1691. void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc);
  1692. void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc);
  1693. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  1694. /* Callbacks Register/UnRegister functions ***********************************/
  1695. HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID,
  1696. pADC_CallbackTypeDef pCallback);
  1697. HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
  1698. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  1699. /**
  1700. * @}
  1701. */
  1702. /** @addtogroup ADC_Exported_Functions_Group2
  1703. * @brief IO operation functions
  1704. * @{
  1705. */
  1706. /* IO operation functions *****************************************************/
  1707. /* Blocking mode: Polling */
  1708. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc);
  1709. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef *hadc);
  1710. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout);
  1711. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef *hadc, uint32_t EventType, uint32_t Timeout);
  1712. /* Non-blocking mode: Interruption */
  1713. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef *hadc);
  1714. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef *hadc);
  1715. /* Non-blocking mode: DMA */
  1716. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);
  1717. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef *hadc);
  1718. /* ADC retrieve conversion value intended to be used with polling or interruption */
  1719. uint32_t HAL_ADC_GetValue(const ADC_HandleTypeDef *hadc);
  1720. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
  1721. void HAL_ADC_IRQHandler(ADC_HandleTypeDef *hadc);
  1722. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc);
  1723. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef *hadc);
  1724. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc);
  1725. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  1726. /**
  1727. * @}
  1728. */
  1729. /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions
  1730. * @brief Peripheral Control functions
  1731. * @{
  1732. */
  1733. /* Peripheral Control functions ***********************************************/
  1734. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, const ADC_ChannelConfTypeDef *pConfig);
  1735. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef *hadc,
  1736. const ADC_AnalogWDGConfTypeDef *pAnalogWDGConfig);
  1737. /**
  1738. * @}
  1739. */
  1740. /* Peripheral State functions *************************************************/
  1741. /** @addtogroup ADC_Exported_Functions_Group4
  1742. * @{
  1743. */
  1744. uint32_t HAL_ADC_GetState(const ADC_HandleTypeDef *hadc);
  1745. uint32_t HAL_ADC_GetError(const ADC_HandleTypeDef *hadc);
  1746. /**
  1747. * @}
  1748. */
  1749. /**
  1750. * @}
  1751. */
  1752. /* Private functions ---------------------------------------------------------*/
  1753. HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc);
  1754. HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc);
  1755. HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc);
  1756. /**
  1757. * @}
  1758. */
  1759. /**
  1760. * @}
  1761. */
  1762. /**
  1763. * @}
  1764. */
  1765. #ifdef __cplusplus
  1766. }
  1767. #endif
  1768. #endif /* STM32G0xx_HAL_ADC_H */