py32f0xx_ll_tim.h 162 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_tim.h
  4. * @author MCU Application Team
  5. * @brief Header file of TIM 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 __PY32F0XX_LL_TIM_H
  32. #define __PY32F0XX_LL_TIM_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. /** @addtogroup PY32F0xx_LL_Driver
  39. * @{
  40. */
  41. #if defined (TIM1) || defined (TIM2) || defined (TIM3) || defined (TIM4) || defined (TIM5) || defined (TIM6) || defined (TIM7) || defined (TIM8) || defined (TIM9) || defined (TIM10) || defined (TIM11) || defined (TIM12) || defined (TIM13) || defined (TIM14) || defined (TIM15) || defined (TIM16) || defined (TIM17)
  42. /** @defgroup TIM_LL TIM
  43. * @{
  44. */
  45. /* Private types -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /** @defgroup TIM_LL_Private_Variables TIM Private Variables
  48. * @{
  49. */
  50. static const uint8_t OFFSET_TAB_CCMRx[] =
  51. {
  52. 0x00U, /* 0: TIMx_CH1 */
  53. 0x00U, /* 1: TIMx_CH1N */
  54. 0x00U, /* 2: TIMx_CH2 */
  55. 0x00U, /* 3: TIMx_CH2N */
  56. 0x04U, /* 4: TIMx_CH3 */
  57. 0x04U, /* 5: TIMx_CH3N */
  58. 0x04U /* 6: TIMx_CH4 */
  59. };
  60. static const uint8_t SHIFT_TAB_OCxx[] =
  61. {
  62. 0U, /* 0: OC1M, OC1FE, OC1PE */
  63. 0U, /* 1: - NA */
  64. 8U, /* 2: OC2M, OC2FE, OC2PE */
  65. 0U, /* 3: - NA */
  66. 0U, /* 4: OC3M, OC3FE, OC3PE */
  67. 0U, /* 5: - NA */
  68. 8U /* 6: OC4M, OC4FE, OC4PE */
  69. };
  70. static const uint8_t SHIFT_TAB_ICxx[] =
  71. {
  72. 0U, /* 0: CC1S, IC1PSC, IC1F */
  73. 0U, /* 1: - NA */
  74. 8U, /* 2: CC2S, IC2PSC, IC2F */
  75. 0U, /* 3: - NA */
  76. 0U, /* 4: CC3S, IC3PSC, IC3F */
  77. 0U, /* 5: - NA */
  78. 8U /* 6: CC4S, IC4PSC, IC4F */
  79. };
  80. static const uint8_t SHIFT_TAB_CCxP[] =
  81. {
  82. 0U, /* 0: CC1P */
  83. 2U, /* 1: CC1NP */
  84. 4U, /* 2: CC2P */
  85. 6U, /* 3: CC2NP */
  86. 8U, /* 4: CC3P */
  87. 10U, /* 5: CC3NP */
  88. 12U /* 6: CC4P */
  89. };
  90. static const uint8_t SHIFT_TAB_OISx[] =
  91. {
  92. 0U, /* 0: OIS1 */
  93. 1U, /* 1: OIS1N */
  94. 2U, /* 2: OIS2 */
  95. 3U, /* 3: OIS2N */
  96. 4U, /* 4: OIS3 */
  97. 5U, /* 5: OIS3N */
  98. 6U /* 6: OIS4 */
  99. };
  100. /**
  101. * @}
  102. */
  103. /* Private constants ---------------------------------------------------------*/
  104. /** @defgroup TIM_LL_Private_Constants TIM Private Constants
  105. * @{
  106. */
  107. /* Mask used to set the TDG[x:0] of the DTG bits of the TIMx_BDTR register */
  108. #define DT_DELAY_1 ((uint8_t)0x7F)
  109. #define DT_DELAY_2 ((uint8_t)0x3F)
  110. #define DT_DELAY_3 ((uint8_t)0x1F)
  111. #define DT_DELAY_4 ((uint8_t)0x1F)
  112. /* Mask used to set the DTG[7:5] bits of the DTG bits of the TIMx_BDTR register */
  113. #define DT_RANGE_1 ((uint8_t)0x00)
  114. #define DT_RANGE_2 ((uint8_t)0x80)
  115. #define DT_RANGE_3 ((uint8_t)0xC0)
  116. #define DT_RANGE_4 ((uint8_t)0xE0)
  117. /**
  118. * @}
  119. */
  120. /* Private macros ------------------------------------------------------------*/
  121. /** @defgroup TIM_LL_Private_Macros TIM Private Macros
  122. * @{
  123. */
  124. /** @brief Convert channel id into channel index.
  125. * @param __CHANNEL__ This parameter can be one of the following values:
  126. * @arg @ref LL_TIM_CHANNEL_CH1
  127. * @arg @ref LL_TIM_CHANNEL_CH1N
  128. * @arg @ref LL_TIM_CHANNEL_CH2
  129. * @arg @ref LL_TIM_CHANNEL_CH2N
  130. * @arg @ref LL_TIM_CHANNEL_CH3
  131. * @arg @ref LL_TIM_CHANNEL_CH3N
  132. * @arg @ref LL_TIM_CHANNEL_CH4
  133. * @retval none
  134. */
  135. #define TIM_GET_CHANNEL_INDEX( __CHANNEL__) \
  136. (((__CHANNEL__) == LL_TIM_CHANNEL_CH1) ? 0U :\
  137. ((__CHANNEL__) == LL_TIM_CHANNEL_CH1N) ? 1U :\
  138. ((__CHANNEL__) == LL_TIM_CHANNEL_CH2) ? 2U :\
  139. ((__CHANNEL__) == LL_TIM_CHANNEL_CH2N) ? 3U :\
  140. ((__CHANNEL__) == LL_TIM_CHANNEL_CH3) ? 4U :\
  141. ((__CHANNEL__) == LL_TIM_CHANNEL_CH3N) ? 5U : 6U)
  142. /** @brief Calculate the deadtime sampling period(in ps).
  143. * @param __TIMCLK__ timer input clock frequency (in Hz).
  144. * @param __CKD__ This parameter can be one of the following values:
  145. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  146. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  147. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  148. * @retval none
  149. */
  150. #define TIM_CALC_DTS(__TIMCLK__, __CKD__) \
  151. (((__CKD__) == LL_TIM_CLOCKDIVISION_DIV1) ? ((uint64_t)1000000000000U/(__TIMCLK__)) : \
  152. ((__CKD__) == LL_TIM_CLOCKDIVISION_DIV2) ? ((uint64_t)1000000000000U/((__TIMCLK__) >> 1U)) : \
  153. ((uint64_t)1000000000000U/((__TIMCLK__) >> 2U)))
  154. /**
  155. * @}
  156. */
  157. /* Exported types ------------------------------------------------------------*/
  158. #if defined(USE_FULL_LL_DRIVER)
  159. /** @defgroup TIM_LL_ES_INIT TIM Exported Init structure
  160. * @{
  161. */
  162. /**
  163. * @brief TIM Time Base configuration structure definition.
  164. */
  165. typedef struct
  166. {
  167. uint16_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  168. This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  169. This feature can be modified afterwards using unitary function @ref LL_TIM_SetPrescaler().*/
  170. uint32_t CounterMode; /*!< Specifies the counter mode.
  171. This parameter can be a value of @ref TIM_LL_EC_COUNTERMODE.
  172. This feature can be modified afterwards using unitary function @ref LL_TIM_SetCounterMode().*/
  173. uint32_t Autoreload; /*!< Specifies the auto reload value to be loaded into the active
  174. Auto-Reload Register at the next update event.
  175. This parameter must be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  176. Some timer instances may support 32 bits counters. In that case this parameter must be a number between 0x0000 and 0xFFFFFFFF.
  177. This feature can be modified afterwards using unitary function @ref LL_TIM_SetAutoReload().*/
  178. uint32_t ClockDivision; /*!< Specifies the clock division.
  179. This parameter can be a value of @ref TIM_LL_EC_CLOCKDIVISION.
  180. This feature can be modified afterwards using unitary function @ref LL_TIM_SetClockDivision().*/
  181. uint8_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  182. reaches zero, an update event is generated and counting restarts
  183. from the RCR value (N).
  184. This means in PWM mode that (N+1) corresponds to:
  185. - the number of PWM periods in edge-aligned mode
  186. - the number of half PWM period in center-aligned mode
  187. This parameter must be a number between 0x00 and 0xFF.
  188. This feature can be modified afterwards using unitary function @ref LL_TIM_SetRepetitionCounter().*/
  189. } LL_TIM_InitTypeDef;
  190. /**
  191. * @brief TIM Output Compare configuration structure definition.
  192. */
  193. typedef struct
  194. {
  195. uint32_t OCMode; /*!< Specifies the output mode.
  196. This parameter can be a value of @ref TIM_LL_EC_OCMODE.
  197. This feature can be modified afterwards using unitary function @ref LL_TIM_OC_SetMode().*/
  198. uint32_t OCState; /*!< Specifies the TIM Output Compare state.
  199. This parameter can be a value of @ref TIM_LL_EC_OCSTATE.
  200. This feature can be modified afterwards using unitary functions @ref LL_TIM_CC_EnableChannel() or @ref LL_TIM_CC_DisableChannel().*/
  201. uint32_t OCNState; /*!< Specifies the TIM complementary Output Compare state.
  202. This parameter can be a value of @ref TIM_LL_EC_OCSTATE.
  203. This feature can be modified afterwards using unitary functions @ref LL_TIM_CC_EnableChannel() or @ref LL_TIM_CC_DisableChannel().*/
  204. uint32_t CompareValue; /*!< Specifies the Compare value to be loaded into the Capture Compare Register.
  205. This parameter can be a number between Min_Data=0x0000 and Max_Data=0xFFFF.
  206. This feature can be modified afterwards using unitary function LL_TIM_OC_SetCompareCHx (x=1..6).*/
  207. uint32_t OCPolarity; /*!< Specifies the output polarity.
  208. This parameter can be a value of @ref TIM_LL_EC_OCPOLARITY.
  209. This feature can be modified afterwards using unitary function @ref LL_TIM_OC_SetPolarity().*/
  210. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  211. This parameter can be a value of @ref TIM_LL_EC_OCPOLARITY.
  212. This feature can be modified afterwards using unitary function @ref LL_TIM_OC_SetPolarity().*/
  213. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  214. This parameter can be a value of @ref TIM_LL_EC_OCIDLESTATE.
  215. This feature can be modified afterwards using unitary function @ref LL_TIM_OC_SetIdleState().*/
  216. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  217. This parameter can be a value of @ref TIM_LL_EC_OCIDLESTATE.
  218. This feature can be modified afterwards using unitary function @ref LL_TIM_OC_SetIdleState().*/
  219. } LL_TIM_OC_InitTypeDef;
  220. /**
  221. * @brief TIM Input Capture configuration structure definition.
  222. */
  223. typedef struct
  224. {
  225. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  226. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  227. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPolarity().*/
  228. uint32_t ICActiveInput; /*!< Specifies the input.
  229. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  230. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetActiveInput().*/
  231. uint32_t ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  232. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  233. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPrescaler().*/
  234. uint32_t ICFilter; /*!< Specifies the input capture filter.
  235. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  236. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetFilter().*/
  237. } LL_TIM_IC_InitTypeDef;
  238. /**
  239. * @brief TIM Encoder interface configuration structure definition.
  240. */
  241. typedef struct
  242. {
  243. uint32_t EncoderMode; /*!< Specifies the encoder resolution (x2 or x4).
  244. This parameter can be a value of @ref TIM_LL_EC_ENCODERMODE.
  245. This feature can be modified afterwards using unitary function @ref LL_TIM_SetEncoderMode().*/
  246. uint32_t IC1Polarity; /*!< Specifies the active edge of TI1 input.
  247. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  248. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPolarity().*/
  249. uint32_t IC1ActiveInput; /*!< Specifies the TI1 input source
  250. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  251. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetActiveInput().*/
  252. uint32_t IC1Prescaler; /*!< Specifies the TI1 input prescaler value.
  253. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  254. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPrescaler().*/
  255. uint32_t IC1Filter; /*!< Specifies the TI1 input filter.
  256. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  257. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetFilter().*/
  258. uint32_t IC2Polarity; /*!< Specifies the active edge of TI2 input.
  259. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  260. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPolarity().*/
  261. uint32_t IC2ActiveInput; /*!< Specifies the TI2 input source
  262. This parameter can be a value of @ref TIM_LL_EC_ACTIVEINPUT.
  263. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetActiveInput().*/
  264. uint32_t IC2Prescaler; /*!< Specifies the TI2 input prescaler value.
  265. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  266. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPrescaler().*/
  267. uint32_t IC2Filter; /*!< Specifies the TI2 input filter.
  268. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  269. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetFilter().*/
  270. } LL_TIM_ENCODER_InitTypeDef;
  271. /**
  272. * @brief TIM Hall sensor interface configuration structure definition.
  273. */
  274. typedef struct
  275. {
  276. uint32_t IC1Polarity; /*!< Specifies the active edge of TI1 input.
  277. This parameter can be a value of @ref TIM_LL_EC_IC_POLARITY.
  278. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPolarity().*/
  279. uint32_t IC1Prescaler; /*!< Specifies the TI1 input prescaler value.
  280. Prescaler must be set to get a maximum counter period longer than the
  281. time interval between 2 consecutive changes on the Hall inputs.
  282. This parameter can be a value of @ref TIM_LL_EC_ICPSC.
  283. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetPrescaler().*/
  284. uint32_t IC1Filter; /*!< Specifies the TI1 input filter.
  285. This parameter can be a value of @ref TIM_LL_EC_IC_FILTER.
  286. This feature can be modified afterwards using unitary function @ref LL_TIM_IC_SetFilter().*/
  287. uint32_t CommutationDelay; /*!< Specifies the compare value to be loaded into the Capture Compare Register.
  288. A positive pulse (TRGO event) is generated with a programmable delay every time
  289. a change occurs on the Hall inputs.
  290. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF.
  291. This feature can be modified afterwards using unitary function @ref LL_TIM_OC_SetCompareCH2().*/
  292. } LL_TIM_HALLSENSOR_InitTypeDef;
  293. /**
  294. * @brief BDTR (Break and Dead Time) structure definition
  295. */
  296. typedef struct
  297. {
  298. uint32_t OSSRState; /*!< Specifies the Off-State selection used in Run mode.
  299. This parameter can be a value of @ref TIM_LL_EC_OSSR
  300. This feature can be modified afterwards using unitary function @ref LL_TIM_SetOffStates()
  301. @note This bit-field cannot be modified as long as LOCK level 2 has been programmed. */
  302. uint32_t OSSIState; /*!< Specifies the Off-State used in Idle state.
  303. This parameter can be a value of @ref TIM_LL_EC_OSSI
  304. This feature can be modified afterwards using unitary function @ref LL_TIM_SetOffStates()
  305. @note This bit-field cannot be modified as long as LOCK level 2 has been programmed. */
  306. uint32_t LockLevel; /*!< Specifies the LOCK level parameters.
  307. This parameter can be a value of @ref TIM_LL_EC_LOCKLEVEL
  308. @note The LOCK bits can be written only once after the reset. Once the TIMx_BDTR register
  309. has been written, their content is frozen until the next reset.*/
  310. uint8_t DeadTime; /*!< Specifies the delay time between the switching-off and the
  311. switching-on of the outputs.
  312. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF.
  313. This feature can be modified afterwards using unitary function @ref LL_TIM_OC_SetDeadTime()
  314. @note This bit-field can not be modified as long as LOCK level 1, 2 or 3 has been programmed. */
  315. uint16_t BreakState; /*!< Specifies whether the TIM Break input is enabled or not.
  316. This parameter can be a value of @ref TIM_LL_EC_BREAK_ENABLE
  317. This feature can be modified afterwards using unitary functions @ref LL_TIM_EnableBRK() or @ref LL_TIM_DisableBRK()
  318. @note This bit-field can not be modified as long as LOCK level 1 has been programmed. */
  319. uint32_t BreakPolarity; /*!< Specifies the TIM Break Input pin polarity.
  320. This parameter can be a value of @ref TIM_LL_EC_BREAK_POLARITY
  321. This feature can be modified afterwards using unitary function @ref LL_TIM_ConfigBRK()
  322. @note This bit-field can not be modified as long as LOCK level 1 has been programmed. */
  323. uint32_t AutomaticOutput; /*!< Specifies whether the TIM Automatic Output feature is enabled or not.
  324. This parameter can be a value of @ref TIM_LL_EC_AUTOMATICOUTPUT_ENABLE
  325. This feature can be modified afterwards using unitary functions @ref LL_TIM_EnableAutomaticOutput() or @ref LL_TIM_DisableAutomaticOutput()
  326. @note This bit-field can not be modified as long as LOCK level 1 has been programmed. */
  327. } LL_TIM_BDTR_InitTypeDef;
  328. /**
  329. * @}
  330. */
  331. #endif /* USE_FULL_LL_DRIVER */
  332. /* Exported constants --------------------------------------------------------*/
  333. /** @defgroup TIM_LL_Exported_Constants TIM Exported Constants
  334. * @{
  335. */
  336. /** @defgroup TIM_LL_EC_GET_FLAG Get Flags Defines
  337. * @brief Flags defines which can be used with LL_TIM_ReadReg function.
  338. * @{
  339. */
  340. #define LL_TIM_SR_UIF TIM_SR_UIF /*!< Update interrupt flag */
  341. #define LL_TIM_SR_CC1IF TIM_SR_CC1IF /*!< Capture/compare 1 interrupt flag */
  342. #define LL_TIM_SR_CC2IF TIM_SR_CC2IF /*!< Capture/compare 2 interrupt flag */
  343. #define LL_TIM_SR_CC3IF TIM_SR_CC3IF /*!< Capture/compare 3 interrupt flag */
  344. #define LL_TIM_SR_CC4IF TIM_SR_CC4IF /*!< Capture/compare 4 interrupt flag */
  345. #define LL_TIM_SR_COMIF TIM_SR_COMIF /*!< COM interrupt flag */
  346. #define LL_TIM_SR_TIF TIM_SR_TIF /*!< Trigger interrupt flag */
  347. #define LL_TIM_SR_BIF TIM_SR_BIF /*!< Break interrupt flag */
  348. #define LL_TIM_SR_CC1OF TIM_SR_CC1OF /*!< Capture/Compare 1 overcapture flag */
  349. #define LL_TIM_SR_CC2OF TIM_SR_CC2OF /*!< Capture/Compare 2 overcapture flag */
  350. #define LL_TIM_SR_CC3OF TIM_SR_CC3OF /*!< Capture/Compare 3 overcapture flag */
  351. #define LL_TIM_SR_CC4OF TIM_SR_CC4OF /*!< Capture/Compare 4 overcapture flag */
  352. /**
  353. * @}
  354. */
  355. #if defined(USE_FULL_LL_DRIVER)
  356. /** @defgroup TIM_LL_EC_BREAK_ENABLE Break Enable
  357. * @{
  358. */
  359. #define LL_TIM_BREAK_DISABLE 0x00000000U /*!< Break function disabled */
  360. #define LL_TIM_BREAK_ENABLE TIM_BDTR_BKE /*!< Break function enabled */
  361. /**
  362. * @}
  363. */
  364. /** @defgroup TIM_LL_EC_AUTOMATICOUTPUT_ENABLE Automatic output enable
  365. * @{
  366. */
  367. #define LL_TIM_AUTOMATICOUTPUT_DISABLE 0x00000000U /*!< MOE can be set only by software */
  368. #define LL_TIM_AUTOMATICOUTPUT_ENABLE TIM_BDTR_AOE /*!< MOE can be set by software or automatically at the next update event */
  369. /**
  370. * @}
  371. */
  372. #endif /* USE_FULL_LL_DRIVER */
  373. /** @defgroup TIM_LL_EC_IT IT Defines
  374. * @brief IT defines which can be used with LL_TIM_ReadReg and LL_TIM_WriteReg functions.
  375. * @{
  376. */
  377. #define LL_TIM_DIER_UIE TIM_DIER_UIE /*!< Update interrupt enable */
  378. #define LL_TIM_DIER_CC1IE TIM_DIER_CC1IE /*!< Capture/compare 1 interrupt enable */
  379. #define LL_TIM_DIER_CC2IE TIM_DIER_CC2IE /*!< Capture/compare 2 interrupt enable */
  380. #define LL_TIM_DIER_CC3IE TIM_DIER_CC3IE /*!< Capture/compare 3 interrupt enable */
  381. #define LL_TIM_DIER_CC4IE TIM_DIER_CC4IE /*!< Capture/compare 4 interrupt enable */
  382. #define LL_TIM_DIER_COMIE TIM_DIER_COMIE /*!< COM interrupt enable */
  383. #define LL_TIM_DIER_TIE TIM_DIER_TIE /*!< Trigger interrupt enable */
  384. #define LL_TIM_DIER_BIE TIM_DIER_BIE /*!< Break interrupt enable */
  385. /**
  386. * @}
  387. */
  388. /** @defgroup TIM_LL_EC_UPDATESOURCE Update Source
  389. * @{
  390. */
  391. #define LL_TIM_UPDATESOURCE_REGULAR 0x00000000U /*!< Counter overflow/underflow, Setting the UG bit or Update generation through the slave mode controller generates an update request */
  392. #define LL_TIM_UPDATESOURCE_COUNTER TIM_CR1_URS /*!< Only counter overflow/underflow generates an update request */
  393. /**
  394. * @}
  395. */
  396. /** @defgroup TIM_LL_EC_ONEPULSEMODE One Pulse Mode
  397. * @{
  398. */
  399. #define LL_TIM_ONEPULSEMODE_SINGLE TIM_CR1_OPM /*!< Counter is not stopped at update event */
  400. #define LL_TIM_ONEPULSEMODE_REPETITIVE 0x00000000U /*!< Counter stops counting at the next update event */
  401. /**
  402. * @}
  403. */
  404. /** @defgroup TIM_LL_EC_COUNTERMODE Counter Mode
  405. * @{
  406. */
  407. #define LL_TIM_COUNTERMODE_UP 0x00000000U /*!<Counter used as upcounter */
  408. #define LL_TIM_COUNTERMODE_DOWN TIM_CR1_DIR /*!< Counter used as downcounter */
  409. #define LL_TIM_COUNTERMODE_CENTER_UP TIM_CR1_CMS_0 /*!< The counter counts up and down alternatively. Output compare interrupt flags of output channels are set only when the counter is counting down. */
  410. #define LL_TIM_COUNTERMODE_CENTER_DOWN TIM_CR1_CMS_1 /*!<The counter counts up and down alternatively. Output compare interrupt flags of output channels are set only when the counter is counting up */
  411. #define LL_TIM_COUNTERMODE_CENTER_UP_DOWN TIM_CR1_CMS /*!< The counter counts up and down alternatively. Output compare interrupt flags of output channels are set only when the counter is counting up or down. */
  412. /**
  413. * @}
  414. */
  415. /** @defgroup TIM_LL_EC_CLOCKDIVISION Clock Division
  416. * @{
  417. */
  418. #define LL_TIM_CLOCKDIVISION_DIV1 0x00000000U /*!< tDTS=tCK_INT */
  419. #define LL_TIM_CLOCKDIVISION_DIV2 TIM_CR1_CKD_0 /*!< tDTS=2*tCK_INT */
  420. #define LL_TIM_CLOCKDIVISION_DIV4 TIM_CR1_CKD_1 /*!< tDTS=4*tCK_INT */
  421. /**
  422. * @}
  423. */
  424. /** @defgroup TIM_LL_EC_COUNTERDIRECTION Counter Direction
  425. * @{
  426. */
  427. #define LL_TIM_COUNTERDIRECTION_UP 0x00000000U /*!< Timer counter counts up */
  428. #define LL_TIM_COUNTERDIRECTION_DOWN TIM_CR1_DIR /*!< Timer counter counts down */
  429. /**
  430. * @}
  431. */
  432. /** @defgroup TIM_LL_EC_CCUPDATESOURCE Capture Compare Update Source
  433. * @{
  434. */
  435. #define LL_TIM_CCUPDATESOURCE_COMG_ONLY 0x00000000U /*!< Capture/compare control bits are updated by setting the COMG bit only */
  436. #define LL_TIM_CCUPDATESOURCE_COMG_AND_TRGI TIM_CR2_CCUS /*!< Capture/compare control bits are updated by setting the COMG bit or when a rising edge occurs on trigger input (TRGI) */
  437. /**
  438. * @}
  439. */
  440. #if (defined(DMA) || defined(DMA1))
  441. /** @defgroup TIM_LL_EC_CCDMAREQUEST Capture Compare DMA Request
  442. * @{
  443. */
  444. #define LL_TIM_CCDMAREQUEST_CC 0x00000000U /*!< CCx DMA request sent when CCx event occurs */
  445. #define LL_TIM_CCDMAREQUEST_UPDATE TIM_CR2_CCDS /*!< CCx DMA requests sent when update event occurs */
  446. /**
  447. * @}
  448. */
  449. #endif
  450. /** @defgroup TIM_LL_EC_LOCKLEVEL Lock Level
  451. * @{
  452. */
  453. #define LL_TIM_LOCKLEVEL_OFF 0x00000000U /*!< LOCK OFF - No bit is write protected */
  454. #define LL_TIM_LOCKLEVEL_1 TIM_BDTR_LOCK_0 /*!< LOCK Level 1 */
  455. #define LL_TIM_LOCKLEVEL_2 TIM_BDTR_LOCK_1 /*!< LOCK Level 2 */
  456. #define LL_TIM_LOCKLEVEL_3 TIM_BDTR_LOCK /*!< LOCK Level 3 */
  457. /**
  458. * @}
  459. */
  460. /** @defgroup TIM_LL_EC_CHANNEL Channel
  461. * @{
  462. */
  463. #define LL_TIM_CHANNEL_CH1 TIM_CCER_CC1E /*!< Timer input/output channel 1 */
  464. #define LL_TIM_CHANNEL_CH1N TIM_CCER_CC1NE /*!< Timer complementary output channel 1 */
  465. #define LL_TIM_CHANNEL_CH2 TIM_CCER_CC2E /*!< Timer input/output channel 2 */
  466. #define LL_TIM_CHANNEL_CH2N TIM_CCER_CC2NE /*!< Timer complementary output channel 2 */
  467. #define LL_TIM_CHANNEL_CH3 TIM_CCER_CC3E /*!< Timer input/output channel 3 */
  468. #define LL_TIM_CHANNEL_CH3N TIM_CCER_CC3NE /*!< Timer complementary output channel 3 */
  469. #define LL_TIM_CHANNEL_CH4 TIM_CCER_CC4E /*!< Timer input/output channel 4 */
  470. /**
  471. * @}
  472. */
  473. #if defined(USE_FULL_LL_DRIVER)
  474. /** @defgroup TIM_LL_EC_OCSTATE Output Configuration State
  475. * @{
  476. */
  477. #define LL_TIM_OCSTATE_DISABLE 0x00000000U /*!< OCx is not active */
  478. #define LL_TIM_OCSTATE_ENABLE TIM_CCER_CC1E /*!< OCx signal is output on the corresponding output pin */
  479. /**
  480. * @}
  481. */
  482. #endif /* USE_FULL_LL_DRIVER */
  483. /** @defgroup TIM_LL_EC_OCMODE Output Configuration Mode
  484. * @{
  485. */
  486. #define LL_TIM_OCMODE_FROZEN 0x00000000U /*!<The comparison between the output compare register TIMx_CCRy and the counter TIMx_CNT has no effect on the output channel level */
  487. #define LL_TIM_OCMODE_ACTIVE TIM_CCMR1_OC1M_0 /*!<OCyREF is forced high on compare match*/
  488. #define LL_TIM_OCMODE_INACTIVE TIM_CCMR1_OC1M_1 /*!<OCyREF is forced low on compare match*/
  489. #define LL_TIM_OCMODE_TOGGLE (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!<OCyREF toggles on compare match*/
  490. #define LL_TIM_OCMODE_FORCED_INACTIVE TIM_CCMR1_OC1M_2 /*!<OCyREF is forced low*/
  491. #define LL_TIM_OCMODE_FORCED_ACTIVE (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0) /*!<OCyREF is forced high*/
  492. #define LL_TIM_OCMODE_PWM1 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1) /*!<In upcounting, channel y is active as long as TIMx_CNT<TIMx_CCRy else inactive. In downcounting, channel y is inactive as long as TIMx_CNT>TIMx_CCRy else active.*/
  493. #define LL_TIM_OCMODE_PWM2 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!<In upcounting, channel y is inactive as long as TIMx_CNT<TIMx_CCRy else active. In downcounting, channel y is active as long as TIMx_CNT>TIMx_CCRy else inactive*/
  494. /**
  495. * @}
  496. */
  497. /** @defgroup TIM_LL_EC_OCPOLARITY Output Configuration Polarity
  498. * @{
  499. */
  500. #define LL_TIM_OCPOLARITY_HIGH 0x00000000U /*!< OCxactive high*/
  501. #define LL_TIM_OCPOLARITY_LOW TIM_CCER_CC1P /*!< OCxactive low*/
  502. /**
  503. * @}
  504. */
  505. /** @defgroup TIM_LL_EC_OCIDLESTATE Output Configuration Idle State
  506. * @{
  507. */
  508. #define LL_TIM_OCIDLESTATE_LOW 0x00000000U /*!<OCx=0 (after a dead-time if OC is implemented) when MOE=0*/
  509. #define LL_TIM_OCIDLESTATE_HIGH TIM_CR2_OIS1 /*!<OCx=1 (after a dead-time if OC is implemented) when MOE=0*/
  510. /**
  511. * @}
  512. */
  513. /** @defgroup TIM_LL_EC_ACTIVEINPUT Active Input Selection
  514. * @{
  515. */
  516. #define LL_TIM_ACTIVEINPUT_DIRECTTI (TIM_CCMR1_CC1S_0 << 16U) /*!< ICx is mapped on TIx */
  517. #define LL_TIM_ACTIVEINPUT_INDIRECTTI (TIM_CCMR1_CC1S_1 << 16U) /*!< ICx is mapped on TIy */
  518. #define LL_TIM_ACTIVEINPUT_TRC (TIM_CCMR1_CC1S << 16U) /*!< ICx is mapped on TRC */
  519. /**
  520. * @}
  521. */
  522. /** @defgroup TIM_LL_EC_ICPSC Input Configuration Prescaler
  523. * @{
  524. */
  525. #define LL_TIM_ICPSC_DIV1 0x00000000U /*!< No prescaler, capture is done each time an edge is detected on the capture input */
  526. #define LL_TIM_ICPSC_DIV2 (TIM_CCMR1_IC1PSC_0 << 16U) /*!< Capture is done once every 2 events */
  527. #define LL_TIM_ICPSC_DIV4 (TIM_CCMR1_IC1PSC_1 << 16U) /*!< Capture is done once every 4 events */
  528. #define LL_TIM_ICPSC_DIV8 (TIM_CCMR1_IC1PSC << 16U) /*!< Capture is done once every 8 events */
  529. /**
  530. * @}
  531. */
  532. /** @defgroup TIM_LL_EC_IC_FILTER Input Configuration Filter
  533. * @{
  534. */
  535. #define LL_TIM_IC_FILTER_FDIV1 0x00000000U /*!< No filter, sampling is done at fDTS */
  536. #define LL_TIM_IC_FILTER_FDIV1_N2 (TIM_CCMR1_IC1F_0 << 16U) /*!< fSAMPLING=fCK_INT, N=2 */
  537. #define LL_TIM_IC_FILTER_FDIV1_N4 (TIM_CCMR1_IC1F_1 << 16U) /*!< fSAMPLING=fCK_INT, N=4 */
  538. #define LL_TIM_IC_FILTER_FDIV1_N8 ((TIM_CCMR1_IC1F_1 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fCK_INT, N=8 */
  539. #define LL_TIM_IC_FILTER_FDIV2_N6 (TIM_CCMR1_IC1F_2 << 16U) /*!< fSAMPLING=fDTS/2, N=6 */
  540. #define LL_TIM_IC_FILTER_FDIV2_N8 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/2, N=8 */
  541. #define LL_TIM_IC_FILTER_FDIV4_N6 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/4, N=6 */
  542. #define LL_TIM_IC_FILTER_FDIV4_N8 ((TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_1 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/4, N=8 */
  543. #define LL_TIM_IC_FILTER_FDIV8_N6 (TIM_CCMR1_IC1F_3 << 16U) /*!< fSAMPLING=fDTS/8, N=6 */
  544. #define LL_TIM_IC_FILTER_FDIV8_N8 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/8, N=8 */
  545. #define LL_TIM_IC_FILTER_FDIV16_N5 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/16, N=5 */
  546. #define LL_TIM_IC_FILTER_FDIV16_N6 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_1 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/16, N=6 */
  547. #define LL_TIM_IC_FILTER_FDIV16_N8 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_2) << 16U) /*!< fSAMPLING=fDTS/16, N=8 */
  548. #define LL_TIM_IC_FILTER_FDIV32_N5 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_0) << 16U) /*!< fSAMPLING=fDTS/32, N=5 */
  549. #define LL_TIM_IC_FILTER_FDIV32_N6 ((TIM_CCMR1_IC1F_3 | TIM_CCMR1_IC1F_2 | TIM_CCMR1_IC1F_1) << 16U) /*!< fSAMPLING=fDTS/32, N=6 */
  550. #define LL_TIM_IC_FILTER_FDIV32_N8 (TIM_CCMR1_IC1F << 16U) /*!< fSAMPLING=fDTS/32, N=8 */
  551. /**
  552. * @}
  553. */
  554. /** @defgroup TIM_LL_EC_IC_POLARITY Input Configuration Polarity
  555. * @{
  556. */
  557. #define LL_TIM_IC_POLARITY_RISING 0x00000000U /*!< The circuit is sensitive to TIxFP1 rising edge, TIxFP1 is not inverted */
  558. #define LL_TIM_IC_POLARITY_FALLING TIM_CCER_CC1P /*!< The circuit is sensitive to TIxFP1 falling edge, TIxFP1 is inverted */
  559. #define LL_TIM_IC_POLARITY_BOTHEDGE (TIM_CCER_CC1P | TIM_CCER_CC1NP) /*!< The circuit is sensitive to both TIxFP1 rising and falling edges, TIxFP1 is not inverted */
  560. /**
  561. * @}
  562. */
  563. /** @defgroup TIM_LL_EC_CLOCKSOURCE Clock Source
  564. * @{
  565. */
  566. #define LL_TIM_CLOCKSOURCE_INTERNAL 0x00000000U /*!< The timer is clocked by the internal clock provided from the RCC */
  567. #define LL_TIM_CLOCKSOURCE_EXT_MODE1 (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< Counter counts at each rising or falling edge on a selected input*/
  568. #define LL_TIM_CLOCKSOURCE_EXT_MODE2 TIM_SMCR_ECE /*!< Counter counts at each rising or falling edge on the external trigger input ETR */
  569. /**
  570. * @}
  571. */
  572. /** @defgroup TIM_LL_EC_ENCODERMODE Encoder Mode
  573. * @{
  574. */
  575. #define LL_TIM_ENCODERMODE_X2_TI1 TIM_SMCR_SMS_0 /*!< Quadrature encoder mode 1, x2 mode - Counter counts up/down on TI1FP1 edge depending on TI2FP2 level */
  576. #define LL_TIM_ENCODERMODE_X2_TI2 TIM_SMCR_SMS_1 /*!< Quadrature encoder mode 2, x2 mode - Counter counts up/down on TI2FP2 edge depending on TI1FP1 level */
  577. #define LL_TIM_ENCODERMODE_X4_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< Quadrature encoder mode 3, x4 mode - Counter counts up/down on both TI1FP1 and TI2FP2 edges depending on the level of the other input */
  578. /**
  579. * @}
  580. */
  581. /** @defgroup TIM_LL_EC_TRGO Trigger Output
  582. * @{
  583. */
  584. #define LL_TIM_TRGO_RESET 0x00000000U /*!< UG bit from the TIMx_EGR register is used as trigger output */
  585. #define LL_TIM_TRGO_ENABLE TIM_CR2_MMS_0 /*!< Counter Enable signal (CNT_EN) is used as trigger output */
  586. #define LL_TIM_TRGO_UPDATE TIM_CR2_MMS_1 /*!< Update event is used as trigger output */
  587. #define LL_TIM_TRGO_CC1IF (TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< CC1 capture or a compare match is used as trigger output */
  588. #define LL_TIM_TRGO_OC1REF TIM_CR2_MMS_2 /*!< OC1REF signal is used as trigger output */
  589. #define LL_TIM_TRGO_OC2REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_0) /*!< OC2REF signal is used as trigger output */
  590. #define LL_TIM_TRGO_OC3REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1) /*!< OC3REF signal is used as trigger output */
  591. #define LL_TIM_TRGO_OC4REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< OC4REF signal is used as trigger output */
  592. /**
  593. * @}
  594. */
  595. /** @defgroup TIM_LL_EC_SLAVEMODE Slave Mode
  596. * @{
  597. */
  598. #define LL_TIM_SLAVEMODE_DISABLED 0x00000000U /*!< Slave mode disabled */
  599. #define LL_TIM_SLAVEMODE_RESET TIM_SMCR_SMS_2 /*!< Reset Mode - Rising edge of the selected trigger input (TRGI) reinitializes the counter */
  600. #define LL_TIM_SLAVEMODE_GATED (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0) /*!< Gated Mode - The counter clock is enabled when the trigger input (TRGI) is high */
  601. #define LL_TIM_SLAVEMODE_TRIGGER (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1) /*!< Trigger Mode - The counter starts at a rising edge of the trigger TRGI */
  602. /**
  603. * @}
  604. */
  605. /** @defgroup TIM_LL_EC_TS Trigger Selection
  606. * @{
  607. */
  608. #define LL_TIM_TS_ITR0 0x00000000U /*!< Internal Trigger 0 (ITR0) is used as trigger input */
  609. #define LL_TIM_TS_ITR1 TIM_SMCR_TS_0 /*!< Internal Trigger 1 (ITR1) is used as trigger input */
  610. #define LL_TIM_TS_ITR2 TIM_SMCR_TS_1 /*!< Internal Trigger 2 (ITR2) is used as trigger input */
  611. #define LL_TIM_TS_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1) /*!< Internal Trigger 3 (ITR3) is used as trigger input */
  612. #define LL_TIM_TS_TI1F_ED TIM_SMCR_TS_2 /*!< TI1 Edge Detector (TI1F_ED) is used as trigger input */
  613. #define LL_TIM_TS_TI1FP1 (TIM_SMCR_TS_2 | TIM_SMCR_TS_0) /*!< Filtered Timer Input 1 (TI1FP1) is used as trigger input */
  614. #define LL_TIM_TS_TI2FP2 (TIM_SMCR_TS_2 | TIM_SMCR_TS_1) /*!< Filtered Timer Input 2 (TI12P2) is used as trigger input */
  615. #define LL_TIM_TS_ETRF (TIM_SMCR_TS_2 | TIM_SMCR_TS_1 | TIM_SMCR_TS_0) /*!< Filtered external Trigger (ETRF) is used as trigger input */
  616. /**
  617. * @}
  618. */
  619. /** @defgroup TIM_LL_EC_ETR_POLARITY External Trigger Polarity
  620. * @{
  621. */
  622. #define LL_TIM_ETR_POLARITY_NONINVERTED 0x00000000U /*!< ETR is non-inverted, active at high level or rising edge */
  623. #define LL_TIM_ETR_POLARITY_INVERTED TIM_SMCR_ETP /*!< ETR is inverted, active at low level or falling edge */
  624. /**
  625. * @}
  626. */
  627. /** @defgroup TIM_LL_EC_ETR_PRESCALER External Trigger Prescaler
  628. * @{
  629. */
  630. #define LL_TIM_ETR_PRESCALER_DIV1 0x00000000U /*!< ETR prescaler OFF */
  631. #define LL_TIM_ETR_PRESCALER_DIV2 TIM_SMCR_ETPS_0 /*!< ETR frequency is divided by 2 */
  632. #define LL_TIM_ETR_PRESCALER_DIV4 TIM_SMCR_ETPS_1 /*!< ETR frequency is divided by 4 */
  633. #define LL_TIM_ETR_PRESCALER_DIV8 TIM_SMCR_ETPS /*!< ETR frequency is divided by 8 */
  634. /**
  635. * @}
  636. */
  637. /** @defgroup TIM_LL_EC_ETR_FILTER External Trigger Filter
  638. * @{
  639. */
  640. #define LL_TIM_ETR_FILTER_FDIV1 0x00000000U /*!< No filter, sampling is done at fDTS */
  641. #define LL_TIM_ETR_FILTER_FDIV1_N2 TIM_SMCR_ETF_0 /*!< fSAMPLING=fCK_INT, N=2 */
  642. #define LL_TIM_ETR_FILTER_FDIV1_N4 TIM_SMCR_ETF_1 /*!< fSAMPLING=fCK_INT, N=4 */
  643. #define LL_TIM_ETR_FILTER_FDIV1_N8 (TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fCK_INT, N=8 */
  644. #define LL_TIM_ETR_FILTER_FDIV2_N6 TIM_SMCR_ETF_2 /*!< fSAMPLING=fDTS/2, N=6 */
  645. #define LL_TIM_ETR_FILTER_FDIV2_N8 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/2, N=8 */
  646. #define LL_TIM_ETR_FILTER_FDIV4_N6 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/4, N=6 */
  647. #define LL_TIM_ETR_FILTER_FDIV4_N8 (TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/4, N=8 */
  648. #define LL_TIM_ETR_FILTER_FDIV8_N6 TIM_SMCR_ETF_3 /*!< fSAMPLING=fDTS/8, N=8 */
  649. #define LL_TIM_ETR_FILTER_FDIV8_N8 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/16, N=5 */
  650. #define LL_TIM_ETR_FILTER_FDIV16_N5 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/16, N=6 */
  651. #define LL_TIM_ETR_FILTER_FDIV16_N6 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_1 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/16, N=8 */
  652. #define LL_TIM_ETR_FILTER_FDIV16_N8 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2) /*!< fSAMPLING=fDTS/16, N=5 */
  653. #define LL_TIM_ETR_FILTER_FDIV32_N5 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2 | TIM_SMCR_ETF_0) /*!< fSAMPLING=fDTS/32, N=5 */
  654. #define LL_TIM_ETR_FILTER_FDIV32_N6 (TIM_SMCR_ETF_3 | TIM_SMCR_ETF_2 | TIM_SMCR_ETF_1) /*!< fSAMPLING=fDTS/32, N=6 */
  655. #define LL_TIM_ETR_FILTER_FDIV32_N8 TIM_SMCR_ETF /*!< fSAMPLING=fDTS/32, N=8 */
  656. /**
  657. * @}
  658. */
  659. /** @defgroup TIM_LL_EC_BREAK_POLARITY break polarity
  660. * @{
  661. */
  662. #define LL_TIM_BREAK_POLARITY_LOW 0x00000000U /*!< Break input BRK is active low */
  663. #define LL_TIM_BREAK_POLARITY_HIGH TIM_BDTR_BKP /*!< Break input BRK is active high */
  664. /**
  665. * @}
  666. */
  667. /** @defgroup TIM_LL_EC_OSSI OSSI
  668. * @{
  669. */
  670. #define LL_TIM_OSSI_DISABLE 0x00000000U /*!< When inactive, OCx/OCxN outputs are disabled */
  671. #define LL_TIM_OSSI_ENABLE TIM_BDTR_OSSI /*!< When inactive, OxC/OCxN outputs are first forced with their inactive level then forced to their idle level after the deadtime */
  672. /**
  673. * @}
  674. */
  675. /** @defgroup TIM_LL_EC_OSSR OSSR
  676. * @{
  677. */
  678. #define LL_TIM_OSSR_DISABLE 0x00000000U /*!< When inactive, OCx/OCxN outputs are disabled */
  679. #define LL_TIM_OSSR_ENABLE TIM_BDTR_OSSR /*!< When inactive, OC/OCN outputs are enabled with their inactive level as soon as CCxE=1 or CCxNE=1 */
  680. /**
  681. * @}
  682. */
  683. #if (defined(DMA) || defined(DMA1))
  684. /** @defgroup TIM_LL_EC_DMABURST_BASEADDR DMA Burst Base Address
  685. * @{
  686. */
  687. #define LL_TIM_DMABURST_BASEADDR_CR1 0x00000000U /*!< TIMx_CR1 register is the DMA base address for DMA burst */
  688. #define LL_TIM_DMABURST_BASEADDR_CR2 TIM_DCR_DBA_0 /*!< TIMx_CR2 register is the DMA base address for DMA burst */
  689. #define LL_TIM_DMABURST_BASEADDR_SMCR TIM_DCR_DBA_1 /*!< TIMx_SMCR register is the DMA base address for DMA burst */
  690. #define LL_TIM_DMABURST_BASEADDR_DIER (TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_DIER register is the DMA base address for DMA burst */
  691. #define LL_TIM_DMABURST_BASEADDR_SR TIM_DCR_DBA_2 /*!< TIMx_SR register is the DMA base address for DMA burst */
  692. #define LL_TIM_DMABURST_BASEADDR_EGR (TIM_DCR_DBA_2 | TIM_DCR_DBA_0) /*!< TIMx_EGR register is the DMA base address for DMA burst */
  693. #define LL_TIM_DMABURST_BASEADDR_CCMR1 (TIM_DCR_DBA_2 | TIM_DCR_DBA_1) /*!< TIMx_CCMR1 register is the DMA base address for DMA burst */
  694. #define LL_TIM_DMABURST_BASEADDR_CCMR2 (TIM_DCR_DBA_2 | TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_CCMR2 register is the DMA base address for DMA burst */
  695. #define LL_TIM_DMABURST_BASEADDR_CCER TIM_DCR_DBA_3 /*!< TIMx_CCER register is the DMA base address for DMA burst */
  696. #define LL_TIM_DMABURST_BASEADDR_CNT (TIM_DCR_DBA_3 | TIM_DCR_DBA_0) /*!< TIMx_CNT register is the DMA base address for DMA burst */
  697. #define LL_TIM_DMABURST_BASEADDR_PSC (TIM_DCR_DBA_3 | TIM_DCR_DBA_1) /*!< TIMx_PSC register is the DMA base address for DMA burst */
  698. #define LL_TIM_DMABURST_BASEADDR_ARR (TIM_DCR_DBA_3 | TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_ARR register is the DMA base address for DMA burst */
  699. #define LL_TIM_DMABURST_BASEADDR_RCR (TIM_DCR_DBA_3 | TIM_DCR_DBA_2) /*!< TIMx_RCR register is the DMA base address for DMA burst */
  700. #define LL_TIM_DMABURST_BASEADDR_CCR1 (TIM_DCR_DBA_3 | TIM_DCR_DBA_2 | TIM_DCR_DBA_0) /*!< TIMx_CCR1 register is the DMA base address for DMA burst */
  701. #define LL_TIM_DMABURST_BASEADDR_CCR2 (TIM_DCR_DBA_3 | TIM_DCR_DBA_2 | TIM_DCR_DBA_1) /*!< TIMx_CCR2 register is the DMA base address for DMA burst */
  702. #define LL_TIM_DMABURST_BASEADDR_CCR3 (TIM_DCR_DBA_3 | TIM_DCR_DBA_2 | TIM_DCR_DBA_1 | TIM_DCR_DBA_0) /*!< TIMx_CCR3 register is the DMA base address for DMA burst */
  703. #define LL_TIM_DMABURST_BASEADDR_CCR4 TIM_DCR_DBA_4 /*!< TIMx_CCR4 register is the DMA base address for DMA burst */
  704. #define LL_TIM_DMABURST_BASEADDR_BDTR (TIM_DCR_DBA_4 | TIM_DCR_DBA_0) /*!< TIMx_BDTR register is the DMA base address for DMA burst */
  705. /**
  706. * @}
  707. */
  708. /** @defgroup TIM_LL_EC_DMABURST_LENGTH DMA Burst Length
  709. * @{
  710. */
  711. #define LL_TIM_DMABURST_LENGTH_1TRANSFER 0x00000000U /*!< Transfer is done to 1 register starting from the DMA burst base address */
  712. #define LL_TIM_DMABURST_LENGTH_2TRANSFERS TIM_DCR_DBL_0 /*!< Transfer is done to 2 registers starting from the DMA burst base address */
  713. #define LL_TIM_DMABURST_LENGTH_3TRANSFERS TIM_DCR_DBL_1 /*!< Transfer is done to 3 registers starting from the DMA burst base address */
  714. #define LL_TIM_DMABURST_LENGTH_4TRANSFERS (TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 4 registers starting from the DMA burst base address */
  715. #define LL_TIM_DMABURST_LENGTH_5TRANSFERS TIM_DCR_DBL_2 /*!< Transfer is done to 5 registers starting from the DMA burst base address */
  716. #define LL_TIM_DMABURST_LENGTH_6TRANSFERS (TIM_DCR_DBL_2 | TIM_DCR_DBL_0) /*!< Transfer is done to 6 registers starting from the DMA burst base address */
  717. #define LL_TIM_DMABURST_LENGTH_7TRANSFERS (TIM_DCR_DBL_2 | TIM_DCR_DBL_1) /*!< Transfer is done to 7 registers starting from the DMA burst base address */
  718. #define LL_TIM_DMABURST_LENGTH_8TRANSFERS (TIM_DCR_DBL_2 | TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 1 registers starting from the DMA burst base address */
  719. #define LL_TIM_DMABURST_LENGTH_9TRANSFERS TIM_DCR_DBL_3 /*!< Transfer is done to 9 registers starting from the DMA burst base address */
  720. #define LL_TIM_DMABURST_LENGTH_10TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_0) /*!< Transfer is done to 10 registers starting from the DMA burst base address */
  721. #define LL_TIM_DMABURST_LENGTH_11TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_1) /*!< Transfer is done to 11 registers starting from the DMA burst base address */
  722. #define LL_TIM_DMABURST_LENGTH_12TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 12 registers starting from the DMA burst base address */
  723. #define LL_TIM_DMABURST_LENGTH_13TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2) /*!< Transfer is done to 13 registers starting from the DMA burst base address */
  724. #define LL_TIM_DMABURST_LENGTH_14TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2 | TIM_DCR_DBL_0) /*!< Transfer is done to 14 registers starting from the DMA burst base address */
  725. #define LL_TIM_DMABURST_LENGTH_15TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2 | TIM_DCR_DBL_1) /*!< Transfer is done to 15 registers starting from the DMA burst base address */
  726. #define LL_TIM_DMABURST_LENGTH_16TRANSFERS (TIM_DCR_DBL_3 | TIM_DCR_DBL_2 | TIM_DCR_DBL_1 | TIM_DCR_DBL_0) /*!< Transfer is done to 16 registers starting from the DMA burst base address */
  727. #define LL_TIM_DMABURST_LENGTH_17TRANSFERS TIM_DCR_DBL_4 /*!< Transfer is done to 17 registers starting from the DMA burst base address */
  728. #define LL_TIM_DMABURST_LENGTH_18TRANSFERS (TIM_DCR_DBL_4 | TIM_DCR_DBL_0) /*!< Transfer is done to 18 registers starting from the DMA burst base address */
  729. /**
  730. * @}
  731. */
  732. #endif
  733. /** @defgroup TIM_LL_EC_OCREF_CLR_INT OCREF clear input selection
  734. * @{
  735. */
  736. #define LL_TIM_OCREF_CLR_INT_OCREF_CLR 0x00000000U /*!< OCREF_CLR_INT is connected to the OCREF_CLR input */
  737. #define LL_TIM_OCREF_CLR_INT_ETR TIM_SMCR_OCCS /*!< OCREF_CLR_INT is connected to ETRF */
  738. /**
  739. * @}
  740. */
  741. /** @defgroup TIMEx_Remap TIM Extended Remapping
  742. * @{
  743. */
  744. #define LL_TIM_TIM14_TI1_RMP_GPIO (0x00000000U) /*!< TIM14 TI1 is connected to GPIO */
  745. #define LL_TIM_TIM14_TI1_RMP_RTC (0x00000001U) /*!< TIM14 TI1 is connected to RTC_clock */
  746. #define LL_TIM_TIM14_TI1_RMP_HSE_32 (0x00000002U) /*!< TIM14 TI1 is connected to HSE/32U */
  747. #define LL_TIM_TIM14_TI1_RMP_MCO (0x00000003U) /*!< TIM14 TI1 is connected to MCO */
  748. /**
  749. * @}
  750. */
  751. /**
  752. * @}
  753. */
  754. /* Exported macro ------------------------------------------------------------*/
  755. /** @defgroup TIM_LL_Exported_Macros TIM Exported Macros
  756. * @{
  757. */
  758. /** @defgroup TIM_LL_EM_WRITE_READ Common Write and read registers Macros
  759. * @{
  760. */
  761. /**
  762. * @brief Write a value in TIM register.
  763. * @param __INSTANCE__ TIM Instance
  764. * @param __REG__ Register to be written
  765. * @param __VALUE__ Value to be written in the register
  766. * @retval None
  767. */
  768. #define LL_TIM_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  769. /**
  770. * @brief Read a value in TIM register.
  771. * @param __INSTANCE__ TIM Instance
  772. * @param __REG__ Register to be read
  773. * @retval Register value
  774. */
  775. #define LL_TIM_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  776. /**
  777. * @}
  778. */
  779. /** @defgroup TIM_LL_EM_Exported_Macros Exported Macros
  780. * @{
  781. */
  782. /**
  783. * @brief HELPER macro calculating DTG[0:7] in the TIMx_BDTR register to achieve the requested dead time duration.
  784. * @note ex: @ref __LL_TIM_CALC_DEADTIME (80000000, @ref LL_TIM_GetClockDivision (), 120);
  785. * @param __TIMCLK__ timer input clock frequency (in Hz)
  786. * @param __CKD__ This parameter can be one of the following values:
  787. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  788. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  789. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  790. * @param __DT__ deadtime duration (in ns)
  791. * @retval DTG[0:7]
  792. */
  793. #define __LL_TIM_CALC_DEADTIME(__TIMCLK__, __CKD__, __DT__) \
  794. ( (((uint64_t)((__DT__)*1000U)) < ((DT_DELAY_1+1U) * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? (uint8_t)(((uint64_t)((__DT__)*1000U) / TIM_CALC_DTS((__TIMCLK__), (__CKD__))) & DT_DELAY_1) : \
  795. (((uint64_t)((__DT__)*1000U)) < ((64U + (DT_DELAY_2+1U)) * 2U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? (uint8_t)(DT_RANGE_2 | ((uint8_t)((uint8_t)((((uint64_t)((__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), (__CKD__))) >> 1U) - (uint8_t) 64) & DT_DELAY_2)) :\
  796. (((uint64_t)((__DT__)*1000U)) < ((32U + (DT_DELAY_3+1U)) * 8U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? (uint8_t)(DT_RANGE_3 | ((uint8_t)((uint8_t)(((((uint64_t)(__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), (__CKD__))) >> 3U) - (uint8_t) 32) & DT_DELAY_3)) :\
  797. (((uint64_t)((__DT__)*1000U)) < ((32U + (DT_DELAY_4+1U)) * 16U * TIM_CALC_DTS((__TIMCLK__), (__CKD__)))) ? (uint8_t)(DT_RANGE_4 | ((uint8_t)((uint8_t)(((((uint64_t)(__DT__)*1000U))/ TIM_CALC_DTS((__TIMCLK__), (__CKD__))) >> 4U) - (uint8_t) 32) & DT_DELAY_4)) :\
  798. 0U)
  799. /**
  800. * @brief HELPER macro calculating the prescaler value to achieve the required counter clock frequency.
  801. * @note ex: @ref __LL_TIM_CALC_PSC (80000000, 1000000);
  802. * @param __TIMCLK__ timer input clock frequency (in Hz)
  803. * @param __CNTCLK__ counter clock frequency (in Hz)
  804. * @retval Prescaler value (between Min_Data=0 and Max_Data=65535)
  805. */
  806. #define __LL_TIM_CALC_PSC(__TIMCLK__, __CNTCLK__) \
  807. (((__TIMCLK__) >= (__CNTCLK__)) ? (uint32_t)(((__TIMCLK__)/(__CNTCLK__)) - 1U) : 0U)
  808. /**
  809. * @brief HELPER macro calculating the auto-reload value to achieve the required output signal frequency.
  810. * @note ex: @ref __LL_TIM_CALC_ARR (1000000, @ref LL_TIM_GetPrescaler (), 10000);
  811. * @param __TIMCLK__ timer input clock frequency (in Hz)
  812. * @param __PSC__ prescaler
  813. * @param __FREQ__ output signal frequency (in Hz)
  814. * @retval Auto-reload value (between Min_Data=0 and Max_Data=65535)
  815. */
  816. #define __LL_TIM_CALC_ARR(__TIMCLK__, __PSC__, __FREQ__) \
  817. ((((__TIMCLK__)/((__PSC__) + 1U)) >= (__FREQ__)) ? (((__TIMCLK__)/((__FREQ__) * ((__PSC__) + 1U))) - 1U) : 0U)
  818. /**
  819. * @brief HELPER macro calculating the compare value required to achieve the required timer output compare active/inactive delay.
  820. * @note ex: @ref __LL_TIM_CALC_DELAY (1000000, @ref LL_TIM_GetPrescaler (), 10);
  821. * @param __TIMCLK__ timer input clock frequency (in Hz)
  822. * @param __PSC__ prescaler
  823. * @param __DELAY__ timer output compare active/inactive delay (in us)
  824. * @retval Compare value (between Min_Data=0 and Max_Data=65535)
  825. */
  826. #define __LL_TIM_CALC_DELAY(__TIMCLK__, __PSC__, __DELAY__) \
  827. ((uint32_t)(((uint64_t)(__TIMCLK__) * (uint64_t)(__DELAY__)) \
  828. / ((uint64_t)1000000U * (uint64_t)((__PSC__) + 1U))))
  829. /**
  830. * @brief HELPER macro calculating the auto-reload value to achieve the required pulse duration (when the timer operates in one pulse mode).
  831. * @note ex: @ref __LL_TIM_CALC_PULSE (1000000, @ref LL_TIM_GetPrescaler (), 10, 20);
  832. * @param __TIMCLK__ timer input clock frequency (in Hz)
  833. * @param __PSC__ prescaler
  834. * @param __DELAY__ timer output compare active/inactive delay (in us)
  835. * @param __PULSE__ pulse duration (in us)
  836. * @retval Auto-reload value (between Min_Data=0 and Max_Data=65535)
  837. */
  838. #define __LL_TIM_CALC_PULSE(__TIMCLK__, __PSC__, __DELAY__, __PULSE__) \
  839. ((uint32_t)(__LL_TIM_CALC_DELAY((__TIMCLK__), (__PSC__), (__PULSE__)) \
  840. + __LL_TIM_CALC_DELAY((__TIMCLK__), (__PSC__), (__DELAY__))))
  841. /**
  842. * @brief HELPER macro retrieving the ratio of the input capture prescaler
  843. * @note ex: @ref __LL_TIM_GET_ICPSC_RATIO (@ref LL_TIM_IC_GetPrescaler ());
  844. * @param __ICPSC__ This parameter can be one of the following values:
  845. * @arg @ref LL_TIM_ICPSC_DIV1
  846. * @arg @ref LL_TIM_ICPSC_DIV2
  847. * @arg @ref LL_TIM_ICPSC_DIV4
  848. * @arg @ref LL_TIM_ICPSC_DIV8
  849. * @retval Input capture prescaler ratio (1, 2, 4 or 8)
  850. */
  851. #define __LL_TIM_GET_ICPSC_RATIO(__ICPSC__) \
  852. ((uint32_t)(0x01U << (((__ICPSC__) >> 16U) >> TIM_CCMR1_IC1PSC_Pos)))
  853. /**
  854. * @}
  855. */
  856. /**
  857. * @}
  858. */
  859. /* Exported functions --------------------------------------------------------*/
  860. /** @defgroup TIM_LL_Exported_Functions TIM Exported Functions
  861. * @{
  862. */
  863. /** @defgroup TIM_LL_EF_Time_Base Time Base configuration
  864. * @{
  865. */
  866. /**
  867. * @brief Enable timer counter.
  868. * @rmtoll CR1 CEN LL_TIM_EnableCounter
  869. * @param TIMx Timer instance
  870. * @retval None
  871. */
  872. __STATIC_INLINE void LL_TIM_EnableCounter(TIM_TypeDef *TIMx)
  873. {
  874. SET_BIT(TIMx->CR1, TIM_CR1_CEN);
  875. }
  876. /**
  877. * @brief Disable timer counter.
  878. * @rmtoll CR1 CEN LL_TIM_DisableCounter
  879. * @param TIMx Timer instance
  880. * @retval None
  881. */
  882. __STATIC_INLINE void LL_TIM_DisableCounter(TIM_TypeDef *TIMx)
  883. {
  884. CLEAR_BIT(TIMx->CR1, TIM_CR1_CEN);
  885. }
  886. /**
  887. * @brief Indicates whether the timer counter is enabled.
  888. * @rmtoll CR1 CEN LL_TIM_IsEnabledCounter
  889. * @param TIMx Timer instance
  890. * @retval State of bit (1 or 0).
  891. */
  892. __STATIC_INLINE uint32_t LL_TIM_IsEnabledCounter(TIM_TypeDef *TIMx)
  893. {
  894. return ((READ_BIT(TIMx->CR1, TIM_CR1_CEN) == (TIM_CR1_CEN)) ? 1UL : 0UL);
  895. }
  896. /**
  897. * @brief Enable update event generation.
  898. * @rmtoll CR1 UDIS LL_TIM_EnableUpdateEvent
  899. * @param TIMx Timer instance
  900. * @retval None
  901. */
  902. __STATIC_INLINE void LL_TIM_EnableUpdateEvent(TIM_TypeDef *TIMx)
  903. {
  904. CLEAR_BIT(TIMx->CR1, TIM_CR1_UDIS);
  905. }
  906. /**
  907. * @brief Disable update event generation.
  908. * @rmtoll CR1 UDIS LL_TIM_DisableUpdateEvent
  909. * @param TIMx Timer instance
  910. * @retval None
  911. */
  912. __STATIC_INLINE void LL_TIM_DisableUpdateEvent(TIM_TypeDef *TIMx)
  913. {
  914. SET_BIT(TIMx->CR1, TIM_CR1_UDIS);
  915. }
  916. /**
  917. * @brief Indicates whether update event generation is enabled.
  918. * @rmtoll CR1 UDIS LL_TIM_IsEnabledUpdateEvent
  919. * @param TIMx Timer instance
  920. * @retval Inverted state of bit (0 or 1).
  921. */
  922. __STATIC_INLINE uint32_t LL_TIM_IsEnabledUpdateEvent(TIM_TypeDef *TIMx)
  923. {
  924. return ((READ_BIT(TIMx->CR1, TIM_CR1_UDIS) == (uint32_t)RESET) ? 1UL : 0UL);
  925. }
  926. /**
  927. * @brief Set update event source
  928. * @note Update event source set to LL_TIM_UPDATESOURCE_REGULAR: any of the following events
  929. * generate an update interrupt or DMA request if enabled:
  930. * - Counter overflow/underflow
  931. * - Setting the UG bit
  932. * - Update generation through the slave mode controller
  933. * @note Update event source set to LL_TIM_UPDATESOURCE_COUNTER: only counter
  934. * overflow/underflow generates an update interrupt or DMA request if enabled.
  935. * @note Depending on devices and packages,DMA may not be available.
  936. * Refer to device datasheet for DMA availability.
  937. * @rmtoll CR1 URS LL_TIM_SetUpdateSource
  938. * @param TIMx Timer instance
  939. * @param UpdateSource This parameter can be one of the following values:
  940. * @arg @ref LL_TIM_UPDATESOURCE_REGULAR
  941. * @arg @ref LL_TIM_UPDATESOURCE_COUNTER
  942. * @retval None
  943. */
  944. __STATIC_INLINE void LL_TIM_SetUpdateSource(TIM_TypeDef *TIMx, uint32_t UpdateSource)
  945. {
  946. MODIFY_REG(TIMx->CR1, TIM_CR1_URS, UpdateSource);
  947. }
  948. /**
  949. * @brief Get actual event update source
  950. * @rmtoll CR1 URS LL_TIM_GetUpdateSource
  951. * @param TIMx Timer instance
  952. * @retval Returned value can be one of the following values:
  953. * @arg @ref LL_TIM_UPDATESOURCE_REGULAR
  954. * @arg @ref LL_TIM_UPDATESOURCE_COUNTER
  955. */
  956. __STATIC_INLINE uint32_t LL_TIM_GetUpdateSource(TIM_TypeDef *TIMx)
  957. {
  958. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_URS));
  959. }
  960. /**
  961. * @brief Set one pulse mode (one shot v.s. repetitive).
  962. * @rmtoll CR1 OPM LL_TIM_SetOnePulseMode
  963. * @param TIMx Timer instance
  964. * @param OnePulseMode This parameter can be one of the following values:
  965. * @arg @ref LL_TIM_ONEPULSEMODE_SINGLE
  966. * @arg @ref LL_TIM_ONEPULSEMODE_REPETITIVE
  967. * @retval None
  968. */
  969. __STATIC_INLINE void LL_TIM_SetOnePulseMode(TIM_TypeDef *TIMx, uint32_t OnePulseMode)
  970. {
  971. MODIFY_REG(TIMx->CR1, TIM_CR1_OPM, OnePulseMode);
  972. }
  973. /**
  974. * @brief Get actual one pulse mode.
  975. * @rmtoll CR1 OPM LL_TIM_GetOnePulseMode
  976. * @param TIMx Timer instance
  977. * @retval Returned value can be one of the following values:
  978. * @arg @ref LL_TIM_ONEPULSEMODE_SINGLE
  979. * @arg @ref LL_TIM_ONEPULSEMODE_REPETITIVE
  980. */
  981. __STATIC_INLINE uint32_t LL_TIM_GetOnePulseMode(TIM_TypeDef *TIMx)
  982. {
  983. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_OPM));
  984. }
  985. /**
  986. * @brief Set the timer counter counting mode.
  987. * @note Macro IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx) can be used to
  988. * check whether or not the counter mode selection feature is supported
  989. * by a timer instance.
  990. * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
  991. * requires a timer reset to avoid unexpected direction
  992. * due to DIR bit readonly in center aligned mode.
  993. * @rmtoll CR1 DIR LL_TIM_SetCounterMode\n
  994. * CR1 CMS LL_TIM_SetCounterMode
  995. * @param TIMx Timer instance
  996. * @param CounterMode This parameter can be one of the following values:
  997. * @arg @ref LL_TIM_COUNTERMODE_UP
  998. * @arg @ref LL_TIM_COUNTERMODE_DOWN
  999. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP
  1000. * @arg @ref LL_TIM_COUNTERMODE_CENTER_DOWN
  1001. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP_DOWN
  1002. * @retval None
  1003. */
  1004. __STATIC_INLINE void LL_TIM_SetCounterMode(TIM_TypeDef *TIMx, uint32_t CounterMode)
  1005. {
  1006. MODIFY_REG(TIMx->CR1, (TIM_CR1_DIR | TIM_CR1_CMS), CounterMode);
  1007. }
  1008. /**
  1009. * @brief Get actual counter mode.
  1010. * @note Macro IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx) can be used to
  1011. * check whether or not the counter mode selection feature is supported
  1012. * by a timer instance.
  1013. * @rmtoll CR1 DIR LL_TIM_GetCounterMode\n
  1014. * CR1 CMS LL_TIM_GetCounterMode
  1015. * @param TIMx Timer instance
  1016. * @retval Returned value can be one of the following values:
  1017. * @arg @ref LL_TIM_COUNTERMODE_UP
  1018. * @arg @ref LL_TIM_COUNTERMODE_DOWN
  1019. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP
  1020. * @arg @ref LL_TIM_COUNTERMODE_CENTER_DOWN
  1021. * @arg @ref LL_TIM_COUNTERMODE_CENTER_UP_DOWN
  1022. */
  1023. __STATIC_INLINE uint32_t LL_TIM_GetCounterMode(TIM_TypeDef *TIMx)
  1024. {
  1025. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_DIR | TIM_CR1_CMS));
  1026. }
  1027. /**
  1028. * @brief Enable auto-reload (ARR) preload.
  1029. * @rmtoll CR1 ARPE LL_TIM_EnableARRPreload
  1030. * @param TIMx Timer instance
  1031. * @retval None
  1032. */
  1033. __STATIC_INLINE void LL_TIM_EnableARRPreload(TIM_TypeDef *TIMx)
  1034. {
  1035. SET_BIT(TIMx->CR1, TIM_CR1_ARPE);
  1036. }
  1037. /**
  1038. * @brief Disable auto-reload (ARR) preload.
  1039. * @rmtoll CR1 ARPE LL_TIM_DisableARRPreload
  1040. * @param TIMx Timer instance
  1041. * @retval None
  1042. */
  1043. __STATIC_INLINE void LL_TIM_DisableARRPreload(TIM_TypeDef *TIMx)
  1044. {
  1045. CLEAR_BIT(TIMx->CR1, TIM_CR1_ARPE);
  1046. }
  1047. /**
  1048. * @brief Indicates whether auto-reload (ARR) preload is enabled.
  1049. * @rmtoll CR1 ARPE LL_TIM_IsEnabledARRPreload
  1050. * @param TIMx Timer instance
  1051. * @retval State of bit (1 or 0).
  1052. */
  1053. __STATIC_INLINE uint32_t LL_TIM_IsEnabledARRPreload(TIM_TypeDef *TIMx)
  1054. {
  1055. return ((READ_BIT(TIMx->CR1, TIM_CR1_ARPE) == (TIM_CR1_ARPE)) ? 1UL : 0UL);
  1056. }
  1057. /**
  1058. * @brief Set the division ratio between the timer clock and the sampling clock used by the dead-time generators (when supported) and the digital filters.
  1059. * @note Macro IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx) can be used to check
  1060. * whether or not the clock division feature is supported by the timer
  1061. * instance.
  1062. * @rmtoll CR1 CKD LL_TIM_SetClockDivision
  1063. * @param TIMx Timer instance
  1064. * @param ClockDivision This parameter can be one of the following values:
  1065. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  1066. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  1067. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  1068. * @retval None
  1069. */
  1070. __STATIC_INLINE void LL_TIM_SetClockDivision(TIM_TypeDef *TIMx, uint32_t ClockDivision)
  1071. {
  1072. MODIFY_REG(TIMx->CR1, TIM_CR1_CKD, ClockDivision);
  1073. }
  1074. /**
  1075. * @brief Get the actual division ratio between the timer clock and the sampling clock used by the dead-time generators (when supported) and the digital filters.
  1076. * @note Macro IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx) can be used to check
  1077. * whether or not the clock division feature is supported by the timer
  1078. * instance.
  1079. * @rmtoll CR1 CKD LL_TIM_GetClockDivision
  1080. * @param TIMx Timer instance
  1081. * @retval Returned value can be one of the following values:
  1082. * @arg @ref LL_TIM_CLOCKDIVISION_DIV1
  1083. * @arg @ref LL_TIM_CLOCKDIVISION_DIV2
  1084. * @arg @ref LL_TIM_CLOCKDIVISION_DIV4
  1085. */
  1086. __STATIC_INLINE uint32_t LL_TIM_GetClockDivision(TIM_TypeDef *TIMx)
  1087. {
  1088. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_CKD));
  1089. }
  1090. /**
  1091. * @brief Set the counter value.
  1092. * @rmtoll CNT CNT LL_TIM_SetCounter
  1093. * @param TIMx Timer instance
  1094. * @param Counter Counter value (between Min_Data=0 and Max_Data=0xFFFF)
  1095. * @retval None
  1096. */
  1097. __STATIC_INLINE void LL_TIM_SetCounter(TIM_TypeDef *TIMx, uint32_t Counter)
  1098. {
  1099. WRITE_REG(TIMx->CNT, Counter);
  1100. }
  1101. /**
  1102. * @brief Get the counter value.
  1103. * @rmtoll CNT CNT LL_TIM_GetCounter
  1104. * @param TIMx Timer instance
  1105. * @retval Counter value (between Min_Data=0 and Max_Data=0xFFFF)
  1106. */
  1107. __STATIC_INLINE uint32_t LL_TIM_GetCounter(TIM_TypeDef *TIMx)
  1108. {
  1109. return (uint32_t)(READ_REG(TIMx->CNT));
  1110. }
  1111. /**
  1112. * @brief Get the current direction of the counter
  1113. * @rmtoll CR1 DIR LL_TIM_GetDirection
  1114. * @param TIMx Timer instance
  1115. * @retval Returned value can be one of the following values:
  1116. * @arg @ref LL_TIM_COUNTERDIRECTION_UP
  1117. * @arg @ref LL_TIM_COUNTERDIRECTION_DOWN
  1118. */
  1119. __STATIC_INLINE uint32_t LL_TIM_GetDirection(TIM_TypeDef *TIMx)
  1120. {
  1121. return (uint32_t)(READ_BIT(TIMx->CR1, TIM_CR1_DIR));
  1122. }
  1123. /**
  1124. * @brief Set the prescaler value.
  1125. * @note The counter clock frequency CK_CNT is equal to fCK_PSC / (PSC[15:0] + 1).
  1126. * @note The prescaler can be changed on the fly as this control register is buffered. The new
  1127. * prescaler ratio is taken into account at the next update event.
  1128. * @note Helper macro @ref __LL_TIM_CALC_PSC can be used to calculate the Prescaler parameter
  1129. * @rmtoll PSC PSC LL_TIM_SetPrescaler
  1130. * @param TIMx Timer instance
  1131. * @param Prescaler between Min_Data=0 and Max_Data=65535
  1132. * @retval None
  1133. */
  1134. __STATIC_INLINE void LL_TIM_SetPrescaler(TIM_TypeDef *TIMx, uint32_t Prescaler)
  1135. {
  1136. WRITE_REG(TIMx->PSC, Prescaler);
  1137. }
  1138. /**
  1139. * @brief Get the prescaler value.
  1140. * @rmtoll PSC PSC LL_TIM_GetPrescaler
  1141. * @param TIMx Timer instance
  1142. * @retval Prescaler value between Min_Data=0 and Max_Data=65535
  1143. */
  1144. __STATIC_INLINE uint32_t LL_TIM_GetPrescaler(TIM_TypeDef *TIMx)
  1145. {
  1146. return (uint32_t)(READ_REG(TIMx->PSC));
  1147. }
  1148. /**
  1149. * @brief Set the auto-reload value.
  1150. * @note The counter is blocked while the auto-reload value is null.
  1151. * @note Helper macro @ref __LL_TIM_CALC_ARR can be used to calculate the AutoReload parameter
  1152. * @rmtoll ARR ARR LL_TIM_SetAutoReload
  1153. * @param TIMx Timer instance
  1154. * @param AutoReload between Min_Data=0 and Max_Data=65535
  1155. * @retval None
  1156. */
  1157. __STATIC_INLINE void LL_TIM_SetAutoReload(TIM_TypeDef *TIMx, uint32_t AutoReload)
  1158. {
  1159. WRITE_REG(TIMx->ARR, AutoReload);
  1160. }
  1161. /**
  1162. * @brief Get the auto-reload value.
  1163. * @rmtoll ARR ARR LL_TIM_GetAutoReload
  1164. * @param TIMx Timer instance
  1165. * @retval Auto-reload value
  1166. */
  1167. __STATIC_INLINE uint32_t LL_TIM_GetAutoReload(TIM_TypeDef *TIMx)
  1168. {
  1169. return (uint32_t)(READ_REG(TIMx->ARR));
  1170. }
  1171. /**
  1172. * @brief Set the repetition counter value.
  1173. * @note Macro IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx) can be used to check
  1174. * whether or not a timer instance supports a repetition counter.
  1175. * @rmtoll RCR REP LL_TIM_SetRepetitionCounter
  1176. * @param TIMx Timer instance
  1177. * @param RepetitionCounter between Min_Data=0 and Max_Data=255
  1178. * @retval None
  1179. */
  1180. __STATIC_INLINE void LL_TIM_SetRepetitionCounter(TIM_TypeDef *TIMx, uint32_t RepetitionCounter)
  1181. {
  1182. WRITE_REG(TIMx->RCR, RepetitionCounter);
  1183. }
  1184. /**
  1185. * @brief Get the repetition counter value.
  1186. * @note Macro IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx) can be used to check
  1187. * whether or not a timer instance supports a repetition counter.
  1188. * @rmtoll RCR REP LL_TIM_GetRepetitionCounter
  1189. * @param TIMx Timer instance
  1190. * @retval Repetition counter value
  1191. */
  1192. __STATIC_INLINE uint32_t LL_TIM_GetRepetitionCounter(TIM_TypeDef *TIMx)
  1193. {
  1194. return (uint32_t)(READ_REG(TIMx->RCR));
  1195. }
  1196. /**
  1197. * @}
  1198. */
  1199. /** @defgroup TIM_LL_EF_Capture_Compare Capture Compare configuration
  1200. * @{
  1201. */
  1202. /**
  1203. * @brief Enable the capture/compare control bits (CCxE, CCxNE and OCxM) preload.
  1204. * @note CCxE, CCxNE and OCxM bits are preloaded, after having been written,
  1205. * they are updated only when a commutation event (COM) occurs.
  1206. * @note Only on channels that have a complementary output.
  1207. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1208. * whether or not a timer instance is able to generate a commutation event.
  1209. * @rmtoll CR2 CCPC LL_TIM_CC_EnablePreload
  1210. * @param TIMx Timer instance
  1211. * @retval None
  1212. */
  1213. __STATIC_INLINE void LL_TIM_CC_EnablePreload(TIM_TypeDef *TIMx)
  1214. {
  1215. SET_BIT(TIMx->CR2, TIM_CR2_CCPC);
  1216. }
  1217. /**
  1218. * @brief Disable the capture/compare control bits (CCxE, CCxNE and OCxM) preload.
  1219. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1220. * whether or not a timer instance is able to generate a commutation event.
  1221. * @rmtoll CR2 CCPC LL_TIM_CC_DisablePreload
  1222. * @param TIMx Timer instance
  1223. * @retval None
  1224. */
  1225. __STATIC_INLINE void LL_TIM_CC_DisablePreload(TIM_TypeDef *TIMx)
  1226. {
  1227. CLEAR_BIT(TIMx->CR2, TIM_CR2_CCPC);
  1228. }
  1229. /**
  1230. * @brief Set the updated source of the capture/compare control bits (CCxE, CCxNE and OCxM).
  1231. * @note Macro IS_TIM_COMMUTATION_EVENT_INSTANCE(TIMx) can be used to check
  1232. * whether or not a timer instance is able to generate a commutation event.
  1233. * @rmtoll CR2 CCUS LL_TIM_CC_SetUpdate
  1234. * @param TIMx Timer instance
  1235. * @param CCUpdateSource This parameter can be one of the following values:
  1236. * @arg @ref LL_TIM_CCUPDATESOURCE_COMG_ONLY
  1237. * @arg @ref LL_TIM_CCUPDATESOURCE_COMG_AND_TRGI
  1238. * @retval None
  1239. */
  1240. __STATIC_INLINE void LL_TIM_CC_SetUpdate(TIM_TypeDef *TIMx, uint32_t CCUpdateSource)
  1241. {
  1242. MODIFY_REG(TIMx->CR2, TIM_CR2_CCUS, CCUpdateSource);
  1243. }
  1244. #if (defined(DMA) || defined(DMA1))
  1245. /**
  1246. * @brief Set the trigger of the capture/compare DMA request.
  1247. * @rmtoll CR2 CCDS LL_TIM_CC_SetDMAReqTrigger
  1248. * @param TIMx Timer instance
  1249. * @param DMAReqTrigger This parameter can be one of the following values:
  1250. * @arg @ref LL_TIM_CCDMAREQUEST_CC
  1251. * @arg @ref LL_TIM_CCDMAREQUEST_UPDATE
  1252. * @retval None
  1253. */
  1254. __STATIC_INLINE void LL_TIM_CC_SetDMAReqTrigger(TIM_TypeDef *TIMx, uint32_t DMAReqTrigger)
  1255. {
  1256. MODIFY_REG(TIMx->CR2, TIM_CR2_CCDS, DMAReqTrigger);
  1257. }
  1258. /**
  1259. * @brief Get actual trigger of the capture/compare DMA request.
  1260. * @rmtoll CR2 CCDS LL_TIM_CC_GetDMAReqTrigger
  1261. * @param TIMx Timer instance
  1262. * @retval Returned value can be one of the following values:
  1263. * @arg @ref LL_TIM_CCDMAREQUEST_CC
  1264. * @arg @ref LL_TIM_CCDMAREQUEST_UPDATE
  1265. */
  1266. __STATIC_INLINE uint32_t LL_TIM_CC_GetDMAReqTrigger(TIM_TypeDef *TIMx)
  1267. {
  1268. return (uint32_t)(READ_BIT(TIMx->CR2, TIM_CR2_CCDS));
  1269. }
  1270. #endif
  1271. /**
  1272. * @brief Set the lock level to freeze the
  1273. * configuration of several capture/compare parameters.
  1274. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  1275. * the lock mechanism is supported by a timer instance.
  1276. * @rmtoll BDTR LOCK LL_TIM_CC_SetLockLevel
  1277. * @param TIMx Timer instance
  1278. * @param LockLevel This parameter can be one of the following values:
  1279. * @arg @ref LL_TIM_LOCKLEVEL_OFF
  1280. * @arg @ref LL_TIM_LOCKLEVEL_1
  1281. * @arg @ref LL_TIM_LOCKLEVEL_2
  1282. * @arg @ref LL_TIM_LOCKLEVEL_3
  1283. * @retval None
  1284. */
  1285. __STATIC_INLINE void LL_TIM_CC_SetLockLevel(TIM_TypeDef *TIMx, uint32_t LockLevel)
  1286. {
  1287. MODIFY_REG(TIMx->BDTR, TIM_BDTR_LOCK, LockLevel);
  1288. }
  1289. /**
  1290. * @brief Enable capture/compare channels.
  1291. * @rmtoll CCER CC1E LL_TIM_CC_EnableChannel\n
  1292. * CCER CC1NE LL_TIM_CC_EnableChannel\n
  1293. * CCER CC2E LL_TIM_CC_EnableChannel\n
  1294. * CCER CC2NE LL_TIM_CC_EnableChannel\n
  1295. * CCER CC3E LL_TIM_CC_EnableChannel\n
  1296. * CCER CC3NE LL_TIM_CC_EnableChannel\n
  1297. * CCER CC4E LL_TIM_CC_EnableChannel
  1298. * @param TIMx Timer instance
  1299. * @param Channels This parameter can be a combination of the following values:
  1300. * @arg @ref LL_TIM_CHANNEL_CH1
  1301. * @arg @ref LL_TIM_CHANNEL_CH1N
  1302. * @arg @ref LL_TIM_CHANNEL_CH2
  1303. * @arg @ref LL_TIM_CHANNEL_CH2N
  1304. * @arg @ref LL_TIM_CHANNEL_CH3
  1305. * @arg @ref LL_TIM_CHANNEL_CH3N
  1306. * @arg @ref LL_TIM_CHANNEL_CH4
  1307. * @retval None
  1308. */
  1309. __STATIC_INLINE void LL_TIM_CC_EnableChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1310. {
  1311. SET_BIT(TIMx->CCER, Channels);
  1312. }
  1313. /**
  1314. * @brief Disable capture/compare channels.
  1315. * @rmtoll CCER CC1E LL_TIM_CC_DisableChannel\n
  1316. * CCER CC1NE LL_TIM_CC_DisableChannel\n
  1317. * CCER CC2E LL_TIM_CC_DisableChannel\n
  1318. * CCER CC2NE LL_TIM_CC_DisableChannel\n
  1319. * CCER CC3E LL_TIM_CC_DisableChannel\n
  1320. * CCER CC3NE LL_TIM_CC_DisableChannel\n
  1321. * CCER CC4E LL_TIM_CC_DisableChannel
  1322. * @param TIMx Timer instance
  1323. * @param Channels This parameter can be a combination of the following values:
  1324. * @arg @ref LL_TIM_CHANNEL_CH1
  1325. * @arg @ref LL_TIM_CHANNEL_CH1N
  1326. * @arg @ref LL_TIM_CHANNEL_CH2
  1327. * @arg @ref LL_TIM_CHANNEL_CH2N
  1328. * @arg @ref LL_TIM_CHANNEL_CH3
  1329. * @arg @ref LL_TIM_CHANNEL_CH3N
  1330. * @arg @ref LL_TIM_CHANNEL_CH4
  1331. * @retval None
  1332. */
  1333. __STATIC_INLINE void LL_TIM_CC_DisableChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1334. {
  1335. CLEAR_BIT(TIMx->CCER, Channels);
  1336. }
  1337. /**
  1338. * @brief Indicate whether channel(s) is(are) enabled.
  1339. * @rmtoll CCER CC1E LL_TIM_CC_IsEnabledChannel\n
  1340. * CCER CC1NE LL_TIM_CC_IsEnabledChannel\n
  1341. * CCER CC2E LL_TIM_CC_IsEnabledChannel\n
  1342. * CCER CC2NE LL_TIM_CC_IsEnabledChannel\n
  1343. * CCER CC3E LL_TIM_CC_IsEnabledChannel\n
  1344. * CCER CC3NE LL_TIM_CC_IsEnabledChannel\n
  1345. * CCER CC4E LL_TIM_CC_IsEnabledChannel
  1346. * @param TIMx Timer instance
  1347. * @param Channels This parameter can be a combination of the following values:
  1348. * @arg @ref LL_TIM_CHANNEL_CH1
  1349. * @arg @ref LL_TIM_CHANNEL_CH1N
  1350. * @arg @ref LL_TIM_CHANNEL_CH2
  1351. * @arg @ref LL_TIM_CHANNEL_CH2N
  1352. * @arg @ref LL_TIM_CHANNEL_CH3
  1353. * @arg @ref LL_TIM_CHANNEL_CH3N
  1354. * @arg @ref LL_TIM_CHANNEL_CH4
  1355. * @retval State of bit (1 or 0).
  1356. */
  1357. __STATIC_INLINE uint32_t LL_TIM_CC_IsEnabledChannel(TIM_TypeDef *TIMx, uint32_t Channels)
  1358. {
  1359. return ((READ_BIT(TIMx->CCER, Channels) == (Channels)) ? 1UL : 0UL);
  1360. }
  1361. /**
  1362. * @}
  1363. */
  1364. /** @defgroup TIM_LL_EF_Output_Channel Output channel configuration
  1365. * @{
  1366. */
  1367. /**
  1368. * @brief Configure an output channel.
  1369. * @rmtoll CCMR1 CC1S LL_TIM_OC_ConfigOutput\n
  1370. * CCMR1 CC2S LL_TIM_OC_ConfigOutput\n
  1371. * CCMR2 CC3S LL_TIM_OC_ConfigOutput\n
  1372. * CCMR2 CC4S LL_TIM_OC_ConfigOutput\n
  1373. * CCER CC1P LL_TIM_OC_ConfigOutput\n
  1374. * CCER CC2P LL_TIM_OC_ConfigOutput\n
  1375. * CCER CC3P LL_TIM_OC_ConfigOutput\n
  1376. * CCER CC4P LL_TIM_OC_ConfigOutput\n
  1377. * CR2 OIS1 LL_TIM_OC_ConfigOutput\n
  1378. * CR2 OIS2 LL_TIM_OC_ConfigOutput\n
  1379. * CR2 OIS3 LL_TIM_OC_ConfigOutput\n
  1380. * CR2 OIS4 LL_TIM_OC_ConfigOutput
  1381. * @param TIMx Timer instance
  1382. * @param Channel This parameter can be one of the following values:
  1383. * @arg @ref LL_TIM_CHANNEL_CH1
  1384. * @arg @ref LL_TIM_CHANNEL_CH2
  1385. * @arg @ref LL_TIM_CHANNEL_CH3
  1386. * @arg @ref LL_TIM_CHANNEL_CH4
  1387. * @param Configuration This parameter must be a combination of all the following values:
  1388. * @arg @ref LL_TIM_OCPOLARITY_HIGH or @ref LL_TIM_OCPOLARITY_LOW
  1389. * @arg @ref LL_TIM_OCIDLESTATE_LOW or @ref LL_TIM_OCIDLESTATE_HIGH
  1390. * @retval None
  1391. */
  1392. __STATIC_INLINE void LL_TIM_OC_ConfigOutput(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Configuration)
  1393. {
  1394. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1395. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1396. CLEAR_BIT(*pReg, (TIM_CCMR1_CC1S << SHIFT_TAB_OCxx[iChannel]));
  1397. MODIFY_REG(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel]),
  1398. (Configuration & TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]);
  1399. MODIFY_REG(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel]),
  1400. (Configuration & TIM_CR2_OIS1) << SHIFT_TAB_OISx[iChannel]);
  1401. }
  1402. /**
  1403. * @brief Define the behavior of the output reference signal OCxREF from which
  1404. * OCx and OCxN (when relevant) are derived.
  1405. * @rmtoll CCMR1 OC1M LL_TIM_OC_SetMode\n
  1406. * CCMR1 OC2M LL_TIM_OC_SetMode\n
  1407. * CCMR2 OC3M LL_TIM_OC_SetMode\n
  1408. * CCMR2 OC4M LL_TIM_OC_SetMode
  1409. * @param TIMx Timer instance
  1410. * @param Channel This parameter can be one of the following values:
  1411. * @arg @ref LL_TIM_CHANNEL_CH1
  1412. * @arg @ref LL_TIM_CHANNEL_CH2
  1413. * @arg @ref LL_TIM_CHANNEL_CH3
  1414. * @arg @ref LL_TIM_CHANNEL_CH4
  1415. * @param Mode This parameter can be one of the following values:
  1416. * @arg @ref LL_TIM_OCMODE_FROZEN
  1417. * @arg @ref LL_TIM_OCMODE_ACTIVE
  1418. * @arg @ref LL_TIM_OCMODE_INACTIVE
  1419. * @arg @ref LL_TIM_OCMODE_TOGGLE
  1420. * @arg @ref LL_TIM_OCMODE_FORCED_INACTIVE
  1421. * @arg @ref LL_TIM_OCMODE_FORCED_ACTIVE
  1422. * @arg @ref LL_TIM_OCMODE_PWM1
  1423. * @arg @ref LL_TIM_OCMODE_PWM2
  1424. * @retval None
  1425. */
  1426. __STATIC_INLINE void LL_TIM_OC_SetMode(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Mode)
  1427. {
  1428. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1429. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1430. MODIFY_REG(*pReg, ((TIM_CCMR1_OC1M | TIM_CCMR1_CC1S) << SHIFT_TAB_OCxx[iChannel]), Mode << SHIFT_TAB_OCxx[iChannel]);
  1431. }
  1432. /**
  1433. * @brief Get the output compare mode of an output channel.
  1434. * @rmtoll CCMR1 OC1M LL_TIM_OC_GetMode\n
  1435. * CCMR1 OC2M LL_TIM_OC_GetMode\n
  1436. * CCMR2 OC3M LL_TIM_OC_GetMode\n
  1437. * CCMR2 OC4M LL_TIM_OC_GetMode
  1438. * @param TIMx Timer instance
  1439. * @param Channel This parameter can be one of the following values:
  1440. * @arg @ref LL_TIM_CHANNEL_CH1
  1441. * @arg @ref LL_TIM_CHANNEL_CH2
  1442. * @arg @ref LL_TIM_CHANNEL_CH3
  1443. * @arg @ref LL_TIM_CHANNEL_CH4
  1444. * @retval Returned value can be one of the following values:
  1445. * @arg @ref LL_TIM_OCMODE_FROZEN
  1446. * @arg @ref LL_TIM_OCMODE_ACTIVE
  1447. * @arg @ref LL_TIM_OCMODE_INACTIVE
  1448. * @arg @ref LL_TIM_OCMODE_TOGGLE
  1449. * @arg @ref LL_TIM_OCMODE_FORCED_INACTIVE
  1450. * @arg @ref LL_TIM_OCMODE_FORCED_ACTIVE
  1451. * @arg @ref LL_TIM_OCMODE_PWM1
  1452. * @arg @ref LL_TIM_OCMODE_PWM2
  1453. */
  1454. __STATIC_INLINE uint32_t LL_TIM_OC_GetMode(TIM_TypeDef *TIMx, uint32_t Channel)
  1455. {
  1456. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1457. register const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1458. return (READ_BIT(*pReg, ((TIM_CCMR1_OC1M | TIM_CCMR1_CC1S) << SHIFT_TAB_OCxx[iChannel])) >> SHIFT_TAB_OCxx[iChannel]);
  1459. }
  1460. /**
  1461. * @brief Set the polarity of an output channel.
  1462. * @rmtoll CCER CC1P LL_TIM_OC_SetPolarity\n
  1463. * CCER CC1NP LL_TIM_OC_SetPolarity\n
  1464. * CCER CC2P LL_TIM_OC_SetPolarity\n
  1465. * CCER CC2NP LL_TIM_OC_SetPolarity\n
  1466. * CCER CC3P LL_TIM_OC_SetPolarity\n
  1467. * CCER CC3NP LL_TIM_OC_SetPolarity\n
  1468. * CCER CC4P LL_TIM_OC_SetPolarity
  1469. * @param TIMx Timer instance
  1470. * @param Channel This parameter can be one of the following values:
  1471. * @arg @ref LL_TIM_CHANNEL_CH1
  1472. * @arg @ref LL_TIM_CHANNEL_CH1N
  1473. * @arg @ref LL_TIM_CHANNEL_CH2
  1474. * @arg @ref LL_TIM_CHANNEL_CH2N
  1475. * @arg @ref LL_TIM_CHANNEL_CH3
  1476. * @arg @ref LL_TIM_CHANNEL_CH3N
  1477. * @arg @ref LL_TIM_CHANNEL_CH4
  1478. * @param Polarity This parameter can be one of the following values:
  1479. * @arg @ref LL_TIM_OCPOLARITY_HIGH
  1480. * @arg @ref LL_TIM_OCPOLARITY_LOW
  1481. * @retval None
  1482. */
  1483. __STATIC_INLINE void LL_TIM_OC_SetPolarity(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Polarity)
  1484. {
  1485. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1486. MODIFY_REG(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel]), Polarity << SHIFT_TAB_CCxP[iChannel]);
  1487. }
  1488. /**
  1489. * @brief Get the polarity of an output channel.
  1490. * @rmtoll CCER CC1P LL_TIM_OC_GetPolarity\n
  1491. * CCER CC1NP LL_TIM_OC_GetPolarity\n
  1492. * CCER CC2P LL_TIM_OC_GetPolarity\n
  1493. * CCER CC2NP LL_TIM_OC_GetPolarity\n
  1494. * CCER CC3P LL_TIM_OC_GetPolarity\n
  1495. * CCER CC3NP LL_TIM_OC_GetPolarity\n
  1496. * CCER CC4P LL_TIM_OC_GetPolarity
  1497. * @param TIMx Timer instance
  1498. * @param Channel This parameter can be one of the following values:
  1499. * @arg @ref LL_TIM_CHANNEL_CH1
  1500. * @arg @ref LL_TIM_CHANNEL_CH1N
  1501. * @arg @ref LL_TIM_CHANNEL_CH2
  1502. * @arg @ref LL_TIM_CHANNEL_CH2N
  1503. * @arg @ref LL_TIM_CHANNEL_CH3
  1504. * @arg @ref LL_TIM_CHANNEL_CH3N
  1505. * @arg @ref LL_TIM_CHANNEL_CH4
  1506. * @retval Returned value can be one of the following values:
  1507. * @arg @ref LL_TIM_OCPOLARITY_HIGH
  1508. * @arg @ref LL_TIM_OCPOLARITY_LOW
  1509. */
  1510. __STATIC_INLINE uint32_t LL_TIM_OC_GetPolarity(TIM_TypeDef *TIMx, uint32_t Channel)
  1511. {
  1512. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1513. return (READ_BIT(TIMx->CCER, (TIM_CCER_CC1P << SHIFT_TAB_CCxP[iChannel])) >> SHIFT_TAB_CCxP[iChannel]);
  1514. }
  1515. /**
  1516. * @brief Set the IDLE state of an output channel
  1517. * @note This function is significant only for the timer instances
  1518. * supporting the break feature. Macro IS_TIM_BREAK_INSTANCE(TIMx)
  1519. * can be used to check whether or not a timer instance provides
  1520. * a break input.
  1521. * @rmtoll CR2 OIS1 LL_TIM_OC_SetIdleState\n
  1522. * CR2 OIS1N LL_TIM_OC_SetIdleState\n
  1523. * CR2 OIS2 LL_TIM_OC_SetIdleState\n
  1524. * CR2 OIS2N LL_TIM_OC_SetIdleState\n
  1525. * CR2 OIS3 LL_TIM_OC_SetIdleState\n
  1526. * CR2 OIS3N LL_TIM_OC_SetIdleState\n
  1527. * CR2 OIS4 LL_TIM_OC_SetIdleState
  1528. * @param TIMx Timer instance
  1529. * @param Channel This parameter can be one of the following values:
  1530. * @arg @ref LL_TIM_CHANNEL_CH1
  1531. * @arg @ref LL_TIM_CHANNEL_CH1N
  1532. * @arg @ref LL_TIM_CHANNEL_CH2
  1533. * @arg @ref LL_TIM_CHANNEL_CH2N
  1534. * @arg @ref LL_TIM_CHANNEL_CH3
  1535. * @arg @ref LL_TIM_CHANNEL_CH3N
  1536. * @arg @ref LL_TIM_CHANNEL_CH4
  1537. * @param IdleState This parameter can be one of the following values:
  1538. * @arg @ref LL_TIM_OCIDLESTATE_LOW
  1539. * @arg @ref LL_TIM_OCIDLESTATE_HIGH
  1540. * @retval None
  1541. */
  1542. __STATIC_INLINE void LL_TIM_OC_SetIdleState(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t IdleState)
  1543. {
  1544. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1545. MODIFY_REG(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel]), IdleState << SHIFT_TAB_OISx[iChannel]);
  1546. }
  1547. /**
  1548. * @brief Get the IDLE state of an output channel
  1549. * @rmtoll CR2 OIS1 LL_TIM_OC_GetIdleState\n
  1550. * CR2 OIS1N LL_TIM_OC_GetIdleState\n
  1551. * CR2 OIS2 LL_TIM_OC_GetIdleState\n
  1552. * CR2 OIS2N LL_TIM_OC_GetIdleState\n
  1553. * CR2 OIS3 LL_TIM_OC_GetIdleState\n
  1554. * CR2 OIS3N LL_TIM_OC_GetIdleState\n
  1555. * CR2 OIS4 LL_TIM_OC_GetIdleState
  1556. * @param TIMx Timer instance
  1557. * @param Channel This parameter can be one of the following values:
  1558. * @arg @ref LL_TIM_CHANNEL_CH1
  1559. * @arg @ref LL_TIM_CHANNEL_CH1N
  1560. * @arg @ref LL_TIM_CHANNEL_CH2
  1561. * @arg @ref LL_TIM_CHANNEL_CH2N
  1562. * @arg @ref LL_TIM_CHANNEL_CH3
  1563. * @arg @ref LL_TIM_CHANNEL_CH3N
  1564. * @arg @ref LL_TIM_CHANNEL_CH4
  1565. * @retval Returned value can be one of the following values:
  1566. * @arg @ref LL_TIM_OCIDLESTATE_LOW
  1567. * @arg @ref LL_TIM_OCIDLESTATE_HIGH
  1568. */
  1569. __STATIC_INLINE uint32_t LL_TIM_OC_GetIdleState(TIM_TypeDef *TIMx, uint32_t Channel)
  1570. {
  1571. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1572. return (READ_BIT(TIMx->CR2, (TIM_CR2_OIS1 << SHIFT_TAB_OISx[iChannel])) >> SHIFT_TAB_OISx[iChannel]);
  1573. }
  1574. /**
  1575. * @brief Enable fast mode for the output channel.
  1576. * @note Acts only if the channel is configured in PWM1 or PWM2 mode.
  1577. * @rmtoll CCMR1 OC1FE LL_TIM_OC_EnableFast\n
  1578. * CCMR1 OC2FE LL_TIM_OC_EnableFast\n
  1579. * CCMR2 OC3FE LL_TIM_OC_EnableFast\n
  1580. * CCMR2 OC4FE LL_TIM_OC_EnableFast
  1581. * @param TIMx Timer instance
  1582. * @param Channel This parameter can be one of the following values:
  1583. * @arg @ref LL_TIM_CHANNEL_CH1
  1584. * @arg @ref LL_TIM_CHANNEL_CH2
  1585. * @arg @ref LL_TIM_CHANNEL_CH3
  1586. * @arg @ref LL_TIM_CHANNEL_CH4
  1587. * @retval None
  1588. */
  1589. __STATIC_INLINE void LL_TIM_OC_EnableFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1590. {
  1591. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1592. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1593. SET_BIT(*pReg, (TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel]));
  1594. }
  1595. /**
  1596. * @brief Disable fast mode for the output channel.
  1597. * @rmtoll CCMR1 OC1FE LL_TIM_OC_DisableFast\n
  1598. * CCMR1 OC2FE LL_TIM_OC_DisableFast\n
  1599. * CCMR2 OC3FE LL_TIM_OC_DisableFast\n
  1600. * CCMR2 OC4FE LL_TIM_OC_DisableFast
  1601. * @param TIMx Timer instance
  1602. * @param Channel This parameter can be one of the following values:
  1603. * @arg @ref LL_TIM_CHANNEL_CH1
  1604. * @arg @ref LL_TIM_CHANNEL_CH2
  1605. * @arg @ref LL_TIM_CHANNEL_CH3
  1606. * @arg @ref LL_TIM_CHANNEL_CH4
  1607. * @retval None
  1608. */
  1609. __STATIC_INLINE void LL_TIM_OC_DisableFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1610. {
  1611. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1612. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1613. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel]));
  1614. }
  1615. /**
  1616. * @brief Indicates whether fast mode is enabled for the output channel.
  1617. * @rmtoll CCMR1 OC1FE LL_TIM_OC_IsEnabledFast\n
  1618. * CCMR1 OC2FE LL_TIM_OC_IsEnabledFast\n
  1619. * CCMR2 OC3FE LL_TIM_OC_IsEnabledFast\n
  1620. * CCMR2 OC4FE LL_TIM_OC_IsEnabledFast\n
  1621. * @param TIMx Timer instance
  1622. * @param Channel This parameter can be one of the following values:
  1623. * @arg @ref LL_TIM_CHANNEL_CH1
  1624. * @arg @ref LL_TIM_CHANNEL_CH2
  1625. * @arg @ref LL_TIM_CHANNEL_CH3
  1626. * @arg @ref LL_TIM_CHANNEL_CH4
  1627. * @retval State of bit (1 or 0).
  1628. */
  1629. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledFast(TIM_TypeDef *TIMx, uint32_t Channel)
  1630. {
  1631. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1632. register const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1633. register uint32_t bitfield = TIM_CCMR1_OC1FE << SHIFT_TAB_OCxx[iChannel];
  1634. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1635. }
  1636. /**
  1637. * @brief Enable compare register (TIMx_CCRx) preload for the output channel.
  1638. * @rmtoll CCMR1 OC1PE LL_TIM_OC_EnablePreload\n
  1639. * CCMR1 OC2PE LL_TIM_OC_EnablePreload\n
  1640. * CCMR2 OC3PE LL_TIM_OC_EnablePreload\n
  1641. * CCMR2 OC4PE LL_TIM_OC_EnablePreload
  1642. * @param TIMx Timer instance
  1643. * @param Channel This parameter can be one of the following values:
  1644. * @arg @ref LL_TIM_CHANNEL_CH1
  1645. * @arg @ref LL_TIM_CHANNEL_CH2
  1646. * @arg @ref LL_TIM_CHANNEL_CH3
  1647. * @arg @ref LL_TIM_CHANNEL_CH4
  1648. * @retval None
  1649. */
  1650. __STATIC_INLINE void LL_TIM_OC_EnablePreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1651. {
  1652. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1653. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1654. SET_BIT(*pReg, (TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel]));
  1655. }
  1656. /**
  1657. * @brief Disable compare register (TIMx_CCRx) preload for the output channel.
  1658. * @rmtoll CCMR1 OC1PE LL_TIM_OC_DisablePreload\n
  1659. * CCMR1 OC2PE LL_TIM_OC_DisablePreload\n
  1660. * CCMR2 OC3PE LL_TIM_OC_DisablePreload\n
  1661. * CCMR2 OC4PE LL_TIM_OC_DisablePreload
  1662. * @param TIMx Timer instance
  1663. * @param Channel This parameter can be one of the following values:
  1664. * @arg @ref LL_TIM_CHANNEL_CH1
  1665. * @arg @ref LL_TIM_CHANNEL_CH2
  1666. * @arg @ref LL_TIM_CHANNEL_CH3
  1667. * @arg @ref LL_TIM_CHANNEL_CH4
  1668. * @retval None
  1669. */
  1670. __STATIC_INLINE void LL_TIM_OC_DisablePreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1671. {
  1672. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1673. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1674. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel]));
  1675. }
  1676. /**
  1677. * @brief Indicates whether compare register (TIMx_CCRx) preload is enabled for the output channel.
  1678. * @rmtoll CCMR1 OC1PE LL_TIM_OC_IsEnabledPreload\n
  1679. * CCMR1 OC2PE LL_TIM_OC_IsEnabledPreload\n
  1680. * CCMR2 OC3PE LL_TIM_OC_IsEnabledPreload\n
  1681. * CCMR2 OC4PE LL_TIM_OC_IsEnabledPreload\n
  1682. * @param TIMx Timer instance
  1683. * @param Channel This parameter can be one of the following values:
  1684. * @arg @ref LL_TIM_CHANNEL_CH1
  1685. * @arg @ref LL_TIM_CHANNEL_CH2
  1686. * @arg @ref LL_TIM_CHANNEL_CH3
  1687. * @arg @ref LL_TIM_CHANNEL_CH4
  1688. * @retval State of bit (1 or 0).
  1689. */
  1690. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledPreload(TIM_TypeDef *TIMx, uint32_t Channel)
  1691. {
  1692. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1693. register const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1694. register uint32_t bitfield = TIM_CCMR1_OC1PE << SHIFT_TAB_OCxx[iChannel];
  1695. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1696. }
  1697. /**
  1698. * @brief Enable clearing the output channel on an external event.
  1699. * @note This function can only be used in Output compare and PWM modes. It does not work in Forced mode.
  1700. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1701. * or not a timer instance can clear the OCxREF signal on an external event.
  1702. * @rmtoll CCMR1 OC1CE LL_TIM_OC_EnableClear\n
  1703. * CCMR1 OC2CE LL_TIM_OC_EnableClear\n
  1704. * CCMR2 OC3CE LL_TIM_OC_EnableClear\n
  1705. * CCMR2 OC4CE LL_TIM_OC_EnableClear
  1706. * @param TIMx Timer instance
  1707. * @param Channel This parameter can be one of the following values:
  1708. * @arg @ref LL_TIM_CHANNEL_CH1
  1709. * @arg @ref LL_TIM_CHANNEL_CH2
  1710. * @arg @ref LL_TIM_CHANNEL_CH3
  1711. * @arg @ref LL_TIM_CHANNEL_CH4
  1712. * @retval None
  1713. */
  1714. __STATIC_INLINE void LL_TIM_OC_EnableClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1715. {
  1716. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1717. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1718. SET_BIT(*pReg, (TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel]));
  1719. }
  1720. /**
  1721. * @brief Disable clearing the output channel on an external event.
  1722. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1723. * or not a timer instance can clear the OCxREF signal on an external event.
  1724. * @rmtoll CCMR1 OC1CE LL_TIM_OC_DisableClear\n
  1725. * CCMR1 OC2CE LL_TIM_OC_DisableClear\n
  1726. * CCMR2 OC3CE LL_TIM_OC_DisableClear\n
  1727. * CCMR2 OC4CE LL_TIM_OC_DisableClear
  1728. * @param TIMx Timer instance
  1729. * @param Channel This parameter can be one of the following values:
  1730. * @arg @ref LL_TIM_CHANNEL_CH1
  1731. * @arg @ref LL_TIM_CHANNEL_CH2
  1732. * @arg @ref LL_TIM_CHANNEL_CH3
  1733. * @arg @ref LL_TIM_CHANNEL_CH4
  1734. * @retval None
  1735. */
  1736. __STATIC_INLINE void LL_TIM_OC_DisableClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1737. {
  1738. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1739. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1740. CLEAR_BIT(*pReg, (TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel]));
  1741. }
  1742. /**
  1743. * @brief Indicates clearing the output channel on an external event is enabled for the output channel.
  1744. * @note This function enables clearing the output channel on an external event.
  1745. * @note This function can only be used in Output compare and PWM modes. It does not work in Forced mode.
  1746. * @note Macro IS_TIM_OCXREF_CLEAR_INSTANCE(TIMx) can be used to check whether
  1747. * or not a timer instance can clear the OCxREF signal on an external event.
  1748. * @rmtoll CCMR1 OC1CE LL_TIM_OC_IsEnabledClear\n
  1749. * CCMR1 OC2CE LL_TIM_OC_IsEnabledClear\n
  1750. * CCMR2 OC3CE LL_TIM_OC_IsEnabledClear\n
  1751. * CCMR2 OC4CE LL_TIM_OC_IsEnabledClear\n
  1752. * @param TIMx Timer instance
  1753. * @param Channel This parameter can be one of the following values:
  1754. * @arg @ref LL_TIM_CHANNEL_CH1
  1755. * @arg @ref LL_TIM_CHANNEL_CH2
  1756. * @arg @ref LL_TIM_CHANNEL_CH3
  1757. * @arg @ref LL_TIM_CHANNEL_CH4
  1758. * @retval State of bit (1 or 0).
  1759. */
  1760. __STATIC_INLINE uint32_t LL_TIM_OC_IsEnabledClear(TIM_TypeDef *TIMx, uint32_t Channel)
  1761. {
  1762. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1763. register const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1764. register uint32_t bitfield = TIM_CCMR1_OC1CE << SHIFT_TAB_OCxx[iChannel];
  1765. return ((READ_BIT(*pReg, bitfield) == bitfield) ? 1UL : 0UL);
  1766. }
  1767. /**
  1768. * @brief Set the dead-time delay (delay inserted between the rising edge of the OCxREF signal and the rising edge of the Ocx and OCxN signals).
  1769. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  1770. * dead-time insertion feature is supported by a timer instance.
  1771. * @note Helper macro @ref __LL_TIM_CALC_DEADTIME can be used to calculate the DeadTime parameter
  1772. * @rmtoll BDTR DTG LL_TIM_OC_SetDeadTime
  1773. * @param TIMx Timer instance
  1774. * @param DeadTime between Min_Data=0 and Max_Data=255
  1775. * @retval None
  1776. */
  1777. __STATIC_INLINE void LL_TIM_OC_SetDeadTime(TIM_TypeDef *TIMx, uint32_t DeadTime)
  1778. {
  1779. MODIFY_REG(TIMx->BDTR, TIM_BDTR_DTG, DeadTime);
  1780. }
  1781. /**
  1782. * @brief Set compare value for output channel 1 (TIMx_CCR1).
  1783. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  1784. * output channel 1 is supported by a timer instance.
  1785. * @rmtoll CCR1 CCR1 LL_TIM_OC_SetCompareCH1
  1786. * @param TIMx Timer instance
  1787. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1788. * @retval None
  1789. */
  1790. __STATIC_INLINE void LL_TIM_OC_SetCompareCH1(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1791. {
  1792. WRITE_REG(TIMx->CCR1, CompareValue);
  1793. }
  1794. /**
  1795. * @brief Set compare value for output channel 2 (TIMx_CCR2).
  1796. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  1797. * output channel 2 is supported by a timer instance.
  1798. * @rmtoll CCR2 CCR2 LL_TIM_OC_SetCompareCH2
  1799. * @param TIMx Timer instance
  1800. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1801. * @retval None
  1802. */
  1803. __STATIC_INLINE void LL_TIM_OC_SetCompareCH2(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1804. {
  1805. WRITE_REG(TIMx->CCR2, CompareValue);
  1806. }
  1807. /**
  1808. * @brief Set compare value for output channel 3 (TIMx_CCR3).
  1809. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  1810. * output channel is supported by a timer instance.
  1811. * @rmtoll CCR3 CCR3 LL_TIM_OC_SetCompareCH3
  1812. * @param TIMx Timer instance
  1813. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1814. * @retval None
  1815. */
  1816. __STATIC_INLINE void LL_TIM_OC_SetCompareCH3(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1817. {
  1818. WRITE_REG(TIMx->CCR3, CompareValue);
  1819. }
  1820. /**
  1821. * @brief Set compare value for output channel 4 (TIMx_CCR4).
  1822. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  1823. * output channel 4 is supported by a timer instance.
  1824. * @rmtoll CCR4 CCR4 LL_TIM_OC_SetCompareCH4
  1825. * @param TIMx Timer instance
  1826. * @param CompareValue between Min_Data=0 and Max_Data=65535
  1827. * @retval None
  1828. */
  1829. __STATIC_INLINE void LL_TIM_OC_SetCompareCH4(TIM_TypeDef *TIMx, uint32_t CompareValue)
  1830. {
  1831. WRITE_REG(TIMx->CCR4, CompareValue);
  1832. }
  1833. /**
  1834. * @brief Get compare value (TIMx_CCR1) set for output channel 1.
  1835. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  1836. * output channel 1 is supported by a timer instance.
  1837. * @rmtoll CCR1 CCR1 LL_TIM_OC_GetCompareCH1
  1838. * @param TIMx Timer instance
  1839. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1840. */
  1841. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH1(TIM_TypeDef *TIMx)
  1842. {
  1843. return (uint32_t)(READ_REG(TIMx->CCR1));
  1844. }
  1845. /**
  1846. * @brief Get compare value (TIMx_CCR2) set for output channel 2.
  1847. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  1848. * output channel 2 is supported by a timer instance.
  1849. * @rmtoll CCR2 CCR2 LL_TIM_OC_GetCompareCH2
  1850. * @param TIMx Timer instance
  1851. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1852. */
  1853. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH2(TIM_TypeDef *TIMx)
  1854. {
  1855. return (uint32_t)(READ_REG(TIMx->CCR2));
  1856. }
  1857. /**
  1858. * @brief Get compare value (TIMx_CCR3) set for output channel 3.
  1859. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  1860. * output channel 3 is supported by a timer instance.
  1861. * @rmtoll CCR3 CCR3 LL_TIM_OC_GetCompareCH3
  1862. * @param TIMx Timer instance
  1863. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1864. */
  1865. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH3(TIM_TypeDef *TIMx)
  1866. {
  1867. return (uint32_t)(READ_REG(TIMx->CCR3));
  1868. }
  1869. /**
  1870. * @brief Get compare value (TIMx_CCR4) set for output channel 4.
  1871. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  1872. * output channel 4 is supported by a timer instance.
  1873. * @rmtoll CCR4 CCR4 LL_TIM_OC_GetCompareCH4
  1874. * @param TIMx Timer instance
  1875. * @retval CompareValue (between Min_Data=0 and Max_Data=65535)
  1876. */
  1877. __STATIC_INLINE uint32_t LL_TIM_OC_GetCompareCH4(TIM_TypeDef *TIMx)
  1878. {
  1879. return (uint32_t)(READ_REG(TIMx->CCR4));
  1880. }
  1881. /**
  1882. * @}
  1883. */
  1884. /** @defgroup TIM_LL_EF_Input_Channel Input channel configuration
  1885. * @{
  1886. */
  1887. /**
  1888. * @brief Configure input channel.
  1889. * @rmtoll CCMR1 CC1S LL_TIM_IC_Config\n
  1890. * CCMR1 IC1PSC LL_TIM_IC_Config\n
  1891. * CCMR1 IC1F LL_TIM_IC_Config\n
  1892. * CCMR1 CC2S LL_TIM_IC_Config\n
  1893. * CCMR1 IC2PSC LL_TIM_IC_Config\n
  1894. * CCMR1 IC2F LL_TIM_IC_Config\n
  1895. * CCMR2 CC3S LL_TIM_IC_Config\n
  1896. * CCMR2 IC3PSC LL_TIM_IC_Config\n
  1897. * CCMR2 IC3F LL_TIM_IC_Config\n
  1898. * CCMR2 CC4S LL_TIM_IC_Config\n
  1899. * CCMR2 IC4PSC LL_TIM_IC_Config\n
  1900. * CCMR2 IC4F LL_TIM_IC_Config\n
  1901. * CCER CC1P LL_TIM_IC_Config\n
  1902. * CCER CC1NP LL_TIM_IC_Config\n
  1903. * CCER CC2P LL_TIM_IC_Config\n
  1904. * CCER CC2NP LL_TIM_IC_Config\n
  1905. * CCER CC3P LL_TIM_IC_Config\n
  1906. * CCER CC3NP LL_TIM_IC_Config\n
  1907. * CCER CC4P LL_TIM_IC_Config\n
  1908. * @param TIMx Timer instance
  1909. * @param Channel This parameter can be one of the following values:
  1910. * @arg @ref LL_TIM_CHANNEL_CH1
  1911. * @arg @ref LL_TIM_CHANNEL_CH2
  1912. * @arg @ref LL_TIM_CHANNEL_CH3
  1913. * @arg @ref LL_TIM_CHANNEL_CH4
  1914. * @param Configuration This parameter must be a combination of all the following values:
  1915. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI or @ref LL_TIM_ACTIVEINPUT_INDIRECTTI or @ref LL_TIM_ACTIVEINPUT_TRC
  1916. * @arg @ref LL_TIM_ICPSC_DIV1 or ... or @ref LL_TIM_ICPSC_DIV8
  1917. * @arg @ref LL_TIM_IC_FILTER_FDIV1 or ... or @ref LL_TIM_IC_FILTER_FDIV32_N8
  1918. * @arg @ref LL_TIM_IC_POLARITY_RISING or @ref LL_TIM_IC_POLARITY_FALLING or @ref LL_TIM_IC_POLARITY_BOTHEDGE
  1919. * @retval None
  1920. */
  1921. __STATIC_INLINE void LL_TIM_IC_Config(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t Configuration)
  1922. {
  1923. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1924. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1925. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC | TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel]),
  1926. ((Configuration >> 16U) & (TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC | TIM_CCMR1_CC1S)) << SHIFT_TAB_ICxx[iChannel]);
  1927. MODIFY_REG(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]),
  1928. (Configuration & (TIM_CCER_CC1NP | TIM_CCER_CC1P)) << SHIFT_TAB_CCxP[iChannel]);
  1929. }
  1930. /**
  1931. * @brief Set the active input.
  1932. * @rmtoll CCMR1 CC1S LL_TIM_IC_SetActiveInput\n
  1933. * CCMR1 CC2S LL_TIM_IC_SetActiveInput\n
  1934. * CCMR2 CC3S LL_TIM_IC_SetActiveInput\n
  1935. * CCMR2 CC4S LL_TIM_IC_SetActiveInput
  1936. * @param TIMx Timer instance
  1937. * @param Channel This parameter can be one of the following values:
  1938. * @arg @ref LL_TIM_CHANNEL_CH1
  1939. * @arg @ref LL_TIM_CHANNEL_CH2
  1940. * @arg @ref LL_TIM_CHANNEL_CH3
  1941. * @arg @ref LL_TIM_CHANNEL_CH4
  1942. * @param ICActiveInput This parameter can be one of the following values:
  1943. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI
  1944. * @arg @ref LL_TIM_ACTIVEINPUT_INDIRECTTI
  1945. * @arg @ref LL_TIM_ACTIVEINPUT_TRC
  1946. * @retval None
  1947. */
  1948. __STATIC_INLINE void LL_TIM_IC_SetActiveInput(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICActiveInput)
  1949. {
  1950. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1951. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1952. MODIFY_REG(*pReg, ((TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel]), (ICActiveInput >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  1953. }
  1954. /**
  1955. * @brief Get the current active input.
  1956. * @rmtoll CCMR1 CC1S LL_TIM_IC_GetActiveInput\n
  1957. * CCMR1 CC2S LL_TIM_IC_GetActiveInput\n
  1958. * CCMR2 CC3S LL_TIM_IC_GetActiveInput\n
  1959. * CCMR2 CC4S LL_TIM_IC_GetActiveInput
  1960. * @param TIMx Timer instance
  1961. * @param Channel This parameter can be one of the following values:
  1962. * @arg @ref LL_TIM_CHANNEL_CH1
  1963. * @arg @ref LL_TIM_CHANNEL_CH2
  1964. * @arg @ref LL_TIM_CHANNEL_CH3
  1965. * @arg @ref LL_TIM_CHANNEL_CH4
  1966. * @retval Returned value can be one of the following values:
  1967. * @arg @ref LL_TIM_ACTIVEINPUT_DIRECTTI
  1968. * @arg @ref LL_TIM_ACTIVEINPUT_INDIRECTTI
  1969. * @arg @ref LL_TIM_ACTIVEINPUT_TRC
  1970. */
  1971. __STATIC_INLINE uint32_t LL_TIM_IC_GetActiveInput(TIM_TypeDef *TIMx, uint32_t Channel)
  1972. {
  1973. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1974. register const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  1975. return ((READ_BIT(*pReg, ((TIM_CCMR1_CC1S) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  1976. }
  1977. /**
  1978. * @brief Set the prescaler of input channel.
  1979. * @rmtoll CCMR1 IC1PSC LL_TIM_IC_SetPrescaler\n
  1980. * CCMR1 IC2PSC LL_TIM_IC_SetPrescaler\n
  1981. * CCMR2 IC3PSC LL_TIM_IC_SetPrescaler\n
  1982. * CCMR2 IC4PSC LL_TIM_IC_SetPrescaler
  1983. * @param TIMx Timer instance
  1984. * @param Channel This parameter can be one of the following values:
  1985. * @arg @ref LL_TIM_CHANNEL_CH1
  1986. * @arg @ref LL_TIM_CHANNEL_CH2
  1987. * @arg @ref LL_TIM_CHANNEL_CH3
  1988. * @arg @ref LL_TIM_CHANNEL_CH4
  1989. * @param ICPrescaler This parameter can be one of the following values:
  1990. * @arg @ref LL_TIM_ICPSC_DIV1
  1991. * @arg @ref LL_TIM_ICPSC_DIV2
  1992. * @arg @ref LL_TIM_ICPSC_DIV4
  1993. * @arg @ref LL_TIM_ICPSC_DIV8
  1994. * @retval None
  1995. */
  1996. __STATIC_INLINE void LL_TIM_IC_SetPrescaler(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICPrescaler)
  1997. {
  1998. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  1999. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2000. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1PSC) << SHIFT_TAB_ICxx[iChannel]), (ICPrescaler >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  2001. }
  2002. /**
  2003. * @brief Get the current prescaler value acting on an input channel.
  2004. * @rmtoll CCMR1 IC1PSC LL_TIM_IC_GetPrescaler\n
  2005. * CCMR1 IC2PSC LL_TIM_IC_GetPrescaler\n
  2006. * CCMR2 IC3PSC LL_TIM_IC_GetPrescaler\n
  2007. * CCMR2 IC4PSC LL_TIM_IC_GetPrescaler
  2008. * @param TIMx Timer instance
  2009. * @param Channel This parameter can be one of the following values:
  2010. * @arg @ref LL_TIM_CHANNEL_CH1
  2011. * @arg @ref LL_TIM_CHANNEL_CH2
  2012. * @arg @ref LL_TIM_CHANNEL_CH3
  2013. * @arg @ref LL_TIM_CHANNEL_CH4
  2014. * @retval Returned value can be one of the following values:
  2015. * @arg @ref LL_TIM_ICPSC_DIV1
  2016. * @arg @ref LL_TIM_ICPSC_DIV2
  2017. * @arg @ref LL_TIM_ICPSC_DIV4
  2018. * @arg @ref LL_TIM_ICPSC_DIV8
  2019. */
  2020. __STATIC_INLINE uint32_t LL_TIM_IC_GetPrescaler(TIM_TypeDef *TIMx, uint32_t Channel)
  2021. {
  2022. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2023. register const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2024. return ((READ_BIT(*pReg, ((TIM_CCMR1_IC1PSC) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2025. }
  2026. /**
  2027. * @brief Set the input filter duration.
  2028. * @rmtoll CCMR1 IC1F LL_TIM_IC_SetFilter\n
  2029. * CCMR1 IC2F LL_TIM_IC_SetFilter\n
  2030. * CCMR2 IC3F LL_TIM_IC_SetFilter\n
  2031. * CCMR2 IC4F LL_TIM_IC_SetFilter
  2032. * @param TIMx Timer instance
  2033. * @param Channel This parameter can be one of the following values:
  2034. * @arg @ref LL_TIM_CHANNEL_CH1
  2035. * @arg @ref LL_TIM_CHANNEL_CH2
  2036. * @arg @ref LL_TIM_CHANNEL_CH3
  2037. * @arg @ref LL_TIM_CHANNEL_CH4
  2038. * @param ICFilter This parameter can be one of the following values:
  2039. * @arg @ref LL_TIM_IC_FILTER_FDIV1
  2040. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N2
  2041. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N4
  2042. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N8
  2043. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N6
  2044. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N8
  2045. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N6
  2046. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N8
  2047. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N6
  2048. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N8
  2049. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N5
  2050. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N6
  2051. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N8
  2052. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N5
  2053. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N6
  2054. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N8
  2055. * @retval None
  2056. */
  2057. __STATIC_INLINE void LL_TIM_IC_SetFilter(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICFilter)
  2058. {
  2059. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2060. register __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2061. MODIFY_REG(*pReg, ((TIM_CCMR1_IC1F) << SHIFT_TAB_ICxx[iChannel]), (ICFilter >> 16U) << SHIFT_TAB_ICxx[iChannel]);
  2062. }
  2063. /**
  2064. * @brief Get the input filter duration.
  2065. * @rmtoll CCMR1 IC1F LL_TIM_IC_GetFilter\n
  2066. * CCMR1 IC2F LL_TIM_IC_GetFilter\n
  2067. * CCMR2 IC3F LL_TIM_IC_GetFilter\n
  2068. * CCMR2 IC4F LL_TIM_IC_GetFilter
  2069. * @param TIMx Timer instance
  2070. * @param Channel This parameter can be one of the following values:
  2071. * @arg @ref LL_TIM_CHANNEL_CH1
  2072. * @arg @ref LL_TIM_CHANNEL_CH2
  2073. * @arg @ref LL_TIM_CHANNEL_CH3
  2074. * @arg @ref LL_TIM_CHANNEL_CH4
  2075. * @retval Returned value can be one of the following values:
  2076. * @arg @ref LL_TIM_IC_FILTER_FDIV1
  2077. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N2
  2078. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N4
  2079. * @arg @ref LL_TIM_IC_FILTER_FDIV1_N8
  2080. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N6
  2081. * @arg @ref LL_TIM_IC_FILTER_FDIV2_N8
  2082. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N6
  2083. * @arg @ref LL_TIM_IC_FILTER_FDIV4_N8
  2084. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N6
  2085. * @arg @ref LL_TIM_IC_FILTER_FDIV8_N8
  2086. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N5
  2087. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N6
  2088. * @arg @ref LL_TIM_IC_FILTER_FDIV16_N8
  2089. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N5
  2090. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N6
  2091. * @arg @ref LL_TIM_IC_FILTER_FDIV32_N8
  2092. */
  2093. __STATIC_INLINE uint32_t LL_TIM_IC_GetFilter(TIM_TypeDef *TIMx, uint32_t Channel)
  2094. {
  2095. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2096. register const __IO uint32_t *pReg = (__IO uint32_t *)((uint32_t)((uint32_t)(&TIMx->CCMR1) + OFFSET_TAB_CCMRx[iChannel]));
  2097. return ((READ_BIT(*pReg, ((TIM_CCMR1_IC1F) << SHIFT_TAB_ICxx[iChannel])) >> SHIFT_TAB_ICxx[iChannel]) << 16U);
  2098. }
  2099. /**
  2100. * @brief Set the input channel polarity.
  2101. * @rmtoll CCER CC1P LL_TIM_IC_SetPolarity\n
  2102. * CCER CC1NP LL_TIM_IC_SetPolarity\n
  2103. * CCER CC2P LL_TIM_IC_SetPolarity\n
  2104. * CCER CC2NP LL_TIM_IC_SetPolarity\n
  2105. * CCER CC3P LL_TIM_IC_SetPolarity\n
  2106. * CCER CC3NP LL_TIM_IC_SetPolarity\n
  2107. * CCER CC4P LL_TIM_IC_SetPolarity\n
  2108. * @param TIMx Timer instance
  2109. * @param Channel This parameter can be one of the following values:
  2110. * @arg @ref LL_TIM_CHANNEL_CH1
  2111. * @arg @ref LL_TIM_CHANNEL_CH2
  2112. * @arg @ref LL_TIM_CHANNEL_CH3
  2113. * @arg @ref LL_TIM_CHANNEL_CH4
  2114. * @param ICPolarity This parameter can be one of the following values:
  2115. * @arg @ref LL_TIM_IC_POLARITY_RISING
  2116. * @arg @ref LL_TIM_IC_POLARITY_FALLING
  2117. * @arg @ref LL_TIM_IC_POLARITY_BOTHEDGE
  2118. * @retval None
  2119. */
  2120. __STATIC_INLINE void LL_TIM_IC_SetPolarity(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ICPolarity)
  2121. {
  2122. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2123. MODIFY_REG(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel]),
  2124. ICPolarity << SHIFT_TAB_CCxP[iChannel]);
  2125. }
  2126. /**
  2127. * @brief Get the current input channel polarity.
  2128. * @rmtoll CCER CC1P LL_TIM_IC_GetPolarity\n
  2129. * CCER CC1NP LL_TIM_IC_GetPolarity\n
  2130. * CCER CC2P LL_TIM_IC_GetPolarity\n
  2131. * CCER CC2NP LL_TIM_IC_GetPolarity\n
  2132. * CCER CC3P LL_TIM_IC_GetPolarity\n
  2133. * CCER CC3NP LL_TIM_IC_GetPolarity\n
  2134. * CCER CC4P LL_TIM_IC_GetPolarity\n
  2135. * @param TIMx Timer instance
  2136. * @param Channel This parameter can be one of the following values:
  2137. * @arg @ref LL_TIM_CHANNEL_CH1
  2138. * @arg @ref LL_TIM_CHANNEL_CH2
  2139. * @arg @ref LL_TIM_CHANNEL_CH3
  2140. * @arg @ref LL_TIM_CHANNEL_CH4
  2141. * @retval Returned value can be one of the following values:
  2142. * @arg @ref LL_TIM_IC_POLARITY_RISING
  2143. * @arg @ref LL_TIM_IC_POLARITY_FALLING
  2144. * @arg @ref LL_TIM_IC_POLARITY_BOTHEDGE
  2145. */
  2146. __STATIC_INLINE uint32_t LL_TIM_IC_GetPolarity(TIM_TypeDef *TIMx, uint32_t Channel)
  2147. {
  2148. register uint8_t iChannel = TIM_GET_CHANNEL_INDEX(Channel);
  2149. return (READ_BIT(TIMx->CCER, ((TIM_CCER_CC1NP | TIM_CCER_CC1P) << SHIFT_TAB_CCxP[iChannel])) >>
  2150. SHIFT_TAB_CCxP[iChannel]);
  2151. }
  2152. /**
  2153. * @brief Connect the TIMx_CH1, CH2 and CH3 pins to the TI1 input (XOR combination).
  2154. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2155. * a timer instance provides an XOR input.
  2156. * @rmtoll CR2 TI1S LL_TIM_IC_EnableXORCombination
  2157. * @param TIMx Timer instance
  2158. * @retval None
  2159. */
  2160. __STATIC_INLINE void LL_TIM_IC_EnableXORCombination(TIM_TypeDef *TIMx)
  2161. {
  2162. SET_BIT(TIMx->CR2, TIM_CR2_TI1S);
  2163. }
  2164. /**
  2165. * @brief Disconnect the TIMx_CH1, CH2 and CH3 pins from the TI1 input.
  2166. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2167. * a timer instance provides an XOR input.
  2168. * @rmtoll CR2 TI1S LL_TIM_IC_DisableXORCombination
  2169. * @param TIMx Timer instance
  2170. * @retval None
  2171. */
  2172. __STATIC_INLINE void LL_TIM_IC_DisableXORCombination(TIM_TypeDef *TIMx)
  2173. {
  2174. CLEAR_BIT(TIMx->CR2, TIM_CR2_TI1S);
  2175. }
  2176. /**
  2177. * @brief Indicates whether the TIMx_CH1, CH2 and CH3 pins are connectected to the TI1 input.
  2178. * @note Macro IS_TIM_XOR_INSTANCE(TIMx) can be used to check whether or not
  2179. * a timer instance provides an XOR input.
  2180. * @rmtoll CR2 TI1S LL_TIM_IC_IsEnabledXORCombination
  2181. * @param TIMx Timer instance
  2182. * @retval State of bit (1 or 0).
  2183. */
  2184. __STATIC_INLINE uint32_t LL_TIM_IC_IsEnabledXORCombination(TIM_TypeDef *TIMx)
  2185. {
  2186. return ((READ_BIT(TIMx->CR2, TIM_CR2_TI1S) == (TIM_CR2_TI1S)) ? 1UL : 0UL);
  2187. }
  2188. /**
  2189. * @brief Get captured value for input channel 1.
  2190. * @note Macro IS_TIM_CC1_INSTANCE(TIMx) can be used to check whether or not
  2191. * input channel 1 is supported by a timer instance.
  2192. * @rmtoll CCR1 CCR1 LL_TIM_IC_GetCaptureCH1
  2193. * @param TIMx Timer instance
  2194. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2195. */
  2196. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH1(TIM_TypeDef *TIMx)
  2197. {
  2198. return (uint32_t)(READ_REG(TIMx->CCR1));
  2199. }
  2200. /**
  2201. * @brief Get captured value for input channel 2.
  2202. * @note Macro IS_TIM_CC2_INSTANCE(TIMx) can be used to check whether or not
  2203. * input channel 2 is supported by a timer instance.
  2204. * @rmtoll CCR2 CCR2 LL_TIM_IC_GetCaptureCH2
  2205. * @param TIMx Timer instance
  2206. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2207. */
  2208. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH2(TIM_TypeDef *TIMx)
  2209. {
  2210. return (uint32_t)(READ_REG(TIMx->CCR2));
  2211. }
  2212. /**
  2213. * @brief Get captured value for input channel 3.
  2214. * @note Macro IS_TIM_CC3_INSTANCE(TIMx) can be used to check whether or not
  2215. * input channel 3 is supported by a timer instance.
  2216. * @rmtoll CCR3 CCR3 LL_TIM_IC_GetCaptureCH3
  2217. * @param TIMx Timer instance
  2218. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2219. */
  2220. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH3(TIM_TypeDef *TIMx)
  2221. {
  2222. return (uint32_t)(READ_REG(TIMx->CCR3));
  2223. }
  2224. /**
  2225. * @brief Get captured value for input channel 4.
  2226. * @note Macro IS_TIM_CC4_INSTANCE(TIMx) can be used to check whether or not
  2227. * input channel 4 is supported by a timer instance.
  2228. * @rmtoll CCR4 CCR4 LL_TIM_IC_GetCaptureCH4
  2229. * @param TIMx Timer instance
  2230. * @retval CapturedValue (between Min_Data=0 and Max_Data=65535)
  2231. */
  2232. __STATIC_INLINE uint32_t LL_TIM_IC_GetCaptureCH4(TIM_TypeDef *TIMx)
  2233. {
  2234. return (uint32_t)(READ_REG(TIMx->CCR4));
  2235. }
  2236. /**
  2237. * @}
  2238. */
  2239. /** @defgroup TIM_LL_EF_Clock_Selection Counter clock selection
  2240. * @{
  2241. */
  2242. /**
  2243. * @brief Enable external clock mode 2.
  2244. * @note When external clock mode 2 is enabled the counter is clocked by any active edge on the ETRF signal.
  2245. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2246. * whether or not a timer instance supports external clock mode2.
  2247. * @rmtoll SMCR ECE LL_TIM_EnableExternalClock
  2248. * @param TIMx Timer instance
  2249. * @retval None
  2250. */
  2251. __STATIC_INLINE void LL_TIM_EnableExternalClock(TIM_TypeDef *TIMx)
  2252. {
  2253. SET_BIT(TIMx->SMCR, TIM_SMCR_ECE);
  2254. }
  2255. /**
  2256. * @brief Disable external clock mode 2.
  2257. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2258. * whether or not a timer instance supports external clock mode2.
  2259. * @rmtoll SMCR ECE LL_TIM_DisableExternalClock
  2260. * @param TIMx Timer instance
  2261. * @retval None
  2262. */
  2263. __STATIC_INLINE void LL_TIM_DisableExternalClock(TIM_TypeDef *TIMx)
  2264. {
  2265. CLEAR_BIT(TIMx->SMCR, TIM_SMCR_ECE);
  2266. }
  2267. /**
  2268. * @brief Indicate whether external clock mode 2 is enabled.
  2269. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2270. * whether or not a timer instance supports external clock mode2.
  2271. * @rmtoll SMCR ECE LL_TIM_IsEnabledExternalClock
  2272. * @param TIMx Timer instance
  2273. * @retval State of bit (1 or 0).
  2274. */
  2275. __STATIC_INLINE uint32_t LL_TIM_IsEnabledExternalClock(TIM_TypeDef *TIMx)
  2276. {
  2277. return ((READ_BIT(TIMx->SMCR, TIM_SMCR_ECE) == (TIM_SMCR_ECE)) ? 1UL : 0UL);
  2278. }
  2279. /**
  2280. * @brief Set the clock source of the counter clock.
  2281. * @note when selected clock source is external clock mode 1, the timer input
  2282. * the external clock is applied is selected by calling the @ref LL_TIM_SetTriggerInput()
  2283. * function. This timer input must be configured by calling
  2284. * the @ref LL_TIM_IC_Config() function.
  2285. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(TIMx) can be used to check
  2286. * whether or not a timer instance supports external clock mode1.
  2287. * @note Macro IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(TIMx) can be used to check
  2288. * whether or not a timer instance supports external clock mode2.
  2289. * @rmtoll SMCR SMS LL_TIM_SetClockSource\n
  2290. * SMCR ECE LL_TIM_SetClockSource
  2291. * @param TIMx Timer instance
  2292. * @param ClockSource This parameter can be one of the following values:
  2293. * @arg @ref LL_TIM_CLOCKSOURCE_INTERNAL
  2294. * @arg @ref LL_TIM_CLOCKSOURCE_EXT_MODE1
  2295. * @arg @ref LL_TIM_CLOCKSOURCE_EXT_MODE2
  2296. * @retval None
  2297. */
  2298. __STATIC_INLINE void LL_TIM_SetClockSource(TIM_TypeDef *TIMx, uint32_t ClockSource)
  2299. {
  2300. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS | TIM_SMCR_ECE, ClockSource);
  2301. }
  2302. /**
  2303. * @brief Set the encoder interface mode.
  2304. * @note Macro IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx) can be used to check
  2305. * whether or not a timer instance supports the encoder mode.
  2306. * @rmtoll SMCR SMS LL_TIM_SetEncoderMode
  2307. * @param TIMx Timer instance
  2308. * @param EncoderMode This parameter can be one of the following values:
  2309. * @arg @ref LL_TIM_ENCODERMODE_X2_TI1
  2310. * @arg @ref LL_TIM_ENCODERMODE_X2_TI2
  2311. * @arg @ref LL_TIM_ENCODERMODE_X4_TI12
  2312. * @retval None
  2313. */
  2314. __STATIC_INLINE void LL_TIM_SetEncoderMode(TIM_TypeDef *TIMx, uint32_t EncoderMode)
  2315. {
  2316. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS, EncoderMode);
  2317. }
  2318. /**
  2319. * @}
  2320. */
  2321. /** @defgroup TIM_LL_EF_Timer_Synchronization Timer synchronisation configuration
  2322. * @{
  2323. */
  2324. /**
  2325. * @brief Set the trigger output (TRGO) used for timer synchronization .
  2326. * @note Macro IS_TIM_MASTER_INSTANCE(TIMx) can be used to check
  2327. * whether or not a timer instance can operate as a master timer.
  2328. * @rmtoll CR2 MMS LL_TIM_SetTriggerOutput
  2329. * @param TIMx Timer instance
  2330. * @param TimerSynchronization This parameter can be one of the following values:
  2331. * @arg @ref LL_TIM_TRGO_RESET
  2332. * @arg @ref LL_TIM_TRGO_ENABLE
  2333. * @arg @ref LL_TIM_TRGO_UPDATE
  2334. * @arg @ref LL_TIM_TRGO_CC1IF
  2335. * @arg @ref LL_TIM_TRGO_OC1REF
  2336. * @arg @ref LL_TIM_TRGO_OC2REF
  2337. * @arg @ref LL_TIM_TRGO_OC3REF
  2338. * @arg @ref LL_TIM_TRGO_OC4REF
  2339. * @retval None
  2340. */
  2341. __STATIC_INLINE void LL_TIM_SetTriggerOutput(TIM_TypeDef *TIMx, uint32_t TimerSynchronization)
  2342. {
  2343. MODIFY_REG(TIMx->CR2, TIM_CR2_MMS, TimerSynchronization);
  2344. }
  2345. /**
  2346. * @brief Set the synchronization mode of a slave timer.
  2347. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2348. * a timer instance can operate as a slave timer.
  2349. * @rmtoll SMCR SMS LL_TIM_SetSlaveMode
  2350. * @param TIMx Timer instance
  2351. * @param SlaveMode This parameter can be one of the following values:
  2352. * @arg @ref LL_TIM_SLAVEMODE_DISABLED
  2353. * @arg @ref LL_TIM_SLAVEMODE_RESET
  2354. * @arg @ref LL_TIM_SLAVEMODE_GATED
  2355. * @arg @ref LL_TIM_SLAVEMODE_TRIGGER
  2356. * @retval None
  2357. */
  2358. __STATIC_INLINE void LL_TIM_SetSlaveMode(TIM_TypeDef *TIMx, uint32_t SlaveMode)
  2359. {
  2360. MODIFY_REG(TIMx->SMCR, TIM_SMCR_SMS, SlaveMode);
  2361. }
  2362. /**
  2363. * @brief Set the selects the trigger input to be used to synchronize the counter.
  2364. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2365. * a timer instance can operate as a slave timer.
  2366. * @rmtoll SMCR TS LL_TIM_SetTriggerInput
  2367. * @param TIMx Timer instance
  2368. * @param TriggerInput This parameter can be one of the following values:
  2369. * @arg @ref LL_TIM_TS_ITR0
  2370. * @arg @ref LL_TIM_TS_ITR1
  2371. * @arg @ref LL_TIM_TS_ITR2
  2372. * @arg @ref LL_TIM_TS_ITR3
  2373. * @arg @ref LL_TIM_TS_TI1F_ED
  2374. * @arg @ref LL_TIM_TS_TI1FP1
  2375. * @arg @ref LL_TIM_TS_TI2FP2
  2376. * @arg @ref LL_TIM_TS_ETRF
  2377. * @retval None
  2378. */
  2379. __STATIC_INLINE void LL_TIM_SetTriggerInput(TIM_TypeDef *TIMx, uint32_t TriggerInput)
  2380. {
  2381. MODIFY_REG(TIMx->SMCR, TIM_SMCR_TS, TriggerInput);
  2382. }
  2383. /**
  2384. * @brief Enable the Master/Slave mode.
  2385. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2386. * a timer instance can operate as a slave timer.
  2387. * @rmtoll SMCR MSM LL_TIM_EnableMasterSlaveMode
  2388. * @param TIMx Timer instance
  2389. * @retval None
  2390. */
  2391. __STATIC_INLINE void LL_TIM_EnableMasterSlaveMode(TIM_TypeDef *TIMx)
  2392. {
  2393. SET_BIT(TIMx->SMCR, TIM_SMCR_MSM);
  2394. }
  2395. /**
  2396. * @brief Disable the Master/Slave mode.
  2397. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2398. * a timer instance can operate as a slave timer.
  2399. * @rmtoll SMCR MSM LL_TIM_DisableMasterSlaveMode
  2400. * @param TIMx Timer instance
  2401. * @retval None
  2402. */
  2403. __STATIC_INLINE void LL_TIM_DisableMasterSlaveMode(TIM_TypeDef *TIMx)
  2404. {
  2405. CLEAR_BIT(TIMx->SMCR, TIM_SMCR_MSM);
  2406. }
  2407. /**
  2408. * @brief Indicates whether the Master/Slave mode is enabled.
  2409. * @note Macro IS_TIM_SLAVE_INSTANCE(TIMx) can be used to check whether or not
  2410. * a timer instance can operate as a slave timer.
  2411. * @rmtoll SMCR MSM LL_TIM_IsEnabledMasterSlaveMode
  2412. * @param TIMx Timer instance
  2413. * @retval State of bit (1 or 0).
  2414. */
  2415. __STATIC_INLINE uint32_t LL_TIM_IsEnabledMasterSlaveMode(TIM_TypeDef *TIMx)
  2416. {
  2417. return ((READ_BIT(TIMx->SMCR, TIM_SMCR_MSM) == (TIM_SMCR_MSM)) ? 1UL : 0UL);
  2418. }
  2419. /**
  2420. * @brief Configure the external trigger (ETR) input.
  2421. * @note Macro IS_TIM_ETR_INSTANCE(TIMx) can be used to check whether or not
  2422. * a timer instance provides an external trigger input.
  2423. * @rmtoll SMCR ETP LL_TIM_ConfigETR\n
  2424. * SMCR ETPS LL_TIM_ConfigETR\n
  2425. * SMCR ETF LL_TIM_ConfigETR
  2426. * @param TIMx Timer instance
  2427. * @param ETRPolarity This parameter can be one of the following values:
  2428. * @arg @ref LL_TIM_ETR_POLARITY_NONINVERTED
  2429. * @arg @ref LL_TIM_ETR_POLARITY_INVERTED
  2430. * @param ETRPrescaler This parameter can be one of the following values:
  2431. * @arg @ref LL_TIM_ETR_PRESCALER_DIV1
  2432. * @arg @ref LL_TIM_ETR_PRESCALER_DIV2
  2433. * @arg @ref LL_TIM_ETR_PRESCALER_DIV4
  2434. * @arg @ref LL_TIM_ETR_PRESCALER_DIV8
  2435. * @param ETRFilter This parameter can be one of the following values:
  2436. * @arg @ref LL_TIM_ETR_FILTER_FDIV1
  2437. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N2
  2438. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N4
  2439. * @arg @ref LL_TIM_ETR_FILTER_FDIV1_N8
  2440. * @arg @ref LL_TIM_ETR_FILTER_FDIV2_N6
  2441. * @arg @ref LL_TIM_ETR_FILTER_FDIV2_N8
  2442. * @arg @ref LL_TIM_ETR_FILTER_FDIV4_N6
  2443. * @arg @ref LL_TIM_ETR_FILTER_FDIV4_N8
  2444. * @arg @ref LL_TIM_ETR_FILTER_FDIV8_N6
  2445. * @arg @ref LL_TIM_ETR_FILTER_FDIV8_N8
  2446. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N5
  2447. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N6
  2448. * @arg @ref LL_TIM_ETR_FILTER_FDIV16_N8
  2449. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N5
  2450. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N6
  2451. * @arg @ref LL_TIM_ETR_FILTER_FDIV32_N8
  2452. * @retval None
  2453. */
  2454. __STATIC_INLINE void LL_TIM_ConfigETR(TIM_TypeDef *TIMx, uint32_t ETRPolarity, uint32_t ETRPrescaler,
  2455. uint32_t ETRFilter)
  2456. {
  2457. MODIFY_REG(TIMx->SMCR, TIM_SMCR_ETP | TIM_SMCR_ETPS | TIM_SMCR_ETF, ETRPolarity | ETRPrescaler | ETRFilter);
  2458. }
  2459. /**
  2460. * @}
  2461. */
  2462. /** @defgroup TIM_LL_EF_Break_Function Break function configuration
  2463. * @{
  2464. */
  2465. /**
  2466. * @brief Enable the break function.
  2467. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2468. * a timer instance provides a break input.
  2469. * @rmtoll BDTR BKE LL_TIM_EnableBRK
  2470. * @param TIMx Timer instance
  2471. * @retval None
  2472. */
  2473. __STATIC_INLINE void LL_TIM_EnableBRK(TIM_TypeDef *TIMx)
  2474. {
  2475. __IO uint32_t tmpreg;
  2476. SET_BIT(TIMx->BDTR, TIM_BDTR_BKE);
  2477. /* Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective. */
  2478. tmpreg = READ_REG(TIMx->BDTR);
  2479. (void)(tmpreg);
  2480. }
  2481. /**
  2482. * @brief Disable the break function.
  2483. * @rmtoll BDTR BKE LL_TIM_DisableBRK
  2484. * @param TIMx Timer instance
  2485. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2486. * a timer instance provides a break input.
  2487. * @retval None
  2488. */
  2489. __STATIC_INLINE void LL_TIM_DisableBRK(TIM_TypeDef *TIMx)
  2490. {
  2491. __IO uint32_t tmpreg;
  2492. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_BKE);
  2493. /* Note: Any write operation to this bit takes a delay of 1 APB clock cycle to become effective. */
  2494. tmpreg = READ_REG(TIMx->BDTR);
  2495. (void)(tmpreg);
  2496. }
  2497. /**
  2498. * @brief Configure the break input.
  2499. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2500. * a timer instance provides a break input.
  2501. * @rmtoll BDTR BKP LL_TIM_ConfigBRK
  2502. * @param TIMx Timer instance
  2503. * @param BreakPolarity This parameter can be one of the following values:
  2504. * @arg @ref LL_TIM_BREAK_POLARITY_LOW
  2505. * @arg @ref LL_TIM_BREAK_POLARITY_HIGH
  2506. * @retval None
  2507. */
  2508. __STATIC_INLINE void LL_TIM_ConfigBRK(TIM_TypeDef *TIMx, uint32_t BreakPolarity)
  2509. {
  2510. __IO uint32_t tmpreg;
  2511. MODIFY_REG(TIMx->BDTR, TIM_BDTR_BKP, BreakPolarity);
  2512. /* Note: Any write operation to BKP bit takes a delay of 1 APB clock cycle to become effective. */
  2513. tmpreg = READ_REG(TIMx->BDTR);
  2514. (void)(tmpreg);
  2515. }
  2516. /**
  2517. * @brief Select the outputs off state (enabled v.s. disabled) in Idle and Run modes.
  2518. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2519. * a timer instance provides a break input.
  2520. * @rmtoll BDTR OSSI LL_TIM_SetOffStates\n
  2521. * BDTR OSSR LL_TIM_SetOffStates
  2522. * @param TIMx Timer instance
  2523. * @param OffStateIdle This parameter can be one of the following values:
  2524. * @arg @ref LL_TIM_OSSI_DISABLE
  2525. * @arg @ref LL_TIM_OSSI_ENABLE
  2526. * @param OffStateRun This parameter can be one of the following values:
  2527. * @arg @ref LL_TIM_OSSR_DISABLE
  2528. * @arg @ref LL_TIM_OSSR_ENABLE
  2529. * @retval None
  2530. */
  2531. __STATIC_INLINE void LL_TIM_SetOffStates(TIM_TypeDef *TIMx, uint32_t OffStateIdle, uint32_t OffStateRun)
  2532. {
  2533. MODIFY_REG(TIMx->BDTR, TIM_BDTR_OSSI | TIM_BDTR_OSSR, OffStateIdle | OffStateRun);
  2534. }
  2535. /**
  2536. * @brief Enable automatic output (MOE can be set by software or automatically when a break input is active).
  2537. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2538. * a timer instance provides a break input.
  2539. * @rmtoll BDTR AOE LL_TIM_EnableAutomaticOutput
  2540. * @param TIMx Timer instance
  2541. * @retval None
  2542. */
  2543. __STATIC_INLINE void LL_TIM_EnableAutomaticOutput(TIM_TypeDef *TIMx)
  2544. {
  2545. SET_BIT(TIMx->BDTR, TIM_BDTR_AOE);
  2546. }
  2547. /**
  2548. * @brief Disable automatic output (MOE can be set only by software).
  2549. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2550. * a timer instance provides a break input.
  2551. * @rmtoll BDTR AOE LL_TIM_DisableAutomaticOutput
  2552. * @param TIMx Timer instance
  2553. * @retval None
  2554. */
  2555. __STATIC_INLINE void LL_TIM_DisableAutomaticOutput(TIM_TypeDef *TIMx)
  2556. {
  2557. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_AOE);
  2558. }
  2559. /**
  2560. * @brief Indicate whether automatic output is enabled.
  2561. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2562. * a timer instance provides a break input.
  2563. * @rmtoll BDTR AOE LL_TIM_IsEnabledAutomaticOutput
  2564. * @param TIMx Timer instance
  2565. * @retval State of bit (1 or 0).
  2566. */
  2567. __STATIC_INLINE uint32_t LL_TIM_IsEnabledAutomaticOutput(TIM_TypeDef *TIMx)
  2568. {
  2569. return ((READ_BIT(TIMx->BDTR, TIM_BDTR_AOE) == (TIM_BDTR_AOE)) ? 1UL : 0UL);
  2570. }
  2571. /**
  2572. * @brief Enable the outputs (set the MOE bit in TIMx_BDTR register).
  2573. * @note The MOE bit in TIMx_BDTR register allows to enable /disable the outputs by
  2574. * software and is reset in case of break or break2 event
  2575. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2576. * a timer instance provides a break input.
  2577. * @rmtoll BDTR MOE LL_TIM_EnableAllOutputs
  2578. * @param TIMx Timer instance
  2579. * @retval None
  2580. */
  2581. __STATIC_INLINE void LL_TIM_EnableAllOutputs(TIM_TypeDef *TIMx)
  2582. {
  2583. SET_BIT(TIMx->BDTR, TIM_BDTR_MOE);
  2584. }
  2585. /**
  2586. * @brief Disable the outputs (reset the MOE bit in TIMx_BDTR register).
  2587. * @note The MOE bit in TIMx_BDTR register allows to enable /disable the outputs by
  2588. * software and is reset in case of break or break2 event.
  2589. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2590. * a timer instance provides a break input.
  2591. * @rmtoll BDTR MOE LL_TIM_DisableAllOutputs
  2592. * @param TIMx Timer instance
  2593. * @retval None
  2594. */
  2595. __STATIC_INLINE void LL_TIM_DisableAllOutputs(TIM_TypeDef *TIMx)
  2596. {
  2597. CLEAR_BIT(TIMx->BDTR, TIM_BDTR_MOE);
  2598. }
  2599. /**
  2600. * @brief Indicates whether outputs are enabled.
  2601. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  2602. * a timer instance provides a break input.
  2603. * @rmtoll BDTR MOE LL_TIM_IsEnabledAllOutputs
  2604. * @param TIMx Timer instance
  2605. * @retval State of bit (1 or 0).
  2606. */
  2607. __STATIC_INLINE uint32_t LL_TIM_IsEnabledAllOutputs(TIM_TypeDef *TIMx)
  2608. {
  2609. return ((READ_BIT(TIMx->BDTR, TIM_BDTR_MOE) == (TIM_BDTR_MOE)) ? 1UL : 0UL);
  2610. }
  2611. /**
  2612. * @}
  2613. */
  2614. #if (defined(DMA) || defined(DMA1))
  2615. /** @defgroup TIM_LL_EF_DMA_Burst_Mode DMA burst mode configuration
  2616. * @{
  2617. */
  2618. /**
  2619. * @brief Configures the timer DMA burst feature.
  2620. * @note Macro IS_TIM_DMABURST_INSTANCE(TIMx) can be used to check whether or
  2621. * not a timer instance supports the DMA burst mode.
  2622. * @rmtoll DCR DBL LL_TIM_ConfigDMABurst\n
  2623. * DCR DBA LL_TIM_ConfigDMABurst
  2624. * @param TIMx Timer instance
  2625. * @param DMABurstBaseAddress This parameter can be one of the following values:
  2626. * @arg @ref LL_TIM_DMABURST_BASEADDR_CR1
  2627. * @arg @ref LL_TIM_DMABURST_BASEADDR_CR2
  2628. * @arg @ref LL_TIM_DMABURST_BASEADDR_SMCR
  2629. * @arg @ref LL_TIM_DMABURST_BASEADDR_DIER
  2630. * @arg @ref LL_TIM_DMABURST_BASEADDR_SR
  2631. * @arg @ref LL_TIM_DMABURST_BASEADDR_EGR
  2632. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCMR1
  2633. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCMR2
  2634. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCER
  2635. * @arg @ref LL_TIM_DMABURST_BASEADDR_CNT
  2636. * @arg @ref LL_TIM_DMABURST_BASEADDR_PSC
  2637. * @arg @ref LL_TIM_DMABURST_BASEADDR_ARR
  2638. * @arg @ref LL_TIM_DMABURST_BASEADDR_RCR
  2639. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR1
  2640. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR2
  2641. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR3
  2642. * @arg @ref LL_TIM_DMABURST_BASEADDR_CCR4
  2643. * @arg @ref LL_TIM_DMABURST_BASEADDR_BDTR
  2644. * @param DMABurstLength This parameter can be one of the following values:
  2645. * @arg @ref LL_TIM_DMABURST_LENGTH_1TRANSFER
  2646. * @arg @ref LL_TIM_DMABURST_LENGTH_2TRANSFERS
  2647. * @arg @ref LL_TIM_DMABURST_LENGTH_3TRANSFERS
  2648. * @arg @ref LL_TIM_DMABURST_LENGTH_4TRANSFERS
  2649. * @arg @ref LL_TIM_DMABURST_LENGTH_5TRANSFERS
  2650. * @arg @ref LL_TIM_DMABURST_LENGTH_6TRANSFERS
  2651. * @arg @ref LL_TIM_DMABURST_LENGTH_7TRANSFERS
  2652. * @arg @ref LL_TIM_DMABURST_LENGTH_8TRANSFERS
  2653. * @arg @ref LL_TIM_DMABURST_LENGTH_9TRANSFERS
  2654. * @arg @ref LL_TIM_DMABURST_LENGTH_10TRANSFERS
  2655. * @arg @ref LL_TIM_DMABURST_LENGTH_11TRANSFERS
  2656. * @arg @ref LL_TIM_DMABURST_LENGTH_12TRANSFERS
  2657. * @arg @ref LL_TIM_DMABURST_LENGTH_13TRANSFERS
  2658. * @arg @ref LL_TIM_DMABURST_LENGTH_14TRANSFERS
  2659. * @arg @ref LL_TIM_DMABURST_LENGTH_15TRANSFERS
  2660. * @arg @ref LL_TIM_DMABURST_LENGTH_16TRANSFERS
  2661. * @arg @ref LL_TIM_DMABURST_LENGTH_17TRANSFERS
  2662. * @arg @ref LL_TIM_DMABURST_LENGTH_18TRANSFERS
  2663. * @retval None
  2664. */
  2665. __STATIC_INLINE void LL_TIM_ConfigDMABurst(TIM_TypeDef *TIMx, uint32_t DMABurstBaseAddress, uint32_t DMABurstLength)
  2666. {
  2667. MODIFY_REG(TIMx->DCR, (TIM_DCR_DBL | TIM_DCR_DBA), (DMABurstBaseAddress | DMABurstLength));
  2668. }
  2669. /**
  2670. * @}
  2671. */
  2672. #endif
  2673. /** @defgroup TIM_LL_EF_OCREF_Clear OCREF_Clear_Management
  2674. * @{
  2675. */
  2676. /**
  2677. * @brief Set the OCREF clear input source
  2678. * @note The OCxREF signal of a given channel can be cleared when a high level is applied on the OCREF_CLR_INPUT
  2679. * @note This function can only be used in Output compare and PWM modes.
  2680. * @rmtoll SMCR OCCS LL_TIM_SetOCRefClearInputSource
  2681. * @param TIMx Timer instance
  2682. * @param OCRefClearInputSource This parameter can be one of the following values:
  2683. * @arg @ref LL_TIM_OCREF_CLR_INT_OCREF_CLR
  2684. * @arg @ref LL_TIM_OCREF_CLR_INT_ETR
  2685. * @retval None
  2686. */
  2687. __STATIC_INLINE void LL_TIM_SetOCRefClearInputSource(TIM_TypeDef *TIMx, uint32_t OCRefClearInputSource)
  2688. {
  2689. MODIFY_REG(TIMx->SMCR, TIM_SMCR_OCCS, OCRefClearInputSource);
  2690. }
  2691. /**
  2692. * @}
  2693. */
  2694. /** @defgroup TIM_LL_EF_FLAG_Management FLAG-Management
  2695. * @{
  2696. */
  2697. /**
  2698. * @brief Clear the update interrupt flag (UIF).
  2699. * @rmtoll SR UIF LL_TIM_ClearFlag_UPDATE
  2700. * @param TIMx Timer instance
  2701. * @retval None
  2702. */
  2703. __STATIC_INLINE void LL_TIM_ClearFlag_UPDATE(TIM_TypeDef *TIMx)
  2704. {
  2705. WRITE_REG(TIMx->SR, ~(TIM_SR_UIF));
  2706. }
  2707. /**
  2708. * @brief Indicate whether update interrupt flag (UIF) is set (update interrupt is pending).
  2709. * @rmtoll SR UIF LL_TIM_IsActiveFlag_UPDATE
  2710. * @param TIMx Timer instance
  2711. * @retval State of bit (1 or 0).
  2712. */
  2713. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_UPDATE(TIM_TypeDef *TIMx)
  2714. {
  2715. return ((READ_BIT(TIMx->SR, TIM_SR_UIF) == (TIM_SR_UIF)) ? 1UL : 0UL);
  2716. }
  2717. /**
  2718. * @brief Clear the Capture/Compare 1 interrupt flag (CC1F).
  2719. * @rmtoll SR CC1IF LL_TIM_ClearFlag_CC1
  2720. * @param TIMx Timer instance
  2721. * @retval None
  2722. */
  2723. __STATIC_INLINE void LL_TIM_ClearFlag_CC1(TIM_TypeDef *TIMx)
  2724. {
  2725. WRITE_REG(TIMx->SR, ~(TIM_SR_CC1IF));
  2726. }
  2727. /**
  2728. * @brief Indicate whether Capture/Compare 1 interrupt flag (CC1F) is set (Capture/Compare 1 interrupt is pending).
  2729. * @rmtoll SR CC1IF LL_TIM_IsActiveFlag_CC1
  2730. * @param TIMx Timer instance
  2731. * @retval State of bit (1 or 0).
  2732. */
  2733. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC1(TIM_TypeDef *TIMx)
  2734. {
  2735. return ((READ_BIT(TIMx->SR, TIM_SR_CC1IF) == (TIM_SR_CC1IF)) ? 1UL : 0UL);
  2736. }
  2737. /**
  2738. * @brief Clear the Capture/Compare 2 interrupt flag (CC2F).
  2739. * @rmtoll SR CC2IF LL_TIM_ClearFlag_CC2
  2740. * @param TIMx Timer instance
  2741. * @retval None
  2742. */
  2743. __STATIC_INLINE void LL_TIM_ClearFlag_CC2(TIM_TypeDef *TIMx)
  2744. {
  2745. WRITE_REG(TIMx->SR, ~(TIM_SR_CC2IF));
  2746. }
  2747. /**
  2748. * @brief Indicate whether Capture/Compare 2 interrupt flag (CC2F) is set (Capture/Compare 2 interrupt is pending).
  2749. * @rmtoll SR CC2IF LL_TIM_IsActiveFlag_CC2
  2750. * @param TIMx Timer instance
  2751. * @retval State of bit (1 or 0).
  2752. */
  2753. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC2(TIM_TypeDef *TIMx)
  2754. {
  2755. return ((READ_BIT(TIMx->SR, TIM_SR_CC2IF) == (TIM_SR_CC2IF)) ? 1UL : 0UL);
  2756. }
  2757. /**
  2758. * @brief Clear the Capture/Compare 3 interrupt flag (CC3F).
  2759. * @rmtoll SR CC3IF LL_TIM_ClearFlag_CC3
  2760. * @param TIMx Timer instance
  2761. * @retval None
  2762. */
  2763. __STATIC_INLINE void LL_TIM_ClearFlag_CC3(TIM_TypeDef *TIMx)
  2764. {
  2765. WRITE_REG(TIMx->SR, ~(TIM_SR_CC3IF));
  2766. }
  2767. /**
  2768. * @brief Indicate whether Capture/Compare 3 interrupt flag (CC3F) is set (Capture/Compare 3 interrupt is pending).
  2769. * @rmtoll SR CC3IF LL_TIM_IsActiveFlag_CC3
  2770. * @param TIMx Timer instance
  2771. * @retval State of bit (1 or 0).
  2772. */
  2773. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC3(TIM_TypeDef *TIMx)
  2774. {
  2775. return ((READ_BIT(TIMx->SR, TIM_SR_CC3IF) == (TIM_SR_CC3IF)) ? 1UL : 0UL);
  2776. }
  2777. /**
  2778. * @brief Clear the Capture/Compare 4 interrupt flag (CC4F).
  2779. * @rmtoll SR CC4IF LL_TIM_ClearFlag_CC4
  2780. * @param TIMx Timer instance
  2781. * @retval None
  2782. */
  2783. __STATIC_INLINE void LL_TIM_ClearFlag_CC4(TIM_TypeDef *TIMx)
  2784. {
  2785. WRITE_REG(TIMx->SR, ~(TIM_SR_CC4IF));
  2786. }
  2787. /**
  2788. * @brief Indicate whether Capture/Compare 4 interrupt flag (CC4F) is set (Capture/Compare 4 interrupt is pending).
  2789. * @rmtoll SR CC4IF LL_TIM_IsActiveFlag_CC4
  2790. * @param TIMx Timer instance
  2791. * @retval State of bit (1 or 0).
  2792. */
  2793. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC4(TIM_TypeDef *TIMx)
  2794. {
  2795. return ((READ_BIT(TIMx->SR, TIM_SR_CC4IF) == (TIM_SR_CC4IF)) ? 1UL : 0UL);
  2796. }
  2797. /**
  2798. * @brief Clear the commutation interrupt flag (COMIF).
  2799. * @rmtoll SR COMIF LL_TIM_ClearFlag_COM
  2800. * @param TIMx Timer instance
  2801. * @retval None
  2802. */
  2803. __STATIC_INLINE void LL_TIM_ClearFlag_COM(TIM_TypeDef *TIMx)
  2804. {
  2805. WRITE_REG(TIMx->SR, ~(TIM_SR_COMIF));
  2806. }
  2807. /**
  2808. * @brief Indicate whether commutation interrupt flag (COMIF) is set (commutation interrupt is pending).
  2809. * @rmtoll SR COMIF LL_TIM_IsActiveFlag_COM
  2810. * @param TIMx Timer instance
  2811. * @retval State of bit (1 or 0).
  2812. */
  2813. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_COM(TIM_TypeDef *TIMx)
  2814. {
  2815. return ((READ_BIT(TIMx->SR, TIM_SR_COMIF) == (TIM_SR_COMIF)) ? 1UL : 0UL);
  2816. }
  2817. /**
  2818. * @brief Clear the trigger interrupt flag (TIF).
  2819. * @rmtoll SR TIF LL_TIM_ClearFlag_TRIG
  2820. * @param TIMx Timer instance
  2821. * @retval None
  2822. */
  2823. __STATIC_INLINE void LL_TIM_ClearFlag_TRIG(TIM_TypeDef *TIMx)
  2824. {
  2825. WRITE_REG(TIMx->SR, ~(TIM_SR_TIF));
  2826. }
  2827. /**
  2828. * @brief Indicate whether trigger interrupt flag (TIF) is set (trigger interrupt is pending).
  2829. * @rmtoll SR TIF LL_TIM_IsActiveFlag_TRIG
  2830. * @param TIMx Timer instance
  2831. * @retval State of bit (1 or 0).
  2832. */
  2833. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_TRIG(TIM_TypeDef *TIMx)
  2834. {
  2835. return ((READ_BIT(TIMx->SR, TIM_SR_TIF) == (TIM_SR_TIF)) ? 1UL : 0UL);
  2836. }
  2837. /**
  2838. * @brief Clear the break interrupt flag (BIF).
  2839. * @rmtoll SR BIF LL_TIM_ClearFlag_BRK
  2840. * @param TIMx Timer instance
  2841. * @retval None
  2842. */
  2843. __STATIC_INLINE void LL_TIM_ClearFlag_BRK(TIM_TypeDef *TIMx)
  2844. {
  2845. WRITE_REG(TIMx->SR, ~(TIM_SR_BIF));
  2846. }
  2847. /**
  2848. * @brief Indicate whether break interrupt flag (BIF) is set (break interrupt is pending).
  2849. * @rmtoll SR BIF LL_TIM_IsActiveFlag_BRK
  2850. * @param TIMx Timer instance
  2851. * @retval State of bit (1 or 0).
  2852. */
  2853. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_BRK(TIM_TypeDef *TIMx)
  2854. {
  2855. return ((READ_BIT(TIMx->SR, TIM_SR_BIF) == (TIM_SR_BIF)) ? 1UL : 0UL);
  2856. }
  2857. /**
  2858. * @brief Clear the Capture/Compare 1 over-capture interrupt flag (CC1OF).
  2859. * @rmtoll SR CC1OF LL_TIM_ClearFlag_CC1OVR
  2860. * @param TIMx Timer instance
  2861. * @retval None
  2862. */
  2863. __STATIC_INLINE void LL_TIM_ClearFlag_CC1OVR(TIM_TypeDef *TIMx)
  2864. {
  2865. WRITE_REG(TIMx->SR, ~(TIM_SR_CC1OF));
  2866. }
  2867. /**
  2868. * @brief Indicate whether Capture/Compare 1 over-capture interrupt flag (CC1OF) is set (Capture/Compare 1 interrupt is pending).
  2869. * @rmtoll SR CC1OF LL_TIM_IsActiveFlag_CC1OVR
  2870. * @param TIMx Timer instance
  2871. * @retval State of bit (1 or 0).
  2872. */
  2873. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC1OVR(TIM_TypeDef *TIMx)
  2874. {
  2875. return ((READ_BIT(TIMx->SR, TIM_SR_CC1OF) == (TIM_SR_CC1OF)) ? 1UL : 0UL);
  2876. }
  2877. /**
  2878. * @brief Clear the Capture/Compare 2 over-capture interrupt flag (CC2OF).
  2879. * @rmtoll SR CC2OF LL_TIM_ClearFlag_CC2OVR
  2880. * @param TIMx Timer instance
  2881. * @retval None
  2882. */
  2883. __STATIC_INLINE void LL_TIM_ClearFlag_CC2OVR(TIM_TypeDef *TIMx)
  2884. {
  2885. WRITE_REG(TIMx->SR, ~(TIM_SR_CC2OF));
  2886. }
  2887. /**
  2888. * @brief Indicate whether Capture/Compare 2 over-capture interrupt flag (CC2OF) is set (Capture/Compare 2 over-capture interrupt is pending).
  2889. * @rmtoll SR CC2OF LL_TIM_IsActiveFlag_CC2OVR
  2890. * @param TIMx Timer instance
  2891. * @retval State of bit (1 or 0).
  2892. */
  2893. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC2OVR(TIM_TypeDef *TIMx)
  2894. {
  2895. return ((READ_BIT(TIMx->SR, TIM_SR_CC2OF) == (TIM_SR_CC2OF)) ? 1UL : 0UL);
  2896. }
  2897. /**
  2898. * @brief Clear the Capture/Compare 3 over-capture interrupt flag (CC3OF).
  2899. * @rmtoll SR CC3OF LL_TIM_ClearFlag_CC3OVR
  2900. * @param TIMx Timer instance
  2901. * @retval None
  2902. */
  2903. __STATIC_INLINE void LL_TIM_ClearFlag_CC3OVR(TIM_TypeDef *TIMx)
  2904. {
  2905. WRITE_REG(TIMx->SR, ~(TIM_SR_CC3OF));
  2906. }
  2907. /**
  2908. * @brief Indicate whether Capture/Compare 3 over-capture interrupt flag (CC3OF) is set (Capture/Compare 3 over-capture interrupt is pending).
  2909. * @rmtoll SR CC3OF LL_TIM_IsActiveFlag_CC3OVR
  2910. * @param TIMx Timer instance
  2911. * @retval State of bit (1 or 0).
  2912. */
  2913. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC3OVR(TIM_TypeDef *TIMx)
  2914. {
  2915. return ((READ_BIT(TIMx->SR, TIM_SR_CC3OF) == (TIM_SR_CC3OF)) ? 1UL : 0UL);
  2916. }
  2917. /**
  2918. * @brief Clear the Capture/Compare 4 over-capture interrupt flag (CC4OF).
  2919. * @rmtoll SR CC4OF LL_TIM_ClearFlag_CC4OVR
  2920. * @param TIMx Timer instance
  2921. * @retval None
  2922. */
  2923. __STATIC_INLINE void LL_TIM_ClearFlag_CC4OVR(TIM_TypeDef *TIMx)
  2924. {
  2925. WRITE_REG(TIMx->SR, ~(TIM_SR_CC4OF));
  2926. }
  2927. /**
  2928. * @brief Indicate whether Capture/Compare 4 over-capture interrupt flag (CC4OF) is set (Capture/Compare 4 over-capture interrupt is pending).
  2929. * @rmtoll SR CC4OF LL_TIM_IsActiveFlag_CC4OVR
  2930. * @param TIMx Timer instance
  2931. * @retval State of bit (1 or 0).
  2932. */
  2933. __STATIC_INLINE uint32_t LL_TIM_IsActiveFlag_CC4OVR(TIM_TypeDef *TIMx)
  2934. {
  2935. return ((READ_BIT(TIMx->SR, TIM_SR_CC4OF) == (TIM_SR_CC4OF)) ? 1UL : 0UL);
  2936. }
  2937. /**
  2938. * @}
  2939. */
  2940. /** @defgroup TIM_LL_EF_IT_Management IT-Management
  2941. * @{
  2942. */
  2943. /**
  2944. * @brief Enable update interrupt (UIE).
  2945. * @rmtoll DIER UIE LL_TIM_EnableIT_UPDATE
  2946. * @param TIMx Timer instance
  2947. * @retval None
  2948. */
  2949. __STATIC_INLINE void LL_TIM_EnableIT_UPDATE(TIM_TypeDef *TIMx)
  2950. {
  2951. SET_BIT(TIMx->DIER, TIM_DIER_UIE);
  2952. }
  2953. /**
  2954. * @brief Disable update interrupt (UIE).
  2955. * @rmtoll DIER UIE LL_TIM_DisableIT_UPDATE
  2956. * @param TIMx Timer instance
  2957. * @retval None
  2958. */
  2959. __STATIC_INLINE void LL_TIM_DisableIT_UPDATE(TIM_TypeDef *TIMx)
  2960. {
  2961. CLEAR_BIT(TIMx->DIER, TIM_DIER_UIE);
  2962. }
  2963. /**
  2964. * @brief Indicates whether the update interrupt (UIE) is enabled.
  2965. * @rmtoll DIER UIE LL_TIM_IsEnabledIT_UPDATE
  2966. * @param TIMx Timer instance
  2967. * @retval State of bit (1 or 0).
  2968. */
  2969. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_UPDATE(TIM_TypeDef *TIMx)
  2970. {
  2971. return ((READ_BIT(TIMx->DIER, TIM_DIER_UIE) == (TIM_DIER_UIE)) ? 1UL : 0UL);
  2972. }
  2973. /**
  2974. * @brief Enable capture/compare 1 interrupt (CC1IE).
  2975. * @rmtoll DIER CC1IE LL_TIM_EnableIT_CC1
  2976. * @param TIMx Timer instance
  2977. * @retval None
  2978. */
  2979. __STATIC_INLINE void LL_TIM_EnableIT_CC1(TIM_TypeDef *TIMx)
  2980. {
  2981. SET_BIT(TIMx->DIER, TIM_DIER_CC1IE);
  2982. }
  2983. /**
  2984. * @brief Disable capture/compare 1 interrupt (CC1IE).
  2985. * @rmtoll DIER CC1IE LL_TIM_DisableIT_CC1
  2986. * @param TIMx Timer instance
  2987. * @retval None
  2988. */
  2989. __STATIC_INLINE void LL_TIM_DisableIT_CC1(TIM_TypeDef *TIMx)
  2990. {
  2991. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC1IE);
  2992. }
  2993. /**
  2994. * @brief Indicates whether the capture/compare 1 interrupt (CC1IE) is enabled.
  2995. * @rmtoll DIER CC1IE LL_TIM_IsEnabledIT_CC1
  2996. * @param TIMx Timer instance
  2997. * @retval State of bit (1 or 0).
  2998. */
  2999. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC1(TIM_TypeDef *TIMx)
  3000. {
  3001. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC1IE) == (TIM_DIER_CC1IE)) ? 1UL : 0UL);
  3002. }
  3003. /**
  3004. * @brief Enable capture/compare 2 interrupt (CC2IE).
  3005. * @rmtoll DIER CC2IE LL_TIM_EnableIT_CC2
  3006. * @param TIMx Timer instance
  3007. * @retval None
  3008. */
  3009. __STATIC_INLINE void LL_TIM_EnableIT_CC2(TIM_TypeDef *TIMx)
  3010. {
  3011. SET_BIT(TIMx->DIER, TIM_DIER_CC2IE);
  3012. }
  3013. /**
  3014. * @brief Disable capture/compare 2 interrupt (CC2IE).
  3015. * @rmtoll DIER CC2IE LL_TIM_DisableIT_CC2
  3016. * @param TIMx Timer instance
  3017. * @retval None
  3018. */
  3019. __STATIC_INLINE void LL_TIM_DisableIT_CC2(TIM_TypeDef *TIMx)
  3020. {
  3021. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC2IE);
  3022. }
  3023. /**
  3024. * @brief Indicates whether the capture/compare 2 interrupt (CC2IE) is enabled.
  3025. * @rmtoll DIER CC2IE LL_TIM_IsEnabledIT_CC2
  3026. * @param TIMx Timer instance
  3027. * @retval State of bit (1 or 0).
  3028. */
  3029. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC2(TIM_TypeDef *TIMx)
  3030. {
  3031. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC2IE) == (TIM_DIER_CC2IE)) ? 1UL : 0UL);
  3032. }
  3033. /**
  3034. * @brief Enable capture/compare 3 interrupt (CC3IE).
  3035. * @rmtoll DIER CC3IE LL_TIM_EnableIT_CC3
  3036. * @param TIMx Timer instance
  3037. * @retval None
  3038. */
  3039. __STATIC_INLINE void LL_TIM_EnableIT_CC3(TIM_TypeDef *TIMx)
  3040. {
  3041. SET_BIT(TIMx->DIER, TIM_DIER_CC3IE);
  3042. }
  3043. /**
  3044. * @brief Disable capture/compare 3 interrupt (CC3IE).
  3045. * @rmtoll DIER CC3IE LL_TIM_DisableIT_CC3
  3046. * @param TIMx Timer instance
  3047. * @retval None
  3048. */
  3049. __STATIC_INLINE void LL_TIM_DisableIT_CC3(TIM_TypeDef *TIMx)
  3050. {
  3051. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC3IE);
  3052. }
  3053. /**
  3054. * @brief Indicates whether the capture/compare 3 interrupt (CC3IE) is enabled.
  3055. * @rmtoll DIER CC3IE LL_TIM_IsEnabledIT_CC3
  3056. * @param TIMx Timer instance
  3057. * @retval State of bit (1 or 0).
  3058. */
  3059. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC3(TIM_TypeDef *TIMx)
  3060. {
  3061. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC3IE) == (TIM_DIER_CC3IE)) ? 1UL : 0UL);
  3062. }
  3063. /**
  3064. * @brief Enable capture/compare 4 interrupt (CC4IE).
  3065. * @rmtoll DIER CC4IE LL_TIM_EnableIT_CC4
  3066. * @param TIMx Timer instance
  3067. * @retval None
  3068. */
  3069. __STATIC_INLINE void LL_TIM_EnableIT_CC4(TIM_TypeDef *TIMx)
  3070. {
  3071. SET_BIT(TIMx->DIER, TIM_DIER_CC4IE);
  3072. }
  3073. /**
  3074. * @brief Disable capture/compare 4 interrupt (CC4IE).
  3075. * @rmtoll DIER CC4IE LL_TIM_DisableIT_CC4
  3076. * @param TIMx Timer instance
  3077. * @retval None
  3078. */
  3079. __STATIC_INLINE void LL_TIM_DisableIT_CC4(TIM_TypeDef *TIMx)
  3080. {
  3081. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC4IE);
  3082. }
  3083. /**
  3084. * @brief Indicates whether the capture/compare 4 interrupt (CC4IE) is enabled.
  3085. * @rmtoll DIER CC4IE LL_TIM_IsEnabledIT_CC4
  3086. * @param TIMx Timer instance
  3087. * @retval State of bit (1 or 0).
  3088. */
  3089. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_CC4(TIM_TypeDef *TIMx)
  3090. {
  3091. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC4IE) == (TIM_DIER_CC4IE)) ? 1UL : 0UL);
  3092. }
  3093. /**
  3094. * @brief Enable commutation interrupt (COMIE).
  3095. * @rmtoll DIER COMIE LL_TIM_EnableIT_COM
  3096. * @param TIMx Timer instance
  3097. * @retval None
  3098. */
  3099. __STATIC_INLINE void LL_TIM_EnableIT_COM(TIM_TypeDef *TIMx)
  3100. {
  3101. SET_BIT(TIMx->DIER, TIM_DIER_COMIE);
  3102. }
  3103. /**
  3104. * @brief Disable commutation interrupt (COMIE).
  3105. * @rmtoll DIER COMIE LL_TIM_DisableIT_COM
  3106. * @param TIMx Timer instance
  3107. * @retval None
  3108. */
  3109. __STATIC_INLINE void LL_TIM_DisableIT_COM(TIM_TypeDef *TIMx)
  3110. {
  3111. CLEAR_BIT(TIMx->DIER, TIM_DIER_COMIE);
  3112. }
  3113. /**
  3114. * @brief Indicates whether the commutation interrupt (COMIE) is enabled.
  3115. * @rmtoll DIER COMIE LL_TIM_IsEnabledIT_COM
  3116. * @param TIMx Timer instance
  3117. * @retval State of bit (1 or 0).
  3118. */
  3119. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_COM(TIM_TypeDef *TIMx)
  3120. {
  3121. return ((READ_BIT(TIMx->DIER, TIM_DIER_COMIE) == (TIM_DIER_COMIE)) ? 1UL : 0UL);
  3122. }
  3123. /**
  3124. * @brief Enable trigger interrupt (TIE).
  3125. * @rmtoll DIER TIE LL_TIM_EnableIT_TRIG
  3126. * @param TIMx Timer instance
  3127. * @retval None
  3128. */
  3129. __STATIC_INLINE void LL_TIM_EnableIT_TRIG(TIM_TypeDef *TIMx)
  3130. {
  3131. SET_BIT(TIMx->DIER, TIM_DIER_TIE);
  3132. }
  3133. /**
  3134. * @brief Disable trigger interrupt (TIE).
  3135. * @rmtoll DIER TIE LL_TIM_DisableIT_TRIG
  3136. * @param TIMx Timer instance
  3137. * @retval None
  3138. */
  3139. __STATIC_INLINE void LL_TIM_DisableIT_TRIG(TIM_TypeDef *TIMx)
  3140. {
  3141. CLEAR_BIT(TIMx->DIER, TIM_DIER_TIE);
  3142. }
  3143. /**
  3144. * @brief Indicates whether the trigger interrupt (TIE) is enabled.
  3145. * @rmtoll DIER TIE LL_TIM_IsEnabledIT_TRIG
  3146. * @param TIMx Timer instance
  3147. * @retval State of bit (1 or 0).
  3148. */
  3149. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_TRIG(TIM_TypeDef *TIMx)
  3150. {
  3151. return ((READ_BIT(TIMx->DIER, TIM_DIER_TIE) == (TIM_DIER_TIE)) ? 1UL : 0UL);
  3152. }
  3153. /**
  3154. * @brief Enable break interrupt (BIE).
  3155. * @rmtoll DIER BIE LL_TIM_EnableIT_BRK
  3156. * @param TIMx Timer instance
  3157. * @retval None
  3158. */
  3159. __STATIC_INLINE void LL_TIM_EnableIT_BRK(TIM_TypeDef *TIMx)
  3160. {
  3161. SET_BIT(TIMx->DIER, TIM_DIER_BIE);
  3162. }
  3163. /**
  3164. * @brief Disable break interrupt (BIE).
  3165. * @rmtoll DIER BIE LL_TIM_DisableIT_BRK
  3166. * @param TIMx Timer instance
  3167. * @retval None
  3168. */
  3169. __STATIC_INLINE void LL_TIM_DisableIT_BRK(TIM_TypeDef *TIMx)
  3170. {
  3171. CLEAR_BIT(TIMx->DIER, TIM_DIER_BIE);
  3172. }
  3173. /**
  3174. * @brief Indicates whether the break interrupt (BIE) is enabled.
  3175. * @rmtoll DIER BIE LL_TIM_IsEnabledIT_BRK
  3176. * @param TIMx Timer instance
  3177. * @retval State of bit (1 or 0).
  3178. */
  3179. __STATIC_INLINE uint32_t LL_TIM_IsEnabledIT_BRK(TIM_TypeDef *TIMx)
  3180. {
  3181. return ((READ_BIT(TIMx->DIER, TIM_DIER_BIE) == (TIM_DIER_BIE)) ? 1UL : 0UL);
  3182. }
  3183. /**
  3184. * @}
  3185. */
  3186. #if (defined(DMA) || defined(DMA1))
  3187. /** @defgroup TIM_LL_EF_DMA_Management DMA-Management
  3188. * @{
  3189. */
  3190. /**
  3191. * @brief Enable update DMA request (UDE).
  3192. * @rmtoll DIER UDE LL_TIM_EnableDMAReq_UPDATE
  3193. * @param TIMx Timer instance
  3194. * @retval None
  3195. */
  3196. __STATIC_INLINE void LL_TIM_EnableDMAReq_UPDATE(TIM_TypeDef *TIMx)
  3197. {
  3198. SET_BIT(TIMx->DIER, TIM_DIER_UDE);
  3199. }
  3200. /**
  3201. * @brief Disable update DMA request (UDE).
  3202. * @rmtoll DIER UDE LL_TIM_DisableDMAReq_UPDATE
  3203. * @param TIMx Timer instance
  3204. * @retval None
  3205. */
  3206. __STATIC_INLINE void LL_TIM_DisableDMAReq_UPDATE(TIM_TypeDef *TIMx)
  3207. {
  3208. CLEAR_BIT(TIMx->DIER, TIM_DIER_UDE);
  3209. }
  3210. /**
  3211. * @brief Indicates whether the update DMA request (UDE) is enabled.
  3212. * @rmtoll DIER UDE LL_TIM_IsEnabledDMAReq_UPDATE
  3213. * @param TIMx Timer instance
  3214. * @retval State of bit (1 or 0).
  3215. */
  3216. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_UPDATE(TIM_TypeDef *TIMx)
  3217. {
  3218. return ((READ_BIT(TIMx->DIER, TIM_DIER_UDE) == (TIM_DIER_UDE)) ? 1UL : 0UL);
  3219. }
  3220. /**
  3221. * @brief Enable capture/compare 1 DMA request (CC1DE).
  3222. * @rmtoll DIER CC1DE LL_TIM_EnableDMAReq_CC1
  3223. * @param TIMx Timer instance
  3224. * @retval None
  3225. */
  3226. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC1(TIM_TypeDef *TIMx)
  3227. {
  3228. SET_BIT(TIMx->DIER, TIM_DIER_CC1DE);
  3229. }
  3230. /**
  3231. * @brief Disable capture/compare 1 DMA request (CC1DE).
  3232. * @rmtoll DIER CC1DE LL_TIM_DisableDMAReq_CC1
  3233. * @param TIMx Timer instance
  3234. * @retval None
  3235. */
  3236. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC1(TIM_TypeDef *TIMx)
  3237. {
  3238. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC1DE);
  3239. }
  3240. /**
  3241. * @brief Indicates whether the capture/compare 1 DMA request (CC1DE) is enabled.
  3242. * @rmtoll DIER CC1DE LL_TIM_IsEnabledDMAReq_CC1
  3243. * @param TIMx Timer instance
  3244. * @retval State of bit (1 or 0).
  3245. */
  3246. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC1(TIM_TypeDef *TIMx)
  3247. {
  3248. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC1DE) == (TIM_DIER_CC1DE)) ? 1UL : 0UL);
  3249. }
  3250. /**
  3251. * @brief Enable capture/compare 2 DMA request (CC2DE).
  3252. * @rmtoll DIER CC2DE LL_TIM_EnableDMAReq_CC2
  3253. * @param TIMx Timer instance
  3254. * @retval None
  3255. */
  3256. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC2(TIM_TypeDef *TIMx)
  3257. {
  3258. SET_BIT(TIMx->DIER, TIM_DIER_CC2DE);
  3259. }
  3260. /**
  3261. * @brief Disable capture/compare 2 DMA request (CC2DE).
  3262. * @rmtoll DIER CC2DE LL_TIM_DisableDMAReq_CC2
  3263. * @param TIMx Timer instance
  3264. * @retval None
  3265. */
  3266. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC2(TIM_TypeDef *TIMx)
  3267. {
  3268. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC2DE);
  3269. }
  3270. /**
  3271. * @brief Indicates whether the capture/compare 2 DMA request (CC2DE) is enabled.
  3272. * @rmtoll DIER CC2DE LL_TIM_IsEnabledDMAReq_CC2
  3273. * @param TIMx Timer instance
  3274. * @retval State of bit (1 or 0).
  3275. */
  3276. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC2(TIM_TypeDef *TIMx)
  3277. {
  3278. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC2DE) == (TIM_DIER_CC2DE)) ? 1UL : 0UL);
  3279. }
  3280. /**
  3281. * @brief Enable capture/compare 3 DMA request (CC3DE).
  3282. * @rmtoll DIER CC3DE LL_TIM_EnableDMAReq_CC3
  3283. * @param TIMx Timer instance
  3284. * @retval None
  3285. */
  3286. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC3(TIM_TypeDef *TIMx)
  3287. {
  3288. SET_BIT(TIMx->DIER, TIM_DIER_CC3DE);
  3289. }
  3290. /**
  3291. * @brief Disable capture/compare 3 DMA request (CC3DE).
  3292. * @rmtoll DIER CC3DE LL_TIM_DisableDMAReq_CC3
  3293. * @param TIMx Timer instance
  3294. * @retval None
  3295. */
  3296. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC3(TIM_TypeDef *TIMx)
  3297. {
  3298. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC3DE);
  3299. }
  3300. /**
  3301. * @brief Indicates whether the capture/compare 3 DMA request (CC3DE) is enabled.
  3302. * @rmtoll DIER CC3DE LL_TIM_IsEnabledDMAReq_CC3
  3303. * @param TIMx Timer instance
  3304. * @retval State of bit (1 or 0).
  3305. */
  3306. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC3(TIM_TypeDef *TIMx)
  3307. {
  3308. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC3DE) == (TIM_DIER_CC3DE)) ? 1UL : 0UL);
  3309. }
  3310. /**
  3311. * @brief Enable capture/compare 4 DMA request (CC4DE).
  3312. * @rmtoll DIER CC4DE LL_TIM_EnableDMAReq_CC4
  3313. * @param TIMx Timer instance
  3314. * @retval None
  3315. */
  3316. __STATIC_INLINE void LL_TIM_EnableDMAReq_CC4(TIM_TypeDef *TIMx)
  3317. {
  3318. SET_BIT(TIMx->DIER, TIM_DIER_CC4DE);
  3319. }
  3320. /**
  3321. * @brief Disable capture/compare 4 DMA request (CC4DE).
  3322. * @rmtoll DIER CC4DE LL_TIM_DisableDMAReq_CC4
  3323. * @param TIMx Timer instance
  3324. * @retval None
  3325. */
  3326. __STATIC_INLINE void LL_TIM_DisableDMAReq_CC4(TIM_TypeDef *TIMx)
  3327. {
  3328. CLEAR_BIT(TIMx->DIER, TIM_DIER_CC4DE);
  3329. }
  3330. /**
  3331. * @brief Indicates whether the capture/compare 4 DMA request (CC4DE) is enabled.
  3332. * @rmtoll DIER CC4DE LL_TIM_IsEnabledDMAReq_CC4
  3333. * @param TIMx Timer instance
  3334. * @retval State of bit (1 or 0).
  3335. */
  3336. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_CC4(TIM_TypeDef *TIMx)
  3337. {
  3338. return ((READ_BIT(TIMx->DIER, TIM_DIER_CC4DE) == (TIM_DIER_CC4DE)) ? 1UL : 0UL);
  3339. }
  3340. /**
  3341. * @brief Enable commutation DMA request (COMDE).
  3342. * @rmtoll DIER COMDE LL_TIM_EnableDMAReq_COM
  3343. * @param TIMx Timer instance
  3344. * @retval None
  3345. */
  3346. __STATIC_INLINE void LL_TIM_EnableDMAReq_COM(TIM_TypeDef *TIMx)
  3347. {
  3348. SET_BIT(TIMx->DIER, TIM_DIER_COMDE);
  3349. }
  3350. /**
  3351. * @brief Disable commutation DMA request (COMDE).
  3352. * @rmtoll DIER COMDE LL_TIM_DisableDMAReq_COM
  3353. * @param TIMx Timer instance
  3354. * @retval None
  3355. */
  3356. __STATIC_INLINE void LL_TIM_DisableDMAReq_COM(TIM_TypeDef *TIMx)
  3357. {
  3358. CLEAR_BIT(TIMx->DIER, TIM_DIER_COMDE);
  3359. }
  3360. /**
  3361. * @brief Indicates whether the commutation DMA request (COMDE) is enabled.
  3362. * @rmtoll DIER COMDE LL_TIM_IsEnabledDMAReq_COM
  3363. * @param TIMx Timer instance
  3364. * @retval State of bit (1 or 0).
  3365. */
  3366. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_COM(TIM_TypeDef *TIMx)
  3367. {
  3368. return ((READ_BIT(TIMx->DIER, TIM_DIER_COMDE) == (TIM_DIER_COMDE)) ? 1UL : 0UL);
  3369. }
  3370. /**
  3371. * @brief Enable trigger interrupt (TDE).
  3372. * @rmtoll DIER TDE LL_TIM_EnableDMAReq_TRIG
  3373. * @param TIMx Timer instance
  3374. * @retval None
  3375. */
  3376. __STATIC_INLINE void LL_TIM_EnableDMAReq_TRIG(TIM_TypeDef *TIMx)
  3377. {
  3378. SET_BIT(TIMx->DIER, TIM_DIER_TDE);
  3379. }
  3380. /**
  3381. * @brief Disable trigger interrupt (TDE).
  3382. * @rmtoll DIER TDE LL_TIM_DisableDMAReq_TRIG
  3383. * @param TIMx Timer instance
  3384. * @retval None
  3385. */
  3386. __STATIC_INLINE void LL_TIM_DisableDMAReq_TRIG(TIM_TypeDef *TIMx)
  3387. {
  3388. CLEAR_BIT(TIMx->DIER, TIM_DIER_TDE);
  3389. }
  3390. /**
  3391. * @brief Indicates whether the trigger interrupt (TDE) is enabled.
  3392. * @rmtoll DIER TDE LL_TIM_IsEnabledDMAReq_TRIG
  3393. * @param TIMx Timer instance
  3394. * @retval State of bit (1 or 0).
  3395. */
  3396. __STATIC_INLINE uint32_t LL_TIM_IsEnabledDMAReq_TRIG(TIM_TypeDef *TIMx)
  3397. {
  3398. return ((READ_BIT(TIMx->DIER, TIM_DIER_TDE) == (TIM_DIER_TDE)) ? 1UL : 0UL);
  3399. }
  3400. /**
  3401. * @}
  3402. */
  3403. #endif
  3404. /** @defgroup TIM_LL_EF_EVENT_Management EVENT-Management
  3405. * @{
  3406. */
  3407. /**
  3408. * @brief Generate an update event.
  3409. * @rmtoll EGR UG LL_TIM_GenerateEvent_UPDATE
  3410. * @param TIMx Timer instance
  3411. * @retval None
  3412. */
  3413. __STATIC_INLINE void LL_TIM_GenerateEvent_UPDATE(TIM_TypeDef *TIMx)
  3414. {
  3415. SET_BIT(TIMx->EGR, TIM_EGR_UG);
  3416. }
  3417. /**
  3418. * @brief Generate Capture/Compare 1 event.
  3419. * @rmtoll EGR CC1G LL_TIM_GenerateEvent_CC1
  3420. * @param TIMx Timer instance
  3421. * @retval None
  3422. */
  3423. __STATIC_INLINE void LL_TIM_GenerateEvent_CC1(TIM_TypeDef *TIMx)
  3424. {
  3425. SET_BIT(TIMx->EGR, TIM_EGR_CC1G);
  3426. }
  3427. /**
  3428. * @brief Generate Capture/Compare 2 event.
  3429. * @rmtoll EGR CC2G LL_TIM_GenerateEvent_CC2
  3430. * @param TIMx Timer instance
  3431. * @retval None
  3432. */
  3433. __STATIC_INLINE void LL_TIM_GenerateEvent_CC2(TIM_TypeDef *TIMx)
  3434. {
  3435. SET_BIT(TIMx->EGR, TIM_EGR_CC2G);
  3436. }
  3437. /**
  3438. * @brief Generate Capture/Compare 3 event.
  3439. * @rmtoll EGR CC3G LL_TIM_GenerateEvent_CC3
  3440. * @param TIMx Timer instance
  3441. * @retval None
  3442. */
  3443. __STATIC_INLINE void LL_TIM_GenerateEvent_CC3(TIM_TypeDef *TIMx)
  3444. {
  3445. SET_BIT(TIMx->EGR, TIM_EGR_CC3G);
  3446. }
  3447. /**
  3448. * @brief Generate Capture/Compare 4 event.
  3449. * @rmtoll EGR CC4G LL_TIM_GenerateEvent_CC4
  3450. * @param TIMx Timer instance
  3451. * @retval None
  3452. */
  3453. __STATIC_INLINE void LL_TIM_GenerateEvent_CC4(TIM_TypeDef *TIMx)
  3454. {
  3455. SET_BIT(TIMx->EGR, TIM_EGR_CC4G);
  3456. }
  3457. /**
  3458. * @brief Generate commutation event.
  3459. * @rmtoll EGR COMG LL_TIM_GenerateEvent_COM
  3460. * @param TIMx Timer instance
  3461. * @retval None
  3462. */
  3463. __STATIC_INLINE void LL_TIM_GenerateEvent_COM(TIM_TypeDef *TIMx)
  3464. {
  3465. SET_BIT(TIMx->EGR, TIM_EGR_COMG);
  3466. }
  3467. /**
  3468. * @brief Generate trigger event.
  3469. * @rmtoll EGR TG LL_TIM_GenerateEvent_TRIG
  3470. * @param TIMx Timer instance
  3471. * @retval None
  3472. */
  3473. __STATIC_INLINE void LL_TIM_GenerateEvent_TRIG(TIM_TypeDef *TIMx)
  3474. {
  3475. SET_BIT(TIMx->EGR, TIM_EGR_TG);
  3476. }
  3477. /**
  3478. * @brief Generate break event.
  3479. * @rmtoll EGR BG LL_TIM_GenerateEvent_BRK
  3480. * @param TIMx Timer instance
  3481. * @retval None
  3482. */
  3483. __STATIC_INLINE void LL_TIM_GenerateEvent_BRK(TIM_TypeDef *TIMx)
  3484. {
  3485. SET_BIT(TIMx->EGR, TIM_EGR_BG);
  3486. }
  3487. /**
  3488. * @}
  3489. */
  3490. /** @defgroup TIM_LL_EF_Remap Remap
  3491. * @{
  3492. */
  3493. #if defined(TIM14)
  3494. /**
  3495. * @brief Configures the TIMx Remapping input capabilities.
  3496. * @param TIMx TIM.
  3497. * @param Remap specifies the TIM remapping source.
  3498. * For TIM14, the parameter can have the following values:
  3499. * @arg LL_TIM_TIM14_TI1_RMP_GPIO: TIM14 TI1 is connected to GPIO
  3500. * @arg LL_TIM_TIM14_TI1_RMP_RTC: TIM14 TI1 is connected to RTC_clock
  3501. * @arg LL_TIM_TIM14_TI1_RMP_HSE_32: TIM14 TI1 is connected to HSE/32
  3502. * @arg LL_TIM_TIM14_TI1_RMP_MCO: TIM14 TI1 is connected to MCO
  3503. *
  3504. * @retval HAL status
  3505. */
  3506. __STATIC_INLINE void LL_TIM_SetRemap(TIM_TypeDef *TIMx, uint32_t Remap)
  3507. {
  3508. WRITE_REG(TIMx->OR, Remap);
  3509. }
  3510. /**
  3511. * @brief Configures the TIMx Remapping input capabilities.
  3512. * @param TIMx TIM
  3513. * @retval Remap specifies the TIM remapping source.
  3514. * For TIM14, the parameter can have the following values:
  3515. * @arg LL_TIM_TIM14_TI1_RMP_GPIO: TIM14 TI1 is connected to GPIO
  3516. * @arg LL_TIM_TIM14_TI1_RMP_RTC: TIM14 TI1 is connected to RTC_clock
  3517. * @arg LL_TIM_TIM14_TI1_RMP_HSE_32: TIM14 TI1 is connected to HSE/32
  3518. * @arg LL_TIM_TIM14_TI1_RMP_MCO: TIM14 TI1 is connected to MCO
  3519. */
  3520. __STATIC_INLINE uint32_t LL_TIM_GetRemap(TIM_TypeDef *TIMx)
  3521. {
  3522. return READ_REG(TIMx->OR);
  3523. }
  3524. #endif
  3525. /**
  3526. * @}
  3527. */
  3528. #if defined(USE_FULL_LL_DRIVER)
  3529. /** @defgroup TIM_LL_EF_Init Initialisation and deinitialisation functions
  3530. * @{
  3531. */
  3532. ErrorStatus LL_TIM_DeInit(TIM_TypeDef *TIMx);
  3533. void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct);
  3534. ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, LL_TIM_InitTypeDef *TIM_InitStruct);
  3535. void LL_TIM_OC_StructInit(LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct);
  3536. ErrorStatus LL_TIM_OC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct);
  3537. void LL_TIM_IC_StructInit(LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  3538. ErrorStatus LL_TIM_IC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_IC_InitTypeDef *TIM_IC_InitStruct);
  3539. void LL_TIM_ENCODER_StructInit(LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct);
  3540. ErrorStatus LL_TIM_ENCODER_Init(TIM_TypeDef *TIMx, LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct);
  3541. void LL_TIM_HALLSENSOR_StructInit(LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct);
  3542. ErrorStatus LL_TIM_HALLSENSOR_Init(TIM_TypeDef *TIMx, LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct);
  3543. void LL_TIM_BDTR_StructInit(LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct);
  3544. ErrorStatus LL_TIM_BDTR_Init(TIM_TypeDef *TIMx, LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct);
  3545. /**
  3546. * @}
  3547. */
  3548. #endif /* USE_FULL_LL_DRIVER */
  3549. /**
  3550. * @}
  3551. */
  3552. /**
  3553. * @}
  3554. */
  3555. #endif /* TIM1 || TIM2 || TIM3 || TIM4 || TIM5 || TIM6 || TIM7 || TIM8 || TIM9 || TIM10 || TIM11 || TIM12 || TIM13 || TIM14 || TIM15 || TIM16 || TIM17 */
  3556. /**
  3557. * @}
  3558. */
  3559. #ifdef __cplusplus
  3560. }
  3561. #endif
  3562. #endif /* __PY32F0XX_LL_TIM_H */
  3563. /************************ (C) COPYRIGHT PY *****END OF FILE****/