21 #ifndef STM32F4xx_HAL_LPTIM_H
22 #define STM32F4xx_HAL_LPTIM_H
45 #define LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT EXTI_IMR_MR23
58 } LPTIM_ClockConfigTypeDef;
76 } LPTIM_ULPClockConfigTypeDef;
93 } LPTIM_TriggerConfigTypeDef;
100 LPTIM_ClockConfigTypeDef Clock;
102 LPTIM_ULPClockConfigTypeDef UltraLowPowerClock;
104 LPTIM_TriggerConfigTypeDef Trigger;
106 uint32_t OutputPolarity;
113 uint32_t CounterSource;
123 HAL_LPTIM_STATE_RESET = 0x00U,
124 HAL_LPTIM_STATE_READY = 0x01U,
125 HAL_LPTIM_STATE_BUSY = 0x02U,
126 HAL_LPTIM_STATE_TIMEOUT = 0x03U,
127 HAL_LPTIM_STATE_ERROR = 0x04U
128 } HAL_LPTIM_StateTypeDef;
133 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
134 typedef struct __LPTIM_HandleTypeDef
141 LPTIM_InitTypeDef
Init;
147 __IO HAL_LPTIM_StateTypeDef State;
149 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
150 void (* MspInitCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
151 void (* MspDeInitCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
152 void (* CompareMatchCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
153 void (* AutoReloadMatchCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
154 void (* TriggerCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
155 void (* CompareWriteCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
156 void (* AutoReloadWriteCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
157 void (* DirectionUpCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
158 void (* DirectionDownCallback)(
struct __LPTIM_HandleTypeDef *hlptim);
160 } LPTIM_HandleTypeDef;
162 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
168 HAL_LPTIM_MSPINIT_CB_ID = 0x00U,
169 HAL_LPTIM_MSPDEINIT_CB_ID = 0x01U,
170 HAL_LPTIM_COMPARE_MATCH_CB_ID = 0x02U,
171 HAL_LPTIM_AUTORELOAD_MATCH_CB_ID = 0x03U,
172 HAL_LPTIM_TRIGGER_CB_ID = 0x04U,
173 HAL_LPTIM_COMPARE_WRITE_CB_ID = 0x05U,
174 HAL_LPTIM_AUTORELOAD_WRITE_CB_ID = 0x06U,
175 HAL_LPTIM_DIRECTION_UP_CB_ID = 0x07U,
176 HAL_LPTIM_DIRECTION_DOWN_CB_ID = 0x08U,
177 } HAL_LPTIM_CallbackIDTypeDef;
182 typedef void (*pLPTIM_CallbackTypeDef)(LPTIM_HandleTypeDef *hlptim);
197 #define LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC 0x00000000U
198 #define LPTIM_CLOCKSOURCE_ULPTIM LPTIM_CFGR_CKSEL
206 #define LPTIM_PRESCALER_DIV1 0x00000000U
207 #define LPTIM_PRESCALER_DIV2 LPTIM_CFGR_PRESC_0
208 #define LPTIM_PRESCALER_DIV4 LPTIM_CFGR_PRESC_1
209 #define LPTIM_PRESCALER_DIV8 (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_1)
210 #define LPTIM_PRESCALER_DIV16 LPTIM_CFGR_PRESC_2
211 #define LPTIM_PRESCALER_DIV32 (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_2)
212 #define LPTIM_PRESCALER_DIV64 (LPTIM_CFGR_PRESC_1 | LPTIM_CFGR_PRESC_2)
213 #define LPTIM_PRESCALER_DIV128 LPTIM_CFGR_PRESC
222 #define LPTIM_OUTPUTPOLARITY_HIGH 0x00000000U
223 #define LPTIM_OUTPUTPOLARITY_LOW LPTIM_CFGR_WAVPOL
231 #define LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION 0x00000000U
232 #define LPTIM_CLOCKSAMPLETIME_2TRANSITIONS LPTIM_CFGR_CKFLT_0
233 #define LPTIM_CLOCKSAMPLETIME_4TRANSITIONS LPTIM_CFGR_CKFLT_1
234 #define LPTIM_CLOCKSAMPLETIME_8TRANSITIONS LPTIM_CFGR_CKFLT
242 #define LPTIM_CLOCKPOLARITY_RISING 0x00000000U
243 #define LPTIM_CLOCKPOLARITY_FALLING LPTIM_CFGR_CKPOL_0
244 #define LPTIM_CLOCKPOLARITY_RISING_FALLING LPTIM_CFGR_CKPOL_1
252 #define LPTIM_TRIGSOURCE_SOFTWARE 0x0000FFFFU
253 #define LPTIM_TRIGSOURCE_0 0x00000000U
254 #define LPTIM_TRIGSOURCE_1 LPTIM_CFGR_TRIGSEL_0
255 #define LPTIM_TRIGSOURCE_2 LPTIM_CFGR_TRIGSEL_1
256 #define LPTIM_TRIGSOURCE_3 (LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_1)
257 #define LPTIM_TRIGSOURCE_4 LPTIM_CFGR_TRIGSEL_2
258 #define LPTIM_TRIGSOURCE_5 (LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_2)
266 #define LPTIM_ACTIVEEDGE_RISING LPTIM_CFGR_TRIGEN_0
267 #define LPTIM_ACTIVEEDGE_FALLING LPTIM_CFGR_TRIGEN_1
268 #define LPTIM_ACTIVEEDGE_RISING_FALLING LPTIM_CFGR_TRIGEN
276 #define LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION 0x00000000U
277 #define LPTIM_TRIGSAMPLETIME_2TRANSITIONS LPTIM_CFGR_TRGFLT_0
278 #define LPTIM_TRIGSAMPLETIME_4TRANSITIONS LPTIM_CFGR_TRGFLT_1
279 #define LPTIM_TRIGSAMPLETIME_8TRANSITIONS LPTIM_CFGR_TRGFLT
288 #define LPTIM_UPDATE_IMMEDIATE 0x00000000U
289 #define LPTIM_UPDATE_ENDOFPERIOD LPTIM_CFGR_PRELOAD
298 #define LPTIM_COUNTERSOURCE_INTERNAL 0x00000000U
299 #define LPTIM_COUNTERSOURCE_EXTERNAL LPTIM_CFGR_COUNTMODE
308 #define LPTIM_FLAG_DOWN LPTIM_ISR_DOWN
309 #define LPTIM_FLAG_UP LPTIM_ISR_UP
310 #define LPTIM_FLAG_ARROK LPTIM_ISR_ARROK
311 #define LPTIM_FLAG_CMPOK LPTIM_ISR_CMPOK
312 #define LPTIM_FLAG_EXTTRIG LPTIM_ISR_EXTTRIG
313 #define LPTIM_FLAG_ARRM LPTIM_ISR_ARRM
314 #define LPTIM_FLAG_CMPM LPTIM_ISR_CMPM
322 #define LPTIM_IT_DOWN LPTIM_IER_DOWNIE
323 #define LPTIM_IT_UP LPTIM_IER_UPIE
324 #define LPTIM_IT_ARROK LPTIM_IER_ARROKIE
325 #define LPTIM_IT_CMPOK LPTIM_IER_CMPOKIE
326 #define LPTIM_IT_EXTTRIG LPTIM_IER_EXTTRIGIE
327 #define LPTIM_IT_ARRM LPTIM_IER_ARRMIE
328 #define LPTIM_IT_CMPM LPTIM_IER_CMPMIE
336 #define LPTIM_OP_PAD_AF 0x00000000U
337 #define LPTIM_OP_PAD_PA4 LPTIM_OR_LPT_IN1_RMP_0
338 #define LPTIM_OP_PAD_PB9 LPTIM_OR_LPT_IN1_RMP_1
339 #define LPTIM_OP_TIM_DAC LPTIM_OR_LPT_IN1_RMP
357 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
358 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) do { \
359 (__HANDLE__)->State = HAL_LPTIM_STATE_RESET; \
360 (__HANDLE__)->MspInitCallback = NULL; \
361 (__HANDLE__)->MspDeInitCallback = NULL; \
364 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_LPTIM_STATE_RESET)
372 #define __HAL_LPTIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (LPTIM_CR_ENABLE))
384 #define __HAL_LPTIM_DISABLE(__HANDLE__) LPTIM_Disable(__HANDLE__)
391 #define __HAL_LPTIM_START_CONTINUOUS(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_CNTSTRT)
397 #define __HAL_LPTIM_START_SINGLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_SNGSTRT)
406 #define __HAL_LPTIM_AUTORELOAD_SET(__HANDLE__ , __VALUE__) ((__HANDLE__)->Instance->ARR = (__VALUE__))
415 #define __HAL_LPTIM_COMPARE_SET(__HANDLE__ , __VALUE__) ((__HANDLE__)->Instance->CMP = (__VALUE__))
431 #define __HAL_LPTIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR &(__FLAG__)) == (__FLAG__))
447 #define __HAL_LPTIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
464 #define __HAL_LPTIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
481 #define __HAL_LPTIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__)))
498 #define __HAL_LPTIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
509 #define __HAL_LPTIM_OPTR_CONFIG(__HANDLE__ , __VALUE__) ((__HANDLE__)->Instance->OR = (__VALUE__))
516 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT() (EXTI->IMR |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
522 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT() (EXTI->IMR &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
528 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_EVENT() (EXTI->EMR |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
534 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_EVENT() (EXTI->EMR &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
535 #if defined(EXTI_IMR_MR23)
541 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE() (EXTI->FTSR |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
547 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE() (EXTI->FTSR &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
553 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE() (EXTI->RTSR |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
559 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE() (EXTI->RTSR &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
565 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE() do{__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();\
566 __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE();\
573 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE() do{__HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();\
574 __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE();\
581 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_GET_FLAG() (EXTI->PR & LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
587 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG() (EXTI->PR = LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
593 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_GENERATE_SWIT() (EXTI->SWIER |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
614 void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim);
615 void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim);
627 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
630 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
635 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
638 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
643 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
646 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
651 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
654 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
659 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout);
662 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout);
667 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
670 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
681 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim);
682 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim);
683 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim);
693 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim);
696 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim);
697 void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim);
698 void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim);
699 void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim);
700 void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim);
701 void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim);
702 void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim);
705 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
706 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID, pLPTIM_CallbackTypeDef pCallback);
707 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID);
718 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim);
759 #define IS_LPTIM_CLOCK_SOURCE(__SOURCE__) (((__SOURCE__) == LPTIM_CLOCKSOURCE_ULPTIM) || \
760 ((__SOURCE__) == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC))
763 #define IS_LPTIM_CLOCK_PRESCALER(__PRESCALER__) (((__PRESCALER__) == LPTIM_PRESCALER_DIV1 ) || \
764 ((__PRESCALER__) == LPTIM_PRESCALER_DIV2 ) || \
765 ((__PRESCALER__) == LPTIM_PRESCALER_DIV4 ) || \
766 ((__PRESCALER__) == LPTIM_PRESCALER_DIV8 ) || \
767 ((__PRESCALER__) == LPTIM_PRESCALER_DIV16 ) || \
768 ((__PRESCALER__) == LPTIM_PRESCALER_DIV32 ) || \
769 ((__PRESCALER__) == LPTIM_PRESCALER_DIV64 ) || \
770 ((__PRESCALER__) == LPTIM_PRESCALER_DIV128))
772 #define IS_LPTIM_CLOCK_PRESCALERDIV1(__PRESCALER__) ((__PRESCALER__) == LPTIM_PRESCALER_DIV1)
774 #define IS_LPTIM_OUTPUT_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_OUTPUTPOLARITY_LOW ) || \
775 ((__POLARITY__) == LPTIM_OUTPUTPOLARITY_HIGH))
777 #define IS_LPTIM_CLOCK_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION) || \
778 ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_2TRANSITIONS) || \
779 ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_4TRANSITIONS) || \
780 ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_8TRANSITIONS))
782 #define IS_LPTIM_CLOCK_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING) || \
783 ((__POLARITY__) == LPTIM_CLOCKPOLARITY_FALLING) || \
784 ((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING_FALLING))
786 #define IS_LPTIM_TRG_SOURCE(__TRIG__) (((__TRIG__) == LPTIM_TRIGSOURCE_SOFTWARE) || \
787 ((__TRIG__) == LPTIM_TRIGSOURCE_0) || \
788 ((__TRIG__) == LPTIM_TRIGSOURCE_1) || \
789 ((__TRIG__) == LPTIM_TRIGSOURCE_2) || \
790 ((__TRIG__) == LPTIM_TRIGSOURCE_3) || \
791 ((__TRIG__) == LPTIM_TRIGSOURCE_4) || \
792 ((__TRIG__) == LPTIM_TRIGSOURCE_5))
794 #define IS_LPTIM_EXT_TRG_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING ) || \
795 ((__POLARITY__) == LPTIM_ACTIVEEDGE_FALLING ) || \
796 ((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING_FALLING ))
798 #define IS_LPTIM_TRIG_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION) || \
799 ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_2TRANSITIONS ) || \
800 ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_4TRANSITIONS ) || \
801 ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_8TRANSITIONS ))
803 #define IS_LPTIM_UPDATE_MODE(__MODE__) (((__MODE__) == LPTIM_UPDATE_IMMEDIATE) || \
804 ((__MODE__) == LPTIM_UPDATE_ENDOFPERIOD))
806 #define IS_LPTIM_COUNTER_SOURCE(__SOURCE__) (((__SOURCE__) == LPTIM_COUNTERSOURCE_INTERNAL) || \
807 ((__SOURCE__) == LPTIM_COUNTERSOURCE_EXTERNAL))
809 #define IS_LPTIM_AUTORELOAD(__AUTORELOAD__) ((__AUTORELOAD__) <= 0x0000FFFFUL)
811 #define IS_LPTIM_COMPARE(__COMPARE__) ((__COMPARE__) <= 0x0000FFFFUL)
813 #define IS_LPTIM_PERIOD(__PERIOD__) ((__PERIOD__) <= 0x0000FFFFUL)
815 #define IS_LPTIM_PULSE(__PULSE__) ((__PULSE__) <= 0x0000FFFFUL)
825 void LPTIM_Disable(LPTIM_HandleTypeDef *hlptim);