summaryrefslogtreecommitdiff
path: root/firmware/target/arm/iriver/h10/adc-h10.c
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/adc-h10.c
parentb249d9ac2d7ac6f418d427c9e7a40c3d3a7f5ad4 (diff)
downloadrockbox-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
Diffstat (limited to 'firmware/target/arm/iriver/h10/adc-h10.c')
-rwxr-xr-xfirmware/target/arm/iriver/h10/adc-h10.c73
1 files changed, 68 insertions, 5 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}