60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
#include "key.h"
|
|
#include "btn.h"
|
|
#include "work.h"
|
|
/* 按钮 */
|
|
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 uint8_t read_button_gpio(button_id_e button_id)
|
|
{
|
|
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_HIGH;
|
|
}
|
|
}
|
|
|
|
static void key_1_press_down_handler(void *btn)
|
|
{
|
|
work_key_handle_cb(KEY_ADD);
|
|
}
|
|
|
|
static void key_2_press_down_handler(void *btn)
|
|
{
|
|
work_key_handle_cb(KEY_SUB);
|
|
}
|
|
|
|
static void key_3_press_down_handler(void *btn)
|
|
{
|
|
work_key_handle_cb(KEY_S);
|
|
}
|
|
|
|
void key_init(void)
|
|
{
|
|
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_LOW, KEY_ADD, KEY_ADD);
|
|
button_init(&key_2, read_button_gpio, ACTIVE_LEVEL_LOW, KEY_SUB, KEY_SUB);
|
|
button_init(&key_3, read_button_gpio, ACTIVE_LEVEL_LOW, 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);
|
|
}
|