From baafde681f0e2f87659d06e8801f9ec9ea1c2277 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 3 Feb 2024 16:42:56 +0800 Subject: [PATCH] zcan board module add pwm driver --- chip/api/zi_pwm_ctrl.hpp | 12 ++++++++---- components/zcancmder/zcan_board_module.cpp | 31 ++++++++++++++++++++++-------- components/zcancmder/zcan_board_module.hpp | 3 +++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/chip/api/zi_pwm_ctrl.hpp b/chip/api/zi_pwm_ctrl.hpp index f974fb3..df1fb22 100644 --- a/chip/api/zi_pwm_ctrl.hpp +++ b/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 diff --git a/components/zcancmder/zcan_board_module.cpp b/components/zcancmder/zcan_board_module.cpp index 6f0d22e..cc89044 100644 --- a/components/zcancmder/zcan_board_module.cpp +++ b/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); } \ No newline at end of file diff --git a/components/zcancmder/zcan_board_module.hpp b/components/zcancmder/zcan_board_module.hpp index 490beb3..71fbbe7 100644 --- a/components/zcancmder/zcan_board_module.hpp +++ b/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 \ No newline at end of file