1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
11 * Revisions copyright (C) 2005 by Gerald Van Baren
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
23 #include "powermgmt.h"
25 const unsigned short battery_level_dangerous
[BATTERY_TYPES_COUNT
] =
30 const unsigned short battery_level_shutoff
[BATTERY_TYPES_COUNT
] =
35 /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
36 const unsigned short percent_to_volt_discharge
[BATTERY_TYPES_COUNT
][11] =
38 /* Sansa Li Ion 750mAH, took from battery benchs */
39 { 3300, 3680, 3740, 3760, 3780, 3810, 3870, 3930, 3970, 4070, 4160 },
42 /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
43 const unsigned short percent_to_volt_charge
[11] =
45 /* Sansa Li Ion 750mAH FIXME */
46 3300, 3680, 3740, 3760, 3780, 3810, 3870, 3930, 3970, 4070, 4160
49 /* ADC should read 0x3ff=5.12V */
50 #define BATTERY_SCALE_FACTOR 5125
51 /* full-scale ADC readout (2^10) in millivolt */
53 /* Returns battery voltage from ADC [millivolts] */
54 unsigned int battery_adc_voltage(void)
56 return (adc_read(ADC_UNREG_POWER
) * BATTERY_SCALE_FACTOR
) >> 10;