diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2005-11-16 13:28:10 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2005-11-16 13:28:10 +0000 |
commit | 91c4873253bd7350e3430c455a7f58df576553de (patch) | |
tree | 595a5c3483c70780c8b21b86cb94ab0628253e39 | |
parent | ffe0b23902ef8e92f60b7c15b53dfbb1f23fce8c (diff) | |
download | rockbox-91c4873253bd7350e3430c455a7f58df576553de.tar.gz rockbox-91c4873253bd7350e3430c455a7f58df576553de.zip |
H300: ADC driver
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7906 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/drivers/adc.c | 27 | ||||
-rw-r--r-- | firmware/export/adc.h | 10 | ||||
-rw-r--r-- | firmware/export/config-h300.h | 2 |
3 files changed, 28 insertions, 11 deletions
diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index c79c22ce0f..c9ae2daca8 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include "kernel.h" | 22 | #include "kernel.h" |
23 | #include "thread.h" | 23 | #include "thread.h" |
24 | #include "adc.h" | 24 | #include "adc.h" |
25 | #include "pcf50606.h" | ||
25 | 26 | ||
26 | #if CONFIG_CPU == SH7034 | 27 | #if CONFIG_CPU == SH7034 |
27 | /************************************************************************** | 28 | /************************************************************************** |
@@ -107,9 +108,29 @@ void adc_init(void) | |||
107 | sleep(2); /* Ensure valid readings when adc_init returns */ | 108 | sleep(2); /* Ensure valid readings when adc_init returns */ |
108 | } | 109 | } |
109 | #elif CONFIG_CPU == MCF5249 | 110 | #elif CONFIG_CPU == MCF5249 |
110 | |||
111 | static unsigned char adcdata[NUM_ADC_CHANNELS]; | 111 | static unsigned char adcdata[NUM_ADC_CHANNELS]; |
112 | 112 | ||
113 | #ifdef IRIVER_H300_SERIES | ||
114 | static int channelnum[] = | ||
115 | { | ||
116 | 5, /* ADC_BUTTONS */ | ||
117 | 6, /* ADC_REMOTE */ | ||
118 | 0, /* ADC_BATTERY */ | ||
119 | }; | ||
120 | |||
121 | unsigned char adc_scan(int channel) | ||
122 | { | ||
123 | unsigned char data; | ||
124 | |||
125 | pcf50606_write(0x2f, 0x80 | (channelnum[channel] << 1) | 1); | ||
126 | data = pcf50606_read(0x30); | ||
127 | |||
128 | adcdata[channel] = data; | ||
129 | |||
130 | return data; | ||
131 | } | ||
132 | #else | ||
133 | |||
113 | #define CS_LO and_l(~0x80, &GPIO_OUT) | 134 | #define CS_LO and_l(~0x80, &GPIO_OUT) |
114 | #define CS_HI or_l(0x80, &GPIO_OUT) | 135 | #define CS_HI or_l(0x80, &GPIO_OUT) |
115 | #define CLK_LO and_l(~0x00400000, &GPIO_OUT) | 136 | #define CLK_LO and_l(~0x00400000, &GPIO_OUT) |
@@ -176,6 +197,7 @@ unsigned char adc_scan(int channel) | |||
176 | 197 | ||
177 | return data; | 198 | return data; |
178 | } | 199 | } |
200 | #endif | ||
179 | 201 | ||
180 | unsigned short adc_read(int channel) | 202 | unsigned short adc_read(int channel) |
181 | { | 203 | { |
@@ -195,6 +217,8 @@ static void adc_tick(void) | |||
195 | 217 | ||
196 | void adc_init(void) | 218 | void adc_init(void) |
197 | { | 219 | { |
220 | #ifdef IRIVER_H300_SERIES | ||
221 | #else | ||
198 | or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS | 222 | or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS |
199 | GPIO21: Data In (to the ADC) | 223 | GPIO21: Data In (to the ADC) |
200 | GPIO22: CLK | 224 | GPIO22: CLK |
@@ -202,6 +226,7 @@ void adc_init(void) | |||
202 | or_l(0x00600080, &GPIO_ENABLE); | 226 | or_l(0x00600080, &GPIO_ENABLE); |
203 | or_l(0x80, &GPIO_OUT); /* CS high */ | 227 | or_l(0x80, &GPIO_OUT); /* CS high */ |
204 | and_l(~0x00400000, &GPIO_OUT); /* CLK low */ | 228 | and_l(~0x00400000, &GPIO_OUT); /* CLK low */ |
229 | #endif | ||
205 | 230 | ||
206 | adc_scan(ADC_BATTERY); | 231 | adc_scan(ADC_BATTERY); |
207 | 232 | ||
diff --git a/firmware/export/adc.h b/firmware/export/adc.h index 7a90afd9b5..a5ba583c38 100644 --- a/firmware/export/adc.h +++ b/firmware/export/adc.h | |||
@@ -21,7 +21,7 @@ | |||
21 | 21 | ||
22 | #include "config.h" | 22 | #include "config.h" |
23 | 23 | ||
24 | #ifdef IRIVER_H100_SERIES | 24 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) |
25 | #define NUM_ADC_CHANNELS 4 | 25 | #define NUM_ADC_CHANNELS 4 |
26 | 26 | ||
27 | #define ADC_BUTTONS 0 | 27 | #define ADC_BUTTONS 0 |
@@ -30,14 +30,6 @@ | |||
30 | #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ | 30 | #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ |
31 | 31 | ||
32 | #else | 32 | #else |
33 | #ifdef IRIVER_H300 | ||
34 | /* TODO: we don't have enough info about the ADC for the H3x0 for now, so this | ||
35 | stuff is only added here for now to make things compile. */ | ||
36 | #define ADC_BUTTONS -2 | ||
37 | #define ADC_REMOTE -3 | ||
38 | unsigned char adc_scan(int channel); | ||
39 | |||
40 | #endif | ||
41 | 33 | ||
42 | #define NUM_ADC_CHANNELS 8 | 34 | #define NUM_ADC_CHANNELS 8 |
43 | 35 | ||
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index 5343b657d9..a3d07a61bd 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h | |||
@@ -57,7 +57,7 @@ | |||
57 | /* Type of mobile power */ | 57 | /* Type of mobile power */ |
58 | #define CONFIG_BATTERY BATT_LIPOL1300 | 58 | #define CONFIG_BATTERY BATT_LIPOL1300 |
59 | 59 | ||
60 | #define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */ | 60 | #define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */ |
61 | 61 | ||
62 | /* Define this if the platform can charge batteries */ | 62 | /* Define this if the platform can charge batteries */ |
63 | #define HAVE_CHARGING 1 | 63 | #define HAVE_CHARGING 1 |