1
0
Fork 0
forked from len0rd/rockbox

- share adc reading code between h10 and mrobe100

- battery voltage calibrated and used for mrobe100 


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16064 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Kukla 2008-01-12 20:36:45 +00:00
parent 36ffa79875
commit a615aabc33
7 changed files with 31 additions and 167 deletions

View file

@ -544,7 +544,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
target/arm/iriver/h10/adc-h10.c
target/arm/adc-pp5020.c
target/arm/iriver/h10/backlight-h10.c
target/arm/iriver/h10/button-h10.c
target/arm/iriver/h10/fmradio_i2c-h10.c
@ -561,7 +561,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
target/arm/iriver/h10/adc-h10.c
target/arm/adc-pp5020.c
target/arm/iriver/h10/backlight-h10.c
target/arm/iriver/h10/button-h10.c
target/arm/iriver/h10/fmradio_i2c-h10.c
@ -658,7 +658,7 @@ target/arm/ata-as-arm.S
target/arm/ata-pp5020.c
target/arm/wmcodec-pp.c
target/arm/i2s-pp.c
target/arm/olympus/mrobe-100/adc-mr100.c
target/arm/adc-pp5020.c
target/arm/olympus/mrobe-100/backlight-mr100.c
target/arm/olympus/mrobe-100/button-mr100.c
target/arm/olympus/mrobe-100/lcd-mr100.c

View file

@ -4,9 +4,6 @@
#define TARGET_TREE
/* until voltages are sorted out */
#define NO_LOW_BATTERY_SHUTDOWN
#define OLYMPUS_MROBE_100 1
/* For Rolo and boot loader */

View file

@ -71,10 +71,10 @@ static void adc_tick(void)
if(++adc_counter == HZ)
{
adc_counter = 0;
adc_scan(ADC_BATTERY);
adc_scan(ADC_UNKNOWN_1);
adc_scan(ADC_REMOTE);
adc_scan(ADC_SCROLLPAD);
adc_scan(0);
adc_scan(1);
adc_scan(2);
adc_scan(3);
}
}
@ -114,28 +114,28 @@ void adc_init(void)
ADC_ADDR |= 0x1000000;
ADC_STATUS |= 0x20;
/* Enable channel 1 (unknown, temperature?) */
/* Enable channel 1 (unknown) */
DEV_INIT1 &=~30;
ADC_ADDR |= 0x2000000;
ADC_STATUS |= 0x2000;
/* Enable channel 2 (remote) */
/* Enable channel 2 (H10:remote) */
DEV_INIT1 &=~0x300;
DEV_INIT1 |= 0x100;
ADC_ADDR |= 0x4000000;
ADC_STATUS |= 0x200000;
/* Enable channel 3 (scroll pad) */
/* Enable channel 3 (H10:scroll pad) */
DEV_INIT1 &=~0x3000;
DEV_INIT1 |= 0x1000;
ADC_ADDR |= 0x8000000;
ADC_STATUS |= 0x20000000;
/* Force a scan of all channels to get initial values */
adc_scan(ADC_BATTERY);
adc_scan(ADC_UNKNOWN_1);
adc_scan(ADC_REMOTE);
adc_scan(ADC_SCROLLPAD);
adc_scan(0);
adc_scan(1);
adc_scan(2);
adc_scan(3);
tick_add_task(adc_tick);
}

View file

@ -1,141 +0,0 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2006 by Barry Wardell
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h"
#include "cpu.h"
#include "system.h"
#include "kernel.h"
#include "thread.h"
#include "adc.h"
static unsigned short adcdata[NUM_ADC_CHANNELS];
/* Scan ADC so that adcdata[channel] gets updated. */
unsigned short adc_scan(int channel)
{
unsigned int adc_data_1;
unsigned int adc_data_2;
/* Start conversion */
ADC_ADDR |= 0x80000000;
/* Wait for conversion to complete */
while((ADC_STATUS & (0x40<<8*channel))==0);
/* Stop conversion */
ADC_ADDR &=~ 0x80000000;
/* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel.
For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the
2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */
adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff);
adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3);
adcdata[channel] = (adc_data_1<<2 | adc_data_2);
/* ADC values read low if PLL is enabled */
if(PLL_CONTROL & 0x80000000){
adcdata[channel] += 0x14;
if(adcdata[channel] > 0x400)
adcdata[channel] = 0x400;
}
return adcdata[channel];
}
/* Read 10-bit channel data */
unsigned short adc_read(int channel)
{
return adcdata[channel];
}
static int adc_counter;
static void adc_tick(void)
{
if(++adc_counter == HZ)
{
adc_counter = 0;
adc_scan(ADC_BATTERY);
adc_scan(ADC_UNKNOWN_1);
adc_scan(ADC_REMOTE);
adc_scan(ADC_SCROLLPAD);
}
}
/* Figured out from how the OF does things */
void adc_init(void)
{
ADC_INIT |= 1;
ADC_INIT |= 0x40000000;
udelay(100);
/* Reset ADC */
DEV_RS2 |= 0x20;
udelay(100);
DEV_RS2 &=~ 0x20;
udelay(100);
/* Enable ADC */
DEV_EN2 |= 0x20;
udelay(100);
ADC_CLOCK_SRC |= 0x3;
udelay(100);
ADC_ADDR |= 0x40;
ADC_ADDR |= 0x20000000;
udelay(100);
ADC_INIT;
ADC_INIT = 0;
udelay(100);
ADC_STATUS = 0;
/* Enable channel 0 (battery) */
DEV_INIT1 &=~0x3;
ADC_ADDR |= 0x1000000;
ADC_STATUS |= 0x20;
/* Enable channel 1 (unknown, temperature?) */
DEV_INIT1 &=~30;
ADC_ADDR |= 0x2000000;
ADC_STATUS |= 0x2000;
/* Enable channel 2 (remote) */
DEV_INIT1 &=~0x300;
DEV_INIT1 |= 0x100;
ADC_ADDR |= 0x4000000;
ADC_STATUS |= 0x200000;
/* Enable channel 3 (scroll pad) */
DEV_INIT1 &=~0x3000;
DEV_INIT1 |= 0x1000;
ADC_ADDR |= 0x8000000;
ADC_STATUS |= 0x20000000;
/* Force a scan of all channels to get initial values */
adc_scan(ADC_BATTERY);
adc_scan(ADC_UNKNOWN_1);
adc_scan(ADC_REMOTE);
adc_scan(ADC_SCROLLPAD);
tick_add_task(adc_tick);
}

View file

@ -29,8 +29,8 @@
#define ADC_BATTERY 0
#define ADC_UNKNOWN_1 1
#define ADC_REMOTE 2
#define ADC_SCROLLPAD 3
#define ADC_UNKNOWN_2 2
#define ADC_UNKNOWN_3 3
#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
/* Force a scan now */

View file

@ -37,7 +37,7 @@ void power_init(void)
bool charger_inserted(void)
{
return (GPIOB_INPUT_VAL & 0x02) ? false : true ;
return (GPIOL_INPUT_VAL & 0x24) ? true : false ;
}
void ide_power_enable(bool on)

View file

@ -27,33 +27,41 @@
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
{
3760
3450
};
const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
{
3650
3400
};
/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{
{ 3760, 3800, 3850, 3870, 3900, 3950, 4020, 4070, 4110, 4180, 4240 }
{ 3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990 },
};
#if CONFIG_CHARGING
/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
const unsigned short percent_to_volt_charge[11] =
{
3990, 4030, 4060, 4080, 4100, 4120, 4150, 4180, 4220, 4260, 4310
3480, 3550, 3590, 3610, 3630, 3650, 3700, 3760, 3800, 3910, 3990
};
#endif /* CONFIG_CHARGING */
#define BATTERY_SCALE_FACTOR 4650
#define BATTERY_SCALE_FACTOR 6052
/* full-scale ADC readout (2^10) in millivolt */
/* adc readout
* max with charger connected: 690
* max fully charged: 682
* min just before shutdown:
*/
/* Returns battery voltage from ADC [millivolts] */
unsigned int battery_adc_voltage(void)
{
return (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) >> 10;
/* work around the inital (false) high readout */
int readout=adc_read(ADC_UNREG_POWER);
return (readout>700) ? 3990 : (readout * BATTERY_SCALE_FACTOR) >> 10;
}