146 lines
3.4 KiB
C
146 lines
3.4 KiB
C
#include "awtk.h"
|
||
#include "key_protocol.h"
|
||
#include "gpio_protocol.h"
|
||
#include "board.h"
|
||
#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];
|
||
|
||
#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]++;
|
||
}
|
||
else
|
||
GPIO_value_high[GPIO_N] = 0;
|
||
|
||
if(gpio_get_value(GPIO_GRADE_D1))
|
||
{
|
||
GPIO_value_high[GPIO_D1]++;
|
||
}
|
||
else
|
||
GPIO_value_high[GPIO_D1] = 0;
|
||
|
||
if(gpio_get_value(GPIO_GRADE_D2))
|
||
{
|
||
GPIO_value_high[GPIO_D2]++;
|
||
}
|
||
else
|
||
GPIO_value_high[GPIO_D2] = 0;
|
||
|
||
if(gpio_get_value(GPIO_GRADE_D3))
|
||
{
|
||
GPIO_value_high[GPIO_D3]++;
|
||
}
|
||
else
|
||
GPIO_value_high[GPIO_D3] = 0;
|
||
|
||
if(gpio_get_value(GPIO_GRADE_D4))
|
||
{
|
||
GPIO_value_high[GPIO_D4]++;
|
||
}
|
||
else
|
||
GPIO_value_high[GPIO_D4] = 0;
|
||
|
||
if(gpio_get_value(GPIO_GRADE_D5))
|
||
{
|
||
GPIO_value_high[GPIO_D5]++;
|
||
}
|
||
else
|
||
GPIO_value_high[GPIO_D5] = 0;
|
||
|
||
if(gpio_get_value(GPIO_GRADE_D6))
|
||
{
|
||
GPIO_value_high[GPIO_D6]++;
|
||
}
|
||
else
|
||
GPIO_value_high[GPIO_D6] = 0;
|
||
|
||
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初始化
|
||
}
|
||
|
||
}
|
||
|
||
// 定时器回调函数
|
||
void vTimerCallback(TimerHandle_t xTimer) {
|
||
// 定时器到期时执行的代码
|
||
//按键检测
|
||
check_key();
|
||
//档位检测
|
||
grade_key();
|
||
|
||
}
|
||
|
||
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(5), // 定时器周期(1000毫秒)
|
||
pdTRUE, // 自动重载定时器
|
||
(void *)0, // 定时器 ID
|
||
vTimerCallback); // 回调函数
|
||
|
||
// 启动定时器
|
||
if (xTimerStart(xTimer, 0) != pdPASS) {
|
||
// 启动定时器失败的处理
|
||
printf("xTimer error!!!!!!!!!!!!!!!!!..........................\r\n");
|
||
}
|
||
|
||
}
|
||
|