bleSDK_expansion_board/projects/blezongkong/src/app_control_out.h

129 lines
3.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _APP_CONTROL_OUT_H_
#define _APP_CONTROL_OUT_H_
// ADC参考电压
#define VREF_1V2 1200
#define VREF_2V4 2400
#define VREF_VDD 3300
#define SADC_VREF VREF_2V4
// Dmin =(0.9V*(1024/3.3))/2 =139.6;
// Dmax =(3.8V*(1024/3.3))/2 =589.6;
// #define ACC_Dmin 138
// #define ACC_Dmax 591
extern uint16_t ACC_Dmin ;
extern uint16_t ACC_Dmax ;
#define ACC_ADC_init(VDD_val) ACC_Dmin =(880*(1024.0/(VDD_val)))/2; \
ACC_Dmax =(3820*(1024.0/(VDD_val)))/2;
#define ACC_PERCENT(s) (ACC_Dmin + ((ACC_Dmax - ACC_Dmin)*(s))/100)
enum app_adc_dac_chx{
ACC_IN_CH =SADC_CH_AIN7, // 油门输入
ACC_FEED_CH =SADC_CH_AIN2, // 油门输出监测
BAT_IN_CH =SADC_CH_AIN3, // 电池输入
};
enum app_control{
OUT_12V_Control =PA17, // 12V电源控制输出 /H:12V输出
OUT_Door_lock =PA18, // 电门锁 /H:开锁
IN_01 =PA19, // 自定义输入
IN_GPS =PA03, // GPS输入0 /边沿触发
IO_MANAGER_MODE =PA13, // 管理员模式 /边沿触发
IO_BACK =PA14, // 倒车 /H:前进/L:后退
IO_BRAKE =PA15, // 制动 /L:低使能
IO_TTL_TX =PA11, // 串口发送
IO_TTL_RX =PA12, // 串口接收
RADAR_TXD0 =PA07, // 串口0发送
RADAR_RXD0 =PA06, // 串口0接收
PAD_TXD1 =PA10, // 串口1发送
PAD_RXD1 =PA09, // 串口1接收
ACC_PA8_ADC7 =PA08, // 油门输入
PWM4_DAC =PA05, // 油门输出
ACC_FEEDBACK_ADC2 =PA02, // 油门输出监测
RGB_DATA_IO =PA16, // RGB数据输出
BAT_PA4_ADC3 =PA04, // 电池电压输入
};
typedef struct sys_sta{
// uint16_t Pmode:2;
union{
uint8_t Pmode;
struct{
uint8_t Tourist:1;
uint8_t Manager:1;
uint8_t RES_0:6;
};
};
union{
uint8_t Smode;
struct{
uint8_t IOgps:1;
uint8_t IOmanager:1;
uint8_t RES_1:6;
};
};
union{// 输入状态
uint8_t I_STA:8;
struct{
uint8_t I_01 :1; // 自定义输入状态
uint8_t I_brake :1; // 制动信号输入状态
uint8_t I_back :1; // 倒车信号输入状态
uint8_t A_brake :1; // 自动刹车状态
uint8_t A_Speed_Cut :1; // 自动减速状态
uint8_t O_lock :1; // 电门锁输出状态
uint8_t P_Radar_EN :1; // PAD雷达输出使能状态
uint8_t Reserve0:1;
};
};
union{// 输入输出状态
uint8_t IO_STA:8;
struct{
uint8_t IO_TX :1;
uint8_t IO_RX :1;
uint8_t O_12V :1; // 12V电源输出状态
uint8_t Reserve1:5;
};
};
} sys_sta_t;
extern sys_sta_t sys_sta;
extern bool app_control_en[PA_MAX];
// 写1使能,写0失能
#define Set_Status(pad,activity) (gpio_put(pad, ((0 == activity) ? !app_control_en[pad] : app_control_en[pad])))
// 获取状态 1使能,0失能
#define Get_Status(pad) ((app_control_en[pad] == gpio_get(pad)) ? 1 : 0)
#define SYS_Manager_STA Get_Status(IO_MANAGER_MODE) //管理员输入状态
#define SYS_Back_STA Get_Status(IO_BACK) //倒车状态
#define SYS_Brake_STA Get_Status(IO_BRAKE) //制动状态
//中控控制IO初始化
void app_control_init(void);
// 获取电池电压值unit:V)
float get_bat_voltage(void);
// 获取输入油门百分比unit:%)(踏板信号)
uint16_t get_in_acc_percent(void);
// 设置输出油门百分比unit:%)
void set_out_acc_percent(uint8_t percent);
// 控制进程,定时调用
void Control_procedure(void);
#endif