summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tcc780x/cowond2/button-cowond2.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/tcc780x/cowond2/button-cowond2.c')
-rw-r--r--firmware/target/arm/tcc780x/cowond2/button-cowond2.c29
1 files changed, 8 insertions, 21 deletions
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}