diff options
author | Rob Purchase <shotofadds@rockbox.org> | 2008-04-12 16:18:28 +0000 |
---|---|---|
committer | Rob Purchase <shotofadds@rockbox.org> | 2008-04-12 16:18:28 +0000 |
commit | ddfd787c54d78104dac4ed144ff6cb6df8617a0e (patch) | |
tree | 4669b7d036b469bfb53b107adc6ae96bc53b0130 /firmware/target/arm/tcc780x | |
parent | 84dc8d2c7ea58e15b624a7fbc26d5c48ab6c9c0c (diff) |
D2: Implement battery voltage readout from PCF50606 (levels not yet calibrated). Adjust I2C delay to ensure this also works when boosted.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17085 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/tcc780x')
-rw-r--r-- | firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c index b3572307e9..71e4e325e8 100644 --- a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c @@ -21,39 +21,62 @@ #include "adc.h" #include "powermgmt.h" #include "kernel.h" +#include "pcf50606.h" unsigned short current_voltage = 3910; + const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = { - 0 + /* FIXME: calibrate value */ + 3380 }; const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = { - 0 + /* FIXME: calibrate value */ + 3300 }; /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = { - { 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320 }, + /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */ + { 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4080, 4160 } }; +#if CONFIG_CHARGING /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ const unsigned short percent_to_volt_charge[11] = { - 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320, + /* FIXME: calibrate values. Table is "inherited" from iPod-PCF / H100 */ + { 3370, 3650, 3700, 3740, 3780, 3820, 3870, 3930, 4000, 4080, 4160 } }; +#endif /* CONFIG_CHARGING */ + +#define BATTERY_SCALE_FACTOR 6000 +/* full-scale ADC readout (2^10) in millivolt */ -void read_battery_inputs(void) -{ - #warning function not implemented -} - /* Returns battery voltage from ADC [millivolts] */ unsigned int battery_adc_voltage(void) { - #warning function not implemented - return 0; + static unsigned last_tick = 0; + + if (TIME_BEFORE(last_tick+HZ, current_tick)) + { + int adc_val, irq_status; + unsigned char buf[2]; + + irq_status = disable_interrupt_save(IRQ_FIQ_DISABLED); + pcf50606_write(PCF5060X_ADCC2, 0x1); + pcf50606_read_multiple(PCF5060X_ADCS1, buf, 2); + restore_interrupt(irq_status); + + adc_val = (buf[0]<<2) | (buf[1] & 3); //ADCDAT1H+ADCDAT1L + current_voltage = (adc_val * BATTERY_SCALE_FACTOR) >> 10; + + last_tick = current_tick; + } + + return current_voltage; } |