summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s3c2440/mini2440
diff options
context:
space:
mode:
authorDominik Wenger <domonoky@googlemail.com>2009-10-27 20:25:40 +0000
committerDominik Wenger <domonoky@googlemail.com>2009-10-27 20:25:40 +0000
commit04ebf48fe4cb7bdd4d125e9e5f2507d03ede6a5b (patch)
tree0b3b501a59d9a774019d277b0947ee4194de0af4 /firmware/target/arm/s3c2440/mini2440
parent6f9724706f4df78a91f3bf9a10b50be109aac996 (diff)
downloadrockbox-04ebf48fe4cb7bdd4d125e9e5f2507d03ede6a5b.tar.gz
rockbox-04ebf48fe4cb7bdd4d125e9e5f2507d03ede6a5b.zip
Initial touchscreen support for mini2440. Based on D2 touchscreen driver
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23370 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/s3c2440/mini2440')
-rw-r--r--firmware/target/arm/s3c2440/mini2440/adc-target.h6
-rw-r--r--firmware/target/arm/s3c2440/mini2440/button-mini2440.c11
-rw-r--r--firmware/target/arm/s3c2440/mini2440/button-target.h16
-rw-r--r--firmware/target/arm/s3c2440/mini2440/touchscreen-mini2440.c190
-rw-r--r--firmware/target/arm/s3c2440/mini2440/touchscreen-target.h33
5 files changed, 249 insertions, 7 deletions
diff --git a/firmware/target/arm/s3c2440/mini2440/adc-target.h b/firmware/target/arm/s3c2440/mini2440/adc-target.h
index 24e878e735..5abf0d06c5 100644
--- a/firmware/target/arm/s3c2440/mini2440/adc-target.h
+++ b/firmware/target/arm/s3c2440/mini2440/adc-target.h
@@ -26,16 +26,12 @@
26 Channels 4-7 are routed to LCD connector for touchscreen operation if 26 Channels 4-7 are routed to LCD connector for touchscreen operation if
27 supported by display panel. 27 supported by display panel.
28*/ 28*/
29#define NUM_ADC_CHANNELS 8 29#define NUM_ADC_CHANNELS 4
30 30
31#define ADC_ONBOARD 0 31#define ADC_ONBOARD 0
32#define ADC_SPARE_1 1 32#define ADC_SPARE_1 1
33#define ADC_SPARE_2 2 33#define ADC_SPARE_2 2
34#define ADC_SPARE_3 3 34#define ADC_SPARE_3 3
35#define ADC_TSYM 4
36#define ADC_TSYP 5
37#define ADC_TSXM 6
38#define ADC_TSXP 7
39 35
40#define ADC_READ_ERROR 0xFFFF 36#define ADC_READ_ERROR 0xFFFF
41 37
diff --git a/firmware/target/arm/s3c2440/mini2440/button-mini2440.c b/firmware/target/arm/s3c2440/mini2440/button-mini2440.c
index 787c04d1ef..0435f47559 100644
--- a/firmware/target/arm/s3c2440/mini2440/button-mini2440.c
+++ b/firmware/target/arm/s3c2440/mini2440/button-mini2440.c
@@ -24,6 +24,7 @@
24#include "system.h" 24#include "system.h"
25#include "button.h" 25#include "button.h"
26#include "kernel.h" 26#include "kernel.h"
27#include "touchscreen-target.h"
27 28
28void button_init_device(void) 29void button_init_device(void)
29{ 30{
@@ -50,6 +51,8 @@ void button_init_device(void)
50 S3C2440_GPIO_PULLUP (GPGUP, 9, GPIO_PULLUP_ENABLE); 51 S3C2440_GPIO_PULLUP (GPGUP, 9, GPIO_PULLUP_ENABLE);
51 S3C2440_GPIO_PULLUP (GPGUP, 10, GPIO_PULLUP_ENABLE); 52 S3C2440_GPIO_PULLUP (GPGUP, 10, GPIO_PULLUP_ENABLE);
52 53
54 /* init touchscreen */
55 touchscreen_init_device();
53} 56}
54 57
55inline bool button_hold(void) 58inline bool button_hold(void)
@@ -57,12 +60,18 @@ inline bool button_hold(void)
57 return 0; 60 return 0;
58} 61}
59 62
60int button_read_device(void) 63int button_read_device(int* data)
61{ 64{
62 int btn = BUTTON_NONE; 65 int btn = BUTTON_NONE;
66 static int old_data = 0;
67
68 *data = old_data;
63 69
64 /* Read the buttons - active low */ 70 /* Read the buttons - active low */
65 btn = (GPGDAT & BUTTON_MAIN) ^ BUTTON_MAIN; 71 btn = (GPGDAT & BUTTON_MAIN) ^ BUTTON_MAIN;
72
73 /* read touchscreen */
74 btn |= touchscreen_read_device(data, &old_data);
66 75
67 return btn; 76 return btn;
68} 77}
diff --git a/firmware/target/arm/s3c2440/mini2440/button-target.h b/firmware/target/arm/s3c2440/mini2440/button-target.h
index 4a84014462..66419b464a 100644
--- a/firmware/target/arm/s3c2440/mini2440/button-target.h
+++ b/firmware/target/arm/s3c2440/mini2440/button-target.h
@@ -27,7 +27,7 @@
27 27
28bool button_hold(void); 28bool button_hold(void);
29void button_init_device(void); 29void button_init_device(void);
30int button_read_device(void); 30int button_read_device(int*);
31void touchpad_set_sensitivity(int level); 31void touchpad_set_sensitivity(int level);
32 32
33/* Mini2440 specific button codes */ 33/* Mini2440 specific button codes */
@@ -43,6 +43,20 @@ void touchpad_set_sensitivity(int level);
43#define BUTTON_SEVEN 0x0200 43#define BUTTON_SEVEN 0x0200
44#define BUTTON_EIGHT 0x0400 44#define BUTTON_EIGHT 0x0400
45 45
46/* Touch Screen Area Buttons */
47#define BUTTON_TOPLEFT 0x010000
48#define BUTTON_TOPMIDDLE 0x020000
49#define BUTTON_TOPRIGHT 0x040000
50#define BUTTON_MIDLEFT 0x080000
51#define BUTTON_CENTER 0x100000
52#define BUTTON_MIDRIGHT 0x200000
53#define BUTTON_BOTTOMLEFT 0x400000
54#define BUTTON_BOTTOMMIDDLE 0x800000
55#define BUTTON_BOTTOMRIGHT 0x100000
56
57#define BUTTON_TOUCH 0x200000
58
59
46#define BUTTON_MENU BUTTON_ONE 60#define BUTTON_MENU BUTTON_ONE
47#define BUTTON_UP BUTTON_TWO 61#define BUTTON_UP BUTTON_TWO
48#define BUTTON_SELECT BUTTON_THREE 62#define BUTTON_SELECT BUTTON_THREE
diff --git a/firmware/target/arm/s3c2440/mini2440/touchscreen-mini2440.c b/firmware/target/arm/s3c2440/mini2440/touchscreen-mini2440.c
new file mode 100644
index 0000000000..ce7c8d5dd7
--- /dev/null
+++ b/firmware/target/arm/s3c2440/mini2440/touchscreen-mini2440.c
@@ -0,0 +1,190 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___void
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Rob Purchase
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "touchscreen-target.h"
24#include "adc-target.h"
25#include "system.h"
26#include "stdlib.h"
27#include "button.h"
28#include "touchscreen.h"
29
30#define NO_OF_TOUCH_DATA 5
31
32struct touch_calibration_point {
33 short px_x; /* known pixel value */
34 short px_y;
35 short val_x; /* touchscreen value at the known pixel */
36 short val_y;
37};
38
39static struct touch_calibration_point topleft, bottomright;
40
41static bool touch_available = false;
42
43static short x[NO_OF_TOUCH_DATA], y[NO_OF_TOUCH_DATA];
44
45/* comparator for qsort */
46static int short_cmp(const void *a, const void *b)
47{
48 return *(short*)a - *(short*)b;
49}
50
51static int touch_to_pixels(short val_x, short val_y)
52{
53 short x,y;
54
55 x=val_x;
56 y=val_y;
57
58 x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x)
59 / (bottomright.val_x - topleft.val_x) + topleft.px_x;
60
61 y = (y-topleft.val_y)*(bottomright.px_y - topleft.px_y)
62 / (bottomright.val_y - topleft.val_y) + topleft.px_y;
63
64 if (x < 0)
65 x = 0;
66 else if (x>=LCD_WIDTH)
67 x=LCD_WIDTH-1;
68
69 if (y < 0)
70 y = 0;
71 else if (y>=LCD_HEIGHT)
72 y=LCD_HEIGHT-1;
73
74 return (x<<16)|y;
75}
76
77void touchscreen_init_device()
78{
79 /* set touchscreen adc controller into wait for interrupt mode */
80 ADCTSC = 0xd3; /* Wfait,XP-PU,XP_DIS,XM_DIS,YP_dis,YM_end */
81
82 /* Arbitrary touchscreen calibration */
83 topleft.px_x = 0;
84 topleft.px_y = 0;
85 topleft.val_x = 105;
86 topleft.val_y = 925;
87
88 bottomright.px_x = LCD_WIDTH;
89 bottomright.px_y = LCD_HEIGHT;
90 bottomright.val_x = 890;
91 bottomright.val_y = 105;
92
93 touch_available = false;
94}
95
96void touchscreen_scan_device()
97{
98 static long last_touch_read = 0;
99 static int touch_data_index = 0;
100
101 int saveADCDLY;
102
103 /* check touch state */
104 if(ADCDAT1 & (1<<15))
105 {
106 return;
107 }
108
109 if (TIME_AFTER(current_tick, last_touch_read + 1))
110 {
111 /* resets the index if the last touch could not be read 5 times */
112 touch_data_index = 0;
113 }
114
115 /* read touch data */
116 saveADCDLY = ADCDLY;
117 ADCDLY = 40000; /*delay ~0.8ms (1/50M)*4000 */
118 ADCTSC = (1<<3)|(1<<2); /* pullup disable, seq x,y pos measure */
119 /* start adc */
120 ADCCON|= 0x1;
121 /* wait for start and end */
122 while(ADCCON & 0x1);
123 while(!(ADCCON & 0x8000));
124
125 x[touch_data_index] = ADCDAT0&0x3ff;
126 y[touch_data_index] = ADCDAT1&0x3ff;
127
128 ADCTSC = 0xd3; /* back to interrupt mode */
129 ADCDLY = saveADCDLY;
130
131 touch_data_index++;
132
133 if (touch_data_index > NO_OF_TOUCH_DATA - 1)
134 {
135 /* coordinates 5 times read */
136 touch_available = true;
137 touch_data_index = 0;
138 }
139 last_touch_read = current_tick;
140}
141
142int touchscreen_read_device(int *data, int *old_data)
143{
144 int btn = BUTTON_NONE;
145 static bool touch_hold = false;
146 static long last_touch = 0;
147
148 if (touch_available || touch_hold)
149 {
150 short x_touch, y_touch;
151 static short last_x = 0, last_y = 0;
152
153 if (touch_hold)
154 {
155 /* get rid of very fast unintended double touches */
156 x_touch = last_x;
157 y_touch = last_y;
158 }
159 else
160 {
161 /* sort the 5 data taken and use the median value */
162 qsort(x, NO_OF_TOUCH_DATA, sizeof(short), short_cmp);
163 qsort(y, NO_OF_TOUCH_DATA, sizeof(short), short_cmp);
164
165 x_touch = last_x = x[(NO_OF_TOUCH_DATA - 1)/2];
166 y_touch = last_y = y[(NO_OF_TOUCH_DATA - 1)/2];
167
168 last_touch = current_tick;
169
170 touch_hold = true;
171 touch_available = false;
172 }
173
174 *old_data = *data = touch_to_pixels(x_touch, y_touch);
175
176 btn |= touchscreen_to_pixels((*data&0xffff0000) >> 16,
177 (*data&0x0000ffff),
178 data);
179 }
180
181 if (TIME_AFTER(current_tick, last_touch + 10))
182 {
183 /* put the touchscreen back into interrupt mode */
184 touch_hold = false;
185 }
186
187 return btn;
188}
189
190
diff --git a/firmware/target/arm/s3c2440/mini2440/touchscreen-target.h b/firmware/target/arm/s3c2440/mini2440/touchscreen-target.h
new file mode 100644
index 0000000000..1019a98330
--- /dev/null
+++ b/firmware/target/arm/s3c2440/mini2440/touchscreen-target.h
@@ -0,0 +1,33 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Dominik Wenger
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _TOUCHSCREEN_TARGET_H
23#define _TOUCHSCREEN_TARGET_H
24
25/* try to get a touchscreen reading from adc */
26void touchscreen_scan_device(void);
27/* init touchscreen driver */
28void touchscreen_init_device(void);
29
30int touchscreen_read_device(int *data, int *old_data);
31
32#endif
33