summaryrefslogtreecommitdiff
path: root/firmware/target/arm/iriver/h10
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-10-16 10:48:16 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-10-16 10:48:16 +0000
commit1d1a17c0dbd0fdf2857c5d1636713247d28f1762 (patch)
tree863d40550a3f6da5406d65471b3593bde9f9d8d5 /firmware/target/arm/iriver/h10
parent8b44601a7c306611b9aba29a7774708585c97539 (diff)
Improved H10 ADC driver. We now do things exactly as the OF does. This includes shifting the readings by 0x14 when PLL is enabled. Battery voltages and remote/scrollpad values adjusted accordingly. We also now wait for the ADC to indicate the conversion is complete before reading the data, so hopefully we will get more reliably steady readings.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15141 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/iriver/h10')
-rw-r--r--firmware/target/arm/iriver/h10/adc-h10.c90
-rw-r--r--firmware/target/arm/iriver/h10/adc-target.h3
-rw-r--r--firmware/target/arm/iriver/h10/button-h10.c12
-rw-r--r--firmware/target/arm/iriver/h10/powermgmt-h10.c18
4 files changed, 79 insertions, 44 deletions
diff --git a/firmware/target/arm/iriver/h10/adc-h10.c b/firmware/target/arm/iriver/h10/adc-h10.c
index df9b16359b..f63e8b8013 100644
--- a/firmware/target/arm/iriver/h10/adc-h10.c
+++ b/firmware/target/arm/iriver/h10/adc-h10.c
@@ -25,29 +25,21 @@
static unsigned short adcdata[NUM_ADC_CHANNELS];
-/* Scan ADC so that adcdata[channel] gets updated */
+/* Scan ADC so that adcdata[channel] gets updated. */
unsigned short adc_scan(int channel)
{
unsigned int adc_data_1;
unsigned int adc_data_2;
- /* Initialise */
- ADC_ADDR=0x130;
- ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is
- off, 0x40 if the channel is on */
+ /* Start conversion */
+ ADC_ADDR |= 0x80000000;
- /* Enable Channel */
- ADC_ADDR |= (0x1000000<<channel);
+ /* Wait for conversion to complete */
+ while((ADC_STATUS & (0x40<<8*channel))==0);
+
+ /* Stop conversion */
+ ADC_ADDR &=~ 0x80000000;
- /* Start? */
- ADC_ADDR |= 0x20000000;
- ADC_ADDR |= 0x80000000;
-
-#if 0
- /* wait for ADC ready. THIS IS NOT WORKING (locks up) */
- while(ADC_STATUS & (0x40 << (channel*8))); /* add loop protection here */
-#endif
-
/* 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. */
@@ -56,6 +48,13 @@ unsigned short adc_scan(int channel)
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];
}
@@ -79,25 +78,64 @@ static void adc_tick(void)
}
}
+/* Figured out from how the OF does things */
void adc_init(void)
{
- /* Enable ADC */
- ADC_ENABLE_ADDR |= ADC_ENABLE;
+ ADC_INIT |= 1;
+ ADC_INIT |= 0x40000000;
+ udelay(100);
+
+ /* Reset ADC */
+ DEV_RS2 |= 0x20;
+ udelay(100);
+
+ DEV_RS2 &=~ 0x20;
+ udelay(100);
- /* Initialise */
- ADC_INIT=0;
+ /* 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);
-
- /* FIXME: The ADC sometimes reads 0 for the battery
- voltage for the first few seconds. It would be better to fix this by
- figuring out how to use the ADC properly. Until then, work around the
- problem by waiting until it reads a proper value*/
- while(adc_scan(ADC_UNREG_POWER)==0);
tick_add_task(adc_tick);
}
diff --git a/firmware/target/arm/iriver/h10/adc-target.h b/firmware/target/arm/iriver/h10/adc-target.h
index 741c293baa..f761e761ef 100644
--- a/firmware/target/arm/iriver/h10/adc-target.h
+++ b/firmware/target/arm/iriver/h10/adc-target.h
@@ -19,9 +19,6 @@
#ifndef _ADC_TARGET_H_
#define _ADC_TARGET_H_
-#define ADC_ENABLE_ADDR (*(volatile unsigned long*)(0x70000010))
-#define ADC_ENABLE 0x1100
-
#define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00))
#define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04))
#define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20))
diff --git a/firmware/target/arm/iriver/h10/button-h10.c b/firmware/target/arm/iriver/h10/button-h10.c
index d8a82cf170..ac09d245e6 100644
--- a/firmware/target/arm/iriver/h10/button-h10.c
+++ b/firmware/target/arm/iriver/h10/button-h10.c
@@ -52,7 +52,7 @@ bool button_hold(void)
bool remote_button_hold(void)
{
- return adc_scan(ADC_REMOTE) < 0x17;
+ return adc_scan(ADC_REMOTE) < 0x2B;
}
/*
@@ -102,7 +102,7 @@ int button_read_device(void)
data = adc_scan(ADC_SCROLLPAD);
GPIOD_OUTPUT_VAL |= 0x40;
- if(data < 0x210)
+ if(data < 0x224)
{
btn |= BUTTON_SCROLL_DOWN;
} else {
@@ -115,7 +115,7 @@ int button_read_device(void)
remote_hold_button_old = remote_hold_button;
data = adc_scan(ADC_REMOTE);
- remote_hold_button = data < 0x17;
+ remote_hold_button = data < 0x2B;
#ifndef BOOTLOADER
if (remote_hold_button != remote_hold_button_old)
@@ -126,13 +126,13 @@ int button_read_device(void)
{
if (data < 0x3FF)
{
- if(data < 0x1F0)
- if(data < 0x141)
+ if(data < 0x204)
+ if(data < 0x155)
btn |= BUTTON_RC_FF;
else
btn |= BUTTON_RC_REW;
else
- if(data < 0x2BC)
+ if(data < 0x2D0)
btn |= BUTTON_RC_VOL_DOWN;
else
btn |= BUTTON_RC_VOL_UP;
diff --git a/firmware/target/arm/iriver/h10/powermgmt-h10.c b/firmware/target/arm/iriver/h10/powermgmt-h10.c
index 18e3879c43..6f8cd12276 100644
--- a/firmware/target/arm/iriver/h10/powermgmt-h10.c
+++ b/firmware/target/arm/iriver/h10/powermgmt-h10.c
@@ -25,18 +25,18 @@
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
{
#ifdef IRIVER_H10
- 3760
+ 3733
#elif defined IRIVER_H10_5GB
- 3720
+ 3695
#endif
};
const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
{
#ifdef IRIVER_H10
- 3650
+ 3627
#elif defined IRIVER_H10_5GB
- 3650
+ 3627
#endif
};
@@ -44,9 +44,9 @@ const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
{
#ifdef IRIVER_H10
- { 3760, 3800, 3850, 3870, 3900, 3950, 4020, 4070, 4110, 4180, 4240 }
+ { 3733, 3772, 3821, 3840, 3869, 3917, 3985, 4034, 4072, 4140, 4198 }
#elif defined IRIVER_H10_5GB
- { 3720, 3740, 3800, 3820, 3840, 3880, 3940, 4020, 4060, 4150, 4240 }
+ { 3695, 3714, 3772, 3791, 3811, 3850, 3908, 3985, 4024, 4111, 4198 }
#endif
};
@@ -54,14 +54,14 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
const unsigned short percent_to_volt_charge[11] =
{
#ifdef IRIVER_H10
- 3990, 4030, 4060, 4080, 4100, 4120, 4150, 4180, 4220, 4260, 4310
+ 3956, 3995, 4024, 4043, 4063, 4082, 4111, 4140, 4179, 4218, 4266
#elif defined IRIVER_H10_5GB
/* TODO: Not yet calibrated */
- 3880, 3920, 3960, 4000, 4060, 4100, 4150, 4190, 4240, 4280, 4330
+ 3850, 3888, 3927, 3966, 4024, 4063, 4111, 4150, 4198, 4237, 4286
#endif
};
-#define BATTERY_SCALE_FACTOR 4800
+#define BATTERY_SCALE_FACTOR 4650
/* full-scale ADC readout (2^10) in millivolt */
/* Returns battery voltage from ADC [millivolts] */