diff options
Diffstat (limited to 'firmware/target/hosted/aigo/button-erosq.c')
-rw-r--r-- | firmware/target/hosted/aigo/button-erosq.c | 106 |
1 files changed, 5 insertions, 101 deletions
diff --git a/firmware/target/hosted/aigo/button-erosq.c b/firmware/target/hosted/aigo/button-erosq.c index db7f7e24e5..1336442370 100644 --- a/firmware/target/hosted/aigo/button-erosq.c +++ b/firmware/target/hosted/aigo/button-erosq.c @@ -6,7 +6,6 @@ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * - * Copyright (C) 2017 Marcin Bukat * Copyright (C) 2020 Solomon Peachy * * This program is free software; you can redistribute it and/or @@ -18,30 +17,20 @@ * KIND, either express or implied. * ****************************************************************************/ -#include <poll.h> -//#include <dir.h> -#include <errno.h> -#include <unistd.h> -#include <sys/types.h> #include <linux/input.h> -#include <fcntl.h> -#include <string.h> -#include <stdlib.h> -#include "sysfs.h" #include "button.h" #include "button-target.h" -#include "panic.h" #include "kernel.h" -#include "backlight.h" -#include "backlight-target.h" #include "erosqlinux_codec.h" -#define NR_POLL_DESC 2 -static struct pollfd poll_fds[NR_POLL_DESC]; +/* + /dev/input/event0: rotary encoder + /dev/input/event1: all keys +*/ -static int button_map(int keycode) +int button_map(int keycode) { switch(keycode) { @@ -80,82 +69,6 @@ static int button_map(int keycode) } } -void button_init_device(void) -{ - const char * const input_devs[NR_POLL_DESC] = { - "/dev/input/event0", // Rotary encoder - "/dev/input/event1" // Keys - }; - - for(int i = 0; i < NR_POLL_DESC; i++) - { - int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC); - - if(fd < 0) - { - panicf("Cannot open input device: %s (%d)\n", input_devs[i], errno); - } - - poll_fds[i].fd = fd; - poll_fds[i].events = POLLIN; - poll_fds[i].revents = 0; - } -} - -int button_read_device(void) -{ - static int button_bitmap = 0; - struct input_event event; - - // FIXME TODO: Make this work via HAVE_SCROLL_WHEEL instead - - /* Wheel gives us press+release back to back, clear them after time elapses */ - static long last_tick = 0; - if (button_bitmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD) && - current_tick - last_tick >= 2) - { - button_bitmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD); - } - - /* check if there are any events pending and process them */ - while(poll(poll_fds, NR_POLL_DESC, 0)) - { - for(int i = 0; i < NR_POLL_DESC; i++) - { - /* read only if non-blocking */ - if(poll_fds[i].revents & POLLIN) - { - int size = read(poll_fds[i].fd, &event, sizeof(event)); - if(size == (int)sizeof(event)) - { - int keycode = event.code; - /* event.value == 1 means press - * event.value == 0 means release - */ - bool press = event.value ? true : false; - - /* map linux event code to rockbox button bitmap */ - if(press) - { - int bmap = button_map(keycode); - if (bmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD)) - last_tick = current_tick; - button_bitmap |= bmap; - } - else - { - /* Wheel gives us press+release back to back; ignore the release */ - int bmap = button_map(keycode) & ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD); - button_bitmap &= ~bmap; - } - } - } - } - } - - return button_bitmap; -} - bool headphones_inserted(void) { #ifdef BOOTLOADER @@ -177,12 +90,3 @@ bool lineout_inserted(void) return (ps == 1); } - -void button_close_device(void) -{ - /* close descriptors */ - for(int i = 0; i < NR_POLL_DESC; i++) - { - close(poll_fds[i].fd); - } -} |