summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Purchase <shotofadds@rockbox.org>2009-10-08 15:47:43 +0000
committerRob Purchase <shotofadds@rockbox.org>2009-10-08 15:47:43 +0000
commit292a53da4b862dcb942b02eb47664efaf294d8c9 (patch)
tree613ea37b76ce89abb9235fa1587978177c708998
parent5a435e62d062c7bc75c27a324e89de06cc4543f9 (diff)
downloadrockbox-292a53da4b862dcb942b02eb47664efaf294d8c9.tar.gz
rockbox-292a53da4b862dcb942b02eb47664efaf294d8c9.zip
D2: Use a common function for reading ADC values from the PMU
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23007 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/pcf50606.c23
-rw-r--r--firmware/export/pcf50606.h2
-rw-r--r--firmware/export/pcf5060x.h17
-rw-r--r--firmware/target/arm/tcc780x/cowond2/button-cowond2.c29
-rw-r--r--firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c14
5 files changed, 54 insertions, 31 deletions
diff --git a/firmware/drivers/pcf50606.c b/firmware/drivers/pcf50606.c
index 6a98b0d021..8592c005fe 100644
--- a/firmware/drivers/pcf50606.c
+++ b/firmware/drivers/pcf50606.c
@@ -62,3 +62,26 @@ void pcf50606_reset_timeout(void)
62 pcf50606_write(PCF5060X_OOCC1, pcf50606_read(PCF5060X_OOCC1) | TOTRST); 62 pcf50606_write(PCF5060X_OOCC1, pcf50606_read(PCF5060X_OOCC1) | TOTRST);
63 restore_irq(level); 63 restore_irq(level);
64} 64}
65
66void pcf50606_read_adc(int adc, short* res1, short* res2)
67{
68 int adcs1 = 0, adcs2 = 0, adcs3 = 0;
69
70 int level = disable_irq_save();
71
72 pcf50606_write(PCF5060X_ADCC2, (adc<<1) | 1); /* ADC start */
73
74 do {
75 adcs2 = pcf50606_read(PCF5060X_ADCS2);
76 } while (!(adcs2 & 0x80)); /* Busy wait on ADCRDY flag */
77
78 adcs1 = pcf50606_read(PCF5060X_ADCS1);
79 if (res2 != NULL) adcs3 = pcf50606_read(PCF5060X_ADCS3);
80
81 pcf50606_write(PCF5060X_ADCC2, 0); /* ADC stop */
82
83 restore_interrupt(level);
84
85 if (res1 != NULL) *res1 = (adcs1 << 2) | (adcs2 & 3);
86 if (res2 != NULL) *res2 = (adcs3 << 2) | ((adcs2 & 0xC) >> 2);
87}
diff --git a/firmware/export/pcf50606.h b/firmware/export/pcf50606.h
index 8e01346028..4ae3d83f97 100644
--- a/firmware/export/pcf50606.h
+++ b/firmware/export/pcf50606.h
@@ -52,4 +52,6 @@ unsigned char pcf50606_i2c_inb(bool ack);
52void pcf50606_reset_timeout(void); 52void pcf50606_reset_timeout(void);
53#endif 53#endif
54 54
55void pcf50606_read_adc(int adc, short* res1, short* res2);
56
55#endif /* PCF50606_H */ 57#endif /* PCF50606_H */
diff --git a/firmware/export/pcf5060x.h b/firmware/export/pcf5060x.h
index 0a8927bab4..e2af9d7122 100644
--- a/firmware/export/pcf5060x.h
+++ b/firmware/export/pcf5060x.h
@@ -92,4 +92,21 @@
92#define PCF5060X_GPOC4 0x3b 92#define PCF5060X_GPOC4 0x3b
93#define PCF5060X_GPOC5 0x3c 93#define PCF5060X_GPOC5 0x3c
94 94
95/* ADCC2 mux values */
96#define PCF5060X_ADC_BATVOLT_RES 0x0
97#define PCF5060X_ADC_BATVOLT_SUBTR 0x1
98#define PCF5060X_ADC_ADCIN1_RES 0x2
99#define PCF5060X_ADC_ADCIN1_SUBTR 0x3
100#define PCF5060X_ADC_BATTEMP 0x4
101#define PCF5060X_ADC_ADCIN2 0x5
102#define PCF5060X_ADC_ADCIN3 0x6
103#define PCF5060X_ADC_ADCIN3_RATIO 0x7
104#define PCF5060X_ADC_TSC_X 0x8
105#define PCF5060X_ADC_TSC_Y 0x9
106#define PCF5060X_ADC_TSC_P1 0xa
107#define PCF5060X_ADC_TSC_P2 0xb
108#define PCF5060X_ADC_BATVOLT_ADCIN1 0xc
109#define PCF5060X_ADC_TSC_XY 0xe
110#define PCF5060X_ADC_TSC_P1P2 0xf
111
95#endif /* PCF5060X_H */ 112#endif /* PCF5060X_H */
diff --git a/firmware/target/arm/tcc780x/cowond2/button-cowond2.c b/firmware/target/arm/tcc780x/cowond2/button-cowond2.c
index e66ba2332a..0f9a9b3d75 100644
--- a/firmware/target/arm/tcc780x/cowond2/button-cowond2.c
+++ b/firmware/target/arm/tcc780x/cowond2/button-cowond2.c
@@ -41,35 +41,22 @@ static int short_cmp(const void *a, const void *b)
41 41
42void button_read_touch() 42void button_read_touch()
43{ 43{
44 unsigned char buf[3];
45
46 static long last_touch_interrupt = 0; 44 static long last_touch_interrupt = 0;
47 static int touch_data_index = 0; 45 static int touch_data_index = 0;
48 46
49 /* put the touchscreen into idle mode */ 47 /* put the touchscreen into idle mode */
50 pcf50606_write(PCF5060X_ADCC1, 0); 48 pcf50606_write(PCF5060X_ADCC1, 0);
51 49
52 /* here the touch coordinates are read 5 times */
53 /* they will be sorted and the middle one will be used */
54 pcf50606_write(PCF5060X_ADCC2, (0xE<<1) | 1); /* ADC start X+Y */
55
56 do {
57 buf[1] = pcf50606_read(PCF5060X_ADCS2);
58 } while (!(buf[1] & 0x80)); /* Busy wait on ADCRDY flag */
59
60 buf[0] = pcf50606_read(PCF5060X_ADCS1);
61 buf[2] = pcf50606_read(PCF5060X_ADCS3);
62
63 pcf50606_write(PCF5060X_ADCC2, 0); /* ADC stop */
64
65 if (TIME_AFTER(current_tick, last_touch_interrupt + 1)) 50 if (TIME_AFTER(current_tick, last_touch_interrupt + 1))
66 { 51 {
67 /* resets the index if the last touch could not be read 5 times */ 52 /* resets the index if the last touch could not be read 5 times */
68 touch_data_index = 0; 53 touch_data_index = 0;
69 } 54 }
70 55
71 x[touch_data_index] = (buf[0] << 2) | (buf[1] & 3); 56 /* here the touch coordinates are read 5 times */
72 y[touch_data_index] = (buf[2] << 2) | ((buf[1] & 0xC) >> 2); 57 /* they will be sorted and the middle one will be used */
58 pcf50606_read_adc(PCF5060X_ADC_TSC_XY,
59 &x[touch_data_index], &y[touch_data_index]);
73 60
74 touch_data_index++; 61 touch_data_index++;
75 62
@@ -126,7 +113,7 @@ void button_init_device(void)
126{ 113{
127 /* Configure GPIOA 4 (POWER) and 8 (HOLD) for input */ 114 /* Configure GPIOA 4 (POWER) and 8 (HOLD) for input */
128 GPIOA_DIR &= ~0x110; 115 GPIOA_DIR &= ~0x110;
129 116
130 /* Configure GPIOB 4 (button pressed) for input */ 117 /* Configure GPIOB 4 (button pressed) for input */
131 GPIOB_DIR &= ~0x10; 118 GPIOB_DIR &= ~0x10;
132 119
@@ -229,12 +216,12 @@ int button_read_device(int *data)
229 touch_hold = false; 216 touch_hold = false;
230 pcf50606_write(PCF5060X_ADCC1, 1); 217 pcf50606_write(PCF5060X_ADCC1, 1);
231 } 218 }
232 219
233 if (!(GPIOA & 0x4)) 220 if (!(GPIOA & 0x4))
234 btn |= BUTTON_POWER; 221 btn |= BUTTON_POWER;
235 222
236 if (btn & BUTTON_TOUCHSCREEN && !is_backlight_on(true)) 223 if (btn & BUTTON_TOUCHSCREEN && !is_backlight_on(true))
237 old_data = *data = 0; 224 old_data = *data = 0;
238 225
239 return btn; 226 return btn;
240} 227}
diff --git a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c
index 683c1c3be7..b52d5c46ba 100644
--- a/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c
+++ b/firmware/target/arm/tcc780x/cowond2/powermgmt-cowond2.c
@@ -26,7 +26,7 @@
26#include "pcf50606.h" 26#include "pcf50606.h"
27 27
28unsigned short current_voltage = 3910; 28unsigned short current_voltage = 3910;
29 29
30const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = 30const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
31{ 31{
32 3380 32 3380
@@ -42,7 +42,7 @@ const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
42{ 42{
43 /* Standard D2 internal battery */ 43 /* Standard D2 internal battery */
44 { 3370, 3690, 3750, 3775, 3790, 3820, 3880, 3940, 3980, 4090, 4170 } 44 { 3370, 3690, 3750, 3775, 3790, 3820, 3880, 3940, 3980, 4090, 4170 }
45 45
46 /* TODO: DIY replacements eg. Nokia BP-4L ? */ 46 /* TODO: DIY replacements eg. Nokia BP-4L ? */
47}; 47};
48 48
@@ -65,15 +65,9 @@ unsigned int battery_adc_voltage(void)
65 65
66 if (TIME_BEFORE(last_tick+HZ, current_tick)) 66 if (TIME_BEFORE(last_tick+HZ, current_tick))
67 { 67 {
68 int adc_val, irq_status; 68 short adc_val;
69 unsigned char buf[2]; 69 pcf50606_read_adc(PCF5060X_ADC_BATVOLT_RES, &adc_val, NULL);
70
71 irq_status = disable_irq_save();
72 pcf50606_write(PCF5060X_ADCC2, 0x1);
73 pcf50606_read_multiple(PCF5060X_ADCS1, buf, 2);
74 restore_interrupt(irq_status);
75 70
76 adc_val = (buf[0]<<2) | (buf[1] & 3); //ADCDAT1H+ADCDAT1L
77 current_voltage = (adc_val * BATTERY_SCALE_FACTOR) >> 10; 71 current_voltage = (adc_val * BATTERY_SCALE_FACTOR) >> 10;
78 72
79 last_tick = current_tick; 73 last_tick = current_tick;