diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c')
-rw-r--r-- | firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c | 77 |
1 files changed, 20 insertions, 57 deletions
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c index 2daae7e5d5..09ff6cbd78 100644 --- a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c +++ b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c | |||
@@ -35,7 +35,10 @@ | |||
35 | #include "touchscreen.h" | 35 | #include "touchscreen.h" |
36 | 36 | ||
37 | static bool touch_available = false; | 37 | static bool touch_available = false; |
38 | static bool hold_button = false; | 38 | static bool hold_button = false; |
39 | |||
40 | static short touch_x, touch_y, touch_z1, touch_z2; | ||
41 | static long last_touch = 0; | ||
39 | 42 | ||
40 | static struct touch_calibration_point topleft, bottomright; | 43 | static struct touch_calibration_point topleft, bottomright; |
41 | 44 | ||
@@ -49,16 +52,16 @@ static struct touch_calibration_point topleft, bottomright; | |||
49 | * (640,480) = 3880, 3900 | 52 | * (640,480) = 3880, 3900 |
50 | */ | 53 | */ |
51 | 54 | ||
52 | static int touch_to_pixels(short val_x, short val_y) | 55 | static int touch_to_pixels(short *val_x, short *val_y) |
53 | { | 56 | { |
54 | short x,y; | 57 | short x,y; |
55 | 58 | ||
56 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT | 59 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT |
57 | x=val_x; | 60 | x=*val_x; |
58 | y=val_y; | 61 | y=*val_y; |
59 | #else | 62 | #else |
60 | x=val_y; | 63 | x=*val_y; |
61 | y=val_x; | 64 | y=*val_x; |
62 | #endif | 65 | #endif |
63 | 66 | ||
64 | x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x; | 67 | x = (x-topleft.val_x)*(bottomright.px_x - topleft.px_x) / (bottomright.val_x - topleft.val_x) + topleft.px_x; |
@@ -74,6 +77,8 @@ static int touch_to_pixels(short val_x, short val_y) | |||
74 | else if (y>=LCD_HEIGHT) | 77 | else if (y>=LCD_HEIGHT) |
75 | y=LCD_HEIGHT-1; | 78 | y=LCD_HEIGHT-1; |
76 | 79 | ||
80 | *val_x=x; | ||
81 | *val_y=y; | ||
77 | 82 | ||
78 | return (x<<16)|y; | 83 | return (x<<16)|y; |
79 | } | 84 | } |
@@ -103,18 +108,6 @@ void button_init_device(void) | |||
103 | 108 | ||
104 | bottomright.px_x = LCD_WIDTH; | 109 | bottomright.px_x = LCD_WIDTH; |
105 | bottomright.px_y = LCD_HEIGHT; | 110 | bottomright.px_y = LCD_HEIGHT; |
106 | |||
107 | /* Enable the touchscreen interrupt */ | ||
108 | IO_INTC_EINT2 |= (1<<3); /* IRQ_GIO14 */ | ||
109 | #if 0 | ||
110 | tsc2100_writereg(TSADC_PAGE, TSADC_ADDRESS, | ||
111 | TSADC_PSTCM| | ||
112 | (0x2<<TSADC_ADSCM_SHIFT)| /* scan x,y,z1,z2 */ | ||
113 | (0x1<<TSADC_RESOL_SHIFT) /* 8 bit resolution */ | ||
114 | ); | ||
115 | /* doesnt work for some reason... | ||
116 | setting to 8bit would probably be better than the 12bit currently */ | ||
117 | #endif | ||
118 | } | 111 | } |
119 | 112 | ||
120 | inline bool button_hold(void) | 113 | inline bool button_hold(void) |
@@ -122,46 +115,35 @@ inline bool button_hold(void) | |||
122 | return hold_button; | 115 | return hold_button; |
123 | } | 116 | } |
124 | 117 | ||
118 | /* This is called from the tsc2100 interupt handler in adc-mr500.c */ | ||
119 | void touch_read_coord(void) | ||
120 | { | ||
121 | touch_available = true; | ||
122 | tsc2100_read_touch(&touch_x, &touch_y, &touch_z1, &touch_z2); | ||
123 | } | ||
124 | |||
125 | int button_read_device(int *data) | 125 | int button_read_device(int *data) |
126 | { | 126 | { |
127 | int button_read = BUTTON_NONE; | 127 | int button_read = BUTTON_NONE; |
128 | static int button_old = BUTTON_NONE; | ||
129 | static bool hold_button_old = false; | 128 | static bool hold_button_old = false; |
130 | static long last_touch = 0; | ||
131 | 129 | ||
132 | *data = 0; | 130 | *data = 0; |
133 | 131 | ||
134 | /* Handle touchscreen */ | 132 | /* Handle touchscreen */ |
135 | if (touch_available) | 133 | if (touch_available) |
136 | { | 134 | { |
137 | short x,y; | 135 | *data = touch_to_pixels(&touch_x, &touch_y); |
138 | short last_z1, last_z2; | 136 | button_read |= touchscreen_to_pixels(touch_x, touch_y, data); |
139 | |||
140 | tsc2100_read_values(&x, &y, &last_z1, &last_z2); | ||
141 | |||
142 | *data = touch_to_pixels(x, y); | ||
143 | button_read |= touchscreen_to_pixels((*data&0xffff0000)>>16, | ||
144 | *data&0x0000ffff, data); | ||
145 | button_old = button_read; | ||
146 | 137 | ||
147 | touch_available = false; | 138 | touch_available = false; |
148 | last_touch=current_tick; | 139 | last_touch=current_tick; |
149 | } | 140 | } |
150 | else | ||
151 | { | ||
152 | /* Touch hasn't happened in a while, clear the bits */ | ||
153 | if(last_touch+3>current_tick) | ||
154 | button_old&=(0xFF); | ||
155 | } | ||
156 | 141 | ||
157 | /* Handle power button */ | 142 | /* Handle power button */ |
158 | if ((IO_GIO_BITSET0&0x01) == 0) | 143 | if ((IO_GIO_BITSET0&0x01) == 0) |
159 | { | 144 | { |
160 | button_read |= BUTTON_POWER; | 145 | button_read |= BUTTON_POWER; |
161 | button_old = button_read; | ||
162 | } | 146 | } |
163 | else | ||
164 | button_old&=~BUTTON_POWER; | ||
165 | 147 | ||
166 | /* Read data from the remote */ | 148 | /* Read data from the remote */ |
167 | button_read |= remote_read_device(); | 149 | button_read |= remote_read_device(); |
@@ -180,27 +162,8 @@ int button_read_device(int *data) | |||
180 | if (hold_button) | 162 | if (hold_button) |
181 | { | 163 | { |
182 | button_read = BUTTON_NONE; | 164 | button_read = BUTTON_NONE; |
183 | button_old = button_read; | ||
184 | } | 165 | } |
185 | 166 | ||
186 | return button_read; | 167 | return button_read; |
187 | } | 168 | } |
188 | 169 | ||
189 | /* Touchscreen data available interupt */ | ||
190 | void read_battery_inputs(void); | ||
191 | void GIO14(void) | ||
192 | { | ||
193 | short tsadc = tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS); | ||
194 | short adscm = (tsadc&TSADC_ADSCM_MASK)>>TSADC_ADSCM_SHIFT; | ||
195 | switch (adscm) | ||
196 | { | ||
197 | case 1: | ||
198 | case 2: | ||
199 | touch_available = true; | ||
200 | break; | ||
201 | case 0xb: | ||
202 | read_battery_inputs(); | ||
203 | break; | ||
204 | } | ||
205 | IO_INTC_IRQ2 = (1<<3); /* IRQ_GIO14 == 35 */ | ||
206 | } | ||