stm32f4xx_lptim.h 17 KB

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