From 2a471e288c16b91a7186a60b3fb84dd55a494c7a Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 8 Oct 2020 09:47:40 -0400 Subject: New port: AIGO EROS Q / EROS K The Q and K have a slightly different case, but the hardware under the shell is completely identical. These models are rebadged versions: * Hifiwalker H2 (== Q) * AGPTek H3 (== K) * Surfans F20 (== K) Other notes: * Significant improvements in the shared Hiby-platform launcher/loader * SD card can theoretically be hot-swapped now * Support external USB mass storage! * Some consolidation of Hiby-platform targets * Some consolidation of plugin keymaps Todo/known issues: * Keymaps need to be gone over properly * Convert to HAVE_SCROLLWHEEL? Change-Id: I5a8a4f22c38a5b69392ca7c0a8ad8c4e07d9523c --- firmware/target/hosted/aigo/usb-erosq.c | 118 ++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 firmware/target/hosted/aigo/usb-erosq.c (limited to 'firmware/target/hosted/aigo/usb-erosq.c') diff --git a/firmware/target/hosted/aigo/usb-erosq.c b/firmware/target/hosted/aigo/usb-erosq.c new file mode 100644 index 0000000000..2a3acf4d62 --- /dev/null +++ b/firmware/target/hosted/aigo/usb-erosq.c @@ -0,0 +1,118 @@ +/*************************************************************************** + * __________ __ ___ + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2018 by Marcin Bukat + * + * 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 +#include +#include "config.h" +#include "disk.h" +#include "usb.h" +#include "sysfs.h" +#include "power.h" +#include "power-erosq.h" + +static bool adb_mode = false; + +/* TODO: implement usb detection properly */ +int usb_detect(void) +{ + return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED; +} + +void usb_enable(bool on) +{ + /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell + * without entering ums mode + */ + if (!adb_mode) + { + sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0); + } +} + +/* This is called by usb thread after usb extract in order to return + * regular FS access + * + * returns the # of successful mounts +*/ +int disk_mount_all(void) +{ + const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"}; + const char *fs[] = {"vfat", "exfat"}; + + sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", ""); + + for (int i=0; i<2; i++) + { + for (int j=0; j<2; j++) + { + if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0) + { + return 1; + } + } + } + + return 0; +} + +/* This is called by usb thread after all threads ACKs usb inserted message + * + * returns the # of successful unmounts + */ +int disk_unmount_all(void) +{ + if (umount("/mnt/sd_0") == 0) + { + sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0"); + return 1; + } + + return 0; +} + +void usb_init_device(void) +{ + char functions[32] = {0}; + + /* Check if ADB was activated in bootloader */ + sysfs_get_string("/sys/class/android_usb/android0/functions", functions, sizeof(functions)); + adb_mode = (strstr(functions, "adb") == NULL) ? false : true; + + usb_enable(false); + + if (adb_mode) + { + sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage,adb"); + sysfs_set_string("/sys/class/android_usb/android0/idVendor", "18D1"); + sysfs_set_string("/sys/class/android_usb/android0/idProduct", "D002"); + } + else + { + sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage"); + sysfs_set_string("/sys/class/android_usb/android0/idVendor", "C502"); + sysfs_set_string("/sys/class/android_usb/android0/idProduct", "0023"); + } + + sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org"); + sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player"); + sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF"); + sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "ErosQ 0100"); +} -- cgit v1.2.3