You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.7 KiB

1 year ago
  1. #pragma once
  2. #include <functional>
  3. #include "basic/base.hpp"
  4. #ifdef HAL_TIM_MODULE_ENABLED
  5. namespace iflytop {
  6. using namespace iflytop;
  7. class ZTIM {
  8. public:
  9. typedef enum {
  10. ktm_null,
  11. ktm_timer,
  12. ktm_pwm,
  13. } mode_t;
  14. typedef function<void()> ontimirq_t;
  15. private:
  16. zchip_tim_t *m_htim;
  17. mode_t m_mode;
  18. volatile bool m_timer_start;
  19. ontimirq_t m_simpleTimer_cb;
  20. bool m_timpwmPolarity[4];
  21. public:
  22. ZTIM() {}
  23. void initialize(zchip_tim_t *htim, mode_t mode);
  24. mode_t getMode();
  25. /******************************************************
  26. * kTimMode_timer *
  27. ******************************************************/
  28. /**
  29. * @brief startTimer
  30. *
  31. * @param periodus
  32. * @param onirq null,使
  33. */
  34. void simpleTimer_regCb(ontimirq_t cb) { m_simpleTimer_cb = cb; }
  35. void simpleTimer_startByPeriod(uint32_t periodus);
  36. void simpleTimer_startByFreq(float freq);
  37. void simpleTimer_stop();
  38. /*******************************************************************************
  39. * PWM_MODE *
  40. *******************************************************************************/
  41. /**
  42. * @brief
  43. *
  44. * @param Channel PWM通道 TIM_CHANNEL_1 TIM_CHANNEL_2 TIM_CHANNEL_3 TIM_CHANNEL_4
  45. * @param Polarity 1:0
  46. */
  47. void setPWMPolarity(uint32_t Channel, uint32_t Polarity);
  48. void setPWMFreq(float freq);
  49. void startPWM(uint32_t Channel, float duty);
  50. void stopPWM(uint32_t Channel);
  51. };
  52. } // namespace iflytop
  53. #endif