修改以下文件,将原驱动的5按键改为6按键
vim kernel/linux-5.4/arch/arm/boot/dts/t113-board.dts
...
&gpadc {
channel_num = <1>;
channel_select = <0x1>;
channel_data_select = <0>;
channel_compare_select = <0x1>;
channel_cld_select = <0x1>;
channel_chd_select = <0>;
channel0_compare_lowdata = <1700000>;
channel0_compare_higdata = <1200000>;
channel1_compare_lowdata = <460000>;
channel1_compare_higdata = <1200000>;
key_cnt = <6>; // 按键数量
key0_vol = <0>; // 按键0电压值
key0_val = <126>; // 按键值
key1_vol = <275>; // 按键1电压值
key1_val = <130>; // 按键值
key2_vol = <505>;
key2_val = <131>;
key3_vol = <771>;
key3_val = <132>;
key4_vol = <1017>;
key4_val = <133>;
key5_vol = <1256>;
key5_val = <134>;
status = "okay";
};
注意,key1_vol 的 值要比 key0_vol 高,key2_vol 的 值要比 key1_vol 高
============================
按键测试程序:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEV_PATH "/dev/input/event2"
const int key_exit = 102;
static int gpadc_fd = 0;
static char devpath[128];
static void sleep_ms(unsigned int secs)
{
struct timeval tval;
tval.tv_sec = secs / 1000;
tval.tv_usec = (secs * 1000) % 1000000;
select(0, NULL, NULL, NULL, &tval);
}
unsigned int test_gpadc(const char *event_file)
{
int code = 0, i;
struct input_event data;
struct timeval timeout;
fd_set read_fds;
gpadc_fd = open(DEV_PATH, O_RDONLY | O_NONBLOCK);
if(gpadc_fd <= 0)
{
printf("open %s error!\n", event_file);
return 1;
}
printf("open %s successful. \n", event_file);
while(1)
{
FD_ZERO(&read_fds);
FD_SET(gpadc_fd, &read_fds);
timeout.tv_sec = 0;
timeout.tv_usec = 50000;
select(gpadc_fd+1, &read_fds, NULL, NULL, &timeout);
read(gpadc_fd, &data, sizeof(data));
//printf("key %d pressed, value: %d \n", data.code, data.value);
//printf("type: %d [%d %d] \n\n", data.type, EV_MSC, EV_KEY);
#if 1
if(data.type == EV_KEY && data.value == 2){
printf("key %d pressed \n", data.code);
}else if(data.type == EV_KEY && data.value == 0){
printf("key %d releaseed \n", data.code);
}
#endif
sleep_ms(10);
//printf("delay 10ms \n");
}
close(gpadc_fd);
return 0;
}
int main(int argc, const char *argv[])
{
int rang_low = 0, rang_high = 0;
if(argc < 2){
printf("please input dev path. \n");
return -1;
}
printf("dev path: %s \n", argv[1]);
return test_gpadc(argv[1]);
}
=================
输出:
# ./gpadc-test /dev/input/event2
dev path: /dev/input/event2
open /dev/input/event2 successful.
key 130 releaseed
key 132 releaseed
key 134 releaseed
key 130 pressed
key 130 pressed
key 130 pressed
key 130 pressed
key 130 pressed
key 130 pressed
key 130 releaseed
key 134 releaseed
key 133 pressed
key 133 pressed
key 133 pressed
key 133 pressed
key 133 pressed
key 133 pressed
key 133 releaseed
key 134 releaseed
阅读(482) | 评论(0) | 转发(0) |