stm8l15x_tim4.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_tim4.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 TIM4 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_TIM4_H
  30. #define __STM8L15x_TIM4_H
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "stm8l15x.h"
  33. /** @addtogroup STM8L15x_StdPeriph_Driver
  34. * @{
  35. */
  36. /** @addtogroup TIM4
  37. * @{
  38. */
  39. /* Exported types ------------------------------------------------------------*/
  40. /** @defgroup TIM4_Exported_Types
  41. * @{
  42. */
  43. /** @defgroup TIM4_Prescaler
  44. * @{
  45. */
  46. typedef enum
  47. {
  48. TIM4_Prescaler_1 = ((uint8_t)0x00), /*!< Time base Prescaler = 1 (No effect)*/
  49. TIM4_Prescaler_2 = ((uint8_t)0x01), /*!< Time base Prescaler = 2 */
  50. TIM4_Prescaler_4 = ((uint8_t)0x02), /*!< Time base Prescaler = 4 */
  51. TIM4_Prescaler_8 = ((uint8_t)0x03), /*!< Time base Prescaler = 8 */
  52. TIM4_Prescaler_16 = ((uint8_t)0x04), /*!< Time base Prescaler = 16 */
  53. TIM4_Prescaler_32 = ((uint8_t)0x05), /*!< Time base Prescaler = 32 */
  54. TIM4_Prescaler_64 = ((uint8_t)0x06), /*!< Time base Prescaler = 64 */
  55. TIM4_Prescaler_128 = ((uint8_t)0x07), /*!< Time base Prescaler = 128 */
  56. TIM4_Prescaler_256 = ((uint8_t)0x08), /*!< Time base Prescaler = 256 */
  57. TIM4_Prescaler_512 = ((uint8_t)0x09), /*!< Time base Prescaler = 512 */
  58. TIM4_Prescaler_1024 = ((uint8_t)0x0A), /*!< Time base Prescaler = 1024 */
  59. TIM4_Prescaler_2048 = ((uint8_t)0x0B), /*!< Time base Prescaler = 2048 */
  60. TIM4_Prescaler_4096 = ((uint8_t)0x0C), /*!< Time base Prescaler = 4096 */
  61. TIM4_Prescaler_8192 = ((uint8_t)0x0D), /*!< Time base Prescaler = 8196 */
  62. TIM4_Prescaler_16384 = ((uint8_t)0x0E), /*!< Time base Prescaler = 16384 */
  63. TIM4_Prescaler_32768 = ((uint8_t)0x0F) /*!< Time base Prescaler = 32768 */
  64. }TIM4_Prescaler_TypeDef;
  65. /**
  66. * @}
  67. */
  68. /** @defgroup TIM4_One_Pulse_Mode
  69. * @{
  70. */
  71. typedef enum
  72. {
  73. TIM4_OPMode_Single = ((uint8_t) 0x01), /*!< Single one Pulse mode (OPM Active) */
  74. TIM4_OPMode_Repetitive = ((uint8_t) 0x00) /*!< Repetitive Pulse mode (OPM inactive) */
  75. }TIM4_OPMode_TypeDef;
  76. /**
  77. * @}
  78. */
  79. /** @defgroup TIM4_Reload_Mode_Prescaler
  80. * @{
  81. */
  82. typedef enum
  83. {
  84. TIM4_PSCReloadMode_Update = ((uint8_t)0x00), /*!< Prescaler value is reloaded at every update */
  85. TIM4_PSCReloadMode_Immediate = ((uint8_t)0x01) /*!< Prescaler value is reloaded immediatly */
  86. }TIM4_PSCReloadMode_TypeDef;
  87. /**
  88. * @}
  89. */
  90. /** @defgroup TIM4_Update_Source
  91. * @{
  92. */
  93. typedef enum
  94. {
  95. TIM4_UpdateSource_Global = ((uint8_t)0x00), /*!< Global Update request source */
  96. TIM4_UpdateSource_Regular = ((uint8_t)0x01) /*!< Regular Update request source */
  97. }TIM4_UpdateSource_TypeDef;
  98. /**
  99. * @}
  100. */
  101. /** @defgroup TIM4_Event_Source
  102. * @{
  103. */
  104. typedef enum
  105. {
  106. TIM4_EventSource_Update = ((uint8_t)0x01), /*!< Update Event */
  107. TIM4_EventSource_Trigger = ((uint8_t)0x40) /*!< Trigger Event */
  108. }TIM4_EventSource_TypeDef;
  109. /**
  110. * @}
  111. */
  112. /** @defgroup TIM4_Trigger_Output_Source
  113. * @{
  114. */
  115. typedef enum
  116. {
  117. TIM4_TRGOSource_Reset = ((uint8_t)0x00), /*!< Trigger Output source = Reset */
  118. TIM4_TRGOSource_Enable = ((uint8_t)0x10), /*!< Trigger Output source = TIM4 is enabled */
  119. TIM4_TRGOSource_Update = ((uint8_t)0x20) /*!< Trigger Output source = Update event */
  120. }TIM4_TRGOSource_TypeDef;
  121. /**
  122. * @}
  123. */
  124. /** @defgroup TIM4_Salve_Mode
  125. * @{
  126. */
  127. typedef enum
  128. {
  129. TIM4_SlaveMode_Disable = ((uint8_t)0x00), /*!< Disable slave mode to clock the prescaler
  130. directly with the internal clock */
  131. TIM4_SlaveMode_Reset = ((uint8_t)0x04), /*!< Slave Mode Selection = Reset*/
  132. TIM4_SlaveMode_Gated = ((uint8_t)0x05), /*!< Slave Mode Selection = Gated*/
  133. TIM4_SlaveMode_Trigger = ((uint8_t)0x06), /*!< Slave Mode Selection = Trigger*/
  134. TIM4_SlaveMode_External1 = ((uint8_t)0x07) /*!< Slave Mode Selection = External 1*/
  135. }TIM4_SlaveMode_TypeDef;
  136. /**
  137. * @}
  138. */
  139. /** @defgroup TIM4_Flags
  140. * @{
  141. */
  142. typedef enum
  143. {
  144. TIM4_FLAG_Update = ((uint8_t)0x01), /*!< Update Flag */
  145. TIM4_FLAG_Trigger = ((uint8_t)0x40) /*!< Trigger Flag */
  146. }TIM4_FLAG_TypeDef;
  147. /**
  148. * @}
  149. */
  150. /** @defgroup TIM4_Interrupts
  151. * @{
  152. */
  153. typedef enum
  154. {
  155. TIM4_IT_Update = ((uint8_t)0x01), /*!< Update Interrupt*/
  156. TIM4_IT_Trigger = ((uint8_t)0x40) /*!< Trigger Interrupt*/
  157. }TIM4_IT_TypeDef;
  158. /**
  159. * @}
  160. */
  161. /** @defgroup TIM4_Internal_Trigger_Selection
  162. * @{
  163. */
  164. typedef enum
  165. {
  166. TIM4_TRGSelection_TIM5 = ((uint8_t)0x00), /*!< TRIG Input source = TIM5 TRIG Output */
  167. TIM4_TRGSelection_TIM1 = ((uint8_t)0x10), /*!< TRIG Input source = TIM1 TRIG Output */
  168. TIM4_TRGSelection_TIM3 = ((uint8_t)0x20), /*!< TRIG Input source = TIM3 TRIG Output */
  169. TIM4_TRGSelection_TIM2 = ((uint8_t)0x30) /*!< TRIG Input source = TIM2 TRIG Output */
  170. }TIM4_TRGSelection_TypeDef;
  171. /**
  172. * @}
  173. */
  174. /** @defgroup TIM4_DMA_source_requests
  175. * @{
  176. */
  177. typedef enum
  178. {
  179. TIM4_DMASource_Update = ((uint8_t)0x01) /*!< TIM4 DMA Update Request*/
  180. }TIM4_DMASource_TypeDef;
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @}
  186. */
  187. /* Exported constants --------------------------------------------------------*/
  188. /* Exported macros -----------------------------------------------------------*/
  189. /** @defgroup TIM4_Exported_Macros
  190. * @{
  191. */
  192. /**
  193. * @brief Macro used by the assert function to check the different functions parameters.
  194. */
  195. /**
  196. * @brief Macro TIM4 Prescaler
  197. */
  198. #define IS_TIM4_Prescaler(PRESCALER) \
  199. (((PRESCALER) == TIM4_Prescaler_1) || \
  200. ((PRESCALER) == TIM4_Prescaler_2) || \
  201. ((PRESCALER) == TIM4_Prescaler_4) || \
  202. ((PRESCALER) == TIM4_Prescaler_8) || \
  203. ((PRESCALER) == TIM4_Prescaler_16) || \
  204. ((PRESCALER) == TIM4_Prescaler_32) || \
  205. ((PRESCALER) == TIM4_Prescaler_64) || \
  206. ((PRESCALER) == TIM4_Prescaler_128) || \
  207. ((PRESCALER) == TIM4_Prescaler_256) || \
  208. ((PRESCALER) == TIM4_Prescaler_512) || \
  209. ((PRESCALER) == TIM4_Prescaler_1024) || \
  210. ((PRESCALER) == TIM4_Prescaler_2048) || \
  211. ((PRESCALER) == TIM4_Prescaler_4096) || \
  212. ((PRESCALER) == TIM4_Prescaler_8192) || \
  213. ((PRESCALER) == TIM4_Prescaler_16384)|| \
  214. ((PRESCALER) == TIM4_Prescaler_32768))
  215. /**
  216. * @brief Macro TIM4 One Pulse Mode
  217. */
  218. #define IS_TIM4_OPM_MODE(MODE) \
  219. (((MODE) == TIM4_OPMode_Single) || \
  220. ((MODE) == TIM4_OPMode_Repetitive))
  221. /**
  222. * @brief Macro TIM4 Prescaler reload
  223. */
  224. #define IS_TIM4_Prescaler_RELOAD(RELOAD) \
  225. (((RELOAD) == TIM4_PSCReloadMode_Update) || \
  226. ((RELOAD) == TIM4_PSCReloadMode_Immediate))
  227. /**
  228. * @brief Macro TIM4 Update source
  229. */
  230. #define IS_TIM4_UPDATE_SOURCE(SOURCE) \
  231. (((SOURCE) == TIM4_UpdateSource_Global) || \
  232. ((SOURCE) == TIM4_UpdateSource_Regular))
  233. /**
  234. * @brief Macro TIM4 Event source
  235. */
  236. #define IS_TIM4_EVENT_SOURCE(SOURCE) \
  237. ((((SOURCE) & (uint8_t)0xBE) == 0x00) && \
  238. ((SOURCE) != 0x00))
  239. /**
  240. * @brief Macro TIM4 TRGO source
  241. */
  242. #define IS_TIM4_TRGO_SOURCE(SOURCE) \
  243. (((SOURCE) == TIM4_TRGOSource_Reset) || \
  244. ((SOURCE) == TIM4_TRGOSource_Enable)|| \
  245. ((SOURCE) == TIM4_TRGOSource_Update))
  246. /**
  247. * @brief Macro TIM4 Slave mode
  248. */
  249. #define IS_TIM4_SLAVE_MODE(MODE) \
  250. (((MODE) == TIM4_SlaveMode_Disable) || \
  251. ((MODE) == TIM4_SlaveMode_Reset) || \
  252. ((MODE) == TIM4_SlaveMode_Gated) || \
  253. ((MODE) == TIM4_SlaveMode_Trigger) || \
  254. ((MODE) == TIM4_SlaveMode_External1))
  255. /**
  256. * @brief Macro TIM4 Flags
  257. */
  258. #define IS_TIM4_GET_FLAG(FLAG) \
  259. (((FLAG) == TIM4_FLAG_Update) || \
  260. ((FLAG) == TIM4_FLAG_Trigger))
  261. #define IS_TIM4_CLEAR_FLAG(FLAG) \
  262. ((((FLAG) & (uint8_t)0xBE) == 0x00) && ((FLAG) != 0x00))
  263. /**
  264. * @brief Macro TIM4 interrupts
  265. */
  266. #define IS_TIM4_IT(IT) \
  267. (((IT) != 0x00) && \
  268. (((uint8_t)(IT) & (uint8_t)(~(uint8_t)(0x41)))== 0x00))
  269. #define IS_TIM4_GET_IT(IT) \
  270. (((IT) == TIM4_IT_Update) || \
  271. ((IT) == TIM4_IT_Trigger))
  272. /**
  273. * @brief Macro TIM4 Trigger selection
  274. */
  275. #define IS_TIM4_TRIGGER_SELECTION(SELECTION) \
  276. (((SELECTION) == TIM4_TRGSelection_TIM5) || \
  277. ((SELECTION) == TIM4_TRGSelection_TIM1) || \
  278. ((SELECTION) == TIM4_TRGSelection_TIM3) || \
  279. ((SELECTION) == TIM4_TRGSelection_TIM2))
  280. /**
  281. * @brief Macro TIM4 DMA sources
  282. */
  283. #define IS_TIM4_DMA_SOURCE(SOURCE) (((SOURCE) == TIM4_DMASource_Update))
  284. /**
  285. * @}
  286. */
  287. /* Exported functions --------------------------------------------------------*/
  288. /* TimeBase management ********************************************************/
  289. void TIM4_DeInit(void);
  290. void TIM4_TimeBaseInit(TIM4_Prescaler_TypeDef TIM4_Prescaler,
  291. uint8_t TIM4_Period);
  292. void TIM4_PrescalerConfig(TIM4_Prescaler_TypeDef Prescaler,
  293. TIM4_PSCReloadMode_TypeDef TIM4_PSCReloadMode);
  294. void TIM4_SetCounter(uint8_t Counter);
  295. void TIM4_SetAutoreload(uint8_t Autoreload);
  296. uint8_t TIM4_GetCounter(void);
  297. TIM4_Prescaler_TypeDef TIM4_GetPrescaler(void);
  298. void TIM4_UpdateDisableConfig(FunctionalState NewState);
  299. void TIM4_UpdateRequestConfig(TIM4_UpdateSource_TypeDef TIM4_UpdateSource);
  300. void TIM4_ARRPreloadConfig(FunctionalState NewState);
  301. void TIM4_SelectOnePulseMode(TIM4_OPMode_TypeDef TIM4_OPMode);
  302. void TIM4_Cmd(FunctionalState NewState);
  303. /* Interrupts, DMA and flags management ***************************************/
  304. void TIM4_ITConfig(TIM4_IT_TypeDef TIM4_IT, FunctionalState NewState);
  305. void TIM4_GenerateEvent(TIM4_EventSource_TypeDef TIM4_EventSource);
  306. FlagStatus TIM4_GetFlagStatus(TIM4_FLAG_TypeDef TIM4_FLAG);
  307. void TIM4_ClearFlag(TIM4_FLAG_TypeDef TIM4_FLAG);
  308. ITStatus TIM4_GetITStatus(TIM4_IT_TypeDef TIM4_IT);
  309. void TIM4_ClearITPendingBit(TIM4_IT_TypeDef TIM4_IT);
  310. void TIM4_DMACmd(TIM4_DMASource_TypeDef TIM4_DMASource, FunctionalState NewState);
  311. /* Clocks management **********************************************************/
  312. void TIM4_InternalClockConfig(void);
  313. /* Synchronization management *************************************************/
  314. void TIM4_SelectInputTrigger(TIM4_TRGSelection_TypeDef TIM4_InputTriggerSource);
  315. void TIM4_SelectOutputTrigger(TIM4_TRGOSource_TypeDef TIM4_TRGOSource);
  316. void TIM4_SelectSlaveMode(TIM4_SlaveMode_TypeDef TIM4_SlaveMode);
  317. void TIM4_SelectMasterSlaveMode(FunctionalState NewState);
  318. #endif /* __STM8L15x_TIM4_H */
  319. /**
  320. * @}
  321. */
  322. /**
  323. * @}
  324. */
  325. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/