summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/iriver/h10
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2006-08-22 20:17:09 +0000
committerBarry Wardell <rockbox@barrywardell.net>2006-08-22 20:17:09 +0000
commite367b05fca08891b0ae47eab8b4a098253122633 (patch)
tree679c959e59b6646007e835662b1737d679cb8764 /firmware/target/arm/iriver/h10
parentb249d9ac2d7ac6f418d427c9e7a40c3d3a7f5ad4 (diff)
downloadrockbox-e367b05fca08891b0ae47eab8b4a098253122633.tar.gz
rockbox-e367b05fca08891b0ae47eab8b4a098253122633.tar.bz2
rockbox-e367b05fca08891b0ae47eab8b4a098253122633.zip
Move X5 ADC code to target tree. Fix power button detection on H10. New ADC
driver for H10. Thanks to Laurent Baum for all his help with this code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10701 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/iriver/h10')
-rwxr-xr-xfirmware/target/arm/iriver/h10/adc-h10.c73
-rw-r--r--firmware/target/arm/iriver/h10/adc-target.h42
-rw-r--r--firmware/target/arm/iriver/h10/button-h10.c2
3 files changed, 111 insertions, 6 deletions
diff --git a/firmware/target/arm/iriver/h10/adc-h10.c b/firmware/target/arm/iriver/h10/adc-h10.c
index 0e17ae4f91..b3a36e6b39 100755
--- a/firmware/target/arm/iriver/h10/adc-h10.c
+++ b/firmware/target/arm/iriver/h10/adc-h10.c
@@ -23,19 +23,82 @@
#include "thread.h"
#include "adc.h"
-/* TODO: implement adc functionality */
+static unsigned short adcdata[NUM_ADC_CHANNELS];
+
+/* Scan ADC so that adcdata[channel] gets updated */
unsigned short adc_scan(int channel)
{
- (void)channel;
- return 0;
+ 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 */
+
+ /* Enable Channel */
+ ADC_ADDR |= (0x1000000<<channel);
+
+ /* Start? */
+ ADC_ADDR |= 0x20000000;
+ ADC_ADDR |= 0x80000000;
+
+ /* Wait 50ms for things to settle */
+ sleep(HZ/20);
+
+ /* 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);
+
+ return adcdata[channel];
}
+/* Read 10-bit channel data */
unsigned short adc_read(int channel)
{
- (void)channel;
- return 0;
+ 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_UNKNOWN_2);
+ adc_scan(ADC_SCROLLPAD);
+ }
}
void adc_init(void)
{
+ /* Enable ADC */
+ ADC_ENABLE_ADDR |= ADC_ENABLE;
+
+ /* Initialise */
+ ADC_INIT=0;
+ ADC_ADDR=0x130;
+ ADC_STATUS=0;
+
+ /* Enable Channels 1-4 */
+ ADC_ADDR |= 0x1000000;
+ ADC_ADDR |= 0x2000000;
+ ADC_ADDR |= 0x4000000;
+ ADC_ADDR |= 0x8000000;
+
+ /* Start? */
+ ADC_ADDR |= 0x20000000;
+ ADC_ADDR |= 0x80000000;
+
+ /* Wait 50ms for things to settle */
+ sleep(HZ/20);
+
+ 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
new file mode 100644
index 0000000000..3aab373290
--- /dev/null
+++ b/firmware/target/arm/iriver/h10/adc-target.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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.
+ *
+ ****************************************************************************/
+#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))
+#define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24))
+#define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c))
+
+#define NUM_ADC_CHANNELS 4
+
+#define ADC_BATTERY 0
+#define ADC_UNKNOWN_1 1
+#define ADC_UNKNOWN_2 2
+#define ADC_SCROLLPAD 3
+#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
+
+/* Force a scan now */
+unsigned short adc_scan(int channel);
+
+#endif
diff --git a/firmware/target/arm/iriver/h10/button-h10.c b/firmware/target/arm/iriver/h10/button-h10.c
index 2a5983e97a..08fb808fcf 100644
--- a/firmware/target/arm/iriver/h10/button-h10.c
+++ b/firmware/target/arm/iriver/h10/button-h10.c
@@ -70,7 +70,7 @@ int button_read_device(void)
if ((state & 0x80) == 0) btn |= BUTTON_LEFT;
/* Read power button */
- if ((GPIOB_INPUT_VAL & 0x1) == 0) btn |= BUTTON_POWER;
+ if ((GPIOB_INPUT_VAL & 0x1) == 1) btn |= BUTTON_POWER;
/* Read scroller */
if ( ((GPIOC_INPUT_VAL & 0x4)==1) && ((GPIOD_INPUT_VAL & 0x10)==1) )