A36 PCB1.1 软件工程整理

This commit is contained in:
2024-04-17 19:45:26 +08:00
commit 3401b91efc
3896 changed files with 4032291 additions and 0 deletions

View File

@ -0,0 +1,454 @@
#include <stdint.h>
#include <stddef.h>
//
////#include "os_task.h"
////#include "os_msg_q.h"
////#include "os_timer.h"
////#include "user_task.h"
//#include "button.h"
//
////#include "driver_pmu.h"
//
//#define BUTTON_IDX_MAX 1
//
//#define BUTTON_SHORT_DURING 0x08 // x10ms
//#define BUTTON_LONG_DURING 0x14 // x100ms
//#define BUTTON_LONG_LONG_DURING 0x28 // x100ms
//#define BUTTON_MULTI_INTERVAL 0x14 // x10ms
//#define BUTTON_LONG_PRESSING_INTERVAL 0x1e // x10ms
//
//uint8_t current_state = BUTTON_WORKING_STATE_IDLE;
//uint16_t button_task_id;
////os_timer_t button_anti_shake_timer;
////os_timer_t button_pressing_timer;
////os_timer_t button_state_timer;
//
///* which io is enabled for button function */
//uint32_t button_io_mask = 0;
//uint32_t curr_button_before_anti_shake = 0;
//uint32_t current_pressed_button = 0;
//uint32_t last_saved_button = 0;
//uint32_t button_to_be_send = 0; //for multi click
//uint8_t pressed_cnt = 0; //for multi click
//
//void button_toggle_detected(uint32_t curr_button)
//{
// //co_printf("button_toggle_detected curr_button :%x,button_io_mask :%x\r\n",curr_button,button_io_mask);
//
// if(button_io_mask != 0) {
// curr_button_before_anti_shake = curr_button & button_io_mask;
// os_timer_start(&button_anti_shake_timer, 10, false);
// }
//}
//
//void button_int_isr(uint32_t changed_button)
//{
// uint32_t curr_button;
// os_event_t toggle_event;
//
// curr_button = current_pressed_button ^ changed_button;
//
// toggle_event.event_id = BUTTON_TOGGLE;
// toggle_event.param = (void *)&curr_button;
// toggle_event.param_len = sizeof(uint32_t);
// os_msg_post(button_task_id, &toggle_event);
//}
//
//void button_send_event(uint8_t event, uint32_t button, uint8_t cnt)
//{
// os_event_t button_event;
// struct button_msg_t msg;
//
// msg.button_index = button;
// msg.button_type = event;
// msg.button_cnt = cnt;
//
// button_event.event_id = USER_EVT_BUTTON;
// button_event.src_task_id = button_task_id;
// button_event.param = (void *)&msg;
// button_event.param_len = sizeof(msg);
//
// os_msg_post(get_user_task_id(), &button_event);
//
// pressed_cnt = 0;
//}
//
//static void button_idle(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_SINGLE_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// }
//}
//
//static void button_just_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// os_timer_stop(&button_state_timer);
// button_send_event(BUTTON_RELEASED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_TIME_OUT)
// {
// current_state = BUTTON_WORKING_STATE_PRESSED;
// os_timer_start(&button_state_timer, (BUTTON_LONG_DURING*10-BUTTON_SHORT_DURING)*10, false);
// }
//}
//
//static void button_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// if(0/*__jump_table.button_disable_multi_click*/ & last_saved_button)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// button_send_event(BUTTON_SHORT_PRESSED, last_saved_button, 0);
// }
// else
// {
// //TBD<42><44><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// current_state = BUTTON_WORKING_STATE_WAIT_MULTI;
// button_to_be_send = last_saved_button;
// pressed_cnt++;
// os_timer_start(&button_state_timer, BUTTON_MULTI_INTERVAL*10, false);
// }
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_TIME_OUT)
// {
// current_state = BUTTON_WORKING_STATE_LONG_PRESSED;
// os_timer_start(&button_state_timer, ((BUTTON_LONG_LONG_DURING-BUTTON_LONG_DURING)*10)*10, false);
// os_timer_start(&button_pressing_timer, BUTTON_LONG_PRESSING_INTERVAL*10, false);
// button_send_event(BUTTON_LONG_PRESSED, current_pressed_button, pressed_cnt);
// }
//}
//
//static void button_wait_multi(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_SINGLE_PRESSED)
// {
// if(current_pressed_button != button_to_be_send)
// {
// if(pressed_cnt > 1)
// {
// button_send_event(BUTTON_MULTI_PRESSED, button_to_be_send, pressed_cnt);
// }
// else
// {
// button_send_event(BUTTON_SHORT_PRESSED, button_to_be_send, pressed_cnt);
// }
// button_send_event(BUTTON_PRESSED, current_pressed_button, pressed_cnt);
// }
// current_state = BUTTON_WORKING_STATE_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// button_send_event(BUTTON_SHORT_PRESSED, button_to_be_send, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_TIME_OUT)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// if(pressed_cnt > 1)
// {
// button_send_event(BUTTON_MULTI_PRESSED, button_to_be_send, pressed_cnt);
// }
// else
// {
// button_send_event(BUTTON_SHORT_PRESSED, button_to_be_send, pressed_cnt);
// }
// }
//}
//
//static void button_long_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// os_timer_stop(&button_state_timer);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_LONG_RELEASED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// button_send_event(BUTTON_LONG_RELEASED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_TIME_OUT)
// {
// current_state = BUTTON_WORKING_STATE_LONG_LONG_PRESSED;
// button_send_event(BUTTON_LONG_LONG_PRESSED, current_pressed_button, pressed_cnt);
// }
//}
//
//static void button_long_long_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// os_timer_stop(&button_pressing_timer);
// current_state = BUTTON_WORKING_STATE_IDLE;
// button_send_event(BUTTON_LONG_LONG_RELEASED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// button_send_event(BUTTON_LONG_LONG_RELEASED, last_saved_button, pressed_cnt);
// }
//}
//
//static void button_comb_just_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// os_timer_stop(&button_state_timer);
// button_send_event(BUTTON_COMB_RELEASED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_SINGLE_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_RELEASED, last_saved_button, pressed_cnt);
// button_send_event(BUTTON_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_TIME_OUT)
// {
// current_state = BUTTON_WORKING_STATE_COMB_PRESSED;
// os_timer_start(&button_state_timer, (BUTTON_LONG_DURING*10-BUTTON_SHORT_DURING)*10, false);
// }
//}
//
//static void button_comb_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// os_timer_stop(&button_state_timer);
// button_send_event(BUTTON_COMB_SHORT_PRESSED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_SINGLE_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_SHORT_PRESSED, last_saved_button, pressed_cnt);
// button_send_event(BUTTON_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// button_send_event(BUTTON_COMB_SHORT_PRESSED, last_saved_button, pressed_cnt);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_TIME_OUT)
// {
// current_state = BUTTON_WORKING_STATE_COMB_LONG_PRESSED;
// os_timer_start(&button_state_timer, ((BUTTON_LONG_LONG_DURING-BUTTON_LONG_DURING)*10)*10, false);
// os_timer_start(&button_pressing_timer, BUTTON_LONG_PRESSING_INTERVAL*10, false);
// button_send_event(BUTTON_COMB_LONG_PRESSED, current_pressed_button, pressed_cnt);
// }
//}
//
//static void button_comb_long_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// os_timer_stop(&button_state_timer);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_LONG_RELEASED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_SINGLE_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_LONG_RELEASED, last_saved_button, pressed_cnt);
// button_send_event(BUTTON_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_LONG_RELEASED, last_saved_button, pressed_cnt);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_TIME_OUT)
// {
// current_state = BUTTON_WORKING_STATE_COMB_LONG_LONG_PRESSED;
// button_send_event(BUTTON_COMB_LONG_LONG_PRESSED, current_pressed_button, pressed_cnt);
// }
//}
//
//static void button_comb_long_long_pressed(uint8_t event)
//{
// if(event == BUTTON_WORKING_EVENT_RELEASED)
// {
// current_state = BUTTON_WORKING_STATE_IDLE;
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_LONG_LONG_RELEASED, last_saved_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_SINGLE_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_LONG_LONG_RELEASED, last_saved_button, pressed_cnt);
// button_send_event(BUTTON_PRESSED, current_pressed_button, pressed_cnt);
// }
// else if(event == BUTTON_WORKING_EVENT_COMB_PRESSED)
// {
// current_state = BUTTON_WORKING_STATE_COMB_JUST_PRESSED;
// os_timer_start(&button_state_timer, BUTTON_SHORT_DURING*10, false);
// os_timer_stop(&button_pressing_timer);
// button_send_event(BUTTON_COMB_LONG_LONG_RELEASED, last_saved_button, pressed_cnt);
// button_send_event(BUTTON_COMB_PRESSED, current_pressed_button, pressed_cnt);
// }
//}
//
//void (*const button_statemachines[BUTTON_WORKING_STATE_MAX])(uint8_t) =
//{
// button_idle,
// button_just_pressed,
// button_pressed,
// button_wait_multi,
// button_long_pressed,
// button_long_long_pressed,
// button_comb_just_pressed,
// button_comb_pressed,
// button_comb_long_pressed,
// button_comb_long_long_pressed,
//};
//
////one or more button is released or pressed
//static int button_toggle_handler(uint32_t curr_button)
//{
// enum button_working_event_t event;
//
// current_pressed_button = curr_button;
//
// if(last_saved_button != current_pressed_button)
// {
// if(current_pressed_button == 0)
// {
// event = BUTTON_WORKING_EVENT_RELEASED;
// }
// else
// {
// if((current_pressed_button & (current_pressed_button-1)) == 0)
// {
// event = BUTTON_WORKING_EVENT_SINGLE_PRESSED;
// }
// else
// {
// event = BUTTON_WORKING_EVENT_COMB_PRESSED;
// }
// }
//
// button_statemachines[current_state](event);
//
// last_saved_button = current_pressed_button;
// }
//
// return EVT_CONSUMED;
//}
//
//static void button_timeout_handler(void *param)
//{
// button_statemachines[current_state](BUTTON_WORKING_EVENT_TIME_OUT);
//}
//
//static void button_pressing_timeout_handler(void *param)
//{
// enum button_type_t event;
// if((current_pressed_button & (current_pressed_button - 1)) == 0)
// {
// event = BUTTON_LONG_PRESSING;
// }
// else
// {
// event = BUTTON_COMB_LONG_PRESSING;
// }
//
// button_send_event(event, current_pressed_button, pressed_cnt);
//
// os_timer_start(&button_pressing_timer, BUTTON_LONG_PRESSING_INTERVAL*10, false);
//}
//
//static void button_anti_shake_timeout_handler(void *param)
//{
// uint32_t curr_button;
// os_event_t toggle_event;
//
// //milo modify curr_button = ool_read32(PMU_REG_PORTA_V);
// curr_button = ool_read32(PMU_REG_PORTA_LAST_STATUS);
// curr_button &= button_io_mask;
//
// if(curr_button == curr_button_before_anti_shake)
// {
// curr_button ^= button_io_mask;
// toggle_event.event_id = BUTTON_TOGGLE;
// toggle_event.param = (void *)&curr_button;
// toggle_event.param_len = sizeof(uint32_t);
// os_msg_post(button_task_id, &toggle_event);
// }
//}
//
//static int button_task_func(os_event_t *event)
//{
// switch(event->event_id)
// {
// case BUTTON_TOGGLE:
// button_toggle_handler(*(uint32_t *)event->param);
// break;
// }
//
// return EVT_CONSUMED;
//}
//
//void button_init(uint32_t enable_io)
//{
// button_io_mask = enable_io;
//
// button_task_id = os_task_create(button_task_func);
// os_timer_init(&button_anti_shake_timer, button_anti_shake_timeout_handler, NULL);
// os_timer_init(&button_pressing_timer, button_pressing_timeout_handler, NULL);
// os_timer_init(&button_state_timer, button_timeout_handler, NULL);
//}

View File

@ -0,0 +1,73 @@
#ifndef _BUTTON_H
#define _BUTTON_H
#include <stdint.h>
enum button_event_t {
BUTTON_TOGGLE,
BUTTON_PRESSED_EVENT,
BUTTON_TIMER_TO_TIMER,
BUTTON_PRESSING_TO_TIMER,
BUTTON_ANTI_SHAKE_TO_TIMER,
};
enum button_type_t {
BUTTON_PRESSED,
BUTTON_RELEASED,
BUTTON_SHORT_PRESSED,
BUTTON_MULTI_PRESSED,
BUTTON_LONG_PRESSED,
BUTTON_LONG_PRESSING,
BUTTON_LONG_RELEASED,
BUTTON_LONG_LONG_PRESSED,
BUTTON_LONG_LONG_RELEASED,
BUTTON_COMB_PRESSED,
BUTTON_COMB_RELEASED,
BUTTON_COMB_SHORT_PRESSED,
BUTTON_COMB_LONG_PRESSED,
BUTTON_COMB_LONG_PRESSING,
BUTTON_COMB_LONG_RELEASED,
BUTTON_COMB_LONG_LONG_PRESSED,
BUTTON_COMB_LONG_LONG_RELEASED,
};
enum button_working_state_t {
BUTTON_WORKING_STATE_IDLE,
BUTTON_WORKING_STATE_JUST_PRESSED,
BUTTON_WORKING_STATE_PRESSED,
BUTTON_WORKING_STATE_WAIT_MULTI,
BUTTON_WORKING_STATE_LONG_PRESSED,
BUTTON_WORKING_STATE_LONG_LONG_PRESSED,
BUTTON_WORKING_STATE_COMB_JUST_PRESSED,
BUTTON_WORKING_STATE_COMB_PRESSED,
BUTTON_WORKING_STATE_COMB_LONG_PRESSED,
BUTTON_WORKING_STATE_COMB_LONG_LONG_PRESSED,
BUTTON_WORKING_STATE_MAX,
};
enum button_working_event_t {
BUTTON_WORKING_EVENT_RELEASED,
BUTTON_WORKING_EVENT_SINGLE_PRESSED,
BUTTON_WORKING_EVENT_COMB_PRESSED,
BUTTON_WORKING_EVENT_TIME_OUT,
};
struct button_toggle_param_t {
uint32_t curr_button;
uint32_t timestamp;
};
struct button_msg_t {
uint32_t button_index;
uint8_t button_type;
uint8_t button_cnt; //only for multi click
};
void button_toggle_detected(uint32_t curr_button);
void button_int_isr(uint32_t changed_button);
void button_init(uint32_t enable_io);
#endif //_BUTTON_H

View File

@ -0,0 +1,75 @@
#include <stdint.h>
#if !MMI_WIN32_SIM
//
//#include "os_task.h"
//#include "os_msg_q.h"
//#include "co_printf.h"
#include "button.h"
//#include "driver_gpio.h"
//#include "SEGGER_RTT.h"
//#include "window_manager.h"
//#include "driver_exti.h"
//#include "driver_cst816d.h"
//#include "input_driver.h"
#include "hal_key_handle.h"
//#include "user_main.h"
#include "lvgl.h"
//#include "../engtest/eng_mode.h"
static uint8_t key_code_type_bit;
static uint8_t key_code;
extern void hal_keypad_msg_handle(uint8_t button_index, uint8_t button_type)
{
key_event_msg_t *key_msg_param;
e_key_event_type key_event_type;
printf("hal_keypad_msg_handle btn %d \r\n",button_index);
switch(button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_SHORT_PRESSED:
key_code_type_bit=SHORT_KEY_BIT;
break;
case BUTTON_MULTI_PRESSED:
key_code_type_bit=MULTI_KEY_BIT;
break;
case BUTTON_COMB_LONG_PRESSED:
case BUTTON_LONG_PRESSED:
key_code_type_bit=LONG_KEY_BIT;
break;
default:
key_code_type_bit=0;
break;
}
//init
key_code|=button_index;
key_code|=key_code_type_bit;
printf("key_code_bit:%d\r\n",key_code);
}
uint8_t get_keycode_type_bit()
{
return key_code_type_bit;
}
uint8_t get_keycode()
{
return key_code;
}
void reset_keycode()
{
key_code=0;
}
#endif

View File

@ -0,0 +1,115 @@
#ifndef __HAL_KEY_HANDLE_H__
#define __HAL_KEY_HANDLE_H__
typedef struct _key_event_msg_t {
uint32_t key_code;
uint8_t key_type;
}key_event_msg_t;
//key state
#define HOME_KEY_BIT 0x08
#define ENTER_KEY_BIT 0x10
#define UP_KEY_BIT 0x20
#define DOWN_KEY_BIT 0x40
#define END_KEY_BIT 0x80
#define HOME_ENTER_BIT HOME_KEY_BIT|ENTER_KEY_BIT
#define HOME_UP_BIT HOME_KEY_BIT|UP_KEY_BIT
#define HOME_DOWN_BIT HOME_KEY_BIT|DOWN_KEY_BIT
#define HOME_END_BIT HOME_KEY_BIT|END_KEY_BIT
#define ENTER_UP_BIT ENTER_KEY_BIT|UP_KEY_BIT
#define ENTER_DOWN_BIT ENTER_KEY_BIT|DOWN_KEY_BIT
#define ENTER_END_BIT ENTER_KEY_BIT|END_KEY_BIT
#define UP_DOWN_BIT UP_KEY_BIT|DOWN_KEY_BIT
#define UP_END_BIT UP_KEY_BIT|END_KEY_BIT
#define DOWN_END_BIT DOWN_KEY_BIT|END_KEY_BIT
#define SHORT_KEY_BIT 0x01
#define MULTI_KEY_BIT 0x02
#define LONG_KEY_BIT 0x04
//keycode
#define KEY_CODE_HOME HOME_KEY_BIT|SHORT_KEY_BIT //0000 1001 0x09
#define KEY_CODE_ENTER ENTER_KEY_BIT|SHORT_KEY_BIT //0001 0001 0x11
#define KEY_CODE_UP UP_KEY_BIT|SHORT_KEY_BIT //0010 0001 0x21
#define KEY_CODE_DOWN DOWN_KEY_BIT|SHORT_KEY_BIT //0100 0001 0x41
#define KEY_CODE_END END_KEY_BIT|SHORT_KEY_BIT //1000 0001 0x81
#define KEY_CODE_2HOME HOME_KEY_BIT|MULTI_KEY_BIT
#define KEY_CODE_2ENTER ENTER_KEY_BIT|MULTI_KEY_BIT
#define KEY_CODE_2UP UP_KEY_BIT|MULTI_KEY_BIT
#define KEY_CODE_2DOWN DOWN_KEY_BIT|MULTI_KEY_BIT
#define KEY_CODE_2END END_KEY_BIT|MULTI_KEY_BIT
#define KEY_CODE_LONG_HOME HOME_KEY_BIT|LONG_KEY_BIT
#define KEY_CODE_LONG_ENTER ENTER_KEY_BIT|LONG_KEY_BIT
#define KEY_CODE_LONG_UP UP_KEY_BIT|LONG_KEY_BIT
#define KEY_CODE_LONG_DOWN DOWN_KEY_BIT|LONG_KEY_BIT
#define KEY_CODE_LONG_END END_KEY_BIT|LONG_KEY_BIT
#define KEY_CODE_COMB_HOME_ENTER ((LV_KEY_HOME|LV_KEY_ENTER)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_HOME_UP ((LV_KEY_HOME|LV_KEY_PREV)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_HOME_DOWN ((LV_KEY_HOME|LV_KEY_NEXT)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_HOME_END ((LV_KEY_HOME|LV_KEY_END)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_ENTER_UP ((LV_KEY_ENTER|LV_KEY_PREV)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_ENTER_DOWN ((LV_KEY_ENTER|LV_KEY_NEXT)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_ENTER_END ((LV_KEY_ENTER|LV_KEY_END)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_UP_DOWN ((LV_KEY_PREV|LV_KEY_NEXT)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_UP_END ((LV_KEY_PREV|LV_KEY_END)|SHORT_KEY_BIT)
#define KEY_CODE_COMB_DOWN_END ((LV_KEY_NEXT|LV_KEY_END)|SHORT_KEY_BIT)
#define KEY_CODE_LONG_COMB_HOME_ENTER ((LV_KEY_HOME|LV_KEY_ENTER)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_HOME_UP ((LV_KEY_HOME|LV_KEY_PREV)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_HOME_DOWN ((LV_KEY_HOME|LV_KEY_NEXT)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_HOME_END ((LV_KEY_HOME|LV_KEY_END)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_ENTER_UP ((LV_KEY_ENTER|LV_KEY_PREV)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_ENTER_DOWN ((LV_KEY_ENTER|LV_KEY_NEXT)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_ENTER_END ((LV_KEY_ENTER|LV_KEY_END)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_UP_DOWN ((LV_KEY_PREV|LV_KEY_NEXT)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_UP_END ((LV_KEY_PREV|LV_KEY_END)|LONG_KEY_BIT)
#define KEY_CODE_LONG_COMB_DOWN_END ((LV_KEY_NEXT|LV_KEY_END)|LONG_KEY_BIT)
#define KEY_CODE_NONE 0
//keyevent
typedef enum {
KEY_EVENT_NONE,
KEY_EVENT_PRESSED,
KEY_EVENT_DOUBLE_PRESSED,
KEY_EVENT_LONG_PRESSED,
KEY_EVENT_COMB_PRESSED,
KEY_EVENT_MAX
}e_key_event_type;
extern uint16_t get_lv_key_task_id(void);
extern uint8_t get_keycode_type_bit();
extern uint8_t get_keycode();
extern void reset_keycode();
#endif

View File

@ -0,0 +1,277 @@
#include <stdint.h>
//#include "os_task.h"
//#include "os_msg_q.h"
//#include "co_printf.h"
#include "user_task.h"
//#include "app_at.h"
#include "button.h"
//#include "driver_system.h"
//#include "driver_gpio.h"
#include "lvgl.h"
#include "hal_key_handle.h"
static uint16_t user_task_id;
extern lv_obj_t * get_root_win(void);
extern void hal_keypad_msg_handle(uint8_t button_index, uint8_t button_type);
static void handle_key_msg_input(uint8_t *param)
{
//key input
struct button_msg_t *button_msg;
const char *button_type_str[] = {
"BUTTON_PRESSED",
"BUTTON_RELEASED",
"BUTTON_SHORT_PRESSED",
"BUTTON_MULTI_PRESSED",
"BUTTON_LONG_PRESSED",
"BUTTON_LONG_PRESSING",
"BUTTON_LONG_RELEASED",
"BUTTON_LONG_LONG_PRESSED",
"BUTTON_LONG_LONG_RELEASED",
"BUTTON_COMB_PRESSED",
"BUTTON_COMB_RELEASED",
"BUTTON_COMB_SHORT_PRESSED",
"BUTTON_COMB_LONG_PRESSED",
"BUTTON_COMB_LONG_PRESSING",
"BUTTON_COMB_LONG_RELEASED",
"BUTTON_COMB_LONG_LONG_PRESSED",
"BUTTON_COMB_LONG_LONG_RELEASED",
};
button_msg = (struct button_msg_t *)param;
co_printf("KEY 0x%08x, TYPE %s.\r\n", button_msg->button_index, button_type_str[button_msg->button_type]);
switch(button_msg->button_index)
{
#ifdef BL01_V10
case GPIO_PA3:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key1 Pressed %d\r\n",button_msg->button_type);
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA4:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key2 Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA5:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key3 Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA6:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key4 Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA7:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key5 Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA3|GPIO_PA4:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key1/2 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA3|GPIO_PA5:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key1/3 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA3|GPIO_PA6:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key1/4 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA3|GPIO_PA7:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key1/5 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA4|GPIO_PA5:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key2/3 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA4|GPIO_PA6:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key2/4 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA4|GPIO_PA7:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key2/5 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA5|GPIO_PA6:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key3/4 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA5|GPIO_PA7:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key3/5 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PA6|GPIO_PA7:
switch(button_msg->button_type)
{
case BUTTON_COMB_SHORT_PRESSED:
case BUTTON_COMB_LONG_PRESSED:
co_printf("key4/5 COMB Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
#else
case GPIO_PC6:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key1 Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PC7:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key2 Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
case GPIO_PD4:
switch(button_msg->button_type)
{
case BUTTON_SHORT_PRESSED:
case BUTTON_MULTI_PRESSED:
case BUTTON_LONG_PRESSED:
co_printf("key3 Pressed\r\n");
hal_keypad_msg_handle(button_msg->button_index,button_msg->button_type);
break;
}
break;
#endif
}
}
static int user_task_func(os_event_t *param)
{
co_printf("user_task_func %d\r\n", param->event_id);
switch(param->event_id)
{
case USER_EVT_AT_COMMAND:
app_at_cmd_recv_handler(param->param, param->param_len);
break;
case USER_EVT_BUTTON:
handle_key_msg_input(param->param);
break;
default:
break;
}
return EVT_CONSUMED;
}
void user_task_init(void)
{
co_printf("user_task_init %d\r\n", user_task_id);
user_task_id = os_task_create(user_task_func);
}
uint16_t get_user_task_id(void)
{
co_printf("get_user_task_id %d\r\n", user_task_id);
return user_task_id;
}

View File

@ -0,0 +1,14 @@
#ifndef _USER_TASK_H
#define _USER_TASK_H
enum user_event_t {
USER_EVT_AT_COMMAND,
USER_EVT_BUTTON,
};
extern uint16_t user_task_id;
void user_task_init(void);
#endif // _USER_TASK_H