stm8l15x_tim2.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_tim2.h
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file contains all the functions prototypes for the TIM2 firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 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 __STM8L15x_TIM2_H
  30. #define __STM8L15x_TIM2_H
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "stm8l15x.h"
  33. /** @addtogroup STM8L15x_StdPeriph_Driver
  34. * @{
  35. */
  36. /** @addtogroup TIM2
  37. * @{
  38. */
  39. /* Exported types ------------------------------------------------------------*/
  40. /** @defgroup TIM2_Exported_Types
  41. * @{
  42. */
  43. /** @defgroup TIM2_Forced_Action
  44. * @{
  45. */
  46. typedef enum
  47. {
  48. TIM2_ForcedAction_Active = ((uint8_t)0x50), /*!< Output Reference is forced low */
  49. TIM2_ForcedAction_Inactive = ((uint8_t)0x40) /*!< Output Reference is forced high */
  50. }
  51. TIM2_ForcedAction_TypeDef;
  52. /**
  53. * @}
  54. */
  55. /** @defgroup TIM2_Prescaler
  56. * @{
  57. */
  58. typedef enum
  59. {
  60. TIM2_Prescaler_1 = ((uint8_t)0x00), /*!< Time base Prescaler = 1 (No effect)*/
  61. TIM2_Prescaler_2 = ((uint8_t)0x01), /*!< Time base Prescaler = 2 */
  62. TIM2_Prescaler_4 = ((uint8_t)0x02), /*!< Time base Prescaler = 4 */
  63. TIM2_Prescaler_8 = ((uint8_t)0x03), /*!< Time base Prescaler = 8 */
  64. TIM2_Prescaler_16 = ((uint8_t)0x04), /*!< Time base Prescaler = 16 */
  65. TIM2_Prescaler_32 = ((uint8_t)0x05), /*!< Time base Prescaler = 32 */
  66. TIM2_Prescaler_64 = ((uint8_t)0x06), /*!< Time base Prescaler = 64 */
  67. TIM2_Prescaler_128 = ((uint8_t)0x07) /*!< Time base Prescaler = 128 */
  68. }TIM2_Prescaler_TypeDef;
  69. /**
  70. * @}
  71. */
  72. /** @defgroup TIM2_OCMode
  73. * @{
  74. */
  75. typedef enum
  76. {
  77. TIM2_OCMode_Timing = ((uint8_t)0x00), /*!< Timing (Frozen) Mode*/
  78. TIM2_OCMode_Active = ((uint8_t)0x10), /*!< Active Mode*/
  79. TIM2_OCMode_Inactive = ((uint8_t)0x20), /*!< Inactive Mode*/
  80. TIM2_OCMode_Toggle = ((uint8_t)0x30), /*!< Toggle Mode*/
  81. TIM2_OCMode_PWM1 = ((uint8_t)0x60), /*!< PWM Mode 1*/
  82. TIM2_OCMode_PWM2 = ((uint8_t)0x70) /*!< PWM Mode 2*/
  83. }TIM2_OCMode_TypeDef;
  84. /**
  85. * @}
  86. */
  87. /** @defgroup TIM2_OnePulseMode
  88. * @{
  89. */
  90. typedef enum
  91. {
  92. TIM2_OPMode_Single = ((uint8_t)0x01), /*!< Single one Pulse mode (OPM Active) */
  93. TIM2_OPMode_Repetitive = ((uint8_t)0x00) /*!< Repetitive Pulse mode (OPM inactive) */
  94. }TIM2_OPMode_TypeDef;
  95. /**
  96. * @}
  97. */
  98. /** @defgroup TIM2_Channel
  99. * @{
  100. */
  101. typedef enum
  102. {
  103. TIM2_Channel_1 = ((uint8_t)0x00), /*!< Channel 1*/
  104. TIM2_Channel_2 = ((uint8_t)0x01) /*!< Channel 2*/
  105. }TIM2_Channel_TypeDef;
  106. /**
  107. * @}
  108. */
  109. /** @defgroup TIM2_CounterMode
  110. * @{
  111. */
  112. typedef enum
  113. {
  114. TIM2_CounterMode_Up = ((uint8_t)0x00), /*!< Counter Up Mode */
  115. TIM2_CounterMode_Down = ((uint8_t)0x10), /*!< Counter Down Mode */
  116. TIM2_CounterMode_CenterAligned1 = ((uint8_t)0x20), /*!< Counter Central aligned Mode 1 */
  117. TIM2_CounterMode_CenterAligned2 = ((uint8_t)0x40), /*!< Counter Central aligned Mode 2 */
  118. TIM2_CounterMode_CenterAligned3 = ((uint8_t)0x60) /*!< Counter Central aligned Mode 3 */
  119. }TIM2_CounterMode_TypeDef;
  120. /**
  121. * @}
  122. */
  123. /** @defgroup TIM2_Output_Compare_Polarity
  124. * @{
  125. */
  126. typedef enum
  127. {
  128. TIM2_OCPolarity_High = ((uint8_t)0x00), /*!< Output compare polarity = High */
  129. TIM2_OCPolarity_Low = ((uint8_t)0x01) /*!< Output compare polarity = Low */
  130. }TIM2_OCPolarity_TypeDef;
  131. /**
  132. * @}
  133. */
  134. /** @defgroup TIM2_Output_State
  135. * @{
  136. */
  137. typedef enum
  138. {
  139. TIM2_OutputState_Disable = ((uint8_t)0x00), /*!< Output compare State disabled (channel output disabled) */
  140. TIM2_OutputState_Enable = ((uint8_t)0x01) /*!< Output compare State enabled (channel output enabled) */
  141. }TIM2_OutputState_TypeDef;
  142. /**
  143. * @}
  144. */
  145. /** @defgroup TIM2_Break_State
  146. * @{
  147. */
  148. typedef enum
  149. {
  150. TIM2_BreakState_Disable = ((uint8_t)0x00), /*!< Break State disabled (break option disabled) */
  151. TIM2_BreakState_Enable = ((uint8_t)0x10) /*!< Break State enabled (break option enabled) */
  152. }TIM2_BreakState_TypeDef;
  153. /**
  154. * @}
  155. */
  156. /** @defgroup TIM2_Break_Polarity
  157. * @{
  158. */
  159. typedef enum
  160. {
  161. TIM2_BreakPolarity_High = ((uint8_t)0x20), /*!< if Break, channel polarity = High */
  162. TIM2_BreakPolarity_Low = ((uint8_t)0x00) /*!< if Break, channel polarity = Low */
  163. }TIM2_BreakPolarity_TypeDef;
  164. /**
  165. * @}
  166. */
  167. /** @defgroup TIM2_Automatic_Output
  168. * @{
  169. */
  170. typedef enum
  171. {
  172. TIM2_AutomaticOutput_Enable = ((uint8_t)0x40), /*!< Automatic Output option enabled */
  173. TIM2_AutomaticOutput_Disable = ((uint8_t)0x00) /*!< Automatic Output option disabled */
  174. }TIM2_AutomaticOutput_TypeDef;
  175. /**
  176. * @}
  177. */
  178. /** @defgroup TIM2_Lock_Level
  179. * @{
  180. */
  181. typedef enum
  182. {
  183. TIM2_LockLevel_Off = ((uint8_t)0x00), /*!< Lock option disabled */
  184. TIM2_LockLevel_1 = ((uint8_t)0x01), /*!< Select Lock Level 1 */
  185. TIM2_LockLevel_2 = ((uint8_t)0x02), /*!< Select Lock Level 2 */
  186. TIM2_LockLevel_3 = ((uint8_t)0x03) /*!< Select Lock Level 3 */
  187. }TIM2_LockLevel_TypeDef;
  188. /**
  189. * @}
  190. */
  191. /** @defgroup TIM2_OSSI_State
  192. * @{
  193. */
  194. typedef enum
  195. {
  196. TIM2_OSSIState_Enable = ((uint8_t)0x04), /*!< Off-State Selection for Idle mode enabled */
  197. TIM2_OSSIState_Disable = ((uint8_t)0x00) /*!< Off-State Selection for Idle mode disabled */
  198. }TIM2_OSSIState_TypeDef;
  199. /**
  200. * @}
  201. */
  202. /** @defgroup TIM2_Output_Compare_Idle_state
  203. * @{
  204. */
  205. typedef enum
  206. {
  207. TIM2_OCIdleState_Reset = ((uint8_t)0x00), /*!< Output Compare Idle state = Reset */
  208. TIM2_OCIdleState_Set = ((uint8_t)0x01) /*!< Output Compare Idle state = Set */
  209. }TIM2_OCIdleState_TypeDef;
  210. /**
  211. * @}
  212. */
  213. /** @defgroup TIM2_Input_Capture_Polarity
  214. * @{
  215. */
  216. typedef enum
  217. {
  218. TIM2_ICPolarity_Rising = ((uint8_t)0x00), /*!< Input Capture on Rising Edge*/
  219. TIM2_ICPolarity_Falling = ((uint8_t)0x01) /*!< Input Capture on Falling Edge*/
  220. }TIM2_ICPolarity_TypeDef;
  221. /**
  222. * @}
  223. */
  224. /** @defgroup TIM2_Input_Capture_Selection
  225. * @{
  226. */
  227. typedef enum
  228. {
  229. TIM2_ICSelection_DirectTI = ((uint8_t)0x01), /*!< Input Capture mapped on the direct input*/
  230. TIM2_ICSelection_IndirectTI = ((uint8_t)0x02), /*!< Input Capture mapped on the indirect input*/
  231. TIM2_ICSelection_TRGI = ((uint8_t)0x03) /*!< Input Capture mapped on the Trigger Input*/
  232. }TIM2_ICSelection_TypeDef;
  233. /**
  234. * @}
  235. */
  236. /** @defgroup TIM2_Input_Capture_Prescaler
  237. * @{
  238. */
  239. typedef enum
  240. {
  241. TIM2_ICPSC_DIV1 = ((uint8_t)0x00), /*!< Input Capture Prescaler = 1 (one capture every 1 event) */
  242. TIM2_ICPSC_DIV2 = ((uint8_t)0x04), /*!< Input Capture Prescaler = 2 (one capture every 2 events) */
  243. TIM2_ICPSC_DIV4 = ((uint8_t)0x08), /*!< Input Capture Prescaler = 4 (one capture every 4 events) */
  244. TIM2_ICPSC_DIV8 = ((uint8_t)0x0C) /*!< Input Capture Prescaler = 8 (one capture every 8 events) */
  245. }TIM2_ICPSC_TypeDef;
  246. /**
  247. * @}
  248. */
  249. /** @defgroup TIM2_Interrupts
  250. * @{
  251. */
  252. typedef enum
  253. {
  254. TIM2_IT_Update = ((uint8_t)0x01), /*!< Update Interrupt*/
  255. TIM2_IT_CC1 = ((uint8_t)0x02), /*!< Capture Compare Channel1 Interrupt*/
  256. TIM2_IT_CC2 = ((uint8_t)0x04), /*!< Capture Compare Channel2 Interrupt*/
  257. TIM2_IT_Trigger = ((uint8_t)0x40), /*!< Trigger Interrupt*/
  258. TIM2_IT_Break = ((uint8_t)0x80) /*!< Break Interrupt*/
  259. }TIM2_IT_TypeDef;
  260. /**
  261. * @}
  262. */
  263. /** @defgroup TIM2_External_Trigger_Prescaler
  264. * @{
  265. */
  266. typedef enum
  267. {
  268. TIM2_ExtTRGPSC_OFF = ((uint8_t)0x00), /*!< No External Trigger prescaler */
  269. TIM2_ExtTRGPSC_DIV2 = ((uint8_t)0x10), /*!< External Trigger prescaler = 2 (ETRP frequency divided by 2) */
  270. TIM2_ExtTRGPSC_DIV4 = ((uint8_t)0x20), /*!< External Trigger prescaler = 4 (ETRP frequency divided by 4) */
  271. TIM2_ExtTRGPSC_DIV8 = ((uint8_t)0x30) /*!< External Trigger prescaler = 8 (ETRP frequency divided by 8) */
  272. }TIM2_ExtTRGPSC_TypeDef;
  273. /**
  274. * @}
  275. */
  276. /** @defgroup TIM2_Internal_Trigger_Selection
  277. * @{
  278. */
  279. typedef enum
  280. {
  281. TIM2_TRGSelection_TIM4 = ((uint8_t)0x00), /*!< TRIG Input source = TIM TRIG Output */
  282. TIM2_TRGSelection_TIM1 = ((uint8_t)0x10), /*!< TRIG Input source = TIM TRIG Output */
  283. TIM2_TRGSelection_TIM3 = ((uint8_t)0x20), /*!< TRIG Input source = TIM TRIG Output */
  284. TIM2_TRGSelection_TIM5 = ((uint8_t)0x30), /*!< TRIG Input source = TIM TRIG Output */
  285. TIM2_TRGSelection_TI1F_ED = ((uint8_t)0x40), /*!< TRIG Input source = TI1F_ED (TI1 Edge Detector) */
  286. TIM2_TRGSelection_TI1FP1 = ((uint8_t)0x50), /*!< TRIG Input source = TI1FP1 (Filtered Timer Input 1) */
  287. TIM2_TRGSelection_TI2FP2 = ((uint8_t)0x60), /*!< TRIG Input source = TI2FP2 (Filtered Timer Input 2) */
  288. TIM2_TRGSelection_ETRF = ((uint8_t)0x70) /*!< TRIG Input source = ETRF (External Trigger Input ) */
  289. }TIM2_TRGSelection_TypeDef;
  290. /**
  291. * @}
  292. */
  293. /** @defgroup TIM2_TI_External_Clock_Source
  294. * @{
  295. */
  296. typedef enum
  297. {
  298. TIM2_TIxExternalCLK1Source_TI1ED = ((uint8_t)0x40), /*!< External Clock mode 1 source = TI1ED */
  299. TIM2_TIxExternalCLK1Source_TI1 = ((uint8_t)0x50), /*!< External Clock mode 1 source = TI1 */
  300. TIM2_TIxExternalCLK1Source_TI2 = ((uint8_t)0x60) /*!< External Clock mode 1 source = TI2 */
  301. }TIM2_TIxExternalCLK1Source_TypeDef;
  302. /**
  303. * @}
  304. */
  305. /** @defgroup TIM2_External_Trigger_Polarity
  306. * @{
  307. */
  308. typedef enum
  309. {
  310. TIM2_ExtTRGPolarity_Inverted = ((uint8_t)0x80), /*!< External Trigger Polarity = inverted */
  311. TIM2_ExtTRGPolarity_NonInverted = ((uint8_t)0x00) /*!< External Trigger Polarity = non inverted */
  312. }TIM2_ExtTRGPolarity_TypeDef;
  313. /**
  314. * @}
  315. */
  316. /** @defgroup TIM2_Prescaler_Reload_Mode
  317. * @{
  318. */
  319. typedef enum
  320. {
  321. TIM2_PSCReloadMode_Update = ((uint8_t)0x00), /*!< Prescaler value is reloaded at every update*/
  322. TIM2_PSCReloadMode_Immediate = ((uint8_t)0x01) /*!< Prescaler value is reloaded immediatly*/
  323. }TIM2_PSCReloadMode_TypeDef;
  324. /**
  325. * @}
  326. */
  327. /** @defgroup TIM2_Encoder_Mode
  328. * @{
  329. */
  330. typedef enum
  331. {
  332. TIM2_EncoderMode_TI1 = ((uint8_t)0x01), /*!< Encoder mode 1*/
  333. TIM2_EncoderMode_TI2 = ((uint8_t)0x02), /*!< Encoder mode 2*/
  334. TIM2_EncoderMode_TI12 = ((uint8_t)0x03) /*!< Encoder mode 3*/
  335. }TIM2_EncoderMode_TypeDef;
  336. /**
  337. * @}
  338. */
  339. /** @defgroup TIM2_Event_Source
  340. * @{
  341. */
  342. typedef enum
  343. {
  344. TIM2_EventSource_Update = ((uint8_t)0x01), /*!< Update Event*/
  345. TIM2_EventSource_CC1 = ((uint8_t)0x02), /*!< Capture Compare Channel1 Event*/
  346. TIM2_EventSource_CC2 = ((uint8_t)0x04), /*!< Capture Compare Channel2 Event*/
  347. TIM2_EventSource_Trigger = ((uint8_t)0x40), /*!< Trigger Event*/
  348. TIM2_EventSource_Break = ((uint8_t)0x80) /*!< Break Event*/
  349. }TIM2_EventSource_TypeDef;
  350. /**
  351. * @}
  352. */
  353. /** @defgroup TIM2_Update_Source
  354. * @{
  355. */
  356. typedef enum
  357. {
  358. TIM2_UpdateSource_Global = ((uint8_t)0x00), /*!< Global Update request source */
  359. TIM2_UpdateSource_Regular = ((uint8_t)0x01) /*!< Regular Update request source */
  360. }TIM2_UpdateSource_TypeDef;
  361. /**
  362. * @}
  363. */
  364. /** @defgroup TIM2_Trigger_Output_Source
  365. * @{
  366. */
  367. typedef enum
  368. {
  369. TIM2_TRGOSource_Reset = ((uint8_t)0x00), /*!< Trigger Output source = Reset*/
  370. TIM2_TRGOSource_Enable = ((uint8_t)0x10), /*!< Trigger Output source = TIM2 is enabled*/
  371. TIM2_TRGOSource_Update = ((uint8_t)0x20), /*!< Trigger Output source = Update event*/
  372. TIM2_TRGOSource_OC1 = ((uint8_t)0x30), /*!< Trigger Output source = output compare channel1 */
  373. TIM2_TRGOSource_OC1REF = ((uint8_t)0x40), /*!< Trigger Output source = output compare channel 1 reference */
  374. TIM2_TRGOSource_OC2REF = ((uint8_t)0x50) /*!< Trigger Output source = output compare channel 2 reference */
  375. }TIM2_TRGOSource_TypeDef;
  376. /**
  377. * @}
  378. */
  379. /** @defgroup TIM2_Slave_Mode
  380. * @{
  381. */
  382. typedef enum
  383. {
  384. TIM2_SlaveMode_Reset = ((uint8_t)0x04), /*!< Slave Mode Selection = Reset*/
  385. TIM2_SlaveMode_Gated = ((uint8_t)0x05), /*!< Slave Mode Selection = Gated*/
  386. TIM2_SlaveMode_Trigger = ((uint8_t)0x06), /*!< Slave Mode Selection = Trigger*/
  387. TIM2_SlaveMode_External1 = ((uint8_t)0x07) /*!< Slave Mode Selection = External 1*/
  388. }TIM2_SlaveMode_TypeDef;
  389. /**
  390. * @}
  391. */
  392. /** @defgroup TIM2_Flags
  393. * @{
  394. */
  395. typedef enum
  396. {
  397. TIM2_FLAG_Update = ((uint16_t)0x0001), /*!< Update Flag */
  398. TIM2_FLAG_CC1 = ((uint16_t)0x0002), /*!< Capture compare 1 Flag */
  399. TIM2_FLAG_CC2 = ((uint16_t)0x0004), /*!< Capture compare 2 Flag */
  400. TIM2_FLAG_Trigger = ((uint16_t)0x0040), /*!< Trigger Flag */
  401. TIM2_FLAG_Break = ((uint16_t)0x0080), /*!< Break Flag */
  402. TIM2_FLAG_CC1OF = ((uint16_t)0x0200), /*!< Capture compare 1 over capture Flag */
  403. TIM2_FLAG_CC2OF = ((uint16_t)0x0400) /*!< Capture compare 2 over capture Flag */
  404. }TIM2_FLAG_TypeDef;
  405. /**
  406. * @}
  407. */
  408. /** @defgroup TIM2_DMA_Source_Requests
  409. * @{
  410. */
  411. typedef enum
  412. {
  413. TIM2_DMASource_Update = ((uint8_t)0x01), /*!< TIM2 DMA Update Request*/
  414. TIM2_DMASource_CC1 = ((uint8_t)0x02), /*!< TIM2 DMA CC1 Request*/
  415. TIM2_DMASource_CC2 = ((uint8_t)0x04) /*!< TIM2 DMA CC2 Request*/
  416. }TIM2_DMASource_TypeDef;
  417. /**
  418. * @}
  419. */
  420. /**
  421. * @}
  422. */
  423. /* Exported constants --------------------------------------------------------*/
  424. /* Exported macros -----------------------------------------------------------*/
  425. /** @defgroup TIM2_Exported_Macros
  426. * @{
  427. */
  428. /**
  429. * @brief Macro used by the assert function to check the different functions parameters.
  430. */
  431. /**
  432. * @brief Macro TIM2 Forced Action
  433. */
  434. #define IS_TIM2_FORCED_ACTION(ACTION) \
  435. (((ACTION) == TIM2_ForcedAction_Active) || \
  436. ((ACTION) == TIM2_ForcedAction_Inactive))
  437. /**
  438. * @brief Macro TIM2 Prescaler
  439. */
  440. #define IS_TIM2_PRESCALER(PRESCALER) \
  441. (((PRESCALER) == TIM2_Prescaler_1) || \
  442. ((PRESCALER) == TIM2_Prescaler_2) || \
  443. ((PRESCALER) == TIM2_Prescaler_4) || \
  444. ((PRESCALER) == TIM2_Prescaler_8) || \
  445. ((PRESCALER) == TIM2_Prescaler_16) || \
  446. ((PRESCALER) == TIM2_Prescaler_32) || \
  447. ((PRESCALER) == TIM2_Prescaler_64) || \
  448. ((PRESCALER) == TIM2_Prescaler_128))
  449. /**
  450. * @brief Macro TIM2 Output Compare and PWM modes
  451. */
  452. #define IS_TIM2_OC_MODE(MODE) \
  453. (((MODE) == TIM2_OCMode_Timing) || \
  454. ((MODE) == TIM2_OCMode_Active) || \
  455. ((MODE) == TIM2_OCMode_Inactive) || \
  456. ((MODE) == TIM2_OCMode_Toggle) || \
  457. ((MODE) == TIM2_OCMode_PWM1) || \
  458. ((MODE) == TIM2_OCMode_PWM2))
  459. #define IS_TIM2_OCM(MODE) \
  460. (((MODE) == TIM2_OCMode_Timing) || \
  461. ((MODE) == TIM2_OCMode_Active) || \
  462. ((MODE) == TIM2_OCMode_Inactive) || \
  463. ((MODE) == TIM2_OCMode_Toggle) || \
  464. ((MODE) == TIM2_OCMode_PWM1) || \
  465. ((MODE) == TIM2_OCMode_PWM2) || \
  466. ((MODE) == (uint8_t)TIM2_ForcedAction_Active) || \
  467. ((MODE) == (uint8_t)TIM2_ForcedAction_Inactive))
  468. /**
  469. * @brief Macro TIM2 One Pulse Mode
  470. */
  471. #define IS_TIM2_OPM_MODE(MODE) \
  472. (((MODE) == TIM2_OPMode_Single) || \
  473. ((MODE) == TIM2_OPMode_Repetitive))
  474. /**
  475. * @brief Macro TIM2 Channel
  476. */
  477. #define IS_TIM2_CHANNEL(CHANNEL) \
  478. (((CHANNEL) == TIM2_Channel_1) || \
  479. ((CHANNEL) == TIM2_Channel_2) )
  480. /**
  481. * @brief Macro TIM2 Counter Mode
  482. */
  483. #define IS_TIM2_COUNTER_MODE(MODE) \
  484. (((MODE) == TIM2_CounterMode_Up) || \
  485. ((MODE) == TIM2_CounterMode_Down) || \
  486. ((MODE) == TIM2_CounterMode_CenterAligned1) || \
  487. ((MODE) == TIM2_CounterMode_CenterAligned2) || \
  488. ((MODE) == TIM2_CounterMode_CenterAligned3))
  489. /**
  490. * @brief Macro TIM2 Output Compare Polarity
  491. */
  492. #define IS_TIM2_OC_POLARITY(POLARITY) \
  493. (((POLARITY) == TIM2_OCPolarity_High) || \
  494. ((POLARITY) == TIM2_OCPolarity_Low))
  495. /**
  496. * @brief Macro TIM2 Output Compare states
  497. */
  498. #define IS_TIM2_OUTPUT_STATE(STATE) \
  499. (((STATE) == TIM2_OutputState_Disable) || \
  500. ((STATE) == TIM2_OutputState_Enable))
  501. /**
  502. * @brief Macro Break Input enable/disable
  503. */
  504. #define IS_TIM2_BREAK_STATE(STATE) \
  505. (((STATE) == TIM2_BreakState_Enable) || \
  506. ((STATE) == TIM2_BreakState_Disable))
  507. /**
  508. * @brief Macro Break Polarity
  509. */
  510. #define IS_TIM2_BREAK_POLARITY(POLARITY) \
  511. (((POLARITY) == TIM2_BreakPolarity_Low) || \
  512. ((POLARITY) == TIM2_BreakPolarity_High))
  513. /**
  514. * @brief Macro TIM2 AOE Bit Set/Reset
  515. */
  516. #define IS_TIM2_AUTOMATIC_OUTPUT_STATE(STATE) \
  517. (((STATE) == TIM2_AutomaticOutput_Enable) || \
  518. ((STATE) == TIM2_AutomaticOutput_Disable))
  519. /**
  520. * @brief Macro Lock levels
  521. */
  522. #define IS_TIM2_LOCK_LEVEL(LEVEL) \
  523. (((LEVEL) == TIM2_LockLevel_Off) || \
  524. ((LEVEL) == TIM2_LockLevel_1) || \
  525. ((LEVEL) == TIM2_LockLevel_2) || \
  526. ((LEVEL) == TIM2_LockLevel_3))
  527. /**
  528. * @brief Macro OSSI: Off-State Selection for Idle mode states
  529. */
  530. #define IS_TIM2_OSSI_STATE(STATE) \
  531. (((STATE) == TIM2_OSSIState_Enable) || \
  532. ((STATE) == TIM2_OSSIState_Disable))
  533. /**
  534. * @brief Macro TIM2 OC IDLE STATE
  535. */
  536. #define IS_TIM2_OCIDLE_STATE(STATE) \
  537. (((STATE) == TIM2_OCIdleState_Set) || \
  538. ((STATE) == TIM2_OCIdleState_Reset))
  539. /**
  540. * @brief Macro TIM2 IC POLARITY
  541. */
  542. #define IS_TIM2_IC_POLARITY(POLARITY) \
  543. (((POLARITY) == TIM2_ICPolarity_Rising) || \
  544. ((POLARITY) == TIM2_ICPolarity_Falling))
  545. /**
  546. * @brief Macro TIM2 IC SELECTION
  547. */
  548. #define IS_TIM2_IC_SELECTION(SELECTION) \
  549. (((SELECTION) == TIM2_ICSelection_DirectTI) || \
  550. ((SELECTION) == TIM2_ICSelection_IndirectTI) || \
  551. ((SELECTION) == TIM2_ICSelection_TRGI))
  552. /**
  553. * @brief Macro TIM2 IC PRESCALER
  554. */
  555. #define IS_TIM2_IC_PRESCALER(PRESCALER) \
  556. (((PRESCALER) == TIM2_ICPSC_DIV1) || \
  557. ((PRESCALER) == TIM2_ICPSC_DIV2) || \
  558. ((PRESCALER) == TIM2_ICPSC_DIV4) || \
  559. ((PRESCALER) == TIM2_ICPSC_DIV8))
  560. /**
  561. * @brief Macro TIM2 Input Capture Filter Value
  562. */
  563. #define IS_TIM2_IC_FILTER(ICFILTER) \
  564. ((ICFILTER) <= 0x0F)
  565. /**
  566. * @brief Macro TIM2 Interrupts
  567. */
  568. #define IS_TIM2_IT(IT) \
  569. ((IT) != 0x00)
  570. #define IS_TIM2_GET_IT(IT) \
  571. (((IT) == TIM2_IT_Update) || \
  572. ((IT) == TIM2_IT_CC1) || \
  573. ((IT) == TIM2_IT_CC2) || \
  574. ((IT) == TIM2_IT_Trigger) || \
  575. ((IT) == TIM2_IT_Break))
  576. /**
  577. * @brief Macro TIM2 external trigger prescaler
  578. */
  579. #define IS_TIM2_EXT_PRESCALER(PRESCALER) \
  580. (((PRESCALER) == TIM2_ExtTRGPSC_OFF) || \
  581. ((PRESCALER) == TIM2_ExtTRGPSC_DIV2) || \
  582. ((PRESCALER) == TIM2_ExtTRGPSC_DIV4) || \
  583. ((PRESCALER) == TIM2_ExtTRGPSC_DIV8))
  584. /**
  585. * @brief Macro TIM2 Trigger Selection
  586. */
  587. #define IS_TIM2_TRIGGER_SELECTION(SELECTION) \
  588. (((SELECTION) == TIM2_TRGSelection_TIM4) || \
  589. ((SELECTION) == TIM2_TRGSelection_TIM1) || \
  590. ((SELECTION) == TIM2_TRGSelection_TIM3) || \
  591. ((SELECTION) == TIM2_TRGSelection_TIM5) || \
  592. ((SELECTION) == TIM2_TRGSelection_TI1F_ED) || \
  593. ((SELECTION) == TIM2_TRGSelection_TI1FP1) || \
  594. ((SELECTION) == TIM2_TRGSelection_TI2FP2) || \
  595. ((SELECTION) == TIM2_TRGSelection_ETRF))
  596. #define IS_TIM2_TIX_TRIGGER_SELECTION(SELECTION) \
  597. (((SELECTION) == TIM2_TRGSelection_TI1F_ED) || \
  598. ((SELECTION) == TIM2_TRGSelection_TI1FP1) || \
  599. ((SELECTION) == TIM2_TRGSelection_TI2FP2))
  600. /**
  601. * @brief Macro TIM2 TIx external Clock Selection
  602. */
  603. #define IS_TIM2_TIXCLK_SOURCE(SOURCE) \
  604. (((SOURCE) == TIM2_TIxExternalCLK1Source_TI1ED) || \
  605. ((SOURCE) == TIM2_TIxExternalCLK1Source_TI2) || \
  606. ((SOURCE) == TIM2_TIxExternalCLK1Source_TI1))
  607. /**
  608. * @brief Macro TIM2 Trigger Polarity
  609. */
  610. #define IS_TIM2_EXT_POLARITY(POLARITY) \
  611. (((POLARITY) == TIM2_ExtTRGPolarity_Inverted) || \
  612. ((POLARITY) == TIM2_ExtTRGPolarity_NonInverted))
  613. /**
  614. * @brief Macro TIM2 External Trigger Filter
  615. */
  616. #define IS_TIM2_EXT_FILTER(EXTFILTER) \
  617. ((EXTFILTER) <= 0x0F)
  618. /**
  619. * @brief Macro TIM2 Prescaler Reload
  620. */
  621. #define IS_TIM2_PRESCALER_RELOAD(RELOAD) \
  622. (((RELOAD) == TIM2_PSCReloadMode_Update) || \
  623. ((RELOAD) == TIM2_PSCReloadMode_Immediate))
  624. /**
  625. * @brief Macro TIM2 encoder mode
  626. */
  627. #define IS_TIM2_ENCODER_MODE(MODE) \
  628. (((MODE) == TIM2_EncoderMode_TI1) || \
  629. ((MODE) == TIM2_EncoderMode_TI2) || \
  630. ((MODE) == TIM2_EncoderMode_TI12))
  631. /**
  632. * @brief Macro TIM2 event source
  633. */
  634. #define IS_TIM2_EVENT_SOURCE(SOURCE) \
  635. ((((SOURCE) & (uint8_t)0x18) == 0x00) && \
  636. ((SOURCE) != 0x00))
  637. /**
  638. * @brief Macro TIM2 update source
  639. */
  640. #define IS_TIM2_UPDATE_SOURCE(SOURCE) \
  641. (((SOURCE) == TIM2_UpdateSource_Global) || \
  642. ((SOURCE) == TIM2_UpdateSource_Regular))
  643. /**
  644. * @brief Macro TIM2 TRGO source
  645. */
  646. #define IS_TIM2_TRGO_SOURCE(SOURCE) \
  647. (((SOURCE) == TIM2_TRGOSource_Reset) || \
  648. ((SOURCE) == TIM2_TRGOSource_Enable) || \
  649. ((SOURCE) == TIM2_TRGOSource_Update) || \
  650. ((SOURCE) == TIM2_TRGOSource_OC1) || \
  651. ((SOURCE) == TIM2_TRGOSource_OC1REF) || \
  652. ((SOURCE) == TIM2_TRGOSource_OC2REF))
  653. /**
  654. * @brief Macro TIM2 Slave mode
  655. */
  656. #define IS_TIM2_SLAVE_MODE(MODE) \
  657. (((MODE) == TIM2_SlaveMode_Reset) || \
  658. ((MODE) == TIM2_SlaveMode_Gated) || \
  659. ((MODE) == TIM2_SlaveMode_Trigger) || \
  660. ((MODE) == TIM2_SlaveMode_External1))
  661. /**
  662. * @brief Macro TIM2 Flags
  663. */
  664. #define IS_TIM2_GET_FLAG(FLAG) \
  665. (((FLAG) == TIM2_FLAG_Update) || \
  666. ((FLAG) == TIM2_FLAG_CC1) || \
  667. ((FLAG) == TIM2_FLAG_CC2) || \
  668. ((FLAG) == TIM2_FLAG_Trigger) || \
  669. ((FLAG) == TIM2_FLAG_Break) || \
  670. ((FLAG) == TIM2_FLAG_CC1OF) || \
  671. ((FLAG) == TIM2_FLAG_CC2OF))
  672. #define IS_TIM2_CLEAR_FLAG(FLAG) \
  673. ((((FLAG) & (uint16_t)0xE100) == 0x0000) && ((FLAG) != 0x0000))
  674. /**
  675. * @brief Macro TIM2 DMA sources
  676. */
  677. #define IS_TIM2_DMA_SOURCE(SOURCE) \
  678. (((SOURCE) == TIM2_DMASource_Update) || \
  679. ((SOURCE) == TIM2_DMASource_CC1) || \
  680. ((SOURCE) == TIM2_DMASource_CC2))
  681. /**
  682. * @}
  683. */
  684. /* Exported functions ------------------------------------------------------- */
  685. /* TimeBase management ********************************************************/
  686. void TIM2_DeInit(void);
  687. void TIM2_TimeBaseInit(TIM2_Prescaler_TypeDef TIM2_Prescaler,
  688. TIM2_CounterMode_TypeDef TIM2_CounterMode, uint16_t TIM2_Period);
  689. void TIM2_PrescalerConfig(TIM2_Prescaler_TypeDef Prescaler,
  690. TIM2_PSCReloadMode_TypeDef TIM2_PSCReloadMode);
  691. void TIM2_CounterModeConfig(TIM2_CounterMode_TypeDef TIM2_CounterMode);
  692. void TIM2_SetCounter(uint16_t Counter);
  693. void TIM2_SetAutoreload(uint16_t Autoreload);
  694. uint16_t TIM2_GetCounter(void);
  695. TIM2_Prescaler_TypeDef TIM2_GetPrescaler(void);
  696. void TIM2_UpdateDisableConfig(FunctionalState NewState);
  697. void TIM2_UpdateRequestConfig(TIM2_UpdateSource_TypeDef TIM2_UpdateSource);
  698. void TIM2_ARRPreloadConfig(FunctionalState NewState);
  699. void TIM2_SelectOnePulseMode(TIM2_OPMode_TypeDef TIM2_OPMode);
  700. void TIM2_Cmd(FunctionalState NewState);
  701. /* Output Compare management **************************************************/
  702. void TIM2_OC1Init(TIM2_OCMode_TypeDef TIM2_OCMode,
  703. TIM2_OutputState_TypeDef TIM2_OutputState,
  704. uint16_t TIM2_Pulse,
  705. TIM2_OCPolarity_TypeDef TIM2_OCPolarity,
  706. TIM2_OCIdleState_TypeDef TIM2_OCIdleState);
  707. void TIM2_OC2Init(TIM2_OCMode_TypeDef TIM2_OCMode,
  708. TIM2_OutputState_TypeDef TIM2_OutputState,
  709. uint16_t TIM2_Pulse,
  710. TIM2_OCPolarity_TypeDef TIM2_OCPolarity,
  711. TIM2_OCIdleState_TypeDef TIM2_OCIdleState);
  712. void TIM2_BKRConfig(TIM2_OSSIState_TypeDef TIM2_OSSIState,
  713. TIM2_LockLevel_TypeDef TIM2_LockLevel,
  714. TIM2_BreakState_TypeDef TIM2_BreakState,
  715. TIM2_BreakPolarity_TypeDef TIM2_BreakPolarity,
  716. TIM2_AutomaticOutput_TypeDef TIM2_AutomaticOutput);
  717. void TIM2_CtrlPWMOutputs(FunctionalState NewState);
  718. void TIM2_SelectOCxM(TIM2_Channel_TypeDef TIM2_Channel, TIM2_OCMode_TypeDef TIM2_OCMode);
  719. void TIM2_SetCompare1(uint16_t Compare);
  720. void TIM2_SetCompare2(uint16_t Compare);
  721. void TIM2_ForcedOC1Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction);
  722. void TIM2_ForcedOC2Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction);
  723. void TIM2_OC1PreloadConfig(FunctionalState NewState);
  724. void TIM2_OC2PreloadConfig(FunctionalState NewState);
  725. void TIM2_OC1FastConfig(FunctionalState NewState);
  726. void TIM2_OC2FastConfig(FunctionalState NewState);
  727. void TIM2_OC1PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  728. void TIM2_OC2PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  729. void TIM2_CCxCmd(TIM2_Channel_TypeDef TIM2_Channel, FunctionalState NewState);
  730. /* Input Capture management ***************************************************/
  731. void TIM2_ICInit(TIM2_Channel_TypeDef TIM2_Channel,
  732. TIM2_ICPolarity_TypeDef TIM2_ICPolarity,
  733. TIM2_ICSelection_TypeDef TIM2_ICSelection,
  734. TIM2_ICPSC_TypeDef TIM2_ICPrescaler,
  735. uint8_t TIM2_ICFilter);
  736. void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel,
  737. TIM2_ICPolarity_TypeDef TIM2_ICPolarity,
  738. TIM2_ICSelection_TypeDef TIM2_ICSelection,
  739. TIM2_ICPSC_TypeDef TIM2_ICPrescaler,
  740. uint8_t TIM2_ICFilter);
  741. uint16_t TIM2_GetCapture1(void);
  742. uint16_t TIM2_GetCapture2(void);
  743. void TIM2_SetIC1Prescaler(TIM2_ICPSC_TypeDef TIM2_IC1Prescaler);
  744. void TIM2_SetIC2Prescaler(TIM2_ICPSC_TypeDef TIM2_IC2Prescaler);
  745. /* Interrupts, DMA and flags management ***************************************/
  746. void TIM2_ITConfig(TIM2_IT_TypeDef TIM2_IT, FunctionalState NewState);
  747. void TIM2_GenerateEvent(TIM2_EventSource_TypeDef TIM2_EventSource);
  748. FlagStatus TIM2_GetFlagStatus(TIM2_FLAG_TypeDef TIM2_FLAG);
  749. void TIM2_ClearFlag(TIM2_FLAG_TypeDef TIM2_FLAG);
  750. ITStatus TIM2_GetITStatus(TIM2_IT_TypeDef TIM2_IT);
  751. void TIM2_ClearITPendingBit(TIM2_IT_TypeDef TIM2_IT);
  752. void TIM2_DMACmd(TIM2_DMASource_TypeDef TIM2_DMASource, FunctionalState NewState);
  753. void TIM2_SelectCCDMA(FunctionalState NewState);
  754. /* Clocks management **********************************************************/
  755. void TIM2_InternalClockConfig(void);
  756. void TIM2_TIxExternalClockConfig(TIM2_TIxExternalCLK1Source_TypeDef TIM2_TIxExternalCLKSource,
  757. TIM2_ICPolarity_TypeDef TIM2_ICPolarity,
  758. uint8_t ICFilter);
  759. void TIM2_ETRClockMode1Config(TIM2_ExtTRGPSC_TypeDef TIM2_ExtTRGPrescaler,
  760. TIM2_ExtTRGPolarity_TypeDef TIM2_ExtTRGPolarity,
  761. uint8_t ExtTRGFilter);
  762. void TIM2_ETRClockMode2Config(TIM2_ExtTRGPSC_TypeDef TIM2_ExtTRGPrescaler,
  763. TIM2_ExtTRGPolarity_TypeDef TIM2_ExtTRGPolarity,
  764. uint8_t ExtTRGFilter);
  765. /* Synchronization management *************************************************/
  766. void TIM2_SelectInputTrigger(TIM2_TRGSelection_TypeDef TIM2_InputTriggerSource);
  767. void TIM2_SelectOutputTrigger(TIM2_TRGOSource_TypeDef TIM2_TRGOSource);
  768. void TIM2_SelectSlaveMode(TIM2_SlaveMode_TypeDef TIM2_SlaveMode);
  769. void TIM2_SelectMasterSlaveMode(FunctionalState NewState);
  770. void TIM2_ETRConfig(TIM2_ExtTRGPSC_TypeDef TIM2_ExtTRGPrescaler,
  771. TIM2_ExtTRGPolarity_TypeDef TIM2_ExtTRGPolarity,
  772. uint8_t ExtTRGFilter);
  773. /* Specific interface management **********************************************/
  774. void TIM2_EncoderInterfaceConfig(TIM2_EncoderMode_TypeDef TIM2_EncoderMode,
  775. TIM2_ICPolarity_TypeDef TIM2_IC1Polarity,
  776. TIM2_ICPolarity_TypeDef TIM2_IC2Polarity);
  777. void TIM2_SelectHallSensor(FunctionalState NewState);
  778. #endif /* __STM8L15x_TIM2_H */
  779. /**
  780. * @}
  781. */
  782. /**
  783. * @}
  784. */
  785. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/