123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943 |
- #include "stm32f4xx_lptim.h"
- #if defined(STM32F410xx) || defined(STM32F413_423xx)
- #define CFGR_INIT_CLEAR_MASK ((uint32_t) 0xFFCFF1FE)
- #define CFGR_TRIG_AND_POL_CLEAR_MASK ((uint32_t) 0xFFF91FFF)
- void LPTIM_DeInit(LPTIM_TypeDef* LPTIMx)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
-
-
- if(LPTIMx == LPTIM1)
- {
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_LPTIM1, ENABLE);
- RCC_APB1PeriphResetCmd(RCC_APB1Periph_LPTIM1, DISABLE);
- }
- }
- void LPTIM_Init(LPTIM_TypeDef* LPTIMx, LPTIM_InitTypeDef* LPTIM_InitStruct)
- {
- uint32_t tmpreg1 = 0;
-
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_InitStruct->LPTIM_ClockSource));
- assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_InitStruct->LPTIM_Prescaler));
- assert_param(IS_LPTIM_WAVEFORM(LPTIM_InitStruct->LPTIM_Waveform));
- assert_param(IS_LPTIM_OUTPUT_POLARITY(LPTIM_InitStruct->LPTIM_OutputPolarity));
-
-
- tmpreg1 = LPTIMx->CFGR;
-
-
- tmpreg1 &= CFGR_INIT_CLEAR_MASK;
-
-
-
-
-
- tmpreg1 |= (LPTIM_InitStruct->LPTIM_ClockSource | LPTIM_InitStruct->LPTIM_Prescaler
- |LPTIM_InitStruct->LPTIM_Waveform | LPTIM_InitStruct->LPTIM_OutputPolarity);
-
-
- LPTIMx->CFGR = tmpreg1;
- }
- void LPTIM_StructInit(LPTIM_InitTypeDef* LPTIM_InitStruct)
- {
-
- LPTIM_InitStruct->LPTIM_ClockSource = LPTIM_ClockSource_APBClock_LPosc;
-
-
- LPTIM_InitStruct->LPTIM_OutputPolarity = LPTIM_OutputPolarity_High;
-
-
- LPTIM_InitStruct->LPTIM_Prescaler = LPTIM_Prescaler_DIV1;
-
-
- LPTIM_InitStruct->LPTIM_Waveform = LPTIM_Waveform_PWM_OnePulse;
- }
- void LPTIM_Cmd(LPTIM_TypeDef* LPTIMx, FunctionalState NewState)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if(NewState != DISABLE)
- {
-
- LPTIMx->CR |= LPTIM_CR_ENABLE;
- }
- else
- {
-
- LPTIMx->CR &= ~(LPTIM_CR_ENABLE);
- }
- }
- void LPTIM_SelectClockSource(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ClockSource)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_CLOCK_SOURCE(LPTIM_ClockSource));
-
-
- LPTIMx->CFGR &= ~(LPTIM_CFGR_CKSEL);
-
-
- LPTIMx->CFGR |= LPTIM_ClockSource;
- }
- void LPTIM_SelectULPTIMClockPolarity(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ClockPolarity)
- {
- uint32_t tmpreg1 = 0;
-
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_CLOCK_POLARITY(LPTIM_ClockPolarity));
-
-
- tmpreg1 = LPTIMx->CFGR;
-
-
- tmpreg1 &= ~(LPTIM_CFGR_CKPOL);
-
-
- tmpreg1 |= LPTIM_ClockPolarity;
-
-
- LPTIMx->CFGR = tmpreg1;
- }
- void LPTIM_ConfigPrescaler(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Prescaler)
- {
- uint32_t tmpreg1 = 0;
-
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_CLOCK_PRESCALER(LPTIM_Prescaler));
-
-
- tmpreg1 = LPTIMx->CFGR;
-
-
- tmpreg1 &= ~(LPTIM_CFGR_PRESC);
-
-
- tmpreg1 |= LPTIM_Prescaler;
-
-
- LPTIMx->CFGR = tmpreg1;
- }
- void LPTIM_ConfigExternalTrigger(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ExtTRGSource, uint32_t LPTIM_ExtTRGPolarity)
- {
- uint32_t tmpreg1 = 0;
-
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_EXT_TRG_SOURCE(LPTIM_ExtTRGSource));
- assert_param(IS_LPTIM_EXT_TRG_POLARITY(LPTIM_ExtTRGPolarity));
-
-
- tmpreg1 = LPTIMx->CFGR;
-
-
- tmpreg1 &= CFGR_TRIG_AND_POL_CLEAR_MASK;
-
-
- tmpreg1 |= (LPTIM_ExtTRGSource | LPTIM_ExtTRGPolarity);
-
-
- LPTIMx->CFGR = tmpreg1;
- }
- void LPTIM_SelectSoftwareStart(LPTIM_TypeDef* LPTIMx)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
-
-
- LPTIMx->CFGR &= ~(LPTIM_CFGR_TRIGEN);
- }
- void LPTIM_ConfigTriggerGlitchFilter(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_TrigSampleTime)
- {
- uint32_t tmpreg1 = 0;
-
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(LPTIM_TrigSampleTime));
-
-
- tmpreg1 = LPTIMx->CFGR;
-
-
- tmpreg1 &= ~(LPTIM_CFGR_TRGFLT);
-
-
- tmpreg1 |= (LPTIM_TrigSampleTime);
-
-
- LPTIMx->CFGR = tmpreg1;
- }
- void LPTIM_ConfigClockGlitchFilter(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ClockSampleTime)
- {
- uint32_t tmpreg1 = 0;
-
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(LPTIM_ClockSampleTime));
-
-
- tmpreg1 = LPTIMx->CFGR;
-
-
- tmpreg1 &= ~(LPTIM_CFGR_CKFLT);
-
-
- tmpreg1 |= LPTIM_ClockSampleTime;
-
-
- LPTIMx->CFGR = tmpreg1;
- }
- void LPTIM_SelectOperatingMode(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Mode)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_MODE(LPTIM_Mode));
-
-
- if(LPTIM_Mode == LPTIM_Mode_Continuous)
- {
-
- LPTIMx->CR |= LPTIM_Mode_Continuous;
- }
- else
- {
-
- LPTIMx->CR |= LPTIM_Mode_Single;
- }
- }
- void LPTIM_TimoutCmd(LPTIM_TypeDef* LPTIMx, FunctionalState NewState)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if(NewState != DISABLE)
- {
-
- LPTIMx->CFGR |= LPTIM_CFGR_TIMOUT;
- }
- else
- {
-
- LPTIMx->CFGR &= ~(LPTIM_CFGR_TIMOUT);
- }
- }
- void LPTIM_ConfigWaveform(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Waveform)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_WAVEFORM(LPTIM_Waveform));
-
-
- LPTIMx->CFGR &= ~(LPTIM_CFGR_CKFLT);
-
-
- LPTIMx->CFGR |= (LPTIM_Waveform);
- }
- void LPTIM_ConfigUpdate(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Update)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_UPDATE(LPTIM_Update));
-
-
- LPTIMx->CFGR &= ~(LPTIM_CFGR_PRELOAD);
-
-
- LPTIMx->CFGR |= (LPTIM_Update);
- }
- void LPTIM_SetAutoreloadValue(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Autoreload)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_AUTORELOAD(LPTIM_Autoreload));
-
-
- LPTIMx->ARR = LPTIM_Autoreload;
- }
- void LPTIM_SetCompareValue(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Compare)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_COMPARE(LPTIM_Compare));
-
-
- LPTIMx->CMP = LPTIM_Compare;
- }
- void LPTIM_SelectCounterMode(LPTIM_TypeDef* LPTIMx, FunctionalState NewState)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if(NewState != DISABLE)
- {
-
- LPTIMx->CFGR |= LPTIM_CFGR_COUNTMODE;
- }
- else
- {
-
- LPTIMx->CFGR &= ~(LPTIM_CFGR_COUNTMODE);
- }
- }
- void LPTIM_SelectEncoderMode(LPTIM_TypeDef* LPTIMx, FunctionalState NewState)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if(NewState != DISABLE)
- {
-
- LPTIMx->CFGR |= LPTIM_CFGR_ENC;
- }
- else
- {
-
- LPTIMx->CFGR &= ~(LPTIM_CFGR_ENC);
- }
- }
- uint32_t LPTIM_GetCounterValue(LPTIM_TypeDef* LPTIMx)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
-
-
- return LPTIMx->CNT;
- }
- uint32_t LPTIM_GetAutoreloadValue(LPTIM_TypeDef* LPTIMx)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
-
-
- return LPTIMx->ARR;
- }
- uint32_t LPTIM_GetCompareValue(LPTIM_TypeDef* LPTIMx)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
-
-
- return LPTIMx->CMP;
- }
- void LPTIM_RemapConfig(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_OPTR)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
-
-
- LPTIMx->OR = LPTIM_OPTR;
- }
- void LPTIM_ITConfig(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_IT, FunctionalState NewState)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_IT(LPTIM_IT));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if(NewState != DISABLE)
- {
-
- LPTIMx->IER |= LPTIM_IT;
- }
- else
- {
-
- LPTIMx->IER &= ~(LPTIM_IT);
- }
- }
- FlagStatus LPTIM_GetFlagStatus(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_FLAG)
- {
- ITStatus bitstatus = RESET;
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_GET_FLAG(LPTIM_FLAG));
- if((LPTIMx->ISR & LPTIM_FLAG) != (RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
- }
- void LPTIM_ClearFlag(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_CLEARF)
- {
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_CLEAR_FLAG(LPTIM_CLEARF));
-
- LPTIMx->ICR |= LPTIM_CLEARF;
- }
- ITStatus LPTIM_GetITStatus(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_IT)
- {
- ITStatus bitstatus = RESET;
- uint32_t itstatus = 0x0, itenable = 0x0;
-
- assert_param(IS_LPTIM_ALL_PERIPH(LPTIMx));
- assert_param(IS_LPTIM_IT(LPTIM_IT));
-
- itstatus = LPTIMx->ISR & LPTIM_IT;
-
- itenable = LPTIMx->IER & LPTIM_IT;
- if((itstatus != RESET) && (itenable != RESET))
- {
- bitstatus = SET;
- }
- else
- {
- bitstatus = RESET;
- }
- return bitstatus;
- }
- #endif
|