A272O版本整理

This commit is contained in:
2025-02-12 14:05:53 +08:00
parent 08e216ffb2
commit 7a59be0434
156 changed files with 27634 additions and 25946 deletions

View File

@ -5,24 +5,38 @@
#include "chip.h"
#include "data_port.h"
#include "gear_protocol.h"
#include "moto_config.h"
extern void check_key(void);
// 定义定时器句柄
TimerHandle_t xTimer;
uint8_t GPIO_value_high[7];
#define IO_KEEP 4
#ifdef UI_VIEW_QUICKLY_ARRANGE
#define IO_KEEP 1 //采样大于1次
#define CNT_KEEP 1 //20ms一次判断
#else
#define IO_KEEP 4 //采样大于两次
#define CNT_KEEP 6 //30ms一次判断
#endif
uint8_t gpio_pins[7] = {GPIO_D6, GPIO_D5, GPIO_D4, GPIO_D3, GPIO_D2, GPIO_D1, GPIO_N};
void grade_key(void){
#ifdef UI_VIEW_QUICKLY_ARRANGE
static uint8_t Gear_value = 7;
#else
uint8_t Gear_value = 7;
#endif
static uint8_t cnt =0;
//数据顺序 N 1 2 3 4 5 6 ABS TCS FAN ENG YG R L RMT
//挡位高电平触发, 灯光、ABS、TCS、FAN ENG 低电平触发
if(gpio_get_value(GPIO_GRADE_N))
{
GPIO_value_high[GPIO_N]++;
if(GPIO_value_high[GPIO_N] == IO_KEEP)
{
Gear_value = 0;
printf("N\r\n");
}
}
else
GPIO_value_high[GPIO_N] = 0;
@ -30,11 +44,6 @@ void grade_key(void){
if(gpio_get_value(GPIO_GRADE_D1))
{
GPIO_value_high[GPIO_D1]++;
if(GPIO_value_high[GPIO_D1] == IO_KEEP)
{
Gear_value = 1;
printf("D1\r\n");
}
}
else
GPIO_value_high[GPIO_D1] = 0;
@ -42,11 +51,6 @@ void grade_key(void){
if(gpio_get_value(GPIO_GRADE_D2))
{
GPIO_value_high[GPIO_D2]++;
if(GPIO_value_high[GPIO_D2] == IO_KEEP)
{
Gear_value = 2;
printf("D2\r\n");
}
}
else
GPIO_value_high[GPIO_D2] = 0;
@ -54,11 +58,6 @@ void grade_key(void){
if(gpio_get_value(GPIO_GRADE_D3))
{
GPIO_value_high[GPIO_D3]++;
if(GPIO_value_high[GPIO_D3] == IO_KEEP)
{
Gear_value = 3;
printf("D3\r\n");
}
}
else
GPIO_value_high[GPIO_D3] = 0;
@ -66,11 +65,6 @@ void grade_key(void){
if(gpio_get_value(GPIO_GRADE_D4))
{
GPIO_value_high[GPIO_D4]++;
if(GPIO_value_high[GPIO_D4] == IO_KEEP)
{
Gear_value = 4;
printf("D4\r\n");
}
}
else
GPIO_value_high[GPIO_D4] = 0;
@ -78,11 +72,6 @@ void grade_key(void){
if(gpio_get_value(GPIO_GRADE_D5))
{
GPIO_value_high[GPIO_D5]++;
if(GPIO_value_high[GPIO_D5] == IO_KEEP)
{
Gear_value = 5;
printf("D5\r\n");
}
}
else
GPIO_value_high[GPIO_D5] = 0;
@ -90,16 +79,28 @@ void grade_key(void){
if(gpio_get_value(GPIO_GRADE_D6))
{
GPIO_value_high[GPIO_D6]++;
if(GPIO_value_high[GPIO_D6] == IO_KEEP)
{
Gear_value = 6;
printf("D6\r\n");
}
}
else
GPIO_value_high[GPIO_D6] = 0;
Set_sys_grade(Gear_value);
cnt++;
// printf("N=%d,D1=%d,D2=%d,D3=%d,D4=%d,D5=%d,D6=%d.\r\n",gpio_get_value(GPIO_GRADE_N),gpio_get_value(GPIO_GRADE_D1),gpio_get_value(GPIO_GRADE_D2),
// gpio_get_value(GPIO_GRADE_D3),gpio_get_value(GPIO_GRADE_D4),gpio_get_value(GPIO_GRADE_D5),gpio_get_value(GPIO_GRADE_D6));
if(cnt>=CNT_KEEP){
// if(cnt){
// 针对当前档位进行赋值
for (uint8_t i = 0; i < 7; i++) {
if (GPIO_value_high[gpio_pins[i]] >= IO_KEEP) {
Gear_value = (6-i); // 根据索引设置 Gear_value
break; // 找到第一个符合条件的引脚后退出循环
}
}
Set_sys_grade(Gear_value);
cnt=0;
memset(GPIO_value_high, 0, 7); //buff初始化
}
}
// 定时器回调函数
@ -109,13 +110,27 @@ void vTimerCallback(TimerHandle_t xTimer) {
check_key();
//档位检测
grade_key();
}
void Moto_gpio_timer(void) {
static void gear_gpio_init(void){
gpio_direction_input(GPIO_GRADE_N);
gpio_direction_input(GPIO_GRADE_D1);
gpio_direction_input(GPIO_GRADE_D2);
gpio_direction_input(GPIO_GRADE_D3);
gpio_direction_input(GPIO_GRADE_D4);
gpio_direction_input(GPIO_GRADE_D5);
gpio_direction_input(GPIO_GRADE_D6);
gpio_direction_input(GPIO_LIGHT_SET);
gpio_direction_input(GPIO_LIGHT_MODE);
}
void Moto_gpio_timer(void) {
gear_gpio_init();
// 创建定时器
xTimer = xTimerCreate("MyTimer", // 定时器名称
pdMS_TO_TICKS(20), // 定时器周期1000毫秒
pdMS_TO_TICKS(5), // 定时器周期1000毫秒
pdTRUE, // 自动重载定时器
(void *)0, // 定时器 ID
vTimerCallback); // 回调函数
@ -123,7 +138,7 @@ void Moto_gpio_timer(void) {
// 启动定时器
if (xTimerStart(xTimer, 0) != pdPASS) {
// 启动定时器失败的处理
printf("xTimer error!!!!!!!!!!!!!!!!!.\r\n");
printf("xTimer error!!!!!!!!!!!!!!!!!..........................\r\n");
}
}

View File

@ -12,7 +12,7 @@ enum
GPIO_D6,
};
#define GPIO_GRADE_N 8
#define GPIO_GRADE_N 8
#define GPIO_GRADE_D1 9
#define GPIO_GRADE_D2 10
#define GPIO_GRADE_D3 11

View File

@ -10,8 +10,16 @@ KEY_DAT gs_keyDat[KEY_NUMBERS]={0};
bool key_readKeyPin(uint8_t keyx)
{
bool status;
#ifdef DATA_CAN //适配270M版本
if(keyx==0) status = gpio_get_value(GPIO_LIGHT_SET);
else if(keyx==1) status = gpio_get_value(GPIO_LIGHT_MODE);
#else
if(keyx==0) status = gpio_get_value(GPIO_LIGHT_MODE);
else if(keyx==1) status = gpio_get_value(GPIO_LIGHT_SET);
#endif
// if(keyx==0) status = gpio_get_value(GPIO_LIGHT_SET);
// else if(keyx==1) status = gpio_get_value(GPIO_LIGHT_MODE);
// return (!status);//低有效
return (status);//高有效
}

View File

@ -302,31 +302,31 @@ void data_analysis(uint8_t *buf){
//按键 高set 低mod
data = *(buf++);
#ifdef KEY_EXCHANGE
if(JUDGE_BIN_4(data))
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OPTION);
else if(JUDGE_BIN_5(data))
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_OPTION);
else if(JUDGE_BIN_0(data))
Key_Distinction(KEY_DATA_PRESS,LV_KEY_SELECT);
else if(JUDGE_BIN_1(data))
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_SELECT);
else if(JUDGE_BIN_7(data)){
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OTHER1);
}
#else
if(JUDGE_BIN_0(data))
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OPTION);
else if(JUDGE_BIN_1(data))
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_OPTION);
else if(JUDGE_BIN_4(data))
Key_Distinction(KEY_DATA_PRESS,LV_KEY_SELECT);
else if(JUDGE_BIN_5(data))
Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_SELECT);
else if(JUDGE_BIN_7(data)){
Key_Distinction(KEY_DATA_PRESS,LV_KEY_OTHER1);
}
#endif
// #ifdef KEY_EXCHANGE
// if(JUDGE_BIN_4(data))
// Key_Distinction(KEY_DATA_PRESS,LV_KEY_OPTION);
// else if(JUDGE_BIN_5(data))
// Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_OPTION);
// else if(JUDGE_BIN_0(data))
// Key_Distinction(KEY_DATA_PRESS,LV_KEY_SELECT);
// else if(JUDGE_BIN_1(data))
// Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_SELECT);
// else if(JUDGE_BIN_7(data)){
// Key_Distinction(KEY_DATA_PRESS,LV_KEY_OTHER1);
// }
// #else
// if(JUDGE_BIN_0(data))
// Key_Distinction(KEY_DATA_PRESS,LV_KEY_OPTION);
// else if(JUDGE_BIN_1(data))
// Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_OPTION);
// else if(JUDGE_BIN_4(data))
// Key_Distinction(KEY_DATA_PRESS,LV_KEY_SELECT);
// else if(JUDGE_BIN_5(data))
// Key_Distinction(KEY_DATA_LONG_PRESS,LV_KEY_SELECT);
// else if(JUDGE_BIN_7(data)){
// Key_Distinction(KEY_DATA_PRESS,LV_KEY_OTHER1);
// }
// #endif
//速度
data = *(buf++);
#ifndef DATA_CAN
@ -428,11 +428,11 @@ void data_analysis(uint8_t *buf){
//档位
data = *(buf++);
if(data == 0){
Set_sys_grade(0);
}else if(data < 8){
Set_sys_grade(data);
}
// if(data == 0){
// Set_sys_grade(0);
// }else if(data < 8){
// Set_sys_grade(data);
// }
//油量
oil = *(buf++);