64 lines
1.8 KiB
C
64 lines
1.8 KiB
C
#include "key.h"
|
||
#include "btn.h"
|
||
|
||
#define INVALID_BUTTON_TICKS 200 // 无效按键时间 毫秒
|
||
static uint32_t key_start_ticks = 0;
|
||
/* 按钮 */
|
||
struct Button key_1;
|
||
struct Button key_2;
|
||
struct Button key_3;
|
||
struct Button key_4;
|
||
struct Button key_5;
|
||
struct Button key_6;
|
||
|
||
static BOOL allow_condition(void)
|
||
{
|
||
/**
|
||
* key的初始化在LCD板子上电之前,因为是低电平有效,所以会误判为按键按下
|
||
*/
|
||
if (sys_millis() - key_start_ticks < INVALID_BUTTON_TICKS) // 仿真的时候按键会有毛刺,在xx秒之后按下有效
|
||
{
|
||
return FALSE;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
static uint8_t read_button_gpio(button_id_e button_id)
|
||
{
|
||
if (allow_condition() == FALSE)
|
||
{
|
||
return ACTIVE_LEVEL_LOW;
|
||
}
|
||
// switch (button_id)
|
||
// {
|
||
// case KEY_ADD:
|
||
// return GPIO_READ(KEY_ADD_GPIO_Port, KEY_ADD_Pin);
|
||
// case KEY_SUB:
|
||
// return GPIO_READ(KEY_SUB_GPIO_Port, KEY_SUB_Pin);
|
||
// case KEY_S:
|
||
// return GPIO_READ(KEY_S_GPIO_Port, KEY_S_Pin);
|
||
// default:
|
||
// return ACTIVE_LEVEL_LOW;
|
||
// }
|
||
}
|
||
|
||
void key_init(void)
|
||
{
|
||
// key_start_ticks = sys_millis();
|
||
// GPIO_SET_INPUT(KEY_ADD_GPIO_Port, KEY_ADD_Pin);
|
||
// GPIO_SET_INPUT(KEY_SUB_GPIO_Port, KEY_SUB_Pin);
|
||
// GPIO_SET_INPUT(KEY_S_GPIO_Port, KEY_S_Pin);
|
||
|
||
// button_init(&key_1, read_button_gpio, ACTIVE_LEVEL_HIGH, KEY_ADD, KEY_ADD);
|
||
// button_init(&key_2, read_button_gpio, ACTIVE_LEVEL_HIGH, KEY_SUB, KEY_SUB);
|
||
// button_init(&key_3, read_button_gpio, ACTIVE_LEVEL_HIGH, KEY_S, KEY_S);
|
||
|
||
// button_attach(&key_1, PRESS_DOWN, key_1_press_down_handler);
|
||
// button_attach(&key_2, PRESS_DOWN, key_2_press_down_handler);
|
||
// button_attach(&key_3, PRESS_DOWN, key_3_press_down_handler);
|
||
|
||
// button_start(&key_1);
|
||
// button_start(&key_2);
|
||
// button_start(&key_3);
|
||
}
|