summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2018-11-05 13:01:55 +0100
committerSolomon Peachy <pizza@shaftnet.org>2020-04-06 18:15:41 +0200
commit180cef835bf40d0081895773aaa637ac926bb0ac (patch)
tree48c380d76c0ea40931cb5e863b40fc5dfa1ecba4 /firmware/target
parentced3a20aacf26642ccc3ffd136f64247c67e5769 (diff)
downloadrockbox-180cef835bf40d0081895773aaa637ac926bb0ac.tar.gz
rockbox-180cef835bf40d0081895773aaa637ac926bb0ac.zip
xDuoo X3II and X20 port
Provided by Roman Stolyarov Integration, Refactoring, and Upstreaming by Solomon Peachy X3II confirmed working by forum tester, X20 is nearly identical. This includes bootloader, main firmware, and the flash image patcher. Eventual Todo: * Further refactor AGPTek Rocker & xduoo hiby bootloaders * Further refactor AGPTek Rocker & xduoo hosted platform code Change-Id: I34a674051d368efcc75d1d18c725971fe46c3eee
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/hosted/backlight-target.h (renamed from firmware/target/hosted/agptek/backlight-target.h)0
-rw-r--r--firmware/target/hosted/backlight-unix.c (renamed from firmware/target/hosted/agptek/backlight-agptek.c)0
-rw-r--r--firmware/target/hosted/filesystem-app.c6
-rw-r--r--firmware/target/hosted/rtc.c2
-rw-r--r--firmware/target/hosted/sdl/sim-ui-defines.h16
-rw-r--r--firmware/target/hosted/sysfs.c (renamed from firmware/target/hosted/agptek/sysfs.c)0
-rw-r--r--firmware/target/hosted/sysfs.h (renamed from firmware/target/hosted/agptek/sysfs.h)0
-rw-r--r--firmware/target/hosted/system-hosted.c (renamed from firmware/target/hosted/agptek/system-agptek.c)0
-rw-r--r--firmware/target/hosted/xduoo/adc-target.h0
-rw-r--r--firmware/target/hosted/xduoo/button-target.h46
-rw-r--r--firmware/target/hosted/xduoo/button-xduoo.c202
-rw-r--r--firmware/target/hosted/xduoo/debug-xduoo.c6
-rw-r--r--firmware/target/hosted/xduoo/lcd-target.h32
-rw-r--r--firmware/target/hosted/xduoo/lcd-xduoo.c140
-rw-r--r--firmware/target/hosted/xduoo/power-xduoo.c74
-rw-r--r--firmware/target/hosted/xduoo/power-xduoo.h31
-rw-r--r--firmware/target/hosted/xduoo/powermgmt-xduoo.c70
-rw-r--r--firmware/target/hosted/xduoo/system-target.h28
-rw-r--r--firmware/target/hosted/xduoo/usb-xduoo.c118
-rw-r--r--firmware/target/hosted/xduoo/xduoo.make52
20 files changed, 818 insertions, 5 deletions
diff --git a/firmware/target/hosted/agptek/backlight-target.h b/firmware/target/hosted/backlight-target.h
index e3b8a7bd78..e3b8a7bd78 100644
--- a/firmware/target/hosted/agptek/backlight-target.h
+++ b/firmware/target/hosted/backlight-target.h
diff --git a/firmware/target/hosted/agptek/backlight-agptek.c b/firmware/target/hosted/backlight-unix.c
index 2f00787f72..2f00787f72 100644
--- a/firmware/target/hosted/agptek/backlight-agptek.c
+++ b/firmware/target/hosted/backlight-unix.c
diff --git a/firmware/target/hosted/filesystem-app.c b/firmware/target/hosted/filesystem-app.c
index d9fcd64e2d..b49412ea48 100644
--- a/firmware/target/hosted/filesystem-app.c
+++ b/firmware/target/hosted/filesystem-app.c
@@ -36,8 +36,7 @@
36#include "rbpaths.h" 36#include "rbpaths.h"
37#include "logf.h" 37#include "logf.h"
38 38
39 39#if (defined(AGPTEK_ROCKER) || defined(XDUOO_X3II) || defined(XDUOO_X20)) && !defined(BOOTLOADER)
40#if defined(AGPTEK_ROCKER) && !defined(BOOTLOADER)
41#define PIVOT_ROOT "/mnt/sd_0" 40#define PIVOT_ROOT "/mnt/sd_0"
42#endif 41#endif
43 42
@@ -52,7 +51,8 @@ static const char rbhome[] = HOME_DIR;
52#endif 51#endif
53 52
54#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \ 53#if !(defined(SAMSUNG_YPR0) || defined(SAMSUNG_YPR1) || defined(DX50) || \
55 defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER)) && \ 54 defined(SONY_NWZ_LINUX) || defined(DX90) || defined(AGPTEK_ROCKER) || \
55 defined(XDUOO_X3II) || defined(XDUOO_X20)) && \
56 !defined(__PCTOOL__) 56 !defined(__PCTOOL__)
57/* Special dirs are user-accessible (and user-writable) dirs which take priority 57/* 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 58 * over the ones where Rockbox is installed to. Classic example would be
diff --git a/firmware/target/hosted/rtc.c b/firmware/target/hosted/rtc.c
index 178e797a8d..488531c77c 100644
--- a/firmware/target/hosted/rtc.c
+++ b/firmware/target/hosted/rtc.c
@@ -42,7 +42,7 @@ int rtc_read_datetime(struct tm *tm)
42 42
43int rtc_write_datetime(const struct tm *tm) 43int rtc_write_datetime(const struct tm *tm)
44{ 44{
45#if defined(AGPTEK_ROCKER) && !defined(WIN32) 45#if !defined(WIN32)
46 struct timeval tv; 46 struct timeval tv;
47 struct tm *tm_time; 47 struct tm *tm_time;
48 48
diff --git a/firmware/target/hosted/sdl/sim-ui-defines.h b/firmware/target/hosted/sdl/sim-ui-defines.h
index 99ae062595..1e96383682 100644
--- a/firmware/target/hosted/sdl/sim-ui-defines.h
+++ b/firmware/target/hosted/sdl/sim-ui-defines.h
@@ -521,6 +521,7 @@
521#define UI_HEIGHT 380 521#define UI_HEIGHT 380
522#define UI_LCD_POSX 29 522#define UI_LCD_POSX 29
523#define UI_LCD_POSY 25 523#define UI_LCD_POSY 25
524
524#elif defined(XDUOO_X3) 525#elif defined(XDUOO_X3)
525#define UI_TITLE "xDuoo X3" 526#define UI_TITLE "xDuoo X3"
526#define UI_WIDTH 192 /* width of GUI window */ 527#define UI_WIDTH 192 /* width of GUI window */
@@ -528,6 +529,20 @@
528#define UI_LCD_POSX 34 529#define UI_LCD_POSX 34
529#define UI_LCD_POSY 73 530#define UI_LCD_POSY 73
530 531
532#elif defined(XDUOO_X3II)
533#define UI_TITLE "xDuoo X3ii"
534#define UI_WIDTH 322 /* width of GUI window */
535#define UI_HEIGHT 609 /* height of GUI window */
536#define UI_LCD_POSX 43
537#define UI_LCD_POSY 62
538
539#elif defined(XDUOO_X20)
540#define UI_TITLE "xDuoo X20"
541#define UI_WIDTH 322 /* width of GUI window */
542#define UI_HEIGHT 609 /* height of GUI window */
543#define UI_LCD_POSX 43
544#define UI_LCD_POSY 62
545
531#elif defined(IHIFI770) 546#elif defined(IHIFI770)
532#define UI_TITLE "iHiFi 770" 547#define UI_TITLE "iHiFi 770"
533#define UI_WIDTH 382 /* width of GUI window */ 548#define UI_WIDTH 382 /* width of GUI window */
@@ -554,4 +569,3 @@
554#endif 569#endif
555 570
556#endif /* #ifndef __UISDL_H__ */ 571#endif /* #ifndef __UISDL_H__ */
557
diff --git a/firmware/target/hosted/agptek/sysfs.c b/firmware/target/hosted/sysfs.c
index 177f338911..177f338911 100644
--- a/firmware/target/hosted/agptek/sysfs.c
+++ b/firmware/target/hosted/sysfs.c
diff --git a/firmware/target/hosted/agptek/sysfs.h b/firmware/target/hosted/sysfs.h
index 639cc1c409..639cc1c409 100644
--- a/firmware/target/hosted/agptek/sysfs.h
+++ b/firmware/target/hosted/sysfs.h
diff --git a/firmware/target/hosted/agptek/system-agptek.c b/firmware/target/hosted/system-hosted.c
index 7f0949daf2..7f0949daf2 100644
--- a/firmware/target/hosted/agptek/system-agptek.c
+++ b/firmware/target/hosted/system-hosted.c
diff --git a/firmware/target/hosted/xduoo/adc-target.h b/firmware/target/hosted/xduoo/adc-target.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/firmware/target/hosted/xduoo/adc-target.h
diff --git a/firmware/target/hosted/xduoo/button-target.h b/firmware/target/hosted/xduoo/button-target.h
new file mode 100644
index 0000000000..6cca5c22a0
--- /dev/null
+++ b/firmware/target/hosted/xduoo/button-target.h
@@ -0,0 +1,46 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2018 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#define HAS_BUTTON_HOLD
24
25/* Main unit's buttons */
26#define BUTTON_POWER 0x00000001
27#define BUTTON_HOME 0x00000002
28#define BUTTON_OPTION 0x00000004
29#define BUTTON_PREV 0x00000008
30#define BUTTON_NEXT 0x00000010
31#define BUTTON_PLAY 0x00000020
32#define BUTTON_VOL_UP 0x00000040
33#define BUTTON_VOL_DOWN 0x00000080
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
41/* Software power-off */
42#define POWEROFF_BUTTON BUTTON_POWER
43#define POWEROFF_COUNT 25
44
45#endif /* _BUTTON_TARGET_H_ */
46
diff --git a/firmware/target/hosted/xduoo/button-xduoo.c b/firmware/target/hosted/xduoo/button-xduoo.c
new file mode 100644
index 0000000000..9fd1392b89
--- /dev/null
+++ b/firmware/target/hosted/xduoo/button-xduoo.c
@@ -0,0 +1,202 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2018 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 bool soft_hold = false;
41#ifndef BOOTLOADER
42static unsigned soft_hold_counter = 0;
43#define SOFT_HOLD_BUTTON BUTTON_POWER
44#define SOFT_HOLD_CNTMAX_1 (HZ)
45#define SOFT_HOLD_CNTMAX_2 (HZ*2)
46#endif
47
48#define NR_POLL_DESC 3
49static struct pollfd poll_fds[NR_POLL_DESC];
50
51static int button_map(int keycode)
52{
53 switch(keycode)
54 {
55 case KEY_BACK:
56 return BUTTON_HOME;
57
58 case KEY_MENU:
59 return BUTTON_OPTION;
60
61 case KEY_UP:
62 return BUTTON_PREV;
63
64 case KEY_DOWN:
65 return BUTTON_NEXT;
66
67 case KEY_ENTER:
68 return BUTTON_PLAY;
69
70 case KEY_VOLUMEUP:
71 return BUTTON_VOL_UP;
72
73 case KEY_VOLUMEDOWN:
74 return BUTTON_VOL_DOWN;
75
76 case KEY_POWER:
77 return BUTTON_POWER;
78
79 default:
80 return 0;
81 }
82}
83
84void button_init_device(void)
85{
86 const char * const input_devs[] = {
87 "/dev/input/event0",
88 "/dev/input/event1",
89 "/dev/input/event2"
90 };
91
92 for(int i = 0; i < NR_POLL_DESC; i++)
93 {
94 int fd = open(input_devs[i], O_RDWR);
95
96 if(fd < 0)
97 {
98 panicf("Cannot open input device: %s\n", input_devs[i]);
99 }
100
101 poll_fds[i].fd = fd;
102 poll_fds[i].events = POLLIN;
103 poll_fds[i].revents = 0;
104 }
105}
106
107int button_read_device(void)
108{
109 static int button_bitmap = 0;
110 struct input_event event;
111
112 /* check if there are any events pending and process them */
113 while(poll(poll_fds, NR_POLL_DESC, 0))
114 {
115 for(int i = 0; i < NR_POLL_DESC; i++)
116 {
117 /* read only if non-blocking */
118 if(poll_fds[i].revents & POLLIN)
119 {
120 int size = read(poll_fds[i].fd, &event, sizeof(event));
121 if(size == (int)sizeof(event))
122 {
123 int keycode = event.code;
124 /* event.value == 1 means press
125 * event.value == 0 means release
126 */
127 bool press = event.value ? true : false;
128
129 /* map linux event code to rockbox button bitmap */
130 if(press)
131 {
132 button_bitmap |= button_map(keycode);
133 }
134 else
135 {
136 button_bitmap &= ~button_map(keycode);
137 }
138 }
139 }
140 }
141 }
142
143#ifndef BOOTLOADER
144 if (button_bitmap == SOFT_HOLD_BUTTON) {
145 soft_hold_counter++;
146 if (soft_hold_counter == SOFT_HOLD_CNTMAX_1) {
147 soft_hold = !soft_hold;
148 backlight_hold_changed(soft_hold);
149 }
150 else
151 if (soft_hold_counter == SOFT_HOLD_CNTMAX_2) {
152 soft_hold = false;
153 backlight_hold_changed(soft_hold);
154 }
155 } else {
156 soft_hold_counter = 0;
157 }
158
159 if((soft_hold) && (button_bitmap != SOFT_HOLD_BUTTON)) {
160 return BUTTON_NONE;
161 }
162#endif
163
164 return button_bitmap;
165}
166
167bool headphones_inserted(void)
168{
169 int status = 0;
170 const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
171 const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
172#ifdef XDUOO_X20
173 const char * const sysfs_bal_switch = "/sys/class/switch/balance/state";
174#endif
175
176 sysfs_get_int(sysfs_lo_switch, &status);
177 if (status) return true;
178
179 sysfs_get_int(sysfs_hs_switch, &status);
180 if (status) return true;
181
182#ifdef XDUOO_X20
183 sysfs_get_int(sysfs_bal_switch, &status);
184 if (status) return true;
185#endif
186
187 return false;
188}
189
190void button_close_device(void)
191{
192 /* close descriptors */
193 for(int i = 0; i < NR_POLL_DESC; i++)
194 {
195 close(poll_fds[i].fd);
196 }
197}
198
199bool button_hold(void)
200{
201 return soft_hold;
202}
diff --git a/firmware/target/hosted/xduoo/debug-xduoo.c b/firmware/target/hosted/xduoo/debug-xduoo.c
new file mode 100644
index 0000000000..33f3ac4b97
--- /dev/null
+++ b/firmware/target/hosted/xduoo/debug-xduoo.c
@@ -0,0 +1,6 @@
1#include <stdbool.h>
2
3bool debug_hw_info(void)
4{
5 return false;
6}
diff --git a/firmware/target/hosted/xduoo/lcd-target.h b/firmware/target/hosted/xduoo/lcd-target.h
new file mode 100644
index 0000000000..bb9b77771b
--- /dev/null
+++ b/firmware/target/hosted/xduoo/lcd-target.h
@@ -0,0 +1,32 @@
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-xduoo.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/xduoo/lcd-xduoo.c b/firmware/target/hosted/xduoo/lcd-xduoo.c
new file mode 100644
index 0000000000..4b3148da03
--- /dev/null
+++ b/firmware/target/hosted/xduoo/lcd-xduoo.c
@@ -0,0 +1,140 @@
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
22#include <stdlib.h>
23#include <unistd.h>
24#include <stdio.h>
25#include <linux/fb.h>
26#include <sys/mman.h>
27#include <sys/ioctl.h>
28#include <fcntl.h>
29#include "lcd.h"
30#include "lcd-target.h"
31#include "backlight-target.h"
32#include "sysfs.h"
33#include "panic.h"
34
35static int fd = -1;
36static struct fb_var_screeninfo vinfo;
37fb_data *framebuffer = 0; /* global variable, see lcd-target.h */
38
39void lcd_init_device(void)
40{
41 const char * const fb_dev = "/dev/fb0";
42 fd = open(fb_dev, O_RDWR);
43 if(fd < 0)
44 {
45 panicf("Cannot open framebuffer: %s\n", fb_dev);
46 }
47
48 /* get fixed and variable information */
49 struct fb_fix_screeninfo finfo;
50 if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0)
51 {
52 panicf("Cannot read framebuffer fixed information");
53 }
54
55 if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
56 {
57 panicf("Cannot read framebuffer variable information");
58 }
59
60#if 0
61 /* check resolution and framebuffer size */
62 if(vinfo.xres != LCD_WIDTH || vinfo.yres != LCD_HEIGHT || vinfo.bits_per_pixel != LCD_DEPTH)
63 {
64 panicf("Unexpected framebuffer resolution: %dx%dx%d\n", vinfo.xres,
65 vinfo.yres, vinfo.bits_per_pixel);
66 }
67#endif
68 /* Note: we use a framebuffer size of width*height*bbp. We cannot trust the
69 * values returned by the driver for line_length */
70
71 /* map framebuffer */
72 framebuffer = mmap(0, FRAMEBUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
73 if((void *)framebuffer == MAP_FAILED)
74 {
75 panicf("Cannot map framebuffer");
76 }
77
78#ifdef HAVE_LCD_ENABLE
79 lcd_set_active(true);
80#endif
81}
82
83#ifdef HAVE_LCD_SHUTDOWN
84void lcd_shutdown(void)
85{
86 munmap(framebuffer, FRAMEBUFFER_SIZE);
87 close(fd);
88}
89#endif
90
91void lcd_enable(bool on)
92{
93 const char * const sysfs_fb_blank = "/sys/class/graphics/fb0/blank";
94
95 if (lcd_active() != on)
96 {
97 sysfs_set_int(sysfs_fb_blank, on ? 0 : 1);
98 lcd_set_active(on);
99
100 if (on)
101 {
102 send_event(LCD_EVENT_ACTIVATION, NULL);
103 }
104 }
105}
106
107static void redraw(void)
108{
109 ioctl(fd, FBIOPAN_DISPLAY, &vinfo);
110}
111
112extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
113 int width, int height);
114
115void lcd_update(void)
116{
117 /* Copy the Rockbox framebuffer to the second framebuffer */
118 lcd_copy_buffer_rect(LCD_FRAMEBUF_ADDR(0, 0), FBADDR(0,0),
119 LCD_WIDTH*LCD_HEIGHT, 1);
120 redraw();
121}
122
123void lcd_update_rect(int x, int y, int width, int height)
124{
125 fb_data *dst = LCD_FRAMEBUF_ADDR(x, y);
126 fb_data * src = FBADDR(x,y);
127
128 /* Copy part of the Rockbox framebuffer to the second framebuffer */
129 if (width < LCD_WIDTH)
130 {
131 /* Not full width - do line-by-line */
132 lcd_copy_buffer_rect(dst, src, width, height);
133 }
134 else
135 {
136 /* Full width - copy as one line */
137 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
138 }
139 redraw();
140}
diff --git a/firmware/target/hosted/xduoo/power-xduoo.c b/firmware/target/hosted/xduoo/power-xduoo.c
new file mode 100644
index 0000000000..97a8dd4779
--- /dev/null
+++ b/firmware/target/hosted/xduoo/power-xduoo.c
@@ -0,0 +1,74 @@
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-xduoo.h"
28#include "power.h"
29#include "panic.h"
30#include "sysfs.h"
31
32const char * const sysfs_bat_voltage =
33 "/sys/class/power_supply/battery/voltage_now";
34
35const char * const sysfs_bat_capacity =
36 "/sys/class/power_supply/battery/capacity";
37
38const char * const sysfs_bat_status =
39 "/sys/class/power_supply/battery/status";
40
41const char * const sysfs_pow_supply =
42 "/sys/class/power_supply/usb/present";
43
44unsigned int xduoo_power_input_status(void)
45{
46 int present = 0;
47 sysfs_get_int(sysfs_pow_supply, &present);
48
49 return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
50}
51
52bool xduoo_power_charging_status(void)
53{
54 char buf[12] = {0};
55 sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
56
57 return (strncmp(buf, "Charging", 8) == 0);
58}
59
60unsigned int xduoo_power_get_battery_voltage(void)
61{
62 int battery_voltage;
63 sysfs_get_int(sysfs_bat_voltage, &battery_voltage);
64
65 return battery_voltage/1000;
66}
67
68unsigned int xduoo_power_get_battery_capacity(void)
69{
70 int battery_capacity;
71 sysfs_get_int(sysfs_bat_capacity, &battery_capacity);
72
73 return battery_capacity;
74}
diff --git a/firmware/target/hosted/xduoo/power-xduoo.h b/firmware/target/hosted/xduoo/power-xduoo.h
new file mode 100644
index 0000000000..d573865ed2
--- /dev/null
+++ b/firmware/target/hosted/xduoo/power-xduoo.h
@@ -0,0 +1,31 @@
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_XDUOO_H_
21#define _POWER_XDUOO_H_
22
23#include <stdbool.h>
24#include "config.h"
25
26unsigned int xduoo_power_input_status(void);
27bool xduoo_power_charging_status(void);
28unsigned int xduoo_power_get_battery_voltage(void);
29unsigned int xduoo_power_get_battery_capacity(void);
30#endif /* _POWER_XDUOO_H_ */
31
diff --git a/firmware/target/hosted/xduoo/powermgmt-xduoo.c b/firmware/target/hosted/xduoo/powermgmt-xduoo.c
new file mode 100644
index 0000000000..30001934ba
--- /dev/null
+++ b/firmware/target/hosted/xduoo/powermgmt-xduoo.c
@@ -0,0 +1,70 @@
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-xduoo.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 xduoo_power_input_status();
51}
52
53#if defined(XDUOO_X3II)
54int _battery_voltage(void)
55{
56 return xduoo_power_get_battery_voltage();
57}
58#endif
59
60#if defined(XDUOO_X20)
61int _battery_level(void)
62{
63 return xduoo_power_get_battery_capacity();
64}
65#endif
66
67bool charging_state(void)
68{
69 return xduoo_power_charging_status();
70}
diff --git a/firmware/target/hosted/xduoo/system-target.h b/firmware/target/hosted/xduoo/system-target.h
new file mode 100644
index 0000000000..830f19fde4
--- /dev/null
+++ b/firmware/target/hosted/xduoo/system-target.h
@@ -0,0 +1,28 @@
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/xduoo/usb-xduoo.c b/firmware/target/hosted/xduoo/usb-xduoo.c
new file mode 100644
index 0000000000..19248ad262
--- /dev/null
+++ b/firmware/target/hosted/xduoo/usb-xduoo.c
@@ -0,0 +1,118 @@
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-xduoo.h"
30
31static bool adb_mode = false;
32
33/* TODO: implement usb detection properly */
34int usb_detect(void)
35{
36 return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED;
37}
38
39void usb_enable(bool on)
40{
41 /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell
42 * without entering ums mode
43 */
44 if (!adb_mode)
45 {
46 sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0);
47 }
48}
49
50/* This is called by usb thread after usb extract in order to return
51 * regular FS access
52 *
53 * returns the # of successful mounts
54*/
55int disk_mount_all(void)
56{
57 const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"};
58 const char *fs[] = {"vfat", "exfat"};
59
60 sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "");
61
62 for (int i=0; i<2; i++)
63 {
64 for (int j=0; j<2; j++)
65 {
66 if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0)
67 {
68 return 1;
69 }
70 }
71 }
72
73 return 0;
74}
75
76/* This is called by usb thread after all threads ACKs usb inserted message
77 *
78 * returns the # of successful unmounts
79 */
80int disk_unmount_all(void)
81{
82 if (umount("/mnt/sd_0") == 0)
83 {
84 sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0");
85 return 1;
86 }
87
88 return 0;
89}
90
91void usb_init_device(void)
92{
93 char functions[32] = {0};
94
95 /* Check if ADB was activated in bootloader */
96 sysfs_get_string("/sys/class/android_usb/android0/functions", functions, sizeof(functions));
97 adb_mode = (strstr(functions, "adb") == NULL) ? false : true;
98
99 usb_enable(false);
100
101 if (adb_mode)
102 {
103 sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage,adb");
104 sysfs_set_string("/sys/class/android_usb/android0/idVendor", "18D1");
105 sysfs_set_string("/sys/class/android_usb/android0/idProduct", "D002");
106 }
107 else
108 {
109 sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage");
110 sysfs_set_string("/sys/class/android_usb/android0/idVendor", "C502");
111 sysfs_set_string("/sys/class/android_usb/android0/idProduct", "0029");
112 }
113
114 sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org");
115 sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player");
116 sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF");
117 sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "xDuoo 0100");
118}
diff --git a/firmware/target/hosted/xduoo/xduoo.make b/firmware/target/hosted/xduoo/xduoo.make
new file mode 100644
index 0000000000..5c37d27412
--- /dev/null
+++ b/firmware/target/hosted/xduoo/xduoo.make
@@ -0,0 +1,52 @@
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)/rockbox.x3ii : $(BUILDDIR)/rockbox.elf
47 $(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
48
49$(BUILDDIR)/rockbox.x20 : $(BUILDDIR)/rockbox.elf
50 $(call PRINTS,OC $(@F))$(call objcopy,$^,$@)
51
52endif