summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUdo Schläfer <rockbox-2014.10@desktopwarrior.net>2014-10-13 21:21:01 +0200
committerMichael Giacomelli <giac2000@hotmail.com>2014-10-18 05:31:34 +0200
commitfe519c7e4d4022fd692c90d507f0917a02547ad8 (patch)
treed331f913a7e3d09f8392d94be6998618636eed42
parentac928ed7a2e0f133c56d7677dc09b001c21be1a5 (diff)
Enable battery charging detection for iBasso DX50/DX90.
This changes iBasso DX50/DX90 config from CHARGING_SIMPLE (Simple, hardware controlled charging (CPU cannot read charger state but may read when power is plugged-in) to CHARGING_MONITOR (Hardware controlled charging with monitoring (CPU is able to read HW charging state and when power is plugged-in)). Not really usefull at the moment, since USB connection (charging) is not (yet) gracefully handled for iBasso devices. Change-Id: I55da81b10637d4de88d713ea5eba08eb59bc629f Reviewed-on: http://gerrit.rockbox.org/1010 Reviewed-by: Michael Giacomelli <giac2000@hotmail.com>
-rw-r--r--firmware/export/config/ibassodx50.h2
-rw-r--r--firmware/export/config/ibassodx90.h2
-rw-r--r--firmware/target/hosted/android/dx50/powermgmt-dx50.c31
3 files changed, 30 insertions, 5 deletions
diff --git a/firmware/export/config/ibassodx50.h b/firmware/export/config/ibassodx50.h
index 652377cc6c..5bbb515c1c 100644
--- a/firmware/export/config/ibassodx50.h
+++ b/firmware/export/config/ibassodx50.h
@@ -99,7 +99,7 @@
#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
-#define CONFIG_CHARGING CHARGING_SIMPLE
+#define CONFIG_CHARGING CHARGING_MONITOR
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/export/config/ibassodx90.h b/firmware/export/config/ibassodx90.h
index d560f3e10b..68a728eab4 100644
--- a/firmware/export/config/ibassodx90.h
+++ b/firmware/export/config/ibassodx90.h
@@ -99,7 +99,7 @@
#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
-#define CONFIG_CHARGING CHARGING_SIMPLE
+#define CONFIG_CHARGING CHARGING_MONITOR
#define NO_LOW_BATTERY_SHUTDOWN
diff --git a/firmware/target/hosted/android/dx50/powermgmt-dx50.c b/firmware/target/hosted/android/dx50/powermgmt-dx50.c
index 45756cb8e8..713e8a977e 100644
--- a/firmware/target/hosted/android/dx50/powermgmt-dx50.c
+++ b/firmware/target/hosted/android/dx50/powermgmt-dx50.c
@@ -21,10 +21,12 @@
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#include "config.h"
#include "power.h"
#include "powermgmt.h"
+
unsigned int power_input_status(void)
{
int val;
@@ -34,8 +36,31 @@ unsigned int power_input_status(void)
return val?POWER_INPUT_MAIN_CHARGER:POWER_INPUT_NONE;
}
-/* Values for stock PISEN battery. TODO: Needs optimization */
+/* Returns true, if battery is charging, false else. */
+bool charging_state( void )
+{
+ /* Full, Charging, Discharging */
+ char state[9];
+
+ /* true if charging. */
+ bool charging = false;
+
+ FILE *f = fopen( "/sys/class/power_supply/battery/status", "r" );
+ if( f != NULL )
+ {
+ if( fgets( state, 9, f ) != NULL )
+ {
+ charging = ( strcmp( state, "Charging" ) == 0 );
+ }
+ }
+ fclose( f );
+
+ return charging;
+}
+
+
+/* Values for stock PISEN battery. TODO: Needs optimization */
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
{
3380
@@ -52,10 +77,10 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{ 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4090, 4190 }
};
-/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
+/* Voltages (millivolt) of 0%, 10%, ... 100% when charging is enabled. */
const unsigned short percent_to_volt_charge[11] =
{
- 3540, 3860, 3930, 3980, 4000, 4020, 4040, 4080, 4130, 4180, 4220 /* LiPo */
+ 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4090, 4190
};