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/chip/api/zi_temperature.hpp b/chip/api/zi_temperature.hpp index b40ae68..4c2a4ca 100644 --- a/chip/api/zi_temperature.hpp +++ b/chip/api/zi_temperature.hpp @@ -3,9 +3,9 @@ namespace iflytop { using namespace std; -class ZITemperatureSensor { +class ZITemperature { public: - virtual ~ZITemperatureSensor(){}; + virtual ~ZITemperature(){}; virtual int32_t getTemperature(int32_t& sensorval) = 0; }; diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp index 684d3a6..9a0372d 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -539,7 +539,6 @@ int32_t StepMotorCtrlModule::motor_move_by(int32_t dx, int32_t motor_velocity, i } int32_t StepMotorCtrlModule::motor_move_to(int32_t tox, int32_t motor_velocity, int32_t acc) { zlock_guard lock(m_lock); - ZLOGI(TAG, "m%d motor_move_to %d", m_id, tox); m_thread.stop(); if (m_param.min_d != 0 && tox < m_param.min_d) { diff --git a/components/sub_modbus_module/sub_modbus_board_initer.cpp b/components/sub_modbus_module/sub_modbus_board_initer.cpp index f9dc20a..4b43254 100644 --- a/components/sub_modbus_module/sub_modbus_board_initer.cpp +++ b/components/sub_modbus_module/sub_modbus_board_initer.cpp @@ -63,5 +63,8 @@ void SubModbusBoardIniter::loop() { ModulebusClient::Inst()->loop(); } } +<<<<<<< HEAD +======= +>>>>>>> 187b88da24aed4d0c06bb06e3158b01c2612b57d #endif \ No newline at end of file diff --git a/components/subcanmodule/zcancmder_subboard_initer.hpp b/components/subcanmodule/zcancmder_subboard_initer.hpp index 3c8055a..5c225b5 100644 --- a/components/subcanmodule/zcancmder_subboard_initer.hpp +++ b/components/subcanmodule/zcancmder_subboard_initer.hpp @@ -17,7 +17,7 @@ class ZCancmderSubboardIniter { int32_t deviceId; ZGPIO::InputGpioCfg_t input_gpio[32]; ZGPIO::OutputGpioCfg_t output_gpio[32]; - ZITemperatureSensor* temperature_sensor[8]; + ZITemperature* temperature_sensor[8]; ZIPWMCtrl* pwmctrl[8]; } cfg_t; diff --git a/components/tmc/ic/ztmc5130.cpp b/components/tmc/ic/ztmc5130.cpp index 2d51720..620422d 100644 --- a/components/tmc/ic/ztmc5130.cpp +++ b/components/tmc/ic/ztmc5130.cpp @@ -146,8 +146,23 @@ void TMC5130::setAcceleration(float accelerationpps2) { writeInt(TMC5130_AMAX void TMC5130::setDeceleration(float accelerationpps2) { writeInt(TMC5130_DMAX, (int32_t)(to_motor_acc(accelerationpps2))); } // 设置最大减速度 void TMC5130::setMotorShaft(bool reverse) { PRV_FIELD_WRITE(TMC5130_GCONF, TMC5130_SHAFT_MASK, TMC5130_SHAFT_SHIFT, reverse); } void TMC5130::setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay) { writeInt(TMC5130_IHOLD_IRUN, (iholddelay << TMC5130_IHOLDDELAY_SHIFT) | (irun << TMC5130_IRUN_SHIFT) | (ihold << TMC5130_IHOLD_SHIFT)); } -void TMC5130::setGlobalScale(uint8_t globalscale) { - // writeInt(TMC5130_GCONF, (readInt(TMC5130_GCONF) & ~TMC5130_SCALE_MASK) | (globalscale << TMC5130_SCALE_SHIFT)); + +#define TMC5160_GLOBAL_SCALER 0x0B +#define TMC5160_GLOBAL_SCALER_MASK 0xFF +#define TMC5160_GLOBAL_SCALER_SHIFT 0 + +void TMC5130::setGlobalScale(uint8_t globalscale) { // + if (globalscale == 0) { + globalscale = 0; + } else if (globalscale <= 31 || globalscale >= 1) { + globalscale = 32; + } else { + globalscale = globalscale; + } + writeInt(TMC5160_GLOBAL_SCALER, (readInt(TMC5160_GLOBAL_SCALER) & ~TMC5160_GLOBAL_SCALER_MASK) | (globalscale << TMC5160_GLOBAL_SCALER_SHIFT)); +} +uint8_t TMC5130::getGlobalScale() { // + return PRV_FIELD_READ(TMC5160_GLOBAL_SCALER, TMC5160_GLOBAL_SCALER_MASK, TMC5160_GLOBAL_SCALER_SHIFT); } uint32_t TMC5130::readICVersion() { diff --git a/components/tmc/ic/ztmc5130.hpp b/components/tmc/ic/ztmc5130.hpp index cf82cbc..f7be04f 100644 --- a/components/tmc/ic/ztmc5130.hpp +++ b/components/tmc/ic/ztmc5130.hpp @@ -127,6 +127,7 @@ class TMC5130 : public IStepperMotor { void setIHOLD_IRUN(uint8_t ihold, uint8_t irun, uint16_t iholddelay); void setGlobalScale(uint8_t globalscale); + uint8_t getGlobalScale(); // void setSubdivision(uint8_t subdivision); void setMotorShaft(bool reverse); // 设置电机旋转方向 diff --git a/components/zcancmder/zcan_board_module.cpp b/components/zcancmder/zcan_board_module.cpp index 5115015..a301e72 100644 --- a/components/zcancmder/zcan_board_module.cpp +++ b/components/zcancmder/zcan_board_module.cpp @@ -62,11 +62,20 @@ int32_t ZCanBoardModule::module_xxx_reg(int32_t param_id, bool read, int32_t &va PROCESS_REG(kreg_pwm0_duty, readPwmDuty(0, val), setPwmDuty(0, val)); PROCESS_REG(kreg_pwm1_duty, readPwmDuty(1, val), setPwmDuty(1, val)); PROCESS_REG(kreg_pwm2_duty, readPwmDuty(2, val), setPwmDuty(2, val)); - PROCESS_REG(kreg_pwm3_duty, readPwmDuty(2, val), setPwmDuty(2, val)); - PROCESS_REG(kreg_pwm4_duty, readPwmDuty(2, val), setPwmDuty(2, val)); - PROCESS_REG(kreg_pwm5_duty, readPwmDuty(2, val), setPwmDuty(2, val)); - PROCESS_REG(kreg_pwm6_duty, readPwmDuty(2, val), setPwmDuty(2, val)); - PROCESS_REG(kreg_pwm7_duty, readPwmDuty(2, val), setPwmDuty(2, val)); + PROCESS_REG(kreg_pwm3_duty, readPwmDuty(3, val), setPwmDuty(3, val)); + PROCESS_REG(kreg_pwm4_duty, readPwmDuty(4, val), setPwmDuty(4, val)); + PROCESS_REG(kreg_pwm5_duty, readPwmDuty(5, val), setPwmDuty(5, val)); + PROCESS_REG(kreg_pwm6_duty, readPwmDuty(6, val), setPwmDuty(6, val)); + PROCESS_REG(kreg_pwm7_duty, readPwmDuty(7, val), setPwmDuty(7, val)); + + PROCESS_REG(kreg_pwm0_ctrl, getPwmState(0, val), setPwmState(0, val)); + PROCESS_REG(kreg_pwm1_ctrl, getPwmState(1, val), setPwmState(1, val)); + PROCESS_REG(kreg_pwm2_ctrl, getPwmState(2, val), setPwmState(2, val)); + PROCESS_REG(kreg_pwm3_ctrl, getPwmState(3, val), setPwmState(3, val)); + PROCESS_REG(kreg_pwm4_ctrl, getPwmState(4, val), setPwmState(4, val)); + PROCESS_REG(kreg_pwm5_ctrl, getPwmState(5, val), setPwmState(5, val)); + PROCESS_REG(kreg_pwm6_ctrl, getPwmState(6, val), setPwmState(6, val)); + PROCESS_REG(kreg_pwm7_ctrl, getPwmState(7, val), setPwmState(7, val)); PROCESS_REG(kreg_pwm0_freq, readPwmFreq(0, val), setPwmFreq(0, val)); PROCESS_REG(kreg_pwm1_freq, readPwmFreq(1, val), setPwmFreq(1, val)); @@ -75,6 +84,7 @@ int32_t ZCanBoardModule::module_xxx_reg(int32_t param_id, bool read, int32_t &va PROCESS_REG(kreg_pwm4_freq, readPwmFreq(4, val), setPwmFreq(4, val)); PROCESS_REG(kreg_pwm5_freq, readPwmFreq(5, val), setPwmFreq(5, val)); PROCESS_REG(kreg_pwm6_freq, readPwmFreq(6, val), setPwmFreq(6, val)); + PROCESS_REG(kreg_pwm7_freq, readPwmFreq(7, val), setPwmFreq(7, val)); default: return err::kmodule_not_find_config_index; @@ -121,6 +131,25 @@ int32_t ZCanBoardModule::readTemperature(int32_t sensorId, int32_t &temperature_ return m_cfg.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; @@ -128,8 +157,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)) { @@ -138,8 +166,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) { @@ -149,8 +176,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)) { @@ -159,6 +185,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 d774090..dfe1685 100644 --- a/components/zcancmder/zcan_board_module.hpp +++ b/components/zcancmder/zcan_board_module.hpp @@ -35,15 +35,15 @@ class ZCanBoardModule : public ZIModule { typedef struct { ZGPIO::InputGpioCfg_t input[32]; ZGPIO::OutputGpioCfg_t output[32]; - ZITemperatureSensor *temperature_sensor[8]; + ZITemperature *temperature_sensor[8]; ZIPWMCtrl *pwmctrl[8]; } hardware_config_t; hardware_config_t m_cfg; int32_t module_id; - ZGPIO m_input[16]; - ZGPIO m_output[16]; + ZGPIO m_input[32]; + ZGPIO m_output[32]; int32_t m_input_num = 0; int32_t m_output_num = 0; @@ -74,6 +74,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 diff --git a/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp b/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp index 1d663dc..9b5ca7c 100644 --- a/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp +++ b/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp @@ -109,7 +109,7 @@ void MicroComputerModuleDeviceScriptCmderPaser::app_dump_reg(int moduleId, const if (ecode == 0) { if (type == kint) { ZLOGI(TAG, "%s(%d) :%d", configtag, configid, configval); - } else if (type == kint) { + } else if (type == kbit) { ZLOGI(TAG, "%s(%d) :%s", configtag, configid, dumpbit(configval)); } } else if (ecode != err::kmodule_not_find_config_index) {