diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-10-29 09:37:57 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-10-31 14:17:22 +0000 |
commit | 125e97b0bf979e1d03b84b17e72fc655b74015fb (patch) | |
tree | 693b24abb83fad6dbc9e3da6b3b0fb22c0e20bd6 /firmware/target/hosted/xduoo/button-xduoo.c | |
parent | dd82f13fa1241266576b508180fcf90b8d9bda2c (diff) | |
download | rockbox-125e97b0bf979e1d03b84b17e72fc655b74015fb.tar.gz rockbox-125e97b0bf979e1d03b84b17e72fc655b74015fb.zip |
hosted: Consolidate common /dev/input code shared by the hiby targets
* Enable dynamic number of input devices, needed for bluetooth support
Change-Id: Ic2425834eb9b0fff298899ab45f3115ce1d95e91
Diffstat (limited to 'firmware/target/hosted/xduoo/button-xduoo.c')
-rw-r--r-- | firmware/target/hosted/xduoo/button-xduoo.c | 88 |
1 files changed, 1 insertions, 87 deletions
diff --git a/firmware/target/hosted/xduoo/button-xduoo.c b/firmware/target/hosted/xduoo/button-xduoo.c index 67cb9a6c46..f5b6c6be62 100644 --- a/firmware/target/hosted/xduoo/button-xduoo.c +++ b/firmware/target/hosted/xduoo/button-xduoo.c | |||
@@ -18,30 +18,15 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
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> | 21 | #include <linux/input.h> |
27 | #include <fcntl.h> | ||
28 | #include <string.h> | ||
29 | #include <stdlib.h> | ||
30 | 22 | ||
31 | #include "sysfs.h" | ||
32 | #include "button.h" | 23 | #include "button.h" |
33 | #include "button-target.h" | 24 | #include "button-target.h" |
34 | #include "panic.h" | ||
35 | 25 | ||
36 | #include "kernel.h" | 26 | #include "kernel.h" |
37 | #include "backlight.h" | ||
38 | #include "backlight-target.h" | ||
39 | #include "xduoolinux_codec.h" | 27 | #include "xduoolinux_codec.h" |
40 | 28 | ||
41 | #define NR_POLL_DESC 3 | 29 | int button_map(int keycode) |
42 | static struct pollfd poll_fds[NR_POLL_DESC]; | ||
43 | |||
44 | static int button_map(int keycode) | ||
45 | { | 30 | { |
46 | switch(keycode) | 31 | switch(keycode) |
47 | { | 32 | { |
@@ -74,68 +59,6 @@ static int button_map(int keycode) | |||
74 | } | 59 | } |
75 | } | 60 | } |
76 | 61 | ||
77 | void button_init_device(void) | ||
78 | { | ||
79 | const char * const input_devs[NR_POLL_DESC] = { | ||
80 | "/dev/input/event0", | ||
81 | "/dev/input/event1", | ||
82 | "/dev/input/event2" | ||
83 | }; | ||
84 | |||
85 | for(int i = 0; i < NR_POLL_DESC; i++) | ||
86 | { | ||
87 | int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC); | ||
88 | |||
89 | if(fd < 0) | ||
90 | { | ||
91 | panicf("Cannot open input device: %s\n", input_devs[i]); | ||
92 | } | ||
93 | |||
94 | poll_fds[i].fd = fd; | ||
95 | poll_fds[i].events = POLLIN; | ||
96 | poll_fds[i].revents = 0; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | int button_read_device(void) | ||
101 | { | ||
102 | static int button_bitmap = 0; | ||
103 | struct input_event event; | ||
104 | |||
105 | /* check if there are any events pending and process them */ | ||
106 | while(poll(poll_fds, NR_POLL_DESC, 0)) | ||
107 | { | ||
108 | for(int i = 0; i < NR_POLL_DESC; i++) | ||
109 | { | ||
110 | /* read only if non-blocking */ | ||
111 | if(poll_fds[i].revents & POLLIN) | ||
112 | { | ||
113 | int size = read(poll_fds[i].fd, &event, sizeof(event)); | ||
114 | if(size == (int)sizeof(event)) | ||
115 | { | ||
116 | int keycode = event.code; | ||
117 | /* event.value == 1 means press | ||
118 | * event.value == 0 means release | ||
119 | */ | ||
120 | bool press = event.value ? true : false; | ||
121 | |||
122 | /* map linux event code to rockbox button bitmap */ | ||
123 | if(press) | ||
124 | { | ||
125 | button_bitmap |= button_map(keycode); | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | button_bitmap &= ~button_map(keycode); | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | |||
136 | return button_bitmap; | ||
137 | } | ||
138 | |||
139 | bool headphones_inserted(void) | 62 | bool headphones_inserted(void) |
140 | { | 63 | { |
141 | #ifdef BOOTLOADER | 64 | #ifdef BOOTLOADER |
@@ -156,12 +79,3 @@ bool lineout_inserted(void) | |||
156 | #endif | 79 | #endif |
157 | return (ps == 1); | 80 | return (ps == 1); |
158 | } | 81 | } |
159 | |||
160 | void button_close_device(void) | ||
161 | { | ||
162 | /* close descriptors */ | ||
163 | for(int i = 0; i < NR_POLL_DESC; i++) | ||
164 | { | ||
165 | close(poll_fds[i].fd); | ||
166 | } | ||
167 | } | ||