12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360 |
- /**
- ******************************************************************************
- * @brief TIMER functions of the firmware library.
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "gd32f10x_timer.h"
- #include "gd32f10x_rcc.h"
- /** @addtogroup GD32F10x_Firmware
- * @{
- */
- /** @defgroup TIMER
- * @brief TIMER driver modules
- * @{
- */
- /** @defgroup TIMER_Private_Defines
- * @{
- */
- /* TIMER registers bit mask */
- #define SMC_ETR_MASK ((uint16_t)0x00FF)
- #define CHCTLR_OFFSET ((uint16_t)0x0018)
- #define CHE_CHE_SET ((uint16_t)0x0001)
- #define CHE_CHNE_SET ((uint16_t)0x0004)
- /**
- * @}
- */
- /* Private function prototypes */
- static void TI1_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter);
- static void TI2_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter);
- static void TI3_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter);
- static void TI4_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter);
- /** @defgroup TIMER_Private_Functions
- * @{
- */
- /**
- * @brief Deinitialize the TIMER .
- * @param TIMERx: x ={ 0-13 } .
- * @retval None
- */
- void TIMER_DeInit(TIMER_TypeDef *TIMERx)
- {
- if (TIMERx == TIMER0) {
- RCC->APB2RCR |= RCC_APB2PERIPH_TIMER0RST;
- RCC->APB2RCR &= ~RCC_APB2PERIPH_TIMER0;
- } else if (TIMERx == TIMER1) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER1RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER1;
- } else if (TIMERx == TIMER2) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER2RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER2;
- } else if (TIMERx == TIMER3) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER3RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER3;
- } else if (TIMERx == TIMER4) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER4RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER4;
- } else if (TIMERx == TIMER5) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER5RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER5;
- } else if (TIMERx == TIMER6) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER6RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER6;
- } else if (TIMERx == TIMER7) {
- RCC->APB2RCR |= RCC_APB2PERIPH_TIMER7RST;
- RCC->APB2RCR &= ~RCC_APB2PERIPH_TIMER7;
- } else if (TIMERx == TIMER8) {
- RCC->APB2RCR |= RCC_APB2PERIPH_TIMER8RST;
- RCC->APB2RCR &= ~RCC_APB2PERIPH_TIMER8;
- } else if (TIMERx == TIMER9) {
- RCC->APB2RCR |= RCC_APB2PERIPH_TIMER9RST;
- RCC->APB2RCR &= ~RCC_APB2PERIPH_TIMER9;
- } else if (TIMERx == TIMER10) {
- RCC->APB2RCR |= RCC_APB2PERIPH_TIMER10RST;
- RCC->APB2RCR &= ~RCC_APB2PERIPH_TIMER10;
- } else if (TIMERx == TIMER11) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER11RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER11;
- } else if (TIMERx == TIMER12) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER12RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER12;
- } else if (TIMERx == TIMER13) {
- RCC->APB1RCR |= RCC_APB1PERIPH_TIMER13RST;
- RCC->APB1RCR &= ~RCC_APB1PERIPH_TIMER13;
- }
- }
- /**
- * @brief Initialize the specified Timer
- * @param TIMERx: x ={ 0 -13 } .
- * @param TIMER_Init: pointer to a TIMER_BaseInitPara structure.
- * @retval None
- */
- void TIMER_BaseInit(TIMER_TypeDef *TIMERx, TIMER_BaseInitPara *TIMER_Init)
- {
- uint16_t tmpctlr1 = 0;
- tmpctlr1 = TIMERx->CTLR1;
- if ((TIMERx == TIMER0) || (TIMERx == TIMER7) || (TIMERx == TIMER1) || (TIMERx == TIMER2) ||
- (TIMERx == TIMER3) || (TIMERx == TIMER4) || (TIMERx == TIMER8) || (TIMERx == TIMER9)
- || (TIMERx == TIMER10) || (TIMERx == TIMER11) || (TIMERx == TIMER12) || (TIMERx == TIMER13)) {
- /* Configure the Counter Mode */
- tmpctlr1 &= (uint16_t)(~((uint16_t)(TIMER_CTLR1_DIR | TIMER_CTLR1_CAM)));
- tmpctlr1 |= (uint32_t)TIMER_Init->TIMER_CounterMode;
- }
- if ((TIMERx != TIMER5) && (TIMERx != TIMER6)) {
- /* Configure the clock division */
- tmpctlr1 &= (uint16_t)(~((uint16_t)TIMER_CTLR1_CDIV));
- tmpctlr1 |= (uint32_t)TIMER_Init->TIMER_ClockDivision;
- }
- TIMERx->CTLR1 = tmpctlr1;
- /* Configure the Autoreload value */
- TIMERx->CARL = TIMER_Init->TIMER_Period ;
- /* Configure the Prescaler value */
- TIMERx->PSC = TIMER_Init->TIMER_Prescaler;
- if ((TIMERx == TIMER0) ||
- (TIMERx == TIMER7)) {
- /* Configure the Repetition Counter value */
- TIMERx->CREP = TIMER_Init->TIMER_RepetitionCounter;
- }
- /* Generate an update event */
- TIMERx->EVG = TIMER_PSC_RELOAD_NOW;
- }
- /**
- * @brief Fill each TIMER_BaseInitPara Struct member with a default value.
- * @param TIMER_Init: pointer to a TIMER_BaseInitPara structure.
- * @retval None
- */
- void TIMER_BaseStructInit(TIMER_BaseInitPara *TIMER_Init)
- {
- /* Fill the default value */
- TIMER_Init->TIMER_Period = 0xFFFFFFFF;
- TIMER_Init->TIMER_Prescaler = 0x0000;
- TIMER_Init->TIMER_ClockDivision = TIMER_CDIV_DIV1;
- TIMER_Init->TIMER_CounterMode = TIMER_COUNTER_UP;
- TIMER_Init->TIMER_RepetitionCounter = 0x0000;
- }
- /**
- * @brief Configure the TIMER Prescaler.
- * @param TIMERx: x ={ 0-13 }
- * @param Prescaler: Prescaler value
- * @param TIMER_PSCReloadMode: Prescaler Reload mode
- * This value will be :
- * @arg TIMER_PSC_RELOAD_UPDATE : The Prescaler is loaded at the next update event.
- * @arg TIMER_PSC_RELOAD_NOW : The Prescaler is loaded right now.
- * @retval None
- */
- void TIMER_PrescalerConfig(TIMER_TypeDef *TIMERx, uint16_t Prescaler, uint16_t TIMER_PSCReloadMode)
- {
- /* Set PSC */
- TIMERx->PSC = Prescaler;
- /* Choose reload mode */
- TIMERx->EVG = TIMER_PSCReloadMode;
- }
- /**
- * @brief Configure the TIMER Counter Mode
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_CounterMode: the Counter Mode
- * This value will be :
- * @arg TIMER_COUNTER_UP : Up Counting Mode
- * @arg TIMER_COUNTER_DOWN : Down Counting Mode
- * @arg TIMER_COUNTER_CENTER_ALIGNED1: Center Aligned Counting Mode1
- * @arg TIMER_COUNTER_CENTER_ALIGNED2: Center Aligned Counting Mode2
- * @arg TIMER_COUNTER_CENTER_ALIGNED3: Center Aligned Counting Mode3
- * @retval None
- */
- void TIMER_CounterMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_CounterMode)
- {
- uint16_t tmpctlr1 = 0;
- tmpctlr1 = TIMERx->CTLR1;
- /* Reset the CAM and DIR Bits */
- tmpctlr1 &= (uint16_t)(~((uint16_t)(TIMER_CTLR1_DIR | TIMER_CTLR1_CAM)));
- /* Configures the Counter Mode */
- tmpctlr1 |= TIMER_CounterMode;
- /* Update the TIMER CTLR1 */
- TIMERx->CTLR1 = tmpctlr1;
- }
- /**
- * @brief Configure the TIMER Counter Register value
- * @param TIMERx: x ={ 0-13 } .
- * @param Counter: the Counter register new value.
- * @retval None
- */
- void TIMER_SetCounter(TIMER_TypeDef *TIMERx, uint32_t Counter)
- {
- TIMERx->CNT = Counter;
- }
- /**
- * @brief Configure the Autoreload value
- * @param TIMERx: x ={ 0-13 } .
- * @param AutoReloadValue:
- * @retval None
- */
- void TIMER_SetAutoreload(TIMER_TypeDef *TIMERx, uint32_t AutoReloadValue)
- {
- TIMERx->CARL = AutoReloadValue;
- }
- /**
- * @brief Get the Counter value.
- * @param TIMERx: x ={ 0-13 } .
- * @retval Counter Register value.
- */
- uint32_t TIMER_GetCounter(TIMER_TypeDef *TIMERx)
- {
- return TIMERx->CNT;
- }
- /**
- * @brief Get the Prescaler value.
- * @param TIMERx: x ={ 0-13 } .
- * @retval Prescaler Register value
- */
- uint16_t TIMER_GetPrescaler(TIMER_TypeDef *TIMERx)
- {
- return TIMERx->PSC;
- }
- /**
- * @brief Configure the TIMERx Update event.
- * @param TIMERx: x ={ 0-13 } .
- * @param NewValue: new value of the TIMERx UPDIS bit
- * This value will be :
- * @arg ENABLE : Update Enbale
- * @arg DISABLE : Update Disable
- * @retval None
- */
- void TIMER_UpdateDisableConfig(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- TIMERx->CTLR1 |= TIMER_CTLR1_UPDIS;
- } else {
- TIMERx->CTLR1 &= (uint16_t)~((uint16_t)TIMER_CTLR1_UPDIS);
- }
- }
- /**
- * @brief Configure the TIMER Update Request source.
- * @param TIMERx: x ={ 0-13 } .
- * @param TIMER_UpdateSrc: Configures the Update source.
- * This value will be :
- * @arg TIMER_UPDATE_SRC_GLOBAL : Update generate by setting of UPG bit or the counter
- * overflow/underflow , or the slave mode controller trigger.
- * @arg TIMER_UPDATE_SRC_REGULAR : Update generate only by counter overflow/underflow.
- * @retval None
- */
- void TIMER_UpdateRequestConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_UpdateSrc)
- {
- if (TIMER_UpdateSrc != TIMER_UPDATE_SRC_GLOBAL) {
- TIMERx->CTLR1 |= TIMER_CTLR1_UPS;
- } else {
- TIMERx->CTLR1 &= (uint16_t)~((uint16_t)TIMER_CTLR1_UPS);
- }
- }
- /**
- * @brief Configure the CARL Preload function
- * @param TIMERx: x ={ 0-13 } .
- * @param NewValue: the state of the Preload function on CARL.
- * This value will be :
- * @arg ENABLE
- * @arg DISABLE
- * @retval None
- */
- void TIMER_CARLPreloadConfig(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- /* Set the CARL Preload Bit */
- TIMERx->CTLR1 |= TIMER_CTLR1_ARSE;
- } else {
- /* Reset the CARL Preload Bit */
- TIMERx->CTLR1 &= (uint16_t)~((uint16_t)TIMER_CTLR1_ARSE);
- }
- }
- /**
- * @brief Select the TIMER Single Pulse Mode.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_SPMode: specifies the SPM Mode to be used.
- * This value will be :
- * @arg TIMER_SP_MODE_SINGLE
- * @arg TIMER_SP_MODE_REPETITIVE
- * @retval None
- */
- void TIMER_SinglePulseMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_SPMode)
- {
- /* Reset the SPM Bit */
- TIMERx->CTLR1 &= (uint16_t)~((uint16_t)TIMER_CTLR1_SPM);
- /* Set the SPM Bit */
- TIMERx->CTLR1 |= TIMER_SPMode;
- }
- /**
- * @brief Configure the TIMERx Clock Division value.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_CDIV: the clock division value.
- * This value will be :
- * @arg TIMER_CDIV_DIV1: TDTS = Tck_tim
- * @arg TIMER_CDIV_DIV2: TDTS = 2*Tck_tim
- * @arg TIMER_CDIV_DIV4: TDTS = 4*Tck_tim
- * @retval None
- */
- void TIMER_SetClockDivision(TIMER_TypeDef *TIMERx, uint16_t TIMER_CDIV)
- {
- /* Reset the CDIV value*/
- TIMERx->CTLR1 &= (uint16_t)~((uint16_t)TIMER_CTLR1_CDIV);
- /* Set the CDIV value */
- TIMERx->CTLR1 |= TIMER_CDIV;
- }
- /**
- * @brief ENABLE or DISABLE the TIMER.
- * @param TIMERx: x ={ 0-13 } .
- * @param NewValue: ENABLE or DISABLE.
- * @retval None
- */
- void TIMER_Enable(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- /* Enable the TIMER */
- TIMERx->CTLR1 |= TIMER_CTLR1_CNTE;
- } else {
- /* Disable the TIMER */
- TIMERx->CTLR1 &= (uint16_t)(~((uint16_t)TIMER_CTLR1_CNTE));
- }
- }
- /**
- * @brief Configure the: Break feature, dead time, Lock level, ROS/IOS State and the OAE
- * @param TIMERx: x ={ 1 , 8 } .
- * @param TIMER_BKDTInit: pointer to a TIMER_BKDTInitPara structure that
- * contains the BKDT Register configuration information for the TIMER.
- * @retval None
- */
- void TIMER_BKDTConfig(TIMER_TypeDef *TIMERx, TIMER_BKDTInitPara *TIMER_BKDTInit)
- {
- TIMERx->BKDT = (uint32_t)TIMER_BKDTInit->TIMER_ROSState |
- TIMER_BKDTInit->TIMER_IOSState |
- TIMER_BKDTInit->TIMER_LOCKLevel |
- TIMER_BKDTInit->TIMER_DeadTime |
- TIMER_BKDTInit->TIMER_Break |
- TIMER_BKDTInit->TIMER_BreakPolarity |
- TIMER_BKDTInit->TIMER_OutAuto;
- }
- /**
- * @brief Fill TIMER_BKDTInit structure member with default value.
- * @param TIMER_BKDTInit : pointer to a TIMER_BKDTInitPara structure which will be initialized.
- * @retval None
- */
- void TIMER_BKDTStructInit(TIMER_BKDTInitPara *TIMER_BKDTInit)
- {
- TIMER_BKDTInit->TIMER_ROSState = TIMER_ROS_STATE_DISABLE;
- TIMER_BKDTInit->TIMER_IOSState = TIMER_IOS_STATE_DISABLE;
- TIMER_BKDTInit->TIMER_LOCKLevel = TIMER_LOCK_LEVEL_OFF;
- TIMER_BKDTInit->TIMER_DeadTime = 0x00;
- TIMER_BKDTInit->TIMER_Break = TIMER_BREAK_DISABLE;
- TIMER_BKDTInit->TIMER_BreakPolarity = TIMER_BREAK_POLARITY_LOW;
- TIMER_BKDTInit->TIMER_OutAuto = TIMER_OUTAUTO_DISABLE;
- }
- /**
- * @brief Enable or disable the TIMER ALL Outputs.
- * @param TIMERx: x ={ 1 , 8 } .
- * @param NewValue: ENABLE or DISABLE .
- * @retval None
- */
- void TIMER_CtrlPWMOutputs(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- /* Enable the TIMER ALL Output */
- TIMERx->BKDT |= TIMER_BKDT_POE;
- } else {
- /* Disable the TIMER ALL Output */
- TIMERx->BKDT &= (uint16_t)(~((uint16_t)TIMER_BKDT_POE));
- }
- }
- /**
- * @brief Initialize the TIMERx Channel1 with TIMER_OCInitPara .
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_OCInit : pointer to a TIMER_OCInitPara structure .
- * @retval None
- */
- void TIMER_OC1_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit)
- {
- uint16_t tmpchctlrx = 0, tmpche = 0, tmpctlr2 = 0;
- /* Disable the Channel 1: Reset the CH1E Bit */
- TIMERx->CHE &= (uint16_t)(~(uint16_t)TIMER_CHE_CH1E);
- /* Get the TIMERx CHE register value */
- tmpche = TIMERx->CHE;
- /* Get the TIMERx CTLR2 register value */
- tmpctlr2 = TIMERx->CTLR2;
- /* Get the TIMERx CHCTLR1 register value */
- tmpchctlrx = TIMERx->CHCTLR1;
- /* Reset the Output Compare Mode Bits */
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR1_CH1OM));
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR1_CH1M));
- /* Select the Output Compare Mode */
- tmpchctlrx |= TIMER_OCInit->TIMER_OCMode;
- /* Reset the Output Polarity */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH1P));
- /* Set the Output Compare Polarity */
- tmpche |= TIMER_OCInit->TIMER_OCPolarity;
- /* Set the Output State */
- tmpche |= TIMER_OCInit->TIMER_OutputState;
- if ((TIMERx == TIMER0) || (TIMERx == TIMER7)) {
- /* Reset the Output complementary Polarity */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH1NP));
- /* Set the Output complementary Polarity */
- tmpche |= TIMER_OCInit->TIMER_OCNPolarity;
- /* Reset the Output complementary State */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH1NE));
- /* Set the Output complementary State */
- tmpche |= TIMER_OCInit->TIMER_OutputNState;
- /* Reset the Ouput Compare and Output Compare complementary IDLE State */
- tmpctlr2 &= (uint16_t)(~((uint16_t)TIMER_CTLR2_ISO1));
- tmpctlr2 &= (uint16_t)(~((uint16_t)TIMER_CTLR2_ISO1N));
- /* Set the Output Idle state */
- tmpctlr2 |= TIMER_OCInit->TIMER_OCIdleState;
- /* Set the Output complementary Idle state */
- tmpctlr2 |= TIMER_OCInit->TIMER_OCNIdleState;
- }
- /* Write to TIMERx CTLR2 */
- TIMERx->CTLR2 = tmpctlr2;
- /* Write to TIMERx CHCTLR1 */
- TIMERx->CHCTLR1 = tmpchctlrx;
- /* Set the Capture / Compare Register value */
- TIMERx->CHCC1 = TIMER_OCInit->TIMER_Pulse;
- /* Write to TIMERx CHE */
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Initialize the TIMERx Channel2 with TIMER_OCInitPara .
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_OCInit : pointer to a TIMER_OCInitPara structure .
- * @retval None
- */
- void TIMER_OC2_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit)
- {
- uint16_t tmpchctlrx = 0, tmpche = 0, tmpctlr2 = 0;
- /* Disable the Channel 2: Reset the CH2E Bit */
- TIMERx->CHE &= (uint16_t)(~((uint16_t)TIMER_CHE_CH2E));
- /* Get the TIMERx CHE register value */
- tmpche = TIMERx->CHE;
- /* Get the TIMERx CTLR2 register value */
- tmpctlr2 = TIMERx->CTLR2;
- /* Get the TIMERx CHCTLR1 register value */
- tmpchctlrx = TIMERx->CHCTLR1;
- /* Reset the Output Compare Mode Bits */
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR1_CH2OM));
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR1_CH2M));
- /* Select the Output Compare Mode */
- tmpchctlrx |= (uint16_t)(TIMER_OCInit->TIMER_OCMode << 8);
- /* Reset the Output Polarity */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH2P));
- /* Set the Output Compare Polarity */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OCPolarity << 4);
- /* Set the Output State */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OutputState << 4);
- if ((TIMERx == TIMER0) || (TIMERx == TIMER7)) {
- /* Reset the Output complementary Polarity */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH2NP));
- /* Set the Output complementary Polarity */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OCNPolarity << 4);
- /* Reset the Output complementary State */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH2NE));
- /* Set the Output complementary State */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OutputNState << 4);
- /* Reset the Ouput Compare and Output Compare complementary IDLE State */
- tmpctlr2 &= (uint16_t)(~((uint16_t)TIMER_CTLR2_ISO2));
- tmpctlr2 &= (uint16_t)(~((uint16_t)TIMER_CTLR2_ISO2N));
- /* Set the Output Idle state */
- tmpctlr2 |= (uint16_t)(TIMER_OCInit->TIMER_OCIdleState << 2);
- /* Set the Output complementary Idle state */
- tmpctlr2 |= (uint16_t)(TIMER_OCInit->TIMER_OCNIdleState << 2);
- }
- /* Write to TIMERx CTLR2 */
- TIMERx->CTLR2 = tmpctlr2;
- /* Write to TIMERx CHCTLR1 */
- TIMERx->CHCTLR1 = tmpchctlrx;
- /* Set the Capture / Compare Register value */
- TIMERx->CHCC2 = TIMER_OCInit->TIMER_Pulse;
- /* Write to TIMERx CHE */
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Initialize the TIMERx Channel3 with TIMER_OCInitPara .
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8} .
- * @param TIMER_OCInit : pointer to a TIMER_OCInitPara structure .
- * @retval None
- */
- void TIMER_OC3_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit)
- {
- uint16_t tmpchctlrx = 0, tmpche = 0, tmpctlr2 = 0;
- /* Disable the Channel 3: Reset the CH3E Bit */
- TIMERx->CHE &= (uint16_t)(~((uint16_t)TIMER_CHE_CH3E));
- /* Get the TIMERx CHE register value */
- tmpche = TIMERx->CHE;
- /* Get the TIMERx CTLR2 register value */
- tmpctlr2 = TIMERx->CTLR2;
- /* Get the TIMERx CHCTLR2 register value */
- tmpchctlrx = TIMERx->CHCTLR2;
- /* Reset the Output Compare Mode Bits */
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR2_CH3OM));
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR2_CH3M));
- /* Select the Output Compare Mode */
- tmpchctlrx |= TIMER_OCInit->TIMER_OCMode;
- /* Reset the Output Polarity */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH3P));
- /* Set the Output Compare Polarity */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OCPolarity << 8);
- /* Set the Output State */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OutputState << 8);
- if ((TIMERx == TIMER0) || (TIMERx == TIMER7)) {
- /* Reset the Output complementary Polarity */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH3NP));
- /* Set the Output complementary Polarity */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OCNPolarity << 8);
- /* Reset the Output complementary State */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH3NE));
- /* Set the Output complementary State */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OutputNState << 8);
- /* Reset the Ouput Compare and Output Compare complementary IDLE State */
- tmpctlr2 &= (uint16_t)(~((uint16_t)TIMER_CTLR2_ISO3));
- tmpctlr2 &= (uint16_t)(~((uint16_t)TIMER_CTLR2_ISO3N));
- /* Set the Output Idle state */
- tmpctlr2 |= (uint16_t)(TIMER_OCInit->TIMER_OCIdleState << 4);
- /* Set the Output complementary Idle state */
- tmpctlr2 |= (uint16_t)(TIMER_OCInit->TIMER_OCNIdleState << 4);
- }
- /* Write to TIMERx CTLR2 */
- TIMERx->CTLR2 = tmpctlr2;
- /* Write to TIMERx CHCTLR2 */
- TIMERx->CHCTLR2 = tmpchctlrx;
- /* Set the Capture / Compare Register value */
- TIMERx->CHCC3 = TIMER_OCInit->TIMER_Pulse;
- /* Write to TIMERx CHE */
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Initialize the TIMERx Channel4 with TIMER_OCInitPara .
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8} .
- * @param TIMER_OCInit : pointer to a TIMER_OCInitPara structure .
- * @retval None
- */
- void TIMER_OC4_Init(TIMER_TypeDef *TIMERx, TIMER_OCInitPara *TIMER_OCInit)
- {
- uint16_t tmpchctlrx = 0, tmpche = 0, tmpctlr2 = 0;
- /* Disable the Channel 4: Reset the CH4E Bit */
- TIMERx->CHE &= (uint16_t)(~((uint16_t)TIMER_CHE_CH4E));
- /* Get the TIMERx CHE register value */
- tmpche = TIMERx->CHE;
- /* Get the TIMERx CTLR2 register value */
- tmpctlr2 = TIMERx->CTLR2;
- /* Get the TIMERx CHCTLR2 register value */
- tmpchctlrx = TIMERx->CHCTLR2;
- /* Reset the Output Compare Mode Bits */
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR2_CH4OM));
- tmpchctlrx &= (uint16_t)(~((uint16_t)TIMER_CHCTLR2_CH4M));
- /* Select the Output Compare Mode */
- tmpchctlrx |= (uint16_t)(TIMER_OCInit->TIMER_OCMode << 8);
- /* Reset the Output Polarity */
- tmpche &= (uint16_t)(~((uint16_t)TIMER_CHE_CH4P));
- /* Set the Output Compare Polarity */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OCPolarity << 12);
- /* Set the Output State */
- tmpche |= (uint16_t)(TIMER_OCInit->TIMER_OutputState << 12);
- if ((TIMERx == TIMER0) || (TIMERx == TIMER7)) {
- /* Reset the Ouput Compare IDLE State */
- tmpctlr2 &= (uint16_t)(~((uint16_t)TIMER_CTLR2_ISO4));
- /* Set the Output Idle state */
- tmpctlr2 |= (uint16_t)(TIMER_OCInit->TIMER_OCIdleState << 6);
- }
- /* Write to TIMERx CTLR2 */
- TIMERx->CTLR2 = tmpctlr2;
- /* Write to TIMERx CHCTLR2 */
- TIMERx->CHCTLR2 = tmpchctlrx;
- /* Set the Capture Compare Register value */
- TIMERx->CHCC4 = TIMER_OCInit->TIMER_Pulse;
- /* Write to TIMERx CHE */
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Fill TIMER_OCInitPara member with default value.
- * @param TIMER_OCInit: pointer to a TIMER_OCInitPara structure.
- * @retval None
- */
- void TIMER_OCStructInit(TIMER_OCInitPara *TIMER_OCInit)
- {
- TIMER_OCInit->TIMER_OCMode = TIMER_OC_MODE_TIMING;
- TIMER_OCInit->TIMER_OutputState = TIMER_OUTPUT_STATE_DISABLE;
- TIMER_OCInit->TIMER_OutputNState = TIMER_OUTPUTN_STATE_DISABLE;
- TIMER_OCInit->TIMER_Pulse = 0x0000000;
- TIMER_OCInit->TIMER_OCPolarity = TIMER_OC_POLARITY_HIGH;
- TIMER_OCInit->TIMER_OCNPolarity = TIMER_OC_POLARITY_HIGH;
- TIMER_OCInit->TIMER_OCIdleState = TIMER_OC_IDLE_STATE_RESET;
- TIMER_OCInit->TIMER_OCNIdleState = TIMER_OCN_IDLE_STATE_RESET;
- }
- /**
- * @brief Configure the TIMER Output Compare Mode.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_Ch:
- * This value will be :
- * @arg TIMER_CH_1
- * @arg TIMER_CH_2
- * @arg TIMER_CH_3
- * @arg TIMER_CH_4
- * @param TIMER_OCMode: the TIMER Output Compare Mode.
- * This value will be :
- * @arg TIMER_OC_MODE_TIMING
- * @arg TIMER_OC_MODE_ACTIVE
- * @arg TIMER_OC_MODE_TOGGLE
- * @arg TIMER_OC_MODE_PWM1
- * @arg TIMER_OC_MODE_PWM2
- * @arg TIMER_FORCED_HIGH
- * @arg TIMER_FORCED_LOW
- * @retval None
- */
- void TIMER_OCxModeConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_Ch, uint16_t TIMER_OCMode)
- {
- uint32_t tmp = 0;
- uint16_t tmp1 = 0;
- tmp = (uint32_t) TIMERx;
- tmp += CHCTLR_OFFSET;
- tmp1 = CHE_CHE_SET << (uint16_t)TIMER_Ch;
- /* Disable the Channel: Reset the CHxE Bit */
- TIMERx->CHE &= (uint16_t) ~tmp1;
- if ((TIMER_Ch == TIMER_CH_1) || (TIMER_Ch == TIMER_CH_3)) {
- tmp += (TIMER_Ch >> 1);
- /* Reset the CHxOM bits in the CHCTLRx register */
- *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIMER_CHCTLR1_CH1OM);
- /* Configure the CHxOM bits in the CHCTLRx register */
- *(__IO uint32_t *) tmp |= TIMER_OCMode;
- } else {
- tmp += (uint16_t)(TIMER_Ch - (uint16_t)4) >> (uint16_t)1;
- /* Reset the CHxOM bits in the CHCTLRx register */
- *(__IO uint32_t *) tmp &= (uint32_t)~((uint32_t)TIMER_CHCTLR1_CH2OM);
- /* Configure the CHxOM bits in the CHCTLRx register */
- *(__IO uint32_t *) tmp |= (uint16_t)(TIMER_OCMode << 8);
- }
- }
- /**
- * @brief Configure the TIMERx Capture or Compare Register value
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param CompValue1: the Capture / Compare1 register new value
- * @retval None
- */
- void TIMER_Compare1Config(TIMER_TypeDef *TIMERx, uint32_t CompValue1)
- {
- TIMERx->CHCC1 = CompValue1 ;
- }
- /**
- * @brief Configure the TIMERx Capture or Compare Register value
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param CompValue2: the Capture / Compare1 register new value
- * @retval None
- */
- void TIMER_Compare2Config(TIMER_TypeDef *TIMERx, uint32_t CompValue2)
- {
- TIMERx->CHCC2 = CompValue2;
- }
- /**
- * @brief Configure the TIMERx Capture or Compare Register value
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param CompValue3: the Capture / Compare1 register new value
- * @retval None
- */
- void TIMER_Compare3Config(TIMER_TypeDef *TIMERx, uint32_t CompValue3)
- {
- TIMERx->CHCC3 = CompValue3;
- }
- /**
- * @brief Configure the TIMERx Capture or Compare Register value
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param CompValue4: the Capture / Compare1 register new value
- * @retval None
- */
- void TIMER_Compare4Config(TIMER_TypeDef *TIMERx, uint32_t CompValue4)
- {
- TIMERx->CHCC4 = CompValue4;
- }
- /**
- * @brief Force the TIMERx output level to high or low
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_Forced: forced the output level.
- * This value will be :
- * @arg TIMER_FORCED_HIGH: Force output high level
- * @arg TIMER_FORCED_LOW : Force output low level
- * @retval None
- */
- void TIMER_Forced_OC1(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the CH1OM Bits */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1OM);
- /* Configure The Forced output Mode */
- tmpchctlr1 |= TIMER_Forced ;
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief Force the TIMERx output level to high or low
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_Forced: forced the output level.
- * This value will be :
- * @arg TIMER_FORCED_HIGH: Force output high level
- * @arg TIMER_FORCED_LOW : Force output low level
- * @retval None
- */
- void TIMER_Forced_OC2(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the CH2OM Bits */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH2OM);
- /* Configure The Forced output Mode */
- tmpchctlr1 |= (uint16_t)(TIMER_Forced << 8);
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief Force the TIMERx output level to high or low
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_Forced: forced the output level.
- * This value will be :
- * @arg TIMER_FORCED_HIGH: Force output high level
- * @arg TIMER_FORCED_LOW : Force output low level
- * @retval None
- */
- void TIMER_Forced_OC3(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the CH3OM Bits */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH3OM);
- /* Configure The Forced output Mode */
- tmpchctlr2 |= TIMER_Forced ;
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief Force the TIMERx output level to high or low
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_Forced: forced the output level.
- * This value will be :
- * @arg TIMER_FORCED_HIGH: Force output high level
- * @arg TIMER_FORCED_LOW : Force output low level
- * @retval None
- */
- void TIMER_Forced_OC4(TIMER_TypeDef *TIMERx, uint16_t TIMER_Forced)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the CH4OM Bits */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH4OM);
- /* Configure The Forced output Mode */
- tmpchctlr2 |= (uint16_t)(TIMER_Forced << 8);
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief Configure the TIMER Capture or Compare Preload Control bit
- * @param TIMERx: x ={ 1 , 8 } .
- * @param NewValue: ENABLE or DISABLE.
- * @retval None
- */
- void TIMER_CC_PreloadControl(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- /* Set the CCSE Bit */
- TIMERx->CTLR2 |= TIMER_CTLR2_CCSE;
- } else {
- /* Reset the CCSE Bit */
- TIMERx->CTLR2 &= (uint16_t)~((uint16_t)TIMER_CTLR2_CCSE);
- }
- }
- /**
- * @brief Configure the TIMER channel 1 Capture or Compare Preload register
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_OCPreload : state of the TIMERx Preload register
- * This value will be :
- * @arg TIMER_OC_PRELOAD_ENABLE
- * @arg TIMER_OC_PRELOAD_DISABLE
- * @retval None
- */
- void TIMER_OC1_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the CH1OSE Bit */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1OSE);
- /* Enable or Disable the Output Compare Preload */
- tmpchctlr1 |= TIMER_OCPreload;
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief Configure the TIMER channel 2 Capture or Compare Preload register
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_OCPreload : state of the TIMERx Preload register
- * This value will be :
- * @arg TIMER_OC_PRELOAD_ENABLE
- * @arg TIMER_OC_PRELOAD_DISABLE
- * @retval None
- */
- void TIMER_OC2_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the CH2OSE Bit */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH2OSE);
- /* Enable or Disable the Output Compare Preload */
- tmpchctlr1 |= (uint16_t)(TIMER_OCPreload << 8);
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief Configure the TIMER channel 3 Capture or Compare Preload register
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCPreload : state of the TIMERx Preload register
- * This value will be :
- * @arg TIMER_OC_PRELOAD_ENABLE
- * @arg TIMER_OC_PRELOAD_DISABLE
- * @retval None
- */
- void TIMER_OC3_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the CH3OSE Bit */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH3OSE);
- /* Enable or Disable the Output Compare Preload */
- tmpchctlr2 |= TIMER_OCPreload;
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief Configure the TIMER channel 4 Capture or Compare Preload register
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCPreload : state of the TIMERx Preload register
- * This value will be :
- * @arg TIMER_OC_PRELOAD_ENABLE
- * @arg TIMER_OC_PRELOAD_DISABLE
- * @retval None
- */
- void TIMER_OC4_Preload(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPreload)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the CH4OSE Bit */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH4OSE);
- /* Enable or Disable the Output Compare Preload */
- tmpchctlr2 |= (uint16_t)(TIMER_OCPreload << 8);
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief Configure the TIMER channel 1 Compare output Fast mode
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_OCFast: state of the Compare Output Fast Enable Bit.
- * This value will be :
- * @arg TIMER_OC_FAST_ENABLE : output fast enable
- * @arg TIMER_OC_FAST_DISABLE: output fast disable
- * @retval None
- */
- void TIMER_OC1_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the CH1OFE Bit */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1OFE);
- /* Enable or Disable the Output Compare Fast Bit */
- tmpchctlr1 |= TIMER_OCFast;
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief Configure the TIMER channel 2 Compare output Fast mode
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_OCFast: state of the Compare Output Fast Enable Bit.
- * This value will be :
- * @arg TIMER_OC_FAST_ENABLE : output fast enable
- * @arg TIMER_OC_FAST_DISABLE: output fast disable
- * @retval None
- */
- void TIMER_OC2_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the CH2OFE Bit */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH2OFE);
- /* Enable or Disable the Output Compare Fast Bit */
- tmpchctlr1 |= (uint16_t)(TIMER_OCFast << 8);
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief Configure the TIMER channel 3 Compare output Fast mode
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCFast: state of the Compare Output Fast Enable Bit.
- * This value will be :
- * @arg TIMER_OC_FAST_ENABLE : output fast enable
- * @arg TIMER_OC_FAST_DISABLE: output fast disable
- * @retval None
- */
- void TIMER_OC3_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the CH3OFE Bit */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH3OFE);
- /* Enable or Disable the Output Compare Fast Bit */
- tmpchctlr2 |= TIMER_OCFast;
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief Configure the TIMER channel 4 Compare output Fast mode
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCFast: state of the Compare Output Fast Enable Bit.
- * This value will be :
- * @arg TIMER_OC_FAST_ENABLE : output fast enable
- * @arg TIMER_OC_FAST_DISABLE: output fast disable
- * @retval None
- */
- void TIMER_OC4_FastConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCFast)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the CH4OFE Bit */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH4OFE);
- /* Enable or Disable the Output Compare Fast Bit */
- tmpchctlr2 |= (uint16_t)(TIMER_OCFast << 8);
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief If Clear the OCREF signal on an external event
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_OCClear: new state of the Output Compare Clear Enable Bit.
- * This value will be :
- * @arg TIMER_OC_CLEAR_ENABLE : Output clear enable
- * @arg TIMER_OC_CLEAR_DISABLE: Output clear disable
- * @retval None
- */
- void TIMER_OC1_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the CH1OCE Bit */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1OCE);
- /* Enable or Disable the Output Compare Clear Bit */
- tmpchctlr1 |= TIMER_OCClear;
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief If Clear the OCREF signal on an external event
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_OCClear: new state the Output Compare Clear Enable Bit.
- * This value will be :
- * @arg TIMER_OC_CLEAR_ENABLE : Output clear enable
- * @arg TIMER_OC_CLEAR_DISABLE: Output clear disable
- * @retval None
- */
- void TIMER_OC2_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear)
- {
- uint16_t tmpchctlr1 = 0;
- tmpchctlr1 = TIMERx->CHCTLR1;
- /* Reset the OC2CE Bit */
- tmpchctlr1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH2OCE);
- /* Enable or Disable the Output Compare Clear Bit */
- tmpchctlr1 |= (uint16_t)(TIMER_OCClear << 8);
- TIMERx->CHCTLR1 = tmpchctlr1;
- }
- /**
- * @brief If Clear the OCREF signal on an external event
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCClear: new state the Output Compare Clear Enable Bit.
- * This value will be :
- * @arg TIMER_OC_CLEAR_ENABLE : Output clear enable
- * @arg TIMER_OC_CLEAR_DISABLE: Output clear disable
- * @retval None
- */
- void TIMER_OC3_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the CH3OCE Bit */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH3OCE);
- /* Enable or Disable the Output Compare Clear Bit */
- tmpchctlr2 |= TIMER_OCClear;
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief If Clear the OCREF signal on an external event
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCClear: new state the Output Compare Clear Enable Bit.
- * This value will be :
- * @arg TIMER_OC_CLEAR_ENABLE : Output clear enable
- * @arg TIMER_OC_CLEAR_DISABLE: Output clear disable
- * @retval None
- */
- void TIMER_OC4_RefClear(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCClear)
- {
- uint16_t tmpchctlr2 = 0;
- tmpchctlr2 = TIMERx->CHCTLR2;
- /* Reset the OC4CE Bit */
- tmpchctlr2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH4OCE);
- /* Enable or Disable the Output Compare Clear Bit */
- tmpchctlr2 |= (uint16_t)(TIMER_OCClear << 8);
- TIMERx->CHCTLR2 = tmpchctlr2;
- }
- /**
- * @brief Configure the TIMERx channel 1 polarity.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_OCPolarity :
- * This value will be :
- * @arg TIMER_OC_POLARITY_HIGH: active high
- * @arg TIMER_OC_POLARITY_LOW : active low
- * @retval None
- */
- void TIMER_OC1_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity)
- {
- uint16_t tmpche = 0;
- tmpche = TIMERx->CHE;
- /* Configures the CH1P Bit */
- tmpche &= (uint16_t)~((uint16_t)TIMER_CHE_CH1P);
- tmpche |= TIMER_OCPolarity;
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TIMERx Channel 1 complementary polarity.
- * @param TIMERx: x ={ 1 , 8 } .
- * @param TIMER_OCNPolarity:
- * This value will be :
- * @arg TIMER_OCN_POLARITY_HIGH: active high
- * @arg TIMER_OCN_POLARITY_LOW: active low
- * @retval None
- */
- void TIMER_OC1N_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCNPolarity)
- {
- uint16_t tmpche = 0;
- tmpche = TIMERx->CHE;
- /* Configures the CH1NP Bit */
- tmpche &= (uint16_t)~((uint16_t)TIMER_CHE_CH1NP);
- tmpche |= TIMER_OCNPolarity;
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TIMERx channel 2 polarity.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_OCPolarity :
- * This value will be :
- * @arg TIMER_OC_POLARITY_HIGH: active high
- * @arg TIMER_OC_POLARITY_LOW : active low
- * @retval None
- */
- void TIMER_OC2_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity)
- {
- uint16_t tmpche = 0;
- tmpche = TIMERx->CHE;
- /* Configure the CH2P Bit */
- tmpche &= (uint16_t)~((uint16_t)TIMER_CHE_CH2P);
- tmpche |= (uint16_t)(TIMER_OCPolarity << 4);
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TIMERx Channel 2 complementary polarity.
- * @param TIMERx: x ={ 1 , 8 } .
- * @param TIMER_OCNPolarity:
- * This value will be :
- * @arg TIMER_OCN_POLARITY_HIGH: active high
- * @arg TIMER_OCN_POLARITY_LOW: active low
- * @retval None
- */
- void TIMER_OC2N_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCNPolarity)
- {
- uint16_t tmpche = 0;
- tmpche = TIMERx->CHE;
- /* Configure the CH2NP Bit */
- tmpche &= (uint16_t)~((uint16_t)TIMER_CHE_CH2NP);
- tmpche |= (uint16_t)(TIMER_OCNPolarity << 4);
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TIMERx channel 3 polarity.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCPolarity :
- * This value will be :
- * @arg TIMER_OC_POLARITY_HIGH: active high
- * @arg TIMER_OC_POLARITY_LOW : active low
- * @retval None
- */
- void TIMER_OC3_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity)
- {
- uint16_t tmpche = 0;
- tmpche = TIMERx->CHE;
- /* Configure the CH3P Bit */
- tmpche &= (uint16_t)~((uint16_t)TIMER_CHE_CH3P);
- tmpche |= (uint16_t)(TIMER_OCPolarity << 8);
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TIMERx Channel 3 complementary polarity.
- * @param TIMERx: x ={ 1 , 8 } .
- * @param TIMER_OCNPolarity:
- * This value will be :
- * @arg TIMER_OCN_POLARITY_HIGH: active high
- * @arg TIMER_OCN_POLARITY_LOW : active low
- * @retval None
- */
- void TIMER_OC3N_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCNPolarity)
- {
- uint16_t tmpche = 0;
- tmpche = TIMERx->CHE;
- /* Configure the CH3NP Bit */
- tmpche &= (uint16_t)~((uint16_t)TIMER_CHE_CH3NP);
- tmpche |= (uint16_t)(TIMER_OCNPolarity << 8);
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TIMERx channel 4 polarity.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_OCPolarity :
- * This value will be :
- * @arg TIMER_OC_POLARITY_HIGH: active high
- * @arg TIMER_OC_POLARITY_LOW : active low
- * @retval None
- */
- void TIMER_OC4_Polarity(TIMER_TypeDef *TIMERx, uint16_t TIMER_OCPolarity)
- {
- uint16_t tmpche = 0;
- tmpche = TIMERx->CHE;
- /* Configure the CH4P Bit */
- tmpche &= (uint16_t)~((uint16_t)TIMER_CHE_CH4P);
- tmpche |= (uint16_t)(TIMER_OCPolarity << 12);
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Turn-on or off the Channel x Capture or Compare .
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_Ch:
- * This value will be :
- * @arg TIMER_CH_1:
- * @arg TIMER_CH_2:
- * @arg TIMER_CH_3:
- * @arg TIMER_CH_4:
- * @param TIMER_CCx: the TIMER Channel CCxE bit new value.
- * This value will be:
- * @arg TIMER_CCX_ENABLE
- * @arg TIMER_CCX_DISABLE
- * @retval None
- */
- void TIMER_CCxCmd(TIMER_TypeDef *TIMERx, uint16_t TIMER_Ch, uint16_t TIMER_CCx)
- {
- uint16_t tmp = 0;
- tmp = CHE_CHE_SET << TIMER_Ch;
- /* Reset the CCx Bit */
- TIMERx->CHE &= (uint16_t)~ tmp;
- /* Configure the CCx Bit */
- TIMERx->CHE |= (uint16_t)(TIMER_CCx << TIMER_Ch);
- }
- /**
- * @brief Turn-on or off the Channel x complementary Capture or Compare
- * @param TIMERx: x ={ 1 , 8 } .
- * @param TIMER_Ch:
- * This value will be :
- * @arg TIMER_CH_1:
- * @arg TIMER_CH_2:
- * @arg TIMER_CH_3:
- * @param TIMER_CCxN: the Channel CCxN bit new value.
- * This value will be:
- * @arg TIMER_CCXN_ENABLE
- * @arg TIMER_CCXN_DISABLE
- * @retval None
- */
- void TIMER_CCxNCmd(TIMER_TypeDef *TIMERx, uint16_t TIMER_Ch, uint16_t TIMER_CCxN)
- {
- uint16_t tmp = 0;
- tmp = CHE_CHNE_SET << TIMER_Ch;
- /* Reset the CCxN Bit */
- TIMERx->CHE &= (uint16_t) ~tmp;
- /* Configure the CCxN Bit */
- TIMERx->CHE |= (uint16_t)(TIMER_CCxN << TIMER_Ch);
- }
- /**
- * @brief Select control shadow register update control.
- * @param TIMERx: x ={ 1, 8 } .
- * @param NewState: ENABLE or DISABLE.
- * @retval None
- */
- void TIMER_SelectCOM(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- /* Set the CCUC Bit */
- TIMERx->CTLR2 |= TIMER_CTLR2_CCUC;
- } else {
- /* Reset the CCUC Bit */
- TIMERx->CTLR2 &= (uint16_t)~((uint16_t)TIMER_CTLR2_CCUC);
- }
- }
- /**
- * @brief Initialize the Input Capture parameters of the timer
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_ICInit: pointer to a TIMER_ICInitPara structure
- * @retval None
- */
- void TIMER_ICInit(TIMER_TypeDef *TIMERx, TIMER_ICInitPara *TIMER_ICInit)
- {
- if (TIMER_ICInit->TIMER_CH == TIMER_CH_1) {
- TI1_Config(TIMERx, TIMER_ICInit->TIMER_ICPolarity,
- TIMER_ICInit->TIMER_ICSelection,
- TIMER_ICInit->TIMER_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIMER_Set_IC1_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- } else if (TIMER_ICInit->TIMER_CH == TIMER_CH_2) {
- TI2_Config(TIMERx, TIMER_ICInit->TIMER_ICPolarity,
- TIMER_ICInit->TIMER_ICSelection,
- TIMER_ICInit->TIMER_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIMER_Set_IC2_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- } else if (TIMER_ICInit->TIMER_CH == TIMER_CH_3) {
- TI3_Config(TIMERx, TIMER_ICInit->TIMER_ICPolarity,
- TIMER_ICInit->TIMER_ICSelection,
- TIMER_ICInit->TIMER_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIMER_Set_IC3_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- } else {
- TI4_Config(TIMERx, TIMER_ICInit->TIMER_ICPolarity,
- TIMER_ICInit->TIMER_ICSelection,
- TIMER_ICInit->TIMER_ICFilter);
- /* Set the Input Capture Prescaler value */
- TIMER_Set_IC4_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- }
- }
- /**
- * @brief Fill TIMER_ICInitPara member with default value.
- * @param TIMER_ICInit : pointer to a TIMER_ICInitPara structure
- * @retval None
- */
- void TIMER_ICStructInit(TIMER_ICInitPara *TIMER_ICInit)
- {
- TIMER_ICInit->TIMER_CH = TIMER_CH_1;
- TIMER_ICInit->TIMER_ICPolarity = TIMER_IC_POLARITY_RISING;
- TIMER_ICInit->TIMER_ICSelection = TIMER_IC_SELECTION_DIRECTTI;
- TIMER_ICInit->TIMER_ICPrescaler = TIMER_IC_PSC_DIV1;
- TIMER_ICInit->TIMER_ICFilter = 0x00;
- }
- /**
- * @brief Configure the TIMER PWM input Capture mode parameters
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_ICInit: pointer to a TIMER_ICInitPara structure
- * @retval None
- */
- void TIMER_PWMCaptureConfig(TIMER_TypeDef *TIMERx, TIMER_ICInitPara *TIMER_ICInit)
- {
- uint16_t icoppositepolarity = TIMER_IC_POLARITY_RISING;
- uint16_t icoppositeselection = TIMER_IC_SELECTION_DIRECTTI;
- /* Select the Opposite Input Polarity */
- if (TIMER_ICInit->TIMER_ICPolarity == TIMER_IC_POLARITY_RISING) {
- icoppositepolarity = TIMER_IC_POLARITY_FALLING;
- } else {
- icoppositepolarity = TIMER_IC_POLARITY_RISING;
- }
- /* Select the Opposite Input */
- if (TIMER_ICInit->TIMER_ICSelection == TIMER_IC_SELECTION_DIRECTTI) {
- icoppositeselection = TIMER_IC_SELECTION_INDIRECTTI;
- } else {
- icoppositeselection = TIMER_IC_SELECTION_DIRECTTI;
- }
- if (TIMER_ICInit->TIMER_CH == TIMER_CH_1) {
- TI1_Config(TIMERx, TIMER_ICInit->TIMER_ICPolarity,
- TIMER_ICInit->TIMER_ICSelection,
- TIMER_ICInit->TIMER_ICFilter);
- TIMER_Set_IC1_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- TI2_Config(TIMERx, icoppositepolarity, icoppositeselection, TIMER_ICInit->TIMER_ICFilter);
- TIMER_Set_IC2_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- } else {
- TI2_Config(TIMERx, TIMER_ICInit->TIMER_ICPolarity,
- TIMER_ICInit->TIMER_ICSelection,
- TIMER_ICInit->TIMER_ICFilter);
- TIMER_Set_IC2_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- TI1_Config(TIMERx, icoppositepolarity, icoppositeselection, TIMER_ICInit->TIMER_ICFilter);
- TIMER_Set_IC1_Prescaler(TIMERx, TIMER_ICInit->TIMER_ICPrescaler);
- }
- }
- /**
- * @brief Read the TIMERx Input Capture value.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @retval None
- */
- uint32_t TIMER_GetCapture1(TIMER_TypeDef *TIMERx)
- {
- return TIMERx->CHCC1;
- }
- /**
- * @brief Read the TIMERx Input Capture value.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @retval None
- */
- uint32_t TIMER_GetCapture2(TIMER_TypeDef *TIMERx)
- {
- return TIMERx->CHCC2;
- }
- /**
- * @brief Read the TIMERx Input Capture value.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @retval None
- */
- uint32_t TIMER_GetCapture3(TIMER_TypeDef *TIMERx)
- {
- return TIMERx->CHCC3;
- }
- /**
- * @brief Read the TIMERx Input Capture value.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @retval None
- */
- uint32_t TIMER_GetCapture4(TIMER_TypeDef *TIMERx)
- {
- return TIMERx->CHCC4;
- }
- /**
- * @brief Configure the TIMERx Input Capture prescaler.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_ICPSC: the Input Capture1 prescaler value.
- * This value will be :
- * @arg TIMER_IC_PSC_DIV1: no prescaler
- * @arg TIMER_IC_PSC_DIV2: divided by 2
- * @arg TIMER_IC_PSC_DIV4: divided by 4
- * @arg TIMER_IC_PSC_DIV8: divided by 8
- * @retval None
- */
- void TIMER_Set_IC1_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC)
- {
- TIMERx->CHCTLR1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1ICP);
- TIMERx->CHCTLR1 |= TIMER_ICPSC;
- }
- /**
- * @brief Configure the TIMERx Input Capture prescaler.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_ICPSC: the Input Capture1 prescaler value.
- * This value will be :
- * @arg TIMER_IC_PSC_DIV1: no prescaler
- * @arg TIMER_IC_PSC_DIV2: divided by 2
- * @arg TIMER_IC_PSC_DIV4: divided by 4
- * @arg TIMER_IC_PSC_DIV8: divided by 8
- * @retval None
- */
- void TIMER_Set_IC2_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC)
- {
- TIMERx->CHCTLR1 &= (uint16_t)~((uint16_t)TIMER_CHCTLR1_CH2ICP);
- TIMERx->CHCTLR1 |= (uint16_t)(TIMER_ICPSC << 8);
- }
- /**
- * @brief Configure the TIMERx Input Capture prescaler.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_ICPSC: the Input Capture1 prescaler value.
- * This value will be :
- * @arg TIMER_IC_PSC_DIV1: no prescaler
- * @arg TIMER_IC_PSC_DIV2: divided by 2
- * @arg TIMER_IC_PSC_DIV4: divided by 4
- * @arg TIMER_IC_PSC_DIV8: divided by 8
- * @retval None
- */
- void TIMER_Set_IC3_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC)
- {
- TIMERx->CHCTLR2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH3ICP);
- TIMERx->CHCTLR2 |= TIMER_ICPSC;
- }
- /**
- * @brief Configure the TIMERx Input Capture prescaler.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_ICPSC: the Input Capture1 prescaler value.
- * This value will be :
- * @arg TIMER_IC_PSC_DIV1: no prescaler
- * @arg TIMER_IC_PSC_DIV2: divided by 2
- * @arg TIMER_IC_PSC_DIV4: divided by 4
- * @arg TIMER_IC_PSC_DIV8: divided by 8
- * @retval None
- */
- void TIMER_Set_IC4_Prescaler(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPSC)
- {
- TIMERx->CHCTLR2 &= (uint16_t)~((uint16_t)TIMER_CHCTLR2_CH4ICP);
- TIMERx->CHCTLR2 |= (uint16_t)(TIMER_ICPSC << 8);
- }
- /**
- * @brief Configure interrupts Enables
- * @param TIMERx: x ={ 0-13 } .
- * @param TIMER_INT: the interrupts sources to Configure.
- * This value will be :
- * @arg TIMER_INT_UPDATE : update Interrupt
- * @arg TIMER_INT_CH1 : Channel 1 Capture or Compare Interrupt
- * @arg TIMER_INT_CH2 : Channel 2 Capture or Compare Interrupt
- * @arg TIMER_INT_CH3 : Channel 3 Capture or Compare Interrupt
- * @arg TIMER_INT_CH4 : Channel 4 Capture or Compare Interrupt
- * @arg TIMER_INT_CCUG : Commutation Interrupt
- * @arg TIMER_INT_TRIGGER : Trigger Interrupt
- * @arg TIMER_INT_BREAK : Break Interrupt
- * @param NewValue: ENABLE or DISABLE.
- * @retval None
- */
- void TIMER_INTConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_INT, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- TIMERx->DIE |= TIMER_INT;
- } else {
- TIMERx->DIE &= (uint16_t)~TIMER_INT;
- }
- }
- /**
- * @brief Generate the software event
- * @param TIMERx: x ={ 0-13 } .
- * @param TIMER_EventSrc:
- * This value will be :
- * @arg TIMER_EVENT_SRC_UPDATE : update Event
- * @arg TIMER_EVENT_SRC_CH1 : Channel 1 Capture or Compare Event
- * @arg TIMER_EVENT_SRC_CH2 : Channel 2 Capture or Compare Event
- * @arg TIMER_EVENT_SRC_CH3 : Channel 3 Capture or Compare Event
- * @arg TIMER_EVENT_SRC_CH4 : Channel 4 Capture or Compare Event
- * @arg TIMER_EVENT_SRC_COM : COM event
- * @arg TIMER_EVENT_SRC_TRIGGER : Trigger Event
- * @arg TIMER_EVENT_SRC_BREAK : Break event
- * @retval None
- */
- void TIMER_GenerateEvent(TIMER_TypeDef *TIMERx, uint16_t TIMER_EventSrc)
- {
- TIMERx->EVG = TIMER_EventSrc;
- }
- /**
- * @brief Get current flag status
- * @param TIMERx: x ={ 0-13 } .
- * @param TIMER_FLAG:
- * This value will be :
- * @arg TIMER_FLAG_UPDATE : update Flag
- * @arg TIMER_FLAG_CH1 : Channel 1 Capture or Compare Flag
- * @arg TIMER_FLAG_CH2 : Channel 2 Capture or Compare Flag
- * @arg TIMER_FLAG_CH3 : Channel 3 Capture or Compare Flag
- * @arg TIMER_FLAG_CH4 : Channel 4 Capture or Compare Flag
- * @arg TIMER_FLAG_COM : Commutation Flag
- * @arg TIMER_FLAG_TRIGGER : Trigger Flag
- * @arg TIMER_FLAG_BREAK : Break Flag
- * @arg TIMER_FLAG_CH1OF : Channel 1 Capture or Compare overcapture Flag
- * @arg TIMER_FLAG_CH2OF : Channel 2 Capture or Compare overcapture Flag
- * @arg TIMER_FLAG_CH3OF : Channel 3 Capture or Compare overcapture Flag
- * @arg TIMER_FLAG_CH4OF : Channel 4 Capture or Compare overcapture Flag
- * @retval The state of TIMER_FLAG ( SET or RESET ).
- */
- TypeState TIMER_GetBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_FLAG)
- {
- if ((TIMERx->STR & TIMER_FLAG) != (uint16_t)RESET) {
- return SET;
- } else {
- return RESET;
- }
- }
- /**
- * @brief Clear the flags
- * @param TIMERx: x ={ 0-13 } .
- * @param TIMER_FLAG: the flag bit to clear.
- * This value will be :
- * @arg TIMER_FLAG_UPDATE : update Flag
- * @arg TIMER_FLAG_CH1 : Channel 1 Capture or Compare Flag
- * @arg TIMER_FLAG_CH2 : Channel 2 Capture or Compare Flag
- * @arg TIMER_FLAG_CH3 : Channel 3 Capture or Compare Flag
- * @arg TIMER_FLAG_CH4 : Channel 4 Capture or Compare Flag
- * @arg TIMER_FLAG_COM : Commutation Flag
- * @arg TIMER_FLAG_TRIGGER : Trigger Flag
- * @arg TIMER_FLAG_BREAK : Break Flag
- * @arg TIMER_FLAG_CH1OF : Channel 1 Capture or Compare overcapture Flag
- * @arg TIMER_FLAG_CH2OF : Channel 2 Capture or Compare overcapture Flag
- * @arg TIMER_FLAG_CH3OF : Channel 3 Capture or Compare overcapture Flag
- * @arg TIMER_FLAG_CH4OF : Channel 4 Capture or Compare overcapture Flag
- * @retval None
- */
- void TIMER_ClearBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_FLAG)
- {
- TIMERx->STR = (uint16_t)~TIMER_FLAG;
- }
- /**
- * @brief Get interrupt state
- * @param TIMERx: x ={ 0-13 } .
- * @param TIMER_INT:
- * This value will be :
- * @arg TIMER_INT_UPDATE: update Interrupt
- * @arg TIMER_INT_CH1 : Channel 1 Capture or Compare Interrupt
- * @arg TIMER_INT_CH2 : Channel 2 Capture or Compare Interrupt
- * @arg TIMER_INT_CH3 : Channel 3 Capture or Compare Interrupt
- * @arg TIMER_INT_CH4 : Channel 4 Capture or Compare Interrupt
- * @arg TIMER_INT_CCUG : Commutation Interrupt
- * @arg TIMER_INT_TRIGGER : Trigger Interrupt
- * @arg TIMER_INT_BREAK : Break Interrupt
- * @retval The new state of the TIMER_INT(SET or RESET).
- */
- TypeState TIMER_GetIntBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_INT)
- {
- uint16_t TypeState = 0x0, itenable = 0x0;
- TypeState = TIMERx->STR & TIMER_INT;
- itenable = TIMERx->DIE & TIMER_INT;
- if ((TypeState != (uint16_t)RESET) && (itenable != (uint16_t)RESET)) {
- return SET;
- } else {
- return RESET;
- }
- }
- /**
- * @brief Clear the interrupt pending bits
- * @param TIMERx: x ={ 0-13 } .
- * @param TIMER_INT:
- * This value will be :
- * @arg TIMER_INT_UPDATE: update Interrupt
- * @arg TIMER_INT_CH1 : Channel 1 Capture or Compare Interrupt
- * @arg TIMER_INT_CH2 : Channel 2 Capture or Compare Interrupt
- * @arg TIMER_INT_CH3 : Channel 3 Capture or Compare Interrupt
- * @arg TIMER_INT_CH4 : Channel 4 Capture or Compare Interrupt
- * @arg TIMER_INT_CCUG : Commutation Interrupt
- * @arg TIMER_INT_TRIGGER : Trigger Interrupt
- * @arg TIMER_INT_BREAK : Break Interrupt
- * @retval None
- */
- void TIMER_ClearIntBitState(TIMER_TypeDef *TIMERx, uint16_t TIMER_INT)
- {
- TIMERx->STR = (uint16_t)~TIMER_INT;
- }
- /**
- * @brief Configure the DMA .
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_DMABase: DMA Base address.
- * This value will be :
- * @arg TIMER_DMA_BASE_ADDR_CTLR1
- * @arg TIMER_DMA_BASE_ADDR_CTLR2
- * @arg TIMER_DMA_BASE_ADDR_SMC
- * @arg TIMER_DMA_BASE_ADDR_DIE
- * @arg TIMER_DMA_BASE_ADDR_STR
- * @arg TIMER_DMA_BASE_ADDR_EVG
- * @arg TIMER_DMA_BASE_ADDR_CHCTLR1
- * @arg TIMER_DMA_BASE_ADDR_CHCTLR2
- * @arg TIMER_DMA_BASE_ADDR_CHE
- * @arg TIMER_DMA_BASE_ADDR_CNT
- * @arg TIMER_DMA_BASE_ADDR_PSC
- * @arg TIMER_DMA_BASE_ADDR_CARL
- * @arg TIMER_DMA_BASE_ADDR_CREP
- * @arg TIMER_DMA_BASE_ADDR_CHCC1
- * @arg TIMER_DMA_BASE_ADDR_CHCC2
- * @arg TIMER_DMA_BASE_ADDR_CHCC3
- * @arg TIMER_DMA_BASE_ADDR_CHCC4
- * @arg TIMER_DMA_BASE_ADDR_BKDT
- * @arg TIMER_DMA_BASE_ADDR_DCTLR
- * @arg TIMER_DMA_BASE_ADDR_DTRSF
- * @param TIMER_DMABurstLength: DMA Burst length.
- * This value will be :
- * [ TIMER_DMA_BURST_1TRANSFER , TIMER_DMA_BURST_18TRANSFERS ]
- * @retval None
- */
- void TIMER_DMAConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_DMABase, uint16_t TIMER_DMABurstLength)
- {
- TIMERx->DCTLR = TIMER_DMABase | TIMER_DMABurstLength;
- }
- /**
- * @brief Configure the TIMERx's DMA Requests
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } .
- * @param TIMER_DMASrc: the DMA Request sources.
- * This value will be :
- * @arg TIMER_DMA_UPDATE : update start DMA
- * @arg TIMER_DMA_CH1 : Channel 1 Capture or Compare start DMA
- * @arg TIMER_DMA_CH2 : Channel 2 Capture or Compare start DMA
- * @arg TIMER_DMA_CH3 : Channel 3 Capture or Compare start DMA
- * @arg TIMER_DMA_CH4 : Channel 4 Capture or Compare start DMA
- * @arg TIMER_DMA_COM : Commutation DMA
- * @arg TIMER_DMA_TRIGGER : Trigger DMA
- * @param NewValue: ENABLE or DISABLE.
- * @retval None
- */
- void TIMER_DMACmd(TIMER_TypeDef *TIMERx, uint16_t TIMER_DMASrc, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- /* Enable the DMA */
- TIMERx->DIE |= TIMER_DMASrc;
- } else {
- /* Disable the DMA */
- TIMERx->DIE &= (uint16_t)~TIMER_DMASrc;
- }
- }
- /**
- * @brief Select the Capture or Compare DMA source
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param NewValue: ENABLE or DISABLE
- * @retval None
- */
- void TIMER_CC_DMA(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- TIMERx->CTLR2 |= TIMER_CTLR2_DMAS;
- } else {
- TIMERx->CTLR2 &= (uint16_t)~((uint16_t)TIMER_CTLR2_DMAS);
- }
- }
- /**
- * @brief Configure the internal Clock
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 }
- * @retval None
- */
- void TIMER_InternalClockConfig(TIMER_TypeDef *TIMERx)
- {
- TIMERx->SMC &= (uint16_t)(~((uint16_t)TIMER_SMC_SMC));
- }
- /**
- * @brief Configure the Internal Trigger as External Input Clock
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_InputTriSrc:
- * This value will be :
- * @arg TIMER_TS_ITR0 : Internal Trigger 0
- * @arg TIMER_TS_ITR1 : Internal Trigger 1
- * @arg TIMER_TS_ITR2 : Internal Trigger 2
- * @arg TIMER_TS_ITR3 : Internal Trigger 3
- * @retval None
- */
- void TIMER_ITRxExtClock(TIMER_TypeDef *TIMERx, uint16_t TIMER_InputTriSrc)
- {
- /* Select the Internal Trigger */
- TIMER_SelectInputTrigger(TIMERx, TIMER_InputTriSrc);
- /* Select the External clock mode1 */
- TIMERx->SMC |= TIMER_SLAVE_MODE_EXTERNAL1;
- }
- /**
- * @brief Configure the External Trigger as External Input Clock
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_TIxExCLKSrc: Trigger source.
- * This value will be :
- * @arg TIMER_TIX_EXCLK1_SRC_TI1ED : TI1 Edge Detector
- * @arg TIMER_TIX_EXCLK1_SRC_TI1 : Filtered Timer Input 1
- * @arg TIMER_TIX_EXCLK1_SRC_TI2 : Filtered Timer Input 2
- * @param TIMER_ICPolarity:
- * This value will be :
- * @arg TIMER_IC_POLARITY_RISING
- * @arg TIMER_IC_POLARITY_FALLING
- * @param ICFilter: specifies the filter value.
- * This parameter must be a value between 0x0 and 0xF.
- * @retval None
- */
- void TIMER_TIxExtCLkConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_TIxExCLKSrc,
- uint16_t TIMER_ICPolarity, uint16_t ICFilter)
- {
- /* Select the Input Clock Source */
- if (TIMER_TIxExCLKSrc == TIMER_TIX_EXCLK1_SRC_TI2) {
- TI2_Config(TIMERx, TIMER_ICPolarity, TIMER_IC_SELECTION_DIRECTTI, ICFilter);
- } else {
- TI1_Config(TIMERx, TIMER_ICPolarity, TIMER_IC_SELECTION_DIRECTTI, ICFilter);
- }
- /* Select the Trigger source */
- TIMER_SelectInputTrigger(TIMERx, TIMER_TIxExCLKSrc);
- /* Enter the External clock mode1 */
- TIMERx->SMC |= TIMER_SLAVE_MODE_EXTERNAL1;
- }
- /**
- * @brief Configure the External clock Mode1
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_ExtTriPrescaler: The external Trigger Prescaler.
- * This value will be :
- * @arg TIMER_EXT_TRI_PSC_OFF: no divided.
- * @arg TIMER_EXT_TRI_PSC_DIV2: divided by 2.
- * @arg TIMER_EXT_TRI_PSC_DIV4: divided by 4.
- * @arg TIMER_EXT_TRI_PSC_DIV8: divided by 8.
- * @param TIMER_ExtTriPolarity: Trigger Polarity.
- * This value will be :
- * @arg TIMER_EXT_TRI_POLARITY_INVERTED : active low or falling edge active.
- * @arg TIMER_EXT_TRI_POLARITY_NONINVERTED: active high or rising edge active.
- * @param ExtTriFilter: External Trigger Filter.
- * This parameter must be a value between 0x00 and 0x0F
- * @retval None
- */
- void TIMER_ETRClockMode1Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ExTriPrescaler, uint16_t TIMER_ExTriPolarity,
- uint16_t ExtTriFilter)
- {
- uint16_t tmpsmc = 0;
- /* Configure the external Trigger Clock source */
- TIMER_ETRConfig(TIMERx, TIMER_ExTriPrescaler, TIMER_ExTriPolarity, ExtTriFilter);
- /* Get the TIMERx SMC register value */
- tmpsmc = TIMERx->SMC;
- tmpsmc &= (uint16_t)(~((uint16_t)TIMER_SMC_SMC));
- /* Select the External clock mode1 */
- tmpsmc |= TIMER_SLAVE_MODE_EXTERNAL1;
- /* Select the Trigger selection : ETRF */
- tmpsmc &= (uint16_t)(~((uint16_t)TIMER_SMC_TRGS));
- tmpsmc |= TIMER_TS_ETRF;
- TIMERx->SMC = tmpsmc;
- }
- /**
- * @brief Configure the External clock Mode2
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_ExtTriPrescaler: The external Trigger Prescaler.
- * This value will be :
- * @arg TIMER_EXT_TRI_PSC_OFF: no divided.
- * @arg TIMER_EXT_TRI_PSC_DIV2: divided by 2.
- * @arg TIMER_EXT_TRI_PSC_DIV4: divided by 4.
- * @arg TIMER_EXT_TRI_PSC_DIV8: divided by 8.
- * @param TIMER_ExtTriPolarity: Trigger Polarity.
- * This value will be :
- * @arg TIMER_EXT_TRI_POLARITY_INVERTED : active low or falling edge active.
- * @arg TIMER_EXT_TRI_POLARITY_NONINVERTED: active high or rising edge active.
- * @param ExtTriFilter: External Trigger Filter.
- * This parameter must be a value between 0x00 and 0x0F
- * @retval None
- */
- void TIMER_ETRClockMode2Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ExTriPrescaler,
- uint16_t TIMER_ExTriPolarity, uint16_t ExtTriFilter)
- {
- /* Configure the ETR Clock source */
- TIMER_ETRConfig(TIMERx, TIMER_ExTriPrescaler, TIMER_ExTriPolarity, ExtTriFilter);
- /* Select the External clock mode2 */
- TIMERx->SMC |= TIMER_SMC_ECM2E;
- }
- /**
- * @brief Select the Input Trigger source
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_InputTriSrc: The Input Trigger source.
- * This value will be :
- * @arg TIMER_TS_ITR0 : Internal Trigger 0
- * @arg TIMER_TS_ITR1 : Internal Trigger 1
- * @arg TIMER_TS_ITR2 : Internal Trigger 2
- * @arg TIMER_TS_ITR3 : Internal Trigger 3
- * @arg TIMER_TS_TI1F_ED : TI1 Edge Detector
- * @arg TIMER_TS_TI1FP1 : Filtered Timer Input 1
- * @arg TIMER_TS_TI2FP2 : Filtered Timer Input 2
- * @arg TIMER_TS_ETRF : External Trigger input
- * @retval None
- */
- void TIMER_SelectInputTrigger(TIMER_TypeDef *TIMERx, uint16_t TIMER_InputTriSrc)
- {
- uint16_t tmpsmc = 0;
- tmpsmc = TIMERx->SMC;
- /* Reset the TS Bits */
- tmpsmc &= (uint16_t)(~((uint16_t)TIMER_SMC_TRGS));
- /* Set the Input Trigger source */
- tmpsmc |= TIMER_InputTriSrc ;
- TIMERx->SMC = tmpsmc;
- }
- /**
- * @brief Configure the TIMERx Trigger Output Mode.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,10 , 11 , 13 , 14} .
- * @param TIMER_TriOutSrc:
- * This value will be :
- * @arg TIMER_TRI_OUT_SRC_RESET : The UPG bit in the TIMERx_EVG register as TriO.
- * @arg TIMER_TRI_OUT_SRC_ENABLE : The CEN bit in TIMERx_CTLR1 as TriO.
- * @arg TIMER_TRI_OUT_SRC_UPDATE : Update event as TriO.
- * @arg TIMER_TRI_OUT_SRC_OC1 : capture or compare match ( CC1IF bit set ) as TriO.
- * @arg TIMER_TRI_OUT_SRC_OC1REF : OC1REF as TriO.
- * @arg TIMER_TRI_OUT_SRC_OC2REF : OC2REF as TriO.
- * @arg TIMER_TRI_OUT_SRC_OC3REF : OC3REF as TriO.
- * @arg TIMER_TRI_OUT_SRC_OC4REF : OC4REF as TriO.
- * @retval None
- */
- void TIMER_SelectOutputTrigger(TIMER_TypeDef *TIMERx, uint16_t TIMER_TriOutSrc)
- {
- /* Reset the MMC Bits */
- TIMERx->CTLR2 &= (uint16_t)~((uint16_t)TIMER_CTLR2_MMC);
- /* Configures the TriO source */
- TIMERx->CTLR2 |= TIMER_TriOutSrc;
- }
- /**
- * @brief Configure the TIMERx Slave Mode
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_SlaveMode:
- * This value will be :
- * @arg TIMER_SLAVE_MODE_RESET : The trigger signal reset the timer
- * @arg TIMER_SLAVE_MODE_GATED : The trigger signal enable the counter when high.
- * @arg TIMER_SLAVE_MODE_TRIGGER : The trigger signal starts the counter.
- * @arg TIMER_SLAVE_MODE_EXTERNAL1 : The trigger signal as a counter clock.
- * @retval None
- */
- void TIMER_SelectSlaveMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_SlaveMode)
- {
- /* Reset the SMC Bits */
- TIMERx->SMC &= (uint16_t)~((uint16_t)TIMER_SMC_SMC);
- /* Configure the Slave Mode */
- TIMERx->SMC |= TIMER_SlaveMode;
- }
- /**
- * @brief Configure the TIMERx Master or Slave Mode
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 10 , 11 , 13 , 14} .
- * @param TIMER_MasterSlaveMode:
- * This value will be :
- * @arg TIMER_MASTER_SLAVE_MODE_ENABLE : synchronize master and slave by TriO
- * @arg TIMER_MASTER_SLAVE_MODE_DISABLE : Don't synchronize
- * @retval None
- */
- void TIMER_SelectMasterSlaveMode(TIMER_TypeDef *TIMERx, uint16_t TIMER_MasterSlaveMode)
- {
- /* Reset the MSM Bit */
- TIMERx->SMC &= (uint16_t)~((uint16_t)TIMER_SMC_MSM);
- /* Configure the MSM Bit */
- TIMERx->SMC |= TIMER_MasterSlaveMode;
- }
- /**
- * @brief Configure the External Trigger (ETR)
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_ExTriPrescaler: external Trigger Prescaler.
- * This value will be :
- * @arg TIMER_EXT_TRI_PSC_OFF : no divided.
- * @arg TIMER_EXT_TRI_PSC_DIV2: divided by 2.
- * @arg TIMER_EXT_TRI_PSC_DIV4: divided by 4.
- * @arg TIMER_EXT_TRI_PSC_DIV8: divided by 8.
- * @param TIMER_ExtTriPolarity: Trigger Polarity.
- * This value will be :
- * @arg TIMER_EXT_TRI_POLARITY_INVERTED : active low or falling edge active.
- * @arg TIMER_EXT_TRI_POLARITY_NONINVERTED: active high or rising edge active.
- * @param ExtTRGFilter: The External Trigger signal Filter.
- * This parameter must be a value between 0x00 and 0x0F
- * @retval None
- */
- void TIMER_ETRConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_ExTriPrescaler, uint16_t TIMER_ExTriPolarity,
- uint16_t ExtTriFilter)
- {
- uint16_t tmpsmc = 0;
- tmpsmc = TIMERx->SMC;
- /*Reset the ETR Bits */
- tmpsmc &= SMC_ETR_MASK;
- /* Configure the Prescaler, the Filter value and the Polarity */
- tmpsmc |= (uint16_t)(TIMER_ExTriPrescaler | (uint16_t)(TIMER_ExTriPolarity | (uint16_t)(ExtTriFilter << (uint16_t)8)));
- TIMERx->SMC = tmpsmc;
- }
- /**
- * @brief Configure the Encoder Interface.
- * @param TIMERx: x ={ 1 , 8 , 9 , 12 } .
- * @param TIMER_EncoderMode:
- * This value will be :
- * @arg TIMER_ENCODER_MODE_TI1 : Counter counts on TI1FP1 edge depending on TI2FP2 level.
- * @arg TIMER_ENCODER_MODE_TI2 : Counter counts on TI2FP2 edge depending on TI1FP1 level.
- * @arg TIMER_ENCODER_MODE_TI12 : Counter counts on both TI1FP1 and TI2FP2 edges depending
- * on the level of the other input.
- * @param TIMER_IC1Polarity: input capture 1 Polarity
- * This value will be :
- * @arg TIMER_IC_POLARITY_FALLING : capture Falling edge.
- * @arg TIMER_IC_POLARITY_RISING : capture Rising edge.
- * @param TIMER_IC2Polarity: input capture 2 Polarity
- * This value will be :
- * @arg TIMER_IC_POLARITY_FALLING : capture Falling edge.
- * @arg TIMER_IC_POLARITY_RISING : capture Rising edge.
- * @retval None
- */
- void TIMER_EncoderInterfaceConfig(TIMER_TypeDef *TIMERx, uint16_t TIMER_EncoderMode,
- uint16_t TIMER_IC1Polarity, uint16_t TIMER_IC2Polarity)
- {
- uint16_t tmpsmc = 0;
- uint16_t tmpchctlr1 = 0;
- uint16_t tmpche = 0;
- tmpsmc = TIMERx->SMC;
- tmpchctlr1 = TIMERx->CHCTLR1;
- tmpche = TIMERx->CHE;
- /* select the encoder Mode */
- tmpsmc &= (uint16_t)(~((uint16_t)TIMER_SMC_SMC));
- tmpsmc |= TIMER_EncoderMode;
- tmpchctlr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1M)) & (uint16_t)(~((uint16_t)TIMER_CHCTLR1_CH2M)));
- tmpchctlr1 |= TIMER_CHCTLR1_CH1M_0 | TIMER_CHCTLR1_CH2M_0;
- /* select the TI1 and the TI2 Polarities*/
- tmpche &= (uint16_t)~((uint16_t)(TIMER_CHE_CH1P | TIMER_CHE_CH1NP)) & (uint16_t)~((uint16_t)(TIMER_CHE_CH2P | TIMER_CHE_CH2NP));
- tmpche |= (uint16_t)(TIMER_IC1Polarity | (uint16_t)(TIMER_IC2Polarity << (uint16_t)4));
- TIMERx->SMC = tmpsmc;
- TIMERx->CHCTLR1 = tmpchctlr1;
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the Hall sensor interface
- * @param TIMERx: x ={ 1 , 8 } .
- * @param NewValue: ENABLE or DISABLE.
- * @retval None
- */
- void TIMER_SelectHallSensor(TIMER_TypeDef *TIMERx, TypeState NewValue)
- {
- if (NewValue != DISABLE) {
- TIMERx->CTLR2 |= TIMER_CTLR2_TI1S;
- } else {
- TIMERx->CTLR2 &= (uint16_t)~((uint16_t)TIMER_CTLR2_TI1S);
- }
- }
- /* Private functions */
- /**
- * @brief Configure the TI1 as Capture Input.
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 10 , 11 , 12 , 13 , 14} .
- * @param TIMER_ICPolarity: Input Capture Polarity.
- * This value will be :
- * @arg TIMER_IC_POLARITY_RISING : Capture rising edge
- * @arg TIMER_IC_POLARITY_FALLING : Capture falling edge
- * @param TIMER_ICSelection: Input Capture source.
- * This value will be :
- * @arg TIMER_IC_SELECTION_DIRECTTI : connected to IC1.
- * @arg TIMER_IC_SELECTION_INDIRECTTI : connected to IC2.
- * @arg TIMER_IC_SELECTION_TRC : connected to TRC.
- * @param TIMER_ICFilter: Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void TI1_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter)
- {
- uint16_t tmpchctlr1 = 0, tmpche = 0;
- /* Disable the Channel 1 */
- TIMERx->CHE &= (uint16_t)~((uint16_t)TIMER_CHE_CH1E);
- tmpchctlr1 = TIMERx->CHCTLR1;
- tmpche = TIMERx->CHE;
- /* Select the Input and Configure the filter */
- tmpchctlr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1M)) & ((uint16_t)~((uint16_t)TIMER_CHCTLR1_CH1ICF)));
- tmpchctlr1 |= (uint16_t)(TIMER_ICSelection | (uint16_t)(TIMER_ICFilter << (uint16_t)4));
- /* Configure the Polarity and channel enable Bit */
- tmpche &= (uint16_t)~((uint16_t)(TIMER_CHE_CH1P | TIMER_CHE_CH1NP));
- tmpche |= (uint16_t)(TIMER_ICPolarity | (uint16_t)TIMER_CHE_CH1E);
- TIMERx->CHCTLR1 = tmpchctlr1;
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TI2 as Capture Input.
- * @note None
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 , 9 , 12 } .
- * @param TIMER_ICPolarity: Input Capture Polarity.
- * This value will be :
- * @arg TIMER_IC_POLARITY_RISING : Capture rising edge
- * @arg TIMER_IC_POLARITY_FALLING : Capture falling edge
- * @param TIMER_ICSelection: Input Capture source.
- * This value will be :
- * @arg TIMER_IC_SELECTION_DIRECTTI : connected to IC2.
- * @arg TIMER_IC_SELECTION_INDIRECTTI : connected to IC1.
- * @arg TIMER_IC_SELECTION_TRC : connected to TRC.
- * @param TIMER_ICFilter: Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void TI2_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter)
- {
- uint16_t tmpchctlr1 = 0, tmpche = 0, tmp = 0;
- /* Disable the Channel 2 */
- TIMERx->CHE &= (uint16_t)~((uint16_t)TIMER_CHE_CH2E);
- tmpchctlr1 = TIMERx->CHCTLR1;
- tmpche = TIMERx->CHE;
- tmp = (uint16_t)(TIMER_ICPolarity << 4);
- /* Select the Input and Configure the filter */
- tmpchctlr1 &= (uint16_t)(((uint16_t)~((uint16_t)TIMER_CHCTLR1_CH2M)) & ((uint16_t)~((uint16_t)TIMER_CHCTLR1_CH2ICF)));
- tmpchctlr1 |= (uint16_t)(TIMER_ICFilter << 12);
- tmpchctlr1 |= (uint16_t)(TIMER_ICSelection << 8);
- /* Configure the Polarity and channel enable Bit */
- tmpche &= (uint16_t)~((uint16_t)(TIMER_CHE_CH2P | TIMER_CHE_CH2NP));
- tmpche |= (uint16_t)(tmp | (uint16_t)TIMER_CHE_CH2E);
- TIMERx->CHCTLR1 = tmpchctlr1 ;
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TI3 as Capture Input
- * @note None
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_ICPolarity: Input Capture Polarity.
- * This value will be :
- * @arg TIMER_IC_POLARITY_RISING : Capture rising edge
- * @arg TIMER_IC_POLARITY_FALLING : Capture falling edge
- * @param TIMER_ICSelection: Input Capture source.
- * This value will be :
- * @arg TIMER_IC_SELECTION_DIRECTTI : connected to IC3.
- * @arg TIMER_IC_SELECTION_INDIRECTTI : connected to IC4.
- * @arg TIMER_IC_SELECTION_TRC : connected to TRC.
- * @param TIMER_ICFilter: Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void TI3_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter)
- {
- uint16_t tmpchctlr2 = 0, tmpche = 0, tmp = 0;
- /* Disable the Channel 3 */
- TIMERx->CHE &= (uint16_t)~((uint16_t)TIMER_CHE_CH3E);
- tmpchctlr2 = TIMERx->CHCTLR2;
- tmpche = TIMERx->CHE;
- tmp = (uint16_t)(TIMER_ICPolarity << 8);
- /* Select the Input and Configure the filter */
- tmpchctlr2 &= (uint16_t)(((uint16_t)~((uint16_t)TIMER_CHCTLR2_CH3M)) & ((uint16_t)~((uint16_t)TIMER_CHCTLR2_CH3ICF)));
- tmpchctlr2 |= (uint16_t)(TIMER_ICSelection | (uint16_t)(TIMER_ICFilter << (uint16_t)4));
- /* Configure the Polarity and channel enable Bit */
- tmpche &= (uint16_t)~((uint16_t)(TIMER_CHE_CH3P | TIMER_CHE_CH3NP));
- tmpche |= (uint16_t)(tmp | (uint16_t)TIMER_CHE_CH3E);
- TIMERx->CHCTLR2 = tmpchctlr2;
- TIMERx->CHE = tmpche;
- }
- /**
- * @brief Configure the TI4 as Capture Input
- * @param TIMERx: x ={ 1 , 2 , 3 , 4 , 5 , 8 } .
- * @param TIMER_ICPolarity: Input Capture Polarity.
- * This value will be :
- * @arg TIMER_IC_POLARITY_RISING : Capture rising edge
- * @arg TIMER_IC_POLARITY_FALLING : Capture falling edge
- * @param TIMER_ICSelection: Input Capture source.
- * This value will be :
- * @arg TIMER_IC_SELECTION_DIRECTTI : connected to IC4.
- * @arg TIMER_IC_SELECTION_INDIRECTTI : connected to IC3.
- * @arg TIMER_IC_SELECTION_TRC : connected to TRC.
- * @param TIMER_ICFilter: Input Capture Filter.
- * This parameter must be a value between 0x00 and 0x0F.
- * @retval None
- */
- static void TI4_Config(TIMER_TypeDef *TIMERx, uint16_t TIMER_ICPolarity, uint16_t TIMER_ICSelection,
- uint16_t TIMER_ICFilter)
- {
- uint16_t tmpchctlr2 = 0, tmpche = 0, tmp = 0;
- /* Disable the Channel 4 */
- TIMERx->CHE &= (uint16_t)~((uint16_t)TIMER_CHE_CH4E);
- tmpchctlr2 = TIMERx->CHCTLR2;
- tmpche = TIMERx->CHE;
- tmp = (uint16_t)(TIMER_ICPolarity << 12);
- /* Select the Input and Configure the filter */
- tmpchctlr2 &= (uint16_t)((uint16_t)(~(uint16_t)TIMER_CHCTLR2_CH4M) & ((uint16_t)~((uint16_t)TIMER_CHCTLR2_CH4ICF)));
- tmpchctlr2 |= (uint16_t)(TIMER_ICSelection << 8);
- tmpchctlr2 |= (uint16_t)(TIMER_ICFilter << 12);
- /* Configure the Polarity and channel enable Bit */
- tmpche &= (uint16_t)~((uint16_t)(TIMER_CHE_CH4P | TIMER_CHE_CH4NP));
- tmpche &= (uint16_t)~((uint16_t)(TIMER_CHE_CH4P));
- tmpche |= (uint16_t)(tmp | (uint16_t)TIMER_CHE_CH4E);
- TIMERx->CHCTLR2 = tmpchctlr2;
- TIMERx->CHE = tmpche;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
|