From aabc8aca47e60cf745a34af28c50679fcb967910 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sat, 3 Oct 2020 18:17:11 -0400 Subject: New port: FiiO M3K Most credit goes to: Roman Skylarov Additional integration and refactoring by myself. *** COMPLETELY UNTESTED *** Change-Id: Ia64c36d92e0214c6b15f7a868df286f8113ea27b --- firmware/SOURCES | 17 +- firmware/asm/SOURCES | 3 +- firmware/drivers/audio/fiiolinux_codec.c | 154 +++++++++++++ firmware/export/audiohw.h | 2 + firmware/export/config.h | 3 + firmware/export/config/fiiom3k.h | 127 ++++++++++ firmware/export/fiiolinux_codec.h | 3 + firmware/export/rbpaths.h | 4 +- firmware/target/hosted/backlight-target.h | 10 +- firmware/target/hosted/fiio/adc-target.h | 0 firmware/target/hosted/fiio/button-fiio.c | 308 +++++++++++++++++++++++++ firmware/target/hosted/fiio/button-target.h | 50 ++++ firmware/target/hosted/fiio/buttonlight-fiio.c | 57 +++++ firmware/target/hosted/fiio/debug-fiio.c | 1 + firmware/target/hosted/fiio/fiio.make | 49 ++++ firmware/target/hosted/fiio/lcd-target.h | 32 +++ firmware/target/hosted/fiio/power-fiio.c | 78 +++++++ firmware/target/hosted/fiio/power-fiio.h | 31 +++ firmware/target/hosted/fiio/powermgmt-fiio.c | 68 ++++++ firmware/target/hosted/fiio/system-fiio.c | 205 ++++++++++++++++ firmware/target/hosted/fiio/system-target.h | 28 +++ firmware/target/hosted/fiio/usb-fiio.c | 81 +++++++ firmware/target/hosted/filesystem-app.c | 11 +- 23 files changed, 1311 insertions(+), 11 deletions(-) create mode 100644 firmware/drivers/audio/fiiolinux_codec.c create mode 100644 firmware/export/config/fiiom3k.h create mode 100644 firmware/target/hosted/fiio/adc-target.h create mode 100644 firmware/target/hosted/fiio/button-fiio.c create mode 100644 firmware/target/hosted/fiio/button-target.h create mode 100644 firmware/target/hosted/fiio/buttonlight-fiio.c create mode 100644 firmware/target/hosted/fiio/debug-fiio.c create mode 100644 firmware/target/hosted/fiio/fiio.make create mode 100644 firmware/target/hosted/fiio/lcd-target.h create mode 100644 firmware/target/hosted/fiio/power-fiio.c create mode 100644 firmware/target/hosted/fiio/power-fiio.h create mode 100644 firmware/target/hosted/fiio/powermgmt-fiio.c create mode 100644 firmware/target/hosted/fiio/system-fiio.c create mode 100644 firmware/target/hosted/fiio/system-target.h create mode 100644 firmware/target/hosted/fiio/usb-fiio.c (limited to 'firmware') diff --git a/firmware/SOURCES b/firmware/SOURCES index 1471eb7b94..42677725fc 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -111,7 +111,7 @@ target/hosted/sonynwz/nvp-nwz.c target/hosted/sonynwz/nwz-db.c #endif -#if ((defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR)) +#if ((defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K)) && !defined(SIMULATOR)) drivers/lcd-memframe.c target/hosted/alsa-controls.c target/hosted/pcm-alsa.c @@ -133,15 +133,24 @@ target/hosted/agptek/powermgmt-agptek.c target/hosted/agptek/usb-agptek.c #endif -#if ((defined(XDUOO_X3II)||defined(XDUOO_X20)) && !defined(SIMULATOR)) +#if (defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR) target/hosted/xduoo/button-xduoo.c target/hosted/xduoo/debug-xduoo.c - target/hosted/xduoo/power-xduoo.c target/hosted/xduoo/powermgmt-xduoo.c target/hosted/xduoo/usb-xduoo.c #endif +#if (defined(FIIO_M3K)) && !defined(SIMULATOR) +target/hosted/fiio/buttonlight-fiio.c +target/hosted/fiio/button-fiio.c +target/hosted/fiio/debug-fiio.c +target/hosted/fiio/power-fiio.c +target/hosted/fiio/powermgmt-fiio.c +target/hosted/fiio/system-fiio.c +target/hosted/fiio/usb-fiio.c +#endif + #if defined(SAMSUNG_YPR0) && !defined(SIMULATOR) drivers/adc-as3514.c #if (CONFIG_RTC == RTC_AS3514) @@ -498,6 +507,8 @@ target/hosted/pcm-alsa.c drivers/audio/rocker_codec.c #elif defined(HAVE_XDUOO_LINUX_CODEC) && !defined(SIMULATOR) drivers/audio/xduoolinux_codec.c +#elif defined(HAVE_FIIO_LINUX_CODEC) && !defined(SIMULATOR) +drivers/audio/fiiolinux_codec.c #elif defined(HAVE_SDL_AUDIO) drivers/audio/sdl.c diff --git a/firmware/asm/SOURCES b/firmware/asm/SOURCES index 085b6351a5..e93f77c770 100644 --- a/firmware/asm/SOURCES +++ b/firmware/asm/SOURCES @@ -15,7 +15,8 @@ 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(XDUOO_X3II) || defined(XDUOO_X20)) && \ + defined(CREATIVE_ZEN) || defined(CREATIVE_ZENXFI) || defined(SONY_NWZ_LINUX) || defined(AGPTEK_ROCKER) || \ + defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K)) && \ !defined(SIMULATOR) #if LCD_DEPTH >= 24 lcd-as-memframe-24bit.c diff --git a/firmware/drivers/audio/fiiolinux_codec.c b/firmware/drivers/audio/fiiolinux_codec.c new file mode 100644 index 0000000000..d8024e3c32 --- /dev/null +++ b/firmware/drivers/audio/fiiolinux_codec.c @@ -0,0 +1,154 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * + * Copyright (c) 2018 Marcin Bukat + * Copyright (c) 2019 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" +#include "pcm-alsa.h" +#include + +static int fd_hw; +static int ak_hw; + +static int vol_sw[2] = {0}; +static long int vol_hw[2] = {0}; + +static void hw_open(void) +{ + fd_hw = open("/dev/snd/controlC0", O_RDWR); + if(fd_hw < 0) + panicf("Cannot open '/dev/snd/controlC0'"); + + ak_hw = open("/dev/ak4376", O_RDWR); + if(ak_hw < 0) + panicf("Cannot open '/dev/ak4376'"); + + if(ioctl(ak_hw, 0x20003424, 0) < 0) + { + panicf("Call cmd AK4376_POWER_ON fail"); + } +} + +static void hw_close(void) +{ + if(ioctl(ak_hw, 0x20003425, 0) < 0) + { + panicf("Call cmd AK4376_POWER_OFF fail"); + } + close(ak_hw); + + close(fd_hw); +} + +void audiohw_preinit(void) +{ + alsa_controls_init(); + hw_open(); +} + +void audiohw_postinit(void) +{ +} + +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) +{ + int vol[2]; + + vol[0] = vol_l / 20; + vol[1] = vol_r / 20; + + for (int i = 0; i < 2; i++) + { + if (vol[i] > -56) + { + if (vol[i] < -12) + { + vol_hw[i] = 1; + vol_sw[i] = vol[i] + 12; + } + else + { + vol_hw[i] = 25 - (-vol[i] * 2); + vol_sw[i] = 0; + } + } + else + { + // Mute + vol_hw[i] = 0; + vol_sw[i] = 0; + } + } + + alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]); + alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]); + pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]); +} + +void audiohw_mute(int mute) +{ + long int vol0 = 0; + + if(mute) + { + alsa_controls_set_ints("DACL Playback Volume", 1, &vol0); + alsa_controls_set_ints("DACR Playback Volume", 1, &vol0); + pcm_alsa_set_digital_volume(0, 0); + } + else + { + alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]); + alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]); + pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]); + } +} + +void audiohw_set_filter_roll_off(int value) +{ + /* 0 = Sharp; + 1 = Slow; + 2 = Short Sharp + 3 = Short Slow */ +#if defined(FIIO_M3K) + long int value_hw = value; + alsa_controls_set_ints("AK4376 Digital Filter", 1, &value_hw); +#else + (void)value; +#endif +} diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h index 31be0555f8..1ff220e403 100644 --- a/firmware/export/audiohw.h +++ b/firmware/export/audiohw.h @@ -224,6 +224,8 @@ struct sound_settings_info #include "rocker_codec.h" #elif defined(HAVE_XDUOO_LINUX_CODEC) #include "xduoolinux_codec.h" +#elif defined(HAVE_FIIO_LINUX_CODEC) +#include "fiiolinux_codec.h" #endif /* convert caps into defines */ diff --git a/firmware/export/config.h b/firmware/export/config.h index 7c57d9a120..a9753e3cf8 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h @@ -161,6 +161,7 @@ #define IHIFI_800_PAD 68 #define XDUOO_X3II_PAD 69 #define XDUOO_X20_PAD 70 +#define FIIO_M3K_PAD 71 /* CONFIG_REMOTE_KEYPAD */ #define H100_REMOTE 1 @@ -599,6 +600,8 @@ Lyre prototype 1 */ #include "config/xduoox3ii.h" #elif defined(XDUOO_X20) #include "config/xduoox20.h" +#elif defined(FIIO_M3K) +#include "config/fiiom3k.h" #else //#error "unknown hwardware platform!" #endif diff --git a/firmware/export/config/fiiom3k.h b/firmware/export/config/fiiom3k.h new file mode 100644 index 0000000000..5b68f3738e --- /dev/null +++ b/firmware/export/config/fiiom3k.h @@ -0,0 +1,127 @@ +/* + * This config file is for the FiiO M3K + */ + +/* For Rolo and boot loader */ +#define MODEL_NUMBER 112 + +#define MODEL_NAME "FiiO M3K" + +/* LCD dimensions */ +#define LCD_WIDTH 240 +#define LCD_HEIGHT 320 +/* sqrt(240^2 + 320^2) / 2.0 = 200 */ +#define LCD_DPI 200 + +#ifndef SIMULATOR +#define CONFIG_PLATFORM (PLATFORM_HOSTED) +#endif + +#define HW_SAMPR_CAPS (SAMPR_CAP_44 | SAMPR_CAP_48 | SAMPR_CAP_88 | SAMPR_CAP_96 | SAMPR_CAP_176 | SAMPR_CAP_192) + +/* 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 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 16 +/* Check that but should not matter */ +#define LCD_PIXELFORMAT RGB565 + +#define HAVE_BACKLIGHT +#define HAVE_BACKLIGHT_BRIGHTNESS + +/* define this if you have a light associated with the buttons */ +#define HAVE_BUTTON_LIGHT +#define HAVE_BUTTONLIGHT_BRIGHTNESS + +/* Main LCD backlight brightness range and defaults: the backlight driver + * has levels from 0 to 32. But 0 is off so start at 1. + */ +#define MIN_BRIGHTNESS_SETTING 1 +#define MAX_BRIGHTNESS_SETTING 255 +#define BRIGHTNESS_STEP 5 +#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 HAVE_HEADPHONE_DETECTION + +/* KeyPad configuration for plugins */ +#define CONFIG_KEYPAD FIIO_M3K_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 1008000000 + +/* No special storage */ +#define CONFIG_STORAGE STORAGE_HOSTFS +#define HAVE_STORAGE_FLUSH + +/* Battery */ +#define BATTERY_TYPES_COUNT 1 + +/* Audio codec */ +#define HAVE_FIIO_LINUX_CODEC + +/* We don't have hardware controls */ +#define HAVE_SW_TONE_CONTROLS + +/* Battery */ +#define BATTERY_CAPACITY_DEFAULT 1100 /* default battery capacity */ +#define BATTERY_CAPACITY_MIN 1100 /* min. capacity selectable */ +#define BATTERY_CAPACITY_MAX 1100 /* max. capacity selectable */ +#define BATTERY_CAPACITY_INC 0 /* capacity increment */ diff --git a/firmware/export/fiiolinux_codec.h b/firmware/export/fiiolinux_codec.h index 22c2263046..118a0928d7 100644 --- a/firmware/export/fiiolinux_codec.h +++ b/firmware/export/fiiolinux_codec.h @@ -2,8 +2,11 @@ #define __FIIOLINUX_CODEC__ #define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP) +#define AUDIOHW_HAVE_SHORT2_ROLL_OFF AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -100, 0, -30) AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0) #endif +#define AUDIOHW_MUTE_ON_PAUSE + void audiohw_mute(int mute); diff --git a/firmware/export/rbpaths.h b/firmware/export/rbpaths.h index 87a6dd91ff..6b686eec0e 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(XDUOO_X3II) || defined(XDUOO_X20) + defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K) #if defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) #define HOME_DIR "/mnt/media0" @@ -53,6 +53,8 @@ #define HOME_DIR "/mnt/sdcard" #elif defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20) #define HOME_DIR "/mnt/sd_0" +#elif defined(FIIO_M3K) +#define HOME_DIR "/mnt" #else #define HOME_DIR "/" #endif diff --git a/firmware/target/hosted/backlight-target.h b/firmware/target/hosted/backlight-target.h index e3b8a7bd78..261af09d72 100644 --- a/firmware/target/hosted/backlight-target.h +++ b/firmware/target/hosted/backlight-target.h @@ -21,16 +21,20 @@ #ifndef _BACKLIGHT_TARGET_H_ #define _BACKLIGHT_TARGET_H_ - #include - /* See backlight.c */ bool backlight_hw_init(void); void backlight_hw_on(void); void backlight_hw_off(void); void backlight_hw_brightness(int brightness); - +#ifdef HAVE_BUTTON_LIGHT +void buttonlight_hw_on(void); +void buttonlight_hw_off(void); +#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS +void buttonlight_hw_brightness(int brightness); +#endif #endif +#endif diff --git a/firmware/target/hosted/fiio/adc-target.h b/firmware/target/hosted/fiio/adc-target.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/firmware/target/hosted/fiio/button-fiio.c b/firmware/target/hosted/fiio/button-fiio.c new file mode 100644 index 0000000000..fcc7480e11 --- /dev/null +++ b/firmware/target/hosted/fiio/button-fiio.c @@ -0,0 +1,308 @@ +/*************************************************************************** + * __________ __ ___ + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2017 Marcin Bukat + * Copyright (C) 2019 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 +//#include +#include +#include +#include +#include +#include +#include +#include + +#include "sysfs.h" +#include "button.h" +#include "button-target.h" +#include "panic.h" + +#include "kernel.h" +#include "backlight.h" +#include "backlight-target.h" + +static int key_enter_delay = 0; +static int key_right_delay = 0; +static int key_left_delay = 0; +static int key_power_delay = 0; +static int key_home_delay = 0; +static int key_backspace_delay = 0; +static int key_leftbrace_delay = 0; +static int key_rightbrace_delay = 0; +static int key_up_delay = 0; +static int key_down_delay = 0; +static int key_f12_delay = 0; + +#define NR_POLL_DESC 2 +static struct pollfd poll_fds[NR_POLL_DESC]; + +#define DEF_DELAY 5 + +static int button_map_on(int keycode) +{ + switch(keycode) + { + case KEY_ENTER: + key_enter_delay = DEF_DELAY; + return BUTTON_PLAY; + case KEY_F10: + key_enter_delay = 0; + return BUTTON_PLAY; + + case KEY_RIGHT: + key_right_delay = DEF_DELAY; + return BUTTON_VOL_DOWN; + case KEY_F7: + key_right_delay = 0; + return BUTTON_VOL_DOWN; + + case KEY_LEFT: + key_left_delay = DEF_DELAY; + return BUTTON_VOL_UP; + case KEY_F6: + key_left_delay = 0; + return BUTTON_VOL_UP; + + case KEY_POWER: + key_power_delay = DEF_DELAY; + return BUTTON_POWER; + case KEY_F8: + key_power_delay = 0; + return BUTTON_POWER; + + case KEY_HOME: + key_home_delay = DEF_DELAY; + return BUTTON_OPTION; + case KEY_F9: + key_home_delay = 0; + return BUTTON_OPTION; + + case KEY_BACKSPACE: + key_backspace_delay = DEF_DELAY; + return BUTTON_HOME; + case KEY_NUMLOCK: + key_backspace_delay = 0; + return BUTTON_HOME; + + case KEY_LEFTBRACE: + key_leftbrace_delay = DEF_DELAY; + return BUTTON_PREV; + case KEY_F5: + key_leftbrace_delay = 0; + return BUTTON_PREV; + + case KEY_RIGHTBRACE: + key_rightbrace_delay = DEF_DELAY; + return BUTTON_NEXT; + case KEY_F4: + key_rightbrace_delay = 0; + return BUTTON_NEXT; + + case KEY_UP: + if (!key_up_delay) key_up_delay = DEF_DELAY; + return BUTTON_UP; + + case KEY_DOWN: + if (!key_down_delay) key_down_delay = DEF_DELAY; + return BUTTON_DOWN; + + case KEY_F12: + key_f12_delay = DEF_DELAY; + //return BUTTON_UNLOCK; + return 0; + + default: + return 0; + } +} + +static int button_map_off(int keycode) +{ + switch(keycode) + { + case KEY_F10: + return BUTTON_PLAY; + + case KEY_F7: + return BUTTON_VOL_DOWN; + + case KEY_F6: + return BUTTON_VOL_UP; + + case KEY_F8: + return BUTTON_POWER; + + case KEY_F9: + return BUTTON_OPTION; + + case KEY_NUMLOCK: + return BUTTON_HOME; + + case KEY_F5: + return BUTTON_PREV; + + case KEY_F4: + return BUTTON_NEXT; + + default: + return 0; + } +} + +static int button_map_timer(void) +{ + int map = 0; + + if (key_enter_delay) + { + if (--key_enter_delay == 0) map |= BUTTON_PLAY; + } + if (key_right_delay) + { + if (--key_right_delay == 0) map |= BUTTON_VOL_DOWN; + } + if (key_left_delay) + { + if (--key_left_delay == 0) map |= BUTTON_VOL_UP; + } + if (key_power_delay) + { + if (--key_power_delay == 0) map |= BUTTON_POWER; + } + if (key_home_delay) + { + if (--key_home_delay == 0) map |= BUTTON_OPTION; + } + if (key_backspace_delay) + { + if (--key_backspace_delay == 0) map |= BUTTON_HOME; + } + if (key_leftbrace_delay) + { + if (--key_leftbrace_delay == 0) map |= BUTTON_PREV; + } + if (key_rightbrace_delay) + { + if (--key_rightbrace_delay == 0) map |= BUTTON_NEXT; + } + if (key_up_delay) + { + if (--key_up_delay == 0) map |= BUTTON_UP; + } + if (key_down_delay) + { + if (--key_down_delay == 0) map |= BUTTON_DOWN; + } + if (key_f12_delay) + { + if (--key_f12_delay == 0) map |= 0; //BUTTON_UNLOCK + } + + return map; +} + +void button_init_device(void) +{ + const char * const input_devs[] = { + "/dev/input/event0", + "/dev/input/event1", + }; + + 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; + static int map; + 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)) + { + if(event.type == EV_KEY) + { + int keycode = event.code; + + /* event.value == 1 means press + * event.value == 0 means release + */ + bool press = event.value ? true : false; + + if(press) + { + map = button_map_on(keycode); + if(map) button_bitmap |= map; + } + else + { + map = button_map_off(keycode); + if(map) button_bitmap &= ~map; + } + } + } + } + } + } + + map = button_map_timer(); + if(map) button_bitmap &= ~map; + + return button_bitmap; +} + +bool headphones_inserted(void) +{ + int status = 0; + const char * const sysfs_hs_switch = "/sys/class/misc/axp173/headset_state"; + + sysfs_get_int(sysfs_hs_switch, &status); + if (status) return true; + + return false; +} + +void button_close_device(void) +{ + /* close descriptors */ + for(int i = 0; i < NR_POLL_DESC; i++) + { + close(poll_fds[i].fd); + } +} diff --git a/firmware/target/hosted/fiio/button-target.h b/firmware/target/hosted/fiio/button-target.h new file mode 100644 index 0000000000..8ed3b7ba0f --- /dev/null +++ b/firmware/target/hosted/fiio/button-target.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2019 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_ + +/* 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_UP 0x00000100 +#define BUTTON_DOWN 0x00000200 + +#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 | \ + BUTTON_UP | BUTTON_DOWN) + +#define BUTTON_LEFT BUTTON_PREV +#define BUTTON_RIGHT BUTTON_NEXT + +/* Software power-off */ +#define POWEROFF_BUTTON BUTTON_POWER +#define POWEROFF_COUNT 25 + +#endif /* _BUTTON_TARGET_H_ */ + diff --git a/firmware/target/hosted/fiio/buttonlight-fiio.c b/firmware/target/hosted/fiio/buttonlight-fiio.c new file mode 100644 index 0000000000..37961f7b63 --- /dev/null +++ b/firmware/target/hosted/fiio/buttonlight-fiio.c @@ -0,0 +1,57 @@ +/*************************************************************************** + * __________ __ ___ + * 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 +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "backlight-target.h" +#include "sysfs.h" +#include "panic.h" +#include "lcd.h" + +static const char * const sysfs_kb_brightness = + "/sys/class/jz_pwm_dev/jz_pwm_dev4/duty_ratio"; + +static const char * const sysfs_kb_power = + "/sys/class/jz_pwm_dev/jz_pwm_dev4/enable"; + +void buttonlight_hw_on(void) +{ + sysfs_set_int(sysfs_kb_power, 1); +} + +void buttonlight_hw_off(void) +{ + sysfs_set_int(sysfs_kb_power, 0); +} + +void buttonlight_hw_brightness(int brightness) +{ + if (brightness > MAX_BRIGHTNESS_SETTING) + brightness = MAX_BRIGHTNESS_SETTING; + if (brightness < MIN_BRIGHTNESS_SETTING) + brightness = MIN_BRIGHTNESS_SETTING; + + sysfs_set_int(sysfs_kb_brightness, brightness); +} diff --git a/firmware/target/hosted/fiio/debug-fiio.c b/firmware/target/hosted/fiio/debug-fiio.c new file mode 100644 index 0000000000..9812b8f8b9 --- /dev/null +++ b/firmware/target/hosted/fiio/debug-fiio.c @@ -0,0 +1 @@ +#include "../agptek/debug-agptek.c" diff --git a/firmware/target/hosted/fiio/fiio.make b/firmware/target/hosted/fiio/fiio.make new file mode 100644 index 0000000000..d159db77f3 --- /dev/null +++ b/firmware/target/hosted/fiio/fiio.make @@ -0,0 +1,49 @@ +# __________ __ ___. +# 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)/$(BINARY): $(BUILDDIR)/rockbox.elf + $(call PRINTS,OC $(@F))$(call objcopy,$^,$@) + +endif diff --git a/firmware/target/hosted/fiio/lcd-target.h b/firmware/target/hosted/fiio/lcd-target.h new file mode 100644 index 0000000000..be5427322e --- /dev/null +++ b/firmware/target/hosted/fiio/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-fiio.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/fiio/power-fiio.c b/firmware/target/hosted/fiio/power-fiio.c new file mode 100644 index 0000000000..a2b19ce550 --- /dev/null +++ b/firmware/target/hosted/fiio/power-fiio.c @@ -0,0 +1,78 @@ +/*************************************************************************** + * __________ __ ___. + * 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 +#include +#include +#include +#include + +#include "system.h" +#include "power.h" +#include "panic.h" +#include "sysfs.h" +#include "usb.h" + +#include "power-fiio.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/ac/online"; + +unsigned int fiio_power_input_status(void) +{ + int present = 0; + sysfs_get_int(sysfs_pow_supply, &present); + + usb_enable(present ? true : false); + + return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE; +} + +bool fiio_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 fiio_power_get_battery_voltage(void) +{ + int battery_voltage; + sysfs_get_int(sysfs_bat_voltage, &battery_voltage); + + return battery_voltage; +} + +unsigned int fiio_power_get_battery_capacity(void) +{ + int battery_capacity; + sysfs_get_int(sysfs_bat_capacity, &battery_capacity); + + return battery_capacity * 20; +} diff --git a/firmware/target/hosted/fiio/power-fiio.h b/firmware/target/hosted/fiio/power-fiio.h new file mode 100644 index 0000000000..c3085e9569 --- /dev/null +++ b/firmware/target/hosted/fiio/power-fiio.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_FIIO_H_ +#define _POWER_FIIO_H_ + +#include +#include "config.h" + +unsigned int fiio_power_input_status(void); +bool fiio_power_charging_status(void); +unsigned int fiio_power_get_battery_voltage(void); +unsigned int fiio_power_get_battery_capacity(void); +#endif /* _POWER_FIIO_H_ */ + diff --git a/firmware/target/hosted/fiio/powermgmt-fiio.c b/firmware/target/hosted/fiio/powermgmt-fiio.c new file mode 100644 index 0000000000..b7c1b5fde2 --- /dev/null +++ b/firmware/target/hosted/fiio/powermgmt-fiio.c @@ -0,0 +1,68 @@ +/*************************************************************************** + * __________ __ ___. + * 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-fiio.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 fiio_power_input_status(); +} + +int _battery_voltage(void) +{ + return fiio_power_get_battery_voltage(); +} + +#if 0 +int _battery_level(void) +{ + return fiio_power_get_battery_capacity(); +} +#endif + +bool charging_state(void) +{ + return fiio_power_charging_status(); +} diff --git a/firmware/target/hosted/fiio/system-fiio.c b/firmware/target/hosted/fiio/system-fiio.c new file mode 100644 index 0000000000..5e638989a1 --- /dev/null +++ b/firmware/target/hosted/fiio/system-fiio.c @@ -0,0 +1,205 @@ +/*************************************************************************** + * __________ __ ___. + * 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 +#include +#include +#include +#include + +#include "system.h" +#include "mv.h" +#include "font.h" +#include "power.h" +#include "button.h" +#include "backlight-target.h" +#include "lcd.h" + +#include "panic.h" +#include +#include + +/* to make thread-internal.h happy */ +uintptr_t *stackbegin; +uintptr_t *stackend; + +static void sig_handler(int sig, siginfo_t *siginfo, void *context) +{ + /* safe guard variable - we call backtrace() only on first + * UIE call. This prevent endless loop if backtrace() touches + * memory regions which cause abort + */ + static bool triggered = false; + + lcd_set_backdrop(NULL); + lcd_set_drawmode(DRMODE_SOLID); + lcd_set_foreground(LCD_BLACK); + lcd_set_background(LCD_WHITE); + unsigned line = 0; + + lcd_setfont(FONT_SYSFIXED); + lcd_set_viewport(NULL); + lcd_clear_display(); + + /* get context info */ + ucontext_t *uc = (ucontext_t *)context; + unsigned long pc = uc->uc_mcontext.pc; + unsigned long sp = uc->uc_mcontext.gregs[29]; + + lcd_putsf(0, line++, "%s at %08x", strsignal(sig), pc); + + if(sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGTRAP) + lcd_putsf(0, line++, "address 0x%08x", siginfo->si_addr); + + if(!triggered) + { + triggered = true; + rb_backtrace(pc, sp, &line); + } + +#ifdef ROCKBOX_HAS_LOGF + lcd_putsf(0, line++, "logf:"); + logf_panic_dump(&line); +#endif + + lcd_update(); + + system_exception_wait(); /* If this returns, try to reboot */ + + backlight_hw_off(); + system_reboot(); + while (1); /* halt */ +} + +static int axp_hw; + +void power_off(void) +{ + backlight_hw_off(); + + axp_hw = open("/dev/axp173", O_RDWR); + if(axp_hw < 0) + panicf("Cannot open '/dev/axp173'"); + + if(ioctl(axp_hw, 0x20003323, 0) < 0) + { + panicf("Call AXP173_SHUTDOWN fail"); + } + + close(axp_hw); +} + +void system_init(void) +{ + int *s; + /* fake stack, to make thread-internal.h happy */ + stackbegin = stackend = (uintptr_t*)&s; + /* catch some signals for easier debugging */ + struct sigaction sa; + sigfillset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO; + sa.sa_sigaction = &sig_handler; + sigaction(SIGILL, &sa, NULL); + sigaction(SIGABRT, &sa, NULL); + sigaction(SIGFPE, &sa, NULL); + sigaction(SIGSEGV, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGBUS, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); +} + +void system_reboot(void) +{ + backlight_hw_off(); + system("/sbin/reboot"); + while (1); /* halt */ +} + +void system_exception_wait(void) +{ + backlight_hw_on(); + backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING); + /* wait until button press and release */ + while(button_read_device() != 0) {} + while(button_read_device() == 0) {} + while(button_read_device() != 0) {} + while(button_read_device() == 0) {} +} + +bool hostfs_removable(IF_MD_NONVOID(int drive)) +{ +#ifdef HAVE_MULTIDRIVE + if (drive > 0) /* Active LOW */ + return true; + else +#endif + return false; /* internal: always present */ +} + +bool hostfs_present(IF_MD_NONVOID(int drive)) +{ +#ifdef HAVE_MULTIDRIVE + if (drive > 0) /* Active LOW */ + return true; //FIXME + else +#endif + return true; /* internal: always present */ +} + +#ifdef HAVE_MULTIDRIVE +int volume_drive(int drive) +{ + return drive; +} +#endif /* HAVE_MULTIDRIVE */ + +#ifdef CONFIG_STORAGE_MULTI +int hostfs_driver_type(int drive) +{ + return drive > 0 ? STORAGE_SD_NUM : STORAGE_HOSTFS_NUM; +} +#endif /* CONFIG_STORAGE_MULTI */ + +int hostfs_init(void) +{ + return 0; +} + +int hostfs_flush(void) +{ + sync(); + return 0; +} + +#ifdef HAVE_HOTSWAP +bool volume_removable(int volume) +{ + /* don't support more than one partition yet, so volume == drive */ + return hostfs_removable(volume); +} + +bool volume_present(int volume) +{ + /* don't support more than one partition yet, so volume == drive */ + return hostfs_present(volume); +} +#endif + diff --git a/firmware/target/hosted/fiio/system-target.h b/firmware/target/hosted/fiio/system-target.h new file mode 100644 index 0000000000..830f19fde4 --- /dev/null +++ b/firmware/target/hosted/fiio/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/fiio/usb-fiio.c b/firmware/target/hosted/fiio/usb-fiio.c new file mode 100644 index 0000000000..76a0ec5a2b --- /dev/null +++ b/firmware/target/hosted/fiio/usb-fiio.c @@ -0,0 +1,81 @@ +/*************************************************************************** + * __________ __ ___ + * 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-fiio.h" + +const char * const sysfs_usb_online = + "/sys/class/power_supply/usb/online"; + +int usb_detect(void) +{ + int present = 0; + sysfs_get_int(sysfs_usb_online, &present); + + return present ? USB_INSERTED : USB_EXTRACTED; +} + +void usb_enable(bool on) +{ + if (on) + { + system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/libcomposite.ko"); + system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/usb_f_mass_storage.ko"); + system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/g_mass_storage.ko file=/dev/mmcblk0 removable=1"); + } + else + { + system ("rmmod g_mass_storage"); + system ("rmmod usb_f_mass_storage"); + system ("rmmod libcomposite"); + } +} + +/* 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) +{ + return 1; +} + +/* This is called by usb thread after all threads ACKs usb inserted message + * + * returns the # of successful unmounts + */ +int disk_unmount_all(void) +{ + return 1; +} + +void usb_init_device(void) +{ + system ("insmod /lib/modules/3.10.14/kernel/driver/staging/dwc2/dwc2.ko"); + usb_enable(true); +} diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c index 57f9b47282..f291ece06d 100644 --- a/firmware/target/hosted/filesystem-app.c +++ b/firmware/target/hosted/filesystem-app.c @@ -36,9 +36,14 @@ #include "rbpaths.h" #include "logf.h" -#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !(defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR)) -#define PIVOT_ROOT HOME_DIR +#if !(defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR)) +#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) +#define PIVOT_ROOT "/mnt/sd_0" +#elif defined(FIIO_M3K) +#define PIVOT_ROOT "/mnt" // XXX check this! +#else #endif +#endif // !(BOOTLOADER|WPS|SIM) #if (CONFIG_PLATFORM & PLATFORM_ANDROID) static const char rbhome[] = "/sdcard"; @@ -52,7 +57,7 @@ static const char rbhome[] = HOME_DIR; #if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \ defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER) || \ - defined(XDUOO_X3II) || defined(XDUOO_X20)) && \ + defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K) || defined(FIIO_M3K_PRO)) && \ !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 -- cgit v1.2.3