diff options
author | Barry Wardell <rockbox@barrywardell.net> | 2006-08-22 20:17:09 +0000 |
---|---|---|
committer | Barry Wardell <rockbox@barrywardell.net> | 2006-08-22 20:17:09 +0000 |
commit | e367b05fca08891b0ae47eab8b4a098253122633 (patch) | |
tree | 679c959e59b6646007e835662b1737d679cb8764 | |
parent | b249d9ac2d7ac6f418d427c9e7a40c3d3a7f5ad4 (diff) | |
download | rockbox-e367b05fca08891b0ae47eab8b4a098253122633.tar.gz 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
-rw-r--r-- | docs/CREDITS | 1 | ||||
-rw-r--r-- | firmware/drivers/adc.c | 2 | ||||
-rw-r--r-- | firmware/export/adc.h | 11 | ||||
-rwxr-xr-x | firmware/target/arm/iriver/h10/adc-h10.c | 73 | ||||
-rw-r--r-- | firmware/target/arm/iriver/h10/adc-target.h | 42 | ||||
-rw-r--r-- | firmware/target/arm/iriver/h10/button-h10.c | 2 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/x5/adc-target.h | 32 |
7 files changed, 148 insertions, 15 deletions
diff --git a/docs/CREDITS b/docs/CREDITS index abde8a1b7f..08b4f0d7ef 100644 --- a/docs/CREDITS +++ b/docs/CREDITS | |||
@@ -226,3 +226,4 @@ Philippe Miossec | |||
226 | Jochen Kemnade | 226 | Jochen Kemnade |
227 | Corry Lazarowitz | 227 | Corry Lazarowitz |
228 | Tom Meyer | 228 | Tom Meyer |
229 | Laurent Baum | ||
diff --git a/firmware/drivers/adc.c b/firmware/drivers/adc.c index 436c71105a..1ebac066e7 100644 --- a/firmware/drivers/adc.c +++ b/firmware/drivers/adc.c | |||
@@ -283,7 +283,7 @@ void adc_init(void) | |||
283 | sleep(2); /* Ensure valid readings when adc_init returns */ | 283 | sleep(2); /* Ensure valid readings when adc_init returns */ |
284 | } | 284 | } |
285 | 285 | ||
286 | #elif (CONFIG_CPU == PP5020) || (CONFIG_CPU == PP5002) | 286 | #elif defined(IPOD_ARCH) |
287 | 287 | ||
288 | struct adc_struct { | 288 | struct adc_struct { |
289 | long timeout; | 289 | long timeout; |
diff --git a/firmware/export/adc.h b/firmware/export/adc.h index 2f14e3cf48..3a438832d6 100644 --- a/firmware/export/adc.h +++ b/firmware/export/adc.h | |||
@@ -21,13 +21,8 @@ | |||
21 | 21 | ||
22 | #include "config.h" | 22 | #include "config.h" |
23 | 23 | ||
24 | #ifdef IAUDIO_X5 | 24 | #ifdef TARGET_TREE |
25 | #define NUM_ADC_CHANNELS 3 | 25 | #include "adc-target.h" |
26 | |||
27 | #define ADC_BUTTONS 0 | ||
28 | #define ADC_REMOTE 1 | ||
29 | #define ADC_BATTERY 2 | ||
30 | #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ | ||
31 | 26 | ||
32 | #elif defined(IPOD_ARCH) | 27 | #elif defined(IPOD_ARCH) |
33 | #define NUM_ADC_CHANNELS 1 | 28 | #define NUM_ADC_CHANNELS 1 |
@@ -112,7 +107,7 @@ unsigned short adc_read(int channel); | |||
112 | void adc_init(void); | 107 | void adc_init(void); |
113 | 108 | ||
114 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)\ | 109 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)\ |
115 | || defined(IAUDIO_X5) || defined(IPOD_ARCH) | 110 | || defined(IPOD_ARCH) |
116 | /* Force a scan now */ | 111 | /* Force a scan now */ |
117 | unsigned short adc_scan(int channel); | 112 | unsigned short adc_scan(int channel); |
118 | #endif | 113 | #endif |
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 @@ | |||
23 | #include "thread.h" | 23 | #include "thread.h" |
24 | #include "adc.h" | 24 | #include "adc.h" |
25 | 25 | ||
26 | /* TODO: implement adc functionality */ | 26 | static unsigned short adcdata[NUM_ADC_CHANNELS]; |
27 | |||
28 | /* Scan ADC so that adcdata[channel] gets updated */ | ||
27 | unsigned short adc_scan(int channel) | 29 | unsigned short adc_scan(int channel) |
28 | { | 30 | { |
29 | (void)channel; | 31 | unsigned int adc_data_1; |
30 | return 0; | 32 | unsigned int adc_data_2; |
33 | |||
34 | /* Initialise */ | ||
35 | ADC_ADDR=0x130; | ||
36 | ADC_STATUS=0; /* 4 bytes, 1 per channel. Each byte is 0 if the channel is | ||
37 | off, 0x40 if the channel is on */ | ||
38 | |||
39 | /* Enable Channel */ | ||
40 | ADC_ADDR |= (0x1000000<<channel); | ||
41 | |||
42 | /* Start? */ | ||
43 | ADC_ADDR |= 0x20000000; | ||
44 | ADC_ADDR |= 0x80000000; | ||
45 | |||
46 | /* Wait 50ms for things to settle */ | ||
47 | sleep(HZ/20); | ||
48 | |||
49 | /* ADC_DATA_1 and ADC_DATA_2 are both four bytes, one byte per channel. | ||
50 | For each channel, ADC_DATA_1 stores the 8-bit msb, ADC_DATA_2 stores the | ||
51 | 2-bit lsb (in bits 0 and 1). Each channel is 10 bits total. */ | ||
52 | adc_data_1 = ((ADC_DATA_1 >> (8*channel)) & 0xff); | ||
53 | adc_data_2 = ((ADC_DATA_2 >> (8*channel+6)) & 0x3); | ||
54 | |||
55 | adcdata[channel] = (adc_data_1<<2 | adc_data_2); | ||
56 | |||
57 | return adcdata[channel]; | ||
31 | } | 58 | } |
32 | 59 | ||
60 | /* Read 10-bit channel data */ | ||
33 | unsigned short adc_read(int channel) | 61 | unsigned short adc_read(int channel) |
34 | { | 62 | { |
35 | (void)channel; | 63 | return adcdata[channel]; |
36 | return 0; | 64 | } |
65 | |||
66 | static int adc_counter; | ||
67 | |||
68 | static void adc_tick(void) | ||
69 | { | ||
70 | if(++adc_counter == HZ) | ||
71 | { | ||
72 | adc_counter = 0; | ||
73 | adc_scan(ADC_BATTERY); | ||
74 | adc_scan(ADC_UNKNOWN_1); | ||
75 | adc_scan(ADC_UNKNOWN_2); | ||
76 | adc_scan(ADC_SCROLLPAD); | ||
77 | } | ||
37 | } | 78 | } |
38 | 79 | ||
39 | void adc_init(void) | 80 | void adc_init(void) |
40 | { | 81 | { |
82 | /* Enable ADC */ | ||
83 | ADC_ENABLE_ADDR |= ADC_ENABLE; | ||
84 | |||
85 | /* Initialise */ | ||
86 | ADC_INIT=0; | ||
87 | ADC_ADDR=0x130; | ||
88 | ADC_STATUS=0; | ||
89 | |||
90 | /* Enable Channels 1-4 */ | ||
91 | ADC_ADDR |= 0x1000000; | ||
92 | ADC_ADDR |= 0x2000000; | ||
93 | ADC_ADDR |= 0x4000000; | ||
94 | ADC_ADDR |= 0x8000000; | ||
95 | |||
96 | /* Start? */ | ||
97 | ADC_ADDR |= 0x20000000; | ||
98 | ADC_ADDR |= 0x80000000; | ||
99 | |||
100 | /* Wait 50ms for things to settle */ | ||
101 | sleep(HZ/20); | ||
102 | |||
103 | tick_add_task(adc_tick); | ||
41 | } | 104 | } |
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006 by Barry Wardell | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef _ADC_TARGET_H_ | ||
20 | #define _ADC_TARGET_H_ | ||
21 | |||
22 | #define ADC_ENABLE_ADDR (*(volatile unsigned long*)(0x70000010)) | ||
23 | #define ADC_ENABLE 0x1100 | ||
24 | |||
25 | #define ADC_ADDR (*(volatile unsigned long*)(0x7000ad00)) | ||
26 | #define ADC_STATUS (*(volatile unsigned long*)(0x7000ad04)) | ||
27 | #define ADC_DATA_1 (*(volatile unsigned long*)(0x7000ad20)) | ||
28 | #define ADC_DATA_2 (*(volatile unsigned long*)(0x7000ad24)) | ||
29 | #define ADC_INIT (*(volatile unsigned long*)(0x7000ad2c)) | ||
30 | |||
31 | #define NUM_ADC_CHANNELS 4 | ||
32 | |||
33 | #define ADC_BATTERY 0 | ||
34 | #define ADC_UNKNOWN_1 1 | ||
35 | #define ADC_UNKNOWN_2 2 | ||
36 | #define ADC_SCROLLPAD 3 | ||
37 | #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ | ||
38 | |||
39 | /* Force a scan now */ | ||
40 | unsigned short adc_scan(int channel); | ||
41 | |||
42 | #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) | |||
70 | if ((state & 0x80) == 0) btn |= BUTTON_LEFT; | 70 | if ((state & 0x80) == 0) btn |= BUTTON_LEFT; |
71 | 71 | ||
72 | /* Read power button */ | 72 | /* Read power button */ |
73 | if ((GPIOB_INPUT_VAL & 0x1) == 0) btn |= BUTTON_POWER; | 73 | if ((GPIOB_INPUT_VAL & 0x1) == 1) btn |= BUTTON_POWER; |
74 | 74 | ||
75 | /* Read scroller */ | 75 | /* Read scroller */ |
76 | if ( ((GPIOC_INPUT_VAL & 0x4)==1) && ((GPIOD_INPUT_VAL & 0x10)==1) ) | 76 | if ( ((GPIOC_INPUT_VAL & 0x4)==1) && ((GPIOD_INPUT_VAL & 0x10)==1) ) |
diff --git a/firmware/target/coldfire/iaudio/x5/adc-target.h b/firmware/target/coldfire/iaudio/x5/adc-target.h new file mode 100644 index 0000000000..5d158056b9 --- /dev/null +++ b/firmware/target/coldfire/iaudio/x5/adc-target.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #ifndef _ADC_TARGET_H_ | ||
20 | #define _ADC_TARGET_H_ | ||
21 | |||
22 | #define NUM_ADC_CHANNELS 3 | ||
23 | |||
24 | #define ADC_BUTTONS 0 | ||
25 | #define ADC_REMOTE 1 | ||
26 | #define ADC_BATTERY 2 | ||
27 | #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ | ||
28 | |||
29 | /* Force a scan now */ | ||
30 | unsigned short adc_scan(int channel); | ||
31 | |||
32 | #endif | ||