summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/aigo
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/aigo')
-rw-r--r--firmware/target/hosted/aigo/adc-target.h0
-rw-r--r--firmware/target/hosted/aigo/button-erosq.c188
-rw-r--r--firmware/target/hosted/aigo/button-target.h45
-rw-r--r--firmware/target/hosted/aigo/debug-erosq.c1
-rw-r--r--firmware/target/hosted/aigo/erosq.make49
-rw-r--r--firmware/target/hosted/aigo/lcd-target.h32
-rw-r--r--firmware/target/hosted/aigo/power-erosq.c74
-rw-r--r--firmware/target/hosted/aigo/power-erosq.h31
-rw-r--r--firmware/target/hosted/aigo/powermgmt-erosq.c61
-rw-r--r--firmware/target/hosted/aigo/system-target.h28
-rw-r--r--firmware/target/hosted/aigo/usb-erosq.c118
11 files changed, 627 insertions, 0 deletions
diff --git a/firmware/target/hosted/aigo/adc-target.h b/firmware/target/hosted/aigo/adc-target.h
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/firmware/target/hosted/aigo/adc-target.h
diff --git a/firmware/target/hosted/aigo/button-erosq.c b/firmware/target/hosted/aigo/button-erosq.c
new file mode 100644
index 0000000000..2735c48c71
--- /dev/null
+++ b/firmware/target/hosted/aigo/button-erosq.c
@@ -0,0 +1,188 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2020 Solomon Peachy
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#include "erosqlinux_codec.h"
40
41#define NR_POLL_DESC 3
42static struct pollfd poll_fds[NR_POLL_DESC];
43
44static int button_map(int keycode)
45{
46 switch(keycode)
47 {
48 case KEY_POWER:
49 return BUTTON_POWER;
50
51 case KEY_MENU:
52 return BUTTON_MENU;
53
54 case KEY_BACK:
55 return BUTTON_BACK;
56
57 case KEY_NEXTSONG:
58 return BUTTON_PREV;
59
60 case KEY_PREVIOUSSONG:
61 return BUTTON_NEXT; // Yes, backwards!
62
63 case KEY_PLAYPAUSE:
64 return BUTTON_PLAY;
65
66 case KEY_LEFT:
67 return BUTTON_SCROLL_BACK;
68
69 case KEY_RIGHT:
70 return BUTTON_SCROLL_FWD;
71
72 case KEY_VOLUMEUP:
73 return BUTTON_VOL_UP;
74
75 case KEY_VOLUMEDOWN:
76 return BUTTON_VOL_DOWN;
77
78 default:
79 return 0;
80 }
81}
82
83void button_init_device(void)
84{
85 const char * const input_devs[] = {
86 "/dev/input/event0", // Rotary encoder
87 "/dev/input/event1" // Keys
88 };
89
90 for(int i = 0; i < NR_POLL_DESC; i++)
91 {
92 int fd = open(input_devs[i], O_RDWR | O_CLOEXEC);
93
94 if(fd < 0)
95 {
96 panicf("Cannot open input device: %s\n", input_devs[i]);
97 }
98
99 poll_fds[i].fd = fd;
100 poll_fds[i].events = POLLIN;
101 poll_fds[i].revents = 0;
102 }
103}
104
105int button_read_device(void)
106{
107 static int button_bitmap = 0;
108 struct input_event event;
109
110 // FIXME TODO: Make this work via HAVE_SCROLL_WHEEL instead
111
112 /* Wheel gives us press+release back to back, clear them after time elapses */
113 static long last_tick = 0;
114 if (button_bitmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD) &&
115 current_tick - last_tick >= 2)
116 {
117 button_bitmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
118 }
119
120 /* check if there are any events pending and process them */
121 while(poll(poll_fds, NR_POLL_DESC, 0))
122 {
123 for(int i = 0; i < NR_POLL_DESC; i++)
124 {
125 /* read only if non-blocking */
126 if(poll_fds[i].revents & POLLIN)
127 {
128 int size = read(poll_fds[i].fd, &event, sizeof(event));
129 if(size == (int)sizeof(event))
130 {
131 int keycode = event.code;
132 /* event.value == 1 means press
133 * event.value == 0 means release
134 */
135 bool press = event.value ? true : false;
136
137 /* map linux event code to rockbox button bitmap */
138 if(press)
139 {
140 int bmap = button_map(keycode);
141 if (bmap & (BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD))
142 last_tick = current_tick;
143 button_bitmap |= bmap;
144 }
145 else
146 {
147 /* Wheel gives us press+release back to back; ignore the release */
148 int bmap = button_map(keycode) & ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
149 button_bitmap &= ~bmap;
150 }
151 }
152 }
153 }
154 }
155
156 return button_bitmap;
157}
158
159bool headphones_inserted(void)
160{
161#ifdef BOOTLOADER
162 int ps = 0;
163#else
164 int ps = erosq_get_outputs();
165#endif
166
167 return (ps == 2);
168}
169
170bool lineout_inserted(void)
171{
172#ifdef BOOTLOADER
173 int ps = 0;
174#else
175 int ps = erosq_get_outputs();
176#endif
177
178 return (ps == 1);
179}
180
181void button_close_device(void)
182{
183 /* close descriptors */
184 for(int i = 0; i < NR_POLL_DESC; i++)
185 {
186 close(poll_fds[i].fd);
187 }
188}
diff --git a/firmware/target/hosted/aigo/button-target.h b/firmware/target/hosted/aigo/button-target.h
new file mode 100644
index 0000000000..f59f491d2f
--- /dev/null
+++ b/firmware/target/hosted/aigo/button-target.h
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2020 Solomon Peachy
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_MENU 0x00000002
26#define BUTTON_BACK 0x00000004
27#define BUTTON_PLAY 0x00000008
28#define BUTTON_NEXT 0x00000010
29#define BUTTON_PREV 0x00000020
30#define BUTTON_VOL_UP 0x00000040
31#define BUTTON_VOL_DOWN 0x00000080
32#define BUTTON_SCROLL_BACK 0x00000100
33#define BUTTON_SCROLL_FWD 0x00000200
34
35#define BUTTON_MAIN (BUTTON_POWER | BUTTON_MENU | BUTTON_BACK | BUTTON_PREV | \
36 BUTTON_NEXT | BUTTON_PLAY | BUTTON_VOL_UP | BUTTON_VOL_DOWN | BUTTON_SCROLL_BACK | BUTTON_SCROLL_FWD)
37
38#define BUTTON_LEFT BUTTON_PREV
39#define BUTTON_RIGHT BUTTON_NEXT
40
41/* Software power-off */
42#define POWEROFF_BUTTON BUTTON_POWER
43#define POWEROFF_COUNT 25
44
45#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/hosted/aigo/debug-erosq.c b/firmware/target/hosted/aigo/debug-erosq.c
new file mode 100644
index 0000000000..9812b8f8b9
--- /dev/null
+++ b/firmware/target/hosted/aigo/debug-erosq.c
@@ -0,0 +1 @@
#include "../agptek/debug-agptek.c"
diff --git a/firmware/target/hosted/aigo/erosq.make b/firmware/target/hosted/aigo/erosq.make
new file mode 100644
index 0000000000..d159db77f3
--- /dev/null
+++ b/firmware/target/hosted/aigo/erosq.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/aigo/lcd-target.h b/firmware/target/hosted/aigo/lcd-target.h
new file mode 100644
index 0000000000..808df3c60a
--- /dev/null
+++ b/firmware/target/hosted/aigo/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-erosq.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/aigo/power-erosq.c b/firmware/target/hosted/aigo/power-erosq.c
new file mode 100644
index 0000000000..0a4f820337
--- /dev/null
+++ b/firmware/target/hosted/aigo/power-erosq.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-erosq.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 erosq_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 erosq_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 erosq_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 erosq_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/aigo/power-erosq.h b/firmware/target/hosted/aigo/power-erosq.h
new file mode 100644
index 0000000000..d06b956924
--- /dev/null
+++ b/firmware/target/hosted/aigo/power-erosq.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 erosq_power_input_status(void);
27bool erosq_power_charging_status(void);
28unsigned int erosq_power_get_battery_voltage(void);
29unsigned int erosq_power_get_battery_capacity(void);
30#endif /* _POWER_XDUOO_H_ */
31
diff --git a/firmware/target/hosted/aigo/powermgmt-erosq.c b/firmware/target/hosted/aigo/powermgmt-erosq.c
new file mode 100644
index 0000000000..14286de3fd
--- /dev/null
+++ b/firmware/target/hosted/aigo/powermgmt-erosq.c
@@ -0,0 +1,61 @@
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-erosq.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 erosq_power_input_status();
51}
52
53int _battery_voltage(void)
54{
55 return erosq_power_get_battery_voltage();
56}
57
58bool charging_state(void)
59{
60 return erosq_power_charging_status();
61}
diff --git a/firmware/target/hosted/aigo/system-target.h b/firmware/target/hosted/aigo/system-target.h
new file mode 100644
index 0000000000..830f19fde4
--- /dev/null
+++ b/firmware/target/hosted/aigo/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/aigo/usb-erosq.c b/firmware/target/hosted/aigo/usb-erosq.c
new file mode 100644
index 0000000000..2a3acf4d62
--- /dev/null
+++ b/firmware/target/hosted/aigo/usb-erosq.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-erosq.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", "0023");
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", "ErosQ 0100");
118}