py32f002b_ll_adc.h 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_ll_adc.h
  4. * @author MCU Application Team
  5. * @brief Header file of ADC LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F002B_LL_ADC_H
  32. #define __PY32F002B_LL_ADC_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. #include "py32f002b_ll_bus.h"
  39. /** @addtogroup PY32F002B_LL_Driver
  40. * @{
  41. */
  42. #if defined (ADC1)
  43. /** @defgroup ADC_LL ADC
  44. * @{
  45. */
  46. /* Private types -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private constants ---------------------------------------------------------*/
  49. /** @defgroup ADC_LL_Private_Constants ADC Private Constants
  50. * @{
  51. */
  52. /* Internal mask for ADC group regular trigger: */
  53. /* To select into literal LL_ADC_REG_TRIG_x the relevant bits for: */
  54. /* - regular trigger source */
  55. /* - regular trigger edge */
  56. #define ADC_REG_TRIG_EXT_EDGE_DEFAULT (ADC_CFGR1_EXTEN_0)
  57. /* Mask containing trigger source masks for each of possible */
  58. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  59. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  60. #define ADC_REG_TRIG_SOURCE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTSEL) << (4U * 0U)) | \
  61. (( ADC_CFGR1_EXTSEL) << (4U * 1U)) | \
  62. (( ADC_CFGR1_EXTSEL) << (4U * 2U)) | \
  63. (( ADC_CFGR1_EXTSEL) << (4U * 3U)) )
  64. /* Mask containing trigger edge masks for each of possible */
  65. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  66. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  67. #define ADC_REG_TRIG_EDGE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN) << (4U * 0U)) | \
  68. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 1U)) | \
  69. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 2U)) | \
  70. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 3U)) )
  71. /* Definition of ADC group regular trigger bits information. */
  72. #define ADC_REG_TRIG_EXTSEL_BITOFFSET_POS ( 6U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_EXTSEL) */
  73. #define ADC_REG_TRIG_EXTEN_BITOFFSET_POS (10U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_EXTEN) */
  74. /* Internal mask for ADC channel: */
  75. /* To select into literal LL_ADC_CHANNEL_x the relevant bits for: */
  76. /* - channel identifier defined by number */
  77. /* - channel identifier defined by bitfield */
  78. /* - channel differentiation between external channels (connected to */
  79. /* GPIO pins) and internal channels (connected to internal paths) */
  80. #define ADC_CHANNEL_ID_NUMBER_MASK (ADC_CFGR1_AWDCH)
  81. #define ADC_CHANNEL_ID_BITFIELD_MASK (ADC_CHSELR_CHSEL)
  82. #define ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS (26U)/* Value equivalent to POSITION_VAL(ADC_CHANNEL_ID_NUMBER_MASK) */
  83. #define ADC_CHANNEL_ID_MASK (ADC_CHANNEL_ID_NUMBER_MASK | ADC_CHANNEL_ID_BITFIELD_MASK | ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  84. /* Equivalent mask of ADC_CHANNEL_NUMBER_MASK aligned on register LSB (bit 0) */
  85. #define ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 (0x0000001FU) /* Equivalent to shift: (ADC_CHANNEL_NUMBER_MASK >> POSITION_VAL(ADC_CHANNEL_NUMBER_MASK)) */
  86. /* Channel differentiation between external and internal channels */
  87. #define ADC_CHANNEL_ID_INTERNAL_CH (0x80000000U) /* Marker of internal channel */
  88. #define ADC_CHANNEL_ID_INTERNAL_CH_MASK (ADC_CHANNEL_ID_INTERNAL_CH)
  89. /* Definition of channels ID number information to be inserted into */
  90. /* channels literals definition. */
  91. #define ADC_CHANNEL_0_NUMBER (0x00000000U)
  92. #define ADC_CHANNEL_1_NUMBER ( ADC_CFGR1_AWDCH_0)
  93. #define ADC_CHANNEL_2_NUMBER ( ADC_CFGR1_AWDCH_1 )
  94. #define ADC_CHANNEL_3_NUMBER ( ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  95. #define ADC_CHANNEL_4_NUMBER ( ADC_CFGR1_AWDCH_2 )
  96. #define ADC_CHANNEL_5_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_0)
  97. #define ADC_CHANNEL_6_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 )
  98. #define ADC_CHANNEL_7_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  99. #define ADC_CHANNEL_8_NUMBER (ADC_CFGR1_AWDCH_3 )
  100. #define ADC_CHANNEL_9_NUMBER (ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_0)
  101. #if defined(ADC_CHSELR_CHSEL10)
  102. #define ADC_CHANNEL_10_NUMBER (ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_1 )
  103. #endif
  104. /* Definition of channels ID bitfield information to be inserted into */
  105. /* channels literals definition. */
  106. #define ADC_CHANNEL_0_BITFIELD (ADC_CHSELR_CHSEL0)
  107. #define ADC_CHANNEL_1_BITFIELD (ADC_CHSELR_CHSEL1)
  108. #define ADC_CHANNEL_2_BITFIELD (ADC_CHSELR_CHSEL2)
  109. #define ADC_CHANNEL_3_BITFIELD (ADC_CHSELR_CHSEL3)
  110. #define ADC_CHANNEL_4_BITFIELD (ADC_CHSELR_CHSEL4)
  111. #define ADC_CHANNEL_5_BITFIELD (ADC_CHSELR_CHSEL5)
  112. #define ADC_CHANNEL_6_BITFIELD (ADC_CHSELR_CHSEL6)
  113. #define ADC_CHANNEL_7_BITFIELD (ADC_CHSELR_CHSEL7)
  114. #define ADC_CHANNEL_8_BITFIELD (ADC_CHSELR_CHSEL8)
  115. #define ADC_CHANNEL_9_BITFIELD (ADC_CHSELR_CHSEL9)
  116. #if defined(ADC_CHSELR_CHSEL10)
  117. #define ADC_CHANNEL_10_BITFIELD (ADC_CHSELR_CHSEL10)
  118. #endif
  119. /* Internal mask for ADC analog watchdog: */
  120. /* To select into literals LL_ADC_AWD_CHANNELx_xxx the relevant bits for: */
  121. /* - analog watchdog 1: monitored channel defined by number, */
  122. /* selection of ADC group (ADC group regular). */
  123. /* Internal register offset for ADC analog watchdog channel configuration */
  124. #define ADC_AWD_CR1_REGOFFSET (0x00000000U)
  125. #define ADC_AWD_CRX_REGOFFSET_MASK (ADC_AWD_CR1_REGOFFSET)
  126. #define ADC_AWD_CR1_CHANNEL_MASK (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL)
  127. #define ADC_AWD_CR_ALL_CHANNEL_MASK (ADC_AWD_CR1_CHANNEL_MASK)
  128. /* Internal register offset for ADC analog watchdog threshold configuration */
  129. #define ADC_AWD_TR1_REGOFFSET (ADC_AWD_CR1_REGOFFSET)
  130. #define ADC_AWD_TRX_REGOFFSET_MASK (ADC_AWD_TR1_REGOFFSET)
  131. /* ADC registers bits positions */
  132. #define ADC_CFGR1_RES_BITOFFSET_POS ( 3U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_RESSEL) */
  133. #define ADC_CFGR1_AWDSGL_BITOFFSET_POS (22U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_AWDSGL) */
  134. #define ADC_TR_HT_BITOFFSET_POS (16U) /* Value equivalent to POSITION_VAL(ADC_TR_HT) */
  135. #define ADC_CHSELR_CHSEL0_BITOFFSET_POS ( 0U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL0) */
  136. #define ADC_CHSELR_CHSEL1_BITOFFSET_POS ( 1U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL1) */
  137. #define ADC_CHSELR_CHSEL2_BITOFFSET_POS ( 2U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL2) */
  138. #define ADC_CHSELR_CHSEL3_BITOFFSET_POS ( 3U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL3) */
  139. #define ADC_CHSELR_CHSEL4_BITOFFSET_POS ( 4U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL4) */
  140. #define ADC_CHSELR_CHSEL5_BITOFFSET_POS ( 5U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL5) */
  141. #define ADC_CHSELR_CHSEL6_BITOFFSET_POS ( 6U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL6) */
  142. #define ADC_CHSELR_CHSEL7_BITOFFSET_POS ( 7U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL7) */
  143. #define ADC_CHSELR_CHSEL8_BITOFFSET_POS ( 8U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL8) */
  144. #define ADC_CHSELR_CHSEL9_BITOFFSET_POS ( 9U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL9) */
  145. #if defined(ADC_CHSELR_CHSEL10)
  146. #define ADC_CHSELR_CHSEL10_BITOFFSET_POS (10U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL10) */
  147. #endif
  148. /* ADC registers bits groups */
  149. #define ADC_CR_BITS_PROPERTY_RS (ADC_CR_ADCAL | ADC_CR_ADSTP | ADC_CR_ADSTART | ADC_CR_ADDIS | ADC_CR_ADEN) /* ADC register CR bits with HW property "rs": Software can read as well as set this bit. Writing '0' has no effect on the bit value. */
  150. /* ADC internal channels related definitions */
  151. /* Internal voltage reference VrefInt */
  152. #define VREFINT_CAL_VREF ( 1200U) /* Analog voltage reference (Vref+) value (tolerance: +-10 mV) (unit: mV). */
  153. /* Temperature sensor */
  154. #define TEMPSENSOR_CAL1_ADDR ((uint16_t*) (0x1fff0114)) /* Internal temperature sensor, address of parameter TS_CAL1: temperature sensor ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */
  155. #define TEMPSENSOR_CAL2_ADDR ((uint16_t*) (0x1fff0118)) /* Internal temperature sensor, address of parameter TS_CAL2: temperature sensor ADC raw data acquired at temperature 85 DegC (tolerance: +-5 DegC), Vref+ = 3.3 V (tolerance: +-10 mV). */
  156. #define TEMPSENSOR_CAL1_TEMP (( int32_t) 30) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL1_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  157. #define TEMPSENSOR_CAL2_TEMP (( int32_t) 85) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL2_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  158. #define TEMPSENSOR_CAL_VREFANALOG ( 3300U) /* Analog voltage reference (Vref+) voltage with which temperature sensor has been calibrated in production (+-10 mV) (unit: mV). */
  159. /* Definitions of ADC hardware constraints delays */
  160. /* Note: Only ADC IP HW delays are defined in ADC LL driver driver, */
  161. /* not timeout values: */
  162. /* Timeout values for ADC operations are dependent to device clock */
  163. /* configuration (system clock versus ADC clock), */
  164. /* and therefore must be defined in user application. */
  165. /* Refer to @ref ADC_LL_EC_HW_DELAYS for description of ADC timeout */
  166. /* values definition. */
  167. /* Unit: CPU cycles. */
  168. #define LL_ADC_CLOCK_RATIO_VS_CPU_HIGHEST ((uint32_t) 512U * 16U * 4U)
  169. #define LL_ADC_TIMEOUT_DISABLE_CPU_CYCLES (LL_ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
  170. #define LL_ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES (LL_ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
  171. /**
  172. * @}
  173. */
  174. /* Exported types ------------------------------------------------------------*/
  175. #if defined(USE_FULL_LL_DRIVER)
  176. /** @defgroup ADC_LL_ES_INIT ADC Exported Init structure
  177. * @{
  178. */
  179. /**
  180. * @brief Structure definition of some features of ADC instance.
  181. * @note These parameters have an impact on ADC scope: ADC instance.
  182. * Refer to corresponding unitary functions into
  183. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  184. * @note The setting of these parameters by function @ref LL_ADC_Init()
  185. * is conditioned to ADC state:
  186. * ADC instance must be disabled.
  187. * Each feature can be updated afterwards with a unitary function
  188. * and potentially with ADC in a different state than disabled,
  189. * refer to description of each function for setting
  190. * conditioned to ADC state.
  191. */
  192. typedef struct
  193. {
  194. uint32_t Clock; /*!< Set ADC instance clock source and prescaler.
  195. This parameter can be a value of @ref ADC_LL_EC_CLOCK_SOURCE
  196. This feature can be modified afterwards using unitary function @ref LL_ADC_SetClock().
  197. For more details, refer to description of this function. */
  198. uint32_t Resolution; /*!< Set ADC resolution.
  199. This parameter can be a value of @ref ADC_LL_EC_RESOLUTION
  200. This feature can be modified afterwards using unitary function @ref LL_ADC_SetResolution(). */
  201. uint32_t DataAlignment; /*!< Set ADC conversion data alignment.
  202. This parameter can be a value of @ref ADC_LL_EC_DATA_ALIGN
  203. This feature can be modified afterwards using unitary function @ref LL_ADC_SetDataAlignment(). */
  204. uint32_t LowPowerMode; /*!< Set ADC low power mode.
  205. This parameter can be a value of @ref ADC_LL_EC_LP_MODE
  206. This feature can be modified afterwards using unitary function @ref LL_ADC_SetLowPowerMode(). */
  207. } LL_ADC_InitTypeDef;
  208. /**
  209. * @brief Structure definition of some features of ADC group regular.
  210. * @note These parameters have an impact on ADC scope: ADC group regular.
  211. * Refer to corresponding unitary functions into
  212. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  213. * (functions with prefix "REG").
  214. */
  215. typedef struct
  216. {
  217. uint32_t TriggerSource; /*!< Set ADC group regular conversion trigger source: internal (SW start) or from external IP (timer event).
  218. This parameter can be a value of @ref ADC_LL_EC_REG_TRIGGER_SOURCE
  219. @note setting trigger source to external trigger also set trigger polarity to rising edge
  220. In case of need to modify trigger edge, use function @ref LL_ADC_REG_SetTriggerEdge().
  221. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetTriggerSource(). */
  222. uint32_t SequencerDiscont; /*!< Set ADC group regular sequencer discontinuous mode: sequence subdivided and scan conversions interrupted every selected number of ranks.
  223. This parameter can be a value of @ref ADC_LL_EC_REG_SEQ_DISCONT_MODE
  224. @note This parameter has an effect only if group regular sequencer is enabled
  225. (several ADC channels enabled in group regular sequencer).
  226. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetSequencerDiscont(). */
  227. uint32_t ContinuousMode; /*!< Set ADC continuous conversion mode on ADC group regular, whether ADC conversions are performed in single mode (one conversion per trigger) or in continuous mode (after the first trigger, following conversions launched successively automatically).
  228. This parameter can be a value of @ref ADC_LL_EC_REG_CONTINUOUS_MODE
  229. Note: It is not possible to enable both ADC group regular continuous mode and discontinuous mode.
  230. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetContinuousMode(). */
  231. uint32_t Overrun; /*!< Set ADC group regular behavior in case of overrun:
  232. data preserved or overwritten.
  233. This parameter can be a value of @ref ADC_LL_EC_REG_OVR_DATA_BEHAVIOR
  234. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetOverrun(). */
  235. } LL_ADC_REG_InitTypeDef;
  236. /**
  237. * @}
  238. */
  239. #endif /* USE_FULL_LL_DRIVER */
  240. /* Exported constants --------------------------------------------------------*/
  241. /** @defgroup ADC_LL_Exported_Constants ADC Exported Constants
  242. * @{
  243. */
  244. /** @defgroup ADC_LL_EC_FLAG ADC flags
  245. * @brief Flags defines which can be used with LL_ADC_ReadReg function
  246. * @{
  247. */
  248. #define LL_ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC flag ADC group regular end of unitary conversion */
  249. #define LL_ADC_FLAG_EOS ADC_ISR_EOSEQ /*!< ADC flag ADC group regular end of sequence conversions */
  250. #define LL_ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC flag ADC group regular overrun */
  251. #define LL_ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC flag ADC group regular end of sampling phase */
  252. #define LL_ADC_FLAG_AWD ADC_ISR_AWD /*!< ADC flag ADC analog watchdog 1 */
  253. /**
  254. * @}
  255. */
  256. /** @defgroup ADC_LL_EC_IT ADC interruptions for configuration (interruption enable or disable)
  257. * @brief IT defines which can be used with LL_ADC_ReadReg and LL_ADC_WriteReg functions
  258. * @{
  259. */
  260. #define LL_ADC_IT_EOC ADC_IER_EOCIE /*!< ADC interruption ADC group regular end of unitary conversion */
  261. #define LL_ADC_IT_EOS ADC_IER_EOSEQIE /*!< ADC interruption ADC group regular end of sequence conversions */
  262. #define LL_ADC_IT_OVR ADC_IER_OVRIE /*!< ADC interruption ADC group regular overrun */
  263. #define LL_ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC interruption ADC group regular end of sampling phase */
  264. #define LL_ADC_IT_AWD ADC_IER_AWDIE /*!< ADC interruption ADC analog watchdog 1 */
  265. /**
  266. * @}
  267. */
  268. /** @defgroup ADC_LL_EC_COMMON_PATH_INTERNAL ADC common - Measurement path to internal channels
  269. * @{
  270. */
  271. /* Note: Other measurement paths to internal channels may be available */
  272. /* (connections to other peripherals). */
  273. /* If they are not listed below, they do not require any specific */
  274. /* path enable. In this case, Access to measurement path is done */
  275. /* only by selecting the corresponding ADC internal channel. */
  276. #define LL_ADC_PATH_INTERNAL_NONE (0x00000000U) /*!< ADC measurement pathes all disabled */
  277. #define LL_ADC_PATH_INTERNAL_VREFINT (ADC_CCR_VREFEN) /*!< ADC measurement path to internal channel VrefInt */
  278. #define LL_ADC_PATH_INTERNAL_TEMPSENSOR (ADC_CCR_TSEN) /*!< ADC measurement path to internal channel temperature sensor */
  279. /**
  280. * @}
  281. */
  282. /** @defgroup ADC_LL_EC_CLOCK_SOURCE ADC instance - Clock source
  283. * @{
  284. */
  285. #define LL_ADC_CLOCK_SYNC_PCLK_DIV1 (0x00000000U) /*!< ADC synchronous clock derived from APB clock divided by a prescaler of 1 */
  286. #define LL_ADC_CLOCK_SYNC_PCLK_DIV2 (ADC_CFGR2_CKMODE_0 ) /*!< ADC synchronous clock derived from APB clock divided by a prescaler of 2 */
  287. #define LL_ADC_CLOCK_SYNC_PCLK_DIV4 ( ADC_CFGR2_CKMODE_1 ) /*!< ADC synchronous clock derived from APB clock divided by a prescaler of 4 */
  288. #define LL_ADC_CLOCK_SYNC_PCLK_DIV8 (ADC_CFGR2_CKMODE_0 | ADC_CFGR2_CKMODE_1 ) /*!< ADC synchronous clock derived from APB clock divided by a prescaler of 8 */
  289. #define LL_ADC_CLOCK_SYNC_PCLK_DIV16 ( ADC_CFGR2_CKMODE_2 ) /*!< ADC synchronous clock derived from APB clock divided by a prescaler of 16 */
  290. #define LL_ADC_CLOCK_SYNC_PCLK_DIV32 (ADC_CFGR2_CKMODE_0 | ADC_CFGR2_CKMODE_2 ) /*!< ADC synchronous clock derived from APB clock divided by a prescaler of 32 */
  291. #define LL_ADC_CLOCK_SYNC_PCLK_DIV64 ( ADC_CFGR2_CKMODE_1 | ADC_CFGR2_CKMODE_2 ) /*!< ADC synchronous clock derived from APB clock divided by a prescaler of 64 */
  292. #define LL_ADC_CLOCK_ASYNC_HSI_DIV1 ( ADC_CFGR2_CKMODE_3) /*!< ADC asynchronous clock derived from HSI clock divided by a prescaler of 1 */
  293. #define LL_ADC_CLOCK_ASYNC_HSI_DIV2 (ADC_CFGR2_CKMODE_0 | ADC_CFGR2_CKMODE_3) /*!< ADC asynchronous clock derived from HSI clock divided by a prescaler of 2 */
  294. #define LL_ADC_CLOCK_ASYNC_HSI_DIV4 ( ADC_CFGR2_CKMODE_1 | ADC_CFGR2_CKMODE_3) /*!< ADC asynchronous clock derived from HSI clock divided by a prescaler of 4 */
  295. #define LL_ADC_CLOCK_ASYNC_HSI_DIV8 (ADC_CFGR2_CKMODE_0 | ADC_CFGR2_CKMODE_1 | ADC_CFGR2_CKMODE_3) /*!< ADC asynchronous clock derived from HSI clock divided by a prescaler of 8 */
  296. #define LL_ADC_CLOCK_ASYNC_HSI_DIV16 ( ADC_CFGR2_CKMODE_2 | ADC_CFGR2_CKMODE_3) /*!< ADC asynchronous clock derived from HSI clock divided by a prescaler of 16 */
  297. #define LL_ADC_CLOCK_ASYNC_HSI_DIV32 (ADC_CFGR2_CKMODE_0 | ADC_CFGR2_CKMODE_2 | ADC_CFGR2_CKMODE_3) /*!< ADC asynchronous clock derived from HSI clock divided by a prescaler of 32 */
  298. #define LL_ADC_CLOCK_ASYNC_HSI_DIV64 ( ADC_CFGR2_CKMODE_1 | ADC_CFGR2_CKMODE_2 | ADC_CFGR2_CKMODE_3) /*!< ADC asynchronous clock derived from HSI clock divided by a prescaler of 64 */
  299. /**
  300. * @}
  301. */
  302. /** @defgroup ADC_LL_EC_RESOLUTION ADC instance - Resolution
  303. * @{
  304. */
  305. #define LL_ADC_RESOLUTION_12B (0x00000000U) /*!< ADC resolution 12 bits */
  306. #define LL_ADC_RESOLUTION_10B (ADC_CFGR1_RESSEL_0) /*!< ADC resolution 10 bits */
  307. #define LL_ADC_RESOLUTION_8B (ADC_CFGR1_RESSEL_1) /*!< ADC resolution 8 bits */
  308. #define LL_ADC_RESOLUTION_6B (ADC_CFGR1_RESSEL_1 | ADC_CFGR1_RESSEL_0) /*!< ADC resolution 6 bits */
  309. /**
  310. * @}
  311. */
  312. /** @defgroup ADC_LL_EC_DATA_ALIGN ADC instance - Data alignment
  313. * @{
  314. */
  315. #define LL_ADC_DATA_ALIGN_RIGHT (0x00000000U) /*!< ADC conversion data alignment: right aligned (alignment on data register LSB bit 0)*/
  316. #define LL_ADC_DATA_ALIGN_LEFT (ADC_CFGR1_ALIGN) /*!< ADC conversion data alignment: left aligned (aligment on data register MSB bit 15)*/
  317. /**
  318. * @}
  319. */
  320. /** @defgroup ADC_LL_EC_LP_MODE ADC instance - Low power mode
  321. * @{
  322. */
  323. #define LL_ADC_LP_MODE_NONE (0x00000000U) /*!< No ADC low power mode activated */
  324. #define LL_ADC_LP_AUTOWAIT (ADC_CFGR1_WAIT) /*!< ADC low power mode auto delay: Dynamic low power mode, ADC conversions are performed only when necessary (when previous ADC conversion data is read). See description with function @ref LL_ADC_SetLowPowerMode(). */
  325. /**
  326. * @}
  327. */
  328. /** @defgroup ADC_LL_EC_GROUPS ADC instance - Groups
  329. * @{
  330. */
  331. #define LL_ADC_GROUP_REGULAR (0x00000001U) /*!< ADC group regular */
  332. /**
  333. * @}
  334. */
  335. /** @defgroup ADC_LL_EC_CHANNEL ADC instance - Channel number
  336. * @{
  337. */
  338. #define LL_ADC_CHANNEL_0 (ADC_CHANNEL_0_NUMBER | ADC_CHANNEL_0_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN0 */
  339. #define LL_ADC_CHANNEL_1 (ADC_CHANNEL_1_NUMBER | ADC_CHANNEL_1_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN1 */
  340. #define LL_ADC_CHANNEL_2 (ADC_CHANNEL_2_NUMBER | ADC_CHANNEL_2_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN2 */
  341. #define LL_ADC_CHANNEL_3 (ADC_CHANNEL_3_NUMBER | ADC_CHANNEL_3_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN3 */
  342. #define LL_ADC_CHANNEL_4 (ADC_CHANNEL_4_NUMBER | ADC_CHANNEL_4_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN4 */
  343. #define LL_ADC_CHANNEL_5 (ADC_CHANNEL_5_NUMBER | ADC_CHANNEL_5_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN5 */
  344. #define LL_ADC_CHANNEL_6 (ADC_CHANNEL_6_NUMBER | ADC_CHANNEL_6_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN6 */
  345. #define LL_ADC_CHANNEL_7 (ADC_CHANNEL_7_NUMBER | ADC_CHANNEL_7_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN7 */
  346. #define LL_ADC_CHANNEL_8 (ADC_CHANNEL_8_NUMBER | ADC_CHANNEL_8_BITFIELD )
  347. #define LL_ADC_CHANNEL_9 (ADC_CHANNEL_9_NUMBER | ADC_CHANNEL_9_BITFIELD )
  348. #if defined(ADC_CHSELR_CHSEL10)
  349. #define LL_ADC_CHANNEL_10 (ADC_CHANNEL_10_NUMBER | ADC_CHANNEL_10_BITFIELD)
  350. #endif
  351. #define LL_ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_8 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to Temperature sensor. */
  352. #define LL_ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_9 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to VrefInt: Internal voltage reference. */
  353. #if defined(ADC_CHSELR_CHSEL10)
  354. #define LL_ADC_CHANNEL_1_3VCCA (LL_ADC_CHANNEL_10 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to 1/3VCCA: Internal voltage reference. */
  355. #endif
  356. /**
  357. * @}
  358. */
  359. /** @defgroup ADC_LL_VREFBUF_VOLTAGE ADC instance - Vrefbuf Voltage
  360. * @{
  361. */
  362. #define LL_ADC_VREFBUF_1P5V (0x00000000U) /*!< VREFBUF Output voltage 1.5V. */
  363. /**
  364. * @}
  365. */
  366. /** @defgroup ADC_LL_EC_REG_TRIGGER_SOURCE ADC group regular - Trigger source
  367. * @{
  368. */
  369. #define LL_ADC_REG_TRIG_SOFTWARE (0x00000000U) /*!< ADC group regular conversion trigger internal: SW start. */
  370. #define LL_ADC_REG_TRIG_EXT_TIM1_TRGO ( ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external IP: TIM1 TRGO. Trigger edge set to rising edge (default setting). */
  371. #define LL_ADC_REG_TRIG_EXT_TIM1_CH4 ( ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external IP: TIM1 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  372. /**
  373. * @}
  374. */
  375. /** @defgroup ADC_LL_EC_REG_TRIGGER_EDGE ADC group regular - Trigger edge
  376. * @{
  377. */
  378. #define LL_ADC_REG_TRIG_EXT_RISING ( ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to rising edge */
  379. #define LL_ADC_REG_TRIG_EXT_FALLING (ADC_CFGR1_EXTEN_1 ) /*!< ADC group regular conversion trigger polarity set to falling edge */
  380. #define LL_ADC_REG_TRIG_EXT_RISINGFALLING (ADC_CFGR1_EXTEN_1 | ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to both rising and falling edges */
  381. /**
  382. * @}
  383. */
  384. /** @defgroup ADC_LL_EC_REG_CONTINUOUS_MODE ADC group regular - Continuous mode
  385. * @{
  386. */
  387. #define LL_ADC_REG_CONV_SINGLE (0x00000000U) /*!< ADC conversions are performed in single mode: one conversion per trigger */
  388. #define LL_ADC_REG_CONV_CONTINUOUS (ADC_CFGR1_CONT) /*!< ADC conversions are performed in continuous mode: after the first trigger, following conversions launched successively automatically */
  389. /**
  390. * @}
  391. */
  392. /** @defgroup ADC_LL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data
  393. * @{
  394. */
  395. #define LL_ADC_REG_OVR_DATA_PRESERVED (0x00000000U) /*!< ADC group regular behavior in case of overrun: data preserved */
  396. #define LL_ADC_REG_OVR_DATA_OVERWRITTEN (ADC_CFGR1_OVRMOD) /*!< ADC group regular behavior in case of overrun: data overwritten */
  397. /**
  398. * @}
  399. */
  400. /** @defgroup ADC_LL_EC_REG_SEQ_SCAN_DIRECTION ADC group regular - Sequencer scan direction
  401. * @{
  402. */
  403. #define LL_ADC_REG_SEQ_SCAN_DIR_FORWARD (0x00000000U) /*!< ADC group regular sequencer scan direction forward: from lowest channel number to highest channel number (scan of all ranks, ADC conversion of ranks with channels enabled in sequencer).*/
  404. #define LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD (ADC_CFGR1_SCANDIR) /*!< ADC group regular sequencer scan direction backward: from highest channel number to lowest channel number (scan of all ranks, ADC conversion of ranks with channels enabled in sequencer) */
  405. /**
  406. * @}
  407. */
  408. /** @defgroup ADC_LL_EC_REG_SEQ_DISCONT_MODE ADC group regular - Sequencer discontinuous mode
  409. * @{
  410. */
  411. #define LL_ADC_REG_SEQ_DISCONT_DISABLE (0x00000000U) /*!< ADC group regular sequencer discontinuous mode disable */
  412. #define LL_ADC_REG_SEQ_DISCONT_1RANK (ADC_CFGR1_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every rank */
  413. /**
  414. * @}
  415. */
  416. /** @defgroup ADC_LL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time
  417. * @{
  418. */
  419. #define LL_ADC_SAMPLINGTIME_3CYCLES_5 (0x00000000U) /*!< Sampling time 3.5 ADC clock cycles */
  420. #define LL_ADC_SAMPLINGTIME_5CYCLES_5 ( ADC_SMPR_SMP_0) /*!< Sampling time 5.5 ADC clock cycles */
  421. #define LL_ADC_SAMPLINGTIME_7CYCLES_5 ( ADC_SMPR_SMP_1 ) /*!< Sampling time 7.5 ADC clock cycles */
  422. #define LL_ADC_SAMPLINGTIME_13CYCLES_5 ( ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0) /*!< Sampling time 13.5 ADC clock cycles */
  423. #define LL_ADC_SAMPLINGTIME_28CYCLES_5 (ADC_SMPR_SMP_2 ) /*!< Sampling time 28.5 ADC clock cycles */
  424. #define LL_ADC_SAMPLINGTIME_41CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_0) /*!< Sampling time 41.5 ADC clock cycles */
  425. #define LL_ADC_SAMPLINGTIME_71CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1 ) /*!< Sampling time 71.5 ADC clock cycles */
  426. #define LL_ADC_SAMPLINGTIME_239CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0) /*!< Sampling time 239.5 ADC clock cycles */
  427. /**
  428. * @}
  429. */
  430. /** @defgroup ADC_LL_EC_AWD_NUMBER Analog watchdog - Analog watchdog number
  431. * @{
  432. */
  433. #define LL_ADC_AWD (ADC_AWD_CR1_CHANNEL_MASK | ADC_AWD_CR1_REGOFFSET) /*!< ADC analog watchdog number 1 */
  434. /**
  435. * @}
  436. */
  437. /** @defgroup ADC_LL_EC_AWD_CHANNELS Analog watchdog - Monitored channels
  438. * @{
  439. */
  440. #define LL_ADC_AWD_DISABLE (0x00000000U) /*!< ADC analog watchdog monitoring disabled */
  441. #define LL_ADC_AWD_ALL_CHANNELS_REG ( ADC_CFGR1_AWDEN ) /*!< ADC analog watchdog monitoring of all channels, converted by group regular only */
  442. #define LL_ADC_AWD_CHANNEL_1_REG ((LL_ADC_CHANNEL_0 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN1, converted by group regular only */
  443. #define LL_ADC_AWD_CHANNEL_2_REG ((LL_ADC_CHANNEL_1 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN2, converted by group regular only */
  444. #define LL_ADC_AWD_CHANNEL_3_REG ((LL_ADC_CHANNEL_2 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN3, converted by group regular only */
  445. #define LL_ADC_AWD_CHANNEL_4_REG ((LL_ADC_CHANNEL_3 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN4, converted by group regular only */
  446. #define LL_ADC_AWD_CHANNEL_5_REG ((LL_ADC_CHANNEL_4 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN5, converted by group regular only */
  447. #define LL_ADC_AWD_CHANNEL_6_REG ((LL_ADC_CHANNEL_5 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN6, converted by group regular only */
  448. #define LL_ADC_AWD_CHANNEL_7_REG ((LL_ADC_CHANNEL_6 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN7, converted by group regular only */
  449. #define LL_ADC_AWD_CHANNEL_8_REG ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN8, converted by group regular only */
  450. #define LL_ADC_AWD_CHANNEL_9_REG ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN9, converted by group regular only */
  451. #if defined(ADC_CHSELR_CHSEL10)
  452. #define LL_ADC_AWD_CHANNEL_10_REG ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN11, converted by group regular only */
  453. #endif
  454. #define LL_ADC_AWD_CH_TEMPSENSOR_REG ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Temperature sensor, converted by group regular only */
  455. #define LL_ADC_AWD_CH_VREFINT_REG ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to VrefInt: Internal voltage reference, converted by group regular only */
  456. #if defined(ADC_CHSELR_CHSEL10)
  457. #define LL_ADC_AWD_CH_1_3VCCA_REG ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to VrefInt: Internal voltage reference, converted by group regular only */
  458. #endif
  459. /**
  460. * @}
  461. */
  462. /** @defgroup ADC_LL_EC_AWD_THRESHOLDS Analog watchdog - Thresholds
  463. * @{
  464. */
  465. #define LL_ADC_AWD_THRESHOLD_HIGH (ADC_TR_HT ) /*!< ADC analog watchdog threshold high */
  466. #define LL_ADC_AWD_THRESHOLD_LOW ( ADC_TR_LT) /*!< ADC analog watchdog threshold low */
  467. #define LL_ADC_AWD_THRESHOLDS_HIGH_LOW (ADC_TR_HT | ADC_TR_LT) /*!< ADC analog watchdog both thresholds high and low concatenated into the same data */
  468. /**
  469. * @}
  470. */
  471. /** @defgroup ADC_LL_EC_CAL_SAMPLINGTIME Calibration - Sampling time
  472. * @{
  473. */
  474. #define LL_ADC_CAL_SAMPLINGTIME_1CYCLE (0x00000000U) /*!< CAL Sampling time 1 ADC clock cycle */
  475. #define LL_ADC_CAL_SAMPLINGTIME_2CYCLES ( ADC_CCSR_CALSMP_0) /*!< CAL Sampling time 2 ADC clock cycles */
  476. #define LL_ADC_CAL_SAMPLINGTIME_4CYCLES (ADC_CCSR_CALSMP_1 ) /*!< CAL Sampling time 4 ADC clock cycles */
  477. #define LL_ADC_CAL_SAMPLINGTIME_8CYCLES (ADC_CCSR_CALSMP_1 | ADC_CCSR_CALSMP_0) /*!< CAL Sampling time 8 ADC clock cycles */
  478. /**
  479. * @}
  480. */
  481. /** @defgroup ADC_LL_EC_CAL_MODE Calibration - Mode
  482. * @{
  483. */
  484. #define LL_ADC_CAL_MODE_OFFSET (0x00000000U) /*!< ADC calibration mode selection only OFFSET */
  485. #define LL_ADC_CAL_MODE_OFFSET_CAPACITANCE ADC_CCSR_CALSEL /*!< ADC calibration mode selection OFFSET AND CAPACITANCE */
  486. /**
  487. * @}
  488. */
  489. /** @defgroup ADC_LL_EC_CAL_STATUS Calibration - Status
  490. * @{
  491. */
  492. #define LL_ADC_CAL_OFFSET_STATUS_FAIL (0x00000000) /*!< ADC calibration status OFFSET FAIL */
  493. #define LL_ADC_CAL_OFFSET_STATUS_SUCCESS (ADC_CCSR_OFFSUC) /*!< ADC calibration status OFFSET SUCCESS */
  494. #define LL_ADC_CAL_CAPACITANCE_STATUS_FAIL (0x00000000) /*!< ADC calibration status CAPACITANCE FAIL */
  495. #define LL_ADC_CAL_CAPACITANCE_STATUS_SUCCESS (ADC_CCSR_CAPSUC) /*!< ADC calibration status CAPACITANCE SUCCESS */
  496. /**
  497. * @}
  498. */
  499. /** @defgroup ADC_LL_EC_HW_DELAYS Definitions of ADC hardware constraints delays
  500. * @note Only ADC IP HW delays are defined in ADC LL driver driver,
  501. * not timeout values.
  502. * For details on delays values, refer to descriptions in source code
  503. * above each literal definition.
  504. * @{
  505. */
  506. /* Delay for internal voltage reference stabilization time. */
  507. /* Delay set to maximum value (refer to device datasheet, */
  508. /* parameter "tSTART"). */
  509. /* Unit: us */
  510. #define LL_ADC_DELAY_VREFINT_STAB_US ( 10U) /*!< Delay for internal voltage reference stabilization time */
  511. /* Delay for temperature sensor stabilization time. */
  512. /* Literal set to maximum value (refer to device datasheet, */
  513. /* parameter "tSTART"). */
  514. /* Unit: us */
  515. #define LL_ADC_DELAY_TEMPSENSOR_STAB_US ( 10U) /*!< Delay for temperature sensor stabilization time */
  516. /* Delay required between ADC end of calibration and ADC enable. */
  517. /* Unit: ADC clock cycles. */
  518. #define LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES ( 4U) /*!< Delay required between ADC end of calibration and ADC enable */
  519. /* Delay between ADC end of calibration and ADC enable. */
  520. /* Delay estimation in CPU cycles: Case of ADC enable done */
  521. /* immediately after ADC calibration, ADC clock setting slow */
  522. /* (CPU clock / ADC clock) is above 64. */
  523. #define LL_ADC_DELAY_CALIB_ENABLE_CPU_CYCLES (LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES * 64)
  524. /* Timeout values for ADC Calibration. */
  525. #define LL_ADC_CALIBRATION_TIMEOUT_CPU_CYCLES ( 1000U)
  526. /**
  527. * @}
  528. */
  529. /**
  530. * @}
  531. */
  532. /* Exported macro ------------------------------------------------------------*/
  533. /** @defgroup ADC_LL_Exported_Macros ADC Exported Macros
  534. * @{
  535. */
  536. /** @defgroup ADC_LL_EM_WRITE_READ Common write and read registers Macros
  537. * @{
  538. */
  539. /**
  540. * @brief Write a value in ADC register
  541. * @param __INSTANCE__ ADC Instance
  542. * @param __REG__ Register to be written
  543. * @param __VALUE__ Value to be written in the register
  544. * @retval None
  545. */
  546. #define LL_ADC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  547. /**
  548. * @brief Read a value in ADC register
  549. * @param __INSTANCE__ ADC Instance
  550. * @param __REG__ Register to be read
  551. * @retval Register value
  552. */
  553. #define LL_ADC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  554. /**
  555. * @}
  556. */
  557. /** @defgroup ADC_LL_EM_HELPER_MACRO ADC helper macro
  558. * @{
  559. */
  560. /**
  561. * @brief Helper macro to get ADC channel number in decimal format
  562. * from literals LL_ADC_CHANNEL_x.
  563. * @note Example:
  564. * __LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_4)
  565. * will return decimal number "4".
  566. * @note The input can be a value from functions where a channel
  567. * number is returned, either defined with number
  568. * or with bitfield (only one bit must be set).
  569. * @note Depending on devices and packages, some channels may not be available.
  570. * Refer to device datasheet for channels availability.
  571. * @param __CHANNEL__ This parameter can be one of the following values:
  572. * @arg @ref LL_ADC_CHANNEL_0
  573. * @arg @ref LL_ADC_CHANNEL_1
  574. * @arg @ref LL_ADC_CHANNEL_2
  575. * @arg @ref LL_ADC_CHANNEL_3
  576. * @arg @ref LL_ADC_CHANNEL_4
  577. * @arg @ref LL_ADC_CHANNEL_5
  578. * @arg @ref LL_ADC_CHANNEL_6
  579. * @arg @ref LL_ADC_CHANNEL_7
  580. * @arg @ref LL_ADC_CHANNEL_8
  581. * @arg @ref LL_ADC_CHANNEL_9
  582. * @arg @ref LL_ADC_CHANNEL_10
  583. * @arg @ref LL_ADC_CHANNEL_VREFINT
  584. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  585. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  586. * @retval Value between Min_Data=0 and Max_Data=11
  587. */
  588. #if defined(ADC_CHSELR_CHSEL10)
  589. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  590. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0U) \
  591. ? ( \
  592. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  593. ) \
  594. : \
  595. ( \
  596. (((__CHANNEL__) & ADC_CHSELR_CHSEL0) == ADC_CHSELR_CHSEL0) ? (0U) : \
  597. ( \
  598. (((__CHANNEL__) & ADC_CHSELR_CHSEL1) == ADC_CHSELR_CHSEL1) ? (1U) : \
  599. ( \
  600. (((__CHANNEL__) & ADC_CHSELR_CHSEL2) == ADC_CHSELR_CHSEL2) ? (2U) : \
  601. ( \
  602. (((__CHANNEL__) & ADC_CHSELR_CHSEL3) == ADC_CHSELR_CHSEL3) ? (3U) : \
  603. ( \
  604. (((__CHANNEL__) & ADC_CHSELR_CHSEL4) == ADC_CHSELR_CHSEL4) ? (4U) : \
  605. ( \
  606. (((__CHANNEL__) & ADC_CHSELR_CHSEL5) == ADC_CHSELR_CHSEL5) ? (5U) : \
  607. ( \
  608. (((__CHANNEL__) & ADC_CHSELR_CHSEL6) == ADC_CHSELR_CHSEL6) ? (6U) : \
  609. ( \
  610. (((__CHANNEL__) & ADC_CHSELR_CHSEL7) == ADC_CHSELR_CHSEL7) ? (7U) : \
  611. ( \
  612. (((__CHANNEL__) & ADC_CHSELR_CHSEL8) == ADC_CHSELR_CHSEL8) ? (8U) : \
  613. ( \
  614. (((__CHANNEL__) & ADC_CHSELR_CHSEL9) == ADC_CHSELR_CHSEL9) ? (9U) : \
  615. ( \
  616. (((__CHANNEL__) & ADC_CHSELR_CHSEL10) == ADC_CHSELR_CHSEL10) ? (10U) : \
  617. (0U) \
  618. ) \
  619. ) \
  620. ) \
  621. ) \
  622. ) \
  623. ) \
  624. ) \
  625. ) \
  626. ) \
  627. ) \
  628. ) \
  629. )
  630. #else
  631. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  632. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0U) \
  633. ? ( \
  634. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  635. ) \
  636. : \
  637. ( \
  638. (((__CHANNEL__) & ADC_CHSELR_CHSEL0) == ADC_CHSELR_CHSEL0) ? (0U) : \
  639. ( \
  640. (((__CHANNEL__) & ADC_CHSELR_CHSEL1) == ADC_CHSELR_CHSEL1) ? (1U) : \
  641. ( \
  642. (((__CHANNEL__) & ADC_CHSELR_CHSEL2) == ADC_CHSELR_CHSEL2) ? (2U) : \
  643. ( \
  644. (((__CHANNEL__) & ADC_CHSELR_CHSEL3) == ADC_CHSELR_CHSEL3) ? (3U) : \
  645. ( \
  646. (((__CHANNEL__) & ADC_CHSELR_CHSEL4) == ADC_CHSELR_CHSEL4) ? (4U) : \
  647. ( \
  648. (((__CHANNEL__) & ADC_CHSELR_CHSEL5) == ADC_CHSELR_CHSEL5) ? (5U) : \
  649. ( \
  650. (((__CHANNEL__) & ADC_CHSELR_CHSEL6) == ADC_CHSELR_CHSEL6) ? (6U) : \
  651. ( \
  652. (((__CHANNEL__) & ADC_CHSELR_CHSEL7) == ADC_CHSELR_CHSEL7) ? (7U) : \
  653. ( \
  654. (((__CHANNEL__) & ADC_CHSELR_CHSEL8) == ADC_CHSELR_CHSEL8) ? (8U) : \
  655. ( \
  656. (((__CHANNEL__) & ADC_CHSELR_CHSEL9) == ADC_CHSELR_CHSEL9) ? (9U) : \
  657. (0U) \
  658. ) \
  659. ) \
  660. ) \
  661. ) \
  662. ) \
  663. ) \
  664. ) \
  665. ) \
  666. ) \
  667. ) \
  668. )
  669. #endif
  670. /**
  671. * @brief Helper macro to get ADC channel in literal format LL_ADC_CHANNEL_x
  672. * from number in decimal format.
  673. * @note Example:
  674. * __LL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  675. * will return a data equivalent to "LL_ADC_CHANNEL_4".
  676. * @note Depending on devices and packages, some channels may not be available.
  677. * Refer to device datasheet for channels availability.
  678. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=10
  679. * @retval Returned value can be one of the following values:
  680. * @arg @ref LL_ADC_CHANNEL_0
  681. * @arg @ref LL_ADC_CHANNEL_1
  682. * @arg @ref LL_ADC_CHANNEL_2
  683. * @arg @ref LL_ADC_CHANNEL_3
  684. * @arg @ref LL_ADC_CHANNEL_4
  685. * @arg @ref LL_ADC_CHANNEL_5
  686. * @arg @ref LL_ADC_CHANNEL_6
  687. * @arg @ref LL_ADC_CHANNEL_7
  688. * @arg @ref LL_ADC_CHANNEL_8
  689. * @arg @ref LL_ADC_CHANNEL_9
  690. * @arg @ref LL_ADC_CHANNEL_10
  691. * @arg @ref LL_ADC_CHANNEL_VREFINT (1)
  692. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (1)
  693. * @arg @ref LL_ADC_CHANNEL_1_3VCCA (1)
  694. * (1) For ADC channel read back from ADC register,
  695. * comparison with internal channel parameter to be done
  696. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  697. */
  698. #define __LL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  699. ( \
  700. ((__DECIMAL_NB__) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) | \
  701. (ADC_CHSELR_CHSEL0 << (__DECIMAL_NB__)) \
  702. )
  703. /**
  704. * @brief Helper macro to determine whether the selected channel
  705. * corresponds to literal definitions of driver.
  706. * @note The different literal definitions of ADC channels are:
  707. * - ADC internal channel:
  708. * LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...
  709. * - ADC external channel (channel connected to a GPIO pin):
  710. * LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...
  711. * @note Depending on devices and packages, some channels may not be available.
  712. * Refer to device datasheet for channels availability.
  713. * @param __CHANNEL__ This parameter can be one of the following values:
  714. * @arg @ref LL_ADC_CHANNEL_0
  715. * @arg @ref LL_ADC_CHANNEL_1
  716. * @arg @ref LL_ADC_CHANNEL_2
  717. * @arg @ref LL_ADC_CHANNEL_3
  718. * @arg @ref LL_ADC_CHANNEL_4
  719. * @arg @ref LL_ADC_CHANNEL_5
  720. * @arg @ref LL_ADC_CHANNEL_6
  721. * @arg @ref LL_ADC_CHANNEL_7
  722. * @arg @ref LL_ADC_CHANNEL_8
  723. * @arg @ref LL_ADC_CHANNEL_9
  724. * @arg @ref LL_ADC_CHANNEL_10
  725. * @arg @ref LL_ADC_CHANNEL_VREFINT
  726. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  727. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  728. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel connected to a GPIO pin).
  729. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  730. */
  731. #define __LL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  732. (((__CHANNEL__) & ADC_CHANNEL_ID_INTERNAL_CH_MASK) != 0U)
  733. /**
  734. * @brief Helper macro to convert a channel defined from parameter
  735. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  736. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  737. * to its equivalent parameter definition of a ADC external channel
  738. * (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...).
  739. * @note Depending on devices and packages, some channels may not be available.
  740. * Refer to device datasheet for channels availability.
  741. * @param __CHANNEL__ This parameter can be one of the following values:
  742. * @arg @ref LL_ADC_CHANNEL_0
  743. * @arg @ref LL_ADC_CHANNEL_1
  744. * @arg @ref LL_ADC_CHANNEL_2
  745. * @arg @ref LL_ADC_CHANNEL_3
  746. * @arg @ref LL_ADC_CHANNEL_4
  747. * @arg @ref LL_ADC_CHANNEL_5
  748. * @arg @ref LL_ADC_CHANNEL_6
  749. * @arg @ref LL_ADC_CHANNEL_7
  750. * @arg @ref LL_ADC_CHANNEL_8
  751. * @arg @ref LL_ADC_CHANNEL_9
  752. * @arg @ref LL_ADC_CHANNEL_10
  753. * @arg @ref LL_ADC_CHANNEL_VREFINT
  754. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  755. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  756. * @retval Returned value can be one of the following values:
  757. * @arg @ref LL_ADC_CHANNEL_0
  758. * @arg @ref LL_ADC_CHANNEL_1
  759. * @arg @ref LL_ADC_CHANNEL_2
  760. * @arg @ref LL_ADC_CHANNEL_3
  761. * @arg @ref LL_ADC_CHANNEL_4
  762. * @arg @ref LL_ADC_CHANNEL_5
  763. * @arg @ref LL_ADC_CHANNEL_6
  764. * @arg @ref LL_ADC_CHANNEL_7
  765. * @arg @ref LL_ADC_CHANNEL_8
  766. * @arg @ref LL_ADC_CHANNEL_9
  767. * @arg @ref LL_ADC_CHANNEL_10
  768. */
  769. #define __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  770. ((__CHANNEL__) & ~ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  771. /**
  772. * @brief Helper macro to determine whether the internal channel
  773. * selected is available on the ADC instance selected.
  774. * @param __ADC_INSTANCE__ ADC instance
  775. * @param __CHANNEL__ This parameter can be one of the following values:
  776. * @arg @ref LL_ADC_CHANNEL_VREFINT
  777. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  778. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  779. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  780. * Value "1" if the internal channel selected is available on the ADC instance selected.
  781. */
  782. #if defined(ADC_CHSELR_CHSEL10)
  783. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  784. ( \
  785. ((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  786. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) || \
  787. ((__CHANNEL__) == LL_ADC_CHANNEL_1_3VCCA) \
  788. )
  789. #else
  790. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  791. ( \
  792. ((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  793. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) \
  794. )
  795. #endif
  796. /**
  797. * @brief Helper macro to define ADC analog watchdog parameter:
  798. * define a single channel to monitor with analog watchdog
  799. * from sequencer channel and groups definition.
  800. * @note To be used with function @ref LL_ADC_SetAnalogWDMonitChannels().
  801. * Example:
  802. * LL_ADC_SetAnalogWDMonitChannels(
  803. * ADC1, LL_ADC_AWD,
  804. * __LL_ADC_ANALOGWD_CHANNEL_GROUP(LL_ADC_CHANNEL4, LL_ADC_GROUP_REGULAR))
  805. * @note Depending on devices and packages, some channels may not be available.
  806. * Refer to device datasheet for channels availability.
  807. * @param __CHANNEL__ This parameter can be one of the following values:
  808. * @arg @ref LL_ADC_CHANNEL_0
  809. * @arg @ref LL_ADC_CHANNEL_1
  810. * @arg @ref LL_ADC_CHANNEL_2
  811. * @arg @ref LL_ADC_CHANNEL_3
  812. * @arg @ref LL_ADC_CHANNEL_4
  813. * @arg @ref LL_ADC_CHANNEL_5
  814. * @arg @ref LL_ADC_CHANNEL_6
  815. * @arg @ref LL_ADC_CHANNEL_7
  816. * @arg @ref LL_ADC_CHANNEL_8
  817. * @arg @ref LL_ADC_CHANNEL_9
  818. * @arg @ref LL_ADC_CHANNEL_10
  819. * @arg @ref LL_ADC_CHANNEL_VREFINT (1)
  820. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (1)
  821. * @arg @ref LL_ADC_CHANNEL_1_3VCCA (1)
  822. * (1) For ADC channel read back from ADC register,
  823. * comparison with internal channel parameter to be done
  824. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  825. * @param __GROUP__ This parameter can be one of the following values:
  826. * @arg @ref LL_ADC_GROUP_REGULAR
  827. * @retval Returned value can be one of the following values:
  828. * @arg @ref LL_ADC_AWD_DISABLE
  829. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  830. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  831. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  832. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  833. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  834. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  835. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  836. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  837. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  838. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  839. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  840. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  841. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  842. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  843. * @arg @ref LL_ADC_AWD_CH_1_3VCCA_REG
  844. */
  845. #define __LL_ADC_ANALOGWD_CHANNEL_GROUP(__CHANNEL__, __GROUP__)\
  846. (((__CHANNEL__) & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL)
  847. /**
  848. * @brief Helper macro to set the value of ADC analog watchdog threshold high
  849. * or low in function of ADC resolution, when ADC resolution is
  850. * different of 12 bits.
  851. * @note To be used with function @ref LL_ADC_ConfigAnalogWDThresholds()
  852. * or @ref LL_ADC_SetAnalogWDThresholds().
  853. * Example, with a ADC resolution of 8 bits, to set the value of
  854. * analog watchdog threshold high (on 8 bits):
  855. * LL_ADC_SetAnalogWDThresholds
  856. * (< ADCx param >,
  857. * __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(LL_ADC_RESOLUTION_8B, <threshold_value_8_bits>)
  858. * );
  859. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  860. * @arg @ref LL_ADC_RESOLUTION_12B
  861. * @arg @ref LL_ADC_RESOLUTION_10B
  862. * @arg @ref LL_ADC_RESOLUTION_8B
  863. * @arg @ref LL_ADC_RESOLUTION_6B
  864. * @param __AWD_THRESHOLD__ Value between Min_Data=0x000 and Max_Data=0xFFF
  865. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  866. */
  867. #define __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD__) \
  868. ((__AWD_THRESHOLD__) << ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  869. /**
  870. * @brief Helper macro to get the value of ADC analog watchdog threshold high
  871. * or low in function of ADC resolution, when ADC resolution is
  872. * different of 12 bits.
  873. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  874. * Example, with a ADC resolution of 8 bits, to get the value of
  875. * analog watchdog threshold high (on 8 bits):
  876. * < threshold_value_6_bits > = __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION
  877. * (LL_ADC_RESOLUTION_8B,
  878. * LL_ADC_GetAnalogWDThresholds(<ADCx param>, LL_ADC_AWD_THRESHOLD_HIGH)
  879. * );
  880. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  881. * @arg @ref LL_ADC_RESOLUTION_12B
  882. * @arg @ref LL_ADC_RESOLUTION_10B
  883. * @arg @ref LL_ADC_RESOLUTION_8B
  884. * @arg @ref LL_ADC_RESOLUTION_6B
  885. * @param __AWD_THRESHOLD_12_BITS__ Value between Min_Data=0x000 and Max_Data=0xFFF
  886. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  887. */
  888. #define __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD_12_BITS__) \
  889. ((__AWD_THRESHOLD_12_BITS__) >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  890. /**
  891. * @brief Helper macro to get the ADC analog watchdog threshold high
  892. * or low from raw value containing both thresholds concatenated.
  893. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  894. * Example, to get analog watchdog threshold high from the register raw value:
  895. * __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(LL_ADC_AWD_THRESHOLD_HIGH, <raw_value_with_both_thresholds>);
  896. * @param __AWD_THRESHOLD_TYPE__ This parameter can be one of the following values:
  897. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  898. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  899. * @param __AWD_THRESHOLDS__ Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  900. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  901. */
  902. #define __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(__AWD_THRESHOLD_TYPE__, __AWD_THRESHOLDS__) \
  903. (((__AWD_THRESHOLD_TYPE__) == LL_ADC_AWD_THRESHOLD_LOW) \
  904. ? ( \
  905. (__AWD_THRESHOLDS__) & LL_ADC_AWD_THRESHOLD_LOW \
  906. ) \
  907. : \
  908. ( \
  909. ((__AWD_THRESHOLDS__) >> ADC_TR_HT_BITOFFSET_POS) & LL_ADC_AWD_THRESHOLD_LOW \
  910. ) \
  911. )
  912. /**
  913. * @brief Helper macro to select the ADC common instance
  914. * to which is belonging the selected ADC instance.
  915. * @note ADC common register instance can be used for:
  916. * - Set parameters common to several ADC instances
  917. * - Multimode (for devices with several ADC instances)
  918. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  919. * @param __ADCx__ ADC instance
  920. * @retval ADC common register instance
  921. */
  922. #define __LL_ADC_COMMON_INSTANCE(__ADCx__) \
  923. (ADC1_COMMON)
  924. /**
  925. * @brief Helper macro to check if all ADC instances sharing the same
  926. * ADC common instance are disabled.
  927. * @note This check is required by functions with setting conditioned to
  928. * ADC state:
  929. * All ADC instances of the ADC common group must be disabled.
  930. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  931. * @note On devices with only 1 ADC common instance, parameter of this macro
  932. * is useless and can be ignored (parameter kept for compatibility
  933. * with devices featuring several ADC common instances).
  934. * @param __ADCXY_COMMON__ ADC common instance
  935. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  936. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  937. * are disabled.
  938. * Value "1" if at least one ADC instance sharing the same ADC common instance
  939. * is enabled.
  940. */
  941. #define __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  942. LL_ADC_IsEnabled(ADC1)
  943. /**
  944. * @brief Helper macro to define the ADC conversion data full-scale digital
  945. * value corresponding to the selected ADC resolution.
  946. * @note ADC conversion data full-scale corresponds to voltage range
  947. * determined by analog voltage references Vref+ and Vref-
  948. * (refer to reference manual).
  949. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  950. * @arg @ref LL_ADC_RESOLUTION_12B
  951. * @arg @ref LL_ADC_RESOLUTION_10B
  952. * @arg @ref LL_ADC_RESOLUTION_8B
  953. * @arg @ref LL_ADC_RESOLUTION_6B
  954. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  955. */
  956. #define __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  957. (0xFFFU >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U)))
  958. /**
  959. * @brief Helper macro to convert the ADC conversion data from
  960. * a resolution to another resolution.
  961. * @param __DATA__ ADC conversion data to be converted
  962. * @param __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted
  963. * This parameter can be one of the following values:
  964. * @arg @ref LL_ADC_RESOLUTION_12B
  965. * @arg @ref LL_ADC_RESOLUTION_10B
  966. * @arg @ref LL_ADC_RESOLUTION_8B
  967. * @arg @ref LL_ADC_RESOLUTION_6B
  968. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  969. * This parameter can be one of the following values:
  970. * @arg @ref LL_ADC_RESOLUTION_12B
  971. * @arg @ref LL_ADC_RESOLUTION_10B
  972. * @arg @ref LL_ADC_RESOLUTION_8B
  973. * @arg @ref LL_ADC_RESOLUTION_6B
  974. * @retval ADC conversion data to the requested resolution
  975. */
  976. #define __LL_ADC_CONVERT_DATA_RESOLUTION(__DATA__, __ADC_RESOLUTION_CURRENT__, __ADC_RESOLUTION_TARGET__) \
  977. (((__DATA__) \
  978. << ((__ADC_RESOLUTION_CURRENT__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U))) \
  979. >> ((__ADC_RESOLUTION_TARGET__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U)) \
  980. )
  981. /**
  982. * @brief Helper macro to calculate the voltage (unit: mVolt)
  983. * corresponding to a ADC conversion data (unit: digital value).
  984. * @note Analog reference voltage (Vref+) must be either known from
  985. * user board environment or can be calculated using ADC measurement
  986. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  987. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  988. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  989. * (unit: digital value).
  990. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  991. * @arg @ref LL_ADC_RESOLUTION_12B
  992. * @arg @ref LL_ADC_RESOLUTION_10B
  993. * @arg @ref LL_ADC_RESOLUTION_8B
  994. * @arg @ref LL_ADC_RESOLUTION_6B
  995. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  996. */
  997. #define __LL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,__ADC_DATA__,__ADC_RESOLUTION__) \
  998. ((__ADC_DATA__) * (__VREFANALOG_VOLTAGE__)/ __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__))
  999. /**
  1000. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1001. * (unit: mVolt) from ADC conversion data of internal voltage
  1002. * reference VrefInt.
  1003. * @note Computation is using VrefInt calibration value
  1004. * stored in system memory for each device during production.
  1005. * @note This voltage depends on user board environment: voltage level
  1006. * connected to pin Vref+.
  1007. * On devices with small package, the pin Vref+ is not present
  1008. * and internally bonded to pin Vdda.
  1009. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1010. * of internal voltage reference VrefInt (unit: digital value).
  1011. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1012. * @arg @ref LL_ADC_RESOLUTION_12B
  1013. * @arg @ref LL_ADC_RESOLUTION_10B
  1014. * @arg @ref LL_ADC_RESOLUTION_8B
  1015. * @arg @ref LL_ADC_RESOLUTION_6B
  1016. * @retval Analog reference voltage (unit: mV)
  1017. */
  1018. #define __LL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,__ADC_RESOLUTION__) \
  1019. (4095*( VREFINT_CAL_VREF)/ __LL_ADC_CONVERT_DATA_RESOLUTION((__VREFINT_ADC_DATA__),(__ADC_RESOLUTION__),LL_ADC_RESOLUTION_12B))
  1020. /**
  1021. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1022. * from ADC conversion data of internal temperature sensor.
  1023. * @note Computation is using temperature sensor calibration values
  1024. * stored in system memory for each device during production.
  1025. * @note Calculation formula:
  1026. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1027. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1028. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1029. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1030. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1031. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1032. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1033. * TEMP_DEGC_CAL1 (calibrated in factory)
  1034. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1035. * TEMP_DEGC_CAL2 (calibrated in factory)
  1036. * Caution: Calculation relevancy under reserve that calibration
  1037. * parameters are correct (address and data).
  1038. * To calculate temperature using temperature sensor
  1039. * datasheet typical values (generic values less, therefore
  1040. * less accurate than calibrated values),
  1041. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1042. * @note As calculation input, the analog reference voltage (Vref+) must be
  1043. * defined as it impacts the ADC LSB equivalent voltage.
  1044. * @note Analog reference voltage (Vref+) must be either known from
  1045. * user board environment or can be calculated using ADC measurement
  1046. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1047. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1048. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1049. * temperature sensor (unit: digital value).
  1050. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1051. * sensor voltage has been measured.
  1052. * This parameter can be one of the following values:
  1053. * @arg @ref LL_ADC_RESOLUTION_12B
  1054. * @arg @ref LL_ADC_RESOLUTION_10B
  1055. * @arg @ref LL_ADC_RESOLUTION_8B
  1056. * @arg @ref LL_ADC_RESOLUTION_6B
  1057. * @retval Temperature (unit: degree Celsius)
  1058. */
  1059. #define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1060. __TEMPSENSOR_ADC_DATA__,\
  1061. __ADC_RESOLUTION__) \
  1062. (((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__), \
  1063. (__ADC_RESOLUTION__), \
  1064. LL_ADC_RESOLUTION_12B) \
  1065. * (__VREFANALOG_VOLTAGE__)) \
  1066. / TEMPSENSOR_CAL_VREFANALOG) \
  1067. - (int32_t) *TEMPSENSOR_CAL1_ADDR) \
  1068. ) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP) \
  1069. ) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \
  1070. ) + TEMPSENSOR_CAL1_TEMP \
  1071. )
  1072. /**
  1073. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1074. * from ADC conversion data of internal temperature sensor.
  1075. * @note Computation is using temperature sensor typical values
  1076. * (refer to device datasheet).
  1077. * @note Calculation formula:
  1078. * Temperature = (TS_ADC_DATA * Conversion_uV-TS_TYP_CALx_VOLT(uV) )
  1079. * / Avg_Slope + CALx_TEMP
  1080. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1081. * (unit: digital value)
  1082. * Avg_Slope = temperature sensor slope
  1083. * (unit: uV/Degree Celsius)
  1084. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1085. * temperature CALx_TEMP (unit: mV)
  1086. * Caution: Calculation relevancy under reserve the temperature sensor
  1087. * of the current device has characteristics in line with
  1088. * datasheet typical values.
  1089. * If temperature sensor calibration values are available on
  1090. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1091. * temperature calculation will be more accurate using
  1092. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1093. * @note As calculation input, the analog reference voltage (Vref+) must be
  1094. * defined as it impacts the ADC LSB equivalent voltage.
  1095. * @note Analog reference voltage (Vref+) must be either known from
  1096. * user board environment or can be calculated using ADC measurement
  1097. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1098. * @note ADC measurement data must correspond to a resolution of 12bits
  1099. * (full scale digital value 4095). If not the case, the data must be
  1100. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1101. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
  1102. * refer to device datasheet parameter "Avg_Slope".
  1103. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
  1104. * refer to device datasheet parameter "V30" (corresponding to TS_CAL1).
  1105. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
  1106. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1107. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1108. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1109. * This parameter can be one of the following values:
  1110. * @arg @ref LL_ADC_RESOLUTION_12B
  1111. * @arg @ref LL_ADC_RESOLUTION_10B
  1112. * @arg @ref LL_ADC_RESOLUTION_8B
  1113. * @arg @ref LL_ADC_RESOLUTION_6B
  1114. * @retval Temperature (unit: degree Celsius)
  1115. */
  1116. #define __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1117. __TEMPSENSOR_TYP_CALX_V__,\
  1118. __TEMPSENSOR_CALX_TEMP__,\
  1119. __VREFANALOG_VOLTAGE__,\
  1120. __TEMPSENSOR_ADC_DATA__,\
  1121. __ADC_RESOLUTION__) \
  1122. (((( (int32_t)((((__TEMPSENSOR_ADC_DATA__) * (__VREFANALOG_VOLTAGE__)) \
  1123. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)) \
  1124. * 1000)- (int32_t)(((__TEMPSENSOR_TYP_CALX_V__)) \
  1125. * 1000))) / (__TEMPSENSOR_TYP_AVGSLOPE__) \
  1126. ) + (__TEMPSENSOR_CALX_TEMP__) \
  1127. )
  1128. /**
  1129. * @}
  1130. */
  1131. /** @defgroup ADC_LL_EF_Configuration_ADC_Common Configuration of ADC hierarchical scope: common to several ADC instances
  1132. * @{
  1133. */
  1134. /**
  1135. * @brief Set parameter common to several ADC: measurement path to internal
  1136. * channels (VrefInt, temperature sensor, ...).
  1137. * @note One or several values can be selected.
  1138. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1139. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1140. * @note Stabilization time of measurement path to internal channel:
  1141. * After enabling internal paths, before starting ADC conversion,
  1142. * a delay is required for internal voltage reference and
  1143. * temperature sensor stabilization time.
  1144. * Refer to device datasheet.
  1145. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1146. * Refer to literal @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US.
  1147. * @note ADC internal channel sampling time constraint:
  1148. * For ADC conversion of internal channels,
  1149. * a sampling time minimum value is required.
  1150. * Refer to device datasheet.
  1151. * @note Setting of this feature is conditioned to ADC state:
  1152. * All ADC instances of the ADC common group must be disabled.
  1153. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1154. * ADC instance or by using helper macro helper macro
  1155. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1156. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalCh\n
  1157. * CCR TSEN LL_ADC_SetCommonPathInternalCh
  1158. * @param ADCxy_COMMON ADC common instance
  1159. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1160. * @param PathInternal This parameter can be a combination of the following values:
  1161. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1162. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1163. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1164. * @retval None
  1165. */
  1166. __STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1167. {
  1168. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN, PathInternal);
  1169. }
  1170. /**
  1171. * @brief Get parameter common to several ADC: measurement path to internal
  1172. * channels (VrefInt, temperature sensor, ...).
  1173. * @note One or several values can be selected.
  1174. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1175. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1176. * @rmtoll CCR VREFEN LL_ADC_GetCommonPathInternalCh\n
  1177. * CCR TSEN LL_ADC_GetCommonPathInternalCh
  1178. * @param ADCxy_COMMON ADC common instance
  1179. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1180. * @retval Returned value can be a combination of the following values:
  1181. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1182. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1183. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1184. */
  1185. __STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
  1186. {
  1187. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN));
  1188. }
  1189. /**
  1190. * @}
  1191. */
  1192. /** @defgroup ADC_LL_EF_Configuration_ADC_Instance Configuration of ADC hierarchical scope: ADC instance
  1193. * @{
  1194. */
  1195. /**
  1196. * @brief Set ADC instance clock source and prescaler.
  1197. * @note Setting of this feature is conditioned to ADC state:
  1198. * ADC must be disabled.
  1199. * @rmtoll CFGR2 CKMODE LL_ADC_SetClock
  1200. * @param ADCx ADC instance
  1201. * @param ClockSource This parameter can be one of the following values:
  1202. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1
  1203. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1204. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1205. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV8
  1206. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV16
  1207. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV32
  1208. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV64
  1209. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV1
  1210. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV2
  1211. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV4
  1212. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV8
  1213. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV16
  1214. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV32
  1215. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV64
  1216. * @retval None
  1217. */
  1218. __STATIC_INLINE void LL_ADC_SetClock(ADC_TypeDef *ADCx, uint32_t ClockSource)
  1219. {
  1220. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_CKMODE, ClockSource);
  1221. }
  1222. /**
  1223. * @brief Get ADC instance clock source and prescaler.
  1224. * @rmtoll CFGR2 CKMODE LL_ADC_GetClock
  1225. * @param ADCx ADC instance
  1226. * @retval Returned value can be one of the following values:
  1227. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1
  1228. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1229. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1230. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV8
  1231. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV16
  1232. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV32
  1233. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV64
  1234. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV1
  1235. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV2
  1236. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV4
  1237. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV8
  1238. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV16
  1239. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV32
  1240. * @arg @ref LL_ADC_CLOCK_ASYNC_HSI_DIV64
  1241. */
  1242. __STATIC_INLINE uint32_t LL_ADC_GetClock(ADC_TypeDef *ADCx)
  1243. {
  1244. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_CKMODE));
  1245. }
  1246. /**
  1247. * @brief Set ADC resolution.
  1248. * Refer to reference manual for alignments formats
  1249. * dependencies to ADC resolutions.
  1250. * @note Setting of this feature is conditioned to ADC state:
  1251. * ADC must be disabled or enabled without conversion on going
  1252. * on group regular.
  1253. * @rmtoll CFGR1 RES LL_ADC_SetResolution
  1254. * @param ADCx ADC instance
  1255. * @param Resolution This parameter can be one of the following values:
  1256. * @arg @ref LL_ADC_RESOLUTION_12B
  1257. * @arg @ref LL_ADC_RESOLUTION_10B
  1258. * @arg @ref LL_ADC_RESOLUTION_8B
  1259. * @arg @ref LL_ADC_RESOLUTION_6B
  1260. * @retval None
  1261. */
  1262. __STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)
  1263. {
  1264. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_RESSEL, Resolution);
  1265. }
  1266. /**
  1267. * @brief Get ADC resolution.
  1268. * Refer to reference manual for alignments formats
  1269. * dependencies to ADC resolutions.
  1270. * @rmtoll CFGR1 RES LL_ADC_GetResolution
  1271. * @param ADCx ADC instance
  1272. * @retval Returned value can be one of the following values:
  1273. * @arg @ref LL_ADC_RESOLUTION_12B
  1274. * @arg @ref LL_ADC_RESOLUTION_10B
  1275. * @arg @ref LL_ADC_RESOLUTION_8B
  1276. * @arg @ref LL_ADC_RESOLUTION_6B
  1277. */
  1278. __STATIC_INLINE uint32_t LL_ADC_GetResolution(ADC_TypeDef *ADCx)
  1279. {
  1280. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_RESSEL));
  1281. }
  1282. /**
  1283. * @brief Set ADC conversion data alignment.
  1284. * @note Refer to reference manual for alignments formats
  1285. * dependencies to ADC resolutions.
  1286. * @note Setting of this feature is conditioned to ADC state:
  1287. * ADC must be disabled or enabled without conversion on going
  1288. * on group regular.
  1289. * @rmtoll CFGR1 ALIGN LL_ADC_SetDataAlignment
  1290. * @param ADCx ADC instance
  1291. * @param DataAlignment This parameter can be one of the following values:
  1292. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  1293. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  1294. * @retval None
  1295. */
  1296. __STATIC_INLINE void LL_ADC_SetDataAlignment(ADC_TypeDef *ADCx, uint32_t DataAlignment)
  1297. {
  1298. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_ALIGN, DataAlignment);
  1299. }
  1300. /**
  1301. * @brief Get ADC conversion data alignment.
  1302. * @note Refer to reference manual for alignments formats
  1303. * dependencies to ADC resolutions.
  1304. * @rmtoll CFGR1 ALIGN LL_ADC_GetDataAlignment
  1305. * @param ADCx ADC instance
  1306. * @retval Returned value can be one of the following values:
  1307. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  1308. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  1309. */
  1310. __STATIC_INLINE uint32_t LL_ADC_GetDataAlignment(ADC_TypeDef *ADCx)
  1311. {
  1312. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_ALIGN));
  1313. }
  1314. /**
  1315. * @brief Set ADC low power mode.
  1316. * @note With ADC low power mode "auto wait", the ADC conversion data read
  1317. * is corresponding to previous ADC conversion start, independently
  1318. * of delay during which ADC was idle.
  1319. * Therefore, the ADC conversion data may be outdated: does not
  1320. * correspond to the current voltage level on the selected
  1321. * ADC channel.
  1322. * @note Setting of this feature is conditioned to ADC state:
  1323. * ADC must be disabled or enabled without conversion on going
  1324. * on group regular.
  1325. * @rmtoll CFGR1 WAIT LL_ADC_SetLowPowerMode
  1326. * @param ADCx ADC instance
  1327. * @param LowPowerMode This parameter can be one of the following values:
  1328. * @arg @ref LL_ADC_LP_MODE_NONE
  1329. * @arg @ref LL_ADC_LP_AUTOWAIT
  1330. * @retval None
  1331. */
  1332. __STATIC_INLINE void LL_ADC_SetLowPowerMode(ADC_TypeDef *ADCx, uint32_t LowPowerMode)
  1333. {
  1334. MODIFY_REG(ADCx->CFGR1, (ADC_CFGR1_WAIT), LowPowerMode);
  1335. }
  1336. /**
  1337. * @brief Get ADC low power mode:
  1338. * @note With ADC low power mode "auto wait", the ADC conversion data read
  1339. * is corresponding to previous ADC conversion start, independently
  1340. * of delay during which ADC was idle.
  1341. * Therefore, the ADC conversion data may be outdated: does not
  1342. * correspond to the current voltage level on the selected
  1343. * ADC channel.
  1344. * @rmtoll CFGR1 WAIT LL_ADC_GetLowPowerMode
  1345. * @param ADCx ADC instance
  1346. * @retval Returned value can be one of the following values:
  1347. * @arg @ref LL_ADC_LP_MODE_NONE
  1348. * @arg @ref LL_ADC_LP_AUTOWAIT
  1349. */
  1350. __STATIC_INLINE uint32_t LL_ADC_GetLowPowerMode(ADC_TypeDef *ADCx)
  1351. {
  1352. return (uint32_t)(READ_BIT(ADCx->CFGR1, (ADC_CFGR1_WAIT )));
  1353. }
  1354. /**
  1355. * @brief Set sampling time common to a group of channels.
  1356. * @note Unit: ADC clock cycles.
  1357. * @note In case of ADC conversion of internal channel (VrefInt,
  1358. * temperature sensor, ...), a sampling time minimum value
  1359. * is required.
  1360. * Refer to device datasheet.
  1361. * @rmtoll SMPR SMP LL_ADC_SetSamplingTimeCommonChannels
  1362. * @param ADCx ADC instance
  1363. * @param SamplingTime This parameter can be one of the following values:
  1364. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  1365. * @arg @ref LL_ADC_SAMPLINGTIME_5CYCLES_5
  1366. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  1367. * @arg @ref LL_ADC_SAMPLINGTIME_13CYCLES_5
  1368. * @arg @ref LL_ADC_SAMPLINGTIME_28CYCLES_5
  1369. * @arg @ref LL_ADC_SAMPLINGTIME_41CYCLES_5
  1370. * @arg @ref LL_ADC_SAMPLINGTIME_71CYCLES_5
  1371. * @arg @ref LL_ADC_SAMPLINGTIME_239CYCLES_5
  1372. * @retval None
  1373. */
  1374. __STATIC_INLINE void LL_ADC_SetSamplingTimeCommonChannels(ADC_TypeDef *ADCx, uint32_t SamplingTime)
  1375. {
  1376. MODIFY_REG(ADCx->SMPR, ADC_SMPR_SMP, SamplingTime);
  1377. }
  1378. /**
  1379. * @brief Get sampling time common to a group of channels.
  1380. * @note Unit: ADC clock cycles.
  1381. * @rmtoll SMPR SMP LL_ADC_GetSamplingTimeCommonChannels
  1382. * @param ADCx ADC instance
  1383. * @retval Returned value can be one of the following values:
  1384. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  1385. * @arg @ref LL_ADC_SAMPLINGTIME_5CYCLES_5
  1386. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  1387. * @arg @ref LL_ADC_SAMPLINGTIME_13CYCLES_5
  1388. * @arg @ref LL_ADC_SAMPLINGTIME_28CYCLES_5
  1389. * @arg @ref LL_ADC_SAMPLINGTIME_41CYCLES_5
  1390. * @arg @ref LL_ADC_SAMPLINGTIME_71CYCLES_5
  1391. * @arg @ref LL_ADC_SAMPLINGTIME_239CYCLES_5
  1392. */
  1393. __STATIC_INLINE uint32_t LL_ADC_GetSamplingTimeCommonChannels(ADC_TypeDef *ADCx)
  1394. {
  1395. return (uint32_t)(READ_BIT(ADCx->SMPR, ADC_SMPR_SMP));
  1396. }
  1397. /**
  1398. * @}
  1399. */
  1400. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Regular Configuration of ADC hierarchical scope: group regular
  1401. * @{
  1402. */
  1403. /**
  1404. * @brief Set ADC group regular conversion trigger source:
  1405. * internal (SW start) or from external IP (timer event,
  1406. * external interrupt line).
  1407. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_SetTriggerSource\n
  1408. * CFGR1 EXTEN LL_ADC_REG_SetTriggerSource
  1409. * @param ADCx ADC instance
  1410. * @param TriggerSource This parameter can be one of the following values:
  1411. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  1412. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO
  1413. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH4
  1414. * @retval None
  1415. */
  1416. __STATIC_INLINE void LL_ADC_REG_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  1417. {
  1418. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN | ADC_CFGR1_EXTSEL, TriggerSource);
  1419. }
  1420. /**
  1421. * @brief Get ADC group regular conversion trigger source:
  1422. * internal (SW start) or from external IP (timer event,
  1423. * external interrupt line).
  1424. * @note To determine whether group regular trigger source is
  1425. * internal (SW start) or external, without detail
  1426. * of which peripheral is selected as external trigger,
  1427. * (equivalent to
  1428. * "if(LL_ADC_REG_GetTriggerSource(ADC1) == LL_ADC_REG_TRIG_SOFTWARE)")
  1429. * use function @ref LL_ADC_REG_IsTriggerSourceSWStart.
  1430. * @note Availability of parameters of trigger sources from timer
  1431. * depends on timers availability on the selected device.
  1432. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_GetTriggerSource\n
  1433. * CFGR1 EXTEN LL_ADC_REG_GetTriggerSource
  1434. * @param ADCx ADC instance
  1435. * @retval Returned value can be one of the following values:
  1436. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  1437. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO
  1438. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH4
  1439. */
  1440. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerSource(ADC_TypeDef *ADCx)
  1441. {
  1442. register uint32_t TriggerSource = READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTSEL | ADC_CFGR1_EXTEN);
  1443. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  1444. /* corresponding to ADC_CFGR1_EXTEN {0; 1; 2; 3}. */
  1445. register uint32_t ShiftExten = ((TriggerSource & ADC_CFGR1_EXTEN) >> (ADC_REG_TRIG_EXTEN_BITOFFSET_POS - 2U));
  1446. /* Set bitfield corresponding to ADC_CFGR1_EXTEN and ADC_CFGR1_EXTSEL */
  1447. /* to match with triggers literals definition. */
  1448. return ((TriggerSource
  1449. & (ADC_REG_TRIG_SOURCE_MASK >> ShiftExten) & ADC_CFGR1_EXTSEL)
  1450. | ((ADC_REG_TRIG_EDGE_MASK >> ShiftExten) & ADC_CFGR1_EXTEN)
  1451. );
  1452. }
  1453. /**
  1454. * @brief Get ADC group regular conversion trigger source internal (SW start)
  1455. * or external.
  1456. * @note In case of group regular trigger source set to external trigger,
  1457. * to determine which peripheral is selected as external trigger,
  1458. * use function @ref LL_ADC_REG_GetTriggerSource().
  1459. * @rmtoll CFGR1 EXTEN LL_ADC_REG_IsTriggerSourceSWStart
  1460. * @param ADCx ADC instance
  1461. * @retval Value "0" if trigger source external trigger
  1462. * Value "1" if trigger source SW start.
  1463. */
  1464. __STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
  1465. {
  1466. return (READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN) == (LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN));
  1467. }
  1468. /**
  1469. * @brief Set ADC group regular conversion trigger polarity.
  1470. * @note Applicable only for trigger source set to external trigger.
  1471. * @rmtoll CFGR1 EXTEN LL_ADC_REG_SetTriggerEdge
  1472. * @param ADCx ADC instance
  1473. * @param ExternalTriggerEdge This parameter can be one of the following values:
  1474. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  1475. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  1476. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  1477. * @retval None
  1478. */
  1479. __STATIC_INLINE void LL_ADC_REG_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  1480. {
  1481. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN, ExternalTriggerEdge);
  1482. }
  1483. /**
  1484. * @brief Get ADC group regular conversion trigger polarity.
  1485. * @note Applicable only for trigger source set to external trigger.
  1486. * @rmtoll CFGR1 EXTEN LL_ADC_REG_GetTriggerEdge
  1487. * @param ADCx ADC instance
  1488. * @retval Returned value can be one of the following values:
  1489. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  1490. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  1491. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  1492. */
  1493. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerEdge(ADC_TypeDef *ADCx)
  1494. {
  1495. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN));
  1496. }
  1497. /**
  1498. * @brief Set ADC group regular sequencer scan direction.
  1499. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_SetSequencerScanDirection
  1500. * @param ADCx ADC instance
  1501. * @param ScanDirection This parameter can be one of the following values:
  1502. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  1503. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  1504. * @retval None
  1505. */
  1506. __STATIC_INLINE void LL_ADC_REG_SetSequencerScanDirection(ADC_TypeDef *ADCx, uint32_t ScanDirection)
  1507. {
  1508. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_SCANDIR, ScanDirection);
  1509. }
  1510. /**
  1511. * @brief Get ADC group regular sequencer scan direction.
  1512. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_GetSequencerScanDirection
  1513. * @param ADCx ADC instance
  1514. * @retval Returned value can be one of the following values:
  1515. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  1516. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  1517. */
  1518. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerScanDirection(ADC_TypeDef *ADCx)
  1519. {
  1520. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_SCANDIR));
  1521. }
  1522. /**
  1523. * @brief Set ADC group regular sequencer discontinuous mode:
  1524. * sequence subdivided and scan conversions interrupted every selected
  1525. * number of ranks.
  1526. * @rmtoll CFGR1 DISCEN LL_ADC_REG_SetSequencerDiscont\n
  1527. * @param ADCx ADC instance
  1528. * @param SeqDiscont This parameter can be one of the following values:
  1529. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  1530. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  1531. * @retval None
  1532. */
  1533. __STATIC_INLINE void LL_ADC_REG_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  1534. {
  1535. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_DISCEN, SeqDiscont);
  1536. }
  1537. /**
  1538. * @brief Get ADC group regular sequencer discontinuous mode:
  1539. * sequence subdivided and scan conversions interrupted every selected
  1540. * number of ranks.
  1541. * @rmtoll CFGR1 DISCEN LL_ADC_REG_GetSequencerDiscont\n
  1542. * @param ADCx ADC instance
  1543. * @retval Returned value can be one of the following values:
  1544. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  1545. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  1546. */
  1547. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerDiscont(ADC_TypeDef *ADCx)
  1548. {
  1549. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_DISCEN));
  1550. }
  1551. /**
  1552. * @brief Set ADC group regular sequence: channel on rank corresponding to
  1553. * channel number.
  1554. * @note One or several values can be selected.
  1555. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_8 | ...)
  1556. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChannels\n
  1557. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChannels\n
  1558. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChannels\n
  1559. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChannels\n
  1560. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChannels\n
  1561. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChannels\n
  1562. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChannels\n
  1563. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChannels\n
  1564. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChannels\n
  1565. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChannels\n
  1566. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChannels
  1567. * @param ADCx ADC instance
  1568. * @param Channel This parameter can be a combination of the following values:
  1569. * @arg @ref LL_ADC_CHANNEL_0
  1570. * @arg @ref LL_ADC_CHANNEL_1
  1571. * @arg @ref LL_ADC_CHANNEL_2
  1572. * @arg @ref LL_ADC_CHANNEL_3
  1573. * @arg @ref LL_ADC_CHANNEL_4
  1574. * @arg @ref LL_ADC_CHANNEL_5
  1575. * @arg @ref LL_ADC_CHANNEL_6
  1576. * @arg @ref LL_ADC_CHANNEL_7
  1577. * @arg @ref LL_ADC_CHANNEL_8
  1578. * @arg @ref LL_ADC_CHANNEL_9
  1579. * @arg @ref LL_ADC_CHANNEL_10
  1580. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1581. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1582. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  1583. * @retval None
  1584. */
  1585. __STATIC_INLINE void LL_ADC_REG_SetSequencerChannels(ADC_TypeDef *ADCx, uint32_t Channel)
  1586. {
  1587. /* Parameter "Channel" is used with masks because containing */
  1588. /* other bits reserved for other purpose. */
  1589. WRITE_REG(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  1590. }
  1591. /**
  1592. * @brief Add channel to ADC group regular sequence: channel on rank corresponding to
  1593. * channel number.
  1594. * @note This function performs:
  1595. * - Channels ordering into each rank of scan sequence:
  1596. * rank of each channel is fixed by channel HW number
  1597. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  1598. * - Set channels selected by adding them to the current sequencer
  1599. * configuration.
  1600. * @note One or several values can be selected.
  1601. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_8 | ...)
  1602. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChAdd\n
  1603. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChAdd\n
  1604. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChAdd\n
  1605. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChAdd\n
  1606. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChAdd\n
  1607. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChAdd\n
  1608. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChAdd\n
  1609. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChAdd\n
  1610. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChAdd\n
  1611. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChAdd\n
  1612. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChAdd
  1613. * @param ADCx ADC instance
  1614. * @param Channel This parameter can be a combination of the following values:
  1615. * @arg @ref LL_ADC_CHANNEL_0
  1616. * @arg @ref LL_ADC_CHANNEL_1
  1617. * @arg @ref LL_ADC_CHANNEL_2
  1618. * @arg @ref LL_ADC_CHANNEL_3
  1619. * @arg @ref LL_ADC_CHANNEL_4
  1620. * @arg @ref LL_ADC_CHANNEL_5
  1621. * @arg @ref LL_ADC_CHANNEL_6
  1622. * @arg @ref LL_ADC_CHANNEL_7
  1623. * @arg @ref LL_ADC_CHANNEL_8
  1624. * @arg @ref LL_ADC_CHANNEL_9
  1625. * @arg @ref LL_ADC_CHANNEL_10
  1626. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1627. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1628. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  1629. * @retval None
  1630. */
  1631. __STATIC_INLINE void LL_ADC_REG_SetSequencerChAdd(ADC_TypeDef *ADCx, uint32_t Channel)
  1632. {
  1633. /* Parameter "Channel" is used with masks because containing */
  1634. /* other bits reserved for other purpose. */
  1635. SET_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  1636. }
  1637. /**
  1638. * @brief Remove channel to ADC group regular sequence: channel on rank corresponding to
  1639. * channel number.
  1640. * @note One or several values can be selected.
  1641. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_8 | ...)
  1642. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChRem\n
  1643. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChRem\n
  1644. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChRem\n
  1645. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChRem\n
  1646. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChRem\n
  1647. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChRem\n
  1648. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChRem\n
  1649. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChRem\n
  1650. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChRem\n
  1651. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChRem\n
  1652. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChRem
  1653. * @param ADCx ADC instance
  1654. * @param Channel This parameter can be a combination of the following values:
  1655. * @arg @ref LL_ADC_CHANNEL_0
  1656. * @arg @ref LL_ADC_CHANNEL_1
  1657. * @arg @ref LL_ADC_CHANNEL_2
  1658. * @arg @ref LL_ADC_CHANNEL_3
  1659. * @arg @ref LL_ADC_CHANNEL_4
  1660. * @arg @ref LL_ADC_CHANNEL_5
  1661. * @arg @ref LL_ADC_CHANNEL_6
  1662. * @arg @ref LL_ADC_CHANNEL_7
  1663. * @arg @ref LL_ADC_CHANNEL_8
  1664. * @arg @ref LL_ADC_CHANNEL_9
  1665. * @arg @ref LL_ADC_CHANNEL_10
  1666. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1667. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1668. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  1669. * @retval None
  1670. */
  1671. __STATIC_INLINE void LL_ADC_REG_SetSequencerChRem(ADC_TypeDef *ADCx, uint32_t Channel)
  1672. {
  1673. /* Parameter "Channel" is used with masks because containing */
  1674. /* other bits reserved for other purpose. */
  1675. CLEAR_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  1676. }
  1677. /**
  1678. * @brief Get ADC group regular sequence: channel on rank corresponding to
  1679. * channel number.
  1680. * @note One or several values can be retrieved.
  1681. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_8 | ...)
  1682. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_GetSequencerChannels\n
  1683. * CHSELR CHSEL1 LL_ADC_REG_GetSequencerChannels\n
  1684. * CHSELR CHSEL2 LL_ADC_REG_GetSequencerChannels\n
  1685. * CHSELR CHSEL3 LL_ADC_REG_GetSequencerChannels\n
  1686. * CHSELR CHSEL4 LL_ADC_REG_GetSequencerChannels\n
  1687. * CHSELR CHSEL5 LL_ADC_REG_GetSequencerChannels\n
  1688. * CHSELR CHSEL6 LL_ADC_REG_GetSequencerChannels\n
  1689. * CHSELR CHSEL7 LL_ADC_REG_GetSequencerChannels\n
  1690. * CHSELR CHSEL8 LL_ADC_REG_GetSequencerChannels\n
  1691. * CHSELR CHSEL9 LL_ADC_REG_GetSequencerChannels\n
  1692. * CHSELR CHSEL10 LL_ADC_REG_GetSequencerChannels
  1693. * @param ADCx ADC instance
  1694. * @retval Returned value can be a combination of the following values:
  1695. * @arg @ref LL_ADC_CHANNEL_0
  1696. * @arg @ref LL_ADC_CHANNEL_1
  1697. * @arg @ref LL_ADC_CHANNEL_2
  1698. * @arg @ref LL_ADC_CHANNEL_3
  1699. * @arg @ref LL_ADC_CHANNEL_4
  1700. * @arg @ref LL_ADC_CHANNEL_5
  1701. * @arg @ref LL_ADC_CHANNEL_6
  1702. * @arg @ref LL_ADC_CHANNEL_7
  1703. * @arg @ref LL_ADC_CHANNEL_8
  1704. * @arg @ref LL_ADC_CHANNEL_9
  1705. * @arg @ref LL_ADC_CHANNEL_10
  1706. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1707. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1708. * @arg @ref LL_ADC_CHANNEL_1_3VCCA
  1709. */
  1710. #if defined(ADC_CHSELR_CHSEL10)
  1711. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerChannels(ADC_TypeDef *ADCx)
  1712. {
  1713. register uint32_t ChannelsBitfield = READ_BIT(ADCx->CHSELR, ADC_CHSELR_CHSEL);
  1714. return ( (((ChannelsBitfield & ADC_CHSELR_CHSEL0) >> ADC_CHSELR_CHSEL0_BITOFFSET_POS) * LL_ADC_CHANNEL_0)
  1715. | (((ChannelsBitfield & ADC_CHSELR_CHSEL1) >> ADC_CHSELR_CHSEL1_BITOFFSET_POS) * LL_ADC_CHANNEL_1)
  1716. | (((ChannelsBitfield & ADC_CHSELR_CHSEL2) >> ADC_CHSELR_CHSEL2_BITOFFSET_POS) * LL_ADC_CHANNEL_2)
  1717. | (((ChannelsBitfield & ADC_CHSELR_CHSEL3) >> ADC_CHSELR_CHSEL3_BITOFFSET_POS) * LL_ADC_CHANNEL_3)
  1718. | (((ChannelsBitfield & ADC_CHSELR_CHSEL4) >> ADC_CHSELR_CHSEL4_BITOFFSET_POS) * LL_ADC_CHANNEL_4)
  1719. | (((ChannelsBitfield & ADC_CHSELR_CHSEL5) >> ADC_CHSELR_CHSEL5_BITOFFSET_POS) * LL_ADC_CHANNEL_5)
  1720. | (((ChannelsBitfield & ADC_CHSELR_CHSEL6) >> ADC_CHSELR_CHSEL6_BITOFFSET_POS) * LL_ADC_CHANNEL_6)
  1721. | (((ChannelsBitfield & ADC_CHSELR_CHSEL7) >> ADC_CHSELR_CHSEL7_BITOFFSET_POS) * LL_ADC_CHANNEL_7)
  1722. | (((ChannelsBitfield & ADC_CHSELR_CHSEL8) >> ADC_CHSELR_CHSEL8_BITOFFSET_POS) * LL_ADC_CHANNEL_8)
  1723. | (((ChannelsBitfield & ADC_CHSELR_CHSEL9) >> ADC_CHSELR_CHSEL9_BITOFFSET_POS) * LL_ADC_CHANNEL_9)
  1724. | (((ChannelsBitfield & ADC_CHSELR_CHSEL10) >> ADC_CHSELR_CHSEL10_BITOFFSET_POS) * LL_ADC_CHANNEL_10)
  1725. );
  1726. }
  1727. #else
  1728. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerChannels(ADC_TypeDef *ADCx)
  1729. {
  1730. register uint32_t ChannelsBitfield = READ_BIT(ADCx->CHSELR, ADC_CHSELR_CHSEL);
  1731. return ( (((ChannelsBitfield & ADC_CHSELR_CHSEL0) >> ADC_CHSELR_CHSEL0_BITOFFSET_POS) * LL_ADC_CHANNEL_0)
  1732. | (((ChannelsBitfield & ADC_CHSELR_CHSEL1) >> ADC_CHSELR_CHSEL1_BITOFFSET_POS) * LL_ADC_CHANNEL_1)
  1733. | (((ChannelsBitfield & ADC_CHSELR_CHSEL2) >> ADC_CHSELR_CHSEL2_BITOFFSET_POS) * LL_ADC_CHANNEL_2)
  1734. | (((ChannelsBitfield & ADC_CHSELR_CHSEL3) >> ADC_CHSELR_CHSEL3_BITOFFSET_POS) * LL_ADC_CHANNEL_3)
  1735. | (((ChannelsBitfield & ADC_CHSELR_CHSEL4) >> ADC_CHSELR_CHSEL4_BITOFFSET_POS) * LL_ADC_CHANNEL_4)
  1736. | (((ChannelsBitfield & ADC_CHSELR_CHSEL5) >> ADC_CHSELR_CHSEL5_BITOFFSET_POS) * LL_ADC_CHANNEL_5)
  1737. | (((ChannelsBitfield & ADC_CHSELR_CHSEL6) >> ADC_CHSELR_CHSEL6_BITOFFSET_POS) * LL_ADC_CHANNEL_6)
  1738. | (((ChannelsBitfield & ADC_CHSELR_CHSEL7) >> ADC_CHSELR_CHSEL7_BITOFFSET_POS) * LL_ADC_CHANNEL_7)
  1739. | (((ChannelsBitfield & ADC_CHSELR_CHSEL8) >> ADC_CHSELR_CHSEL8_BITOFFSET_POS) * LL_ADC_CHANNEL_8)
  1740. | (((ChannelsBitfield & ADC_CHSELR_CHSEL9) >> ADC_CHSELR_CHSEL9_BITOFFSET_POS) * LL_ADC_CHANNEL_9)
  1741. );
  1742. }
  1743. #endif
  1744. /**
  1745. * @brief Set ADC continuous conversion mode on ADC group regular.
  1746. * @note Description of ADC continuous conversion mode:
  1747. * - single mode: one conversion per trigger
  1748. * - continuous mode: after the first trigger, following
  1749. * conversions launched successively automatically.
  1750. * @rmtoll CFGR1 CONT LL_ADC_REG_SetContinuousMode
  1751. * @param ADCx ADC instance
  1752. * @param Continuous This parameter can be one of the following values:
  1753. * @arg @ref LL_ADC_REG_CONV_SINGLE
  1754. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  1755. * @retval None
  1756. */
  1757. __STATIC_INLINE void LL_ADC_REG_SetContinuousMode(ADC_TypeDef *ADCx, uint32_t Continuous)
  1758. {
  1759. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_CONT, Continuous);
  1760. }
  1761. /**
  1762. * @brief Get ADC continuous conversion mode on ADC group regular.
  1763. * @note Description of ADC continuous conversion mode:
  1764. * - single mode: one conversion per trigger
  1765. * - continuous mode: after the first trigger, following
  1766. * conversions launched successively automatically.
  1767. * @rmtoll CFGR1 CONT LL_ADC_REG_GetContinuousMode
  1768. * @param ADCx ADC instance
  1769. * @retval Returned value can be one of the following values:
  1770. * @arg @ref LL_ADC_REG_CONV_SINGLE
  1771. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  1772. */
  1773. __STATIC_INLINE uint32_t LL_ADC_REG_GetContinuousMode(ADC_TypeDef *ADCx)
  1774. {
  1775. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_CONT));
  1776. }
  1777. /**
  1778. * @brief Set ADC group regular behavior in case of overrun:
  1779. * data preserved or overwritten.
  1780. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_SetOverrun
  1781. * @param ADCx ADC instance
  1782. * @param Overrun This parameter can be one of the following values:
  1783. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  1784. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  1785. * @retval None
  1786. */
  1787. __STATIC_INLINE void LL_ADC_REG_SetOverrun(ADC_TypeDef *ADCx, uint32_t Overrun)
  1788. {
  1789. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_OVRMOD, Overrun);
  1790. }
  1791. /**
  1792. * @brief Get ADC group regular behavior in case of overrun:
  1793. * data preserved or overwritten.
  1794. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_GetOverrun
  1795. * @param ADCx ADC instance
  1796. * @retval Returned value can be one of the following values:
  1797. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  1798. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  1799. */
  1800. __STATIC_INLINE uint32_t LL_ADC_REG_GetOverrun(ADC_TypeDef *ADCx)
  1801. {
  1802. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_OVRMOD));
  1803. }
  1804. /**
  1805. * @}
  1806. */
  1807. /** @defgroup ADC_LL_EF_Configuration_ADC_AnalogWatchdog Configuration of ADC transversal scope: analog watchdog
  1808. * @{
  1809. */
  1810. /**
  1811. * @brief Set ADC analog watchdog monitored channels:
  1812. * a single channel or all channels,
  1813. * on ADC group regular.
  1814. * @note Once monitored channels are selected, analog watchdog
  1815. * is enabled.
  1816. * @note Depending on devices and packages, some channels may not be available.
  1817. * Refer to device datasheet for channels availability.
  1818. * @rmtoll CFGR1 AWDCH LL_ADC_SetAnalogWDMonitChannels\n
  1819. * CFGR1 AWDSGL LL_ADC_SetAnalogWDMonitChannels\n
  1820. * CFGR1 AWDEN LL_ADC_SetAnalogWDMonitChannels
  1821. * @param ADCx ADC instance
  1822. * @param AWDChannelGroup This parameter can be one of the following values:
  1823. * @arg @ref LL_ADC_AWD_DISABLE
  1824. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  1825. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  1826. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  1827. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  1828. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  1829. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  1830. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  1831. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  1832. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  1833. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  1834. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  1835. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  1836. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  1837. * @arg @ref LL_ADC_AWD_CH_1_3VCCA_REG
  1838. * @retval None
  1839. */
  1840. __STATIC_INLINE void LL_ADC_SetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDChannelGroup)
  1841. {
  1842. MODIFY_REG(ADCx->CFGR1,
  1843. (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN),
  1844. (AWDChannelGroup & ADC_AWD_CR_ALL_CHANNEL_MASK));
  1845. }
  1846. /**
  1847. * @brief Get ADC analog watchdog monitored channel.
  1848. * @note Usage of the returned channel number:
  1849. * - To reinject this channel into another function LL_ADC_xxx:
  1850. * the returned channel number is only partly formatted on definition
  1851. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  1852. * with parts of literals LL_ADC_CHANNEL_x or using
  1853. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  1854. * Then the selected literal LL_ADC_CHANNEL_x can be used
  1855. * as parameter for another function.
  1856. * - To get the channel number in decimal format:
  1857. * process the returned value with the helper macro
  1858. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  1859. * Applicable only when the analog watchdog is set to monitor
  1860. * one channel.
  1861. * @note Depending on devices and packages, some channels may not be available.
  1862. * Refer to device datasheet for channels availability.
  1863. * @rmtoll CFGR1 AWDCH LL_ADC_GetAnalogWDMonitChannels\n
  1864. * CFGR1 AWDSGL LL_ADC_GetAnalogWDMonitChannels\n
  1865. * CFGR1 AWDEN LL_ADC_GetAnalogWDMonitChannels
  1866. * @param ADCx ADC instance
  1867. * @retval Returned value can be one of the following values:
  1868. * @arg @ref LL_ADC_AWD_DISABLE
  1869. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  1870. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  1871. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  1872. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  1873. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  1874. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  1875. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  1876. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  1877. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  1878. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  1879. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  1880. */
  1881. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDMonitChannels(ADC_TypeDef *ADCx)
  1882. {
  1883. register uint32_t AWDChannelGroup = READ_BIT(ADCx->CFGR1, (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN));
  1884. /* Note: Set variable according to channel definition including channel ID */
  1885. /* with bitfield. */
  1886. register uint32_t AWDChannelSingle = ((AWDChannelGroup & ADC_CFGR1_AWDSGL) >> ADC_CFGR1_AWDSGL_BITOFFSET_POS);
  1887. register uint32_t AWDChannelBitField = (ADC_CHANNEL_0_BITFIELD << ((AWDChannelGroup & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS));
  1888. return (AWDChannelGroup | (AWDChannelBitField * AWDChannelSingle));
  1889. }
  1890. /**
  1891. * @brief Set ADC analog watchdog thresholds value of both thresholds
  1892. * high and low.
  1893. * @note If value of only one threshold high or low must be set,
  1894. * use function @ref LL_ADC_SetAnalogWDThresholds().
  1895. * @note In case of ADC resolution different of 12 bits,
  1896. * analog watchdog thresholds data require a specific shift.
  1897. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  1898. * @rmtoll TR HT LL_ADC_ConfigAnalogWDThresholds\n
  1899. * TR LT LL_ADC_ConfigAnalogWDThresholds
  1900. * @param ADCx ADC instance
  1901. * @param AWDThresholdHighValue Value between Min_Data=0x000 and Max_Data=0xFFF
  1902. * @param AWDThresholdLowValue Value between Min_Data=0x000 and Max_Data=0xFFF
  1903. * @retval None
  1904. */
  1905. __STATIC_INLINE void LL_ADC_ConfigAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdHighValue, uint32_t AWDThresholdLowValue)
  1906. {
  1907. MODIFY_REG(ADCx->TR,ADC_TR_HT | ADC_TR_LT,(AWDThresholdHighValue << ADC_TR_HT_BITOFFSET_POS) | AWDThresholdLowValue);
  1908. }
  1909. /**
  1910. * @brief Set ADC analog watchdog threshold value of threshold
  1911. * high or low.
  1912. * @note If values of both thresholds high or low must be set,
  1913. * use function @ref LL_ADC_ConfigAnalogWDThresholds().
  1914. * @note In case of ADC resolution different of 12 bits,
  1915. * analog watchdog thresholds data require a specific shift.
  1916. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  1917. * @rmtoll TR HT LL_ADC_SetAnalogWDThresholds\n
  1918. * TR LT LL_ADC_SetAnalogWDThresholds
  1919. * @param ADCx ADC instance
  1920. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  1921. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  1922. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  1923. * @param AWDThresholdValue Value between Min_Data=0x000 and Max_Data=0xFFF
  1924. * @retval None
  1925. */
  1926. __STATIC_INLINE void LL_ADC_SetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdsHighLow, uint32_t AWDThresholdValue)
  1927. {
  1928. /* Parameter "AWDThresholdsHighLow" is used with mask "0x00000010" */
  1929. /* to be equivalent to "POSITION_VAL(AWDThresholdsHighLow)": if threshold */
  1930. /* high is selected, then data is shifted to LSB. Else(threshold low), */
  1931. /* data is not shifted. */
  1932. MODIFY_REG(ADCx->TR, AWDThresholdsHighLow,AWDThresholdValue << ((AWDThresholdsHighLow >> ADC_TR_HT_BITOFFSET_POS) & 0x00000010U));
  1933. }
  1934. /**
  1935. * @brief Get ADC analog watchdog threshold value of threshold high,
  1936. * threshold low or raw data with ADC thresholds high and low
  1937. * concatenated.
  1938. * @note If raw data with ADC thresholds high and low is retrieved,
  1939. * the data of each threshold high or low can be isolated
  1940. * using helper macro:
  1941. * @ref __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW().
  1942. * @note In case of ADC resolution different of 12 bits,
  1943. * analog watchdog thresholds data require a specific shift.
  1944. * Use helper macro @ref __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION().
  1945. * @rmtoll TR HT LL_ADC_GetAnalogWDThresholds\n
  1946. * TR LT LL_ADC_GetAnalogWDThresholds
  1947. * @param ADCx ADC instance
  1948. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  1949. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  1950. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  1951. * @arg @ref LL_ADC_AWD_THRESHOLDS_HIGH_LOW
  1952. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1953. */
  1954. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdsHighLow)
  1955. {
  1956. /* Parameter "AWDThresholdsHighLow" is used with mask "0x00000010" */
  1957. /* to be equivalent to "POSITION_VAL(AWDThresholdsHighLow)": if threshold */
  1958. /* high is selected, then data is shifted to LSB. Else(threshold low or */
  1959. /* both thresholds), data is not shifted. */
  1960. return (uint32_t)(READ_BIT(ADCx->TR,(AWDThresholdsHighLow | ADC_TR_LT))>> ((~AWDThresholdsHighLow) & 0x00000010U));
  1961. }
  1962. /** @defgroup ADC_LL_EF_Operation_ADC_Instance Operation on ADC hierarchical scope: ADC instance
  1963. * @{
  1964. */
  1965. /**
  1966. * @brief Enable the selected ADC instance.
  1967. * @rmtoll CR ADEN LL_ADC_Enable
  1968. * @param ADCx ADC instance
  1969. * @retval None
  1970. */
  1971. __STATIC_INLINE void LL_ADC_Enable(ADC_TypeDef *ADCx)
  1972. {
  1973. /* Note: Write register with some additional bits forced to state reset */
  1974. /* instead of modifying only the selected bit for this function, */
  1975. /* to not interfere with bits with HW property "rs". */
  1976. MODIFY_REG(ADCx->CR,ADC_CR_BITS_PROPERTY_RS,ADC_CR_ADEN);
  1977. }
  1978. /**
  1979. * @brief Disable the selected ADC instance.
  1980. * @rmtoll CR ADDIS LL_ADC_Disable
  1981. * @param ADCx ADC instance
  1982. * @retval None
  1983. */
  1984. __STATIC_INLINE void LL_ADC_Disable(ADC_TypeDef *ADCx)
  1985. {
  1986. /* Note: Write register with some additional bits forced to state reset */
  1987. /* instead of modifying only the selected bit for this function, */
  1988. /* to not interfere with bits with HW property "rs". */
  1989. MODIFY_REG(ADCx->CR, ADC_CR_BITS_PROPERTY_RS, ADC_CR_ADDIS);
  1990. }
  1991. /**
  1992. * @brief Reset the selected ADC instance.
  1993. * @param ADCx ADC instance
  1994. * @retval None
  1995. */
  1996. __STATIC_INLINE void LL_ADC_Reset(ADC_TypeDef *ADCx)
  1997. {
  1998. /* Note: Write register with some additional bits forced to state reset */
  1999. /* instead of modifying only the selected bit for this function */
  2000. /* Force reset of ADC clock (core clock) */
  2001. LL_APB1_GRP2_ForceReset(LL_APB1_GRP2_PERIPH_ADC1);
  2002. /* Release reset of ADC clock (core clock) */
  2003. LL_APB1_GRP2_ReleaseReset(LL_APB1_GRP2_PERIPH_ADC1);
  2004. }
  2005. /**
  2006. * @brief Get the selected ADC instance enable state.
  2007. * (not only core clock: this ADC has a dual clock domain)
  2008. * @rmtoll CR ADEN LL_ADC_IsEnabled
  2009. * @param ADCx ADC instance
  2010. * @retval 0: ADC is disabled, 1: ADC is enabled.
  2011. */
  2012. __STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
  2013. {
  2014. return (READ_BIT(ADCx->CR, ADC_CR_ADEN) == (ADC_CR_ADEN));
  2015. }
  2016. /**
  2017. * @brief Get the selected ADC instance disable state.
  2018. * @rmtoll CR ADDIS LL_ADC_IsDisableOngoing
  2019. * @param ADCx ADC instance
  2020. * @retval 0: no ADC disable command on going.
  2021. */
  2022. __STATIC_INLINE uint32_t LL_ADC_IsDisableOngoing(ADC_TypeDef *ADCx)
  2023. {
  2024. return (READ_BIT(ADCx->CR, ADC_CR_ADDIS) == (ADC_CR_ADDIS));
  2025. }
  2026. /**
  2027. * @brief Start ADC calibration in the mode single-ended
  2028. * or differential (for devices with differential mode available).
  2029. * ADC must be ADC disabled.
  2030. * @rmtoll CR ADCAL LL_ADC_StartCalibration
  2031. * @param ADCx ADC instance
  2032. * @retval None
  2033. */
  2034. __STATIC_INLINE void LL_ADC_StartCalibration(ADC_TypeDef *ADCx)
  2035. {
  2036. /* Note: Write register with some additional bits forced to state reset */
  2037. /* instead of modifying only the selected bit for this function, */
  2038. /* to not interfere with bits with HW property "rs". */
  2039. MODIFY_REG(ADCx->CR,ADC_CR_BITS_PROPERTY_RS,ADC_CR_ADCAL);
  2040. }
  2041. /**
  2042. * @brief Get ADC calibration state.
  2043. * @rmtoll CR ADCAL LL_ADC_IsCalibrationOnGoing
  2044. * @param ADCx ADC instance
  2045. * @retval 0: calibration complete, 1: calibration in progress.
  2046. */
  2047. __STATIC_INLINE uint32_t LL_ADC_IsCalibrationOnGoing(ADC_TypeDef *ADCx)
  2048. {
  2049. return (READ_BIT(ADCx->CR, ADC_CR_ADCAL) == (ADC_CR_ADCAL));
  2050. }
  2051. /**
  2052. * @}
  2053. */
  2054. /**
  2055. * @}
  2056. */
  2057. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Regular Operation on ADC hierarchical scope: group regular
  2058. * @{
  2059. */
  2060. /**
  2061. * @brief Start ADC group regular conversion.
  2062. * @rmtoll CR ADSTART LL_ADC_REG_StartConversion
  2063. * @param ADCx ADC instance
  2064. * @retval None
  2065. */
  2066. __STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
  2067. {
  2068. /* Note: Write register with some additional bits forced to state reset */
  2069. /* instead of modifying only the selected bit for this function, */
  2070. /* to not interfere with bits with HW property "rs". */
  2071. MODIFY_REG(ADCx->CR, ADC_CR_BITS_PROPERTY_RS,ADC_CR_ADSTART);
  2072. }
  2073. /**
  2074. * @brief Stop ADC group regular conversion.
  2075. * @rmtoll CR ADSTP LL_ADC_REG_StopConversion
  2076. * @param ADCx ADC instance
  2077. * @retval None
  2078. */
  2079. __STATIC_INLINE void LL_ADC_REG_StopConversion(ADC_TypeDef *ADCx)
  2080. {
  2081. /* Note: Write register with some additional bits forced to state reset */
  2082. /* instead of modifying only the selected bit for this function, */
  2083. /* to not interfere with bits with HW property "rs". */
  2084. MODIFY_REG(ADCx->CR,ADC_CR_BITS_PROPERTY_RS,ADC_CR_ADSTP);
  2085. }
  2086. /**
  2087. * @brief Get ADC group regular conversion state.
  2088. * @rmtoll CR ADSTART LL_ADC_REG_IsConversionOngoing
  2089. * @param ADCx ADC instance
  2090. * @retval 0: no conversion is on going on ADC group regular.
  2091. */
  2092. __STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
  2093. {
  2094. return (READ_BIT(ADCx->CR, ADC_CR_ADSTART) == (ADC_CR_ADSTART));
  2095. }
  2096. /**
  2097. * @brief Get ADC group regular command of conversion stop state
  2098. * @rmtoll CR ADSTP LL_ADC_REG_IsStopConversionOngoing
  2099. * @param ADCx ADC instance
  2100. * @retval 0: no command of conversion stop is on going on ADC group regular.
  2101. */
  2102. __STATIC_INLINE uint32_t LL_ADC_REG_IsStopConversionOngoing(ADC_TypeDef *ADCx)
  2103. {
  2104. return (READ_BIT(ADCx->CR, ADC_CR_ADSTP) == (ADC_CR_ADSTP));
  2105. }
  2106. /**
  2107. * @brief Get ADC group regular conversion data, range fit for
  2108. * all ADC configurations: all ADC resolutions and
  2109. * all oversampling increased data width (for devices
  2110. * with feature oversampling).
  2111. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData32
  2112. * @param ADCx ADC instance
  2113. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  2114. */
  2115. __STATIC_INLINE uint32_t LL_ADC_REG_ReadConversionData32(ADC_TypeDef *ADCx)
  2116. {
  2117. return (uint32_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  2118. }
  2119. /**
  2120. * @brief Get ADC group regular conversion data, range fit for
  2121. * ADC resolution 12 bits.
  2122. * @note For devices with feature oversampling: Oversampling
  2123. * can increase data width, function for extended range
  2124. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  2125. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData12
  2126. * @param ADCx ADC instance
  2127. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  2128. */
  2129. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData12(ADC_TypeDef *ADCx)
  2130. {
  2131. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  2132. }
  2133. /**
  2134. * @brief Get ADC group regular conversion data, range fit for
  2135. * ADC resolution 10 bits.
  2136. * @note For devices with feature oversampling: Oversampling
  2137. * can increase data width, function for extended range
  2138. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  2139. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData10
  2140. * @param ADCx ADC instance
  2141. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  2142. */
  2143. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData10(ADC_TypeDef *ADCx)
  2144. {
  2145. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  2146. }
  2147. /**
  2148. * @brief Get ADC group regular conversion data, range fit for
  2149. * ADC resolution 8 bits.
  2150. * @note For devices with feature oversampling: Oversampling
  2151. * can increase data width, function for extended range
  2152. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  2153. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData8
  2154. * @param ADCx ADC instance
  2155. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  2156. */
  2157. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData8(ADC_TypeDef *ADCx)
  2158. {
  2159. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  2160. }
  2161. /**
  2162. * @brief Get ADC group regular conversion data, range fit for
  2163. * ADC resolution 6 bits.
  2164. * @note For devices with feature oversampling: Oversampling
  2165. * can increase data width, function for extended range
  2166. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  2167. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData6
  2168. * @param ADCx ADC instance
  2169. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  2170. */
  2171. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(ADC_TypeDef *ADCx)
  2172. {
  2173. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  2174. }
  2175. /**
  2176. * @}
  2177. */
  2178. /** @defgroup ADC_LL_EF_FLAG_Management ADC flag management
  2179. * @{
  2180. */
  2181. /**
  2182. * @brief Get flag ADC group regular end of unitary conversion.
  2183. * @rmtoll ISR EOC LL_ADC_IsActiveFlag_EOC
  2184. * @param ADCx ADC instance
  2185. * @retval State of bit (1 or 0).
  2186. */
  2187. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOC(ADC_TypeDef *ADCx)
  2188. {
  2189. return (READ_BIT(ADCx->ISR, ADC_ISR_EOC) == (ADC_ISR_EOC));
  2190. }
  2191. /**
  2192. * @brief Get flag ADC group regular end of sequence conversions.
  2193. * @rmtoll ISR EOSEQ LL_ADC_IsActiveFlag_EOS
  2194. * @param ADCx ADC instance
  2195. * @retval State of bit (1 or 0).
  2196. */
  2197. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOS(ADC_TypeDef *ADCx)
  2198. {
  2199. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOS) == (LL_ADC_FLAG_EOS));
  2200. }
  2201. /**
  2202. * @brief Get flag ADC group regular overrun.
  2203. * @rmtoll ISR OVR LL_ADC_IsActiveFlag_OVR
  2204. * @param ADCx ADC instance
  2205. * @retval State of bit (1 or 0).
  2206. */
  2207. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_OVR(ADC_TypeDef *ADCx)
  2208. {
  2209. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_OVR) == (LL_ADC_FLAG_OVR));
  2210. }
  2211. /**
  2212. * @brief Get flag ADC group regular end of sampling phase.
  2213. * @rmtoll ISR EOSMP LL_ADC_IsActiveFlag_EOSMP
  2214. * @param ADCx ADC instance
  2215. * @retval State of bit (1 or 0).
  2216. */
  2217. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOSMP(ADC_TypeDef *ADCx)
  2218. {
  2219. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOSMP) == (LL_ADC_FLAG_EOSMP));
  2220. }
  2221. /**
  2222. * @brief Get flag ADC analog watchdog 1 flag
  2223. * @rmtoll ISR AWD LL_ADC_IsActiveFlag_AWD
  2224. * @param ADCx ADC instance
  2225. * @retval State of bit (1 or 0).
  2226. */
  2227. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD(ADC_TypeDef *ADCx)
  2228. {
  2229. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD) == (LL_ADC_FLAG_AWD));
  2230. }
  2231. /**
  2232. * @brief Clear flag ADC group regular end of unitary conversion.
  2233. * @rmtoll ISR EOC LL_ADC_ClearFlag_EOC
  2234. * @param ADCx ADC instance
  2235. * @retval None
  2236. */
  2237. __STATIC_INLINE void LL_ADC_ClearFlag_EOC(ADC_TypeDef *ADCx)
  2238. {
  2239. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOC);
  2240. }
  2241. /**
  2242. * @brief Clear flag ADC group regular end of sequence conversions.
  2243. * @rmtoll ISR EOSEQ LL_ADC_ClearFlag_EOS
  2244. * @param ADCx ADC instance
  2245. * @retval None
  2246. */
  2247. __STATIC_INLINE void LL_ADC_ClearFlag_EOS(ADC_TypeDef *ADCx)
  2248. {
  2249. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOS);
  2250. }
  2251. /**
  2252. * @brief Clear flag ADC group regular overrun.
  2253. * @rmtoll ISR OVR LL_ADC_ClearFlag_OVR
  2254. * @param ADCx ADC instance
  2255. * @retval None
  2256. */
  2257. __STATIC_INLINE void LL_ADC_ClearFlag_OVR(ADC_TypeDef *ADCx)
  2258. {
  2259. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_OVR);
  2260. }
  2261. /**
  2262. * @brief Clear flag ADC group regular end of sampling phase.
  2263. * @rmtoll ISR EOSMP LL_ADC_ClearFlag_EOSMP
  2264. * @param ADCx ADC instance
  2265. * @retval None
  2266. */
  2267. __STATIC_INLINE void LL_ADC_ClearFlag_EOSMP(ADC_TypeDef *ADCx)
  2268. {
  2269. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOSMP);
  2270. }
  2271. /**
  2272. * @brief Clear flag ADC analog watchdog 1.
  2273. * @rmtoll ISR AWD LL_ADC_ClearFlag_AWD
  2274. * @param ADCx ADC instance
  2275. * @retval None
  2276. */
  2277. __STATIC_INLINE void LL_ADC_ClearFlag_AWD(ADC_TypeDef *ADCx)
  2278. {
  2279. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD);
  2280. }
  2281. /**
  2282. * @}
  2283. */
  2284. /** @defgroup ADC_LL_EF_IT_Management ADC IT management
  2285. * @{
  2286. */
  2287. /**
  2288. * @brief Enable interruption ADC group regular end of unitary conversion.
  2289. * @rmtoll IER EOCIE LL_ADC_EnableIT_EOC
  2290. * @param ADCx ADC instance
  2291. * @retval None
  2292. */
  2293. __STATIC_INLINE void LL_ADC_EnableIT_EOC(ADC_TypeDef *ADCx)
  2294. {
  2295. SET_BIT(ADCx->IER, LL_ADC_IT_EOC);
  2296. }
  2297. /**
  2298. * @brief Enable interruption ADC group regular end of sequence conversions.
  2299. * @rmtoll IER EOSEQIE LL_ADC_EnableIT_EOS
  2300. * @param ADCx ADC instance
  2301. * @retval None
  2302. */
  2303. __STATIC_INLINE void LL_ADC_EnableIT_EOS(ADC_TypeDef *ADCx)
  2304. {
  2305. SET_BIT(ADCx->IER, LL_ADC_IT_EOS);
  2306. }
  2307. /**
  2308. * @brief Enable ADC group regular interruption overrun.
  2309. * @rmtoll IER OVRIE LL_ADC_EnableIT_OVR
  2310. * @param ADCx ADC instance
  2311. * @retval None
  2312. */
  2313. __STATIC_INLINE void LL_ADC_EnableIT_OVR(ADC_TypeDef *ADCx)
  2314. {
  2315. SET_BIT(ADCx->IER, LL_ADC_IT_OVR);
  2316. }
  2317. /**
  2318. * @brief Enable interruption ADC group regular end of sampling.
  2319. * @rmtoll IER EOSMPIE LL_ADC_EnableIT_EOSMP
  2320. * @param ADCx ADC instance
  2321. * @retval None
  2322. */
  2323. __STATIC_INLINE void LL_ADC_EnableIT_EOSMP(ADC_TypeDef *ADCx)
  2324. {
  2325. SET_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  2326. }
  2327. /**
  2328. * @brief Enable interruption ADC analog watchdog 1.
  2329. * @rmtoll IER AWDIE LL_ADC_EnableIT_AWD
  2330. * @param ADCx ADC instance
  2331. * @retval None
  2332. */
  2333. __STATIC_INLINE void LL_ADC_EnableIT_AWD(ADC_TypeDef *ADCx)
  2334. {
  2335. SET_BIT(ADCx->IER, LL_ADC_IT_AWD);
  2336. }
  2337. /**
  2338. * @brief Disable interruption ADC group regular end of unitary conversion.
  2339. * @rmtoll IER EOCIE LL_ADC_DisableIT_EOC
  2340. * @param ADCx ADC instance
  2341. * @retval None
  2342. */
  2343. __STATIC_INLINE void LL_ADC_DisableIT_EOC(ADC_TypeDef *ADCx)
  2344. {
  2345. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOC);
  2346. }
  2347. /**
  2348. * @brief Disable interruption ADC group regular end of sequence conversions.
  2349. * @rmtoll IER EOSEQIE LL_ADC_DisableIT_EOS
  2350. * @param ADCx ADC instance
  2351. * @retval None
  2352. */
  2353. __STATIC_INLINE void LL_ADC_DisableIT_EOS(ADC_TypeDef *ADCx)
  2354. {
  2355. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOS);
  2356. }
  2357. /**
  2358. * @brief Disable interruption ADC group regular overrun.
  2359. * @rmtoll IER OVRIE LL_ADC_DisableIT_OVR
  2360. * @param ADCx ADC instance
  2361. * @retval None
  2362. */
  2363. __STATIC_INLINE void LL_ADC_DisableIT_OVR(ADC_TypeDef *ADCx)
  2364. {
  2365. CLEAR_BIT(ADCx->IER, LL_ADC_IT_OVR);
  2366. }
  2367. /**
  2368. * @brief Disable interruption ADC group regular end of sampling.
  2369. * @rmtoll IER EOSMPIE LL_ADC_DisableIT_EOSMP
  2370. * @param ADCx ADC instance
  2371. * @retval None
  2372. */
  2373. __STATIC_INLINE void LL_ADC_DisableIT_EOSMP(ADC_TypeDef *ADCx)
  2374. {
  2375. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  2376. }
  2377. /**
  2378. * @brief Disable interruption ADC analog watchdog 1.
  2379. * @rmtoll IER AWDIE LL_ADC_DisableIT_AWD
  2380. * @param ADCx ADC instance
  2381. * @retval None
  2382. */
  2383. __STATIC_INLINE void LL_ADC_DisableIT_AWD(ADC_TypeDef *ADCx)
  2384. {
  2385. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD);
  2386. }
  2387. /**
  2388. * @brief Get state of interruption ADC group regular end of unitary conversion
  2389. * (0: interrupt disabled, 1: interrupt enabled).
  2390. * @rmtoll IER EOCIE LL_ADC_IsEnabledIT_EOC
  2391. * @param ADCx ADC instance
  2392. * @retval State of bit (1 or 0).
  2393. */
  2394. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOC(ADC_TypeDef *ADCx)
  2395. {
  2396. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOC) == (LL_ADC_IT_EOC));
  2397. }
  2398. /**
  2399. * @brief Get state of interruption ADC group regular end of sequence conversions
  2400. * (0: interrupt disabled, 1: interrupt enabled).
  2401. * @rmtoll IER EOSEQIE LL_ADC_IsEnabledIT_EOS
  2402. * @param ADCx ADC instance
  2403. * @retval State of bit (1 or 0).
  2404. */
  2405. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOS(ADC_TypeDef *ADCx)
  2406. {
  2407. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOS) == (LL_ADC_IT_EOS));
  2408. }
  2409. /**
  2410. * @brief Get state of interruption ADC group regular overrun
  2411. * (0: interrupt disabled, 1: interrupt enabled).
  2412. * @rmtoll IER OVRIE LL_ADC_IsEnabledIT_OVR
  2413. * @param ADCx ADC instance
  2414. * @retval State of bit (1 or 0).
  2415. */
  2416. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_OVR(ADC_TypeDef *ADCx)
  2417. {
  2418. return (READ_BIT(ADCx->IER, LL_ADC_IT_OVR) == (LL_ADC_IT_OVR));
  2419. }
  2420. /**
  2421. * @brief Get state of interruption ADC group regular end of sampling
  2422. * (0: interrupt disabled, 1: interrupt enabled).
  2423. * @rmtoll IER EOSMPIE LL_ADC_IsEnabledIT_EOSMP
  2424. * @param ADCx ADC instance
  2425. * @retval State of bit (1 or 0).
  2426. */
  2427. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOSMP(ADC_TypeDef *ADCx)
  2428. {
  2429. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOSMP) == (LL_ADC_IT_EOSMP));
  2430. }
  2431. /**
  2432. * @brief Get state of interruption ADC analog watchdog 1
  2433. * (0: interrupt disabled, 1: interrupt enabled).
  2434. * @rmtoll IER AWDIE LL_ADC_IsEnabledIT_AWD
  2435. * @param ADCx ADC instance
  2436. * @retval State of bit (1 or 0).
  2437. */
  2438. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD(ADC_TypeDef *ADCx)
  2439. {
  2440. return (READ_BIT(ADCx->IER, LL_ADC_IT_AWD) == (LL_ADC_IT_AWD));
  2441. }
  2442. /**
  2443. * @}
  2444. */
  2445. /** @defgroup ADC_LL_EF_Calibration_Management ADC Calibration management
  2446. * @{
  2447. */
  2448. /**
  2449. * @brief Set calibration sample time
  2450. * @note Unit: ADC clock cycles.
  2451. * @rmtoll CCSR CALSMP LL_ADC_SetCalibrationSamplingTime
  2452. * @param ADCx ADC instance
  2453. * @param CalibrationSamplingTime This parameter can be one of the following values:
  2454. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_2CYCLES
  2455. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_4CYCLES
  2456. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_8CYCLES
  2457. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_1CYCLE
  2458. * @retval None
  2459. */
  2460. __STATIC_INLINE void LL_ADC_SetCalibrationSamplingTime(ADC_TypeDef *ADCx, uint32_t CalibrationSamplingTime)
  2461. {
  2462. MODIFY_REG(ADCx->CCSR, ADC_CCSR_CALSMP, CalibrationSamplingTime);
  2463. }
  2464. /**
  2465. * @brief Get sampling time common to a group of channels.
  2466. * @note Unit: ADC clock cycles.
  2467. * @rmtoll CCSR CALSMP LL_ADC_GetCalibrationSamplingTime
  2468. * @param ADCx ADC instance
  2469. * @retval Returned value can be one of the following values:
  2470. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_2CYCLES
  2471. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_4CYCLES
  2472. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_8CYCLES
  2473. * @arg @ref LL_ADC_CAL_SAMPLINGTIME_1CYCLE
  2474. */
  2475. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationSamplingTime(ADC_TypeDef *ADCx)
  2476. {
  2477. return (uint32_t)(READ_BIT(ADCx->CCSR, ADC_CCSR_CALSMP));
  2478. }
  2479. /**
  2480. * @brief Get the calibration offset status
  2481. * @rmtoll CCSR OFFSUC LL_ADC_GetCalibrationOffsetStatus
  2482. * @param ADCx ADC instance
  2483. * @retval Returned value can be one of the following values:
  2484. * @arg @ref LL_ADC_CAL_OFFSET_STATUS_SUCCESS
  2485. * @arg @ref LL_ADC_CAL_OFFSET_STATUS_FAIL
  2486. */
  2487. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationOffsetStatus(ADC_TypeDef *ADCx)
  2488. {
  2489. return (uint32_t)(READ_BIT(ADCx->CCSR, ADC_CCSR_OFFSUC));
  2490. }
  2491. /**
  2492. * @brief Get the calibration capacitance status
  2493. * @rmtoll CCSR CAPSUC LL_ADC_GetCalibrationCapacitanceStatus
  2494. * @param ADCx ADC instance
  2495. * @retval Returned value can be one of the following values:
  2496. * @arg @ref LL_ADC_CAL_CAPACITANCE_STATUS_SUCCESS
  2497. * @arg @ref LL_ADC_CAL_CAPACITANCE_STATUS_FAIL
  2498. */
  2499. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationCapacitanceStatus(ADC_TypeDef *ADCx)
  2500. {
  2501. return (uint32_t)(READ_BIT(ADCx->CCSR, ADC_CCSR_CAPSUC));
  2502. }
  2503. /**
  2504. * @brief Set the calibration mode
  2505. * @rmtoll CCSR CALSEL LL_ADC_SetCalibrationMode
  2506. * @param ADCx ADC instance
  2507. * @param CalibrationMode This parameter can be one of the following values:
  2508. @arg @ref LL_ADC_CAL_MODE_OFFSET
  2509. * @arg @ref LL_ADC_CAL_MODE_OFFSET_CAPACITANCE
  2510. * @retval None
  2511. */
  2512. __STATIC_INLINE void LL_ADC_SetCalibrationMode(ADC_TypeDef *ADCx,uint32_t CalibrationMode)
  2513. {
  2514. MODIFY_REG(ADCx->CCSR,ADC_CCSR_CALSEL, CalibrationMode);
  2515. }
  2516. /**
  2517. * @brief Get the calibration mode
  2518. * @rmtoll CCSR CALSEL LL_ADC_GetCalibrationMode
  2519. * @param ADCx ADC instance
  2520. * @retval Returned value can be one of the following values:
  2521. * @arg @ref LL_ADC_CAL_MODE_OFFSET
  2522. * @arg @ref LL_ADC_CAL_MODE_OFFSET_CAPACITANCE
  2523. */
  2524. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationMode(ADC_TypeDef *ADCx)
  2525. {
  2526. return (uint32_t)(READ_BIT(ADCx->CCSR, ADC_CCSR_CALSEL));
  2527. }
  2528. /**
  2529. * @}
  2530. */
  2531. /** @defgroup ADC_LL_EF_VrefBuf ADC Vrefbuf Management
  2532. * @{
  2533. */
  2534. /**
  2535. * @brief Enable VrefBuffer Output.
  2536. * @rmtoll CR VREF_BUFFERE LL_ADC_EnableVrefBuffVoltage
  2537. * @param ADCx ADC instance
  2538. * @retval None
  2539. */
  2540. __STATIC_INLINE void LL_ADC_EnableVrefBufferVoltage(ADC_TypeDef *ADCx)
  2541. {
  2542. SET_BIT(ADCx->CR, ADC_CR_VREF_BUFFERE);
  2543. }
  2544. /**
  2545. * @brief Disable VrefBuffer Output.
  2546. * @rmtoll CR VREF_BUFFERE LL_ADC_DisableVrefBuffVoltage
  2547. * @param ADCx ADC instance
  2548. * @retval None
  2549. */
  2550. __STATIC_INLINE void LL_ADC_DisableVrefBufferVoltage(ADC_TypeDef *ADCx)
  2551. {
  2552. CLEAR_BIT(ADCx->CR, ADC_CR_VREF_BUFFERE);
  2553. }
  2554. /**
  2555. * @brief Get state of VrefBuff Voltage output
  2556. * (0: output disabled, 1: output enabled).
  2557. * @rmtoll CR VREF_BUFFERE LL_ADC_IsEnabled_VrefBuffVoltage
  2558. * @param ADCx ADC instance
  2559. * @retval State of bit (1 or 0).
  2560. */
  2561. __STATIC_INLINE uint32_t LL_ADC_IsEnabled_VrefBufferVoltage(ADC_TypeDef *ADCx)
  2562. {
  2563. return (READ_BIT(ADCx->CR, ADC_CR_VREF_BUFFERE) == (ADC_CR_VREF_BUFFERE));
  2564. }
  2565. /**
  2566. * @brief Set ADC VrefBuffer Voltage.
  2567. * @rmtoll CR VREFBUFF_SEL LL_ADC_SetVrefBufferVoltage
  2568. * @param ADCx ADC instance
  2569. * @param VrefBufferVoltage This parameter can be one of the following values:
  2570. * @arg @ref LL_ADC_VREFBUF_1P5V
  2571. * @retval None
  2572. */
  2573. __STATIC_INLINE void LL_ADC_SetVrefBufferVoltage(ADC_TypeDef *ADCx, uint32_t VrefBufferVoltage)
  2574. {
  2575. MODIFY_REG(ADCx->CR, ADC_CR_VREFBUFF_SEL, VrefBufferVoltage);
  2576. }
  2577. /**
  2578. * @brief Get ADC VrefBuffer Voltage.
  2579. * @rmtoll CR VREFBUFF_SEL LL_ADC_GetVrefBufferVoltage
  2580. * @param ADCx ADC instance
  2581. * @retval Returned value can be one of the following values:
  2582. * @arg @ref LL_ADC_VREFBUF_1P5V
  2583. */
  2584. __STATIC_INLINE uint32_t LL_ADC_GetVrefBufferVoltage(ADC_TypeDef *ADCx)
  2585. {
  2586. return (uint32_t)(READ_BIT(ADCx->CR, ADC_CR_VREFBUFF_SEL));
  2587. }
  2588. /**
  2589. * @}
  2590. */
  2591. #if defined(USE_FULL_LL_DRIVER)
  2592. /** @defgroup ADC_LL_EF_Init Initialization and de-initialization functions
  2593. * @{
  2594. */
  2595. /* Initialization of some features of ADC common parameters and multimode */
  2596. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON);
  2597. /* De-initialization of ADC instance */
  2598. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx);
  2599. /* Initialization of some features of ADC instance */
  2600. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct);
  2601. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct);
  2602. /* Initialization of some features of ADC instance and ADC group regular */
  2603. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  2604. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  2605. /**
  2606. * @}
  2607. */
  2608. #endif /* USE_FULL_LL_DRIVER */
  2609. /**
  2610. * @}
  2611. */
  2612. /**
  2613. * @}
  2614. */
  2615. #endif /* ADC1 */
  2616. /**
  2617. * @}
  2618. */
  2619. #ifdef __cplusplus
  2620. }
  2621. #endif
  2622. #endif /* __PY32F002B_LL_ADC_H */
  2623. /************************ (C) COPYRIGHT Puya *****END OF FILE****/