stm8s_tim1.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_tim1.h
  4. * @author MCD Application Team
  5. * @version V2.3.0
  6. * @date 16-June-2017
  7. * @brief This file contains all functions prototype and macros for the TIM1 peripheral.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STM8S_TIM1_H
  29. #define __STM8S_TIM1_H
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm8s.h"
  32. /** @addtogroup STM8S_StdPeriph_Driver
  33. * @{
  34. */
  35. /** @addtogroup TIM1_Exported_Types
  36. * @{
  37. */
  38. /** TIM1 Output Compare and PWM modes */
  39. typedef enum
  40. {
  41. TIM1_OCMODE_TIMING = ((uint8_t)0x00),
  42. TIM1_OCMODE_ACTIVE = ((uint8_t)0x10),
  43. TIM1_OCMODE_INACTIVE = ((uint8_t)0x20),
  44. TIM1_OCMODE_TOGGLE = ((uint8_t)0x30),
  45. TIM1_OCMODE_PWM1 = ((uint8_t)0x60),
  46. TIM1_OCMODE_PWM2 = ((uint8_t)0x70)
  47. }TIM1_OCMode_TypeDef;
  48. #define IS_TIM1_OC_MODE_OK(MODE) (((MODE) == TIM1_OCMODE_TIMING) || \
  49. ((MODE) == TIM1_OCMODE_ACTIVE) || \
  50. ((MODE) == TIM1_OCMODE_INACTIVE) || \
  51. ((MODE) == TIM1_OCMODE_TOGGLE)|| \
  52. ((MODE) == TIM1_OCMODE_PWM1) || \
  53. ((MODE) == TIM1_OCMODE_PWM2))
  54. #define IS_TIM1_OCM_OK(MODE)(((MODE) == TIM1_OCMODE_TIMING) || \
  55. ((MODE) == TIM1_OCMODE_ACTIVE) || \
  56. ((MODE) == TIM1_OCMODE_INACTIVE) || \
  57. ((MODE) == TIM1_OCMODE_TOGGLE)|| \
  58. ((MODE) == TIM1_OCMODE_PWM1) || \
  59. ((MODE) == TIM1_OCMODE_PWM2) || \
  60. ((MODE) == (uint8_t)TIM1_FORCEDACTION_ACTIVE) || \
  61. ((MODE) == (uint8_t)TIM1_FORCEDACTION_INACTIVE))
  62. /** TIM1 One Pulse Mode */
  63. typedef enum
  64. {
  65. TIM1_OPMODE_SINGLE = ((uint8_t)0x01),
  66. TIM1_OPMODE_REPETITIVE = ((uint8_t)0x00)
  67. }TIM1_OPMode_TypeDef;
  68. #define IS_TIM1_OPM_MODE_OK(MODE) (((MODE) == TIM1_OPMODE_SINGLE) || \
  69. ((MODE) == TIM1_OPMODE_REPETITIVE))
  70. /** TIM1 Channel */
  71. typedef enum
  72. {
  73. TIM1_CHANNEL_1 = ((uint8_t)0x00),
  74. TIM1_CHANNEL_2 = ((uint8_t)0x01),
  75. TIM1_CHANNEL_3 = ((uint8_t)0x02),
  76. TIM1_CHANNEL_4 = ((uint8_t)0x03)
  77. }TIM1_Channel_TypeDef;
  78. #define IS_TIM1_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM1_CHANNEL_1) || \
  79. ((CHANNEL) == TIM1_CHANNEL_2) || \
  80. ((CHANNEL) == TIM1_CHANNEL_3) || \
  81. ((CHANNEL) == TIM1_CHANNEL_4))
  82. #define IS_TIM1_PWMI_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM1_CHANNEL_1) || \
  83. ((CHANNEL) == TIM1_CHANNEL_2))
  84. #define IS_TIM1_COMPLEMENTARY_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM1_CHANNEL_1) || \
  85. ((CHANNEL) == TIM1_CHANNEL_2) || \
  86. ((CHANNEL) == TIM1_CHANNEL_3))
  87. /** TIM1 Counter Mode */
  88. typedef enum
  89. {
  90. TIM1_COUNTERMODE_UP = ((uint8_t)0x00),
  91. TIM1_COUNTERMODE_DOWN = ((uint8_t)0x10),
  92. TIM1_COUNTERMODE_CENTERALIGNED1 = ((uint8_t)0x20),
  93. TIM1_COUNTERMODE_CENTERALIGNED2 = ((uint8_t)0x40),
  94. TIM1_COUNTERMODE_CENTERALIGNED3 = ((uint8_t)0x60)
  95. }TIM1_CounterMode_TypeDef;
  96. #define IS_TIM1_COUNTER_MODE_OK(MODE) (((MODE) == TIM1_COUNTERMODE_UP) || \
  97. ((MODE) == TIM1_COUNTERMODE_DOWN) || \
  98. ((MODE) == TIM1_COUNTERMODE_CENTERALIGNED1) || \
  99. ((MODE) == TIM1_COUNTERMODE_CENTERALIGNED2) || \
  100. ((MODE) == TIM1_COUNTERMODE_CENTERALIGNED3))
  101. /** TIM1 Output Compare Polarity */
  102. typedef enum
  103. {
  104. TIM1_OCPOLARITY_HIGH = ((uint8_t)0x00),
  105. TIM1_OCPOLARITY_LOW = ((uint8_t)0x22)
  106. }TIM1_OCPolarity_TypeDef;
  107. #define IS_TIM1_OC_POLARITY_OK(POLARITY) (((POLARITY) == TIM1_OCPOLARITY_HIGH) || \
  108. ((POLARITY) == TIM1_OCPOLARITY_LOW))
  109. /** TIM1 Output Compare N Polarity */
  110. typedef enum
  111. {
  112. TIM1_OCNPOLARITY_HIGH = ((uint8_t)0x00),
  113. TIM1_OCNPOLARITY_LOW = ((uint8_t)0x88)
  114. }TIM1_OCNPolarity_TypeDef;
  115. #define IS_TIM1_OCN_POLARITY_OK(POLARITY) (((POLARITY) == TIM1_OCNPOLARITY_HIGH) || \
  116. ((POLARITY) == TIM1_OCNPOLARITY_LOW))
  117. /** TIM1 Output Compare states */
  118. typedef enum
  119. {
  120. TIM1_OUTPUTSTATE_DISABLE = ((uint8_t)0x00),
  121. TIM1_OUTPUTSTATE_ENABLE = ((uint8_t)0x11)
  122. }TIM1_OutputState_TypeDef;
  123. #define IS_TIM1_OUTPUT_STATE_OK(STATE) (((STATE) == TIM1_OUTPUTSTATE_DISABLE) || \
  124. ((STATE) == TIM1_OUTPUTSTATE_ENABLE))
  125. /** TIM1 Output Compare N States */
  126. typedef enum
  127. {
  128. TIM1_OUTPUTNSTATE_DISABLE = ((uint8_t)0x00),
  129. TIM1_OUTPUTNSTATE_ENABLE = ((uint8_t)0x44)
  130. } TIM1_OutputNState_TypeDef;
  131. #define IS_TIM1_OUTPUTN_STATE_OK(STATE) (((STATE) == TIM1_OUTPUTNSTATE_DISABLE) ||\
  132. ((STATE) == TIM1_OUTPUTNSTATE_ENABLE))
  133. /** TIM1 Break Input enable/disable */
  134. typedef enum
  135. {
  136. TIM1_BREAK_ENABLE = ((uint8_t)0x10),
  137. TIM1_BREAK_DISABLE = ((uint8_t)0x00)
  138. }TIM1_BreakState_TypeDef;
  139. #define IS_TIM1_BREAK_STATE_OK(STATE) (((STATE) == TIM1_BREAK_ENABLE) || \
  140. ((STATE) == TIM1_BREAK_DISABLE))
  141. /** TIM1 Break Polarity */
  142. typedef enum
  143. {
  144. TIM1_BREAKPOLARITY_LOW = ((uint8_t)0x00),
  145. TIM1_BREAKPOLARITY_HIGH = ((uint8_t)0x20)
  146. }TIM1_BreakPolarity_TypeDef;
  147. #define IS_TIM1_BREAK_POLARITY_OK(POLARITY) (((POLARITY) == TIM1_BREAKPOLARITY_LOW) || \
  148. ((POLARITY) == TIM1_BREAKPOLARITY_HIGH))
  149. /** TIM1 AOE Bit Set/Reset */
  150. typedef enum
  151. {
  152. TIM1_AUTOMATICOUTPUT_ENABLE = ((uint8_t)0x40),
  153. TIM1_AUTOMATICOUTPUT_DISABLE = ((uint8_t)0x00)
  154. }TIM1_AutomaticOutput_TypeDef;
  155. #define IS_TIM1_AUTOMATIC_OUTPUT_STATE_OK(STATE) (((STATE) == TIM1_AUTOMATICOUTPUT_ENABLE) || \
  156. ((STATE) == TIM1_AUTOMATICOUTPUT_DISABLE))
  157. /** TIM1 Lock levels */
  158. typedef enum
  159. {
  160. TIM1_LOCKLEVEL_OFF = ((uint8_t)0x00),
  161. TIM1_LOCKLEVEL_1 = ((uint8_t)0x01),
  162. TIM1_LOCKLEVEL_2 = ((uint8_t)0x02),
  163. TIM1_LOCKLEVEL_3 = ((uint8_t)0x03)
  164. }TIM1_LockLevel_TypeDef;
  165. #define IS_TIM1_LOCK_LEVEL_OK(LEVEL) (((LEVEL) == TIM1_LOCKLEVEL_OFF) || \
  166. ((LEVEL) == TIM1_LOCKLEVEL_1) || \
  167. ((LEVEL) == TIM1_LOCKLEVEL_2) || \
  168. ((LEVEL) == TIM1_LOCKLEVEL_3))
  169. /** TIM1 OSSI: Off-State Selection for Idle mode states */
  170. typedef enum
  171. {
  172. TIM1_OSSISTATE_ENABLE = ((uint8_t)0x04),
  173. TIM1_OSSISTATE_DISABLE = ((uint8_t)0x00)
  174. }TIM1_OSSIState_TypeDef;
  175. #define IS_TIM1_OSSI_STATE_OK(STATE) (((STATE) == TIM1_OSSISTATE_ENABLE) || \
  176. ((STATE) == TIM1_OSSISTATE_DISABLE))
  177. /** TIM1 Output Compare Idle State */
  178. typedef enum
  179. {
  180. TIM1_OCIDLESTATE_SET = ((uint8_t)0x55),
  181. TIM1_OCIDLESTATE_RESET = ((uint8_t)0x00)
  182. }TIM1_OCIdleState_TypeDef;
  183. #define IS_TIM1_OCIDLE_STATE_OK(STATE) (((STATE) == TIM1_OCIDLESTATE_SET) || \
  184. ((STATE) == TIM1_OCIDLESTATE_RESET))
  185. /** TIM1 Output Compare N Idle State */
  186. typedef enum
  187. {
  188. TIM1_OCNIDLESTATE_SET = ((uint8_t)0x2A),
  189. TIM1_OCNIDLESTATE_RESET = ((uint8_t)0x00)
  190. }TIM1_OCNIdleState_TypeDef;
  191. #define IS_TIM1_OCNIDLE_STATE_OK(STATE) (((STATE) == TIM1_OCNIDLESTATE_SET) || \
  192. ((STATE) == TIM1_OCNIDLESTATE_RESET))
  193. /** TIM1 Input Capture Polarity */
  194. typedef enum
  195. {
  196. TIM1_ICPOLARITY_RISING = ((uint8_t)0x00),
  197. TIM1_ICPOLARITY_FALLING = ((uint8_t)0x01)
  198. }TIM1_ICPolarity_TypeDef;
  199. #define IS_TIM1_IC_POLARITY_OK(POLARITY) (((POLARITY) == TIM1_ICPOLARITY_RISING) || \
  200. ((POLARITY) == TIM1_ICPOLARITY_FALLING))
  201. /** TIM1 Input Capture Selection */
  202. typedef enum
  203. {
  204. TIM1_ICSELECTION_DIRECTTI = ((uint8_t)0x01),
  205. TIM1_ICSELECTION_INDIRECTTI = ((uint8_t)0x02),
  206. TIM1_ICSELECTION_TRGI = ((uint8_t)0x03)
  207. }TIM1_ICSelection_TypeDef;
  208. #define IS_TIM1_IC_SELECTION_OK(SELECTION) (((SELECTION) == TIM1_ICSELECTION_DIRECTTI) || \
  209. ((SELECTION) == TIM1_ICSELECTION_INDIRECTTI) || \
  210. ((SELECTION) == TIM1_ICSELECTION_TRGI))
  211. /** TIM1 Input Capture Prescaler */
  212. typedef enum
  213. {
  214. TIM1_ICPSC_DIV1 = ((uint8_t)0x00),
  215. TIM1_ICPSC_DIV2 = ((uint8_t)0x04),
  216. TIM1_ICPSC_DIV4 = ((uint8_t)0x08),
  217. TIM1_ICPSC_DIV8 = ((uint8_t)0x0C)
  218. }TIM1_ICPSC_TypeDef;
  219. #define IS_TIM1_IC_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM1_ICPSC_DIV1) || \
  220. ((PRESCALER) == TIM1_ICPSC_DIV2) || \
  221. ((PRESCALER) == TIM1_ICPSC_DIV4) || \
  222. ((PRESCALER) == TIM1_ICPSC_DIV8))
  223. /** TIM1 Input Capture Filer Value */
  224. #define IS_TIM1_IC_FILTER_OK(ICFILTER) ((ICFILTER) <= 0x0F)
  225. /** TIM1 External Trigger Filer Value */
  226. #define IS_TIM1_EXT_TRG_FILTER_OK(FILTER) ((FILTER) <= 0x0F)
  227. /** TIM1 interrupt sources */
  228. typedef enum
  229. {
  230. TIM1_IT_UPDATE = ((uint8_t)0x01),
  231. TIM1_IT_CC1 = ((uint8_t)0x02),
  232. TIM1_IT_CC2 = ((uint8_t)0x04),
  233. TIM1_IT_CC3 = ((uint8_t)0x08),
  234. TIM1_IT_CC4 = ((uint8_t)0x10),
  235. TIM1_IT_COM = ((uint8_t)0x20),
  236. TIM1_IT_TRIGGER = ((uint8_t)0x40),
  237. TIM1_IT_BREAK = ((uint8_t)0x80)
  238. }TIM1_IT_TypeDef;
  239. #define IS_TIM1_IT_OK(IT) ((IT) != 0x00)
  240. #define IS_TIM1_GET_IT_OK(IT) (((IT) == TIM1_IT_UPDATE) || \
  241. ((IT) == TIM1_IT_CC1) || \
  242. ((IT) == TIM1_IT_CC2) || \
  243. ((IT) == TIM1_IT_CC3) || \
  244. ((IT) == TIM1_IT_CC4) || \
  245. ((IT) == TIM1_IT_COM) || \
  246. ((IT) == TIM1_IT_TRIGGER) || \
  247. ((IT) == TIM1_IT_BREAK))
  248. /** TIM1 External Trigger Prescaler */
  249. typedef enum
  250. {
  251. TIM1_EXTTRGPSC_OFF = ((uint8_t)0x00),
  252. TIM1_EXTTRGPSC_DIV2 = ((uint8_t)0x10),
  253. TIM1_EXTTRGPSC_DIV4 = ((uint8_t)0x20),
  254. TIM1_EXTTRGPSC_DIV8 = ((uint8_t)0x30)
  255. }TIM1_ExtTRGPSC_TypeDef;
  256. #define IS_TIM1_EXT_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM1_EXTTRGPSC_OFF) || \
  257. ((PRESCALER) == TIM1_EXTTRGPSC_DIV2) || \
  258. ((PRESCALER) == TIM1_EXTTRGPSC_DIV4) || \
  259. ((PRESCALER) == TIM1_EXTTRGPSC_DIV8))
  260. /** TIM1 Internal Trigger Selection */
  261. typedef enum
  262. {
  263. TIM1_TS_TIM6 = ((uint8_t)0x00), /*!< TRIG Input source = TIM6 TRIG Output */
  264. TIM1_TS_TIM5 = ((uint8_t)0x30), /*!< TRIG Input source = TIM5 TRIG Output */
  265. TIM1_TS_TI1F_ED = ((uint8_t)0x40),
  266. TIM1_TS_TI1FP1 = ((uint8_t)0x50),
  267. TIM1_TS_TI2FP2 = ((uint8_t)0x60),
  268. TIM1_TS_ETRF = ((uint8_t)0x70)
  269. }TIM1_TS_TypeDef;
  270. #define IS_TIM1_TRIGGER_SELECTION_OK(SELECTION) (((SELECTION) == TIM1_TS_TI1F_ED) || \
  271. ((SELECTION) == TIM1_TS_TI1FP1) || \
  272. ((SELECTION) == TIM1_TS_TI2FP2) || \
  273. ((SELECTION) == TIM1_TS_ETRF) || \
  274. ((SELECTION) == TIM1_TS_TIM5) || \
  275. ((SELECTION) == TIM1_TS_TIM6))
  276. #define IS_TIM1_TIX_TRIGGER_SELECTION_OK(SELECTION) (((SELECTION) == TIM1_TS_TI1F_ED) || \
  277. ((SELECTION) == TIM1_TS_TI1FP1) || \
  278. ((SELECTION) == TIM1_TS_TI2FP2))
  279. /** TIM1 TIx External Clock Source */
  280. typedef enum
  281. {
  282. TIM1_TIXEXTERNALCLK1SOURCE_TI1ED = ((uint8_t)0x40),
  283. TIM1_TIXEXTERNALCLK1SOURCE_TI1 = ((uint8_t)0x50),
  284. TIM1_TIXEXTERNALCLK1SOURCE_TI2 = ((uint8_t)0x60)
  285. }TIM1_TIxExternalCLK1Source_TypeDef;
  286. #define IS_TIM1_TIXCLK_SOURCE_OK(SOURCE) (((SOURCE) == TIM1_TIXEXTERNALCLK1SOURCE_TI1ED) || \
  287. ((SOURCE) == TIM1_TIXEXTERNALCLK1SOURCE_TI2) || \
  288. ((SOURCE) == TIM1_TIXEXTERNALCLK1SOURCE_TI1))
  289. /** TIM1 External Trigger Polarity */
  290. typedef enum
  291. {
  292. TIM1_EXTTRGPOLARITY_INVERTED = ((uint8_t)0x80),
  293. TIM1_EXTTRGPOLARITY_NONINVERTED = ((uint8_t)0x00)
  294. }TIM1_ExtTRGPolarity_TypeDef;
  295. #define IS_TIM1_EXT_POLARITY_OK(POLARITY) (((POLARITY) == TIM1_EXTTRGPOLARITY_INVERTED) || \
  296. ((POLARITY) == TIM1_EXTTRGPOLARITY_NONINVERTED))
  297. /** TIM1 Prescaler Reload Mode */
  298. typedef enum
  299. {
  300. TIM1_PSCRELOADMODE_UPDATE = ((uint8_t)0x00),
  301. TIM1_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01)
  302. }TIM1_PSCReloadMode_TypeDef;
  303. #define IS_TIM1_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM1_PSCRELOADMODE_UPDATE) || \
  304. ((RELOAD) == TIM1_PSCRELOADMODE_IMMEDIATE))
  305. /** TIM1 Encoder Mode */
  306. typedef enum
  307. {
  308. TIM1_ENCODERMODE_TI1 = ((uint8_t)0x01),
  309. TIM1_ENCODERMODE_TI2 = ((uint8_t)0x02),
  310. TIM1_ENCODERMODE_TI12 = ((uint8_t)0x03)
  311. }TIM1_EncoderMode_TypeDef;
  312. #define IS_TIM1_ENCODER_MODE_OK(MODE) (((MODE) == TIM1_ENCODERMODE_TI1) || \
  313. ((MODE) == TIM1_ENCODERMODE_TI2) || \
  314. ((MODE) == TIM1_ENCODERMODE_TI12))
  315. /** TIM1 Event Source */
  316. typedef enum
  317. {
  318. TIM1_EVENTSOURCE_UPDATE = ((uint8_t)0x01),
  319. TIM1_EVENTSOURCE_CC1 = ((uint8_t)0x02),
  320. TIM1_EVENTSOURCE_CC2 = ((uint8_t)0x04),
  321. TIM1_EVENTSOURCE_CC3 = ((uint8_t)0x08),
  322. TIM1_EVENTSOURCE_CC4 = ((uint8_t)0x10),
  323. TIM1_EVENTSOURCE_COM = ((uint8_t)0x20),
  324. TIM1_EVENTSOURCE_TRIGGER = ((uint8_t)0x40),
  325. TIM1_EVENTSOURCE_BREAK = ((uint8_t)0x80)
  326. }TIM1_EventSource_TypeDef;
  327. #define IS_TIM1_EVENT_SOURCE_OK(SOURCE) ((SOURCE) != 0x00)
  328. /** TIM1 Update Source */
  329. typedef enum
  330. {
  331. TIM1_UPDATESOURCE_GLOBAL = ((uint8_t)0x00),
  332. TIM1_UPDATESOURCE_REGULAR = ((uint8_t)0x01)
  333. }TIM1_UpdateSource_TypeDef;
  334. #define IS_TIM1_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM1_UPDATESOURCE_GLOBAL) || \
  335. ((SOURCE) == TIM1_UPDATESOURCE_REGULAR))
  336. /** TIM1 Trigger Output Source */
  337. typedef enum
  338. {
  339. TIM1_TRGOSOURCE_RESET = ((uint8_t)0x00),
  340. TIM1_TRGOSOURCE_ENABLE = ((uint8_t)0x10),
  341. TIM1_TRGOSOURCE_UPDATE = ((uint8_t)0x20),
  342. TIM1_TRGOSource_OC1 = ((uint8_t)0x30),
  343. TIM1_TRGOSOURCE_OC1REF = ((uint8_t)0x40),
  344. TIM1_TRGOSOURCE_OC2REF = ((uint8_t)0x50),
  345. TIM1_TRGOSOURCE_OC3REF = ((uint8_t)0x60)
  346. }TIM1_TRGOSource_TypeDef;
  347. #define IS_TIM1_TRGO_SOURCE_OK(SOURCE) (((SOURCE) == TIM1_TRGOSOURCE_RESET) || \
  348. ((SOURCE) == TIM1_TRGOSOURCE_ENABLE) || \
  349. ((SOURCE) == TIM1_TRGOSOURCE_UPDATE) || \
  350. ((SOURCE) == TIM1_TRGOSource_OC1) || \
  351. ((SOURCE) == TIM1_TRGOSOURCE_OC1REF) || \
  352. ((SOURCE) == TIM1_TRGOSOURCE_OC2REF) || \
  353. ((SOURCE) == TIM1_TRGOSOURCE_OC3REF))
  354. /** TIM1 Slave Mode */
  355. typedef enum
  356. {
  357. TIM1_SLAVEMODE_RESET = ((uint8_t)0x04),
  358. TIM1_SLAVEMODE_GATED = ((uint8_t)0x05),
  359. TIM1_SLAVEMODE_TRIGGER = ((uint8_t)0x06),
  360. TIM1_SLAVEMODE_EXTERNAL1 = ((uint8_t)0x07)
  361. }TIM1_SlaveMode_TypeDef;
  362. #define IS_TIM1_SLAVE_MODE_OK(MODE) (((MODE) == TIM1_SLAVEMODE_RESET) || \
  363. ((MODE) == TIM1_SLAVEMODE_GATED) || \
  364. ((MODE) == TIM1_SLAVEMODE_TRIGGER) || \
  365. ((MODE) == TIM1_SLAVEMODE_EXTERNAL1))
  366. /** TIM1 Flags */
  367. typedef enum
  368. {
  369. TIM1_FLAG_UPDATE = ((uint16_t)0x0001),
  370. TIM1_FLAG_CC1 = ((uint16_t)0x0002),
  371. TIM1_FLAG_CC2 = ((uint16_t)0x0004),
  372. TIM1_FLAG_CC3 = ((uint16_t)0x0008),
  373. TIM1_FLAG_CC4 = ((uint16_t)0x0010),
  374. TIM1_FLAG_COM = ((uint16_t)0x0020),
  375. TIM1_FLAG_TRIGGER = ((uint16_t)0x0040),
  376. TIM1_FLAG_BREAK = ((uint16_t)0x0080),
  377. TIM1_FLAG_CC1OF = ((uint16_t)0x0200),
  378. TIM1_FLAG_CC2OF = ((uint16_t)0x0400),
  379. TIM1_FLAG_CC3OF = ((uint16_t)0x0800),
  380. TIM1_FLAG_CC4OF = ((uint16_t)0x1000)
  381. }TIM1_FLAG_TypeDef;
  382. #define IS_TIM1_GET_FLAG_OK(FLAG) (((FLAG) == TIM1_FLAG_UPDATE) || \
  383. ((FLAG) == TIM1_FLAG_CC1) || \
  384. ((FLAG) == TIM1_FLAG_CC2) || \
  385. ((FLAG) == TIM1_FLAG_CC3) || \
  386. ((FLAG) == TIM1_FLAG_CC4) || \
  387. ((FLAG) == TIM1_FLAG_COM) || \
  388. ((FLAG) == TIM1_FLAG_TRIGGER) || \
  389. ((FLAG) == TIM1_FLAG_BREAK) || \
  390. ((FLAG) == TIM1_FLAG_CC1OF) || \
  391. ((FLAG) == TIM1_FLAG_CC2OF) || \
  392. ((FLAG) == TIM1_FLAG_CC3OF) || \
  393. ((FLAG) == TIM1_FLAG_CC4OF))
  394. #define IS_TIM1_CLEAR_FLAG_OK(FLAG) ((((uint16_t)(FLAG) & (uint16_t)0xE100) == 0x0000) && ((FLAG) != 0x0000))
  395. /** TIM1 Forced Action */
  396. typedef enum
  397. {
  398. TIM1_FORCEDACTION_ACTIVE = ((uint8_t)0x50),
  399. TIM1_FORCEDACTION_INACTIVE = ((uint8_t)0x40)
  400. }TIM1_ForcedAction_TypeDef;
  401. #define IS_TIM1_FORCED_ACTION_OK(ACTION) (((ACTION) == TIM1_FORCEDACTION_ACTIVE) || \
  402. ((ACTION) == TIM1_FORCEDACTION_INACTIVE))
  403. /**
  404. * @}
  405. */
  406. /* Exported macro ------------------------------------------------------------*/
  407. /* Exported functions --------------------------------------------------------*/
  408. /** @addtogroup TIM1_Exported_Functions
  409. * @{
  410. */
  411. void TIM1_DeInit(void);
  412. void TIM1_TimeBaseInit(uint16_t TIM1_Prescaler,
  413. TIM1_CounterMode_TypeDef TIM1_CounterMode,
  414. uint16_t TIM1_Period, uint8_t TIM1_RepetitionCounter);
  415. void TIM1_OC1Init(TIM1_OCMode_TypeDef TIM1_OCMode,
  416. TIM1_OutputState_TypeDef TIM1_OutputState,
  417. TIM1_OutputNState_TypeDef TIM1_OutputNState,
  418. uint16_t TIM1_Pulse, TIM1_OCPolarity_TypeDef TIM1_OCPolarity,
  419. TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity,
  420. TIM1_OCIdleState_TypeDef TIM1_OCIdleState,
  421. TIM1_OCNIdleState_TypeDef TIM1_OCNIdleState);
  422. void TIM1_OC2Init(TIM1_OCMode_TypeDef TIM1_OCMode,
  423. TIM1_OutputState_TypeDef TIM1_OutputState,
  424. TIM1_OutputNState_TypeDef TIM1_OutputNState,
  425. uint16_t TIM1_Pulse, TIM1_OCPolarity_TypeDef TIM1_OCPolarity,
  426. TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity,
  427. TIM1_OCIdleState_TypeDef TIM1_OCIdleState,
  428. TIM1_OCNIdleState_TypeDef TIM1_OCNIdleState);
  429. void TIM1_OC3Init(TIM1_OCMode_TypeDef TIM1_OCMode,
  430. TIM1_OutputState_TypeDef TIM1_OutputState,
  431. TIM1_OutputNState_TypeDef TIM1_OutputNState,
  432. uint16_t TIM1_Pulse, TIM1_OCPolarity_TypeDef TIM1_OCPolarity,
  433. TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity,
  434. TIM1_OCIdleState_TypeDef TIM1_OCIdleState,
  435. TIM1_OCNIdleState_TypeDef TIM1_OCNIdleState);
  436. void TIM1_OC4Init(TIM1_OCMode_TypeDef TIM1_OCMode,
  437. TIM1_OutputState_TypeDef TIM1_OutputState, uint16_t TIM1_Pulse,
  438. TIM1_OCPolarity_TypeDef TIM1_OCPolarity,
  439. TIM1_OCIdleState_TypeDef TIM1_OCIdleState);
  440. void TIM1_BDTRConfig(TIM1_OSSIState_TypeDef TIM1_OSSIState,
  441. TIM1_LockLevel_TypeDef TIM1_LockLevel, uint8_t TIM1_DeadTime,
  442. TIM1_BreakState_TypeDef TIM1_Break,
  443. TIM1_BreakPolarity_TypeDef TIM1_BreakPolarity,
  444. TIM1_AutomaticOutput_TypeDef TIM1_AutomaticOutput);
  445. void TIM1_ICInit(TIM1_Channel_TypeDef TIM1_Channel,
  446. TIM1_ICPolarity_TypeDef TIM1_ICPolarity,
  447. TIM1_ICSelection_TypeDef TIM1_ICSelection,
  448. TIM1_ICPSC_TypeDef TIM1_ICPrescaler, uint8_t TIM1_ICFilter);
  449. void TIM1_PWMIConfig(TIM1_Channel_TypeDef TIM1_Channel,
  450. TIM1_ICPolarity_TypeDef TIM1_ICPolarity,
  451. TIM1_ICSelection_TypeDef TIM1_ICSelection,
  452. TIM1_ICPSC_TypeDef TIM1_ICPrescaler, uint8_t TIM1_ICFilter);
  453. void TIM1_Cmd(FunctionalState NewState);
  454. void TIM1_CtrlPWMOutputs(FunctionalState NewState);
  455. void TIM1_ITConfig(TIM1_IT_TypeDef TIM1_IT, FunctionalState NewState);
  456. void TIM1_InternalClockConfig(void);
  457. void TIM1_ETRClockMode1Config(TIM1_ExtTRGPSC_TypeDef TIM1_ExtTRGPrescaler,
  458. TIM1_ExtTRGPolarity_TypeDef TIM1_ExtTRGPolarity,
  459. uint8_t ExtTRGFilter);
  460. void TIM1_ETRClockMode2Config(TIM1_ExtTRGPSC_TypeDef TIM1_ExtTRGPrescaler,
  461. TIM1_ExtTRGPolarity_TypeDef TIM1_ExtTRGPolarity,
  462. uint8_t ExtTRGFilter);
  463. void TIM1_ETRConfig(TIM1_ExtTRGPSC_TypeDef TIM1_ExtTRGPrescaler,
  464. TIM1_ExtTRGPolarity_TypeDef TIM1_ExtTRGPolarity,
  465. uint8_t ExtTRGFilter);
  466. void TIM1_TIxExternalClockConfig(TIM1_TIxExternalCLK1Source_TypeDef TIM1_TIxExternalCLKSource,
  467. TIM1_ICPolarity_TypeDef TIM1_ICPolarity,
  468. uint8_t ICFilter);
  469. void TIM1_SelectInputTrigger(TIM1_TS_TypeDef TIM1_InputTriggerSource);
  470. void TIM1_UpdateDisableConfig(FunctionalState NewState);
  471. void TIM1_UpdateRequestConfig(TIM1_UpdateSource_TypeDef TIM1_UpdateSource);
  472. void TIM1_SelectHallSensor(FunctionalState NewState);
  473. void TIM1_SelectOnePulseMode(TIM1_OPMode_TypeDef TIM1_OPMode);
  474. void TIM1_SelectOutputTrigger(TIM1_TRGOSource_TypeDef TIM1_TRGOSource);
  475. void TIM1_SelectSlaveMode(TIM1_SlaveMode_TypeDef TIM1_SlaveMode);
  476. void TIM1_SelectMasterSlaveMode(FunctionalState NewState);
  477. void TIM1_EncoderInterfaceConfig(TIM1_EncoderMode_TypeDef TIM1_EncoderMode,
  478. TIM1_ICPolarity_TypeDef TIM1_IC1Polarity,
  479. TIM1_ICPolarity_TypeDef TIM1_IC2Polarity);
  480. void TIM1_PrescalerConfig(uint16_t Prescaler, TIM1_PSCReloadMode_TypeDef TIM1_PSCReloadMode);
  481. void TIM1_CounterModeConfig(TIM1_CounterMode_TypeDef TIM1_CounterMode);
  482. void TIM1_ForcedOC1Config(TIM1_ForcedAction_TypeDef TIM1_ForcedAction);
  483. void TIM1_ForcedOC2Config(TIM1_ForcedAction_TypeDef TIM1_ForcedAction);
  484. void TIM1_ForcedOC3Config(TIM1_ForcedAction_TypeDef TIM1_ForcedAction);
  485. void TIM1_ForcedOC4Config(TIM1_ForcedAction_TypeDef TIM1_ForcedAction);
  486. void TIM1_ARRPreloadConfig(FunctionalState NewState);
  487. void TIM1_SelectCOM(FunctionalState NewState);
  488. void TIM1_CCPreloadControl(FunctionalState NewState);
  489. void TIM1_OC1PreloadConfig(FunctionalState NewState);
  490. void TIM1_OC2PreloadConfig(FunctionalState NewState);
  491. void TIM1_OC3PreloadConfig(FunctionalState NewState);
  492. void TIM1_OC4PreloadConfig(FunctionalState NewState);
  493. void TIM1_OC1FastConfig(FunctionalState NewState);
  494. void TIM1_OC2FastConfig(FunctionalState NewState);
  495. void TIM1_OC3FastConfig(FunctionalState NewState);
  496. void TIM1_OC4FastConfig(FunctionalState NewState);
  497. void TIM1_GenerateEvent(TIM1_EventSource_TypeDef TIM1_EventSource);
  498. void TIM1_OC1PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity);
  499. void TIM1_OC1NPolarityConfig(TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity);
  500. void TIM1_OC2PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity);
  501. void TIM1_OC2NPolarityConfig(TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity);
  502. void TIM1_OC3PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity);
  503. void TIM1_OC3NPolarityConfig(TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity);
  504. void TIM1_OC4PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity);
  505. void TIM1_CCxCmd(TIM1_Channel_TypeDef TIM1_Channel, FunctionalState NewState);
  506. void TIM1_CCxNCmd(TIM1_Channel_TypeDef TIM1_Channel, FunctionalState NewState);
  507. void TIM1_SelectOCxM(TIM1_Channel_TypeDef TIM1_Channel, TIM1_OCMode_TypeDef TIM1_OCMode);
  508. void TIM1_SetCounter(uint16_t Counter);
  509. void TIM1_SetAutoreload(uint16_t Autoreload);
  510. void TIM1_SetCompare1(uint16_t Compare1);
  511. void TIM1_SetCompare2(uint16_t Compare2);
  512. void TIM1_SetCompare3(uint16_t Compare3);
  513. void TIM1_SetCompare4(uint16_t Compare4);
  514. void TIM1_SetIC1Prescaler(TIM1_ICPSC_TypeDef TIM1_IC1Prescaler);
  515. void TIM1_SetIC2Prescaler(TIM1_ICPSC_TypeDef TIM1_IC2Prescaler);
  516. void TIM1_SetIC3Prescaler(TIM1_ICPSC_TypeDef TIM1_IC3Prescaler);
  517. void TIM1_SetIC4Prescaler(TIM1_ICPSC_TypeDef TIM1_IC4Prescaler);
  518. uint16_t TIM1_GetCapture1(void);
  519. uint16_t TIM1_GetCapture2(void);
  520. uint16_t TIM1_GetCapture3(void);
  521. uint16_t TIM1_GetCapture4(void);
  522. uint16_t TIM1_GetCounter(void);
  523. uint16_t TIM1_GetPrescaler(void);
  524. FlagStatus TIM1_GetFlagStatus(TIM1_FLAG_TypeDef TIM1_FLAG);
  525. void TIM1_ClearFlag(TIM1_FLAG_TypeDef TIM1_FLAG);
  526. ITStatus TIM1_GetITStatus(TIM1_IT_TypeDef TIM1_IT);
  527. void TIM1_ClearITPendingBit(TIM1_IT_TypeDef TIM1_IT);
  528. /**
  529. * @}
  530. */
  531. #endif /* __STM8S_TIM1_H */
  532. /**
  533. * @}
  534. */
  535. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/