#include #include "by_fan_control.h" #include "zf_common_headfile.h" #include "jj_blueteeth.h" #include "jj_motion.h" #define FAN_LL_PWM_PIN TIM8_PWM_MAP1_CH1_B6 // 左升力风扇 #define FAN_RL_PWM_PIN TIM8_PWM_MAP1_CH2_B7 // 右升力风扇 // M4 #define FAN_RB_PWM_PIN TIM10_PWM_MAP3_CH4_D7 #define FAN_LB_PWM_PIN TIM4_PWM_MAP1_CH2_D13 #define FAN_LS_PWM_PIN TIM1_PWM_MAP0_CH4_A11 #define FAN_RS_PWM_PIN TIM1_PWM_MAP0_CH1_A8 int32_t pwm_duty_ls_g; int32_t pwm_duty_rs_g; int32_t pwm_duty_lb_g; int32_t pwm_duty_rb_g; inline static uint32_t clip_u32(uint32_t x, uint32_t low, uint32_t up) { return (x > up ? up : x < low ? low : x); } inline static int32_t clip_s32(int32_t x, int32_t low, int32_t up) { return (x > up ? up : x < low ? low : x); } inline static float clip_f32(float x, float low, float up) { return (x > up ? up : x < low ? low : x); } #define FIX_DRIVE 0 void by_pwm_init(void) { gpio_init(D4, GPO, 1, GPO_PUSH_PULL); gpio_init(C8, GPO, 1, GPO_PUSH_PULL); pwm_init(FAN_LL_PWM_PIN, 50, 500); pwm_init(FAN_RL_PWM_PIN, 50, 500); pwm_init(FAN_LS_PWM_PIN, 50, 500); pwm_init(FAN_RS_PWM_PIN, 50, 500); pwm_init(FAN_LB_PWM_PIN, 300, 300); pwm_init(FAN_RB_PWM_PIN, 300, 300); } /** * @brief 更新升力风扇占空比 * * @param update_pwm_duty1 * @param update_pwm_duty2 */ void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2) { update_pwm_duty1 = clip_u32(update_pwm_duty1, 500, 1000); update_pwm_duty2 = clip_u32(update_pwm_duty2, 500, 1000); pwm_set_duty(FAN_LL_PWM_PIN, update_pwm_duty1); pwm_set_duty(FAN_RL_PWM_PIN, update_pwm_duty2); } /** * @brief 更新动力风扇占空比 * * @param pwm_duty_ls * @param pwm_duty_rs * @param pwm_duty_lb * @param pwm_duty_rb */ void by_pwm_power_duty(int32_t bpwm_duty_ls, int32_t bpwm_duty_rs, int32_t bpwm_duty_lb, int32_t bpwm_duty_rb) { bpwm_duty_ls = clip_s32(bpwm_duty_ls, 500, 999); bpwm_duty_rs = clip_s32(bpwm_duty_rs, 500, 999); bpwm_duty_lb = clip_s32(bpwm_duty_lb, 2500, 6000); bpwm_duty_rb = clip_s32(bpwm_duty_rb, 2500, 6000); pwm_set_duty(FAN_LS_PWM_PIN, bpwm_duty_ls); pwm_set_duty(FAN_RS_PWM_PIN, bpwm_duty_rs); pwm_set_duty(FAN_LB_PWM_PIN, bpwm_duty_lb); pwm_set_duty(FAN_RB_PWM_PIN, bpwm_duty_rb); }