stm8s_tim3.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_tim3.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 TIM3 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_TIM3_H
  29. #define __STM8S_TIM3_H
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm8s.h"
  32. /** @addtogroup STM8S_StdPeriph_Driver
  33. * @{
  34. */
  35. /* Exported types ------------------------------------------------------------*/
  36. /** @addtogroup TIM3_Exported_Types
  37. * @{
  38. */
  39. /** TIM3 Forced Action */
  40. typedef enum
  41. {
  42. TIM3_FORCEDACTION_ACTIVE = ((uint8_t)0x50),
  43. TIM3_FORCEDACTION_INACTIVE = ((uint8_t)0x40)
  44. } TIM3_ForcedAction_TypeDef;
  45. #define IS_TIM3_FORCED_ACTION_OK(ACTION) (((ACTION) == TIM3_FORCEDACTION_ACTIVE) || \
  46. ((ACTION) == TIM3_FORCEDACTION_INACTIVE))
  47. /** TIM3 Prescaler */
  48. typedef enum
  49. {
  50. TIM3_PRESCALER_1 = ((uint8_t)0x00),
  51. TIM3_PRESCALER_2 = ((uint8_t)0x01),
  52. TIM3_PRESCALER_4 = ((uint8_t)0x02),
  53. TIM3_PRESCALER_8 = ((uint8_t)0x03),
  54. TIM3_PRESCALER_16 = ((uint8_t)0x04),
  55. TIM3_PRESCALER_32 = ((uint8_t)0x05),
  56. TIM3_PRESCALER_64 = ((uint8_t)0x06),
  57. TIM3_PRESCALER_128 = ((uint8_t)0x07),
  58. TIM3_PRESCALER_256 = ((uint8_t)0x08),
  59. TIM3_PRESCALER_512 = ((uint8_t)0x09),
  60. TIM3_PRESCALER_1024 = ((uint8_t)0x0A),
  61. TIM3_PRESCALER_2048 = ((uint8_t)0x0B),
  62. TIM3_PRESCALER_4096 = ((uint8_t)0x0C),
  63. TIM3_PRESCALER_8192 = ((uint8_t)0x0D),
  64. TIM3_PRESCALER_16384 = ((uint8_t)0x0E),
  65. TIM3_PRESCALER_32768 = ((uint8_t)0x0F)
  66. } TIM3_Prescaler_TypeDef;
  67. #define IS_TIM3_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM3_PRESCALER_1 ) || \
  68. ((PRESCALER) == TIM3_PRESCALER_2 ) || \
  69. ((PRESCALER) == TIM3_PRESCALER_4 ) || \
  70. ((PRESCALER) == TIM3_PRESCALER_8 ) || \
  71. ((PRESCALER) == TIM3_PRESCALER_16 ) || \
  72. ((PRESCALER) == TIM3_PRESCALER_32 ) || \
  73. ((PRESCALER) == TIM3_PRESCALER_64 ) || \
  74. ((PRESCALER) == TIM3_PRESCALER_128 ) || \
  75. ((PRESCALER) == TIM3_PRESCALER_256 ) || \
  76. ((PRESCALER) == TIM3_PRESCALER_512 ) || \
  77. ((PRESCALER) == TIM3_PRESCALER_1024 ) || \
  78. ((PRESCALER) == TIM3_PRESCALER_2048 ) || \
  79. ((PRESCALER) == TIM3_PRESCALER_4096 ) || \
  80. ((PRESCALER) == TIM3_PRESCALER_8192 ) || \
  81. ((PRESCALER) == TIM3_PRESCALER_16384 ) || \
  82. ((PRESCALER) == TIM3_PRESCALER_32768 ))
  83. /** TIM3 Output Compare and PWM modes */
  84. typedef enum
  85. {
  86. TIM3_OCMODE_TIMING = ((uint8_t)0x00),
  87. TIM3_OCMODE_ACTIVE = ((uint8_t)0x10),
  88. TIM3_OCMODE_INACTIVE = ((uint8_t)0x20),
  89. TIM3_OCMODE_TOGGLE = ((uint8_t)0x30),
  90. TIM3_OCMODE_PWM1 = ((uint8_t)0x60),
  91. TIM3_OCMODE_PWM2 = ((uint8_t)0x70)
  92. } TIM3_OCMode_TypeDef;
  93. #define IS_TIM3_OC_MODE_OK(MODE) (((MODE) == TIM3_OCMODE_TIMING) || \
  94. ((MODE) == TIM3_OCMODE_ACTIVE) || \
  95. ((MODE) == TIM3_OCMODE_INACTIVE) || \
  96. ((MODE) == TIM3_OCMODE_TOGGLE)|| \
  97. ((MODE) == TIM3_OCMODE_PWM1) || \
  98. ((MODE) == TIM3_OCMODE_PWM2))
  99. #define IS_TIM3_OCM_OK(MODE)(((MODE) == TIM3_OCMODE_TIMING) || \
  100. ((MODE) == TIM3_OCMODE_ACTIVE) || \
  101. ((MODE) == TIM3_OCMODE_INACTIVE) || \
  102. ((MODE) == TIM3_OCMODE_TOGGLE)|| \
  103. ((MODE) == TIM3_OCMODE_PWM1) || \
  104. ((MODE) == TIM3_OCMODE_PWM2) || \
  105. ((MODE) == (uint8_t)TIM3_FORCEDACTION_ACTIVE) || \
  106. ((MODE) == (uint8_t)TIM3_FORCEDACTION_INACTIVE))
  107. /** TIM3 One Pulse Mode */
  108. typedef enum
  109. {
  110. TIM3_OPMODE_SINGLE = ((uint8_t)0x01),
  111. TIM3_OPMODE_REPETITIVE = ((uint8_t)0x00)
  112. } TIM3_OPMode_TypeDef;
  113. #define IS_TIM3_OPM_MODE_OK(MODE) (((MODE) == TIM3_OPMODE_SINGLE) || \
  114. ((MODE) == TIM3_OPMODE_REPETITIVE))
  115. /** TIM3 Channel */
  116. typedef enum
  117. {
  118. TIM3_CHANNEL_1 = ((uint8_t)0x00),
  119. TIM3_CHANNEL_2 = ((uint8_t)0x01)
  120. } TIM3_Channel_TypeDef;
  121. #define IS_TIM3_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM3_CHANNEL_1) || \
  122. ((CHANNEL) == TIM3_CHANNEL_2))
  123. #define IS_TIM3_PWMI_CHANNEL_OK(CHANNEL) (((CHANNEL) == TIM3_CHANNEL_1) || \
  124. ((CHANNEL) == TIM3_CHANNEL_2))
  125. /** TIM3 Output Compare Polarity */
  126. typedef enum
  127. {
  128. TIM3_OCPOLARITY_HIGH = ((uint8_t)0x00),
  129. TIM3_OCPOLARITY_LOW = ((uint8_t)0x22)
  130. } TIM3_OCPolarity_TypeDef;
  131. #define IS_TIM3_OC_POLARITY_OK(POLARITY) (((POLARITY) == TIM3_OCPOLARITY_HIGH) || \
  132. ((POLARITY) == TIM3_OCPOLARITY_LOW))
  133. /** TIM3 Output Compare states */
  134. typedef enum
  135. {
  136. TIM3_OUTPUTSTATE_DISABLE = ((uint8_t)0x00),
  137. TIM3_OUTPUTSTATE_ENABLE = ((uint8_t)0x11)
  138. } TIM3_OutputState_TypeDef;
  139. #define IS_TIM3_OUTPUT_STATE_OK(STATE) (((STATE) == TIM3_OUTPUTSTATE_DISABLE) || \
  140. ((STATE) == TIM3_OUTPUTSTATE_ENABLE))
  141. /** TIM3 Input Capture Polarity */
  142. typedef enum
  143. {
  144. TIM3_ICPOLARITY_RISING = ((uint8_t)0x00),
  145. TIM3_ICPOLARITY_FALLING = ((uint8_t)0x44)
  146. } TIM3_ICPolarity_TypeDef;
  147. #define IS_TIM3_IC_POLARITY_OK(POLARITY) (((POLARITY) == TIM3_ICPOLARITY_RISING) || \
  148. ((POLARITY) == TIM3_ICPOLARITY_FALLING))
  149. /** TIM3 Input Capture Selection */
  150. typedef enum
  151. {
  152. TIM3_ICSELECTION_DIRECTTI = ((uint8_t)0x01),
  153. TIM3_ICSELECTION_INDIRECTTI = ((uint8_t)0x02),
  154. TIM3_ICSELECTION_TRGI = ((uint8_t)0x03)
  155. } TIM3_ICSelection_TypeDef;
  156. #define IS_TIM3_IC_SELECTION_OK(SELECTION) (((SELECTION) == TIM3_ICSELECTION_DIRECTTI) || \
  157. ((SELECTION) == TIM3_ICSELECTION_INDIRECTTI) || \
  158. ((SELECTION) == TIM3_ICSELECTION_TRGI))
  159. /** TIM3 Input Capture Prescaler */
  160. typedef enum
  161. {
  162. TIM3_ICPSC_DIV1 = ((uint8_t)0x00),
  163. TIM3_ICPSC_DIV2 = ((uint8_t)0x04),
  164. TIM3_ICPSC_DIV4 = ((uint8_t)0x08),
  165. TIM3_ICPSC_DIV8 = ((uint8_t)0x0C)
  166. } TIM3_ICPSC_TypeDef;
  167. #define IS_TIM3_IC_PRESCALER_OK(PRESCALER) (((PRESCALER) == TIM3_ICPSC_DIV1) || \
  168. ((PRESCALER) == TIM3_ICPSC_DIV2) || \
  169. ((PRESCALER) == TIM3_ICPSC_DIV4) || \
  170. ((PRESCALER) == TIM3_ICPSC_DIV8))
  171. /** TIM3 Input Capture Filer Value */
  172. #define IS_TIM3_IC_FILTER_OK(ICFILTER) ((ICFILTER) <= 0x0F)
  173. /** TIM3 interrupt sources */
  174. typedef enum
  175. {
  176. TIM3_IT_UPDATE = ((uint8_t)0x01),
  177. TIM3_IT_CC1 = ((uint8_t)0x02),
  178. TIM3_IT_CC2 = ((uint8_t)0x04)
  179. } TIM3_IT_TypeDef;
  180. #define IS_TIM3_IT_OK(IT) (((IT) != 0x00) && ((IT) <= 0x07))
  181. #define IS_TIM3_GET_IT_OK(IT) (((IT) == TIM3_IT_UPDATE) || \
  182. ((IT) == TIM3_IT_CC1) || \
  183. ((IT) == TIM3_IT_CC2))
  184. /** TIM3 Prescaler Reload Mode */
  185. typedef enum
  186. {
  187. TIM3_PSCRELOADMODE_UPDATE = ((uint8_t)0x00),
  188. TIM3_PSCRELOADMODE_IMMEDIATE = ((uint8_t)0x01)
  189. } TIM3_PSCReloadMode_TypeDef;
  190. #define IS_TIM3_PRESCALER_RELOAD_OK(RELOAD) (((RELOAD) == TIM3_PSCRELOADMODE_UPDATE) || \
  191. ((RELOAD) == TIM3_PSCRELOADMODE_IMMEDIATE))
  192. /** TIM3 Event Source */
  193. typedef enum
  194. {
  195. TIM3_EVENTSOURCE_UPDATE = ((uint8_t)0x01),
  196. TIM3_EVENTSOURCE_CC1 = ((uint8_t)0x02),
  197. TIM3_EVENTSOURCE_CC2 = ((uint8_t)0x04)
  198. } TIM3_EventSource_TypeDef;
  199. #define IS_TIM3_EVENT_SOURCE_OK(SOURCE) (((SOURCE) != 0x00))
  200. /** TIM3 Update Source */
  201. typedef enum
  202. {
  203. TIM3_UPDATESOURCE_GLOBAL = ((uint8_t)0x00),
  204. TIM3_UPDATESOURCE_REGULAR = ((uint8_t)0x01)
  205. } TIM3_UpdateSource_TypeDef;
  206. #define IS_TIM3_UPDATE_SOURCE_OK(SOURCE) (((SOURCE) == TIM3_UPDATESOURCE_GLOBAL) || \
  207. ((SOURCE) == TIM3_UPDATESOURCE_REGULAR))
  208. /** TIM3 Flags */
  209. typedef enum
  210. {
  211. TIM3_FLAG_UPDATE = ((uint16_t)0x0001),
  212. TIM3_FLAG_CC1 = ((uint16_t)0x0002),
  213. TIM3_FLAG_CC2 = ((uint16_t)0x0004),
  214. TIM3_FLAG_CC1OF = ((uint16_t)0x0200),
  215. TIM3_FLAG_CC2OF = ((uint16_t)0x0400)
  216. } TIM3_FLAG_TypeDef;
  217. #define IS_TIM3_GET_FLAG_OK(FLAG) (((FLAG) == TIM3_FLAG_UPDATE) || \
  218. ((FLAG) == TIM3_FLAG_CC1) || \
  219. ((FLAG) == TIM3_FLAG_CC2) || \
  220. ((FLAG) == TIM3_FLAG_CC1OF) || \
  221. ((FLAG) == TIM3_FLAG_CC2OF) )
  222. #define IS_TIM3_CLEAR_FLAG_OK(FLAG) ((((uint16_t)(FLAG) & 0xF9F8) == 0x0000) && ((uint16_t)(FLAG)!= 0x0000))
  223. /**
  224. * @}
  225. */
  226. /* Exported macro ------------------------------------------------------------*/
  227. /* Exported functions --------------------------------------------------------*/
  228. /** @addtogroup TIM3_Exported_Functions
  229. * @{
  230. */
  231. void TIM3_DeInit(void);
  232. void TIM3_TimeBaseInit(TIM3_Prescaler_TypeDef TIM3_Prescaler, uint16_t TIM3_Period);
  233. void TIM3_OC1Init(TIM3_OCMode_TypeDef TIM3_OCMode, TIM3_OutputState_TypeDef TIM3_OutputState, uint16_t TIM3_Pulse, TIM3_OCPolarity_TypeDef TIM3_OCPolarity);
  234. void TIM3_OC2Init(TIM3_OCMode_TypeDef TIM3_OCMode, TIM3_OutputState_TypeDef TIM3_OutputState, uint16_t TIM3_Pulse, TIM3_OCPolarity_TypeDef TIM3_OCPolarity);
  235. void TIM3_ICInit(TIM3_Channel_TypeDef TIM3_Channel, TIM3_ICPolarity_TypeDef TIM3_ICPolarity, TIM3_ICSelection_TypeDef TIM3_ICSelection, TIM3_ICPSC_TypeDef TIM3_ICPrescaler, uint8_t TIM3_ICFilter);
  236. void TIM3_PWMIConfig(TIM3_Channel_TypeDef TIM3_Channel, TIM3_ICPolarity_TypeDef TIM3_ICPolarity, TIM3_ICSelection_TypeDef TIM3_ICSelection, TIM3_ICPSC_TypeDef TIM3_ICPrescaler, uint8_t TIM3_ICFilter);
  237. void TIM3_Cmd(FunctionalState NewState);
  238. void TIM3_ITConfig(TIM3_IT_TypeDef TIM3_IT, FunctionalState NewState);
  239. void TIM3_InternalClockConfig(void);
  240. void TIM3_UpdateDisableConfig(FunctionalState NewState);
  241. void TIM3_UpdateRequestConfig(TIM3_UpdateSource_TypeDef TIM3_UpdateSource);
  242. void TIM3_SelectOnePulseMode(TIM3_OPMode_TypeDef TIM3_OPMode);
  243. void TIM3_PrescalerConfig(TIM3_Prescaler_TypeDef Prescaler, TIM3_PSCReloadMode_TypeDef TIM3_PSCReloadMode);
  244. void TIM3_ForcedOC1Config(TIM3_ForcedAction_TypeDef TIM3_ForcedAction);
  245. void TIM3_ForcedOC2Config(TIM3_ForcedAction_TypeDef TIM3_ForcedAction);
  246. void TIM3_ARRPreloadConfig(FunctionalState NewState);
  247. void TIM3_CCPreloadControl(FunctionalState NewState);
  248. void TIM3_OC1PreloadConfig(FunctionalState NewState);
  249. void TIM3_OC2PreloadConfig(FunctionalState NewState);
  250. void TIM3_GenerateEvent(TIM3_EventSource_TypeDef TIM3_EventSource);
  251. void TIM3_OC1PolarityConfig(TIM3_OCPolarity_TypeDef TIM3_OCPolarity);
  252. void TIM3_OC2PolarityConfig(TIM3_OCPolarity_TypeDef TIM3_OCPolarity);
  253. void TIM3_CCxCmd(TIM3_Channel_TypeDef TIM3_Channel, FunctionalState NewState);
  254. void TIM3_SelectOCxM(TIM3_Channel_TypeDef TIM3_Channel, TIM3_OCMode_TypeDef TIM3_OCMode);
  255. void TIM3_SetCounter(uint16_t Counter);
  256. void TIM3_SetAutoreload(uint16_t Autoreload);
  257. void TIM3_SetCompare1(uint16_t Compare1);
  258. void TIM3_SetCompare2(uint16_t Compare2);
  259. void TIM3_SetIC1Prescaler(TIM3_ICPSC_TypeDef TIM3_IC1Prescaler);
  260. void TIM3_SetIC2Prescaler(TIM3_ICPSC_TypeDef TIM3_IC2Prescaler);
  261. uint16_t TIM3_GetCapture1(void);
  262. uint16_t TIM3_GetCapture2(void);
  263. uint16_t TIM3_GetCounter(void);
  264. TIM3_Prescaler_TypeDef TIM3_GetPrescaler(void);
  265. FlagStatus TIM3_GetFlagStatus(TIM3_FLAG_TypeDef TIM3_FLAG);
  266. void TIM3_ClearFlag(TIM3_FLAG_TypeDef TIM3_FLAG);
  267. ITStatus TIM3_GetITStatus(TIM3_IT_TypeDef TIM3_IT);
  268. void TIM3_ClearITPendingBit(TIM3_IT_TypeDef TIM3_IT);
  269. /**
  270. * @}
  271. */
  272. #endif /* __STM8S_TIM3_H */
  273. /**
  274. * @}
  275. */
  276. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/