diff options
-rw-r--r-- | firmware/SOURCES | 18 | ||||
-rw-r--r-- | firmware/target/arm/as3525/sansa-clip/powermgmt-clip.c | 64 |
2 files changed, 77 insertions, 5 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index d0862ba37b..752db73b01 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -348,6 +348,7 @@ target/arm/as3525/ata_sd_as3525.c target/arm/as3525/power-as3525.c target/arm/as3525/usb-as3525.c target/arm/as3525/dma-pl081.c +target/arm/as3525/as3525-codec.c #ifndef BOOTLOADER target/arm/adc-as3514.c target/arm/as3525/pcm-as3525.c @@ -355,7 +356,6 @@ target/arm/as3525/audio-as3525.c target/arm/as3525/debug-as3525.c target/arm/as3525/i2s-as3525.c target/arm/as3525/i2c-as3525.c -target/arm/as3525/powermgmt-as3525.c #endif /* BOOTLOADER */ #endif /* CONFIG_CPU == AS3525 */ @@ -1071,7 +1071,9 @@ target/arm/as3525/sansa-clip/lcd-ssd1303.c target/arm/as3525/sansa-clip/lcd-as-clip.S target/arm/as3525/sansa-clip/button-clip.c target/arm/as3525/sansa-clip/backlight-clip.c -target/arm/as3525/as3525-codec.c +#ifndef BOOTLOADER +target/arm/as3525/sansa-clip/powermgmt-clip.c +#endif /* !BOOTLOADER */ #endif /* !SIMULATOR */ #endif /* SANSA_CLIP */ @@ -1080,7 +1082,9 @@ target/arm/as3525/as3525-codec.c target/arm/as3525/sansa-e200v2/lcd-e200v2.c target/arm/as3525/sansa-e200v2/button-e200v2.c target/arm/as3525/backlight-e200v2-fuze.c -target/arm/as3525/as3525-codec.c +#ifndef BOOTLOADER +target/arm/as3525/powermgmt-as3525.c +#endif /* !BOOTLOADER */ #endif /* !SIMULATOR */ #endif /* SANSA_E200V2 */ @@ -1088,7 +1092,9 @@ target/arm/as3525/as3525-codec.c #ifndef SIMULATOR target/arm/lcd-ssd1815.c target/arm/as3525/sansa-m200v4/button-m200v4.c -target/arm/as3525/as3525-codec.c +#ifndef BOOTLOADER +target/arm/as3525/powermgmt-as3525.c +#endif /* !BOOTLOADER */ #endif /* !SIMULATOR */ #endif /* SANSA_M200V4 */ @@ -1097,7 +1103,9 @@ target/arm/as3525/as3525-codec.c target/arm/as3525/sansa-fuze/button-fuze.c target/arm/as3525/sansa-fuze/lcd-fuze.c target/arm/as3525/backlight-e200v2-fuze.c -target/arm/as3525/as3525-codec.c +#ifndef BOOTLOADER +target/arm/as3525/powermgmt-as3525.c +#endif /* !BOOTLOADER */ #endif /* !SIMULATOR */ #endif /* SANSA_FUZE */ diff --git a/firmware/target/arm/as3525/sansa-clip/powermgmt-clip.c b/firmware/target/arm/as3525/sansa-clip/powermgmt-clip.c new file mode 100644 index 0000000000..f04760d9de --- /dev/null +++ b/firmware/target/arm/as3525/sansa-clip/powermgmt-clip.c @@ -0,0 +1,64 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright © 2008 Rafaël Carré + * + * 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 "config.h" +#include "adc.h" +#include "adc-target.h" +#include "powermgmt.h" + +/* The battery manufacturer's website shows discharge curves down to 3.0V, + so 'dangerous' and 'shutoff' levels of 3.4V and 3.3V should be safe. + */ +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + 3400 +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + 3300 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3300, 3653, 3701, 3735, 3768, 3790, 3833, 3900, 3966, 4056, 4140 } +}; + +#if CONFIG_CHARGING +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = +{ + /* TODO: simple linear uncalibrated curve */ + 3300, 3390, 3480, 3570, 3660, 3750, 3840, 3930, 4020, 4110, 4200 +}; +#endif /* CONFIG_CHARGING */ + +/* ADC should read 0x3ff=5.12V */ +#define BATTERY_SCALE_FACTOR 5125 +/* full-scale ADC readout (2^10) in millivolt */ + +/* Returns battery voltage from ADC [millivolts] */ +unsigned int battery_adc_voltage(void) +{ + return (adc_read(ADC_RTCSUP) * BATTERY_SCALE_FACTOR) >> 10; +} + |