From 0b5ad60c26f30dc5363c21e436b73292c09ac567 Mon Sep 17 00:00:00 2001 From: Simon Rothen Date: Sat, 30 Aug 2014 13:15:53 +0200 Subject: 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 Reviewed-by: Michael Giacomelli --- firmware/target/hosted/android/dx50/button-dx50.c | 314 ++++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100644 firmware/target/hosted/android/dx50/button-dx50.c (limited to 'firmware/target/hosted/android/dx50/button-dx50.c') 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (c) 2010 Thomas Martitz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#include +#include "button.h" +#include "buttonmap.h" +#include "config.h" +#include "kernel.h" +#include "system.h" +#include "touchscreen.h" +#include "powermgmt.h" +#include "backlight.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static struct pollfd *ufds; +static char **device_names; +static int nfds; + +enum { + PRINT_DEVICE_ERRORS = 1U << 0, + PRINT_DEVICE = 1U << 1, + PRINT_DEVICE_NAME = 1U << 2, + PRINT_DEVICE_INFO = 1U << 3, + PRINT_VERSION = 1U << 4, + PRINT_POSSIBLE_EVENTS = 1U << 5, + PRINT_INPUT_PROPS = 1U << 6, + PRINT_HID_DESCRIPTOR = 1U << 7, + + PRINT_ALL_INFO = (1U << 8) - 1, + + PRINT_LABELS = 1U << 16, +}; + +static int last_y, last_x; +static int last_btns; + +static enum { + STATE_UNKNOWN, + STATE_UP, + STATE_DOWN +} last_touch_state = STATE_UNKNOWN; + + +static int open_device(const char *device, int print_flags) +{ + int fd; + struct pollfd *new_ufds; + char **new_device_names; + + fd = open(device, O_RDWR); + if(fd < 0) { + if(print_flags & PRINT_DEVICE_ERRORS) + fprintf(stderr, "could not open %s, %s\n", device, strerror(errno)); + return -1; + } + + new_ufds = realloc(ufds, sizeof(ufds[0]) * (nfds + 1)); + if(new_ufds == NULL) { + fprintf(stderr, "out of memory\n"); + return -1; + } + ufds = new_ufds; + new_device_names = realloc(device_names, sizeof(device_names[0]) * (nfds + 1)); + if(new_device_names == NULL) { + fprintf(stderr, "out of memory\n"); + return -1; + } + device_names = new_device_names; + + ufds[nfds].fd = fd; + ufds[nfds].events = POLLIN; + device_names[nfds] = strdup(device); + nfds++; + + return 0; +} + + + +static int scan_dir(const char *dirname, int print_flags) +{ + char devname[PATH_MAX]; + char *filename; + DIR *dir; + struct dirent *de; + dir = opendir(dirname); + if(dir == NULL) + return -1; + strcpy(devname, dirname); + filename = devname + strlen(devname); + *filename++ = '/'; + while((de = readdir(dir))) { + if(de->d_name[0] == '.' && + (de->d_name[1] == '\0' || + (de->d_name[1] == '.' && de->d_name[2] == '\0'))) + continue; + strcpy(filename, de->d_name); + open_device(devname, print_flags); + } + closedir(dir); + return 0; +} + +bool _hold; + +bool button_hold() +{ + FILE *f = fopen("/sys/class/axppower/holdkey", "r"); + char x; + fscanf(f, "%c", &x); + fclose(f); + _hold = !(x&STATE_UNLOCKED); + return _hold; +} + + +void button_init_device(void) +{ + int res; + int print_flags = 0; + const char *device = NULL; + const char *device_path = "/dev/input"; + + nfds = 1; + ufds = calloc(1, sizeof(ufds[0])); + ufds[0].fd = inotify_init(); + ufds[0].events = POLLIN; + if(device) { + res = open_device(device, print_flags); + if(res < 0) { + // return 1; + } + } else { + res = inotify_add_watch(ufds[0].fd, device_path, IN_DELETE | IN_CREATE); + if(res < 0) { + fprintf(stderr, "could not add watch for %s, %s\n", device_path, strerror(errno)); + // return 1; + } + res = scan_dir(device_path, print_flags); + if(res < 0) { + fprintf(stderr, "scan dir failed for %s\n", device_path); + // return 1; + } + } + + button_hold(); //store state + + set_rockbox_ready(); +} + +void touchscreen_enable_device(bool en) +{ + (void)en; /* FIXME: do something smart */ +} + + +int keycode_to_button(int keyboard_key) +{ + switch(keyboard_key){ + case KEYCODE_PWR: + return BUTTON_POWER; + + case KEYCODE_PWR_LONG: + return BUTTON_POWER_LONG; + + case KEYCODE_VOLPLUS: + return BUTTON_VOL_UP; + + case KEYCODE_VOLMINUS: + return BUTTON_VOL_DOWN; + + case KEYCODE_PREV: + return BUTTON_LEFT; + + case KEYCODE_NEXT: + return BUTTON_RIGHT; + + case KEYCODE_PLAY: + return BUTTON_PLAY; + + case KEYCODE_HOLD: + button_hold(); /* store state */ + backlight_hold_changed(_hold); + return BUTTON_NONE; + + default: + return BUTTON_NONE; + } +} + + +int button_read_device(int *data) +{ + int i; + int res; + struct input_event event; + int read_more; + unsigned button = 0; + + if(last_btns & BUTTON_POWER_LONG) + { + return last_btns; /* simulate repeat */ + } + + do { + read_more = 0; + poll(ufds, nfds, 10); + for(i = 1; i < nfds; i++) { + if(ufds[i].revents & POLLIN) { + res = read(ufds[i].fd, &event, sizeof(event)); + if(res < (int)sizeof(event)) { + fprintf(stderr, "could not get event\n"); + } + + switch(event.type) + { + case 1: /* HW-Button */ + button = keycode_to_button(event.code); + if (_hold) /* we have to wait for keycode_to_button() first to maybe clear hold state */ + break; + if (button == BUTTON_NONE) + { + last_btns = button; + break; + } +/* workaround for a wrong feedback, only present with DX90 */ +#if defined(DX90) + if (button == BUTTON_RIGHT && (last_btns & BUTTON_LEFT == BUTTON_LEFT) && !event.value) + { + button = BUTTON_LEFT; + } +#endif + if (event.value) + last_btns |= button; + else + last_btns &= (~button); + + break; + + case 3: /* Touchscreen */ + if(_hold) + break; + + switch(event.code) + { + case 53: /* x -> next will be y */ + last_x = event.value; + read_more = 1; + break; + case 54: /* y */ + last_y = event.value; + break; + case 57: /* press -> next will be x */ + if(event.value==1) + { + last_touch_state = STATE_DOWN; + read_more = 1; + } + else + last_touch_state = STATE_UP; + break; + } + break; + } + } + } + } while(read_more); + + + /* Get grid button/coordinates based on the current touchscreen mode + * + * Caveat: the caller seemingly depends on *data always being filled with + * the last known touchscreen position, so always call + * touchscreen_to_pixels() */ + int touch = touchscreen_to_pixels(last_x, last_y, data); + + if (last_touch_state == STATE_DOWN) + return last_btns | touch; + + return last_btns; +} + -- cgit v1.2.3