static int tq210_hs0038_read(struct tq210_hs0038 *hs0038_data) { u32 values[4]; int i=0; struct gpio_keys_button *button = hs0038_data->button; gpio_direction_input(button->gpio); while(((gpio_get_value(S5PV210_GPH0(6))) & 1)==0);//在9ms内判断IO口的值 while(((gpio_get_value(S5PV210_GPH0(6))) & 1)==1) { udelay(900); if(i>4) return -1; i++; } values[0] = serial_data_read_byte(); values[1] = serial_data_read_byte(); values[2] = serial_data_read_byte(); values[3] = serial_data_read_byte(); for(i=0;i<sizeof(values)/sizeof(values[0]);i++) { printk("values[%d]=0x%x\n", i,values[i]); } input_report_key(hs0038_data->input,values[0], 1); input_report_key(hs0038_data->input,values[0], 0); input_sync(hs0038_data->input); input_report_key(hs0038_data->input,values[1], 1); input_report_key(hs0038_data->input,values[1], 0); input_sync(hs0038_data->input); input_report_key(hs0038_data->input,values[2], 1); input_report_key(hs0038_data->input,values[2], 0); input_sync(hs0038_data->input); input_report_key(hs0038_data->input,values[3], 1); input_report_key(hs0038_data->input,values[3], 0); input_sync(hs0038_data->input);
所以要实现read到键值,就要修改drivers/input/input.c
case EV_KEY: // if (is_event_supported(code, dev->keybit, KEY_MAX) && // !!test_bit(code, dev->key) != value) if(1){ if (value != 2) { __change_bit(code, dev->key); if (value) input_start_autorepeat(dev, code); else input_stop_autorepeat(dev); } disposition = INPUT_PASS_TO_HANDLERS; } break;
这下就可以了
#include<stdio.h> //#include<stdlib.h> #include<linux/input.h> #include<fcntl.h> main() { int keys_id; struct input_event t; keys_id = open("/dev/event1",O_RDONLY); if(keys_id < 0) { printf("error\n"); } printf("begin\n"); while(1) { if(read(keys_id,&t,sizeof(t)) == sizeof(t)) { if(t.type == EV_KEY) if(t.value == 0|| t.value ==1) { printf("type:%d,code:%x,value:%d\n",t.type,t.code,t.value); } } else { printf("ty:%d,co:%d,val:%d\n",t.type,t.code,t.value); } } }