stm8s_tim2.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_tim2.h
  4. * @author MCD Application Team
  5. * @version V2.2.0
  6. * @date 30-September-2014
  7. * @brief This file contains all functions prototype and macros for the TIM2 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_TIM2_H
  29. #define __STM8S_TIM2_H
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm8s.h"
  32. /** @addtogroup STM8S_StdPeriph_Driver
  33. * @{
  34. */
  35. /* Exported types ------------------------------------------------------------*/
  36. /** TIM2 Forced Action */
  37. typedef enum
  38. {
  39. TIM2_FORCEDACTION_ACTIVE = ((uint8_t)0x50),
  40. TIM2_FORCEDACTION_INACTIVE = ((uint8_t)0x40)
  41. }TIM2_ForcedAction_TypeDef;
  42. #define IS_TIM2_FORCED_ACTION_OK(ACTION) (((ACTION) == TIM2_FORCEDACTION_ACTIVE) || \
  43. ((ACTION) == TIM2_FORCEDACTION_INACTIVE))
  44. /** TIM2 Prescaler */
  45. typedef enum
  46. {
  47. TIM2_PRESCALER_1 = ((uint8_t)0x00),
  48. TIM2_PRESCALER_2 = ((uint8_t)0x01),
  49. TIM2_PRESCALER_4 = ((uint8_t)0x02),
  50. TIM2_PRESCALER_8 = ((uint8_t)0x03),
  51. TIM2_PRESCALER_16 = ((uint8_t)0x04),
  52. TIM2_PRESCALER_32 = ((uint8_t)0x05),
  53. TIM2_PRESCALER_64 = ((uint8_t)0x06),
  54. TIM2_PRESCALER_128 = ((uint8_t)0x07),
  55. TIM2_PRESCALER_256 = ((uint8_t)0x08),
  56. TIM2_PRESCALER_512 = ((uint8_t)0x09),
  57. TIM2_PRESCALER_1024 = ((uint8_t)0x0A),
  58. TIM2_PRESCALER_2048 = ((uint8_t)0x0B),
  59. TIM2_PRESCALER_4096 = ((uint8_t)0x0C),
  60. TIM2_PRESCALER_8192 = ((uint8_t)0x0D),
  61. TIM2_PRESCALER_16384 = ((uint8_t)0x0E),
  62. TIM2_PRESCALER_32768 = ((uint8_t)0x0F)
  63. }TIM2_Prescaler_TypeDef;
  64. #define IS_TIM2_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM2_PRESCALER_1 ) || \
  65. ((PRESCALER) == TIM2_PRESCALER_2 ) || \
  66. ((PRESCALER) == TIM2_PRESCALER_4 ) || \
  67. ((PRESCALER) == TIM2_PRESCALER_8 ) || \
  68. ((PRESCALER) == TIM2_PRESCALER_16 ) || \
  69. ((PRESCALER) == TIM2_PRESCALER_32 ) || \
  70. ((PRESCALER) == TIM2_PRESCALER_64 ) || \
  71. ((PRESCALER) == TIM2_PRESCALER_128 ) || \
  72. ((PRESCALER) == TIM2_PRESCALER_256 ) || \
  73. ((PRESCALER) == TIM2_PRESCALER_512 ) || \
  74. ((PRESCALER) == TIM2_PRESCALER_1024 ) || \
  75. ((PRESCALER) == TIM2_PRESCALER_2048 ) || \
  76. ((PRESCALER) == TIM2_PRESCALER_4096 ) || \
  77. ((PRESCALER) == TIM2_PRESCALER_8192 ) || \
  78. ((PRESCALER) == TIM2_PRESCALER_16384 ) || \
  79. ((PRESCALER) == TIM2_PRESCALER_32768 ))
  80. /** TIM2 Output Compare and PWM modes */
  81. typedef enum
  82. {
  83. TIM2_OCMODE_TIMING = ((uint8_t)0x00),
  84. TIM2_OCMODE_ACTIVE = ((uint8_t)0x10),
  85. TIM2_OCMODE_INACTIVE = ((uint8_t)0x20),
  86. TIM2_OCMODE_TOGGLE = ((uint8_t)0x30),
  87. TIM2_OCMODE_PWM1 = ((uint8_t)0x60),
  88. TIM2_OCMODE_PWM2 = ((uint8_t)0x70)
  89. }TIM2_OCMode_TypeDef;
  90. #define IS_TIM2_OC_MODE_OK(MODE) (((MODE) == TIM2_OCMODE_TIMING) || \
  91. ((MODE) == TIM2_OCMODE_ACTIVE) || \
  92. ((MODE) == TIM2_OCMODE_INACTIVE) || \
  93. ((MODE) == TIM2_OCMODE_TOGGLE)|| \
  94. ((MODE) == TIM2_OCMODE_PWM1) || \
  95. ((MODE) == TIM2_OCMODE_PWM2))
  96. #define IS_TIM2_OCM_OK(MODE)(((MODE) == TIM2_OCMODE_TIMING) || \
  97. ((MODE) == TIM2_OCMODE_ACTIVE) || \
  98. ((MODE) == TIM2_OCMODE_INACTIVE) || \
  99. ((MODE) == TIM2_OCMODE_TOGGLE)|| \
  100. ((MODE) == TIM2_OCMODE_PWM1) || \
  101. ((MODE) == TIM2_OCMODE_PWM2) || \
  102. ((MODE) == (uint8_t)TIM2_FORCEDACTION_ACTIVE) || \
  103. ((MODE) == (uint8_t)TIM2_FORCEDACTION_INACTIVE))
  104. /** TIM2 One Pulse Mode */
  105. typedef enum
  106. {
  107. TIM2_OPMODE_SINGLE = ((uint8_t)0x01),
  108. TIM2_OPMODE_REPETITIVE = ((uint8_t)0x00)
  109. }TIM2_OPMode_TypeDef;
  110. #define IS_TIM2_OPM_MODE_OK(MODE) (((MODE) == TIM2_OPMODE_SINGLE) || \
  111. ((MODE) == TIM2_OPMODE_REPETITIVE))
  112. /** TIM2 Channel */
  113. typedef enum
  114. {
  115. TIM2_CHANNEL_1 = ((uint8_t)0x00),
  116. TIM2_CHANNEL_2 = ((uint8_t)0x01),
  117. TIM2_CHANNEL_3 = ((uint8_t)0x02)
  118. }TIM2_Channel_TypeDef;
  119. #define IS_TIM2_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM2_CHANNEL_1) || \
  120. ((CHANNEL) == TIM2_CHANNEL_2) || \
  121. ((CHANNEL) == TIM2_CHANNEL_3))
  122. #define IS_TIM2_PWMI_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM2_CHANNEL_1) || \
  123. ((CHANNEL) == TIM2_CHANNEL_2))
  124. /** TIM2 Output Compare Polarity */
  125. typedef enum
  126. {
  127. TIM2_OCPOLARITY_HIGH = ((uint8_t)0x00),
  128. TIM2_OCPOLARITY_LOW = ((uint8_t)0x22)
  129. }TIM2_OCPolarity_TypeDef;
  130. #define IS_TIM2_OC_POLARITY_OK(POLARITY) (((POLARITY) == TIM2_OCPOLARITY_HIGH) || \
  131. ((POLARITY) == TIM2_OCPOLARITY_LOW))
  132. /** TIM2 Output Compare states */
  133. typedef enum
  134. {
  135. TIM2_OUTPUTSTATE_DISABLE = ((uint8_t)0x00),
  136. TIM2_OUTPUTSTATE_ENABLE = ((uint8_t)0x11)
  137. }TIM2_OutputState_TypeDef;
  138. #define IS_TIM2_OUTPUT_STATE_OK(STATE) (((STATE) == TIM2_OUTPUTSTATE_DISABLE) || \
  139. ((STATE) == TIM2_OUTPUTSTATE_ENABLE))
  140. /** TIM2 Input Capture Polarity */
  141. typedef enum
  142. {
  143. TIM2_ICPOLARITY_RISING = ((uint8_t)0x00),
  144. TIM2_ICPOLARITY_FALLING = ((uint8_t)0x44)
  145. }TIM2_ICPolarity_TypeDef;
  146. #define IS_TIM2_IC_POLARITY_OK(POLARITY) (((POLARITY) == TIM2_ICPOLARITY_RISING) || \
  147. ((POLARITY) == TIM2_ICPOLARITY_FALLING))
  148. /** TIM2 Input Capture Selection */
  149. typedef enum
  150. {
  151. TIM2_ICSELECTION_DIRECTTI = ((uint8_t)0x01),
  152. TIM2_ICSELECTION_INDIRECTTI = ((uint8_t)0x02),
  153. TIM2_ICSELECTION_TRGI = ((uint8_t)0x03)
  154. }TIM2_ICSelection_TypeDef;
  155. #define IS_TIM2_IC_SELECTION_OK(SELECTION) (((SELECTION) == TIM2_ICSELECTION_DIRECTTI) || \
  156. ((SELECTION) == TIM2_ICSELECTION_INDIRECTTI) || \
  157. ((SELECTION) == TIM2_ICSELECTION_TRGI))
  158. #define IS_TIM2_IC_SELECTION1_OK(SELECTION) (((SELECTION) == TIM2_ICSELECTION_DIRECTTI) || \
  159. ((SELECTION) == TIM2_ICSELECTION_TRGI))
  160. /** TIM2 Input Capture Prescaler */
  161. typedef enum
  162. {
  163. TIM2_ICPSC_DIV1 = ((uint8_t)0x00),
  164. TIM2_ICPSC_DIV2 = ((uint8_t)0x04),
  165. TIM2_ICPSC_DIV4 = ((uint8_t)0x08),
  166. TIM2_ICPSC_DIV8 = ((uint8_t)0x0C)
  167. }TIM2_ICPSC_TypeDef;
  168. #define IS_TIM2_IC_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM2_ICPSC_DIV1) || \
  169. ((PRESCALER) == TIM2_ICPSC_DIV2) || \
  170. ((PRESCALER) == TIM2_ICPSC_DIV4) || \
  171. ((PRESCALER) == TIM2_ICPSC_DIV8))
  172. /** TIM2 Input Capture Filer Value */
  173. #define IS_TIM2_IC_FILTER_OK(ICFILTER) ((ICFILTER) <= 0x0F)
  174. /** TIM2 interrupt sources */
  175. typedef enum
  176. {
  177. TIM2_IT_UPDATE = ((uint8_t)0x01),
  178. TIM2_IT_CC1 = ((uint8_t)0x02),
  179. TIM2_IT_CC2 = ((uint8_t)0x04),
  180. TIM2_IT_CC3 = ((uint8_t)0x08)
  181. }TIM2_IT_TypeDef;
  182. #define IS_TIM2_IT_OK(IT) (((IT) != 0x00) && ((IT) <= 0x0F))
  183. #define IS_TIM2_GET_IT_OK(IT) (((IT) == TIM2_IT_UPDATE) || \
  184. ((IT) == TIM2_IT_CC1) || \
  185. ((IT) == TIM2_IT_CC2) || \
  186. ((IT) == TIM2_IT_CC3))
  187. /** TIM2 Prescaler Reload Mode */
  188. typedef enum
  189. {
  190. TIM2_PSCRELOADMODE_UPDATE = ((uint8_t)0x00),
  191. TIM2_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01)
  192. }TIM2_PSCReloadMode_TypeDef;
  193. #define IS_TIM2_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM2_PSCRELOADMODE_UPDATE) || \
  194. ((RELOAD) == TIM2_PSCRELOADMODE_IMMEDIATE))
  195. /** TIM2 Event Source */
  196. typedef enum
  197. {
  198. TIM2_EVENTSOURCE_UPDATE = ((uint8_t)0x01),
  199. TIM2_EVENTSOURCE_CC1 = ((uint8_t)0x02),
  200. TIM2_EVENTSOURCE_CC2 = ((uint8_t)0x04),
  201. TIM2_EVENTSOURCE_CC3 = ((uint8_t)0x08)
  202. }TIM2_EventSource_TypeDef;
  203. #define IS_TIM2_EVENT_SOURCE_OK(SOURCE) (((SOURCE) != 0x00))
  204. /** TIM2 Update Source */
  205. typedef enum
  206. {
  207. TIM2_UPDATESOURCE_GLOBAL = ((uint8_t)0x00),
  208. TIM2_UPDATESOURCE_REGULAR = ((uint8_t)0x01)
  209. }TIM2_UpdateSource_TypeDef;
  210. #define IS_TIM2_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM2_UPDATESOURCE_GLOBAL) || \
  211. ((SOURCE) == TIM2_UPDATESOURCE_REGULAR))
  212. /** TIM2 Flags */
  213. typedef enum
  214. {
  215. TIM2_FLAG_UPDATE = ((uint16_t)0x0001),
  216. TIM2_FLAG_CC1 = ((uint16_t)0x0002),
  217. TIM2_FLAG_CC2 = ((uint16_t)0x0004),
  218. TIM2_FLAG_CC3 = ((uint16_t)0x0008),
  219. TIM2_FLAG_CC1OF = ((uint16_t)0x0200),
  220. TIM2_FLAG_CC2OF = ((uint16_t)0x0400),
  221. TIM2_FLAG_CC3OF = ((uint16_t)0x0800)
  222. }TIM2_FLAG_TypeDef;
  223. #define IS_TIM2_GET_FLAG_OK(FLAG) (((FLAG) == TIM2_FLAG_UPDATE) || \
  224. ((FLAG) == TIM2_FLAG_CC1) || \
  225. ((FLAG) == TIM2_FLAG_CC2) || \
  226. ((FLAG) == TIM2_FLAG_CC3) || \
  227. ((FLAG) == TIM2_FLAG_CC1OF) || \
  228. ((FLAG) == TIM2_FLAG_CC2OF) || \
  229. ((FLAG) == TIM2_FLAG_CC3OF))
  230. #define IS_TIM2_CLEAR_FLAG_OK(FLAG) ((((uint16_t)(FLAG) & 0xF1F0) == 0x0000) && ((uint16_t)(FLAG) != 0x0000))
  231. /**
  232. * @}
  233. */
  234. /* Exported macro ------------------------------------------------------------*/
  235. /* Exported functions --------------------------------------------------------*/
  236. /** @addtogroup TIM2_Exported_Functions
  237. * @{
  238. */
  239. void TIM2_DeInit(void);
  240. void TIM2_TimeBaseInit(TIM2_Prescaler_TypeDef TIM2_Prescaler, uint16_t TIM2_Period);
  241. void TIM2_OC1Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  242. void TIM2_OC2Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  243. void TIM2_OC3Init(TIM2_OCMode_TypeDef TIM2_OCMode, TIM2_OutputState_TypeDef TIM2_OutputState, uint16_t TIM2_Pulse, TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  244. void TIM2_ICInit(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter);
  245. void TIM2_PWMIConfig(TIM2_Channel_TypeDef TIM2_Channel, TIM2_ICPolarity_TypeDef TIM2_ICPolarity, TIM2_ICSelection_TypeDef TIM2_ICSelection, TIM2_ICPSC_TypeDef TIM2_ICPrescaler, uint8_t TIM2_ICFilter);
  246. void TIM2_Cmd(FunctionalState NewState);
  247. void TIM2_ITConfig(TIM2_IT_TypeDef TIM2_IT, FunctionalState NewState);
  248. void TIM2_InternalClockConfig(void);
  249. void TIM2_UpdateDisableConfig(FunctionalState NewState);
  250. void TIM2_UpdateRequestConfig(TIM2_UpdateSource_TypeDef TIM2_UpdateSource);
  251. void TIM2_SelectOnePulseMode(TIM2_OPMode_TypeDef TIM2_OPMode);
  252. void TIM2_PrescalerConfig(TIM2_Prescaler_TypeDef Prescaler, TIM2_PSCReloadMode_TypeDef TIM2_PSCReloadMode);
  253. void TIM2_ForcedOC1Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction);
  254. void TIM2_ForcedOC2Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction);
  255. void TIM2_ForcedOC3Config(TIM2_ForcedAction_TypeDef TIM2_ForcedAction);
  256. void TIM2_ARRPreloadConfig(FunctionalState NewState);
  257. void TIM2_CCPreloadControl(FunctionalState NewState);
  258. void TIM2_OC1PreloadConfig(FunctionalState NewState);
  259. void TIM2_OC2PreloadConfig(FunctionalState NewState);
  260. void TIM2_OC3PreloadConfig(FunctionalState NewState);
  261. void TIM2_GenerateEvent(TIM2_EventSource_TypeDef TIM2_EventSource);
  262. void TIM2_OC1PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  263. void TIM2_OC2PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  264. void TIM2_OC3PolarityConfig(TIM2_OCPolarity_TypeDef TIM2_OCPolarity);
  265. void TIM2_CCxCmd(TIM2_Channel_TypeDef TIM2_Channel, FunctionalState NewState);
  266. void TIM2_SelectOCxM(TIM2_Channel_TypeDef TIM2_Channel, TIM2_OCMode_TypeDef TIM2_OCMode);
  267. void TIM2_SetCounter(uint16_t Counter);
  268. void TIM2_SetAutoreload(uint16_t Autoreload);
  269. void TIM2_SetCompare1(uint16_t Compare1);
  270. void TIM2_SetCompare2(uint16_t Compare2);
  271. void TIM2_SetCompare3(uint16_t Compare3);
  272. void TIM2_SetIC1Prescaler(TIM2_ICPSC_TypeDef TIM2_IC1Prescaler);
  273. void TIM2_SetIC2Prescaler(TIM2_ICPSC_TypeDef TIM2_IC2Prescaler);
  274. void TIM2_SetIC3Prescaler(TIM2_ICPSC_TypeDef TIM2_IC3Prescaler);
  275. uint16_t TIM2_GetCapture1(void);
  276. uint16_t TIM2_GetCapture2(void);
  277. uint16_t TIM2_GetCapture3(void);
  278. uint16_t TIM2_GetCounter(void);
  279. TIM2_Prescaler_TypeDef TIM2_GetPrescaler(void);
  280. FlagStatus TIM2_GetFlagStatus(TIM2_FLAG_TypeDef TIM2_FLAG);
  281. void TIM2_ClearFlag(TIM2_FLAG_TypeDef TIM2_FLAG);
  282. ITStatus TIM2_GetITStatus(TIM2_IT_TypeDef TIM2_IT);
  283. void TIM2_ClearITPendingBit(TIM2_IT_TypeDef TIM2_IT);
  284. /**
  285. * @}
  286. */
  287. #endif /* __STM8S_TIM2_H */
  288. /**
  289. * @}
  290. */
  291. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/