apm32f0xx_tmr.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*!
  2. * @file apm32f0xx_tmr.h
  3. *
  4. * @brief This file contains all functions prototype and macros for the TMR peripheral
  5. *
  6. * @version V1.0.3
  7. *
  8. * @date 2022-09-20
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. #ifndef __APM32F0XX_TMR_H
  26. #define __APM32F0XX_TMR_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #include "apm32f0xx.h"
  31. /** @addtogroup APM32F0xx_StdPeriphDriver
  32. @{
  33. */
  34. /** @addtogroup TMR_Driver TMR Driver
  35. @{
  36. */
  37. /** @defgroup TMR_Marcos Marcos
  38. @{
  39. */
  40. /**@} end of group TMR_Marcos */
  41. /** @defgroup TMR_Enumerations Enumerations
  42. @{
  43. */
  44. /**
  45. * @brief Counter_Mode
  46. */
  47. typedef enum
  48. {
  49. TMR_COUNTER_MODE_UP = 0, /*!< Timer Up Counting Mode */
  50. TMR_COUNTER_MODE_DOWN = 1, /*!< Timer Down Counting Mode */
  51. TMR_COUNTER_MODE_CENTERALIGNED1 = 2, /*!< Timer Center Aligned Mode1 */
  52. TMR_COUNTER_MODE_CENTERALIGNED2 = 4, /*!< Timer Center Aligned Mode2 */
  53. TMR_COUNTER_MODE_CENTERALIGNED3 = 6 /*!< Timer Center Aligned Mode3 */
  54. } TMR_COUNTER_MODE_T;
  55. /**
  56. * @brief Clock_Division_CKD
  57. */
  58. typedef enum
  59. {
  60. TMR_CKD_DIV1 = 0, /*!< TDTS = Tck_tim */
  61. TMR_CKD_DIV2 = 1, /*!< TDTS = 2 * Tck_tim */
  62. TMR_CKD_DIV4 = 2 /*!< TDTS = 4 * Tck_tim */
  63. } TMR_CKD_T;
  64. /**
  65. * @brief Prescaler_Reload_Mode
  66. */
  67. typedef enum
  68. {
  69. TMR_PRESCALER_RELOAD_UPDATA = 0, /*!< The Prescaler reload at the update event */
  70. TMR_PRESCALER_RELOAD_IMMEDIATE = 1 /*!< The Prescaler reload immediately */
  71. } TMR_PRESCALER_RELOAD_T;
  72. /**
  73. * @brief TMR UpdateSource
  74. */
  75. typedef enum
  76. {
  77. TMR_UPDATE_SOURCE_GLOBAL = 0, /*!< Source of update is Counter overflow/underflow.
  78. - UEG bit of Control event generation register(CEG) is set.
  79. - Update generation through the slave mode controller. */
  80. TMR_UPDATE_SOURCE_REGULAR = 1 /*!< Source of update is Counter overflow/underflow */
  81. } TMR_UPDATE_SOURCE_T;
  82. /**
  83. * @brief TMR OPMode
  84. */
  85. typedef enum
  86. {
  87. TMR_OPMODE_REPETITIVE = 0, /*!< Enable repetitive pulse mode */
  88. TMR_OPMODE_SINGLE = 1 /*!< Enable single pulse mode */
  89. } TMR_OPMODE_T;
  90. /**
  91. * @brief TMR Specifies the Off-State selection used in Run mode
  92. */
  93. typedef enum
  94. {
  95. TMR_RMOS_STATE_DISABLE = 0, /*!< Disable run mode off-state */
  96. TMR_RMOS_STATE_ENABLE = 1 /*!< Enable run mode off-state */
  97. } TMR_RMOS_STATE_T;
  98. /**
  99. * @brief TMR Closed state configuration in idle mode
  100. */
  101. typedef enum
  102. {
  103. TMR_IMOS_STATE_DISABLE = 0, /*!< Disable idle mode off-state */
  104. TMR_IMOS_STATE_ENABLE = 1 /*!< Enable idle mode off-state */
  105. } TMR_IMOS_STATE_T;
  106. /**
  107. * @brief TMR Protect mode configuration values
  108. */
  109. typedef enum
  110. {
  111. TMR_LOCK_LEVEL_OFF = 0, /*!< No lock write protection */
  112. TMR_LOCK_LEVEL_1 = 1, /*!< Lock write protection level 1 */
  113. TMR_LOCK_LEVEL_2 = 2, /*!< Lock write protection level 2 */
  114. TMR_LOCK_LEVEL_3 = 3 /*!< Lock write protection level 3 */
  115. } TMR_LOCK_LEVEL_T;
  116. /**
  117. * @brief TMR break state
  118. */
  119. typedef enum
  120. {
  121. TMR_BREAK_STATE_DISABLE, /*!< Disable brake function */
  122. TMR_BREAK_STATE_ENABLE /*!< Enable brake function */
  123. } TMR_BREAK_STATE_T;
  124. /**
  125. * @brief TMR Specifies the Break Input pin polarity.
  126. */
  127. typedef enum
  128. {
  129. TMR_BREAK_POLARITY_LOW, /*!< BREAK low level valid */
  130. TMR_BREAK_POLARITY_HIGH /*!< BREAK high level valid */
  131. } TMR_BREAK_POLARITY_T;
  132. /**
  133. * @brief TMR Automatic Output feature is enable or disable
  134. */
  135. typedef enum
  136. {
  137. TMR_AUTOMATIC_OUTPUT_DISABLE, /*!< Disable automatic output */
  138. TMR_AUTOMATIC_OUTPUT_ENABLE /*!< Enable automatic output */
  139. } TMR_AUTOMATIC_OUTPUT_T;
  140. /**
  141. * @brief TMR_Output_Compare_and_PWM_modes
  142. */
  143. typedef enum
  144. {
  145. TMR_OC_MODE_TMRING = 0x00, /*!< Frozen TMR output compare mode */
  146. TMR_OC_MODE_ACTIVE = 0x01, /*!< Set output to high when matching */
  147. TMR_OC_MODE_INACTIVE = 0x02, /*!< Set output to low when matching */
  148. TMR_OC_MODE_TOGGEL = 0x03, /*!< Toggle output when matching */
  149. TMR_OC_MODE_LOWLEVEL = 0x04, /*!< Force output to be low */
  150. TMR_OC_MODE_HIGHLEVEL = 0x05, /*!< Force output to be high */
  151. TMR_OC_MODE_PWM1 = 0x06, /*!< PWM1 mode */
  152. TMR_OC_MODE_PWM2 = 0x07 /*!< PWM2 mode */
  153. } TMR_OC_MODE_T;
  154. /**
  155. * @brief TMR_Output_Compare_state
  156. */
  157. typedef enum
  158. {
  159. TMR_OUTPUT_STATE_DISABLE, /*!< Disable output compare */
  160. TMR_OUTPUT_STATE_ENABLE /*!< Enable output compare */
  161. } TMR_OC_OUTPUT_STATE_T;
  162. /**
  163. * @brief TMR_Output_Compare_N_state
  164. */
  165. typedef enum
  166. {
  167. TMR_OUTPUT_NSTATE_DISABLE, /*!< Disable complementary output */
  168. TMR_OUTPUT_NSTATE_ENABLE /*!< Enable complementary output */
  169. } TMR_OC_OUTPUT_NSTATE_T;
  170. /**
  171. * @brief TMR_Output_Compare_Polarity
  172. */
  173. typedef enum
  174. {
  175. TMR_OC_POLARITY_HIGH, /*!< Output Compare active high */
  176. TMR_OC_POLARITY_LOW /*!< Output Compare active low */
  177. } TMR_OC_POLARITY_T;
  178. /**
  179. * @brief TMR_Output_Compare_N_Polarity
  180. */
  181. typedef enum
  182. {
  183. TMR_OC_NPOLARITY_HIGH, /*!< Output Compare active high */
  184. TMR_OC_NPOLARITY_LOW /*!< Output Compare active low */
  185. } TMR_OC_NPOLARITY_T;
  186. /**
  187. * @brief TMR_Output_Compare_Idle_State
  188. */
  189. typedef enum
  190. {
  191. TMR_OCIDLESTATE_RESET, /*!< Reset output compare idle state */
  192. TMR_OCIDLESTATE_SET /*!< Set output compare idle state */
  193. } TMR_OC_IDLE_STATE_T;
  194. /**
  195. * @brief TMR_Output_Compare_N_Idle_State
  196. */
  197. typedef enum
  198. {
  199. TMR_OCNIDLESTATE_RESET, /*!< Reset output complementary idle state */
  200. TMR_OCNIDLESTATE_SET /*!< Set output complementary idle state */
  201. } TMR_OC_NIDLE_STATE_T;
  202. /**
  203. * @brief TMR Input Capture Init structure definition
  204. */
  205. typedef enum
  206. {
  207. TMR_CHANNEL_1 = 0x0000, /*!< Timer Channel 1 */
  208. TMR_CHANNEL_2 = 0x0004, /*!< Timer Channel 2 */
  209. TMR_CHANNEL_3 = 0x0008, /*!< Timer Channel 3 */
  210. TMR_CHANNEL_4 = 0x000C /*!< Timer Channel 4 */
  211. } TMR_CHANNEL_T;
  212. /**
  213. * @brief TMR ForcedAction
  214. */
  215. typedef enum
  216. {
  217. TMR_FORCEDACTION_INACTIVE = 0x04, /*!< Force inactive level on OC1REF */
  218. TMR_FORCEDACTION_ACTIVE = 0x05 /*!< Force active level on OC1REF */
  219. } TMR_FORCED_ACTION_T;
  220. /**
  221. * @brief TMR Output_Compare_Preload_State
  222. */
  223. typedef enum
  224. {
  225. TMR_OC_PRELOAD_DISABLE, /*!< Disable preload */
  226. TMR_OC_PRELOAD_ENABLE /*!< Enable preload */
  227. } TMR_OC_PRELOAD_T;
  228. /**
  229. * @brief TMR Output_Compare_Fast_State
  230. */
  231. typedef enum
  232. {
  233. TMR_OCFAST_DISABLE, /*!< Disable fast output compare */
  234. TMR_OCFAST_ENABLE /*!< Enable fast output compare */
  235. } TMR_OCFAST_T;
  236. /**
  237. * @brief TMR Output_Compare_Clear_State
  238. */
  239. typedef enum
  240. {
  241. TMR_OCCLER_DISABLE, /*!< Disable output compare clear */
  242. TMR_OCCLER_ENABLE /*!< Enable output compare clear */
  243. } TMR_OCCLER_T;
  244. /**
  245. * @brief TMR_OCReferenceClear Clear source
  246. */
  247. typedef enum
  248. {
  249. TMR_OCCS_ETRF, /*!< Select ETRF as clear source */
  250. TMR_OCCS_OCREFCLR /*!< Select OCREFCLR as clear source */
  251. } TMR_OCCSEL_T;
  252. /**
  253. * @brief TMR Input_Capture_Polarity
  254. */
  255. typedef enum
  256. {
  257. TMR_IC_POLARITY_RISING = 0x00, /*!< Rising edge */
  258. TMR_IC_POLARITY_FALLING = 0x02, /*!< Falling edge */
  259. TMR_IC_POLARITY_BOTHEDGE = 0x0A /*!< Both rising and falling edge */
  260. } TMR_IC_POLARITY_T;
  261. /**
  262. * @brief TMR Input_Capture_Selection
  263. */
  264. typedef enum
  265. {
  266. TMR_IC_SELECTION_DIRECT_TI = 0x01, /*!< Input capture mapping in TI1 */
  267. TMR_IC_SELECTION_INDIRECT_TI = 0x02, /*!< Input capture mapping in TI2 */
  268. TMR_IC_SELECTION_TRC = 0x03 /*!< Input capture mapping in TRC */
  269. } TMR_IC_SELECTION_T;
  270. /**
  271. * @brief TMR_Input_Capture_Prescaler
  272. */
  273. typedef enum
  274. {
  275. TMR_ICPSC_DIV1 = 0x00, /*!< No prescaler */
  276. TMR_ICPSC_DIV2 = 0x01, /*!< Capture is done once every 2 events */
  277. TMR_ICPSC_DIV4 = 0x02, /*!< capture is done once every 4 events */
  278. TMR_ICPSC_DIV8 = 0x03 /*!< capture is done once every 8 events */
  279. } TMR_IC_PRESCALER_T;
  280. /**
  281. * @brief TMR_interrupt_sources
  282. */
  283. typedef enum
  284. {
  285. TMR_INT_UPDATE = 0x0001, /*!< Timer update Interrupt source */
  286. TMR_INT_CH1 = 0x0002, /*!< Timer Capture Compare 1 Interrupt source */
  287. TMR_INT_CH2 = 0x0004, /*!< Timer Capture Compare 2 Interrupt source */
  288. TMR_INT_CH3 = 0x0008, /*!< Timer Capture Compare 3 Interrupt source */
  289. TMR_INT_CH4 = 0x0010, /*!< Timer Capture Compare 4 Interrupt source */
  290. TMR_INT_CCU = 0x0020, /*!< Timer Commutation Interrupt */
  291. TMR_INT_TRG = 0x0040, /*!< Timer Trigger Interrupt source */
  292. TMR_INT_BRK = 0x0080 /*!< Timer Break Interrupt source */
  293. } TMR_INT_T;
  294. /**
  295. * @brief TMR_event_sources
  296. */
  297. typedef enum
  298. {
  299. TMR_EVENT_UPDATE = 0x0001, /*!< Timer update Interrupt source */
  300. TMR_EVENT_CH1 = 0x0002, /*!< Timer Capture Compare 1 Event source */
  301. TMR_EVENT_CH2 = 0x0004, /*!< Timer Capture Compare 2 Event source */
  302. TMR_EVENT_CH3 = 0x0008, /*!< Timer Capture Compare 3 Event source */
  303. TMR_EVENT_CH4 = 0x0010, /*!< Timer Capture Compare 4 Event source */
  304. TMR_EVENT_CCU = 0x0020, /*!< Timer Commutation Event source */
  305. TMR_EVENT_TRG = 0x0040, /*!< Timer Trigger Event source */
  306. TMR_EVENT_BRK = 0x0080 /*!< Timer Break Event source */
  307. } TMR_EVENT_T;
  308. /**
  309. * @brief TMR_interrupt_flag
  310. */
  311. typedef enum
  312. {
  313. TMR_INT_FLAG_UPDATE = 0x0001, /*!< Timer update Interrupt source */
  314. TMR_INT_FLAG_CH1 = 0x0002, /*!< Timer Capture Compare 1 Interrupt source */
  315. TMR_INT_FLAG_CH2 = 0x0004, /*!< Timer Capture Compare 2 Interrupt source */
  316. TMR_INT_FLAG_CH3 = 0x0008, /*!< Timer Capture Compare 3 Interrupt source */
  317. TMR_INT_FLAG_CH4 = 0x0010, /*!< Timer Capture Compare 4 Interrupt source */
  318. TMR_INT_FLAG_CCU = 0x0020, /*!< Timer Commutation Interrupt source */
  319. TMR_INT_FLAG_TRG = 0x0040, /*!< Timer Trigger Interrupt source */
  320. TMR_INT_FLAG_BRK = 0x0080 /*!< Timer Break Interrupt source */
  321. } TMR_INT_FLAG_T;
  322. /**
  323. * @brief TMR Flag
  324. */
  325. typedef enum
  326. {
  327. TMR_FLAG_UPDATE = 0x0001, /*!< Timer update Flag */
  328. TMR_FLAG_CH1 = 0x0002, /*!< Timer Capture Compare 1 Flag */
  329. TMR_FLAG_CH2 = 0x0004, /*!< Timer Capture Compare 2 Flag */
  330. TMR_FLAG_CH3 = 0x0008, /*!< Timer Capture Compare 3 Flag */
  331. TMR_FLAG_CH4 = 0x0010, /*!< Timer Capture Compare 4 Flag */
  332. TMR_FLAG_CCU = 0x0020, /*!< Timer Commutation Flag */
  333. TMR_FLAG_TRG = 0x0040, /*!< Timer Trigger Flag */
  334. TMR_FLAG_BRK = 0x0080, /*!< Timer Break Flag (Only for TMR1 and TMR8) */
  335. TMR_FLAG_CH1OC = 0x0200, /*!< Timer Capture Compare 1 Repetition Flag */
  336. TMR_FLAG_CH2OC = 0x0400, /*!< Timer Capture Compare 2 Repetition Flag */
  337. TMR_FLAG_CH3OC = 0x0800, /*!< Timer Capture Compare 3 Repetition Flag */
  338. TMR_FLAG_CH4OC = 0x1000 /*!< Timer Capture Compare 4 Repetition Flag */
  339. } TMR_FLAG_T;
  340. /**
  341. * @brief TMR DMA Base Address
  342. */
  343. typedef enum
  344. {
  345. TMR_DMABASE_CTRL1 = 0x0000, /*!< TMR CTRL1 DMA base address setup */
  346. TMR_DMABASE_CTRL2 = 0x0001, /*!< TMR CTRL2 DMA base address setup */
  347. TMR_DMABASE_SMCTRL = 0x0002, /*!< TMR SMCTRL DMA base address setup */
  348. TMR_DMABASE_DIEN = 0x0003, /*!< TMR DIEN DMA base address setup */
  349. TMR_DMABASE_STS = 0x0004, /*!< TMR STS DMA base address setup */
  350. TMR_DMABASE_CEG = 0x0005, /*!< TMR CEG DMA base address setup */
  351. TMR_DMABASE_CCM1 = 0x0006, /*!< TMR CCM1 DMA base address setup */
  352. TMR_DMABASE_CCM2 = 0x0007, /*!< TMR CCM2 DMA base address setup */
  353. TMR_DMABASE_CHCTRL = 0x0008, /*!< TMR CHCTRL DMA base address setup */
  354. TMR_DMABASE_CNT = 0x0009, /*!< TMR CNT DMA base address setup */
  355. TMR_DMABASE_DIV = 0x000A, /*!< TMR DIV DMA base address setup */
  356. TMR_DMABASE_AUTORLD = 0x000B, /*!< TMR AUTORLD DMA base address setup */
  357. TMR_DMABASE_REPCNT = 0x000C, /*!< TMR REPCNT DMA base address setup */
  358. TMR_DMABASE_CH1CC = 0x000D, /*!< TMR CH1CC DMA base address setup */
  359. TMR_DMABASE_CH2CC = 0x000E, /*!< TMR CH2CC DMA base address setup */
  360. TMR_DMABASE_CH3CC = 0x000F, /*!< TMR CH3CC DMA base address setup */
  361. TMR_DMABASE_CH4CC = 0x0010, /*!< TMR CH4CC DMA base address setup */
  362. TMR_DMABASE_BDT = 0x0011, /*!< TMR BDT DMA base address setup */
  363. TMR_DMABASE_DMAB = 0x0012 /*!< TMR DMAB DMA base address setup */
  364. } TMR_DMA_BASE_ADDERSS_T;
  365. /**
  366. * @brief TMR DMA Burst Lenght
  367. */
  368. typedef enum
  369. {
  370. TMR_DMA_BURSTLENGHT_1TRANSFER = 0x0000, /*!< Select TMR DMA burst Length 1 */
  371. TMR_DMA_BURSTLENGHT_2TRANSFERS = 0x0100, /*!< Select TMR DMA burst Length 2 */
  372. TMR_DMA_BURSTLENGHT_3TRANSFERS = 0x0200, /*!< Select TMR DMA burst Length 3 */
  373. TMR_DMA_BURSTLENGHT_4TRANSFERS = 0x0300, /*!< Select TMR DMA burst Length 4 */
  374. TMR_DMA_BURSTLENGHT_5TRANSFERS = 0x0400, /*!< Select TMR DMA burst Length 5 */
  375. TMR_DMA_BURSTLENGHT_6TRANSFERS = 0x0500, /*!< Select TMR DMA burst Length 6 */
  376. TMR_DMA_BURSTLENGHT_7TRANSFERS = 0x0600, /*!< Select TMR DMA burst Length 7 */
  377. TMR_DMA_BURSTLENGHT_8TRANSFERS = 0x0700, /*!< Select TMR DMA burst Length 8 */
  378. TMR_DMA_BURSTLENGHT_9TRANSFERS = 0x0800, /*!< Select TMR DMA burst Length 9 */
  379. TMR_DMA_BURSTLENGHT_10TRANSFERS = 0x0900, /*!< Select TMR DMA burst Length 10 */
  380. TMR_DMA_BURSTLENGHT_11TRANSFERS = 0x0A00, /*!< Select TMR DMA burst Length 11 */
  381. TMR_DMA_BURSTLENGHT_12TRANSFERS = 0x0B00, /*!< Select TMR DMA burst Length 12 */
  382. TMR_DMA_BURSTLENGHT_13TRANSFERS = 0x0C00, /*!< Select TMR DMA burst Length 13 */
  383. TMR_DMA_BURSTLENGHT_14TRANSFERS = 0x0D00, /*!< Select TMR DMA burst Length 14 */
  384. TMR_DMA_BURSTLENGHT_15TRANSFERS = 0x0E00, /*!< Select TMR DMA burst Length 15 */
  385. TMR_DMA_BURSTLENGHT_16TRANSFERS = 0x0F00, /*!< Select TMR DMA burst Length 16 */
  386. TMR_DMA_BURSTLENGHT_17TRANSFERS = 0x1000, /*!< Select TMR DMA burst Length 17 */
  387. TMR_DMA_BURSTLENGHT_18TRANSFERS = 0x1100, /*!< Select TMR DMA burst Length 18 */
  388. } TMR_DMA_BURST_LENGHT_T;
  389. /**
  390. * @brief TMR DMA Soueces
  391. */
  392. typedef enum
  393. {
  394. TMR_DMA_UPDATE = 0x0100, /*!< TMR update DMA souces */
  395. TMR_DMA_CH1 = 0x0200, /*!< TMR Capture Compare 1 DMA souces */
  396. TMR_DMA_CH2 = 0x0400, /*!< TMR Capture Compare 2 DMA souces */
  397. TMR_DMA_CH3 = 0x0800, /*!< TMR Capture Compare 3 DMA souces */
  398. TMR_DMA_CH4 = 0x1000, /*!< TMR Capture Compare 4 DMA souces */
  399. TMR_DMA_CCU = 0x2000, /*!< TMR Commutation DMA souces */
  400. TMR_DMA_TRG = 0x4000 /*!< TMR Trigger DMA souces */
  401. } TMR_DMA_SOUCES_T;
  402. /**
  403. * @brief TMR Internal_Trigger_Selection
  404. */
  405. typedef enum
  406. {
  407. TMR_TS_ITR0 = 0x00, /*!< Internal Trigger 0 */
  408. TMR_TS_ITR1 = 0x01, /*!< Internal Trigger 1 */
  409. TMR_TS_ITR2 = 0x02, /*!< Internal Trigger 2 */
  410. TMR_TS_ITR3 = 0x03, /*!< Internal Trigger 3 */
  411. TMR_TS_TI1F_ED = 0x04, /*!< TI1 Edge Detector */
  412. TMR_TS_TI1FP1 = 0x05, /*!< Filtered Timer Input 1 */
  413. TMR_TS_TI2FP2 = 0x06, /*!< Filtered Timer Input 2 */
  414. TMR_TS_ETRF = 0x07 /*!< External Trigger input */
  415. } TMR_INPUT_TRIGGER_SOURCE_T;
  416. /**
  417. * @brief TMR The external Trigger Prescaler.
  418. */
  419. typedef enum
  420. {
  421. TMR_ExtTRGPSC_OFF = 0x00, /*!< ETRP Prescaler OFF */
  422. TMR_EXTTRGPSC_DIV2 = 0x01, /*!< ETRP frequency divided by 2 */
  423. TMR_EXTTRGPSC_DIV4 = 0x02, /*!< ETRP frequency divided by 4 */
  424. TMR_EXTTRGPSC_DIV8 = 0x03 /*!< ETRP frequency divided by 8 */
  425. } TMR_EXTTRG_PRESCALER_T;
  426. /**
  427. * @brief TMR External_Trigger_Polarity
  428. */
  429. typedef enum
  430. {
  431. TMR_EXTTRGPOLARITY_INVERTED = 0x01, /*!< Active low or falling edge active */
  432. TMR_EXTTGRPOLARITY_NONINVERTED = 0x00 /*!< Active high or rising edge active */
  433. } TMR_EXTTRG_POLARITY_T;
  434. /**
  435. * @brief TMR OPMode
  436. */
  437. typedef enum
  438. {
  439. TMR_TRGOSOURCE_RESET, /*!< Select reset signal as TRGO source */
  440. TMR_TRGOSOURCE_ENABLE, /*!< Select enable signal as TRGO source */
  441. TMR_TRGOSOURCE_UPDATE, /*!< Select update signal as TRGO source */
  442. TMR_TRGOSOURCE_OC1, /*!< Select OC1 signal as TRGO source */
  443. TMR_TRGOSOURCE_OC1REF, /*!< Select OC1REF signal as TRGO source */
  444. TMR_TRGOSOURCE_OC2REF, /*!< Select OC2REF signal as TRGO source */
  445. TMR_TRGOSOURCE_OC3REF, /*!< Select OC3REF signal as TRGO source */
  446. TMR_TRGOSOURCE_OC4REF /*!< Select OC4REF signal as TRGO source */
  447. } TMR_TRGOSOURCE_T;
  448. /**
  449. * @brief TMR OPMode
  450. */
  451. typedef enum
  452. {
  453. TMR_SLAVEMODE_RESET = 0x04, /*!< Reset mode */
  454. TMR_SLAVEMODE_GATED = 0x05, /*!< Gated mode */
  455. TMR_SLAVEMODE_TRIGGER = 0x06, /*!< Trigger mode */
  456. TMR_SLAVEMODE_EXTERNALL = 0x07 /*!< External 1 mode */
  457. } TMR_SLAVEMODE_T;
  458. /**
  459. * @brief TMR Encoder_Mode
  460. */
  461. typedef enum
  462. {
  463. TMR_ENCODER_MODE_TI1 = 0x01, /*!< Encoder mode 1 */
  464. TMR_ENCODER_MODE_TI2 = 0x02, /*!< Encoder mode 2 */
  465. TMR_ENCODER_MODE_TI12 = 0x03 /*!< Encoder mode 3 */
  466. } TMR_ENCODER_MODE_T;
  467. /**
  468. * @brief TMR Remap Select
  469. */
  470. typedef enum
  471. {
  472. TMR_REMAP_GPIO = 0x00, /*!< TMR input is connected to GPIO */
  473. TMR_REMAP_RTC_CLK = 0x01, /*!< TMR input is connected to RTC clock */
  474. TMR_REMAP_HSEDiv32 = 0x02, /*!< TMR input is connected to HSE clock/32 */
  475. TMR_REMAP_MCO = 0x03 /*!< TMR input is connected to MCO */
  476. } TMR_REMAP_T;
  477. /**@} end of group TMR_Enumerations*/
  478. /** @defgroup TMR_Structures Stuctures
  479. @{
  480. */
  481. /**
  482. * @brief TMR Time Base Init structure definition
  483. * @note This sturcture is used with all TMRx.
  484. */
  485. typedef struct
  486. {
  487. uint16_t div; /*!< This must between 0x0000 and 0xFFFF */
  488. TMR_COUNTER_MODE_T counterMode; /*!< TMR counter mode selection */
  489. uint32_t period; /*!< This must between 0x0000 and 0xFFFF */
  490. TMR_CKD_T clockDivision; /*!< TMR clock division selection */
  491. uint8_t repetitionCounter; /*!< This must between 0x00 and 0xFF, only for TMR1 and TMR8. */
  492. } TMR_TimeBase_T;
  493. /**
  494. * @brief TMR BDT structure definition
  495. */
  496. typedef struct
  497. {
  498. TMR_RMOS_STATE_T RMOS_State; /*!< TMR Specifies the Off-State selection used in Run mode selection */
  499. TMR_IMOS_STATE_T IMOS_State; /*!< TMR Closed state configuration in idle mode selection */
  500. TMR_LOCK_LEVEL_T lockLevel; /*!< TMR Protect mode configuration values selection */
  501. uint8_t deadTime; /*!< Setup dead time */
  502. TMR_BREAK_STATE_T breakState; /*!< Setup TMR BRK state */
  503. TMR_BREAK_POLARITY_T breakPolarity; /*!< Setup TMR BRK polarity */
  504. TMR_AUTOMATIC_OUTPUT_T automaticOutput; /*!< Setup break input pin polarity */
  505. } TMR_BDTInit_T;
  506. /**
  507. * @brief TMR Config struct definition
  508. */
  509. typedef struct
  510. {
  511. TMR_OC_MODE_T OC_Mode; /*!< Specifies the TMR mode. */
  512. TMR_OC_OUTPUT_STATE_T OC_OutputState; /*!< Specifies the TMR Output Compare state. */
  513. TMR_OC_OUTPUT_NSTATE_T OC_OutputNState; /*!< Specifies the TMR complementary Output Compare state. @note This parameter is valid only for TMR1 and TMR8. */
  514. TMR_OC_POLARITY_T OC_Polarity; /*!< Specifies the output polarity. */
  515. TMR_OC_NPOLARITY_T OC_NPolarity; /*!< Specifies the complementary output polarity. @note This parameter is valid only for TMR1 and TMR8. */
  516. TMR_OC_IDLE_STATE_T OC_Idlestate; /*!< Specifies the TMR Output Compare pin state during Idle state. @note This parameter is valid only for TMR1 and TMR8. */
  517. TMR_OC_NIDLE_STATE_T OC_NIdlestate; /*!< Specifies the TMR Output Compare pin state during Idle state. @note This parameter is valid only for TMR1 and TMR8. */
  518. uint16_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. */
  519. } TMR_OCConfig_T;
  520. /**
  521. * @brief TMR Input Capture Config struct definition
  522. */
  523. typedef struct
  524. {
  525. TMR_CHANNEL_T channel; /*!< Specifies the TMR channel. */
  526. TMR_IC_POLARITY_T ICpolarity; /*!< Specifies the active edge of the input signal. */
  527. TMR_IC_SELECTION_T ICselection; /*!< Specifies the input. */
  528. TMR_IC_PRESCALER_T ICprescaler; /*!< Specifies the Input Capture Prescaler. */
  529. uint16_t ICfilter; /*!< Specifies the input capture filter. */
  530. } TMR_ICConfig_T;
  531. /**@} end of group TMR_Structures*/
  532. /** @defgroup TMR_Variables Variables
  533. @{
  534. */
  535. /**@} end of group TMR_Variables */
  536. /** @defgroup TMR_Functions Functions
  537. @{
  538. */
  539. /* TimeBase management */
  540. void TMR_Reset(TMR_T* TMRx);
  541. void TMR_ConfigTimeBase(TMR_T* TMRx, TMR_TimeBase_T* timeBaseConfig);
  542. void TMR_ConfigTimeBaseStruct(TMR_TimeBase_T* timeBaseConfig);
  543. void TMR_ConfigDIV(TMR_T* TMRx, uint16_t div, TMR_PRESCALER_RELOAD_T mode);
  544. void TMR_ConfigCounterMode(TMR_T* TMRx, TMR_COUNTER_MODE_T mode);
  545. void TMR_SetCounter(TMR_T* TMRx, uint32_t counter);
  546. void TMR_SetAutoReload(TMR_T* TMRx, uint32_t autoReload);
  547. uint32_t TMR_ReadCounter(TMR_T* TMRx);
  548. uint32_t TMR_ReadDiv(TMR_T* TMRx);
  549. void TMR_EnableNGUpdate(TMR_T* TMRx);
  550. void TMR_DisableNGUpdate(TMR_T* TMRx);
  551. void TMR_ConfigUPdateRequest(TMR_T* TMRx, TMR_UPDATE_SOURCE_T source);
  552. void TMR_EnableAUTOReload(TMR_T* TMRx);
  553. void TMR_DisableAUTOReload(TMR_T* TMRx);
  554. void TMR_SetClockDivision(TMR_T* TMRx, TMR_CKD_T clockDivision);
  555. void TMR_Enable(TMR_T* TMRx);
  556. void TMR_Disable(TMR_T* TMRx);
  557. void TMR_ConfigBDT(TMR_T* TMRx, TMR_BDTInit_T* structure);
  558. void TMR_ConfigBDTStructInit(TMR_BDTInit_T* structure);
  559. void TMR_EnablePWMOutputs(TMR_T* TMRx);
  560. void TMR_DisablePWMOutputs(TMR_T* TMRx);
  561. void TMR_OC1Config(TMR_T* TMRx, TMR_OCConfig_T* OCcongigStruct);
  562. void TMR_OC2Config(TMR_T* TMRx, TMR_OCConfig_T* OCcongigStruct);
  563. void TMR_OC3Config(TMR_T* TMRx, TMR_OCConfig_T* OCcongigStruct);
  564. void TMR_OC4Config(TMR_T* TMRx, TMR_OCConfig_T* OCcongigStruct);
  565. void TMR_OCConfigStructInit(TMR_OCConfig_T* OCcongigStruct);
  566. void TMR_SelectOCxMode(TMR_T* TMRx, TMR_CHANNEL_T channel, TMR_OC_MODE_T mode);
  567. void TMR_SelectSlaveMode(TMR_T* TMRx, TMR_SLAVEMODE_T mode);
  568. void TMR_SelectOnePulseMode(TMR_T* TMRx, TMR_OPMODE_T OPMode);
  569. void TMR_SetCompare1(TMR_T* TMRx, uint32_t compare);
  570. void TMR_SetCompare2(TMR_T* TMRx, uint32_t compare);
  571. void TMR_SetCompare3(TMR_T* TMRx, uint32_t compare);
  572. void TMR_SetCompare4(TMR_T* TMRx, uint32_t compare);
  573. void TMR_ForcedOC1Config(TMR_T* TMRx, TMR_FORCED_ACTION_T action);
  574. void TMR_ForcedOC2Config(TMR_T* TMRx, TMR_FORCED_ACTION_T action);
  575. void TMR_ForcedOC3Config(TMR_T* TMRx, TMR_FORCED_ACTION_T action);
  576. void TMR_ForcedOC4Config(TMR_T* TMRx, TMR_FORCED_ACTION_T action);
  577. void TMR_EnableCCPreload(TMR_T* TMRx);
  578. void TMR_DisableCCPreload(TMR_T* TMRx);
  579. void TMR_OC1PreloadConfig(TMR_T* TMRx, TMR_OC_PRELOAD_T OCPreload);
  580. void TMR_OC2PreloadConfig(TMR_T* TMRx, TMR_OC_PRELOAD_T OCPreload);
  581. void TMR_OC3PreloadConfig(TMR_T* TMRx, TMR_OC_PRELOAD_T OCPreload);
  582. void TMR_OC4PreloadConfig(TMR_T* TMRx, TMR_OC_PRELOAD_T OCPreload);
  583. void TMR_OC1FastConfit(TMR_T* TMRx, TMR_OCFAST_T OCFast);
  584. void TMR_OC2FastConfit(TMR_T* TMRx, TMR_OCFAST_T OCFast);
  585. void TMR_OC3FastConfit(TMR_T* TMRx, TMR_OCFAST_T OCFast);
  586. void TMR_OC4FastConfit(TMR_T* TMRx, TMR_OCFAST_T OCFast);
  587. void TMR_OC1PolarityConfig(TMR_T* TMRx, TMR_OC_POLARITY_T OCPolarity);
  588. void TMR_OC1NPolarityConfig(TMR_T* TMRx, TMR_OC_NPOLARITY_T OCNPolarity);
  589. void TMR_OC2PolarityConfig(TMR_T* TMRx, TMR_OC_POLARITY_T OCPolarity);
  590. void TMR_OC2NPolarityConfig(TMR_T* TMRx, TMR_OC_NPOLARITY_T OCNPolarity);
  591. void TMR_OC3PolarityConfig(TMR_T* TMRx, TMR_OC_POLARITY_T OCPolarity);
  592. void TMR_OC3NPolarityConfig(TMR_T* TMRx, TMR_OC_NPOLARITY_T OCNPolarity);
  593. void TMR_OC4PolarityConfig(TMR_T* TMRx, TMR_OC_POLARITY_T OCPolarity);
  594. void TMR_SelectOCREFClear(TMR_T* TMRx, TMR_OCCSEL_T OCReferenceClear);
  595. void TMR_EnableCCxChannel(TMR_T* TMRx, TMR_CHANNEL_T channel);
  596. void TMR_DisableCCxChannel(TMR_T* TMRx, TMR_CHANNEL_T channel);
  597. void TMR_EnableCCxNChannel(TMR_T* TMRx, TMR_CHANNEL_T channel);
  598. void TMR_DisableCCxNChannel(TMR_T* TMRx, TMR_CHANNEL_T channel);
  599. void TMR_EnableAUTOReload(TMR_T* TMRx);
  600. void TMR_DisableAUTOReload(TMR_T* TMRx);
  601. void TMR_EnableSelectCOM(TMR_T* TMRx);
  602. void TMR_DisableSelectCOM(TMR_T* TMRx);
  603. void TMR_ICConfig(TMR_T* TMRx, TMR_ICConfig_T* ICconfigstruct);
  604. void TMR_ICConfigStructInit(TMR_ICConfig_T* ICconfigstruct);
  605. void TMR_PWMConfig(TMR_T* TMRx, TMR_ICConfig_T* ICconfigstruct);
  606. uint16_t TMR_ReadCaputer1(TMR_T* TMRx);
  607. uint16_t TMR_ReadCaputer2(TMR_T* TMRx);
  608. uint16_t TMR_ReadCaputer3(TMR_T* TMRx);
  609. uint16_t TMR_ReadCaputer4(TMR_T* TMRx);
  610. void TMR_SetIC1Prescal(TMR_T* TMRx, TMR_IC_PRESCALER_T prescaler);
  611. void TMR_SetIC2Prescal(TMR_T* TMRx, TMR_IC_PRESCALER_T prescaler);
  612. void TMR_SetIC3Prescal(TMR_T* TMRx, TMR_IC_PRESCALER_T prescaler);
  613. void TMR_SetIC4Prescal(TMR_T* TMRx, TMR_IC_PRESCALER_T prescaler);
  614. /* Interrupts and Event management functions */
  615. void TMR_EnableInterrupt(TMR_T* TMRx, uint16_t interrupt);
  616. void TMR_DisableInterrupt(TMR_T* TMRx, uint16_t interrupt);
  617. void TMR_GenerateEvent(TMR_T* TMRx, uint16_t event);
  618. uint16_t TMR_ReadStatusFlag(TMR_T* TMRx, TMR_FLAG_T flag);
  619. void TMR_ClearStatusFlag(TMR_T* TMRx, uint16_t flag);
  620. uint16_t TMR_ReadIntFlag(TMR_T* TMRx, TMR_INT_FLAG_T flag);
  621. void TMR_ClearIntFlag(TMR_T* TMRx, uint16_t flag);
  622. void TMR_ConfigDMA(TMR_T* TMRx, TMR_DMA_BASE_ADDERSS_T address, TMR_DMA_BURST_LENGHT_T lenght);
  623. void TMR_EnableDMASoure(TMR_T* TMRx, uint16_t souces);
  624. void TMR_DisableDMASoure(TMR_T* TMRx, uint16_t souces);
  625. void TMR_EnableCCDMA(TMR_T* TMRx);
  626. void TMR_DisableCCDMA(TMR_T* TMRx);
  627. /* Clocks management */
  628. void TMR_ConfigInternalClock(TMR_T* TMRx);
  629. void TMR_ConfigITRxExternalClock(TMR_T* TMRx, TMR_INPUT_TRIGGER_SOURCE_T input);
  630. void TMR_ConfigTIxExternalClock(TMR_T* TMRx, TMR_INPUT_TRIGGER_SOURCE_T input,
  631. TMR_IC_POLARITY_T ICpolarity, uint16_t ICfilter);
  632. void TMR_ConfigExternalClockMode1(TMR_T* TMRx, TMR_EXTTRG_PRESCALER_T prescaler,
  633. TMR_EXTTRG_POLARITY_T polarity, uint16_t filter);
  634. void TMR_ConfigExternalClockMode2(TMR_T* TMRx, TMR_EXTTRG_PRESCALER_T prescaler,
  635. TMR_EXTTRG_POLARITY_T polarity, uint16_t filter);
  636. /* Synchronization management */
  637. void TMR_SelectInputTrigger(TMR_T* TMRx, TMR_INPUT_TRIGGER_SOURCE_T input);
  638. void TMR_SelectOutputTrigger(TMR_T* TMRx, TMR_TRGOSOURCE_T source);
  639. void TMR_EnableMasterSlaveMode(TMR_T* TMRx);
  640. void TMR_DisableMasterSlaveMode(TMR_T* TMRx);
  641. void TMR_ConfigExternalTrigger(TMR_T* TMRx, TMR_EXTTRG_PRESCALER_T prescaler,
  642. TMR_EXTTRG_POLARITY_T polarity, uint16_t filter);
  643. /* Specific interface management */
  644. void TMR_ConfigEncodeInterface(TMR_T* TMRx, TMR_ENCODER_MODE_T encodeMode, TMR_IC_POLARITY_T IC1Polarity,
  645. TMR_IC_POLARITY_T IC2Polarity);
  646. void TMR_EnableHallSensor(TMR_T* TMRx);
  647. void TMR_DisableHallSensor(TMR_T* TMRx);
  648. /* Specific remapping management */
  649. void TMR_ConfigRemap(TMR_T* TMRx, TMR_REMAP_T remap);
  650. #ifdef __cplusplus
  651. }
  652. #endif
  653. #endif /* __APM32F0XX_TMR_H */
  654. /**@} end of group TMR_Functions */
  655. /**@} end of group TMR_Driver */
  656. /**@} end of group APM32F0xx_StdPeriphDriver */