There are buttons on pcDuino v2, that are by default not used by Lbuntu linux system. In this post, we will show how to use them.
1. Modify pcDuino.fex file. The file can be found at: https://github.com/pcduino/kernel/blob/master/sunxi-boards/sys_config/a10/pcduino.fex, append the following lines:
[sb_keypad_para] sb_key_used = 1 key_num = 3 ; BACK ==> KEY_ESC key_pin_0 = port:PH17<6><1><3> key_code_0 = 1 ; MENU ==> KEY_SPACE key_pin_1 = port:PH18<6><1><3> key_code_1 = 57 ; HOME ==> KEY_ENTER key_pin_2 = port:PH19<6><1><3> key_code_2 = 28
We can rebuild the whole kernel, or just compile the fex file. For the second approach, we can use fex2bin tool that can be downloaded from https://github.com/linux-sunxi/sunxi-tools. To compile it, we just need to run:
$ ./fex2bin pcduino.fex script.bin
2. After the compilation is done, copy it over to pcDuino and replace the existing script.bin.
$mount /dev/nanda /mnt $cp pcduino.fex /mnt/script.bin
3. Reboot your pcDuino
4. Load keypad driver, and now you can find there are event1 under /dev/input even if you didn’t install keyboard and mouse:
$modprobe keypad
5. Now if you use cat to list the content of this file, and press any buttons, it will display the information:
6. If you open any terminals, you will find out that menu button is return, home button is space, and back button actually is backspace.
7. In the following, we show how to use these buttons in a C code:
We can modify the code for these buttons:
[sb_keypad_para] sb_key_used = 1 key_num = 3 ; BACK ==> KEY_ESC key_pin_0 = port:PH17<6><1><3> key_code_0 = 1 ;other code ; MENU ==> KEY_SPACE key_pin_1 = port:PH18<6><1><3> key_code_1 = 57;other code ; HOME ==> KEY_ENTER key_pin_2 = port:PH19<6><1><3> key_code_2 = 28;other code
The following is the C code to test:
#include <stdio.h> #include <fcntl.h> #include <linux/input.h> #include <sys/types.h> #include <unistd.h> int main(int argc, char** argv) { int fd; int count; int i = 0; int j = 0; struct input_event key2; fd = open("/dev/event1", O_RDWR); if (fd < 0) { perror("open"); return -1; } while (1) { lseek(fd, 0, SEEK_SET); count = read(fd, &key2, sizeof(struct input_event)); if(count != sizeof(struct input_event)) { perror("read"); } if(EV_KEY == key2.type) { printf("\r\ni = %d, type:%d, code:%d, value:%d\r\n", i, key2.type, key2.code, key2.value); if (key2.value) { i++; printf("***********the k2 down %d times***********\r\n", i); } else { printf("****************the k2 up*****************\r\n"); } } if(EV_SYN == key2.type) { printf("syn event\r\n"); if (++j == 2) { j = 0; printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\n"); } } } close(fd); return 0; }
Leave a Reply
You must be logged in to post a comment.