imx233: add automatic battery conversion using delay channel, make 5V a virtual channel since it has a builtin divider

fuze+: use 5V virtual channel

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30982 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Amaury Pouly 2011-11-14 21:05:14 +00:00
parent a9d56ac5de
commit e167c1d8d7
3 changed files with 22 additions and 7 deletions

View file

@ -30,25 +30,37 @@
* and channel 6 to vddio */
static int pmos_chan, nmos_chan;
static int battery_chan, vddio_chan;
static int battery_delay_chan;
void adc_init(void)
{
imx233_lradc_init();
/* reserve channels 6 for vddio and 7 for battery (special for conversion) */
battery_chan = 7;
vddio_chan = 6;
imx233_lradc_reserve_channel(battery_chan);
imx233_lradc_reserve_channel(vddio_chan);
/* reserve any channels for PMOS and NMOS */
pmos_chan = imx233_lradc_acquire_channel(TIMEOUT_NOBLOCK);
if(pmos_chan < 0) panicf("No LRADC channel for PMOS !");
nmos_chan = imx233_lradc_acquire_channel(TIMEOUT_NOBLOCK);
if(nmos_chan < 0) panicf("No LRADC channel for NMOS !");
// setup them
/* setup them for the simplest use: no accumulation, no division*/
imx233_lradc_setup_channel(battery_chan, false, false, 0, HW_LRADC_CHANNEL_BATTERY);
imx233_lradc_setup_channel(vddio_chan, false, false, 0, HW_LRADC_CHANNEL_VDDIO);
imx233_lradc_setup_channel(nmos_chan, false, false, 0, HW_LRADC_CHANNEL_NMOS_THIN);
imx233_lradc_setup_channel(pmos_chan, false, false, 0, HW_LRADC_CHANNEL_PMOS_THIN);
/* setup delay channel for battery for automatic reading and scaling */
battery_delay_chan = 0;
imx233_lradc_reserve_delay(battery_delay_chan);
/* setup delay to trigger battery channel and retrigger itself.
* The counter runs at 2KHz so a delay of 200 will trigger 10
* conversions per seconds */
imx233_lradc_setup_delay(battery_delay_chan, 1 << battery_chan,
1 << battery_delay_chan, 0, 200);
/* enable automatic conversion, use Li-Ion type battery */
imx233_lradc_setup_battery_conversion(true, HW_LRADC_CONVERSION__SCALE_FACTOR__LI_ION);
}
int adc_read_physical_ex(int virt)
@ -56,8 +68,7 @@ int adc_read_physical_ex(int virt)
imx233_lradc_clear_channel(virt);
imx233_lradc_kick_channel(virt);
imx233_lradc_wait_channel(virt);
int v = imx233_lradc_read_channel(virt);
return v;
return imx233_lradc_read_channel(virt);
}
int adc_read_physical(int src)
@ -75,9 +86,12 @@ unsigned short adc_read_virtual(int c)
switch(c)
{
case IMX233_ADC_BATTERY:
return adc_read_physical_ex(battery_chan);
return /*imx233_lradc_read_battery_voltage()*/adc_read_physical_ex(battery_chan);
case IMX233_ADC_VDDIO:
return adc_read_physical_ex(vddio_chan);
case IMX233_ADC_5V:
/* channel 15 5V has a 4:1 built it divider */
return adc_read_physical(HW_LRADC_CHANNEL_5V) * 4;
case IMX233_ADC_DIE_TEMP:
// do kelvin to celsius conversion
return imx233_lradc_sense_die_temperature(nmos_chan, pmos_chan) - 273;

View file

@ -29,6 +29,7 @@
#define IMX233_ADC_BATTERY -1 /* Battery voltage (mV) */
#define IMX233_ADC_DIE_TEMP -2 /* Die temperature (°C) */
#define IMX233_ADC_VDDIO -3 /* VddIO voltage (mV) */
#define IMX233_ADC_5V -4 /* Vdd5V voltage (mV) */
/* Channel mapping */
extern int imx233_adc_mapping[];

View file

@ -26,7 +26,7 @@ int imx233_adc_mapping[] =
[ADC_BATTERY] = IMX233_ADC_BATTERY,
[ADC_DIE_TEMP] = IMX233_ADC_DIE_TEMP,
[ADC_VDDIO] = IMX233_ADC_VDDIO,
[ADC_5V] = HW_LRADC_CHANNEL_5V,
[ADC_5V] = IMX233_ADC_5V,
};
const char *imx233_adc_channel_name[] =
@ -34,5 +34,5 @@ const char *imx233_adc_channel_name[] =
"Battery(mV)",
"Die temperature(°C)",
"VddIO",
"5V",
"Vdd5V",
};