summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2018-11-05 13:01:55 +0100
committerSolomon Peachy <pizza@shaftnet.org>2020-04-06 18:15:41 +0200
commit180cef835bf40d0081895773aaa637ac926bb0ac (patch)
tree48c380d76c0ea40931cb5e863b40fc5dfa1ecba4 /firmware
parentced3a20aacf26642ccc3ffd136f64247c67e5769 (diff)
downloadrockbox-180cef835bf40d0081895773aaa637ac926bb0ac.tar.gz
rockbox-180cef835bf40d0081895773aaa637ac926bb0ac.tar.bz2
rockbox-180cef835bf40d0081895773aaa637ac926bb0ac.zip
xDuoo X3II and X20 port
Provided by Roman Stolyarov Integration, Refactoring, and Upstreaming by Solomon Peachy X3II confirmed working by forum tester, X20 is nearly identical. This includes bootloader, main firmware, and the flash image patcher. Eventual Todo: * Further refactor AGPTek Rocker & xduoo hiby bootloaders * Further refactor AGPTek Rocker & xduoo hosted platform code Change-Id: I34a674051d368efcc75d1d18c725971fe46c3eee
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES38
-rw-r--r--firmware/asm/SOURCES2
-rw-r--r--firmware/drivers/audio/xduoolinux_codec.c122
-rw-r--r--firmware/export/audiohw.h2
-rw-r--r--firmware/export/config.h6
-rw-r--r--firmware/export/config/agptekrocker.h2
-rw-r--r--firmware/export/config/xduoox20.h126
-rw-r--r--firmware/export/config/xduoox3ii.h126
-rw-r--r--firmware/export/rbpaths.h2
-rw-r--r--firmware/export/xduoolinux_codec.h7
-rw-r--r--firmware/target/hosted/backlight-target.h (renamed from firmware/target/hosted/agptek/backlight-target.h)0
-rw-r--r--firmware/target/hosted/backlight-unix.c (renamed from firmware/target/hosted/agptek/backlight-agptek.c)0
-rw-r--r--firmware/target/hosted/filesystem-app.c6
-rw-r--r--firmware/target/hosted/rtc.c2
-rw-r--r--firmware/target/hosted/sdl/sim-ui-defines.h16
-rw-r--r--firmware/target/hosted/sysfs.c (renamed from firmware/target/hosted/agptek/sysfs.c)0
-rw-r--r--firmware/target/hosted/sysfs.h (renamed from firmware/target/hosted/agptek/sysfs.h)0
-rw-r--r--firmware/target/hosted/system-hosted.c (renamed from firmware/target/hosted/agptek/system-agptek.c)0
-rw-r--r--firmware/target/hosted/xduoo/adc-target.h0
-rw-r--r--firmware/target/hosted/xduoo/button-target.h46
-rw-r--r--firmware/target/hosted/xduoo/button-xduoo.c202
-rw-r--r--firmware/target/hosted/xduoo/debug-xduoo.c6
-rw-r--r--firmware/target/hosted/xduoo/lcd-target.h32
-rw-r--r--firmware/target/hosted/xduoo/lcd-xduoo.c140
-rw-r--r--firmware/target/hosted/xduoo/power-xduoo.c74
-rw-r--r--firmware/target/hosted/xduoo/power-xduoo.h31
-rw-r--r--firmware/target/hosted/xduoo/powermgmt-xduoo.c70
-rw-r--r--firmware/target/hosted/xduoo/system-target.h28
-rw-r--r--firmware/target/hosted/xduoo/usb-xduoo.c118
-rw-r--r--firmware/target/hosted/xduoo/xduoo.make52
30 files changed, 1236 insertions, 20 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 89f4f52895..7be6010ab7 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -113,25 +113,37 @@ target/hosted/sonynwz/nvp-nwz.c
target/hosted/sonynwz/nwz-db.c
#endif
-#if defined(AGPTEK_ROCKER) && !defined(SIMULATOR)
+#if ((defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR))
drivers/lcd-memframe.c
+target/hosted/alsa-controls.c
+target/hosted/pcm-alsa.c
target/hosted/backtrace-glibc.c
-target/hosted/kernel-unix.c
target/hosted/filesystem-unix.c
+target/hosted/kernel-unix.c
target/hosted/lc-unix.c
-target/hosted/alsa-controls.c
-target/hosted/pcm-alsa.c
-target/hosted/agptek/sysfs.c
-target/hosted/agptek/backlight-agptek.c
+target/hosted/sysfs.c
+target/hosted/backlight-unix.c
+target/hosted/system-hosted.c
+#endif
+
+#if defined(AGPTEK_ROCKER) && !defined(SIMULATOR)
target/hosted/agptek/button-agptek.c
target/hosted/agptek/debug-agptek.c
target/hosted/agptek/lcd-agptek.c
target/hosted/agptek/power-agptek.c
target/hosted/agptek/powermgmt-agptek.c
-target/hosted/agptek/system-agptek.c
target/hosted/agptek/usb-agptek.c
#endif
+#if ((defined(XDUOO_X3II)||defined(XDUOO_X20)) && !defined(SIMULATOR))
+target/hosted/xduoo/button-xduoo.c
+target/hosted/xduoo/debug-xduoo.c
+target/hosted/xduoo/lcd-xduoo.c
+target/hosted/xduoo/power-xduoo.c
+target/hosted/xduoo/powermgmt-xduoo.c
+target/hosted/xduoo/usb-xduoo.c
+#endif
+
#if defined(SAMSUNG_YPR0) && !defined(SIMULATOR)
drivers/adc-as3514.c
#if (CONFIG_RTC == RTC_AS3514)
@@ -502,6 +514,8 @@ target/hosted/alsa-controls.c
target/hosted/pcm-alsa.c
#elif defined(HAVE_ROCKER_CODEC) && !defined(SIMULATOR)
drivers/audio/rocker_codec.c
+#elif defined(HAVE_XDUOO_LINUX_CODEC) && !defined(SIMULATOR)
+drivers/audio/xduoolinux_codec.c
#elif defined(HAVE_SDL_AUDIO)
drivers/audio/sdl.c
#if CONFIG_CODEC == SWCODEC
@@ -584,7 +598,7 @@ target/arm/ipod/powermgmt-ipod-pcf.c
target/arm/pp/i2c-pp.c
#elif CONFIG_I2C == I2C_PNX0101
target/arm/pnx0101/i2c-pnx0101.c
-#elif CONFIG_I2C == I2C_TCC780X || CONFIG_I2C == I2C_TCC77X
+#elif CONFIG_I2C == I2C_TCC780X || CONFIG_I2C == I2C_TCC77X
target/arm/i2c-telechips.c
#elif CONFIG_I2C == I2C_S3C2440
target/arm/s3c2440/i2c-s3c2440.c
@@ -837,9 +851,9 @@ drivers/isp1583.c
target/arm/rk27xx/usb-drv-rk27xx.c
#endif
#else /* !defined(HAVE_USBSTACK) */
-#if CONFIG_USBOTG == USBOTG_ISP1362
+#if CONFIG_USBOTG == USBOTG_ISP1362
drivers/isp1362.c
-#elif CONFIG_USBOTG == USBOTG_M5636
+#elif CONFIG_USBOTG == USBOTG_M5636
drivers/m5636.c
#endif
#endif /* !defined(HAVE_USBSTACK) */
@@ -1415,7 +1429,7 @@ target/arm/pnx0101/iriver-ifp7xx/button-ifp7xx.c
target/arm/pnx0101/iriver-ifp7xx/lcd-ifp7xx.c
target/arm/pnx0101/iriver-ifp7xx/power-ifp7xx.c
target/arm/pnx0101/iriver-ifp7xx/powermgmt-ifp7xx.c
-target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
+target/arm/pnx0101/iriver-ifp7xx/usb-ifp7xx.c
#ifndef BOOTLOADER
target/arm/pnx0101/pcm-pnx0101.c
#endif /* BOOTLOADER */
@@ -1989,7 +2003,7 @@ target/hosted/ibasso/dx90/button-dx90.c
#ifdef WIN32
asm/mempcpy.c
target/hosted/filesystem-win32.c
-#else /* !WIN32 */
+#else /* !WIN32 */
target/hosted/filesystem-unix.c
#endif /* WIN32 */
target/hosted/sdl/load_code-sdl.c
diff --git a/firmware/asm/SOURCES b/firmware/asm/SOURCES
index eba5bd2cb6..085b6351a5 100644
--- a/firmware/asm/SOURCES
+++ b/firmware/asm/SOURCES
@@ -15,7 +15,7 @@ mempcpy.c
defined(CREATIVE_ZVx) || defined(SANSA_CONNECT) || defined(SANSA_FUZEPLUS) || \
defined(COWON_D2) || defined(MINI2440) || defined(SAMSUNG_YPR0) || \
defined(SAMSUNG_YPR1) || defined(DX50) || defined(DX90) || (defined(MROBE_500) && !defined(LCD_USE_DMA)) || \
- defined(CREATIVE_ZEN) || defined(CREATIVE_ZENXFI) || defined(SONY_NWZ_LINUX) || defined(AGPTEK_ROCKER)) && \
+ defined(CREATIVE_ZEN) || defined(CREATIVE_ZENXFI) || defined(SONY_NWZ_LINUX) || defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && \
!defined(SIMULATOR)
#if LCD_DEPTH >= 24
lcd-as-memframe-24bit.c
diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c
new file mode 100644
index 0000000000..5db4902e5f
--- /dev/null
+++ b/firmware/drivers/audio/xduoolinux_codec.c
@@ -0,0 +1,122 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ *
+ * Copyright (c) 2018 Marcin Bukat
+ * Copyright (c) 2018 Roman Stolyarov
+ *
+ * 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 "config.h"
+#include "audio.h"
+#include "audiohw.h"
+#include "system.h"
+#include "kernel.h"
+#include "panic.h"
+#include "sysfs.h"
+#include "alsa-controls.h"
+
+static int fd_hw;
+
+static void hw_open(void)
+{
+ fd_hw = open("/dev/snd/controlC0", O_RDWR);
+ if(fd_hw < 0)
+ panicf("Cannot open '/dev/snd/controlC0'");
+}
+
+static void hw_close(void)
+{
+ close(fd_hw);
+}
+
+void audiohw_preinit(void)
+{
+ alsa_controls_init();
+ hw_open();
+}
+
+void audiohw_postinit(void)
+{
+ long int ps = 2; // headset
+ int status = 0;
+
+ const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
+ const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
+#ifdef XDUOO_X20
+ const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
+#endif
+
+#if defined(XDUOO_X3II)
+ alsa_controls_set_bool("AK4490 Soft Mute", true);
+#endif
+
+ sysfs_get_int(sysfs_lo_switch, &status);
+ if (status) ps = 1; // lineout
+
+ sysfs_get_int(sysfs_hs_switch, &status);
+ if (status) ps = 2; // headset
+
+#ifdef XDUOO_X20
+ sysfs_get_int(sysfs_bal_switch, &status);
+ if (status) ps = 3; // balance
+#endif
+
+ /* Output port switch */
+ alsa_controls_set_ints("Output Port Switch", 1, &ps);
+
+#if defined(XDUOO_X3II)
+ alsa_controls_set_bool("AK4490 Soft Mute", false);
+#endif
+}
+
+void audiohw_close(void)
+{
+ hw_close();
+ alsa_controls_close();
+}
+
+void audiohw_set_frequency(int fsel)
+{
+ (void)fsel;
+}
+
+void audiohw_set_volume(int vol_l, int vol_r)
+{
+ long int vol_l_hw = -vol_l/5;
+ long int vol_r_hw = -vol_r/5;
+
+ alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw);
+ alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw);
+}
+
+void audiohw_set_filter_roll_off(int value)
+{
+ /* 0 = fast (sharp);
+ 1 = slow;
+ 2 = fast2
+ 3 = slow2
+ 4 = NOS ? */
+ long int value_hw = value;
+#if defined(XDUOO_X3II)
+ alsa_controls_set_ints("AK4490 Digital Filter", 1, &value_hw);
+#elif defined(XDUOO_X20)
+ alsa_controls_set_ints("ES9018_K2M Digital Filter", 1, &value_hw);
+#else
+ (void)value;
+#endif
+}
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 458fba3412..00bb15812d 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -224,6 +224,8 @@ struct sound_settings_info
#include "codec-dx90.h"
#elif defined(HAVE_ROCKER_CODEC)
#include "rocker_codec.h"
+#elif defined(HAVE_XDUOO_LINUX_CODEC)
+#include "rocker_codec.h"
#endif
/* convert caps into defines */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index a41cceff59..c55d489c26 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -171,6 +171,8 @@
#define XDUOO_X3_PAD 66
#define IHIFI_770_PAD 67
#define IHIFI_800_PAD 68
+#define XDUOO_X3II_PAD 69
+#define XDUOO_X20_PAD 70
/* CONFIG_REMOTE_KEYPAD */
#define H100_REMOTE 1
@@ -624,6 +626,10 @@ Lyre prototype 1 */
#include "config/agptekrocker.h"
#elif defined(XDUOO_X3)
#include "config/xduoox3.h"
+#elif defined(XDUOO_X3II)
+#include "config/xduoox3ii.h"
+#elif defined(XDUOO_X20)
+#include "config/xduoox20.h"
#else
/* no known platform */
#endif
diff --git a/firmware/export/config/agptekrocker.h b/firmware/export/config/agptekrocker.h
index 172e079721..372287f4b5 100644
--- a/firmware/export/config/agptekrocker.h
+++ b/firmware/export/config/agptekrocker.h
@@ -3,7 +3,7 @@
*/
/* For Rolo and boot loader */
-#define MODEL_NUMBER 103//???
+#define MODEL_NUMBER 105
#define MODEL_NAME "Agptek Rocker"
diff --git a/firmware/export/config/xduoox20.h b/firmware/export/config/xduoox20.h
new file mode 100644
index 0000000000..d451ba31f4
--- /dev/null
+++ b/firmware/export/config/xduoox20.h
@@ -0,0 +1,126 @@
+/*
+ * This config file is for the xDuoo X20
+ */
+
+/* For Rolo and boot loader */
+#define MODEL_NUMBER 111
+
+#define MODEL_NAME "xDuoo X20"
+
+/* LCD dimensions */
+#define LCD_WIDTH 240
+#define LCD_HEIGHT 320
+/* sqrt(240^2 + 320^2) / 2.4 = 166 */
+#define LCD_DPI 166
+
+#ifndef SIMULATOR
+#define CONFIG_PLATFORM (PLATFORM_HOSTED)
+#endif
+
+/* define this if you have a bitmap LCD display */
+#define HAVE_LCD_BITMAP
+
+/* define this if you have a colour LCD */
+#define HAVE_LCD_COLOR
+
+#define HAVE_LCD_ENABLE
+
+/* Define this if the LCD can shut down */
+#define HAVE_LCD_SHUTDOWN
+
+/* define this if you want album art for this target */
+#define HAVE_ALBUMART
+
+/* define this to enable bitmap scaling */
+#define HAVE_BMP_SCALING
+
+/* define this to enable JPEG decoding */
+#define HAVE_JPEG
+
+/* define this if you have access to the quickscreen */
+#define HAVE_QUICKSCREEN
+
+/* define this if you would like tagcache to build on this target */
+#define HAVE_TAGCACHE
+
+#define LCD_DEPTH 32
+/* Check that but should not matter */
+#define LCD_PIXELFORMAT XRGB8888
+
+#define HAVE_BACKLIGHT
+#define HAVE_BACKLIGHT_BRIGHTNESS
+
+/* Main LCD backlight brightness range and defaults: the backlight driver
+ * has levels from 0 to 2555. But 0 is off so start at 1.
+ */
+#define MIN_BRIGHTNESS_SETTING 1
+#define MAX_BRIGHTNESS_SETTING 255
+#define DEFAULT_BRIGHTNESS_SETTING 70
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
+/* define this if you have a real-time clock */
+#define CONFIG_RTC APPLICATION
+
+/* The number of bytes reserved for loadable codecs */
+#define CODEC_SIZE 0x80000
+
+/* The number of bytes reserved for loadable plugins */
+#define PLUGIN_BUFFER_SIZE 0x100000
+
+/* Define this if you do software codec */
+#define CONFIG_CODEC SWCODEC
+
+#define HAVE_HEADPHONE_DETECTION
+
+/* KeyPad configuration for plugins */
+#define CONFIG_KEYPAD XDUOO_X20_PAD
+
+/* Define this if a programmable hotkey is mapped */
+#define HAVE_HOTKEY
+
+/* define this if the target has volume keys which can be used in the lists */
+#define HAVE_VOLUME_IN_LIST
+
+#ifndef SIMULATOR
+/* We have usb power and can detect usb but it is handled by Linux */
+#define HAVE_USB_POWER
+
+#endif
+
+#define CONFIG_BATTERY_MEASURE PERCENTAGE_MEASURE
+
+/* Linux controlls charging, we can monitor */
+#define CONFIG_CHARGING CHARGING_MONITOR
+
+/* define this if the hardware can be powered off while charging */
+#define HAVE_POWEROFF_WHILE_CHARGING
+
+/* same dimensions as gigabeats */
+#define CONFIG_LCD LCD_INGENIC_LINUX
+
+/* Define this if you have a software controlled poweroff */
+#define HAVE_SW_POWEROFF
+
+/* Define this to the CPU frequency */
+#define CPU_FREQ 504000000
+
+/* No special storage */
+#define CONFIG_STORAGE STORAGE_HOSTFS
+#define HAVE_STORAGE_FLUSH
+
+/* Battery */
+#define BATTERY_TYPES_COUNT 1
+
+/* Audio codec */
+#define HAVE_XDUOO_LINUX_CODEC
+
+/* We don't have hardware controls */
+#define HAVE_SW_TONE_CONTROLS
+
+/* Battery */
+#define BATTERY_CAPACITY_DEFAULT 2400 /* default battery capacity */
+#define BATTERY_CAPACITY_MIN 2400 /* min. capacity selectable */
+#define BATTERY_CAPACITY_MAX 2400 /* max. capacity selectable */
+#define BATTERY_CAPACITY_INC 0 /* capacity increment */
diff --git a/firmware/export/config/xduoox3ii.h b/firmware/export/config/xduoox3ii.h
new file mode 100644
index 0000000000..af63c4f97b
--- /dev/null
+++ b/firmware/export/config/xduoox3ii.h
@@ -0,0 +1,126 @@
+/*
+ * This config file is for the xDuoo X3ii
+ */
+
+/* For Rolo and boot loader */
+#define MODEL_NUMBER 110
+
+#define MODEL_NAME "xDuoo X3ii"
+
+/* LCD dimensions */
+#define LCD_WIDTH 240
+#define LCD_HEIGHT 320
+/* sqrt(240^2 + 320^2) / 2.4 = 166 */
+#define LCD_DPI 166
+
+#ifndef SIMULATOR
+#define CONFIG_PLATFORM (PLATFORM_HOSTED)
+#endif
+
+/* define this if you have a bitmap LCD display */
+#define HAVE_LCD_BITMAP
+
+/* define this if you have a colour LCD */
+#define HAVE_LCD_COLOR
+
+#define HAVE_LCD_ENABLE
+
+/* Define this if the LCD can shut down */
+#define HAVE_LCD_SHUTDOWN
+
+/* define this if you want album art for this target */
+#define HAVE_ALBUMART
+
+/* define this to enable bitmap scaling */
+#define HAVE_BMP_SCALING
+
+/* define this to enable JPEG decoding */
+#define HAVE_JPEG
+
+/* define this if you have access to the quickscreen */
+#define HAVE_QUICKSCREEN
+
+/* define this if you would like tagcache to build on this target */
+#define HAVE_TAGCACHE
+
+#define LCD_DEPTH 32
+/* Check that but should not matter */
+#define LCD_PIXELFORMAT XRGB8888
+
+#define HAVE_BACKLIGHT
+#define HAVE_BACKLIGHT_BRIGHTNESS
+
+/* Main LCD backlight brightness range and defaults: the backlight driver
+ * has levels from 0 to 2555. But 0 is off so start at 1.
+ */
+#define MIN_BRIGHTNESS_SETTING 1
+#define MAX_BRIGHTNESS_SETTING 255
+#define DEFAULT_BRIGHTNESS_SETTING 70
+
+/* Which backlight fading type? */
+#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
+
+/* define this if you have a real-time clock */
+#define CONFIG_RTC APPLICATION
+
+/* The number of bytes reserved for loadable codecs */
+#define CODEC_SIZE 0x80000
+
+/* The number of bytes reserved for loadable plugins */
+#define PLUGIN_BUFFER_SIZE 0x100000
+
+/* Define this if you do software codec */
+#define CONFIG_CODEC SWCODEC
+
+#define HAVE_HEADPHONE_DETECTION
+
+/* KeyPad configuration for plugins */
+#define CONFIG_KEYPAD XDUOO_X3II_PAD
+
+/* Define this if a programmable hotkey is mapped */
+#define HAVE_HOTKEY
+
+/* define this if the target has volume keys which can be used in the lists */
+#define HAVE_VOLUME_IN_LIST
+
+#ifndef SIMULATOR
+/* We have usb power and can detect usb but it is handled by Linux */
+#define HAVE_USB_POWER
+
+#endif
+
+#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
+
+/* Linux controlls charging, we can monitor */
+#define CONFIG_CHARGING CHARGING_MONITOR
+
+/* define this if the hardware can be powered off while charging */
+#define HAVE_POWEROFF_WHILE_CHARGING
+
+/* same dimensions as gigabeats */
+#define CONFIG_LCD LCD_INGENIC_LINUX
+
+/* Define this if you have a software controlled poweroff */
+#define HAVE_SW_POWEROFF
+
+/* Define this to the CPU frequency */
+#define CPU_FREQ 504000000
+
+/* No special storage */
+#define CONFIG_STORAGE STORAGE_HOSTFS
+#define HAVE_STORAGE_FLUSH
+
+/* Battery */
+#define BATTERY_TYPES_COUNT 1
+
+/* Audio codec */
+#define HAVE_XDUOO_LINUX_CODEC
+
+/* We don't have hardware controls */
+#define HAVE_SW_TONE_CONTROLS
+
+/* Battery */
+#define BATTERY_CAPACITY_DEFAULT 2000 /* default battery capacity */
+#define BATTERY_CAPACITY_MIN 2000 /* min. capacity selectable */
+#define BATTERY_CAPACITY_MAX 2000 /* max. capacity selectable */
+#define BATTERY_CAPACITY_INC 0 /* capacity increment */
diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h
index 165dd37494..b95f1614eb 100644
--- a/firmware/export/rbpaths.h
+++ b/firmware/export/rbpaths.h
@@ -42,7 +42,7 @@
#if !defined(APPLICATION) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \
- defined(AGPTEK_ROCKER)
+ defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)
#if defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)
#define HOME_DIR "/mnt/media0"
diff --git a/firmware/export/xduoolinux_codec.h b/firmware/export/xduoolinux_codec.h
new file mode 100644
index 0000000000..ccd49f09aa
--- /dev/null
+++ b/firmware/export/xduoolinux_codec.h
@@ -0,0 +1,7 @@
+#ifndef __XDUOOLINUX_CODEC__
+#define __XDUOOLINUX_CODEC__
+
+#define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP)
+AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -127, 0, -30)
+AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0)
+#endif
diff --git a/firmware/target/hosted/agptek/backlight-target.h b/firmware/target/hosted/backlight-target.h
index e3b8a7bd78..e3b8a7bd78 100644
--- a/firmware/target/hosted/agptek/backlight-target.h
+++ b/firmware/target/hosted/backlight-target.h
diff --git a/firmware/target/hosted/agptek/backlight-agptek.c b/firmware/target/hosted/backlight-unix.c
index 2f00787f72..2f00787f72 100644
--- a/firmware/target/hosted/agptek/backlight-agptek.c
+++ b/firmware/target/hosted/backlight-unix.c
diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c
index d9fcd64e2d..b49412ea48 100644
--- a/firmware/target/hosted/filesystem-app.c
+++ b/firmware/target/hosted/filesystem-app.c
@@ -36,8 +36,7 @@
#include "rbpaths.h"
#include "logf.h"
-
-#if defined(AGPTEK_ROCKER) && !defined(BOOTLOADER)
+#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(BOOTLOADER)
#define PIVOT_ROOT "/mnt/sd_0"
#endif
@@ -52,7 +51,8 @@ static const char rbhome[] = HOME_DIR;
#endif
#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \
- defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER)) && \
+ defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER) || \
+ defined(XDUOO_X3II) || defined(XDUOO_X20)) && \
!defined(__PCTOOL__)
/* Special dirs are user-accessible (and user-writable) dirs which take priority
* over the ones where Rockbox is installed to. Classic example would be
diff --git a/firmware/target/hosted/rtc.c b/firmware/target/hosted/rtc.c
index 178e797a8d..488531c77c 100644
--- a/firmware/target/hosted/rtc.c
+++ b/firmware/target/hosted/rtc.c
@@ -42,7 +42,7 @@ int rtc_read_datetime(struct tm *tm)
int rtc_write_datetime(const struct tm *tm)
{
-#if defined(AGPTEK_ROCKER) && !defined(WIN32)
+#if !defined(WIN32)
struct timeval tv;
struct tm *tm_time;
diff --git a/firmware/target/hosted/sdl/sim-ui-defines.h b/firmware/target/hosted/sdl/sim-ui-defines.h
index 99ae062595..1e96383682 100644
--- a/firmware/target/hosted/sdl/sim-ui-defines.h
+++ b/firmware/target/hosted/sdl/sim-ui-defines.h
@@ -521,6 +521,7 @@
#define UI_HEIGHT 380
#define UI_LCD_POSX 29
#define UI_LCD_POSY 25
+
#elif defined(XDUOO_X3)
#define UI_TITLE "xDuoo X3"
#define UI_WIDTH 192 /* width of GUI window */
@@ -528,6 +529,20 @@
#define UI_LCD_POSX 34
#define UI_LCD_POSY 73
+#elif defined(XDUOO_X3II)
+#define UI_TITLE "xDuoo X3ii"
+#define UI_WIDTH 322 /* width of GUI window */
+#define UI_HEIGHT 609 /* height of GUI window */
+#define UI_LCD_POSX 43
+#define UI_LCD_POSY 62
+
+#elif defined(XDUOO_X20)
+#define UI_TITLE "xDuoo X20"
+#define UI_WIDTH 322 /* width of GUI window */
+#define UI_HEIGHT 609 /* height of GUI window */
+#define UI_LCD_POSX 43
+#define UI_LCD_POSY 62
+
#elif defined(IHIFI770)
#define UI_TITLE "iHiFi 770"
#define UI_WIDTH 382 /* width of GUI window */
@@ -554,4 +569,3 @@
#endif
#endif /* #ifndef __UISDL_H__ */
-
diff --git a/firmware/target/hosted/agptek/sysfs.c b/firmware/target/hosted/sysfs.c
index 177f338911..177f338911 100644
--- a/firmware/target/hosted/agptek/sysfs.c
+++ b/firmware/target/hosted/sysfs.c
diff --git a/firmware/target/hosted/agptek/sysfs.h b/firmware/target/hosted/sysfs.h
index 639cc1c409..639cc1c409 100644
--- a/firmware/target/hosted/agptek/sysfs.h
+++ b/firmware/target/hosted/sysfs.h
diff --git a/firmware/target/hosted/agptek/system-agptek.c b/firmware/target/hosted/system-hosted.c
index 7f0949daf2..7f0949daf2 100644
--- a/firmware/target/hosted/agptek/system-agptek.c
+++ b/firmware/target/hosted/system-hosted.c
diff --git a/firmware/target/hosted/xduoo/adc-target.h b/firmware/target/hosted/xduoo/adc-target.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/firmware/target/hosted/xduoo/adc-target.h
diff --git a/firmware/target/hosted/xduoo/button-target.h b/firmware/target/hosted/xduoo/button-target.h
new file mode 100644
index 0000000000..6cca5c22a0
--- /dev/null
+++ b/firmware/target/hosted/xduoo/button-target.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2018 by Roman Stolyarov
+ *
+ * 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.
+ *
+ ****************************************************************************/
+#ifndef _BUTTON_TARGET_H_
+#define _BUTTON_TARGET_H_
+
+#define HAS_BUTTON_HOLD
+
+/* Main unit's buttons */
+#define BUTTON_POWER 0x00000001
+#define BUTTON_HOME 0x00000002
+#define BUTTON_OPTION 0x00000004
+#define BUTTON_PREV 0x00000008
+#define BUTTON_NEXT 0x00000010
+#define BUTTON_PLAY 0x00000020
+#define BUTTON_VOL_UP 0x00000040
+#define BUTTON_VOL_DOWN 0x00000080
+
+#define BUTTON_LEFT 0
+#define BUTTON_RIGHT 0
+
+#define BUTTON_MAIN (BUTTON_POWER | BUTTON_HOME | BUTTON_OPTION | BUTTON_PREV | \
+ BUTTON_NEXT | BUTTON_PLAY | BUTTON_VOL_UP | BUTTON_VOL_DOWN)
+
+/* Software power-off */
+#define POWEROFF_BUTTON BUTTON_POWER
+#define POWEROFF_COUNT 25
+
+#endif /* _BUTTON_TARGET_H_ */
+
diff --git a/firmware/target/hosted/xduoo/button-xduoo.c b/firmware/target/hosted/xduoo/button-xduoo.c
new file mode 100644
index 0000000000..9fd1392b89
--- /dev/null
+++ b/firmware/target/hosted/xduoo/button-xduoo.c
@@ -0,0 +1,202 @@
+/***************************************************************************
+ * __________ __ ___
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2017 Marcin Bukat
+ * Copyright (C) 2018 Roman Stolyarov
+ *
+ * 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 <poll.h>
+//#include <dir.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <linux/input.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "sysfs.h"
+#include "button.h"
+#include "button-target.h"
+#include "panic.h"
+
+#include "kernel.h"
+#include "backlight.h"
+#include "backlight-target.h"
+
+static bool soft_hold = false;
+#ifndef BOOTLOADER
+static unsigned soft_hold_counter = 0;
+#define SOFT_HOLD_BUTTON BUTTON_POWER
+#define SOFT_HOLD_CNTMAX_1 (HZ)
+#define SOFT_HOLD_CNTMAX_2 (HZ*2)
+#endif
+
+#define NR_POLL_DESC 3
+static struct pollfd poll_fds[NR_POLL_DESC];
+
+static int button_map(int keycode)
+{
+ switch(keycode)
+ {
+ case KEY_BACK:
+ return BUTTON_HOME;
+
+ case KEY_MENU:
+ return BUTTON_OPTION;
+
+ case KEY_UP:
+ return BUTTON_PREV;
+
+ case KEY_DOWN:
+ return BUTTON_NEXT;
+
+ case KEY_ENTER:
+ return BUTTON_PLAY;
+
+ case KEY_VOLUMEUP:
+ return BUTTON_VOL_UP;
+
+ case KEY_VOLUMEDOWN:
+ return BUTTON_VOL_DOWN;
+
+ case KEY_POWER:
+ return BUTTON_POWER;
+
+ default:
+ return 0;
+ }
+}
+
+void button_init_device(void)
+{
+ const char * const input_devs[] = {
+ "/dev/input/event0",
+ "/dev/input/event1",
+ "/dev/input/event2"
+ };
+
+ for(int i = 0; i < NR_POLL_DESC; i++)
+ {
+ int fd = open(input_devs[i], O_RDWR);
+
+ if(fd < 0)
+ {
+ panicf("Cannot open input device: %s\n", input_devs[i]);
+ }
+
+ poll_fds[i].fd = fd;
+ poll_fds[i].events = POLLIN;
+ poll_fds[i].revents = 0;
+ }
+}
+
+int button_read_device(void)
+{
+ static int button_bitmap = 0;
+ struct input_event event;
+
+ /* check if there are any events pending and process them */
+ while(poll(poll_fds, NR_POLL_DESC, 0))
+ {
+ for(int i = 0; i < NR_POLL_DESC; i++)
+ {
+ /* read only if non-blocking */
+ if(poll_fds[i].revents & POLLIN)
+ {
+ int size = read(poll_fds[i].fd, &event, sizeof(event));
+ if(size == (int)sizeof(event))
+ {
+ int keycode = event.code;
+ /* event.value == 1 means press
+ * event.value == 0 means release
+ */
+ bool press = event.value ? true : false;
+
+ /* map linux event code to rockbox button bitmap */
+ if(press)
+ {
+ button_bitmap |= button_map(keycode);
+ }
+ else
+ {
+ button_bitmap &= ~button_map(keycode);
+ }
+ }
+ }
+ }
+ }
+
+#ifndef BOOTLOADER
+ if (button_bitmap == SOFT_HOLD_BUTTON) {
+ soft_hold_counter++;
+ if (soft_hold_counter == SOFT_HOLD_CNTMAX_1) {
+ soft_hold = !soft_hold;
+ backlight_hold_changed(soft_hold);
+ }
+ else
+ if (soft_hold_counter == SOFT_HOLD_CNTMAX_2) {
+ soft_hold = false;
+ backlight_hold_changed(soft_hold);
+ }
+ } else {
+ soft_hold_counter = 0;
+ }
+
+ if((soft_hold) && (button_bitmap != SOFT_HOLD_BUTTON)) {
+ return BUTTON_NONE;
+ }
+#endif
+
+ return button_bitmap;
+}
+
+bool headphones_inserted(void)
+{
+ int status = 0;
+ const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
+ const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
+#ifdef XDUOO_X20
+ const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
+#endif
+
+ sysfs_get_int(sysfs_lo_switch, &status);
+ if (status) return true;
+
+ sysfs_get_int(sysfs_hs_switch, &status);
+ if (status) return true;
+
+#ifdef XDUOO_X20
+ sysfs_get_int(sysfs_bal_switch, &status);
+ if (status) return true;
+#endif
+
+ return false;
+}
+
+void button_close_device(void)
+{
+ /* close descriptors */
+ for(int i = 0; i < NR_POLL_DESC; i++)
+ {
+ close(poll_fds[i].fd);
+ }
+}
+
+bool button_hold(void)
+{
+ return soft_hold;
+}
diff --git a/firmware/target/hosted/xduoo/debug-xduoo.c b/firmware/target/hosted/xduoo/debug-xduoo.c
new file mode 100644
index 0000000000..33f3ac4b97
--- /dev/null
+++ b/firmware/target/hosted/xduoo/debug-xduoo.c
@@ -0,0 +1,6 @@
+#include <stdbool.h>
+
+bool debug_hw_info(void)
+{
+ return false;
+}
diff --git a/firmware/target/hosted/xduoo/lcd-target.h b/firmware/target/hosted/xduoo/lcd-target.h
new file mode 100644
index 0000000000..bb9b77771b
--- /dev/null
+++ b/firmware/target/hosted/xduoo/lcd-target.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2016 Amaury Pouly
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __LCD_TARGET_H__
+#define __LCD_TARGET_H__
+
+/* needs special ioctl() to redraw updated framebuffer content */
+#define LCD_OPTIMIZED_UPDATE
+#define LCD_OPTIMIZED_UPDATE_RECT
+
+extern fb_data *framebuffer; /* see lcd-xduoo.c */
+#define LCD_FRAMEBUF_ADDR(col, row) (framebuffer + (row)*LCD_WIDTH + (col))
+
+extern void lcd_set_active(bool active);
+#endif /* __LCD_TARGET_H__ */
diff --git a/firmware/target/hosted/xduoo/lcd-xduoo.c b/firmware/target/hosted/xduoo/lcd-xduoo.c
new file mode 100644
index 0000000000..4b3148da03
--- /dev/null
+++ b/firmware/target/hosted/xduoo/lcd-xduoo.c
@@ -0,0 +1,140 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2017 Marcin Bukat
+ * Copyright (C) 2016 Amaury Pouly
+ *
+ * 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 <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <linux/fb.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include "lcd.h"
+#include "lcd-target.h"
+#include "backlight-target.h"
+#include "sysfs.h"
+#include "panic.h"
+
+static int fd = -1;
+static struct fb_var_screeninfo vinfo;
+fb_data *framebuffer = 0; /* global variable, see lcd-target.h */
+
+void lcd_init_device(void)
+{
+ const char * const fb_dev = "/dev/fb0";
+ fd = open(fb_dev, O_RDWR);
+ if(fd < 0)
+ {
+ panicf("Cannot open framebuffer: %s\n", fb_dev);
+ }
+
+ /* get fixed and variable information */
+ struct fb_fix_screeninfo finfo;
+ if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0)
+ {
+ panicf("Cannot read framebuffer fixed information");
+ }
+
+ if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
+ {
+ panicf("Cannot read framebuffer variable information");
+ }
+
+#if 0
+ /* check resolution and framebuffer size */
+ if(vinfo.xres != LCD_WIDTH || vinfo.yres != LCD_HEIGHT || vinfo.bits_per_pixel != LCD_DEPTH)
+ {
+ panicf("Unexpected framebuffer resolution: %dx%dx%d\n", vinfo.xres,
+ vinfo.yres, vinfo.bits_per_pixel);
+ }
+#endif
+ /* Note: we use a framebuffer size of width*height*bbp. We cannot trust the
+ * values returned by the driver for line_length */
+
+ /* map framebuffer */
+ framebuffer = mmap(0, FRAMEBUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if((void *)framebuffer == MAP_FAILED)
+ {
+ panicf("Cannot map framebuffer");
+ }
+
+#ifdef HAVE_LCD_ENABLE
+ lcd_set_active(true);
+#endif
+}
+
+#ifdef HAVE_LCD_SHUTDOWN
+void lcd_shutdown(void)
+{
+ munmap(framebuffer, FRAMEBUFFER_SIZE);
+ close(fd);
+}
+#endif
+
+void lcd_enable(bool on)
+{
+ const char * const sysfs_fb_blank = "/sys/class/graphics/fb0/blank";
+
+ if (lcd_active() != on)
+ {
+ sysfs_set_int(sysfs_fb_blank, on ? 0 : 1);
+ lcd_set_active(on);
+
+ if (on)
+ {
+ send_event(LCD_EVENT_ACTIVATION, NULL);
+ }
+ }
+}
+
+static void redraw(void)
+{
+ ioctl(fd, FBIOPAN_DISPLAY, &vinfo);
+}
+
+extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
+ int width, int height);
+
+void lcd_update(void)
+{
+ /* Copy the Rockbox framebuffer to the second framebuffer */
+ lcd_copy_buffer_rect(LCD_FRAMEBUF_ADDR(0, 0), FBADDR(0,0),
+ LCD_WIDTH*LCD_HEIGHT, 1);
+ redraw();
+}
+
+void lcd_update_rect(int x, int y, int width, int height)
+{
+ fb_data *dst = LCD_FRAMEBUF_ADDR(x, y);
+ fb_data * src = FBADDR(x,y);
+
+ /* Copy part of the Rockbox framebuffer to the second framebuffer */
+ if (width < LCD_WIDTH)
+ {
+ /* Not full width - do line-by-line */
+ lcd_copy_buffer_rect(dst, src, width, height);
+ }
+ else
+ {
+ /* Full width - copy as one line */
+ lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
+ }
+ redraw();
+}
diff --git a/firmware/target/hosted/xduoo/power-xduoo.c b/firmware/target/hosted/xduoo/power-xduoo.c
new file mode 100644
index 0000000000..97a8dd4779
--- /dev/null
+++ b/firmware/target/hosted/xduoo/power-xduoo.c
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2017 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 <sys/types.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include "system.h"
+#include "power-xduoo.h"
+#include "power.h"
+#include "panic.h"
+#include "sysfs.h"
+
+const char * const sysfs_bat_voltage =
+ "/sys/class/power_supply/battery/voltage_now";
+
+const char * const sysfs_bat_capacity =
+ "/sys/class/power_supply/battery/capacity";
+
+const char * const sysfs_bat_status =
+ "/sys/class/power_supply/battery/status";
+
+const char * const sysfs_pow_supply =
+ "/sys/class/power_supply/usb/present";
+
+unsigned int xduoo_power_input_status(void)
+{
+ int present = 0;
+ sysfs_get_int(sysfs_pow_supply, &present);
+
+ return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
+}
+
+bool xduoo_power_charging_status(void)
+{
+ char buf[12] = {0};
+ sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
+
+ return (strncmp(buf, "Charging", 8) == 0);
+}
+
+unsigned int xduoo_power_get_battery_voltage(void)
+{
+ int battery_voltage;
+ sysfs_get_int(sysfs_bat_voltage, &battery_voltage);
+
+ return battery_voltage/1000;
+}
+
+unsigned int xduoo_power_get_battery_capacity(void)
+{
+ int battery_capacity;
+ sysfs_get_int(sysfs_bat_capacity, &battery_capacity);
+
+ return battery_capacity;
+}
diff --git a/firmware/target/hosted/xduoo/power-xduoo.h b/firmware/target/hosted/xduoo/power-xduoo.h
new file mode 100644
index 0000000000..d573865ed2
--- /dev/null
+++ b/firmware/target/hosted/xduoo/power-xduoo.h
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2017 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.
+ *
+ ****************************************************************************/
+#ifndef _POWER_XDUOO_H_
+#define _POWER_XDUOO_H_
+
+#include <stdbool.h>
+#include "config.h"
+
+unsigned int xduoo_power_input_status(void);
+bool xduoo_power_charging_status(void);
+unsigned int xduoo_power_get_battery_voltage(void);
+unsigned int xduoo_power_get_battery_capacity(void);
+#endif /* _POWER_XDUOO_H_ */
+
diff --git a/firmware/target/hosted/xduoo/powermgmt-xduoo.c b/firmware/target/hosted/xduoo/powermgmt-xduoo.c
new file mode 100644
index 0000000000..30001934ba
--- /dev/null
+++ b/firmware/target/hosted/xduoo/powermgmt-xduoo.c
@@ -0,0 +1,70 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2017 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 "powermgmt.h"
+#include "power.h"
+#include "power-xduoo.h"
+
+const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
+{
+ 3470
+};
+
+/* the OF shuts down at this voltage */
+const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
+{
+ 3400
+};
+
+/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
+const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
+{
+ { 3400, 3639, 3697, 3723, 3757, 3786, 3836, 3906, 3980, 4050, 4159 }
+};
+
+/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
+const unsigned short const percent_to_volt_charge[11] =
+{
+ 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
+};
+
+unsigned int power_input_status(void)
+{
+ /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
+ return xduoo_power_input_status();
+}
+
+#if defined(XDUOO_X3II)
+int _battery_voltage(void)
+{
+ return xduoo_power_get_battery_voltage();
+}
+#endif
+
+#if defined(XDUOO_X20)
+int _battery_level(void)
+{
+ return xduoo_power_get_battery_capacity();
+}
+#endif
+
+bool charging_state(void)
+{
+ return xduoo_power_charging_status();
+}
diff --git a/firmware/target/hosted/xduoo/system-target.h b/firmware/target/hosted/xduoo/system-target.h
new file mode 100644
index 0000000000..830f19fde4
--- /dev/null
+++ b/firmware/target/hosted/xduoo/system-target.h
@@ -0,0 +1,28 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2017 Marcin Bukat
+ * Copyright (C) 2016 Amaury Pouly
+ *
+ * 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.
+ *
+ ****************************************************************************/
+#ifndef __SYSTEM_TARGET_H__
+#define __SYSTEM_TARGET_H__
+
+#include "kernel-unix.h"
+#include "system-hosted.h"
+
+#define NEED_GENERIC_BYTESWAPS
+#endif /* __SYSTEM_TARGET_H__ */
diff --git a/firmware/target/hosted/xduoo/usb-xduoo.c b/firmware/target/hosted/xduoo/usb-xduoo.c
new file mode 100644
index 0000000000..19248ad262
--- /dev/null
+++ b/firmware/target/hosted/xduoo/usb-xduoo.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 <stdlib.h>
+#include <sys/mount.h>
+#include <string.h>
+#include "config.h"
+#include "disk.h"
+#include "usb.h"
+#include "sysfs.h"
+#include "power.h"
+#include "power-xduoo.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", "0029");
+ }
+
+ 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", "xDuoo 0100");
+}
diff --git a/firmware/target/hosted/xduoo/xduoo.make b/firmware/target/hosted/xduoo/xduoo.make
new file mode 100644
index 0000000000..5c37d27412
--- /dev/null
+++ b/firmware/target/hosted/xduoo/xduoo.make
@@ -0,0 +1,52 @@
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+# $Id$
+#
+
+INCLUDES += -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
+
+SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
+
+# bootloader build is sligtly different
+ifneq (,$(findstring bootloader,$(APPSDIR)))
+
+SRC += $(call preprocess, $(APPSDIR)/SOURCES)
+CLEANOBJS += $(BUILDDIR)/bootloader.*
+
+endif #bootloader
+
+.SECONDEXPANSION: # $$(OBJ) is not populated until after this
+
+ifneq (,$(findstring bootloader,$(APPSDIR)))
+# bootloader build
+
+$(BUILDDIR)/bootloader.elf : $$(OBJ) $(FIRMLIB) $(CORE_LIBS)
+ $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -o $@ $(OBJ) \
+ -L$(BUILDDIR)/firmware -lfirmware \
+ -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \
+ $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,--gc-sections -Wl,-Map,$(BUILDDIR)/bootloader.map
+
+$(BUILDDIR)/$(BINARY): $(BUILDDIR)/bootloader.elf
+ $(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
+
+else
+# rockbox app build
+
+$(BUILDDIR)/rockbox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS)
+ $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -o $@ $(OBJ) \
+ -L$(BUILDDIR)/firmware -lfirmware \
+ -L$(RBCODEC_BLD)/codecs $(call a2lnk, $(VOICESPEEXLIB)) \
+ -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \
+ $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map
+
+$(BUILDDIR)/rockbox.x3ii : $(BUILDDIR)/rockbox.elf
+ $(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
+
+$(BUILDDIR)/rockbox.x20 : $(BUILDDIR)/rockbox.elf
+ $(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
+
+endif