mr500 sort of working battery measurments. probably could be done better, but it works

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15271 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2007-10-22 15:28:40 +00:00
parent 0ed79898af
commit 4c06ad6e72
2 changed files with 46 additions and 2 deletions

View file

@ -187,8 +187,21 @@ int button_read_device(int *data)
} }
/* Touchpad data available interupt */ /* Touchpad data available interupt */
void read_battery_inputs(void);
void GIO14(void) void GIO14(void)
{ {
short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
switch (adscm)
{
case 1:
case 2:
touch_available = true;
break;
case 0xb:
read_battery_inputs();
break;
}
touch_available = true; touch_available = true;
IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */ IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */
} }

View file

@ -20,7 +20,10 @@
#include "config.h" #include "config.h"
#include "adc.h" #include "adc.h"
#include "powermgmt.h" #include "powermgmt.h"
#include "tsc2100.h"
#include "kernel.h"
unsigned short current_voltage = 3910;
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
{ {
3450 3450
@ -42,10 +45,38 @@ const unsigned short percent_to_volt_charge[11] =
{ {
3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990
}; };
void read_battery_inputs(void)
{
short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT;
if (adscm == 0xb) /* battery is available */
{
current_voltage = tsc2100_readreg(0, 5); /* BAT1 */
tsc2100_readreg(0, 6); /* BAT2 */
tsc2100_readreg(0, 7); /* AUX */
/* reset the TSC2100 to read touches */
tsadc &= ~(TSADC_PSTCM|TSADC_ADST|TSADC_ADSCM_MASK);
tsadc |= TSADC_PSTCM|(0x2<<TSADC_ADSCM_SHIFT);
tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS, tsadc);
tsc2100_writereg(TSSTAT_PAGE, TSSTAT_ADDRESS, 2<<TSSTAT_PINTDAV_SHIFT);
}
}
/* Returns battery voltage from ADC [millivolts] */ /* Returns battery voltage from ADC [millivolts] */
unsigned int battery_adc_voltage(void) unsigned int battery_adc_voltage(void)
{ {
return 3910; static unsigned last_tick = 0;
short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS);
if (TIME_BEFORE(last_tick+2*HZ, current_tick))
{
tsadc &= ~(TSADC_PSTCM|TSADC_ADST|TSADC_ADSCM_MASK);
tsadc |= 0xb<<TSADC_ADSCM_SHIFT;
tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS, tsadc&(~(1<<15)));
tsc2100_writereg(TSSTAT_PAGE, TSSTAT_ADDRESS, 2<<TSSTAT_PINTDAV_SHIFT);
last_tick = current_tick;
}
else
read_battery_inputs();
return current_voltage;
} }