diff options
author | Barry Wardell <rockbox@barrywardell.net> | 2007-03-13 01:50:13 +0000 |
---|---|---|
committer | Barry Wardell <rockbox@barrywardell.net> | 2007-03-13 01:50:13 +0000 |
commit | 7f4f9aead74f7e11cf13811e002bffde464c4ba8 (patch) | |
tree | 2e7c1ab3399cb6208bfd3ea80cefff4234bfd094 | |
parent | b051f101d95bb2581eceacd374dd1fbf02b25bc4 (diff) |
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
-rw-r--r-- | apps/debug_menu.c | 28 | ||||
-rw-r--r-- | firmware/export/as3514.h | 9 | ||||
-rw-r--r-- | firmware/export/config-e200.h | 2 | ||||
-rw-r--r-- | firmware/target/arm/sandisk/sansa-e200/adc-e200.c | 24 | ||||
-rw-r--r-- | firmware/target/arm/sandisk/sansa-e200/adc-target.h | 22 |
5 files changed, 70 insertions, 15 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index b08fcb461f..996f13d55c 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -1190,6 +1190,34 @@ bool dbg_ports(void) lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "ADC_SCROLLPAD: %02x", adc_read(ADC_SCROLLPAD)); lcd_puts(0, line++, buf); +#elif defined(SANSA_E200) + line++; + snprintf(buf, sizeof(buf), "ADC_BVDD: %02x", adc_read(ADC_BVDD)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_RTCSUP: %02x", adc_read(ADC_RTCSUP)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_UVDD: %02x", adc_read(ADC_UVDD)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_CHG_IN: %02x", adc_read(ADC_CHG_IN)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_CVDD: %02x", adc_read(ADC_CVDD)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_BATTEMP: %02x", adc_read(ADC_BATTEMP)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_MICSUP1: %02x", adc_read(ADC_MICSUP1)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_MICSUP2: %02x", adc_read(ADC_MICSUP2)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_VBE1: %02x", adc_read(ADC_VBE1)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_VBE2: %02x", adc_read(ADC_VBE2)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_I_MICSUP1: %02x", adc_read(ADC_I_MICSUP1)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_I_MICSUP2: %02x", adc_read(ADC_I_MICSUP2)); + lcd_puts(0, line++, buf); + snprintf(buf, sizeof(buf), "ADC_VBAT: %02x", adc_read(ADC_VBAT)); + lcd_puts(0, line++, buf); #endif lcd_update(); if (button_get_w_tmo(HZ/10) == (DEBUG_CANCEL|BUTTON_REL)) diff --git a/firmware/export/as3514.h b/firmware/export/as3514.h index 0bf87dbc46..3261765f7f 100644 --- a/firmware/export/as3514.h +++ b/firmware/export/as3514.h @@ -20,6 +20,8 @@ #ifndef _AS3514_H #define _AS3514_H +#include <stdbool.h> + extern int tenthdb2master(int db); extern int tenthdb2mixer(int db); @@ -67,6 +69,13 @@ extern void audiohw_set_equalizer_band(int band, int freq, int bw, int gain); #define AUDIOSET3 0x16 #define PLLMODE 0x1d +#define IRQ_ENRD0 0x25 +#define IRQ_ENRD1 0x26 +#define IRQ_ENRD2 0x27 + +#define ADC_0 0x2e +#define ADC_1 0x2f + /* Headphone volume goes from -45.43 - 1.07dB */ #define VOLUME_MIN -454 #define VOLUME_MAX 10 diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h index 1b3404a148..304c7062e5 100644 --- a/firmware/export/config-e200.h +++ b/firmware/export/config-e200.h @@ -88,7 +88,7 @@ #define BATTERY_CAPACITY_MAX 750 /* max. capacity selectable */ #define BATTERY_CAPACITY_INC 0 /* capacity increment */ #define BATTERY_TYPES_COUNT 1 /* only one type */ -#define BATTERY_SCALE_FACTOR 5054 +#define BATTERY_SCALE_FACTOR 5005 /* ADC should read 0x3ff=5.12V */ /* Hardware controlled charging? FIXME */ #define CONFIG_CHARGING CHARGING_SIMPLE 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 |