driver_tmr.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * @File name : driver_tmr.h
  3. * @Author : Bluetrum IOT Team
  4. * @Date : 2023-02-14
  5. * @Description : This file contains all the functions prototypes for the TMR library.
  6. *
  7. * Copyright (c) by Bluetrum, All Rights reserved.
  8. */
  9. #ifndef _DRIVER_TMR_H
  10. #define _DRIVER_TMR_H
  11. #include "driver_com.h"
  12. /**
  13. * @brief TMR Interrupt Flag Definition
  14. */
  15. typedef enum {
  16. TMR_IT_UPDATE = 0x01,
  17. TMR_IT_CAPTURE = 0x02,
  18. } TMR_IT_TYPEDEF;
  19. /**
  20. * @brief Clock Source Selection
  21. */
  22. typedef enum {
  23. TMR_INC_SOURCE = 0x00000000,
  24. TMR_PIN_SOURCE = 0x00000040,
  25. } TMR_COUNTER_TYPEDEF;
  26. /**
  27. * @brief Capture Edge Selection
  28. */
  29. typedef enum {
  30. TMR_CAP_NULL = 0x00000000,
  31. TMR_CAP_RISING = 0x00000010,
  32. TMR_CAP_FALLING = 0x00000020,
  33. TMR_CAP_EDGE = 0x00000030,
  34. } TMR_CAP_EDGE_TYPEDEF;
  35. /**
  36. * @brief Clock Triggle Selection
  37. */
  38. typedef enum {
  39. TMR_SYSTEM_CLOCK = 0x00000000,
  40. TMR_COUNTER_RISING = 0x00000004,
  41. TMR_COUNTER_FALLING = 0x00000008,
  42. TMR_COUNTER_EDGE = 0x0000000c,
  43. } TMR_CLOCK_TYPEDEF;
  44. /**
  45. * @brief PWM Mode Selection
  46. */
  47. typedef enum {
  48. TMR_PWM0 = 0x00000200,
  49. TMR_PWM1 = 0x00000400,
  50. TMR_PWM2 = 0x00000800,
  51. } TMR_PWM_TYPEDDEF;
  52. /**
  53. * @brief Timer Init Structure
  54. */
  55. typedef struct {
  56. uint32_t period;
  57. uint32_t prescale;
  58. TMR_COUNTER_TYPEDEF counter_source;
  59. TMR_CLOCK_TYPEDEF clock_source;
  60. } tmr_base_init_typedef;
  61. /********************** Function used to configure timer base **********************/
  62. void tmr_base_init(tmr_typedef *tmrx, tmr_base_init_typedef *tmr_base_init_struct);
  63. void tmr_deinit(tmr_typedef *tmrx);
  64. void tmr_set_counter(tmr_typedef *tmrx, uint32_t cnt);
  65. void tmr_set_period(tmr_typedef *tmrx, uint32_t period);
  66. void tmr_set_prescale(tmr_typedef *tmrx, uint16_t psc);
  67. uint32_t tmr_get_counter(tmr_typedef *tmrx);
  68. uint32_t tmr_get_period(tmr_typedef *tmrx);
  69. uint16_t tmr_get_prescale(tmr_typedef *tmrx);
  70. void tmr_cmd(tmr_typedef *tmrx, FUNCTIONAL_STATE state);
  71. /*************************** Function used to set pwm ******************************/
  72. void tmr_pwm_duty_config(tmr_typedef *tmrx, TMR_PWM_TYPEDDEF pwm, uint16_t duty);
  73. void tmr_pwm_cmd(tmr_typedef *tmrx, TMR_PWM_TYPEDDEF pwm, FUNCTIONAL_STATE state);
  74. /************************** Function used to set capture ***************************/
  75. uint32_t tmr_get_capture(tmr_typedef *tmrx);
  76. void tmr_capture_config(tmr_typedef *tmrx, TMR_CAP_EDGE_TYPEDEF edge_select);
  77. void tmr_capture_cmd(tmr_typedef *tmrx, FUNCTIONAL_STATE state);
  78. /********************** Function used to configure interrupt ***********************/
  79. void tmr_pic_config(tmr_typedef *tmrx, isr_t isr, int pr, TMR_IT_TYPEDEF interrupt_type, FUNCTIONAL_STATE state);
  80. FLAG_STATE tmr_get_flag(tmr_typedef *tmrx, TMR_IT_TYPEDEF interrupt_type);
  81. void tmr_clear_flag(tmr_typedef *tmrx, TMR_IT_TYPEDEF interrupt_type);
  82. #endif // _DRIVER_TMR_H