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 | 98 |
1 files changed, 41 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 daa53f794f..036f777340 100644 --- a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c +++ b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c | |||
@@ -35,12 +35,6 @@ | |||
35 | #include "string.h" | 35 | #include "string.h" |
36 | #include "touchscreen.h" | 36 | #include "touchscreen.h" |
37 | 37 | ||
38 | #define BUTTON_TIMEOUT 50 | ||
39 | |||
40 | #define BUTTON_START_BYTE 0xF0 | ||
41 | #define BUTTON_START_BYTE2 0xF4 /* not sure why, but sometimes you get F0 or F4, */ | ||
42 | /* but always the same one for the session? */ | ||
43 | static short last_x, last_y, last_z1, last_z2; /* for the touch screen */ | ||
44 | static bool touch_available = false; | 38 | static bool touch_available = false; |
45 | static bool hold_button = false; | 39 | static bool hold_button = false; |
46 | 40 | ||
@@ -129,93 +123,83 @@ inline bool button_hold(void) | |||
129 | return hold_button; | 123 | return hold_button; |
130 | } | 124 | } |
131 | 125 | ||
132 | #define TOUCH_MARGIN 8 | ||
133 | char r_buffer[5]; | ||
134 | int r_button = BUTTON_NONE; | ||
135 | int button_read_device(int *data) | 126 | int button_read_device(int *data) |
136 | { | 127 | { |
137 | int retval, button1_location, button2_location; | 128 | char r_buffer[5]; |
129 | int r_button = BUTTON_NONE; | ||
130 | |||
138 | static int oldbutton = BUTTON_NONE; | 131 | static int oldbutton = BUTTON_NONE; |
139 | static bool oldhold = false; | 132 | static bool oldhold = false; |
140 | |||
141 | static long last_touch = 0; | 133 | static long last_touch = 0; |
142 | 134 | ||
143 | r_button=BUTTON_NONE; | ||
144 | *data = 0; | 135 | *data = 0; |
145 | 136 | ||
137 | /* Handle touchscreen */ | ||
146 | if (touch_available) | 138 | if (touch_available) |
147 | { | 139 | { |
148 | short x,y; | 140 | short x,y; |
149 | bool send_touch = false; | 141 | short last_z1, last_z2; |
142 | |||
150 | tsc2100_read_values(&x, &y, &last_z1, &last_z2); | 143 | tsc2100_read_values(&x, &y, &last_z1, &last_z2); |
151 | if (TIME_BEFORE(last_touch + HZ/5, current_tick)) | 144 | |
152 | { | 145 | *data = touch_to_pixels(x, y); |
153 | if ((x > last_x + TOUCH_MARGIN) || | 146 | r_button |= touchscreen_to_pixels((*data&0xffff0000)>>16, |
154 | (x < last_x - TOUCH_MARGIN) || | 147 | *data&0x0000ffff, data); |
155 | (y > last_y + TOUCH_MARGIN) || | 148 | oldbutton = r_button; |
156 | (y < last_y - TOUCH_MARGIN)) | 149 | |
157 | { | ||
158 | send_touch = true; | ||
159 | } | ||
160 | } | ||
161 | else | ||
162 | send_touch = true; | ||
163 | if (send_touch) | ||
164 | { | ||
165 | last_x = x; | ||
166 | last_y = y; | ||
167 | *data = touch_to_pixels(x, y); | ||
168 | r_button |= touchscreen_to_pixels((*data&0xffff0000)>>16, | ||
169 | *data&0x0000ffff, data); | ||
170 | oldbutton = r_button; | ||
171 | } | ||
172 | last_touch = current_tick; | ||
173 | touch_available = false; | 150 | touch_available = false; |
151 | last_touch=current_tick; | ||
174 | } | 152 | } |
175 | else | 153 | else |
176 | { | 154 | { |
177 | /* Touch hasn't happened in a while, clear the bits */ | 155 | /* Touch hasn't happened in a while, clear the bits */ |
178 | if(last_touch+3>current_tick) | 156 | if(last_touch+3>current_tick) |
179 | { | ||
180 | oldbutton&=(0xFF); | 157 | oldbutton&=(0xFF); |
181 | } | ||
182 | } | 158 | } |
183 | 159 | ||
160 | /* Handle power button */ | ||
184 | if ((IO_GIO_BITSET0&0x01) == 0) | 161 | if ((IO_GIO_BITSET0&0x01) == 0) |
185 | { | 162 | { |
186 | r_button |= BUTTON_POWER; | 163 | r_button |= BUTTON_POWER; |
187 | oldbutton=r_button; | 164 | oldbutton=r_button; |
188 | } | 165 | } |
166 | else | ||
167 | oldbutton&=~BUTTON_POWER; | ||
189 | 168 | ||
190 | retval=uart1_gets_queue(r_buffer, 5); | 169 | /* Handle remote buttons */ |
191 | 170 | if(uart1_gets_queue(r_buffer, 5)>=0) | |
192 | for(button1_location=0;button1_location<4;button1_location++) | ||
193 | { | 171 | { |
194 | if((r_buffer[button1_location]&0xF0)==0xF0 | 172 | int button_location; |
195 | && (r_buffer[button1_location+1]&0xF0)!=0xF0) | ||
196 | break; | ||
197 | } | ||
198 | button1_location++; | ||
199 | if(button1_location==5) | ||
200 | button1_location=0; | ||
201 | 173 | ||
202 | if(button1_location==4) | 174 | for(button_location=0;button_location<4;button_location++) |
203 | button2_location=0; | 175 | { |
204 | else | 176 | if((r_buffer[button_location]&0xF0)==0xF0 |
205 | button2_location=button1_location+1; | 177 | && (r_buffer[button_location+1]&0xF0)!=0xF0) |
178 | break; | ||
179 | } | ||
180 | |||
181 | if(button_location==4) | ||
182 | button_location=0; | ||
183 | |||
184 | button_location++; | ||
185 | |||
186 | r_button |= r_buffer[button_location]; | ||
187 | |||
188 | /* Find the hold status location */ | ||
189 | if(button_location==4) | ||
190 | button_location=0; | ||
191 | else | ||
192 | button_location++; | ||
193 | |||
194 | hold_button=((r_buffer[button_location]&0x80)?true:false); | ||
206 | 195 | ||
207 | if(retval>=0) | ||
208 | { | ||
209 | uart1_clear_queue(); | 196 | uart1_clear_queue(); |
210 | r_button |= r_buffer[button1_location]; | ||
211 | oldbutton=r_button; | 197 | oldbutton=r_button; |
212 | hold_button=((r_buffer[button2_location]&0x80)?true:false); | ||
213 | } | 198 | } |
214 | else | 199 | else |
215 | { | ||
216 | r_button=oldbutton; | 200 | r_button=oldbutton; |
217 | } | ||
218 | 201 | ||
202 | /* Take care of hold notices */ | ||
219 | #ifndef BOOTLOADER | 203 | #ifndef BOOTLOADER |
220 | /* give BL notice if HB state chaged */ | 204 | /* give BL notice if HB state chaged */ |
221 | if (hold_button != oldhold) | 205 | if (hold_button != oldhold) |