H300: Read battery voltage with 10bit precision.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14379 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
98a3789071
commit
bfa1adcd06
2 changed files with 10 additions and 7 deletions
|
@ -26,20 +26,23 @@
|
|||
|
||||
static int adcc2_parms[] =
|
||||
{
|
||||
[ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */
|
||||
[ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */
|
||||
[ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */
|
||||
[ADC_REMOTEDETECT] = 0x80 | (2 << 1) | 1, /* ADCIN1, resistive divider */
|
||||
[ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* 8b, ADCIN2 */
|
||||
[ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* 8b, ADCIN3 */
|
||||
[ADC_BATTERY] = 0x00 | (0 << 1) | 1, /* 10b, BATVOLT, resistive divider */
|
||||
[ADC_REMOTEDETECT] = 0x80 | (2 << 1) | 1, /* 8b, ADCIN1, resistive divider */
|
||||
};
|
||||
|
||||
unsigned short adc_scan(int channel)
|
||||
{
|
||||
int level = set_irq_level(HIGHEST_IRQ_LEVEL);
|
||||
unsigned char data;
|
||||
unsigned data;
|
||||
|
||||
pcf50606_write(0x2f, adcc2_parms[channel]);
|
||||
data = pcf50606_read(0x30);
|
||||
|
||||
if (channel == ADC_BATTERY)
|
||||
data = (data << 2) | (pcf50606_read(0x31) & 0x03);
|
||||
|
||||
set_irq_level(level);
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -48,11 +48,11 @@ const unsigned short percent_to_volt_charge[11] =
|
|||
|
||||
/* FIX: this value is picked at random */
|
||||
#define BATTERY_SCALE_FACTOR 6000
|
||||
/* full-scale ADC readout (2^8) in millivolt */
|
||||
/* full-scale ADC readout (2^10) in millivolt */
|
||||
|
||||
/* Returns battery voltage from ADC [millivolts] */
|
||||
unsigned int battery_adc_voltage(void)
|
||||
{
|
||||
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 8;
|
||||
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue