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.

61 lines
1.4 KiB

2 years 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. public:
  21. ZTIM() {}
  22. void initialize(zchip_tim_t *htim, mode_t mode);
  23. mode_t getMode();
  24. /******************************************************
  25. * kTimMode_timer *
  26. ******************************************************/
  27. /**
  28. * @brief startTimer
  29. *
  30. * @param periodus ʱ
  31. * @param onirq صΪnull,ʹϴעĻص
  32. */
  33. void simpleTimer_regCb(ontimirq_t cb) { m_simpleTimer_cb = cb; }
  34. void simpleTimer_startByPeriod(uint32_t periodus);
  35. void simpleTimer_startByFreq(float freq);
  36. void simpleTimer_stop();
  37. /*******************************************************************************
  38. * PWM_MODE *
  39. *******************************************************************************/
  40. void setPWMFreq(float freq);
  41. void startPWM(uint32_t Channel, float duty);
  42. void stopPWM(uint32_t Channel);
  43. };
  44. } // namespace iflytop
  45. #endif