rockbox/firmware/target/hosted/android/dx50/powermgmt-dx50.c
Udo Schläfer fe519c7e4d 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>
2014-10-18 05:31:34 +02:00

97 lines
2.6 KiB
C

/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2010 by Thomas Martitz
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#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;
FILE *f = fopen("/sys/class/power_supply/ac/present", "r");
fscanf(f, "%d", &val);
fclose(f);
return val?POWER_INPUT_MAIN_CHARGER:POWER_INPUT_NONE;
}
/* 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
};
const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
{
3100
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
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 is enabled. */
const unsigned short percent_to_volt_charge[11] =
{
3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4090, 4190
};
/* Returns battery voltage from android measurement [millivolts] */
int _battery_voltage(void)
{
int val;
FILE *f = fopen("/sys/class/power_supply/battery/voltage_now", "r");
fscanf(f, "%d", &val);
fclose(f);
return (val/1000);
}