summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2004-11-03 00:39:30 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2004-11-03 00:39:30 +0000
commit8d68eb6d5eaba2fc8fb4f04c7d7732f3b998ce48 (patch)
tree2b0614f93d64bb31743bef6243b7ad27336019f4
parent01530ac5c8ea6ba0cbdeb8eed6f5035ccfaa5bbb (diff)
downloadrockbox-8d68eb6d5eaba2fc8fb4f04c7d7732f3b998ce48.zip
rockbox-8d68eb6d5eaba2fc8fb4f04c7d7732f3b998ce48.tar.gz
rockbox-8d68eb6d5eaba2fc8fb4f04c7d7732f3b998ce48.tar.bz2
rockbox-8d68eb6d5eaba2fc8fb4f04c7d7732f3b998ce48.tar.xz
Ported to iRiver (unfinished)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5378 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/adc.c89
1 files changed, 88 insertions, 1 deletions
diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c
index 1865e8c..4b11c7d 100644
--- a/firmware/drivers/adc.c
+++ b/firmware/drivers/adc.c
@@ -17,11 +17,12 @@
*
****************************************************************************/
#include "config.h"
-#include "sh7034.h"
+#include "cpu.h"
#include "kernel.h"
#include "thread.h"
#include "adc.h"
+#if CONFIG_CPU == SH7034
/**************************************************************************
** The A/D conversion is done every tick, in three steps:
**
@@ -104,3 +105,89 @@ void adc_init(void)
sleep(2); /* Ensure valid readings when adc_init returns */
}
+#elif CONFIG_CPU == MCF5249
+
+static unsigned char adcdata[NUM_ADC_CHANNELS];
+
+#define CS_LO GPIO_OUT &= ~0x80
+#define CS_HI GPIO_OUT |= 0x80
+#define CLK_LO GPIO_OUT &= ~0x00400000
+#define CLK_HI GPIO_OUT |= 0x00400000
+#define DO (GPIO_READ & 0x80000000)
+#define DI_LO GPIO_OUT &= ~0x00200000
+#define DI_HI GPIO_OUT |= 0x00200000
+
+/* delay loop */
+#define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0)
+
+unsigned char adc_scan(int channel)
+{
+ unsigned char data = 0;
+ int i;
+
+ CS_LO;
+
+ DI_HI; /* Start bit */
+ DELAY;
+ CLK_HI;
+ DELAY;
+ CLK_LO;
+
+ DI_HI; /* Single channel */
+ DELAY;
+ CLK_HI;
+ DELAY;
+ CLK_LO;
+
+ if(channel & 1) /* LSB of channel number */
+ DI_HI;
+ else
+ DI_LO;
+ DELAY;
+ CLK_HI;
+ DELAY;
+ CLK_LO;
+
+ if(channel & 2) /* MSB of channel number */
+ DI_HI;
+ else
+ DI_LO;
+ DELAY;
+ CLK_HI;
+ DELAY;
+ CLK_LO;
+
+ DELAY;
+
+ for(i = 0;i < 8;i++) /* 8 bits of data */
+ {
+ CLK_HI;
+ DELAY;
+ CLK_LO;
+ DELAY;
+ data <<= 1;
+ data |= DO?1:0;
+ }
+
+ CS_HI;
+
+ return data;
+}
+
+unsigned short adc_read(int channel)
+{
+ return adcdata[channel];
+}
+
+void adc_init(void)
+{
+ GPIO_FUNCTION |= 0x80600080; /* GPIO7: CS
+ GPIO21: Data In (to the ADC)
+ GPIO22: CLK
+ GPIO31: Data Out (from the ADC) */
+ GPIO_ENABLE |= 0x00600080;
+ GPIO_OUT |= 0x80; /* CS high */
+ GPIO_OUT &= ~0x00400000; /* CLK low */
+}
+
+#endif