2024-03-24 18:24:32 +08:00
|
|
|
#include <stdio.h>
|
2023-12-15 21:42:43 +08:00
|
|
|
#include "by_fan_control.h"
|
|
|
|
|
#include "zf_common_headfile.h"
|
2024-03-28 04:24:59 +08:00
|
|
|
#include "jj_blueteeth.h"
|
2024-05-05 19:15:51 +08:00
|
|
|
#include "jj_motion.h"
|
2024-04-16 16:09:34 +08:00
|
|
|
#define FAN_LL_PWM_PIN TIM8_PWM_MAP1_CH1_B6 // 左升力风扇
|
|
|
|
|
#define FAN_RL_PWM_PIN TIM8_PWM_MAP1_CH2_B7 // 右升力风扇
|
|
|
|
|
// M4
|
2024-07-07 23:08:49 +08:00
|
|
|
#define FAN_RB_PWM_PIN TIM10_PWM_MAP3_CH4_D7
|
|
|
|
|
#define FAN_LB_PWM_PIN TIM4_PWM_MAP1_CH2_D13
|
2024-07-05 03:29:56 +08:00
|
|
|
#define FAN_LS_PWM_PIN TIM1_PWM_MAP0_CH4_A11
|
2024-07-07 23:08:49 +08:00
|
|
|
#define FAN_RS_PWM_PIN TIM1_PWM_MAP0_CH1_A8
|
2024-04-16 16:09:34 +08:00
|
|
|
int32_t pwm_duty_ls_g;
|
|
|
|
|
int32_t pwm_duty_rs_g;
|
|
|
|
|
int32_t pwm_duty_lb_g;
|
|
|
|
|
int32_t pwm_duty_rb_g;
|
2024-03-24 18:24:32 +08:00
|
|
|
|
2024-04-16 16:09:34 +08:00
|
|
|
inline static uint32_t clip_u32(uint32_t x, uint32_t low, uint32_t up)
|
2024-03-24 18:24:32 +08:00
|
|
|
{
|
|
|
|
|
return (x > up ? up : x < low ? low
|
|
|
|
|
: x);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 16:49:14 +08:00
|
|
|
inline static int32_t clip_s32(int32_t x, int32_t low, int32_t up)
|
2024-04-16 16:09:34 +08:00
|
|
|
{
|
|
|
|
|
return (x > up ? up : x < low ? low
|
|
|
|
|
: x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline static float clip_f32(float x, float low, float up)
|
2024-01-16 20:03:21 +08:00
|
|
|
{
|
|
|
|
|
return (x > up ? up : x < low ? low
|
|
|
|
|
: x);
|
|
|
|
|
}
|
2023-12-15 21:42:43 +08:00
|
|
|
|
2024-06-18 16:11:59 +08:00
|
|
|
#define FIX_DRIVE 0
|
2023-12-15 21:42:43 +08:00
|
|
|
void by_pwm_init(void)
|
|
|
|
|
{
|
2024-06-28 18:23:53 +08:00
|
|
|
gpio_init(D4, GPO, 1, GPO_PUSH_PULL);
|
|
|
|
|
gpio_init(C8, GPO, 1, GPO_PUSH_PULL);
|
2024-03-22 11:35:15 +08:00
|
|
|
pwm_init(FAN_LL_PWM_PIN, 50, 500);
|
|
|
|
|
pwm_init(FAN_RL_PWM_PIN, 50, 500);
|
2024-07-05 03:29:56 +08:00
|
|
|
pwm_init(FAN_LS_PWM_PIN, 50, 500);
|
|
|
|
|
pwm_init(FAN_RS_PWM_PIN, 50, 500);
|
2024-07-07 23:08:49 +08:00
|
|
|
pwm_init(FAN_LB_PWM_PIN, 300, 300);
|
|
|
|
|
pwm_init(FAN_RB_PWM_PIN, 300, 300);
|
2023-12-15 21:42:43 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-22 11:35:15 +08:00
|
|
|
/**
|
|
|
|
|
* @brief 更新升力风扇占空比
|
|
|
|
|
*
|
|
|
|
|
* @param update_pwm_duty1
|
|
|
|
|
* @param update_pwm_duty2
|
|
|
|
|
*/
|
2024-01-16 20:03:21 +08:00
|
|
|
void by_pwm_update_duty(uint32_t update_pwm_duty1, uint32_t update_pwm_duty2)
|
2023-12-15 21:42:43 +08:00
|
|
|
{
|
2024-04-16 16:09:34 +08:00
|
|
|
update_pwm_duty1 = clip_u32(update_pwm_duty1, 500, 1000);
|
|
|
|
|
update_pwm_duty2 = clip_u32(update_pwm_duty2, 500, 1000);
|
2024-03-22 11:35:15 +08:00
|
|
|
pwm_set_duty(FAN_LL_PWM_PIN, update_pwm_duty1);
|
|
|
|
|
pwm_set_duty(FAN_RL_PWM_PIN, update_pwm_duty2);
|
2023-12-15 21:42:43 +08:00
|
|
|
}
|
2024-03-22 11:35:15 +08:00
|
|
|
|
2024-03-02 16:05:24 +08:00
|
|
|
/**
|
2024-03-22 11:35:15 +08:00
|
|
|
* @brief 更新动力风扇占空比
|
|
|
|
|
*
|
|
|
|
|
* @param pwm_duty_ls
|
|
|
|
|
* @param pwm_duty_rs
|
|
|
|
|
* @param pwm_duty_lb
|
|
|
|
|
* @param pwm_duty_rb
|
2024-03-02 16:05:24 +08:00
|
|
|
*/
|
2024-05-05 19:15:51 +08:00
|
|
|
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)
|
2023-12-15 21:42:43 +08:00
|
|
|
{
|
2024-08-09 17:00:24 +08:00
|
|
|
bpwm_duty_ls = clip_s32(bpwm_duty_ls, 500, 980);
|
|
|
|
|
bpwm_duty_rs = clip_s32(bpwm_duty_rs, 500, 980);
|
2024-07-07 23:08:49 +08:00
|
|
|
bpwm_duty_lb = clip_s32(bpwm_duty_lb, 2500, 6000);
|
|
|
|
|
bpwm_duty_rb = clip_s32(bpwm_duty_rb, 2500, 6000);
|
2024-07-05 03:29:56 +08:00
|
|
|
pwm_set_duty(FAN_LS_PWM_PIN, bpwm_duty_ls);
|
|
|
|
|
pwm_set_duty(FAN_RS_PWM_PIN, bpwm_duty_rs);
|
2024-07-07 23:08:49 +08:00
|
|
|
pwm_set_duty(FAN_LB_PWM_PIN, bpwm_duty_lb);
|
|
|
|
|
pwm_set_duty(FAN_RB_PWM_PIN, bpwm_duty_rb);
|
|
|
|
|
}
|