summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-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
-rw-r--r--firmware/target/coldfire/iaudio/x5/adc-target.h32
4 files changed, 143 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 @@
23#include "thread.h" 23#include "thread.h"
24#include "adc.h" 24#include "adc.h"
25 25
26/* TODO: implement adc functionality */ 26static unsigned short adcdata[NUM_ADC_CHANNELS];
27
28/* Scan ADC so that adcdata[channel] gets updated */
27unsigned short adc_scan(int channel) 29unsigned 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 */
33unsigned short adc_read(int channel) 61unsigned short adc_read(int channel)
34{ 62{
35 (void)channel; 63 return adcdata[channel];
36 return 0; 64}
65
66static int adc_counter;
67
68static 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
39void adc_init(void) 80void 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 */
40unsigned 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 */
30unsigned short adc_scan(int channel);
31
32#endif