diff options
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c | 66 | ||||
-rw-r--r-- | firmware/target/arm/imx233/sansa-fuzeplus/button-target.h | 1 |
2 files changed, 39 insertions, 28 deletions
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c b/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c index f4166d0c2c..ea4aa083e5 100644 --- a/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c +++ b/firmware/target/arm/imx233/sansa-fuzeplus/button-fuzeplus.c | |||
@@ -192,33 +192,22 @@ bool button_debug_screen(void) | |||
192 | return true; | 192 | return true; |
193 | } | 193 | } |
194 | 194 | ||
195 | struct button_area_t | 195 | /* we emulate a 3x3 grid, this gives the button mapping */ |
196 | int button_mapping[3][3] = | ||
196 | { | 197 | { |
197 | /* define a rectangle region */ | 198 | {BUTTON_BOTTOMLEFT, BUTTON_LEFT, BUTTON_BACK}, |
198 | int lx, ly; | 199 | {BUTTON_DOWN, BUTTON_SELECT, BUTTON_UP}, |
199 | int rx, ry; | 200 | {BUTTON_BOTTOMRIGHT, BUTTON_RIGHT, BUTTON_PLAYPAUSE}, |
200 | int button; | ||
201 | }; | ||
202 | |||
203 | static struct button_area_t button_areas[] = | ||
204 | { | ||
205 | {1003, 658, 2006, 1316, BUTTON_SELECT}, | ||
206 | {0, 658, 1003, 1316, BUTTON_LEFT}, | ||
207 | {2006, 658, 3009, 1316, BUTTON_RIGHT}, | ||
208 | {1003, 0 , 2006, 658, BUTTON_DOWN}, | ||
209 | {1003, 1316, 2006, 1974, BUTTON_UP}, | ||
210 | {2006, 1316, 3009, 1974, BUTTON_PLAYPAUSE}, | ||
211 | {0, 1316, 1003, 1974, BUTTON_BACK}, | ||
212 | {0, 0 , 1003, 658, BUTTON_BOTTOMLEFT}, | ||
213 | {2006, 0 , 3009, 658, BUTTON_BOTTOMRIGHT}, | ||
214 | {0, 0, 0, 0, 0}, | ||
215 | }; | 201 | }; |
216 | 202 | ||
217 | #define RMI_INTERRUPT 1 | 203 | #define RMI_INTERRUPT 1 |
218 | #define RMI_SET_SENSITIVITY 2 | 204 | #define RMI_SET_SENSITIVITY 2 |
219 | #define RMI_SET_SLEEP_MODE 3 | 205 | #define RMI_SET_SLEEP_MODE 3 |
220 | /* timeout before lowering touchpad power from lack of activity */ | 206 | /* timeout before lowering touchpad power from lack of activity */ |
221 | #define ACTIVITY_TMO (5 * HZ) | 207 | #define ACTIVITY_TMO (5 * HZ) |
208 | #define TOUCHPAD_WIDTH 3010 | ||
209 | #define TOUCHPAD_HEIGHT 1975 | ||
210 | #define DEADZONE_MULTIPLIER 2 /* deadzone multiplier */ | ||
222 | 211 | ||
223 | static int touchpad_btns = 0; | 212 | static int touchpad_btns = 0; |
224 | static long rmi_stack [DEFAULT_STACK_SIZE/sizeof(long)]; | 213 | static long rmi_stack [DEFAULT_STACK_SIZE/sizeof(long)]; |
@@ -226,17 +215,38 @@ static const char rmi_thread_name[] = "rmi"; | |||
226 | static struct event_queue rmi_queue; | 215 | static struct event_queue rmi_queue; |
227 | static unsigned last_activity = 0; | 216 | static unsigned last_activity = 0; |
228 | static bool t_enable = true; | 217 | static bool t_enable = true; |
218 | static int deadzone; | ||
219 | |||
220 | /* Ignore deadzone function. If outside of the pad, project to border. */ | ||
221 | static int find_button_no_deadzone(int x, int y) | ||
222 | { | ||
223 | /* compute grid coordinate */ | ||
224 | int gx = MAX(MIN(x * 3 / TOUCHPAD_WIDTH, 2), 0); | ||
225 | int gy = MAX(MIN(y * 3 / TOUCHPAD_HEIGHT, 2), 0); | ||
226 | |||
227 | return button_mapping[gx][gy]; | ||
228 | } | ||
229 | 229 | ||
230 | static int find_button(int x, int y) | 230 | static int find_button(int x, int y) |
231 | { | 231 | { |
232 | struct button_area_t *area = button_areas; | 232 | /* find button ignoring deadzones */ |
233 | for(; area->button != 0; area++) | 233 | int btn = find_button_no_deadzone(x, y); |
234 | { | 234 | /* To check if we are in a deadzone, we try to shift the coordinates |
235 | if(area->lx <= x && x <= area->rx && | 235 | * and see if we get the same button. Not that we do not want to apply |
236 | area->ly <= y && y <= area->ry) | 236 | * the deadzone in the borders ! The code works even in the borders because |
237 | return area->button; | 237 | * the find_button_no_deadzone() project out-of-bound coordinates to the |
238 | } | 238 | * borders */ |
239 | return 0; | 239 | if(find_button_no_deadzone(x + deadzone, y) != btn || |
240 | find_button_no_deadzone(x - deadzone, y) != btn || | ||
241 | find_button_no_deadzone(x, y + deadzone) != btn || | ||
242 | find_button_no_deadzone(x, y - deadzone) != btn) | ||
243 | return 0; | ||
244 | return btn; | ||
245 | } | ||
246 | |||
247 | void touchpad_set_deadzone(int touchpad_deadzone) | ||
248 | { | ||
249 | deadzone = touchpad_deadzone * DEADZONE_MULTIPLIER; | ||
240 | } | 250 | } |
241 | 251 | ||
242 | static int touchpad_read_device(void) | 252 | static int touchpad_read_device(void) |
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h b/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h index ce5ffe464a..7a4396e0f2 100644 --- a/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h +++ b/firmware/target/arm/imx233/sansa-fuzeplus/button-target.h | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <stdbool.h> | 24 | #include <stdbool.h> |
25 | bool button_debug_screen(void); | 25 | bool button_debug_screen(void); |
26 | void touchpad_set_sensitivity(int level); | 26 | void touchpad_set_sensitivity(int level); |
27 | void touchpad_set_deadzone(int touchpad_deadzone); | ||
27 | void touchpad_enable_device(bool en); | 28 | void touchpad_enable_device(bool en); |
28 | 29 | ||
29 | /* Main unit's buttons */ | 30 | /* Main unit's buttons */ |