summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/ibasso/powermgmt-ibasso.c
diff options
context:
space:
mode:
authorUdo Schläpfer <rockbox-2014.10@desktopwarrior.net>2015-02-02 21:44:29 +0100
committerUdo Schläpfer <rockbox-2014.10@desktopwarrior.net>2015-02-02 21:57:55 +0100
commitdbabd0d9c34a33bc0c51243ec37f230d117db955 (patch)
tree46de348929ce739702a230a2587fdb5539585753 /firmware/target/hosted/ibasso/powermgmt-ibasso.c
parentcef17e3d59ad93f766e8ee23b1610540a33dfe5e (diff)
downloadrockbox-dbabd0d9c34a33bc0c51243ec37f230d117db955.tar.gz
rockbox-dbabd0d9c34a33bc0c51243ec37f230d117db955.zip
iBasso DX50/DX90: Major code cleanup and reorganization.
Reorganization - Separated iBasso devices from PLATFORM_ANDROID. These are now standlone hosted targets. Most device specific code is in the firmware/target/hosted/ibasso directory. - No dependency on Android SDK, only the Android NDK is needed. 32 bit Android NDK and Android API Level 16. - Separate implementation for each device where feasible. Code cleanup - Rewrite of existing code, from simple reformat to complete reimplementation. - New backlight interface, seperating backlight from touchscreen. - Rewrite of device button handler, removing unneeded code and fixing memory leaks. - New Debug messages interface logging to Android adb logcat (DEBUGF, panicf, logf). - Rewrite of lcd device handler, removing unneeded code and fixing memory leaks. - Rewrite of audiohw device handler/pcm interface, removing unneeded code and fixing memory leaks, enabling 44.1/48kHz pthreaded playback. - Rewrite of power and powermng, proper shutdown, using batterylog results (see http://gerrit.rockbox.org/r/#/c/1047/). - Rewrite of configure (Android NDK) and device specific config. - Rewrite of the Android NDK specific Makefile. Misc - All plugins/games/demos activated. - Update tinyalsa to latest from https://github.com/tinyalsa/tinyalsa. Includes - http://gerrit.rockbox.org/r/#/c/993/ - http://gerrit.rockbox.org/r/#/c/1010/ - http://gerrit.rockbox.org/r/#/c/1035/ Does not include http://gerrit.rockbox.org/r/#/c/1007/ due to new backlight interface and new option for hold switch, touchscreen, physical button interaction. Rockbox needs the iBasso DX50/DX90 loader for startup, see http://gerrit.rockbox.org/r/#/c/1099/ The loader expects Rockbox to be installed in /mnt/sdcard/.rockbox/. If /mnt/sdcard/ is accessed as USB mass storage device, Rockbox will exit gracefully and the loader will restart Rockbox on USB disconnect. Tested on iBasso DX50. Compiled (not tested) for iBasso DX90. Compiled (not tested) for PLATFORM_ANDROID. Change-Id: I5f5e22e68f5b4cf29c28e2b40b2c265f2beb7ab7
Diffstat (limited to 'firmware/target/hosted/ibasso/powermgmt-ibasso.c')
-rw-r--r--firmware/target/hosted/ibasso/powermgmt-ibasso.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/firmware/target/hosted/ibasso/powermgmt-ibasso.c b/firmware/target/hosted/ibasso/powermgmt-ibasso.c
new file mode 100644
index 0000000000..7df0064097
--- /dev/null
+++ b/firmware/target/hosted/ibasso/powermgmt-ibasso.c
@@ -0,0 +1,122 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2014 by Ilia Sergachev: Initial Rockbox port to iBasso DX50
10 * Copyright (C) 2014 by Mario Basister: iBasso DX90 port
11 * Copyright (C) 2014 by Simon Rothen: Initial Rockbox repository submission, additional features
12 * Copyright (C) 2014 by Udo Schläpfer: Code clean up, additional features
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
25#include <stdio.h>
26
27#include "config.h"
28#include "debug.h"
29#include "panic.h"
30
31#include "debug-ibasso.h"
32#include "sysfs-ibasso.h"
33
34
35/* Based on batterymonitor with PISEN and Samsung SIII battery. */
36
37
38const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
39{
40 3600
41};
42
43
44const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
45{
46 3500
47};
48
49
50/*
51 Averages at percent of running time from five measuremnts with PISEN and Samsung SIII battery
52 during normal usage.
53
54 Mongo default values (?)
55 < 3660 (0%), < 3730 (1% - 10%), < 3780 (11% - 20%), < 3830 (21% - 40%), < 3950 (41% - 60%),
56 < 4080 (61% - 80%), > 4081 (81% - 100%)
57*/
58const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
59{
60 { 3522, 3660, 3720, 3752, 3784, 3827, 3896, 3978, 4072, 4168, 4255 }
61};
62
63
64/* Copied from percent_to_volt_discharge. */
65const unsigned short percent_to_volt_charge[11] =
66{
67 3500, 3544, 3578, 3623, 3660, 3773, 3782, 3853, 3980, 4130, 4360
68};
69
70
71static int _battery_present = -1;
72
73
74int _battery_voltage(void)
75{
76 /*TRACE;*/
77
78 if( (_battery_present == -1)
79 && (! sysfs_get_int(SYSFS_BATTERY_PRESENT, &_battery_present)))
80 {
81 /* This check is only done once at startup. */
82
83 DEBUGF("ERROR %s: Can not get current battery availabilty.", __func__);
84 _battery_present = 1;
85 }
86
87 int val;
88
89 if(_battery_present == 1)
90 {
91 /* Battery is present. */
92
93 /*
94 /sys/class/power_supply/battery/voltage_now
95 Voltage in microvolt.
96 */
97 if(! sysfs_get_int(SYSFS_BATTERY_VOLTAGE_NOW, &val))
98 {
99 DEBUGF("ERROR %s: Can not get current battery voltage.", __func__);
100 return 0;
101 }
102 }
103 else
104 {
105 /*
106 No battery, so we have to be running solely from USB power.
107 This will prevent Rockbox from forcing shutdown due to low power.
108 */
109
110 /*
111 /sys/class/power_supply/usb/voltage_now
112 Voltage in microvolt.
113 */
114 if(! sysfs_get_int(SYSFS_USB_POWER_VOLTAGE_NOW, &val))
115 {
116 DEBUGF("ERROR %s: Can not get current USB voltage.", __func__);
117 return 0;
118 }
119 }
120
121 return(val / 1000);
122}