summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES17
-rw-r--r--firmware/asm/SOURCES3
-rw-r--r--firmware/drivers/audio/fiiolinux_codec.c154
-rw-r--r--firmware/export/audiohw.h2
-rw-r--r--firmware/export/config.h3
-rw-r--r--firmware/export/config/fiiom3k.h127
-rw-r--r--firmware/export/fiiolinux_codec.h3
-rw-r--r--firmware/export/rbpaths.h4
-rw-r--r--firmware/target/hosted/backlight-target.h10
-rw-r--r--firmware/target/hosted/fiio/adc-target.h0
-rw-r--r--firmware/target/hosted/fiio/button-fiio.c308
-rw-r--r--firmware/target/hosted/fiio/button-target.h50
-rw-r--r--firmware/target/hosted/fiio/buttonlight-fiio.c57
-rw-r--r--firmware/target/hosted/fiio/debug-fiio.c1
-rw-r--r--firmware/target/hosted/fiio/fiio.make49
-rw-r--r--firmware/target/hosted/fiio/lcd-target.h32
-rw-r--r--firmware/target/hosted/fiio/power-fiio.c78
-rw-r--r--firmware/target/hosted/fiio/power-fiio.h31
-rw-r--r--firmware/target/hosted/fiio/powermgmt-fiio.c68
-rw-r--r--firmware/target/hosted/fiio/system-fiio.c205
-rw-r--r--firmware/target/hosted/fiio/system-target.h28
-rw-r--r--firmware/target/hosted/fiio/usb-fiio.c81
-rw-r--r--firmware/target/hosted/filesystem-app.c11
23 files changed, 1311 insertions, 11 deletions
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
111target/hosted/sonynwz/nwz-db.c 111target/hosted/sonynwz/nwz-db.c
112#endif 112#endif
113 113
114#if ((defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR)) 114#if ((defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K)) && !defined(SIMULATOR))
115drivers/lcd-memframe.c 115drivers/lcd-memframe.c
116target/hosted/alsa-controls.c 116target/hosted/alsa-controls.c
117target/hosted/pcm-alsa.c 117target/hosted/pcm-alsa.c
@@ -133,15 +133,24 @@ target/hosted/agptek/powermgmt-agptek.c
133target/hosted/agptek/usb-agptek.c 133target/hosted/agptek/usb-agptek.c
134#endif 134#endif
135 135
136#if ((defined(XDUOO_X3II)||defined(XDUOO_X20)) && !defined(SIMULATOR)) 136#if (defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(SIMULATOR)
137target/hosted/xduoo/button-xduoo.c 137target/hosted/xduoo/button-xduoo.c
138target/hosted/xduoo/debug-xduoo.c 138target/hosted/xduoo/debug-xduoo.c
139
140target/hosted/xduoo/power-xduoo.c 139target/hosted/xduoo/power-xduoo.c
141target/hosted/xduoo/powermgmt-xduoo.c 140target/hosted/xduoo/powermgmt-xduoo.c
142target/hosted/xduoo/usb-xduoo.c 141target/hosted/xduoo/usb-xduoo.c
143#endif 142#endif
144 143
144#if (defined(FIIO_M3K)) && !defined(SIMULATOR)
145target/hosted/fiio/buttonlight-fiio.c
146target/hosted/fiio/button-fiio.c
147target/hosted/fiio/debug-fiio.c
148target/hosted/fiio/power-fiio.c
149target/hosted/fiio/powermgmt-fiio.c
150target/hosted/fiio/system-fiio.c
151target/hosted/fiio/usb-fiio.c
152#endif
153
145#if defined(SAMSUNG_YPR0) && !defined(SIMULATOR) 154#if defined(SAMSUNG_YPR0) && !defined(SIMULATOR)
146drivers/adc-as3514.c 155drivers/adc-as3514.c
147#if (CONFIG_RTC == RTC_AS3514) 156#if (CONFIG_RTC == RTC_AS3514)
@@ -498,6 +507,8 @@ target/hosted/pcm-alsa.c
498drivers/audio/rocker_codec.c 507drivers/audio/rocker_codec.c
499#elif defined(HAVE_XDUOO_LINUX_CODEC) && !defined(SIMULATOR) 508#elif defined(HAVE_XDUOO_LINUX_CODEC) && !defined(SIMULATOR)
500drivers/audio/xduoolinux_codec.c 509drivers/audio/xduoolinux_codec.c
510#elif defined(HAVE_FIIO_LINUX_CODEC) && !defined(SIMULATOR)
511drivers/audio/fiiolinux_codec.c
501#elif defined(HAVE_SDL_AUDIO) 512#elif defined(HAVE_SDL_AUDIO)
502drivers/audio/sdl.c 513drivers/audio/sdl.c
503 514
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
15 defined(CREATIVE_ZVx) || defined(SANSA_CONNECT) || defined(SANSA_FUZEPLUS) || \ 15 defined(CREATIVE_ZVx) || defined(SANSA_CONNECT) || defined(SANSA_FUZEPLUS) || \
16 defined(COWON_D2) || defined(MINI2440) || defined(SAMSUNG_YPR0) || \ 16 defined(COWON_D2) || defined(MINI2440) || defined(SAMSUNG_YPR0) || \
17 defined(SAMSUNG_YPR1) || defined(DX50) || defined(DX90) || (defined(MROBE_500) && !defined(LCD_USE_DMA)) || \ 17 defined(SAMSUNG_YPR1) || defined(DX50) || defined(DX90) || (defined(MROBE_500) && !defined(LCD_USE_DMA)) || \
18 defined(CREATIVE_ZEN) || defined(CREATIVE_ZENXFI) || defined(SONY_NWZ_LINUX) || defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && \ 18 defined(CREATIVE_ZEN) || defined(CREATIVE_ZENXFI) || defined(SONY_NWZ_LINUX) || defined(AGPTEK_ROCKER) || \
19 defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K)) && \
19 !defined(SIMULATOR) 20 !defined(SIMULATOR)
20#if LCD_DEPTH >= 24 21#if LCD_DEPTH >= 24
21lcd-as-memframe-24bit.c 22lcd-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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 *
11 * Copyright (c) 2018 Marcin Bukat
12 * Copyright (c) 2019 Roman Stolyarov
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include "config.h"
25#include "audio.h"
26#include "audiohw.h"
27#include "system.h"
28#include "kernel.h"
29#include "panic.h"
30#include "sysfs.h"
31#include "alsa-controls.h"
32#include "pcm-alsa.h"
33#include <sys/ioctl.h>
34
35static int fd_hw;
36static int ak_hw;
37
38static int vol_sw[2] = {0};
39static long int vol_hw[2] = {0};
40
41static void hw_open(void)
42{
43 fd_hw = open("/dev/snd/controlC0", O_RDWR);
44 if(fd_hw < 0)
45 panicf("Cannot open '/dev/snd/controlC0'");
46
47 ak_hw = open("/dev/ak4376", O_RDWR);
48 if(ak_hw < 0)
49 panicf("Cannot open '/dev/ak4376'");
50
51 if(ioctl(ak_hw, 0x20003424, 0) < 0)
52 {
53 panicf("Call cmd AK4376_POWER_ON fail");
54 }
55}
56
57static void hw_close(void)
58{
59 if(ioctl(ak_hw, 0x20003425, 0) < 0)
60 {
61 panicf("Call cmd AK4376_POWER_OFF fail");
62 }
63 close(ak_hw);
64
65 close(fd_hw);
66}
67
68void audiohw_preinit(void)
69{
70 alsa_controls_init();
71 hw_open();
72}
73
74void audiohw_postinit(void)
75{
76}
77
78void audiohw_close(void)
79{
80 hw_close();
81 alsa_controls_close();
82}
83
84void audiohw_set_frequency(int fsel)
85{
86 (void)fsel;
87}
88
89void audiohw_set_volume(int vol_l, int vol_r)
90{
91 int vol[2];
92
93 vol[0] = vol_l / 20;
94 vol[1] = vol_r / 20;
95
96 for (int i = 0; i < 2; i++)
97 {
98 if (vol[i] > -56)
99 {
100 if (vol[i] < -12)
101 {
102 vol_hw[i] = 1;
103 vol_sw[i] = vol[i] + 12;
104 }
105 else
106 {
107 vol_hw[i] = 25 - (-vol[i] * 2);
108 vol_sw[i] = 0;
109 }
110 }
111 else
112 {
113 // Mute
114 vol_hw[i] = 0;
115 vol_sw[i] = 0;
116 }
117 }
118
119 alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]);
120 alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]);
121 pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]);
122}
123
124void audiohw_mute(int mute)
125{
126 long int vol0 = 0;
127
128 if(mute)
129 {
130 alsa_controls_set_ints("DACL Playback Volume", 1, &vol0);
131 alsa_controls_set_ints("DACR Playback Volume", 1, &vol0);
132 pcm_alsa_set_digital_volume(0, 0);
133 }
134 else
135 {
136 alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]);
137 alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]);
138 pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]);
139 }
140}
141
142void audiohw_set_filter_roll_off(int value)
143{
144 /* 0 = Sharp;
145 1 = Slow;
146 2 = Short Sharp
147 3 = Short Slow */
148#if defined(FIIO_M3K)
149 long int value_hw = value;
150 alsa_controls_set_ints("AK4376 Digital Filter", 1, &value_hw);
151#else
152 (void)value;
153#endif
154}
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
224#include "rocker_codec.h" 224#include "rocker_codec.h"
225#elif defined(HAVE_XDUOO_LINUX_CODEC) 225#elif defined(HAVE_XDUOO_LINUX_CODEC)
226#include "xduoolinux_codec.h" 226#include "xduoolinux_codec.h"
227#elif defined(HAVE_FIIO_LINUX_CODEC)
228#include "fiiolinux_codec.h"
227#endif 229#endif
228 230
229/* convert caps into defines */ 231/* 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 @@
161#define IHIFI_800_PAD 68 161#define IHIFI_800_PAD 68
162#define XDUOO_X3II_PAD 69 162#define XDUOO_X3II_PAD 69
163#define XDUOO_X20_PAD 70 163#define XDUOO_X20_PAD 70
164#define FIIO_M3K_PAD 71
164 165
165/* CONFIG_REMOTE_KEYPAD */ 166/* CONFIG_REMOTE_KEYPAD */
166#define H100_REMOTE 1 167#define H100_REMOTE 1
@@ -599,6 +600,8 @@ Lyre prototype 1 */
599#include "config/xduoox3ii.h" 600#include "config/xduoox3ii.h"
600#elif defined(XDUOO_X20) 601#elif defined(XDUOO_X20)
601#include "config/xduoox20.h" 602#include "config/xduoox20.h"
603#elif defined(FIIO_M3K)
604#include "config/fiiom3k.h"
602#else 605#else
603//#error "unknown hwardware platform!" 606//#error "unknown hwardware platform!"
604#endif 607#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 @@
1/*
2 * This config file is for the FiiO M3K
3 */
4
5/* For Rolo and boot loader */
6#define MODEL_NUMBER 112
7
8#define MODEL_NAME "FiiO M3K"
9
10/* LCD dimensions */
11#define LCD_WIDTH 240
12#define LCD_HEIGHT 320
13/* sqrt(240^2 + 320^2) / 2.0 = 200 */
14#define LCD_DPI 200
15
16#ifndef SIMULATOR
17#define CONFIG_PLATFORM (PLATFORM_HOSTED)
18#endif
19
20#define HW_SAMPR_CAPS (SAMPR_CAP_44 | SAMPR_CAP_48 | SAMPR_CAP_88 | SAMPR_CAP_96 | SAMPR_CAP_176 | SAMPR_CAP_192)
21
22/* define this if you have a bitmap LCD display */
23#define HAVE_LCD_BITMAP
24
25/* define this if you have a colour LCD */
26#define HAVE_LCD_COLOR
27
28#define HAVE_LCD_ENABLE
29
30/* define this if you want album art for this target */
31#define HAVE_ALBUMART
32
33/* define this to enable bitmap scaling */
34#define HAVE_BMP_SCALING
35
36/* define this to enable JPEG decoding */
37#define HAVE_JPEG
38
39/* define this if you have access to the quickscreen */
40#define HAVE_QUICKSCREEN
41
42/* define this if you would like tagcache to build on this target */
43#define HAVE_TAGCACHE
44
45#define LCD_DEPTH 16
46/* Check that but should not matter */
47#define LCD_PIXELFORMAT RGB565
48
49#define HAVE_BACKLIGHT
50#define HAVE_BACKLIGHT_BRIGHTNESS
51
52/* define this if you have a light associated with the buttons */
53#define HAVE_BUTTON_LIGHT
54#define HAVE_BUTTONLIGHT_BRIGHTNESS
55
56/* Main LCD backlight brightness range and defaults: the backlight driver
57 * has levels from 0 to 32. But 0 is off so start at 1.
58 */
59#define MIN_BRIGHTNESS_SETTING 1
60#define MAX_BRIGHTNESS_SETTING 255
61#define BRIGHTNESS_STEP 5
62#define DEFAULT_BRIGHTNESS_SETTING 70
63
64/* Which backlight fading type? */
65#define CONFIG_BACKLIGHT_FADING BACKLIGHT_FADING_SW_SETTING
66
67/* define this if you have a real-time clock */
68#define CONFIG_RTC APPLICATION
69
70/* The number of bytes reserved for loadable codecs */
71#define CODEC_SIZE 0x80000
72
73/* The number of bytes reserved for loadable plugins */
74#define PLUGIN_BUFFER_SIZE 0x100000
75
76#define HAVE_HEADPHONE_DETECTION
77
78/* KeyPad configuration for plugins */
79#define CONFIG_KEYPAD FIIO_M3K_PAD
80
81/* Define this if a programmable hotkey is mapped */
82#define HAVE_HOTKEY
83
84/* define this if the target has volume keys which can be used in the lists */
85#define HAVE_VOLUME_IN_LIST
86
87#ifndef SIMULATOR
88/* We have usb power and can detect usb but it is handled by Linux */
89#define HAVE_USB_POWER
90
91#endif
92
93#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
94
95/* Linux controlls charging, we can monitor */
96#define CONFIG_CHARGING CHARGING_MONITOR
97
98/* define this if the hardware can be powered off while charging */
99#define HAVE_POWEROFF_WHILE_CHARGING
100
101/* same dimensions as gigabeats */
102#define CONFIG_LCD LCD_INGENIC_LINUX
103
104/* Define this if you have a software controlled poweroff */
105#define HAVE_SW_POWEROFF
106
107/* Define this to the CPU frequency */
108#define CPU_FREQ 1008000000
109
110/* No special storage */
111#define CONFIG_STORAGE STORAGE_HOSTFS
112#define HAVE_STORAGE_FLUSH
113
114/* Battery */
115#define BATTERY_TYPES_COUNT 1
116
117/* Audio codec */
118#define HAVE_FIIO_LINUX_CODEC
119
120/* We don't have hardware controls */
121#define HAVE_SW_TONE_CONTROLS
122
123/* Battery */
124#define BATTERY_CAPACITY_DEFAULT 1100 /* default battery capacity */
125#define BATTERY_CAPACITY_MIN 1100 /* min. capacity selectable */
126#define BATTERY_CAPACITY_MAX 1100 /* max. capacity selectable */
127#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 @@
2#define __FIIOLINUX_CODEC__ 2#define __FIIOLINUX_CODEC__
3 3
4#define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP) 4#define AUDIOHW_CAPS (FILTER_ROLL_OFF_CAP)
5#define AUDIOHW_HAVE_SHORT2_ROLL_OFF
5AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -100, 0, -30) 6AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -100, 0, -30)
6AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0) 7AUDIOHW_SETTING(FILTER_ROLL_OFF, "", 0, 1, 0, 4, 0)
7#endif 8#endif
8 9
10#define AUDIOHW_MUTE_ON_PAUSE
11
9void audiohw_mute(int mute); 12void 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 @@
42 42
43#if !defined(APPLICATION) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \ 43#if !defined(APPLICATION) || defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || \
44 defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \ 44 defined(DX50) || defined(DX90) || defined(SONY_NWZ_LINUX) || \
45 defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20) 45 defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K)
46 46
47#if defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) 47#if defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1)
48#define HOME_DIR "/mnt/media0" 48#define HOME_DIR "/mnt/media0"
@@ -53,6 +53,8 @@
53#define HOME_DIR "/mnt/sdcard" 53#define HOME_DIR "/mnt/sdcard"
54#elif defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20) 54#elif defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)
55#define HOME_DIR "/mnt/sd_0" 55#define HOME_DIR "/mnt/sd_0"
56#elif defined(FIIO_M3K)
57#define HOME_DIR "/mnt"
56#else 58#else
57#define HOME_DIR "/" 59#define HOME_DIR "/"
58#endif 60#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 @@
21#ifndef _BACKLIGHT_TARGET_H_ 21#ifndef _BACKLIGHT_TARGET_H_
22#define _BACKLIGHT_TARGET_H_ 22#define _BACKLIGHT_TARGET_H_
23 23
24
25#include <stdbool.h> 24#include <stdbool.h>
26 25
27
28/* See backlight.c */ 26/* See backlight.c */
29bool backlight_hw_init(void); 27bool backlight_hw_init(void);
30void backlight_hw_on(void); 28void backlight_hw_on(void);
31void backlight_hw_off(void); 29void backlight_hw_off(void);
32void backlight_hw_brightness(int brightness); 30void backlight_hw_brightness(int brightness);
33 31
34 32#ifdef HAVE_BUTTON_LIGHT
33void buttonlight_hw_on(void);
34void buttonlight_hw_off(void);
35#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
36void buttonlight_hw_brightness(int brightness);
37#endif
35#endif 38#endif
36 39
40#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
--- /dev/null
+++ b/firmware/target/hosted/fiio/adc-target.h
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 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2019 Roman Stolyarov
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <poll.h>
22//#include <dir.h>
23#include <errno.h>
24#include <unistd.h>
25#include <sys/types.h>
26#include <linux/input.h>
27#include <fcntl.h>
28#include <string.h>
29#include <stdlib.h>
30
31#include "sysfs.h"
32#include "button.h"
33#include "button-target.h"
34#include "panic.h"
35
36#include "kernel.h"
37#include "backlight.h"
38#include "backlight-target.h"
39
40static int key_enter_delay = 0;
41static int key_right_delay = 0;
42static int key_left_delay = 0;
43static int key_power_delay = 0;
44static int key_home_delay = 0;
45static int key_backspace_delay = 0;
46static int key_leftbrace_delay = 0;
47static int key_rightbrace_delay = 0;
48static int key_up_delay = 0;
49static int key_down_delay = 0;
50static int key_f12_delay = 0;
51
52#define NR_POLL_DESC 2
53static struct pollfd poll_fds[NR_POLL_DESC];
54
55#define DEF_DELAY 5
56
57static int button_map_on(int keycode)
58{
59 switch(keycode)
60 {
61 case KEY_ENTER:
62 key_enter_delay = DEF_DELAY;
63 return BUTTON_PLAY;
64 case KEY_F10:
65 key_enter_delay = 0;
66 return BUTTON_PLAY;
67
68 case KEY_RIGHT:
69 key_right_delay = DEF_DELAY;
70 return BUTTON_VOL_DOWN;
71 case KEY_F7:
72 key_right_delay = 0;
73 return BUTTON_VOL_DOWN;
74
75 case KEY_LEFT:
76 key_left_delay = DEF_DELAY;
77 return BUTTON_VOL_UP;
78 case KEY_F6:
79 key_left_delay = 0;
80 return BUTTON_VOL_UP;
81
82 case KEY_POWER:
83 key_power_delay = DEF_DELAY;
84 return BUTTON_POWER;
85 case KEY_F8:
86 key_power_delay = 0;
87 return BUTTON_POWER;
88
89 case KEY_HOME:
90 key_home_delay = DEF_DELAY;
91 return BUTTON_OPTION;
92 case KEY_F9:
93 key_home_delay = 0;
94 return BUTTON_OPTION;
95
96 case KEY_BACKSPACE:
97 key_backspace_delay = DEF_DELAY;
98 return BUTTON_HOME;
99 case KEY_NUMLOCK:
100 key_backspace_delay = 0;
101 return BUTTON_HOME;
102
103 case KEY_LEFTBRACE:
104 key_leftbrace_delay = DEF_DELAY;
105 return BUTTON_PREV;
106 case KEY_F5:
107 key_leftbrace_delay = 0;
108 return BUTTON_PREV;
109
110 case KEY_RIGHTBRACE:
111 key_rightbrace_delay = DEF_DELAY;
112 return BUTTON_NEXT;
113 case KEY_F4:
114 key_rightbrace_delay = 0;
115 return BUTTON_NEXT;
116
117 case KEY_UP:
118 if (!key_up_delay) key_up_delay = DEF_DELAY;
119 return BUTTON_UP;
120
121 case KEY_DOWN:
122 if (!key_down_delay) key_down_delay = DEF_DELAY;
123 return BUTTON_DOWN;
124
125 case KEY_F12:
126 key_f12_delay = DEF_DELAY;
127 //return BUTTON_UNLOCK;
128 return 0;
129
130 default:
131 return 0;
132 }
133}
134
135static int button_map_off(int keycode)
136{
137 switch(keycode)
138 {
139 case KEY_F10:
140 return BUTTON_PLAY;
141
142 case KEY_F7:
143 return BUTTON_VOL_DOWN;
144
145 case KEY_F6:
146 return BUTTON_VOL_UP;
147
148 case KEY_F8:
149 return BUTTON_POWER;
150
151 case KEY_F9:
152 return BUTTON_OPTION;
153
154 case KEY_NUMLOCK:
155 return BUTTON_HOME;
156
157 case KEY_F5:
158 return BUTTON_PREV;
159
160 case KEY_F4:
161 return BUTTON_NEXT;
162
163 default:
164 return 0;
165 }
166}
167
168static int button_map_timer(void)
169{
170 int map = 0;
171
172 if (key_enter_delay)
173 {
174 if (--key_enter_delay == 0) map |= BUTTON_PLAY;
175 }
176 if (key_right_delay)
177 {
178 if (--key_right_delay == 0) map |= BUTTON_VOL_DOWN;
179 }
180 if (key_left_delay)
181 {
182 if (--key_left_delay == 0) map |= BUTTON_VOL_UP;
183 }
184 if (key_power_delay)
185 {
186 if (--key_power_delay == 0) map |= BUTTON_POWER;
187 }
188 if (key_home_delay)
189 {
190 if (--key_home_delay == 0) map |= BUTTON_OPTION;
191 }
192 if (key_backspace_delay)
193 {
194 if (--key_backspace_delay == 0) map |= BUTTON_HOME;
195 }
196 if (key_leftbrace_delay)
197 {
198 if (--key_leftbrace_delay == 0) map |= BUTTON_PREV;
199 }
200 if (key_rightbrace_delay)
201 {
202 if (--key_rightbrace_delay == 0) map |= BUTTON_NEXT;
203 }
204 if (key_up_delay)
205 {
206 if (--key_up_delay == 0) map |= BUTTON_UP;
207 }
208 if (key_down_delay)
209 {
210 if (--key_down_delay == 0) map |= BUTTON_DOWN;
211 }
212 if (key_f12_delay)
213 {
214 if (--key_f12_delay == 0) map |= 0; //BUTTON_UNLOCK
215 }
216
217 return map;
218}
219
220void button_init_device(void)
221{
222 const char * const input_devs[] = {
223 "/dev/input/event0",
224 "/dev/input/event1",
225 };
226
227 for(int i = 0; i < NR_POLL_DESC; i++)
228 {
229 int fd = open(input_devs[i], O_RDWR);
230
231 if(fd < 0)
232 {
233 panicf("Cannot open input device: %s\n", input_devs[i]);
234 }
235
236 poll_fds[i].fd = fd;
237 poll_fds[i].events = POLLIN;
238 poll_fds[i].revents = 0;
239 }
240}
241
242int button_read_device(void)
243{
244 static int button_bitmap = 0;
245 static int map;
246 struct input_event event;
247
248 /* check if there are any events pending and process them */
249 while(poll(poll_fds, NR_POLL_DESC, 0))
250 {
251 for(int i = 0; i < NR_POLL_DESC; i++)
252 {
253 /* read only if non-blocking */
254 if(poll_fds[i].revents & POLLIN)
255 {
256 int size = read(poll_fds[i].fd, &event, sizeof(event));
257 if(size == (int)sizeof(event))
258 {
259 if(event.type == EV_KEY)
260 {
261 int keycode = event.code;
262
263 /* event.value == 1 means press
264 * event.value == 0 means release
265 */
266 bool press = event.value ? true : false;
267
268 if(press)
269 {
270 map = button_map_on(keycode);
271 if(map) button_bitmap |= map;
272 }
273 else
274 {
275 map = button_map_off(keycode);
276 if(map) button_bitmap &= ~map;
277 }
278 }
279 }
280 }
281 }
282 }
283
284 map = button_map_timer();
285 if(map) button_bitmap &= ~map;
286
287 return button_bitmap;
288}
289
290bool headphones_inserted(void)
291{
292 int status = 0;
293 const char * const sysfs_hs_switch = "/sys/class/misc/axp173/headset_state";
294
295 sysfs_get_int(sysfs_hs_switch, &status);
296 if (status) return true;
297
298 return false;
299}
300
301void button_close_device(void)
302{
303 /* close descriptors */
304 for(int i = 0; i < NR_POLL_DESC; i++)
305 {
306 close(poll_fds[i].fd);
307 }
308}
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2019 by Roman Stolyarov
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#ifndef _BUTTON_TARGET_H_
21#define _BUTTON_TARGET_H_
22
23/* Main unit's buttons */
24#define BUTTON_POWER 0x00000001
25#define BUTTON_HOME 0x00000002
26#define BUTTON_OPTION 0x00000004
27#define BUTTON_PREV 0x00000008
28#define BUTTON_NEXT 0x00000010
29#define BUTTON_PLAY 0x00000020
30#define BUTTON_VOL_UP 0x00000040
31#define BUTTON_VOL_DOWN 0x00000080
32#define BUTTON_UP 0x00000100
33#define BUTTON_DOWN 0x00000200
34
35#define BUTTON_LEFT 0
36#define BUTTON_RIGHT 0
37
38#define BUTTON_MAIN (BUTTON_POWER | BUTTON_HOME | BUTTON_OPTION | BUTTON_PREV | \
39 BUTTON_NEXT | BUTTON_PLAY | BUTTON_VOL_UP | BUTTON_VOL_DOWN | \
40 BUTTON_UP | BUTTON_DOWN)
41
42#define BUTTON_LEFT BUTTON_PREV
43#define BUTTON_RIGHT BUTTON_NEXT
44
45/* Software power-off */
46#define POWEROFF_BUTTON BUTTON_POWER
47#define POWEROFF_COUNT 25
48
49#endif /* _BUTTON_TARGET_H_ */
50
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 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include <sys/types.h>
21#include <sys/stat.h>
22#include <fcntl.h>
23#include <stdbool.h>
24#include <unistd.h>
25#include <string.h>
26#include <stdio.h>
27#include "config.h"
28#include "backlight-target.h"
29#include "sysfs.h"
30#include "panic.h"
31#include "lcd.h"
32
33static const char * const sysfs_kb_brightness =
34 "/sys/class/jz_pwm_dev/jz_pwm_dev4/duty_ratio";
35
36static const char * const sysfs_kb_power =
37 "/sys/class/jz_pwm_dev/jz_pwm_dev4/enable";
38
39void buttonlight_hw_on(void)
40{
41 sysfs_set_int(sysfs_kb_power, 1);
42}
43
44void buttonlight_hw_off(void)
45{
46 sysfs_set_int(sysfs_kb_power, 0);
47}
48
49void buttonlight_hw_brightness(int brightness)
50{
51 if (brightness > MAX_BRIGHTNESS_SETTING)
52 brightness = MAX_BRIGHTNESS_SETTING;
53 if (brightness < MIN_BRIGHTNESS_SETTING)
54 brightness = MIN_BRIGHTNESS_SETTING;
55
56 sysfs_set_int(sysfs_kb_brightness, brightness);
57}
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 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10INCLUDES += -I$(FIRMDIR)/include -I$(FIRMDIR)/export $(TARGET_INC) -I$(BUILDDIR) -I$(APPSDIR)
11
12SIMFLAGS += $(INCLUDES) $(DEFINES) -DHAVE_CONFIG_H $(GCCOPTS)
13
14# bootloader build is sligtly different
15ifneq (,$(findstring bootloader,$(APPSDIR)))
16
17SRC += $(call preprocess, $(APPSDIR)/SOURCES)
18CLEANOBJS += $(BUILDDIR)/bootloader.*
19
20endif #bootloader
21
22.SECONDEXPANSION: # $$(OBJ) is not populated until after this
23
24ifneq (,$(findstring bootloader,$(APPSDIR)))
25# bootloader build
26
27$(BUILDDIR)/bootloader.elf : $$(OBJ) $(FIRMLIB) $(CORE_LIBS)
28 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -o $@ $(OBJ) \
29 -L$(BUILDDIR)/firmware -lfirmware \
30 -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \
31 $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,--gc-sections -Wl,-Map,$(BUILDDIR)/bootloader.map
32
33$(BUILDDIR)/$(BINARY): $(BUILDDIR)/bootloader.elf
34 $(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
35
36else
37# rockbox app build
38
39$(BUILDDIR)/rockbox.elf : $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS)
40 $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -Os -o $@ $(OBJ) \
41 -L$(BUILDDIR)/firmware -lfirmware \
42 -L$(RBCODEC_BLD)/codecs $(call a2lnk, $(VOICESPEEXLIB)) \
43 -L$(BUILDDIR)/lib $(call a2lnk,$(CORE_LIBS)) \
44 $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-Map,$(BUILDDIR)/rockbox.map
45
46$(BUILDDIR)/$(BINARY): $(BUILDDIR)/rockbox.elf
47 $(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
48
49endif
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2016 Amaury Pouly
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#ifndef __LCD_TARGET_H__
22#define __LCD_TARGET_H__
23
24/* needs special ioctl() to redraw updated framebuffer content */
25#define LCD_OPTIMIZED_UPDATE
26#define LCD_OPTIMIZED_UPDATE_RECT
27
28extern fb_data *framebuffer; /* see lcd-fiio.c */
29#define LCD_FRAMEBUF_ADDR(col, row) (framebuffer + (row)*LCD_WIDTH + (col))
30
31extern void lcd_set_active(bool active);
32#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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 by Marcin Bukat
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include <sys/types.h>
21#include <fcntl.h>
22#include <string.h>
23#include <unistd.h>
24#include <stdio.h>
25
26#include "system.h"
27#include "power.h"
28#include "panic.h"
29#include "sysfs.h"
30#include "usb.h"
31
32#include "power-fiio.h"
33
34const char * const sysfs_bat_voltage =
35 "/sys/class/power_supply/battery/voltage_now";
36
37const char * const sysfs_bat_capacity =
38 "/sys/class/power_supply/battery/capacity";
39
40const char * const sysfs_bat_status =
41 "/sys/class/power_supply/battery/status";
42
43const char * const sysfs_pow_supply =
44 "/sys/class/power_supply/ac/online";
45
46unsigned int fiio_power_input_status(void)
47{
48 int present = 0;
49 sysfs_get_int(sysfs_pow_supply, &present);
50
51 usb_enable(present ? true : false);
52
53 return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
54}
55
56bool fiio_power_charging_status(void)
57{
58 char buf[12] = {0};
59 sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
60
61 return (strncmp(buf, "Charging", 8) == 0);
62}
63
64unsigned int fiio_power_get_battery_voltage(void)
65{
66 int battery_voltage;
67 sysfs_get_int(sysfs_bat_voltage, &battery_voltage);
68
69 return battery_voltage;
70}
71
72unsigned int fiio_power_get_battery_capacity(void)
73{
74 int battery_capacity;
75 sysfs_get_int(sysfs_bat_capacity, &battery_capacity);
76
77 return battery_capacity * 20;
78}
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 by Marcin Bukat
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#ifndef _POWER_FIIO_H_
21#define _POWER_FIIO_H_
22
23#include <stdbool.h>
24#include "config.h"
25
26unsigned int fiio_power_input_status(void);
27bool fiio_power_charging_status(void);
28unsigned int fiio_power_get_battery_voltage(void);
29unsigned int fiio_power_get_battery_capacity(void);
30#endif /* _POWER_FIIO_H_ */
31
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20#include "powermgmt.h"
21#include "power.h"
22#include "power-fiio.h"
23
24const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
25{
26 3470
27};
28
29/* the OF shuts down at this voltage */
30const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
31{
32 3400
33};
34
35/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
36const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
37{
38 { 3400, 3639, 3697, 3723, 3757, 3786, 3836, 3906, 3980, 4050, 4159 }
39};
40
41/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
42const unsigned short const percent_to_volt_charge[11] =
43{
44 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
45};
46
47unsigned int power_input_status(void)
48{
49 /* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
50 return fiio_power_input_status();
51}
52
53int _battery_voltage(void)
54{
55 return fiio_power_get_battery_voltage();
56}
57
58#if 0
59int _battery_level(void)
60{
61 return fiio_power_get_battery_capacity();
62}
63#endif
64
65bool charging_state(void)
66{
67 return fiio_power_charging_status();
68}
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <unistd.h>
22#include <signal.h>
23#include <string.h>
24#include <ucontext.h>
25#include <backtrace.h>
26
27#include "system.h"
28#include "mv.h"
29#include "font.h"
30#include "power.h"
31#include "button.h"
32#include "backlight-target.h"
33#include "lcd.h"
34
35#include "panic.h"
36#include <fcntl.h>
37#include <sys/ioctl.h>
38
39/* to make thread-internal.h happy */
40uintptr_t *stackbegin;
41uintptr_t *stackend;
42
43static void sig_handler(int sig, siginfo_t *siginfo, void *context)
44{
45 /* safe guard variable - we call backtrace() only on first
46 * UIE call. This prevent endless loop if backtrace() touches
47 * memory regions which cause abort
48 */
49 static bool triggered = false;
50
51 lcd_set_backdrop(NULL);
52 lcd_set_drawmode(DRMODE_SOLID);
53 lcd_set_foreground(LCD_BLACK);
54 lcd_set_background(LCD_WHITE);
55 unsigned line = 0;
56
57 lcd_setfont(FONT_SYSFIXED);
58 lcd_set_viewport(NULL);
59 lcd_clear_display();
60
61 /* get context info */
62 ucontext_t *uc = (ucontext_t *)context;
63 unsigned long pc = uc->uc_mcontext.pc;
64 unsigned long sp = uc->uc_mcontext.gregs[29];
65
66 lcd_putsf(0, line++, "%s at %08x", strsignal(sig), pc);
67
68 if(sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGTRAP)
69 lcd_putsf(0, line++, "address 0x%08x", siginfo->si_addr);
70
71 if(!triggered)
72 {
73 triggered = true;
74 rb_backtrace(pc, sp, &line);
75 }
76
77#ifdef ROCKBOX_HAS_LOGF
78 lcd_putsf(0, line++, "logf:");
79 logf_panic_dump(&line);
80#endif
81
82 lcd_update();
83
84 system_exception_wait(); /* If this returns, try to reboot */
85
86 backlight_hw_off();
87 system_reboot();
88 while (1); /* halt */
89}
90
91static int axp_hw;
92
93void power_off(void)
94{
95 backlight_hw_off();
96
97 axp_hw = open("/dev/axp173", O_RDWR);
98 if(axp_hw < 0)
99 panicf("Cannot open '/dev/axp173'");
100
101 if(ioctl(axp_hw, 0x20003323, 0) < 0)
102 {
103 panicf("Call AXP173_SHUTDOWN fail");
104 }
105
106 close(axp_hw);
107}
108
109void system_init(void)
110{
111 int *s;
112 /* fake stack, to make thread-internal.h happy */
113 stackbegin = stackend = (uintptr_t*)&s;
114 /* catch some signals for easier debugging */
115 struct sigaction sa;
116 sigfillset(&sa.sa_mask);
117 sa.sa_flags = SA_SIGINFO;
118 sa.sa_sigaction = &sig_handler;
119 sigaction(SIGILL, &sa, NULL);
120 sigaction(SIGABRT, &sa, NULL);
121 sigaction(SIGFPE, &sa, NULL);
122 sigaction(SIGSEGV, &sa, NULL);
123 sigaction(SIGPIPE, &sa, NULL);
124 sigaction(SIGTERM, &sa, NULL);
125 sigaction(SIGBUS, &sa, NULL);
126 sigaction(SIGTERM, &sa, NULL);
127}
128
129void system_reboot(void)
130{
131 backlight_hw_off();
132 system("/sbin/reboot");
133 while (1); /* halt */
134}
135
136void system_exception_wait(void)
137{
138 backlight_hw_on();
139 backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING);
140 /* wait until button press and release */
141 while(button_read_device() != 0) {}
142 while(button_read_device() == 0) {}
143 while(button_read_device() != 0) {}
144 while(button_read_device() == 0) {}
145}
146
147bool hostfs_removable(IF_MD_NONVOID(int drive))
148{
149#ifdef HAVE_MULTIDRIVE
150 if (drive > 0) /* Active LOW */
151 return true;
152 else
153#endif
154 return false; /* internal: always present */
155}
156
157bool hostfs_present(IF_MD_NONVOID(int drive))
158{
159#ifdef HAVE_MULTIDRIVE
160 if (drive > 0) /* Active LOW */
161 return true; //FIXME
162 else
163#endif
164 return true; /* internal: always present */
165}
166
167#ifdef HAVE_MULTIDRIVE
168int volume_drive(int drive)
169{
170 return drive;
171}
172#endif /* HAVE_MULTIDRIVE */
173
174#ifdef CONFIG_STORAGE_MULTI
175int hostfs_driver_type(int drive)
176{
177 return drive > 0 ? STORAGE_SD_NUM : STORAGE_HOSTFS_NUM;
178}
179#endif /* CONFIG_STORAGE_MULTI */
180
181int hostfs_init(void)
182{
183 return 0;
184}
185
186int hostfs_flush(void)
187{
188 sync();
189 return 0;
190}
191
192#ifdef HAVE_HOTSWAP
193bool volume_removable(int volume)
194{
195 /* don't support more than one partition yet, so volume == drive */
196 return hostfs_removable(volume);
197}
198
199bool volume_present(int volume)
200{
201 /* don't support more than one partition yet, so volume == drive */
202 return hostfs_present(volume);
203}
204#endif
205
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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __SYSTEM_TARGET_H__
22#define __SYSTEM_TARGET_H__
23
24#include "kernel-unix.h"
25#include "system-hosted.h"
26
27#define NEED_GENERIC_BYTESWAPS
28#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 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2018 by Marcin Bukat
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include <stdlib.h>
22#include <sys/mount.h>
23#include <string.h>
24#include "config.h"
25#include "disk.h"
26#include "usb.h"
27#include "sysfs.h"
28#include "power.h"
29#include "power-fiio.h"
30
31const char * const sysfs_usb_online =
32 "/sys/class/power_supply/usb/online";
33
34int usb_detect(void)
35{
36 int present = 0;
37 sysfs_get_int(sysfs_usb_online, &present);
38
39 return present ? USB_INSERTED : USB_EXTRACTED;
40}
41
42void usb_enable(bool on)
43{
44 if (on)
45 {
46 system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/libcomposite.ko");
47 system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/usb_f_mass_storage.ko");
48 system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/g_mass_storage.ko file=/dev/mmcblk0 removable=1");
49 }
50 else
51 {
52 system ("rmmod g_mass_storage");
53 system ("rmmod usb_f_mass_storage");
54 system ("rmmod libcomposite");
55 }
56}
57
58/* This is called by usb thread after usb extract in order to return
59 * regular FS access
60 *
61 * returns the # of successful mounts
62*/
63int disk_mount_all(void)
64{
65 return 1;
66}
67
68/* This is called by usb thread after all threads ACKs usb inserted message
69 *
70 * returns the # of successful unmounts
71 */
72int disk_unmount_all(void)
73{
74 return 1;
75}
76
77void usb_init_device(void)
78{
79 system ("insmod /lib/modules/3.10.14/kernel/driver/staging/dwc2/dwc2.ko");
80 usb_enable(true);
81}
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 @@
36#include "rbpaths.h" 36#include "rbpaths.h"
37#include "logf.h" 37#include "logf.h"
38 38
39#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !(defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR)) 39#if !(defined(BOOTLOADER) || defined(CHECKWPS) || defined(SIMULATOR))
40#define PIVOT_ROOT HOME_DIR 40#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20))
41#define PIVOT_ROOT "/mnt/sd_0"
42#elif defined(FIIO_M3K)
43#define PIVOT_ROOT "/mnt" // XXX check this!
44#else
41#endif 45#endif
46#endif // !(BOOTLOADER|WPS|SIM)
42 47
43#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 48#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
44static const char rbhome[] = "/sdcard"; 49static const char rbhome[] = "/sdcard";
@@ -52,7 +57,7 @@ static const char rbhome[] = HOME_DIR;
52 57
53#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \ 58#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \
54 defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER) || \ 59 defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER) || \
55 defined(XDUOO_X3II) || defined(XDUOO_X20)) && \ 60 defined(XDUOO_X3II) || defined(XDUOO_X20) || defined(FIIO_M3K) || defined(FIIO_M3K_PRO)) && \
56 !defined(__PCTOOL__) 61 !defined(__PCTOOL__)
57/* Special dirs are user-accessible (and user-writable) dirs which take priority 62/* Special dirs are user-accessible (and user-writable) dirs which take priority
58 * over the ones where Rockbox is installed to. Classic example would be 63 * over the ones where Rockbox is installed to. Classic example would be