summaryrefslogtreecommitdiff
path: root/firmware/target/hosted
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted')
-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
15 files changed, 1003 insertions, 6 deletions
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