From 7f4f9aead74f7e11cf13811e002bffde464c4ba8 Mon Sep 17 00:00:00 2001 From: Barry Wardell Date: Tue, 13 Mar 2007 01:50:13 +0000 Subject: Improved ADC driver for AS3514 (used in PP5024 - ie. Sansa e200) based off datasheet. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12745 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/sandisk/sansa-e200/adc-e200.c | 24 ++++++++++++---------- .../target/arm/sandisk/sansa-e200/adc-target.h | 22 +++++++++++++++++--- 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'firmware/target/arm') diff --git a/firmware/target/arm/sandisk/sansa-e200/adc-e200.c b/firmware/target/arm/sandisk/sansa-e200/adc-e200.c index b3206d68d1..5e57e4bec5 100644 --- a/firmware/target/arm/sandisk/sansa-e200/adc-e200.c +++ b/firmware/target/arm/sandisk/sansa-e200/adc-e200.c @@ -18,23 +18,25 @@ ****************************************************************************/ #include "adc.h" #include "i2c-pp.h" -#include "logf.h" +#include "as3514.h" /* Read 10-bit channel data */ unsigned short adc_read(int channel) { - unsigned char bat[2]; + unsigned char buf[2]; unsigned short data = 0; - switch( channel) - { - case ADC_UNREG_POWER: - pp_i2c_send( 0x46, 0x2e, 0x0); - pp_i2c_send( 0x46, 0x27, 0x1); - i2c_readbytes( 0x46, 0x2e, 2, bat); - data = ((bat[0]<<8) | bat[1]); - break; - } + /* Select channel */ + pp_i2c_send( AS3514_I2C_ADDR, ADC_0, (channel << 4)); + + /* Wait for conversion to be complete */ + pp_i2c_send( AS3514_I2C_ADDR, IRQ_ENRD2, 0x1); + while( (i2c_readbyte( AS3514_I2C_ADDR, IRQ_ENRD2) & 0x1) == 0); + + /* Read data */ + i2c_readbytes( AS3514_I2C_ADDR, ADC_0, 2, buf); + data = (((buf[0] & 0x3) << 8) | buf[1]); + return data; } diff --git a/firmware/target/arm/sandisk/sansa-e200/adc-target.h b/firmware/target/arm/sandisk/sansa-e200/adc-target.h index e9bff42a52..56efdf7574 100644 --- a/firmware/target/arm/sandisk/sansa-e200/adc-target.h +++ b/firmware/target/arm/sandisk/sansa-e200/adc-target.h @@ -19,9 +19,25 @@ #ifndef _ADC_TARGET_H_ #define _ADC_TARGET_H_ -#define NUM_ADC_CHANNELS 1 +/* ADC channels */ +#define NUM_ADC_CHANNELS 13 -#define ADC_BATTERY 0 -#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ +#define ADC_BVDD 0 /* Battery voltage of 4V LiIo accumulator */ +#define ADC_RTCSUP 1 /* RTC backup battery voltage */ +#define ADC_UVDD 2 /* USB host voltage */ +#define ADC_CHG_IN 3 /* Charger input voltage */ +#define ADC_CVDD 4 /* Charger pump output voltage */ +#define ADC_BATTEMP 5 /* Battery charging temperature */ +#define ADC_MICSUP1 6 /* Voltage on MicSup1 for remote control + or external voltage measurement */ +#define ADC_MICSUP2 7 /* Voltage on MicSup1 for remote control + or external voltage measurement */ +#define ADC_VBE1 8 /* Measuring junction temperature @ 2uA */ +#define ADC_VBE2 9 /* Measuring junction temperature @ 1uA */ +#define ADC_I_MICSUP1 10 /* Current of MicSup1 for remote control detection */ +#define ADC_I_MICSUP2 11 /* Current of MicSup2 for remote control detection */ +#define ADC_VBAT 12 /* Single cell battery voltage */ + +#define ADC_UNREG_POWER ADC_BVDD /* For compatibility */ #endif -- cgit v1.2.3