Browse Source

zcan board module add pwm driver

master
zhaohe 2 years ago
parent
commit
baafde681f
  1. 12
      chip/api/zi_pwm_ctrl.hpp
  2. 31
      components/zcancmder/zcan_board_module.cpp
  3. 3
      components/zcancmder/zcan_board_module.hpp

12
chip/api/zi_pwm_ctrl.hpp

@ -7,9 +7,13 @@ class ZIPWMCtrl {
public:
virtual ~ZIPWMCtrl(){};
virtual int32_t set_pwm_duty(int32_t duty) = 0;
virtual int32_t set_pwm_freq(int32_t freq) = 0;
virtual int32_t get_pwm_duty() = 0;
virtual int32_t get_pwm_freq() = 0;
virtual int32_t pwm_set_state(int32_t state) = 0;
virtual int32_t pwm_get_state(int32_t& state) = 0;
virtual int32_t set_pwm_duty(int32_t duty) = 0;
virtual int32_t get_pwm_duty(int32_t& duty) = 0;
virtual int32_t set_pwm_freq(int32_t freq) = 0;
virtual int32_t get_pwm_freq(int32_t& duty) = 0;
};
} // namespace iflytop

31
components/zcancmder/zcan_board_module.cpp

@ -119,6 +119,25 @@ int32_t ZCanBoardModule::readTemperature(int32_t sensorId, int32_t &temperature_
return temperature_sensor[sensorId]->getTemperature(temperature_val);
}
int32_t ZCanBoardModule::setPwmState(int32_t pwmId, int32_t state) {
if (pwmId < 0 || pwmId >= ZARRAY_SIZE(m_cfg.pwmctrl)) {
return err::kmodule_not_find_config_index;
}
if (m_cfg.pwmctrl[pwmId] == nullptr) {
return err::kmodule_not_find_config_index;
}
return m_cfg.pwmctrl[pwmId]->pwm_set_state(state);
}
int32_t ZCanBoardModule::getPwmState(int32_t pwmId, int32_t &state) {
if (pwmId < 0 || pwmId >= ZARRAY_SIZE(m_cfg.pwmctrl)) {
return err::kmodule_not_find_config_index;
}
if (m_cfg.pwmctrl[pwmId] == nullptr) {
return err::kmodule_not_find_config_index;
}
return m_cfg.pwmctrl[pwmId]->pwm_get_state(state);
}
int32_t ZCanBoardModule::readPwmDuty(int32_t pwmId, int32_t &duty) {
if (pwmId < 0 || pwmId >= ZARRAY_SIZE(m_cfg.pwmctrl)) {
return err::kmodule_not_find_config_index;
@ -126,8 +145,7 @@ int32_t ZCanBoardModule::readPwmDuty(int32_t pwmId, int32_t &duty) {
if (m_cfg.pwmctrl[pwmId] == nullptr) {
return err::kmodule_not_find_config_index;
}
duty = m_cfg.pwmctrl[pwmId]->get_pwm_duty();
return 0;
return m_cfg.pwmctrl[pwmId]->get_pwm_duty(duty);
}
int32_t ZCanBoardModule::setPwmDuty(int32_t pwmId, int32_t duty) {
if (pwmId < 0 || pwmId >= ZARRAY_SIZE(m_cfg.pwmctrl)) {
@ -136,8 +154,7 @@ int32_t ZCanBoardModule::setPwmDuty(int32_t pwmId, int32_t duty) {
if (m_cfg.pwmctrl[pwmId] == nullptr) {
return err::kmodule_not_find_config_index;
}
m_cfg.pwmctrl[pwmId]->set_pwm_duty(duty);
return 0;
return m_cfg.pwmctrl[pwmId]->set_pwm_duty(duty);
}
int32_t ZCanBoardModule::readPwmFreq(int32_t pwmId, int32_t &freq) {
@ -147,8 +164,7 @@ int32_t ZCanBoardModule::readPwmFreq(int32_t pwmId, int32_t &freq) {
if (m_cfg.pwmctrl[pwmId] == nullptr) {
return err::kmodule_not_find_config_index;
}
freq = m_cfg.pwmctrl[pwmId]->get_pwm_freq();
return 0;
return m_cfg.pwmctrl[pwmId]->get_pwm_freq(freq);
}
int32_t ZCanBoardModule::setPwmFreq(int32_t pwmId, int32_t freq) {
if (pwmId < 0 || pwmId >= ZARRAY_SIZE(m_cfg.pwmctrl)) {
@ -157,6 +173,5 @@ int32_t ZCanBoardModule::setPwmFreq(int32_t pwmId, int32_t freq) {
if (m_cfg.pwmctrl[pwmId] == nullptr) {
return err::kmodule_not_find_config_index;
}
m_cfg.pwmctrl[pwmId]->set_pwm_freq(freq);
return 0;
return m_cfg.pwmctrl[pwmId]->set_pwm_freq(freq);
}

3
components/zcancmder/zcan_board_module.hpp

@ -76,6 +76,9 @@ class ZCanBoardModule : public ZIModule {
int32_t readPwmFreq(int32_t pwmId, int32_t &freq);
int32_t setPwmFreq(int32_t pwmId, int32_t freq);
int32_t setPwmState(int32_t pwmId, int32_t state);
int32_t getPwmState(int32_t pwmId, int32_t &state);
};
} // namespace iflytop
Loading…
Cancel
Save