stm32f4xx_lptim.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_lptim.h
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  7. * @brief This file contains all the functions prototypes for the LPTIM
  8. * firmware library
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * Copyright (c) 2016 STMicroelectronics.
  13. * All rights reserved.
  14. *
  15. * This software is licensed under terms that can be found in the LICENSE file
  16. * in the root directory of this software component.
  17. * If no LICENSE file comes with this software, it is provided AS-IS.
  18. *
  19. ******************************************************************************
  20. */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __STM32F4XX_LPTIM_H
  23. #define __STM32F4XX_LPTIM_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32f4xx.h"
  29. /** @addtogroup STM32F4xx_StdPeriph_Driver
  30. * @{
  31. */
  32. /** @addtogroup LPTIM
  33. * @{
  34. */
  35. #if defined(STM32F410xx) || defined(STM32F413_423xx)
  36. /* Exported types ------------------------------------------------------------*/
  37. /**
  38. * @brief LPTIM Init structure definition
  39. * @note
  40. */
  41. typedef struct
  42. {
  43. uint32_t LPTIM_ClockSource; /*!< Selects the clock source.
  44. This parameter can be a value of @ref LPTIM_Clock_Source */
  45. uint32_t LPTIM_Prescaler; /*!< Specifies the timer clock Prescaler.
  46. This parameter can be a value of @ref LPTIM_Clock_Prescaler */
  47. uint32_t LPTIM_Waveform; /*!< Selects the output shape.
  48. This parameter can be a value of @ref LPTIM_Waveform_Shape */
  49. uint32_t LPTIM_OutputPolarity; /*!< Specifies the LPTIM Output pin polarity.
  50. This parameter can be a value of @ref LPTIM_Output_Polarity */
  51. }LPTIM_InitTypeDef;
  52. /* Exported constants --------------------------------------------------------*/
  53. /** @defgroup LPTIM_Exported_Constants
  54. * @{
  55. */
  56. #define IS_LPTIM_ALL_PERIPH(PERIPH) ((PERIPH) == LPTIM1)
  57. /** @defgroup LPTIM_Clock_Source LPTIM Clock Source
  58. * @{
  59. */
  60. #define LPTIM_ClockSource_APBClock_LPosc ((uint32_t)0x00000000)
  61. #define LPTIM_ClockSource_ULPTIM ((uint32_t)0x00000001)
  62. #define IS_LPTIM_CLOCK_SOURCE(SOURCE) (((SOURCE) == LPTIM_ClockSource_ULPTIM) || \
  63. ((SOURCE) == LPTIM_ClockSource_APBClock_LPosc))
  64. /**
  65. * @}
  66. */
  67. /** @defgroup LPTIM_Clock_Prescaler LPTIM Clock Prescaler
  68. * @{
  69. */
  70. #define LPTIM_Prescaler_DIV1 ((uint32_t)0x00000000)
  71. #define LPTIM_Prescaler_DIV2 ((uint32_t)0x00000200)
  72. #define LPTIM_Prescaler_DIV4 ((uint32_t)0x00000400)
  73. #define LPTIM_Prescaler_DIV8 ((uint32_t)0x00000600)
  74. #define LPTIM_Prescaler_DIV16 ((uint32_t)0x00000800)
  75. #define LPTIM_Prescaler_DIV32 ((uint32_t)0x00000A00)
  76. #define LPTIM_Prescaler_DIV64 ((uint32_t)0x00000C00)
  77. #define LPTIM_Prescaler_DIV128 ((uint32_t)0x00000E00)
  78. #define IS_LPTIM_CLOCK_PRESCALER(PRESCALER) (((PRESCALER) == LPTIM_Prescaler_DIV1) || \
  79. ((PRESCALER) == LPTIM_Prescaler_DIV2) || \
  80. ((PRESCALER) == LPTIM_Prescaler_DIV4) || \
  81. ((PRESCALER) == LPTIM_Prescaler_DIV8) || \
  82. ((PRESCALER) == LPTIM_Prescaler_DIV16) || \
  83. ((PRESCALER) == LPTIM_Prescaler_DIV32) || \
  84. ((PRESCALER) == LPTIM_Prescaler_DIV64) || \
  85. ((PRESCALER) == LPTIM_Prescaler_DIV128))
  86. /**
  87. * @}
  88. */
  89. /** @defgroup LPTIM_Waveform_Shape LPTIM Waveform Shape
  90. * @{
  91. */
  92. #define LPTIM_Waveform_PWM_OnePulse ((uint32_t)0x00000000)
  93. #define LPTIM_Waveform_SetOnce ((uint32_t)0x00100000)
  94. #define IS_LPTIM_WAVEFORM(WAVE) (((WAVE) == LPTIM_Waveform_SetOnce) || \
  95. ((WAVE) == LPTIM_Waveform_PWM_OnePulse))
  96. /**
  97. * @}
  98. */
  99. /** @defgroup LPTIM_Output_Polarity LPTIM Output Polarity
  100. * @{
  101. */
  102. #define LPTIM_OutputPolarity_High ((uint32_t)0x00000000)
  103. #define LPTIM_OutputPolarity_Low ((uint32_t)0x00200000)
  104. #define IS_LPTIM_OUTPUT_POLARITY(POLARITY) (((POLARITY) == LPTIM_OutputPolarity_Low ) || \
  105. ((POLARITY) == LPTIM_OutputPolarity_High))
  106. /**
  107. * @}
  108. */
  109. /** @defgroup LPTIM_Clock_Polarity LPTIM Clock Polarity
  110. * @{
  111. */
  112. #define LPTIM_ClockPolarity_RisingEdge ((uint32_t)0x00000000)
  113. #define LPTIM_ClockPolarity_FallingEdge ((uint32_t)0x00000002)
  114. #define LPTIM_ClockPolarity_BothEdges ((uint32_t)0x00000004)
  115. #define IS_LPTIM_CLOCK_POLARITY(POLARITY) (((POLARITY) == LPTIM_ClockPolarity_RisingEdge ) || \
  116. ((POLARITY) == LPTIM_ClockPolarity_FallingEdge ) || \
  117. ((POLARITY) == LPTIM_ClockPolarity_BothEdges))
  118. /**
  119. * @}
  120. */
  121. /** @defgroup LPTIM_External_Trigger_Source LPTIM External Trigger Source
  122. * @{
  123. */
  124. #define LPTIM_ExtTRGSource_0 ((uint32_t)0x00000000)
  125. #define LPTIM_ExtTRGSource_1 ((uint32_t)0x00002000)
  126. #define LPTIM_ExtTRGSource_2 ((uint32_t)0x00004000)
  127. #define LPTIM_ExtTRGSource_3 ((uint32_t)0x00006000)
  128. #define LPTIM_ExtTRGSource_4 ((uint32_t)0x00008000)
  129. #define LPTIM_ExtTRGSource_5 ((uint32_t)0x0000A000)
  130. #define LPTIM_ExtTRGSource_6 ((uint32_t)0x0000C000)
  131. #define LPTIM_ExtTRGSource_7 ((uint32_t)0x0000E000)
  132. #define IS_LPTIM_EXT_TRG_SOURCE(TRIG) (((TRIG) == LPTIM_ExtTRGSource_0) || \
  133. ((TRIG) == LPTIM_ExtTRGSource_1) || \
  134. ((TRIG) == LPTIM_ExtTRGSource_2) || \
  135. ((TRIG) == LPTIM_ExtTRGSource_3) || \
  136. ((TRIG) == LPTIM_ExtTRGSource_4) || \
  137. ((TRIG) == LPTIM_ExtTRGSource_5) || \
  138. ((TRIG) == LPTIM_ExtTRGSource_6) || \
  139. ((TRIG) == LPTIM_ExtTRGSource_7))
  140. /**
  141. * @}
  142. */
  143. /** @defgroup LPTIM_External_Trigger_Polarity LPTIM External Trigger Polarity
  144. * @{
  145. */
  146. #define LPTIM_ExtTRGPolarity_RisingEdge ((uint32_t)0x00020000)
  147. #define LPTIM_ExtTRGPolarity_FallingEdge ((uint32_t)0x00040000)
  148. #define LPTIM_ExtTRGPolarity_BothEdges ((uint32_t)0x00060000)
  149. #define IS_LPTIM_EXT_TRG_POLARITY(POLAR) (((POLAR) == LPTIM_ExtTRGPolarity_RisingEdge) || \
  150. ((POLAR) == LPTIM_ExtTRGPolarity_FallingEdge) || \
  151. ((POLAR) == LPTIM_ExtTRGPolarity_BothEdges))
  152. /**
  153. * @}
  154. */
  155. /** @defgroup LPTIM_Clock_Sample_Time LPTIM Clock Sample Time
  156. * @{
  157. */
  158. #define LPTIM_ClockSampleTime_DirectTransistion ((uint32_t)0x00000000)
  159. #define LPTIM_ClockSampleTime_2Transistions ((uint32_t)0x00000008)
  160. #define LPTIM_ClockSampleTime_4Transistions ((uint32_t)0x00000010)
  161. #define LPTIM_ClockSampleTime_8Transistions ((uint32_t)0x00000018)
  162. #define IS_LPTIM_CLOCK_SAMPLE_TIME(SAMPLETIME) (((SAMPLETIME) == LPTIM_ClockSampleTime_DirectTransistion) || \
  163. ((SAMPLETIME) == LPTIM_ClockSampleTime_2Transistions) || \
  164. ((SAMPLETIME) == LPTIM_ClockSampleTime_4Transistions) || \
  165. ((SAMPLETIME) == LPTIM_ClockSampleTime_8Transistions))
  166. /**
  167. * @}
  168. */
  169. /** @defgroup LPTIM_Trigger_Sample_Time LPTIM Trigger Sample Time
  170. * @{
  171. */
  172. #define LPTIM_TrigSampleTime_DirectTransistion ((uint32_t)0x00000000)
  173. #define LPTIM_TrigSampleTime_2Transistions ((uint32_t)0x00000040)
  174. #define LPTIM_TrigSampleTime_4Transistions ((uint32_t)0x00000080)
  175. #define LPTIM_TrigSampleTime_8Transistions ((uint32_t)0x000000C0)
  176. #define IS_LPTIM_TRIG_SAMPLE_TIME(SAMPLETIME) (((SAMPLETIME) == LPTIM_TrigSampleTime_DirectTransistion) || \
  177. ((SAMPLETIME) == LPTIM_TrigSampleTime_2Transistions) || \
  178. ((SAMPLETIME) == LPTIM_TrigSampleTime_4Transistions) || \
  179. ((SAMPLETIME) == LPTIM_TrigSampleTime_8Transistions))
  180. /**
  181. * @}
  182. */
  183. /** @defgroup LPTIM_Operating_Mode LPTIM Operating Mode
  184. * @{
  185. */
  186. #define LPTIM_Mode_Continuous ((uint32_t)0x00000004)
  187. #define LPTIM_Mode_Single ((uint32_t)0x00000002)
  188. #define IS_LPTIM_MODE(MODE) (((MODE) == LPTIM_Mode_Continuous) || \
  189. ((MODE) == LPTIM_Mode_Single))
  190. /**
  191. * @}
  192. */
  193. /** @defgroup LPTIM_Updating_Register LPTIM Updating Register
  194. * @{
  195. */
  196. #define LPTIM_Update_Immediate ((uint32_t)0x00000000)
  197. #define LPTIM_Update_EndOfPeriod ((uint32_t)0x00400000)
  198. #define IS_LPTIM_UPDATE(UPDATE) (((UPDATE) == LPTIM_Update_Immediate) || \
  199. ((UPDATE) == LPTIM_Update_EndOfPeriod))
  200. /**
  201. * @}
  202. */
  203. /** @defgroup LPTIM_Interrupts_Definition LPTIM Interrupts Definition
  204. * @{
  205. */
  206. #define LPTIM_IT_DOWN LPTIM_IER_DOWNIE
  207. #define LPTIM_IT_UP LPTIM_IER_UPIE
  208. #define LPTIM_IT_ARROK LPTIM_IER_ARROKIE
  209. #define LPTIM_IT_CMPOK LPTIM_IER_CMPOKIE
  210. #define LPTIM_IT_EXTTRIG LPTIM_IER_EXTTRIGIE
  211. #define LPTIM_IT_ARRM LPTIM_IER_ARRMIE
  212. #define LPTIM_IT_CMPM LPTIM_IER_CMPMIE
  213. #define IS_LPTIM_IT(IT) (((IT) == LPTIM_IT_DOWN) || \
  214. ((IT) == LPTIM_IT_UP) || \
  215. ((IT) == LPTIM_IT_ARROK) || \
  216. ((IT) == LPTIM_IT_CMPOK) || \
  217. ((IT) == LPTIM_IT_EXTTRIG) || \
  218. ((IT) == LPTIM_IT_ARRM) || \
  219. ((IT) == LPTIM_IT_CMPM))
  220. #define IS_LPTIM_GET_IT(IT) (((IT) == LPTIM_IT_DOWN) || \
  221. ((IT) == LPTIM_IT_UP) || \
  222. ((IT) == LPTIM_IT_ARROK) || \
  223. ((IT) == LPTIM_IT_CMPOK) || \
  224. ((IT) == LPTIM_IT_EXTTRIG) || \
  225. ((IT) == LPTIM_IT_ARRM) || \
  226. ((IT) == LPTIM_IT_CMPM))
  227. /**
  228. * @}
  229. */
  230. /** @defgroup LPTIM_Flag_Definition LPTIM Flag Definition
  231. * @{
  232. */
  233. #define LPTIM_FLAG_DOWN LPTIM_ISR_DOWN
  234. #define LPTIM_FLAG_UP LPTIM_ISR_UP
  235. #define LPTIM_FLAG_ARROK LPTIM_ISR_ARROK
  236. #define LPTIM_FLAG_CMPOK LPTIM_ISR_CMPOK
  237. #define LPTIM_FLAG_EXTTRIG LPTIM_ISR_EXTTRIG
  238. #define LPTIM_FLAG_ARRM LPTIM_ISR_ARRM
  239. #define LPTIM_FLAG_CMPM LPTIM_ISR_CMPM
  240. #define IS_LPTIM_GET_FLAG(FLAG) (((FLAG) == LPTIM_FLAG_DOWN) || \
  241. ((FLAG) == LPTIM_FLAG_UP) || \
  242. ((FLAG) == LPTIM_FLAG_ARROK) || \
  243. ((FLAG) == LPTIM_FLAG_CMPOK) || \
  244. ((FLAG) == LPTIM_FLAG_EXTTRIG) || \
  245. ((FLAG) == LPTIM_FLAG_ARRM) || \
  246. ((FLAG) == LPTIM_FLAG_CMPM))
  247. /**
  248. * @}
  249. */
  250. /** @defgroup LPTIM_Clear_Flag_Definition LPTIM Clear Flag Definition
  251. * @{
  252. */
  253. #define LPTIM_CLEAR_DOWN LPTIM_ICR_DOWNCF
  254. #define LPTIM_CLEAR_UP LPTIM_ICR_UPCF
  255. #define LPTIM_CLEAR_ARROK LPTIM_ICR_ARROKCF
  256. #define LPTIM_CLEAR_CMPOK LPTIM_ICR_CMPOKCF
  257. #define LPTIM_CLEAR_EXTTRIG LPTIM_ICR_EXTTRIGCF
  258. #define LPTIM_CLEAR_ARRM LPTIM_ICR_ARRMCF
  259. #define LPTIM_CLEAR_CMPM LPTIM_ICR_CMPMCF
  260. #define IS_LPTIM_CLEAR_FLAG(CLEARF) (((CLEARF) == LPTIM_CLEAR_DOWN) || \
  261. ((CLEARF) == LPTIM_CLEAR_UP) || \
  262. ((CLEARF) == LPTIM_CLEAR_ARROK) || \
  263. ((CLEARF) == LPTIM_CLEAR_CMPOK) || \
  264. ((CLEARF) == LPTIM_CLEAR_EXTTRIG) || \
  265. ((CLEARF) == LPTIM_CLEAR_ARRM ) || \
  266. ((CLEARF) == LPTIM_CLEAR_CMPM))
  267. /**
  268. * @}
  269. */
  270. /** @defgroup LPTIM_Autorelaod_Value LPTIM Autorelaod Value
  271. * @{
  272. */
  273. #define IS_LPTIM_AUTORELOAD(AUTORELOAD) ((AUTORELOAD) <= 0x0000FFFF)
  274. /**
  275. * @}
  276. */
  277. /** @defgroup LPTIM_Compare_Value LPTIM Compare Value
  278. * @{
  279. */
  280. #define IS_LPTIM_COMPARE(COMPARE) ((COMPARE) <= 0x0000FFFF)
  281. /**
  282. * @}
  283. */
  284. /** @defgroup LPTIM_Option_Register_Definition LPTIM Option Register Definition
  285. * @{
  286. */
  287. #define LPTIM_OP_PAD_AF ((uint32_t)0x00000000)
  288. #define LPTIM_OP_PAD_PA4 LPTIM_OR_OR_0
  289. #define LPTIM_OP_PAD_PB9 LPTIM_OR_OR_1
  290. #define LPTIM_OP_TIM_DAC LPTIM_OR_OR
  291. /**
  292. * @}
  293. */
  294. /**
  295. * @}
  296. */
  297. /* Exported macro ------------------------------------------------------------*/
  298. /* Exported functions ------------------------------------------------------- */
  299. /* Initialization functions ***************************************************/
  300. void LPTIM_DeInit(LPTIM_TypeDef* LPTIMx);
  301. void LPTIM_Init(LPTIM_TypeDef* LPTIMx, LPTIM_InitTypeDef* LPTIM_InitStruct);
  302. void LPTIM_StructInit(LPTIM_InitTypeDef* LPTIM_InitStruct);
  303. /* Configuration functions ****************************************************/
  304. void LPTIM_Cmd(LPTIM_TypeDef* LPTIMx, FunctionalState NewState);
  305. void LPTIM_SelectClockSource(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ClockSource);
  306. void LPTIM_SelectULPTIMClockPolarity(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ClockPolarity);
  307. void LPTIM_ConfigPrescaler(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Prescaler);
  308. void LPTIM_ConfigExternalTrigger(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ExtTRGSource, uint32_t LPTIM_ExtTRGPolarity);
  309. void LPTIM_SelectSoftwareStart(LPTIM_TypeDef* LPTIMx);
  310. void LPTIM_ConfigTriggerGlitchFilter(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_TrigSampleTime);
  311. void LPTIM_ConfigClockGlitchFilter(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_ClockSampleTime);
  312. void LPTIM_SelectOperatingMode(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Mode);
  313. void LPTIM_TimoutCmd(LPTIM_TypeDef* LPTIMx, FunctionalState NewState);
  314. void LPTIM_ConfigWaveform(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Waveform);
  315. void LPTIM_ConfigUpdate(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Update);
  316. void LPTIM_SetAutoreloadValue(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Autoreload);
  317. void LPTIM_SetCompareValue(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_Compare);
  318. void LPTIM_SelectCounterMode(LPTIM_TypeDef* LPTIMx, FunctionalState NewState);
  319. void LPTIM_SelectEncoderMode(LPTIM_TypeDef* LPTIMx, FunctionalState NewState);
  320. void LPTIM_RemapConfig(LPTIM_TypeDef* LPTIMx,uint32_t LPTIM_OPTR);
  321. uint32_t LPTIM_GetCounterValue(LPTIM_TypeDef* LPTIMx);
  322. uint32_t LPTIM_GetAutoreloadValue(LPTIM_TypeDef* LPTIMx);
  323. uint32_t LPTIM_GetCompareValue(LPTIM_TypeDef* LPTIMx);
  324. /* Interrupts and flags management functions **********************************/
  325. void LPTIM_ITConfig(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_IT, FunctionalState NewState);
  326. FlagStatus LPTIM_GetFlagStatus(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_FLAG);
  327. void LPTIM_ClearFlag(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_CLEARF);
  328. ITStatus LPTIM_GetITStatus(LPTIM_TypeDef* LPTIMx, uint32_t LPTIM_IT);
  329. #endif /* STM32F410xx || STM32F413_423xx */
  330. /**
  331. * @}
  332. */
  333. /**
  334. * @}
  335. */
  336. #ifdef __cplusplus
  337. }
  338. #endif
  339. #endif /*__STM32F4xx_LPTIM_H */