summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/aigo/button-erosq.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/aigo/button-erosq.c')
-rw-r--r--firmware/target/hosted/aigo/button-erosq.c106
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 @@
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * 8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2020 Solomon Peachy 9 * Copyright (C) 2020 Solomon Peachy
11 * 10 *
12 * This program is free software; you can redistribute it and/or 11 * This program is free software; you can redistribute it and/or
@@ -18,30 +17,20 @@
18 * KIND, either express or implied. 17 * KIND, either express or implied.
19 * 18 *
20 ****************************************************************************/ 19 ****************************************************************************/
21#include <poll.h>
22//#include <dir.h>
23#include <errno.h>
24#include <unistd.h>
25#include <sys/types.h>
26#include <linux/input.h> 20#include <linux/input.h>
27#include <fcntl.h>
28#include <string.h>
29#include <stdlib.h>
30 21
31#include "sysfs.h"
32#include "button.h" 22#include "button.h"
33#include "button-target.h" 23#include "button-target.h"
34#include "panic.h"
35 24
36#include "kernel.h" 25#include "kernel.h"
37#include "backlight.h"
38#include "backlight-target.h"
39#include "erosqlinux_codec.h" 26#include "erosqlinux_codec.h"
40 27
41#define NR_POLL_DESC 2 28/*
42static struct pollfd poll_fds[NR_POLL_DESC]; 29 /dev/input/event0: rotary encoder
30 /dev/input/event1: all keys
31*/
43 32
44static int button_map(int keycode) 33int button_map(int keycode)
45{ 34{
46 switch(keycode) 35 switch(keycode)
47 { 36 {
@@ -80,82 +69,6 @@ static int button_map(int keycode)
80 } 69 }
81} 70}
82 71
83void button_init_device(void)
84{
85 const char * const input_devs[NR_POLL_DESC] = {
86 "/dev/input/event0", // Rotary encoder
87 "/dev/input/event1" // Keys
88 };
89
90 for(int i = 0; i < NR_POLL_DESC; i++)
91 {
92 int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC);
93
94 if(fd < 0)
95 {
96 panicf("Cannot open input device: %s (%d)\n", input_devs[i], errno);
97 }
98
99 poll_fds[i].fd = fd;
100 poll_fds[i].events = POLLIN;
101 poll_fds[i].revents = 0;
102 }
103}
104
105int button_read_device(void)
106{
107 static int button_bitmap = 0;
108 struct input_event event;
109
110 // FIXME TODO: Make this work via HAVE_SCROLL_WHEEL instead
111
112 /* Wheel gives us press+release back to back, clear them after time elapses */
113 static long last_tick = 0;
114 if (button_bitmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD) &&
115 current_tick - last_tick >= 2)
116 {
117 button_bitmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
118 }
119
120 /* check if there are any events pending and process them */
121 while(poll(poll_fds, NR_POLL_DESC, 0))
122 {
123 for(int i = 0; i < NR_POLL_DESC; i++)
124 {
125 /* read only if non-blocking */
126 if(poll_fds[i].revents & POLLIN)
127 {
128 int size = read(poll_fds[i].fd, &event, sizeof(event));
129 if(size == (int)sizeof(event))
130 {
131 int keycode = event.code;
132 /* event.value == 1 means press
133 * event.value == 0 means release
134 */
135 bool press = event.value ? true : false;
136
137 /* map linux event code to rockbox button bitmap */
138 if(press)
139 {
140 int bmap = button_map(keycode);
141 if (bmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD))
142 last_tick = current_tick;
143 button_bitmap |= bmap;
144 }
145 else
146 {
147 /* Wheel gives us press+release back to back; ignore the release */
148 int bmap = button_map(keycode) & ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
149 button_bitmap &= ~bmap;
150 }
151 }
152 }
153 }
154 }
155
156 return button_bitmap;
157}
158
159bool headphones_inserted(void) 72bool headphones_inserted(void)
160{ 73{
161#ifdef BOOTLOADER 74#ifdef BOOTLOADER
@@ -177,12 +90,3 @@ bool lineout_inserted(void)
177 90
178 return (ps == 1); 91 return (ps == 1);
179} 92}
180
181void button_close_device(void)
182{
183 /* close descriptors */
184 for(int i = 0; i < NR_POLL_DESC; i++)
185 {
186 close(poll_fds[i].fd);
187 }
188}