summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android/dx50/button-dx50.c
diff options
context:
space:
mode:
authorSimon Rothen <rothen@gmx.net>2014-08-30 13:15:53 +0200
committerMichael Giacomelli <giac2000@hotmail.com>2014-09-18 18:19:01 +0200
commit0b5ad60c26f30dc5363c21e436b73292c09ac567 (patch)
tree2d7cee2b2133218d59e0f462c9dbdbec8e88b2e2 /firmware/target/hosted/android/dx50/button-dx50.c
parent1f0fa0546647a191c52784a4a225982ffbd1af11 (diff)
downloadrockbox-0b5ad60c26f30dc5363c21e436b73292c09ac567.tar.gz
rockbox-0b5ad60c26f30dc5363c21e436b73292c09ac567.zip
Introducing Targets iBasso DX50 & iBasso DX90
The port to for this two targets has been entirely developped by Ilia Sergachev (alias Il or xzcc). His source can be found at https://bitbucket.org/isergachev/rockbox . The few necesary modifications for the DX90 port was done by headwhacker form head-fi.org. Unfortunately i could not try out the final state of the DX90 port. The port is hosted on android (without java) as standalone app. The official Firmware is required to run this port. Ilia did modify the source files for the "android" target in the rockbox source to make the DX port work. The work I did was to separate the code for DX50 (&DX90) from the android target. On this Target Ilia used source from tinyalsa from AOSP. I did not touch that part of the code because I do not understand it. What else I changed from Ilias sources besides the separation from the target "android": * removed a dirty hack to keep backlight off * changed value battery meter to voltage battery meter * made all plugins compile (named target as "standalone") and added keymaps * i added the graphics for the manual but did not do anything else for the manual yet * minor optimizations known bugs: * timers are slowed donw when playback is active (tinyalsa related?) * some minor bugs Things to do: * The main prolem will be how to install the app correctly. A guy called DOC2008 added a CWM (by androtab.info) to the official firmware and Ilia made a CWM installation script and a dualboot selector (rbutils/ibassoboot, build with ndk-build). We will have to find a way to install rockbox in a proper way without breaking any copyrights. Maybe ADB is an option but it is not enable with OF by default. Patching the OF is probably the way to go. * All the wiki and manual to build: needed: android ndk installed, android sdk installed with additional build-tools 19.1.0 installed ./tools/configure select iBasso DX50 or iBasso DX90 make -j apk the content of rockbox.zip/.rockbox needs to be copied to /system/rockbox/app_rockbox/rockbox/ (rockbox app not needed) the content of libs/armeabi to /system/rockbox/lib/ (rockbox app needed) The boot selector is needed as /system/bin/MangoPlayer and the iBasso app as /system/bin/MangoPlayer_original. There is also the "vold" file. The one from OF does not work with DX50 rockbox (DX90 works!?), the one from Ilia is necessary. Until we have found a proper way to install it, it can only be installed following the instructions of Ilia on his bitbucket page, using the CWM-OF and his installation script package. Change-Id: Ic4faaf84824c162aabcc08e492cee6e0068719d0 Reviewed-on: http://gerrit.rockbox.org/941 Tested: Chiwen Chang <rock1104.tw@yahoo.com.tw> Reviewed-by: Michael Giacomelli <giac2000@hotmail.com>
Diffstat (limited to 'firmware/target/hosted/android/dx50/button-dx50.c')
-rw-r--r--firmware/target/hosted/android/dx50/button-dx50.c314
1 files changed, 314 insertions, 0 deletions
diff --git a/firmware/target/hosted/android/dx50/button-dx50.c b/firmware/target/hosted/android/dx50/button-dx50.c
new file mode 100644
index 0000000000..5ab58ce420
--- /dev/null
+++ b/firmware/target/hosted/android/dx50/button-dx50.c
@@ -0,0 +1,314 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <stdbool.h>
24#include "button.h"
25#include "buttonmap.h"
26#include "config.h"
27#include "kernel.h"
28#include "system.h"
29#include "touchscreen.h"
30#include "powermgmt.h"
31#include "backlight.h"
32
33#include <linux/input.h>
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <stdint.h>
38#include <dirent.h>
39#include <fcntl.h>
40#include <sys/ioctl.h>
41#include <sys/inotify.h>
42#include <sys/limits.h>
43#include <sys/poll.h>
44#include <errno.h>
45
46
47static struct pollfd *ufds;
48static char **device_names;
49static int nfds;
50
51enum {
52 PRINT_DEVICE_ERRORS = 1U << 0,
53 PRINT_DEVICE = 1U << 1,
54 PRINT_DEVICE_NAME = 1U << 2,
55 PRINT_DEVICE_INFO = 1U << 3,
56 PRINT_VERSION = 1U << 4,
57 PRINT_POSSIBLE_EVENTS = 1U << 5,
58 PRINT_INPUT_PROPS = 1U << 6,
59 PRINT_HID_DESCRIPTOR = 1U << 7,
60
61 PRINT_ALL_INFO = (1U << 8) - 1,
62
63 PRINT_LABELS = 1U << 16,
64};
65
66static int last_y, last_x;
67static int last_btns;
68
69static enum {
70 STATE_UNKNOWN,
71 STATE_UP,
72 STATE_DOWN
73} last_touch_state = STATE_UNKNOWN;
74
75
76static int open_device(const char *device, int print_flags)
77{
78 int fd;
79 struct pollfd *new_ufds;
80 char **new_device_names;
81
82 fd = open(device, O_RDWR);
83 if(fd < 0) {
84 if(print_flags & PRINT_DEVICE_ERRORS)
85 fprintf(stderr, "could not open %s, %s\n", device, strerror(errno));
86 return -1;
87 }
88
89 new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1));
90 if(new_ufds == NULL) {
91 fprintf(stderr, "out of memory\n");
92 return -1;
93 }
94 ufds = new_ufds;
95 new_device_names = realloc(device_names, sizeof(device_names[0]) * (nfds + 1));
96 if(new_device_names == NULL) {
97 fprintf(stderr, "out of memory\n");
98 return -1;
99 }
100 device_names = new_device_names;
101
102 ufds[nfds].fd = fd;
103 ufds[nfds].events = POLLIN;
104 device_names[nfds] = strdup(device);
105 nfds++;
106
107 return 0;
108}
109
110
111
112static int scan_dir(const char *dirname, int print_flags)
113{
114 char devname[PATH_MAX];
115 char *filename;
116 DIR *dir;
117 struct dirent *de;
118 dir = opendir(dirname);
119 if(dir == NULL)
120 return -1;
121 strcpy(devname, dirname);
122 filename = devname + strlen(devname);
123 *filename++ = '/';
124 while((de = readdir(dir))) {
125 if(de->d_name[0] == '.' &&
126 (de->d_name[1] == '\0' ||
127 (de->d_name[1] == '.' && de->d_name[2] == '\0')))
128 continue;
129 strcpy(filename, de->d_name);
130 open_device(devname, print_flags);
131 }
132 closedir(dir);
133 return 0;
134}
135
136bool _hold;
137
138bool button_hold()
139{
140 FILE *f = fopen("/sys/class/axppower/holdkey", "r");
141 char x;
142 fscanf(f, "%c", &x);
143 fclose(f);
144 _hold = !(x&STATE_UNLOCKED);
145 return _hold;
146}
147
148
149void button_init_device(void)
150{
151 int res;
152 int print_flags = 0;
153 const char *device = NULL;
154 const char *device_path = "/dev/input";
155
156 nfds = 1;
157 ufds = calloc(1, sizeof(ufds[0]));
158 ufds[0].fd = inotify_init();
159 ufds[0].events = POLLIN;
160 if(device) {
161 res = open_device(device, print_flags);
162 if(res < 0) {
163 // return 1;
164 }
165 } else {
166 res = inotify_add_watch(ufds[0].fd, device_path, IN_DELETE | IN_CREATE);
167 if(res < 0) {
168 fprintf(stderr, "could not add watch for %s, %s\n", device_path, strerror(errno));
169 // return 1;
170 }
171 res = scan_dir(device_path, print_flags);
172 if(res < 0) {
173 fprintf(stderr, "scan dir failed for %s\n", device_path);
174 // return 1;
175 }
176 }
177
178 button_hold(); //store state
179
180 set_rockbox_ready();
181}
182
183void touchscreen_enable_device(bool en)
184{
185 (void)en; /* FIXME: do something smart */
186}
187
188
189int keycode_to_button(int keyboard_key)
190{
191 switch(keyboard_key){
192 case KEYCODE_PWR:
193 return BUTTON_POWER;
194
195 case KEYCODE_PWR_LONG:
196 return BUTTON_POWER_LONG;
197
198 case KEYCODE_VOLPLUS:
199 return BUTTON_VOL_UP;
200
201 case KEYCODE_VOLMINUS:
202 return BUTTON_VOL_DOWN;
203
204 case KEYCODE_PREV:
205 return BUTTON_LEFT;
206
207 case KEYCODE_NEXT:
208 return BUTTON_RIGHT;
209
210 case KEYCODE_PLAY:
211 return BUTTON_PLAY;
212
213 case KEYCODE_HOLD:
214 button_hold(); /* store state */
215 backlight_hold_changed(_hold);
216 return BUTTON_NONE;
217
218 default:
219 return BUTTON_NONE;
220 }
221}
222
223
224int button_read_device(int *data)
225{
226 int i;
227 int res;
228 struct input_event event;
229 int read_more;
230 unsigned button = 0;
231
232 if(last_btns & BUTTON_POWER_LONG)
233 {
234 return last_btns; /* simulate repeat */
235 }
236
237 do {
238 read_more = 0;
239 poll(ufds, nfds, 10);
240 for(i = 1; i < nfds; i++) {
241 if(ufds[i].revents & POLLIN) {
242 res = read(ufds[i].fd, &event, sizeof(event));
243 if(res < (int)sizeof(event)) {
244 fprintf(stderr, "could not get event\n");
245 }
246
247 switch(event.type)
248 {
249 case 1: /* HW-Button */
250 button = keycode_to_button(event.code);
251 if (_hold) /* we have to wait for keycode_to_button() first to maybe clear hold state */
252 break;
253 if (button == BUTTON_NONE)
254 {
255 last_btns = button;
256 break;
257 }
258/* workaround for a wrong feedback, only present with DX90 */
259#if defined(DX90)
260 if (button == BUTTON_RIGHT && (last_btns & BUTTON_LEFT == BUTTON_LEFT) && !event.value)
261 {
262 button = BUTTON_LEFT;
263 }
264#endif
265 if (event.value)
266 last_btns |= button;
267 else
268 last_btns &= (~button);
269
270 break;
271
272 case 3: /* Touchscreen */
273 if(_hold)
274 break;
275
276 switch(event.code)
277 {
278 case 53: /* x -> next will be y */
279 last_x = event.value;
280 read_more = 1;
281 break;
282 case 54: /* y */
283 last_y = event.value;
284 break;
285 case 57: /* press -> next will be x */
286 if(event.value==1)
287 {
288 last_touch_state = STATE_DOWN;
289 read_more = 1;
290 }
291 else
292 last_touch_state = STATE_UP;
293 break;
294 }
295 break;
296 }
297 }
298 }
299 } while(read_more);
300
301
302 /* Get grid button/coordinates based on the current touchscreen mode
303 *
304 * Caveat: the caller seemingly depends on *data always being filled with
305 * the last known touchscreen position, so always call
306 * touchscreen_to_pixels() */
307 int touch = touchscreen_to_pixels(last_x, last_y, data);
308
309 if (last_touch_state == STATE_DOWN)
310 return last_btns | touch;
311
312 return last_btns;
313}
314