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

#pragma once
#include <functional>
#include "sdk/basic/base.hpp"
#ifdef HAL_TIM_MODULE_ENABLED
namespace iflytop {
using namespace iflytop;
class ZTIM {
public:
typedef enum {
ktm_null,
ktm_timer,
ktm_pwm,
} mode_t;
typedef function<void()> ontimirq_t;
private:
zchip_tim_t *m_htim;
mode_t m_mode;
volatile bool m_timer_start;
ontimirq_t m_simpleTimer_cb;
bool m_timpwmPolarity[4];
public:
ZTIM() {}
void initialize(zchip_tim_t *htim, mode_t mode);
mode_t getMode();
/******************************************************
* kTimMode_timer *
******************************************************/
/**
* @brief startTimer
*
* @param periodus 定时器周期
* @param onirq 回调函数,如果为null,则使用上次注册的回调函数
*/
void simpleTimer_regCb(ontimirq_t cb) { m_simpleTimer_cb = cb; }
void simpleTimer_startByPeriod(uint32_t periodus);
void simpleTimer_startByFreq(float freq);
void simpleTimer_stop();
/*******************************************************************************
* PWM_MODE *
*******************************************************************************/
/**
* @brief
*
* @param Channel PWM通道 TIM_CHANNEL_1 TIM_CHANNEL_2 TIM_CHANNEL_3 TIM_CHANNEL_4
* @param Polarity 1:高为有效电平,0:低为有效电平
*/
void setPWMPolarity(uint32_t Channel, uint32_t Polarity);
void setPWMFreq(float freq);
void startPWM(uint32_t Channel, float duty);
void stopPWM(uint32_t Channel);
};
} // namespace iflytop
#endif