diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-16 17:04:47 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2009-06-16 17:04:47 +0000 |
commit | b8435f54464fd50c145d321b118d773ea05ef6a2 (patch) | |
tree | a514bbe44e41c454dfca56184376209787c40268 | |
parent | b1a60934c5d178842ec3bec83a3e5286410cab7d (diff) | |
download | rockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.tar.gz rockbox-b8435f54464fd50c145d321b118d773ea05ef6a2.zip |
Touchscreen targets: add calibration screen + rewrite calibration driver (FS#10295)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21312 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/lang/english.lang | 57 | ||||
-rw-r--r-- | apps/lang/nederlands.lang | 57 | ||||
-rw-r--r-- | apps/menus/display_menu.c | 29 | ||||
-rw-r--r-- | apps/menus/settings_menu.c | 18 | ||||
-rw-r--r-- | apps/screens.c | 82 | ||||
-rw-r--r-- | apps/screens.h | 5 | ||||
-rw-r--r-- | apps/settings.c | 1 | ||||
-rw-r--r-- | apps/settings.h | 1 | ||||
-rw-r--r-- | apps/settings_list.c | 50 | ||||
-rwxr-xr-x | firmware/drivers/touchscreen.c | 124 | ||||
-rwxr-xr-x | firmware/export/touchscreen.h | 14 |
11 files changed, 335 insertions, 103 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 09cbdbfc09..da09e3c49a 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -12405,7 +12405,7 @@ | |||
12405 | </phrase> | 12405 | </phrase> |
12406 | <phrase> | 12406 | <phrase> |
12407 | id: LANG_TOUCHSCREEN_MODE | 12407 | id: LANG_TOUCHSCREEN_MODE |
12408 | desc: in Settings -> General -> System menu | 12408 | desc: in Settings -> General -> Display -> Touchscreen Settings |
12409 | user: core | 12409 | user: core |
12410 | <source> | 12410 | <source> |
12411 | *: none | 12411 | *: none |
@@ -12422,7 +12422,7 @@ | |||
12422 | </phrase> | 12422 | </phrase> |
12423 | <phrase> | 12423 | <phrase> |
12424 | id: LANG_TOUCHSCREEN_GRID | 12424 | id: LANG_TOUCHSCREEN_GRID |
12425 | desc: in Settings -> General -> System menu | 12425 | desc: in Settings -> General -> Display -> Touchscreen Settings |
12426 | user: core | 12426 | user: core |
12427 | <source> | 12427 | <source> |
12428 | *: none | 12428 | *: none |
@@ -12439,7 +12439,7 @@ | |||
12439 | </phrase> | 12439 | </phrase> |
12440 | <phrase> | 12440 | <phrase> |
12441 | id: LANG_TOUCHSCREEN_POINT | 12441 | id: LANG_TOUCHSCREEN_POINT |
12442 | desc: in Settings -> General -> System menu | 12442 | desc: in Settings -> General -> Display -> Touchscreen Settings |
12443 | user: core | 12443 | user: core |
12444 | <source> | 12444 | <source> |
12445 | *: none | 12445 | *: none |
@@ -12502,3 +12502,54 @@ | |||
12502 | swcodec: "Speed" | 12502 | swcodec: "Speed" |
12503 | </voice> | 12503 | </voice> |
12504 | </phrase> | 12504 | </phrase> |
12505 | <phrase> | ||
12506 | id: LANG_TOUCHSCREEN_SETTINGS | ||
12507 | desc: in Settings -> General -> Display menu | ||
12508 | user: core | ||
12509 | <source> | ||
12510 | *: none | ||
12511 | touchscreen: "Touchscreen Settings" | ||
12512 | </source> | ||
12513 | <dest> | ||
12514 | *: none | ||
12515 | touchscreen: "Touchscreen Settings" | ||
12516 | </dest> | ||
12517 | <voice> | ||
12518 | *: none | ||
12519 | touchscreen: "Touchscreen Settings" | ||
12520 | </voice> | ||
12521 | </phrase> | ||
12522 | <phrase> | ||
12523 | id: LANG_TOUCHSCREEN_CALIBRATE | ||
12524 | desc: in Settings -> General -> Display -> Touchscreen Settings | ||
12525 | user: core | ||
12526 | <source> | ||
12527 | *: none | ||
12528 | touchscreen: "Calibrate" | ||
12529 | </source> | ||
12530 | <dest> | ||
12531 | *: none | ||
12532 | touchscreen: "Calibrate" | ||
12533 | </dest> | ||
12534 | <voice> | ||
12535 | *: none | ||
12536 | touchscreen: "Calibrate" | ||
12537 | </voice> | ||
12538 | </phrase> | ||
12539 | <phrase> | ||
12540 | id: LANG_TOUCHSCREEN_RESET_CALIBRATION | ||
12541 | desc: in Settings -> General -> Display -> Touchscreen Settings | ||
12542 | user: core | ||
12543 | <source> | ||
12544 | *: none | ||
12545 | touchscreen: "Reset Calibration" | ||
12546 | </source> | ||
12547 | <dest> | ||
12548 | *: none | ||
12549 | touchscreen: "Reset Calibration" | ||
12550 | </dest> | ||
12551 | <voice> | ||
12552 | *: none | ||
12553 | touchscreen: "Reset Calibration" | ||
12554 | </voice> | ||
12555 | </phrase> | ||
diff --git a/apps/lang/nederlands.lang b/apps/lang/nederlands.lang index 2d476d1d14..e73839926f 100644 --- a/apps/lang/nederlands.lang +++ b/apps/lang/nederlands.lang | |||
@@ -12335,7 +12335,7 @@ | |||
12335 | </phrase> | 12335 | </phrase> |
12336 | <phrase> | 12336 | <phrase> |
12337 | id: LANG_TOUCHSCREEN_MODE | 12337 | id: LANG_TOUCHSCREEN_MODE |
12338 | desc: in Settings -> General -> System menu | 12338 | desc: in Settings -> General -> Display -> Touchscreen Settings |
12339 | user: core | 12339 | user: core |
12340 | <source> | 12340 | <source> |
12341 | *: none | 12341 | *: none |
@@ -12352,7 +12352,7 @@ | |||
12352 | </phrase> | 12352 | </phrase> |
12353 | <phrase> | 12353 | <phrase> |
12354 | id: LANG_TOUCHSCREEN_GRID | 12354 | id: LANG_TOUCHSCREEN_GRID |
12355 | desc: in Settings -> General -> System menu | 12355 | desc: in Settings -> General -> Display -> Touchscreen Settings |
12356 | user: core | 12356 | user: core |
12357 | <source> | 12357 | <source> |
12358 | *: none | 12358 | *: none |
@@ -12369,7 +12369,7 @@ | |||
12369 | </phrase> | 12369 | </phrase> |
12370 | <phrase> | 12370 | <phrase> |
12371 | id: LANG_TOUCHSCREEN_POINT | 12371 | id: LANG_TOUCHSCREEN_POINT |
12372 | desc: in Settings -> General -> System menu | 12372 | desc: in Settings -> General -> Display -> Touchscreen Settings |
12373 | user: core | 12373 | user: core |
12374 | <source> | 12374 | <source> |
12375 | *: none | 12375 | *: none |
@@ -12432,3 +12432,54 @@ | |||
12432 | swcodec: "Snelheid" | 12432 | swcodec: "Snelheid" |
12433 | </voice> | 12433 | </voice> |
12434 | </phrase> | 12434 | </phrase> |
12435 | <phrase> | ||
12436 | id: LANG_TOUCHSCREEN_SETTINGS | ||
12437 | desc: in Settings -> General -> Display menu | ||
12438 | user: core | ||
12439 | <source> | ||
12440 | *: none | ||
12441 | touchscreen: "Touchscreen Settings" | ||
12442 | </source> | ||
12443 | <dest> | ||
12444 | *: none | ||
12445 | touchscreen: "Touchscreen instellingen" | ||
12446 | </dest> | ||
12447 | <voice> | ||
12448 | *: none | ||
12449 | touchscreen: "Touchscreen instellingen" | ||
12450 | </voice> | ||
12451 | </phrase> | ||
12452 | <phrase> | ||
12453 | id: LANG_TOUCHSCREEN_CALIBRATE | ||
12454 | desc: in Settings -> General -> Display -> Touchscreen Settings | ||
12455 | user: core | ||
12456 | <source> | ||
12457 | *: none | ||
12458 | touchscreen: "Calibrate" | ||
12459 | </source> | ||
12460 | <dest> | ||
12461 | *: none | ||
12462 | touchscreen: "Kalibreer" | ||
12463 | </dest> | ||
12464 | <voice> | ||
12465 | *: none | ||
12466 | touchscreen: "Kalibreer" | ||
12467 | </voice> | ||
12468 | </phrase> | ||
12469 | <phrase> | ||
12470 | id: LANG_TOUCHSCREEN_RESET_CALIBRATION | ||
12471 | desc: in Settings -> General -> Display -> Touchscreen Settings | ||
12472 | user: core | ||
12473 | <source> | ||
12474 | *: none | ||
12475 | touchscreen: "Reset Calibration" | ||
12476 | </source> | ||
12477 | <dest> | ||
12478 | *: none | ||
12479 | touchscreen: "Kalibratie terugzetten" | ||
12480 | </dest> | ||
12481 | <voice> | ||
12482 | *: none | ||
12483 | touchscreen: "Kalibratie terugzetten" | ||
12484 | </voice> | ||
12485 | </phrase> | ||
diff --git a/apps/menus/display_menu.c b/apps/menus/display_menu.c index a015be3a23..aee9c1828d 100644 --- a/apps/menus/display_menu.c +++ b/apps/menus/display_menu.c | |||
@@ -36,6 +36,9 @@ | |||
36 | #include "talk.h" | 36 | #include "talk.h" |
37 | #include "lcd.h" | 37 | #include "lcd.h" |
38 | #include "lcd-remote.h" | 38 | #include "lcd-remote.h" |
39 | #ifdef HAVE_TOUCHSCREEN | ||
40 | #include "screens.h" | ||
41 | #endif | ||
39 | 42 | ||
40 | #ifdef HAVE_BACKLIGHT | 43 | #ifdef HAVE_BACKLIGHT |
41 | static int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item) | 44 | static int filterfirstkeypress_callback(int action,const struct menu_item_ex *this_item) |
@@ -496,6 +499,29 @@ MAKE_MENU(peak_meter_menu, ID2P(LANG_PM_MENU), NULL, Icon_NOICON, | |||
496 | /***********************************/ | 499 | /***********************************/ |
497 | 500 | ||
498 | 501 | ||
502 | #ifdef HAVE_TOUCHSCREEN | ||
503 | static int touch_mode_callback(int action,const struct menu_item_ex *this_item) | ||
504 | { | ||
505 | (void)this_item; | ||
506 | switch (action) | ||
507 | { | ||
508 | case ACTION_EXIT_MENUITEM: /* on exit */ | ||
509 | touchscreen_set_mode(global_settings.touch_mode); | ||
510 | break; | ||
511 | } | ||
512 | return action; | ||
513 | } | ||
514 | MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback); | ||
515 | |||
516 | MENUITEM_FUNCTION(touchscreen_menu_calibrate, 0, ID2P(LANG_TOUCHSCREEN_CALIBRATE), calibrate, | ||
517 | NULL, NULL, Icon_NOICON); | ||
518 | MENUITEM_FUNCTION(touchscreen_menu_reset_calibration, 0, ID2P(LANG_TOUCHSCREEN_RESET_CALIBRATION), reset_mapping, | ||
519 | NULL, NULL, Icon_NOICON); | ||
520 | |||
521 | MAKE_MENU(touchscreen_menu, ID2P(LANG_TOUCHSCREEN_SETTINGS), NULL, Icon_NOICON, &touch_mode, | ||
522 | &touchscreen_menu_calibrate, &touchscreen_menu_reset_calibration); | ||
523 | #endif | ||
524 | |||
499 | 525 | ||
500 | MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL); | 526 | MENUITEM_SETTING(codepage_setting, &global_settings.default_codepage, NULL); |
501 | 527 | ||
@@ -511,4 +537,7 @@ MAKE_MENU(display_menu, ID2P(LANG_DISPLAY), | |||
511 | &bars_menu, &peak_meter_menu, | 537 | &bars_menu, &peak_meter_menu, |
512 | #endif | 538 | #endif |
513 | &codepage_setting, | 539 | &codepage_setting, |
540 | #ifdef HAVE_TOUCHSCREEN | ||
541 | &touchscreen_menu, | ||
542 | #endif | ||
514 | ); | 543 | ); |
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 56a0178000..fdc775877a 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c | |||
@@ -265,21 +265,6 @@ MENUITEM_SETTING(buttonlight_brightness, &global_settings.buttonlight_brightness | |||
265 | MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL); | 265 | MENUITEM_SETTING(touchpad_sensitivity, &global_settings.touchpad_sensitivity, NULL); |
266 | #endif | 266 | #endif |
267 | 267 | ||
268 | #ifdef HAVE_TOUCHSCREEN | ||
269 | static int touch_mode_callback(int action,const struct menu_item_ex *this_item) | ||
270 | { | ||
271 | (void)this_item; | ||
272 | switch (action) | ||
273 | { | ||
274 | case ACTION_EXIT_MENUITEM: /* on exit */ | ||
275 | touchscreen_set_mode(global_settings.touch_mode); | ||
276 | break; | ||
277 | } | ||
278 | return action; | ||
279 | } | ||
280 | MENUITEM_SETTING(touch_mode, &global_settings.touch_mode, touch_mode_callback); | ||
281 | #endif | ||
282 | |||
283 | MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), | 268 | MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), |
284 | 0, Icon_System_menu, | 269 | 0, Icon_System_menu, |
285 | &start_screen, | 270 | &start_screen, |
@@ -315,9 +300,6 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), | |||
315 | #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING | 300 | #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING |
316 | &touchpad_sensitivity, | 301 | &touchpad_sensitivity, |
317 | #endif | 302 | #endif |
318 | #ifdef HAVE_TOUCHSCREEN | ||
319 | &touch_mode, | ||
320 | #endif | ||
321 | ); | 303 | ); |
322 | 304 | ||
323 | /* SYSTEM MENU */ | 305 | /* SYSTEM MENU */ |
diff --git a/apps/screens.c b/apps/screens.c index 096b81411e..829aa191e1 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -1019,3 +1019,85 @@ bool view_runtime(void) | |||
1019 | } | 1019 | } |
1020 | return false; | 1020 | return false; |
1021 | } | 1021 | } |
1022 | |||
1023 | #ifdef HAVE_TOUCHSCREEN | ||
1024 | static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i, | ||
1025 | struct screen* screen) | ||
1026 | { | ||
1027 | int action; | ||
1028 | short ts_x, ts_y; | ||
1029 | |||
1030 | /* Draw a cross */ | ||
1031 | screen->drawline(x - 10, y, x - 2, y); | ||
1032 | screen->drawline(x + 2, y, x + 10, y); | ||
1033 | screen->drawline(x, y - 10, x, y - 2); | ||
1034 | screen->drawline(x, y + 2, x, y + 10); | ||
1035 | screen->update(); | ||
1036 | |||
1037 | /* Wait for a touchscreen press */ | ||
1038 | while(true) | ||
1039 | { | ||
1040 | action = get_action(CONTEXT_STD, TIMEOUT_BLOCK); | ||
1041 | if(action == ACTION_TOUCHSCREEN) | ||
1042 | { | ||
1043 | if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL) | ||
1044 | break; | ||
1045 | } | ||
1046 | else if(action == ACTION_STD_CANCEL) | ||
1047 | return -1; | ||
1048 | } | ||
1049 | |||
1050 | cal->x[i][0] = ts_x; | ||
1051 | cal->y[i][0] = ts_y; | ||
1052 | cal->x[i][1] = x; | ||
1053 | cal->y[i][1] = y; | ||
1054 | |||
1055 | return 0; | ||
1056 | } | ||
1057 | |||
1058 | |||
1059 | int calibrate(void) | ||
1060 | { | ||
1061 | short points[3][2] = { | ||
1062 | {LCD_WIDTH/10, LCD_HEIGHT/10}, | ||
1063 | {7*LCD_WIDTH/8, LCD_HEIGHT/2}, | ||
1064 | {LCD_WIDTH/2, 7*LCD_HEIGHT/8} | ||
1065 | }; | ||
1066 | struct screen* screen = &screens[SCREEN_MAIN]; | ||
1067 | enum touchscreen_mode old_mode = touchscreen_get_mode(); | ||
1068 | struct touchscreen_calibration cal; | ||
1069 | int i, ret = 0; | ||
1070 | bool statusbar = global_settings.statusbar; /* hide the statusbar */ | ||
1071 | |||
1072 | global_settings.statusbar = false; | ||
1073 | touchscreen_disable_mapping(); /* set raw mode */ | ||
1074 | touchscreen_set_mode(TOUCHSCREEN_POINT); | ||
1075 | for(i=0; i<3; i++) | ||
1076 | { | ||
1077 | screen->clear_display(); | ||
1078 | |||
1079 | if(get_sample(&cal, points[i][0], points[i][1], i, screen)) | ||
1080 | { | ||
1081 | ret = -1; | ||
1082 | break; | ||
1083 | } | ||
1084 | } | ||
1085 | |||
1086 | if(ret == 0) | ||
1087 | touchscreen_calibrate(&cal); | ||
1088 | else | ||
1089 | touchscreen_reset_mapping(); | ||
1090 | memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter)); | ||
1091 | touchscreen_set_mode(old_mode); | ||
1092 | global_settings.statusbar = statusbar; | ||
1093 | |||
1094 | return ret; | ||
1095 | } | ||
1096 | |||
1097 | int reset_mapping(void) | ||
1098 | { | ||
1099 | touchscreen_reset_mapping(); | ||
1100 | memcpy(&global_settings.ts_calibration_data, &calibration_parameters, sizeof(struct touchscreen_parameter)); | ||
1101 | return 0; | ||
1102 | } | ||
1103 | #endif | ||
diff --git a/apps/screens.h b/apps/screens.h index eb613fc178..38fef14d60 100644 --- a/apps/screens.h +++ b/apps/screens.h | |||
@@ -50,5 +50,10 @@ bool shutdown_screen(void); | |||
50 | bool browse_id3(void); | 50 | bool browse_id3(void); |
51 | bool view_runtime(void); | 51 | bool view_runtime(void); |
52 | 52 | ||
53 | #ifdef HAVE_TOUCHSCREEN | ||
54 | int calibrate(void); | ||
55 | int reset_mapping(void); | ||
56 | #endif | ||
57 | |||
53 | #endif | 58 | #endif |
54 | 59 | ||
diff --git a/apps/settings.c b/apps/settings.c index 9594bd164e..3219dbbf12 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -966,6 +966,7 @@ void settings_apply(bool read_disk) | |||
966 | 966 | ||
967 | #ifdef HAVE_TOUCHSCREEN | 967 | #ifdef HAVE_TOUCHSCREEN |
968 | touchscreen_set_mode(global_settings.touch_mode); | 968 | touchscreen_set_mode(global_settings.touch_mode); |
969 | memcpy(&calibration_parameters, &global_settings.ts_calibration_data, sizeof(struct touchscreen_parameter)); | ||
969 | #endif | 970 | #endif |
970 | 971 | ||
971 | /* This should stay last */ | 972 | /* This should stay last */ |
diff --git a/apps/settings.h b/apps/settings.h index 6ccaeed92e..ef5a62013d 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -730,6 +730,7 @@ struct user_settings | |||
730 | 730 | ||
731 | #ifdef HAVE_TOUCHSCREEN | 731 | #ifdef HAVE_TOUCHSCREEN |
732 | int touch_mode; | 732 | int touch_mode; |
733 | struct touchscreen_parameter ts_calibration_data; | ||
733 | #endif | 734 | #endif |
734 | 735 | ||
735 | /* If values are just added to the end, no need to bump plugin API | 736 | /* If values are just added to the end, no need to bump plugin API |
diff --git a/apps/settings_list.c b/apps/settings_list.c index 74e2cab3cd..dcad718ee5 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c | |||
@@ -53,6 +53,10 @@ | |||
53 | #include "iap.h" | 53 | #include "iap.h" |
54 | #endif | 54 | #endif |
55 | #include "statusbar.h" | 55 | #include "statusbar.h" |
56 | #ifdef HAVE_TOUCHSCREEN | ||
57 | #include "touchscreen.h" | ||
58 | #include "ctype.h" /* For isspace() */ | ||
59 | #endif | ||
56 | 60 | ||
57 | #define NVRAM(bytes) (bytes<<F_NVRAM_MASK_SHIFT) | 61 | #define NVRAM(bytes) (bytes<<F_NVRAM_MASK_SHIFT) |
58 | /** NOTE: NVRAM_CONFIG_VERSION is in settings_list.h | 62 | /** NOTE: NVRAM_CONFIG_VERSION is in settings_list.h |
@@ -452,6 +456,48 @@ static void qs_set_default(void* setting, void* defaultval) | |||
452 | find_setting(defaultval, (int*)setting); | 456 | find_setting(defaultval, (int*)setting); |
453 | } | 457 | } |
454 | #endif | 458 | #endif |
459 | #ifdef HAVE_TOUCHSCREEN | ||
460 | static void tsc_load_from_cfg(void* setting, char*value) | ||
461 | { | ||
462 | struct touchscreen_parameter *var = (struct touchscreen_parameter*) setting; | ||
463 | |||
464 | /* Replacement for sscanf(value, "%d ..., &var->A, ...); */ | ||
465 | int vals[7], count = 0; | ||
466 | while(*value != 0 && count < 7) | ||
467 | { | ||
468 | if(isspace(*value)) | ||
469 | value++; | ||
470 | else | ||
471 | { | ||
472 | vals[count++] = atoi(value); | ||
473 | while(!isspace(*value)) | ||
474 | value++; | ||
475 | } | ||
476 | } | ||
477 | var->A = vals[0]; | ||
478 | var->B = vals[1]; | ||
479 | var->C = vals[2]; | ||
480 | var->D = vals[3]; | ||
481 | var->E = vals[4]; | ||
482 | var->F = vals[5]; | ||
483 | var->divider = vals[6]; | ||
484 | } | ||
485 | |||
486 | static char* tsc_write_to_cfg(void* setting, char*buf, int buf_len) | ||
487 | { | ||
488 | const struct touchscreen_parameter *var = (const struct touchscreen_parameter*) setting; | ||
489 | snprintf(buf, buf_len, "%d %d %d %d %d %d %d", var->A, var->B, var->C, var->D, var->E, var->F, var->divider); | ||
490 | return buf; | ||
491 | } | ||
492 | static bool tsc_is_changed(void* setting, void* defaultval) | ||
493 | { | ||
494 | return memcmp(setting, defaultval, sizeof(struct touchscreen_parameter)) != 0; | ||
495 | } | ||
496 | static void tsc_set_default(void* setting, void* defaultval) | ||
497 | { | ||
498 | memcpy(setting, defaultval, sizeof(struct touchscreen_parameter)); | ||
499 | } | ||
500 | #endif | ||
455 | const struct settings_list settings[] = { | 501 | const struct settings_list settings[] = { |
456 | /* sound settings */ | 502 | /* sound settings */ |
457 | SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME), | 503 | SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME), |
@@ -1470,6 +1516,10 @@ const struct settings_list settings[] = { | |||
1470 | CHOICE_SETTING(0, touch_mode, LANG_TOUCHSCREEN_MODE, TOUCHSCREEN_BUTTON, | 1516 | CHOICE_SETTING(0, touch_mode, LANG_TOUCHSCREEN_MODE, TOUCHSCREEN_BUTTON, |
1471 | "touchscreen mode", "point,grid", NULL, 2, | 1517 | "touchscreen mode", "point,grid", NULL, 2, |
1472 | ID2P(LANG_TOUCHSCREEN_POINT), ID2P(LANG_TOUCHSCREEN_GRID)), | 1518 | ID2P(LANG_TOUCHSCREEN_POINT), ID2P(LANG_TOUCHSCREEN_GRID)), |
1519 | CUSTOM_SETTING(0, ts_calibration_data, -1, | ||
1520 | &default_calibration_parameters, "touchscreen calibration", | ||
1521 | tsc_load_from_cfg, tsc_write_to_cfg, | ||
1522 | tsc_is_changed, tsc_set_default), | ||
1473 | #endif | 1523 | #endif |
1474 | OFFON_SETTING(0, prevent_skip, LANG_PREVENT_SKIPPING, false, "prevent track skip", NULL), | 1524 | OFFON_SETTING(0, prevent_skip, LANG_PREVENT_SKIPPING, false, "prevent track skip", NULL), |
1475 | }; | 1525 | }; |
diff --git a/firmware/drivers/touchscreen.c b/firmware/drivers/touchscreen.c index f7b1b09b92..002acf1236 100755 --- a/firmware/drivers/touchscreen.c +++ b/firmware/drivers/touchscreen.c | |||
@@ -34,119 +34,93 @@ static const int touchscreen_buttons[3][3] = | |||
34 | {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT} | 34 | {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT} |
35 | }; | 35 | }; |
36 | 36 | ||
37 | /* Based on ftp://ftp.embedded.com/pub/2002/06vidales/calibrate.c | ||
38 | * | ||
39 | * Copyright (c) 2001, Carlos E. Vidales. All rights reserved. | ||
40 | * | ||
41 | * This sample program was written and put in the public domain | ||
42 | * by Carlos E. Vidales. The program is provided "as is" | ||
43 | * without warranty of any kind, either expressed or implied. | ||
44 | * If you choose to use the program within your own products | ||
45 | * you do so at your own risk, and assume the responsibility | ||
46 | * for servicing, repairing or correcting the program should | ||
47 | * it prove defective in any manner. | ||
48 | * You may copy and distribute the program's source code in any | ||
49 | * medium, provided that you also include in each copy an | ||
50 | * appropriate copyright notice and disclaimer of warranty. | ||
51 | * You may also modify this program and distribute copies of | ||
52 | * it provided that you include prominent notices stating | ||
53 | * that you changed the file(s) and the date of any change, | ||
54 | * and that you do not charge any royalties or licenses for | ||
55 | * its use. | ||
56 | */ | ||
57 | struct touchscreen_parameter | ||
58 | { | ||
59 | long A; | ||
60 | long B; | ||
61 | long C; | ||
62 | long D; | ||
63 | long E; | ||
64 | long F; | ||
65 | long divider; | ||
66 | }; | ||
67 | |||
68 | #ifndef DEFAULT_TOUCHSCREEN_CALIBRATION | 37 | #ifndef DEFAULT_TOUCHSCREEN_CALIBRATION |
69 | #define DEFAULT_TOUCHSCREEN_CALIBRATION {.A=1, .B=0, .C=0, \ | 38 | #define DEFAULT_TOUCHSCREEN_CALIBRATION { .A=1, .B=0, .C=0, \ |
70 | .D=0, .E=1, .F=0, \ | 39 | .D=0, .E=1, .F=0, \ |
71 | .divider=1} | 40 | .divider=1 } |
72 | #endif | 41 | #endif |
73 | 42 | ||
74 | static struct touchscreen_parameter calibration_parameters | 43 | struct touchscreen_parameter calibration_parameters |
75 | = DEFAULT_TOUCHSCREEN_CALIBRATION; | 44 | = DEFAULT_TOUCHSCREEN_CALIBRATION; |
76 | static const struct touchscreen_parameter default_parameters | 45 | const struct touchscreen_parameter default_calibration_parameters |
77 | = DEFAULT_TOUCHSCREEN_CALIBRATION; | 46 | = DEFAULT_TOUCHSCREEN_CALIBRATION; |
78 | 47 | ||
79 | void touchscreen_disable_mapping(void) | 48 | void touchscreen_disable_mapping(void) |
80 | { | 49 | { |
81 | calibration_parameters.A = 1; | 50 | #define C(x) calibration_parameters.x |
82 | calibration_parameters.B = 0; | 51 | C(A) = C(E) = 1; |
83 | calibration_parameters.C = 0; | 52 | C(B) = C(C) = C(D) = C(F) = 0; |
84 | calibration_parameters.D = 0; | 53 | C(divider) = 1; |
85 | calibration_parameters.E = 1; | 54 | #undef C |
86 | calibration_parameters.F = 0; | ||
87 | calibration_parameters.divider = 1; | ||
88 | } | 55 | } |
89 | 56 | ||
90 | void touchscreen_reset_mapping(void) | 57 | void touchscreen_reset_mapping(void) |
91 | { | 58 | { |
92 | memcpy(&calibration_parameters, &default_parameters, | 59 | memcpy(&calibration_parameters, &default_calibration_parameters, |
93 | sizeof(struct touchscreen_parameter)); | 60 | sizeof(struct touchscreen_parameter)); |
94 | } | 61 | } |
95 | 62 | ||
96 | int touchscreen_calibrate(struct touchscreen_calibration *cal) | 63 | int touchscreen_calibrate(struct touchscreen_calibration *cal) |
97 | { | 64 | { |
98 | calibration_parameters.divider = ((cal->x[0] - cal->x[2]) * (cal->y[1] - cal->y[2])) - | 65 | #define C(x) calibration_parameters.x /* Calibration */ |
99 | ((cal->x[1] - cal->x[2]) * (cal->y[0] - cal->y[2])) ; | 66 | #define S(i,j) cal->i[j][0] /* Screen */ |
67 | #define D(i,j) cal->i[j][1] /* Display */ | ||
68 | long divider = (S(x,0) - S(x,2)) * (S(y,1) - S(y,2)) - | ||
69 | (S(x,1) - S(x,2)) * (S(y,0) - S(y,2)); | ||
100 | 70 | ||
101 | if(calibration_parameters.divider == 0) | 71 | if(divider == 0) |
102 | return -1; | 72 | return -1; |
103 | 73 | else | |
104 | calibration_parameters.A = ((cal->xfb[0] - cal->xfb[2]) * (cal->y[1] - cal->y[2])) - | 74 | C(divider) = divider; |
105 | ((cal->xfb[1] - cal->xfb[2]) * (cal->y[0] - cal->y[2])) ; | ||
106 | 75 | ||
107 | calibration_parameters.B = ((cal->x[0] - cal->x[2]) * (cal->xfb[1] - cal->xfb[2])) - | 76 | C(A) = (D(x,0) - D(x,2)) * (S(y,1) - S(y,2)) - |
108 | ((cal->xfb[0] - cal->xfb[2]) * (cal->x[1] - cal->x[2])) ; | 77 | (D(x,1) - D(x,2)) * (S(y,0) - S(y,2)); |
109 | 78 | ||
110 | calibration_parameters.C = (cal->x[2] * cal->xfb[1] - cal->x[1] * cal->xfb[2]) * cal->y[0] + | 79 | C(B) = (S(x,0) - S(x,2)) * (D(x,1) - D(x,2)) - |
111 | (cal->x[0] * cal->xfb[2] - cal->x[2] * cal->xfb[0]) * cal->y[1] + | 80 | (D(x,0) - D(x,2)) * (S(x,1) - S(x,2)); |
112 | (cal->x[1] * cal->xfb[0] - cal->x[0] * cal->xfb[1]) * cal->y[2] ; | ||
113 | 81 | ||
114 | calibration_parameters.D = ((cal->yfb[0] - cal->yfb[2]) * (cal->y[1] - cal->y[2])) - | 82 | C(C) = S(y,0) * (S(x,2) * D(x,1) - S(x,1) * D(x,2)) + |
115 | ((cal->yfb[1] - cal->yfb[2]) * (cal->y[0] - cal->y[2])) ; | 83 | S(y,1) * (S(x,0) * D(x,2) - S(x,2) * D(x,0)) + |
84 | S(y,2) * (S(x,1) * D(x,0) - S(x,0) * D(x,1)); | ||
116 | 85 | ||
117 | calibration_parameters.E = ((cal->x[0] - cal->x[2]) * (cal->yfb[1] - cal->yfb[2])) - | 86 | C(D) = (D(y,0) - D(y,2)) * (S(y,1) - S(y,2)) - |
118 | ((cal->yfb[0] - cal->yfb[2]) * (cal->x[1] - cal->x[2])) ; | 87 | (D(y,1) - D(y,2)) * (S(y,0) - S(y,2)); |
119 | 88 | ||
120 | calibration_parameters.F = (cal->x[2] * cal->yfb[1] - cal->x[1] * cal->yfb[2]) * cal->y[0] + | 89 | C(E) = (S(x,0) - S(x,2)) * (D(y,1) - D(y,2)) - |
121 | (cal->x[0] * cal->yfb[2] - cal->x[2] * cal->yfb[0]) * cal->y[1] + | 90 | (D(y,0) - D(y,2)) * (S(x,1) - S(x,2)); |
122 | (cal->x[1] * cal->yfb[0] - cal->x[0] * cal->yfb[1]) * cal->y[2] ; | 91 | |
92 | C(F) = S(y,0) * (S(x,2) * D(y,1) - S(x,1) * D(y,2)) + | ||
93 | S(y,1) * (S(x,0) * D(y,2) - S(x,2) * D(y,0)) + | ||
94 | S(y,2) * (S(x,1) * D(y,0) - S(x,0) * D(y,1)); | ||
95 | |||
96 | logf("A: %lX B: %lX C: %lX", C(A), C(B), C(C)); | ||
97 | logf("D: %lX E: %lX F: %lX", C(D), C(E), C(F)); | ||
98 | logf("divider: %lX", C(divider)); | ||
123 | 99 | ||
124 | logf("A: %lX B: %lX C: %lX", calibration_parameters.A, | ||
125 | calibration_parameters.B, calibration_parameters.C); | ||
126 | logf("D: %lX E: %lX F: %lX", calibration_parameters.D, | ||
127 | calibration_parameters.E, calibration_parameters.F); | ||
128 | logf("divider: %lX", calibration_parameters.divider); | ||
129 | |||
130 | return 0; | 100 | return 0; |
101 | #undef C | ||
102 | #undef S | ||
103 | #undef D | ||
131 | } | 104 | } |
132 | 105 | ||
133 | static void map_pixels(int *x, int *y) | 106 | static void map_pixels(int *x, int *y) |
134 | { | 107 | { |
108 | #define C(x) calibration_parameters.x | ||
135 | int _x = *x, _y = *y; | 109 | int _x = *x, _y = *y; |
136 | 110 | ||
137 | *x = (calibration_parameters.A*_x + calibration_parameters.B*_y + | 111 | *x = (C(A) * _x + C(B) * _y + C(C)) / C(divider); |
138 | calibration_parameters.C) / calibration_parameters.divider; | 112 | *y = (C(D) * _x + C(E) * _y + C(F)) / C(divider); |
139 | *y = (calibration_parameters.D*_x + calibration_parameters.E*_y + | 113 | #undef C |
140 | calibration_parameters.F) / calibration_parameters.divider; | ||
141 | } | 114 | } |
142 | 115 | ||
116 | /* TODO: add jitter (and others) filter */ | ||
143 | int touchscreen_to_pixels(int x, int y, int *data) | 117 | int touchscreen_to_pixels(int x, int y, int *data) |
144 | { | 118 | { |
145 | x &= 0xFFFF; | 119 | x &= 0xFFFF; |
146 | y &= 0xFFFF; | 120 | y &= 0xFFFF; |
147 | 121 | ||
148 | map_pixels(&x, &y); | 122 | map_pixels(&x, &y); |
149 | 123 | ||
150 | if(current_mode == TOUCHSCREEN_BUTTON) | 124 | if(current_mode == TOUCHSCREEN_BUTTON) |
151 | return touchscreen_buttons[y / (LCD_HEIGHT/3)] | 125 | return touchscreen_buttons[y / (LCD_HEIGHT/3)] |
152 | [x / (LCD_WIDTH/3) ]; | 126 | [x / (LCD_WIDTH/3) ]; |
diff --git a/firmware/export/touchscreen.h b/firmware/export/touchscreen.h index 0d8233a522..7d1eb4ac8a 100755 --- a/firmware/export/touchscreen.h +++ b/firmware/export/touchscreen.h | |||
@@ -24,10 +24,14 @@ | |||
24 | 24 | ||
25 | struct touchscreen_calibration | 25 | struct touchscreen_calibration |
26 | { | 26 | { |
27 | int x[3]; | 27 | int x[3][2]; |
28 | int xfb[3]; | 28 | int y[3][2]; |
29 | int y[3]; | 29 | }; |
30 | int yfb[3]; | 30 | |
31 | struct touchscreen_parameter | ||
32 | { | ||
33 | int A, B, C, D, E, F; | ||
34 | int divider; | ||
31 | }; | 35 | }; |
32 | 36 | ||
33 | enum touchscreen_mode | 37 | enum touchscreen_mode |
@@ -38,6 +42,8 @@ enum touchscreen_mode | |||
38 | from button_get_data */ | 42 | from button_get_data */ |
39 | }; | 43 | }; |
40 | 44 | ||
45 | extern struct touchscreen_parameter calibration_parameters; | ||
46 | extern const struct touchscreen_parameter default_calibration_parameters; | ||
41 | int touchscreen_calibrate(struct touchscreen_calibration *cal); | 47 | int touchscreen_calibrate(struct touchscreen_calibration *cal); |
42 | int touchscreen_to_pixels(int x, int y, int *data); | 48 | int touchscreen_to_pixels(int x, int y, int *data); |
43 | void touchscreen_set_mode(enum touchscreen_mode mode); | 49 | void touchscreen_set_mode(enum touchscreen_mode mode); |