summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2007-10-01 07:52:39 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2007-10-01 07:52:39 +0000
commit274c2b8d69900c3156ced83949d37c66492db22f (patch)
tree91941736e4b71010262fac758535d39f587443b4
parentf8ada4b9c104fdc729dcce4cf381cf356faadea5 (diff)
downloadrockbox-274c2b8d69900c3156ced83949d37c66492db22f.tar.gz
rockbox-274c2b8d69900c3156ced83949d37c66492db22f.zip
touchpad calibration (very simple calibration screen is in mrobe500.c
but will not actually be used in the bootloader once rockbox main is running) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14937 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-xbootloader/mrobe500.c79
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c32
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/button-target.h8
3 files changed, 99 insertions, 20 deletions
diff --git a/bootloader/mrobe500.c b/bootloader/mrobe500.c
index 1133fa6def..5f80d6d6c9 100755
--- a/bootloader/mrobe500.c
+++ b/bootloader/mrobe500.c
@@ -41,9 +41,59 @@
41#include "spi.h" 41#include "spi.h"
42#include "uart-target.h" 42#include "uart-target.h"
43#include "tsc2100.h" 43#include "tsc2100.h"
44#include "time.h"
44 45
45extern int line; 46extern int line;
46 47
48struct touch_calibration_point tl, br;
49
50void touchpad_get_one_point(struct touch_calibration_point *p)
51{
52 int data = 0;
53 int start = current_tick;
54 while (TIME_AFTER(start+(HZ/3), current_tick))
55 {
56 if (button_read_device()&BUTTON_TOUCHPAD)
57 {
58 data = button_get_last_touch();
59 p->val_x = data>>16;
60 p->val_y = data&0xffff;
61 start = current_tick;
62 }
63 else if (data == 0)
64 start = current_tick;
65 }
66}
67
68#define MARGIN 25
69#define LEN 7
70void touchpad_calibrate_screen(void)
71{
72 reset_screen();
73 printf("touch the center of the crosshairs to calibrate");
74 /* get the topleft value */
75 lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN);
76 lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN);
77 lcd_update();
78 tl.px_x = MARGIN; tl.px_y = MARGIN;
79 touchpad_get_one_point(&tl);
80 reset_screen();
81 printf("touch the center of the crosshairs to calibrate");
82 /* get the topright value */
83 lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN);
84 lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN);
85 lcd_update();
86 br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN;
87 touchpad_get_one_point(&br);
88 reset_screen();
89 line++;
90 printf("tl %d %d", tl.val_x, tl.val_y);
91 printf("br %d %d", br.val_x, br.val_y);
92 line++;
93 set_calibration_points(&tl, &br);
94}
95
96
47void main(void) 97void main(void)
48{ 98{
49 unsigned char* loadbuffer; 99 unsigned char* loadbuffer;
@@ -101,8 +151,14 @@ void main(void)
101 } 151 }
102#if 0 152#if 0
103 int button=0, *address=0x0, count=0; 153 int button=0, *address=0x0, count=0;
154 use_calibration(false);
155 touchpad_calibrate_screen();
156 use_calibration(true);
104 while(true) 157 while(true)
105 { 158 {
159 struct tm *t = get_time();
160 printf("%d:%d:%d %d %d %d", t->tm_hour, t->tm_min, t->tm_sec, t->tm_mday, t->tm_mon, t->tm_year);
161 printf("time: %d", mktime(t));
106 button = button_read_device(); 162 button = button_read_device();
107 if (button == BUTTON_POWER) 163 if (button == BUTTON_POWER)
108 { 164 {
@@ -119,26 +175,11 @@ void main(void)
119 address-=0x1000; 175 address-=0x1000;
120 if (button&BUTTON_TOUCHPAD) 176 if (button&BUTTON_TOUCHPAD)
121 { 177 {
122 int touch = button_get_last_touch(); 178 unsigned int data = button_get_last_touch();
123 printf("x: %d, y: %d", (touch>>16), touch&0xffff); 179 printf("x: %d, y: %d", data>>16, data&0xffff);
124 line--; 180 line-=3;
125 } 181 }
126// if ((IO_GIO_BITSET0&(1<<14) == 0) 182 else line -=2;
127// {
128// short x,y,z1,z2, reg;
129// extern int uart1count;
130// tsc2100_read_values(&x, &y, &z1, &z2);
131// printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
132// printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
133// printf("current tick: %04x", current_tick);
134// printf("Address: 0x%08x Data: 0x%08x", address, *address);
135// printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
136// printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
137// printf("uart1count: %d", uart1count);
138// printf("%x %x", IO_UART1_RFCR & 0x3f, IO_UART1_DTRR & 0xff);
139// tsc2100_keyclick(); /* doesnt work :( */
140// line -= 8;
141// }
142 } 183 }
143#endif 184#endif
144 printf("ATA"); 185 printf("ATA");
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
index b157ae2d12..c30422fc79 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
+++ b/firmware/target/arm/tms320dm320/mrobe-500/button-mr500.c
@@ -38,6 +38,36 @@
38 /* but always the same one for the session? */ 38 /* but always the same one for the session? */
39static short last_x, last_y, last_z1, last_z2; /* for the touch screen */ 39static short last_x, last_y, last_z1, last_z2; /* for the touch screen */
40static int last_touch; 40static int last_touch;
41
42static struct touch_calibration_point topleft, bottomright;
43static bool using_calibration = false;
44void use_calibration(bool enable)
45{
46 using_calibration = enable;
47}
48
49void set_calibration_points(struct touch_calibration_point *tl,
50 struct touch_calibration_point *br)
51{
52 memcpy(&topleft, tl, sizeof(struct touch_calibration_point));
53 memcpy(&bottomright, br, sizeof(struct touch_calibration_point));
54}
55static int touch_to_pixels(short val_x, short val_y)
56{
57 short x,y;
58 int x1,x2;
59 if (!using_calibration)
60 return (val_x<<16)|val_y;
61 x1 = topleft.val_x; x2 = bottomright.val_x;
62 x = (val_x-x1)*(bottomright.px_x - topleft.px_x) / (x2 - x1) + topleft.px_x;
63 x1 = topleft.val_y; x2 = bottomright.val_y;
64 y = (val_y-x1)*(bottomright.px_y - topleft.px_y) / (x2 - x1) + topleft.px_y;
65 if (x < 0)
66 x = 0;
67 if (y < 0)
68 y = 0;
69 return (x<<16)|y;
70}
41void button_init_device(void) 71void button_init_device(void)
42{ 72{
43 last_touch = 0; 73 last_touch = 0;
@@ -128,6 +158,6 @@ void GIO14(void)
128{ 158{
129 tsc2100_read_values(&last_x, &last_y, 159 tsc2100_read_values(&last_x, &last_y,
130 &last_z1, &last_z2); 160 &last_z1, &last_z2);
131 last_touch = (last_x<<16)|last_y; 161 last_touch = touch_to_pixels(last_x, last_y);
132 IO_INTC_IRQ2 = (1<<3); 162 IO_INTC_IRQ2 = (1<<3);
133} 163}
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/button-target.h b/firmware/target/arm/tms320dm320/mrobe-500/button-target.h
index f574321717..d1fd46c629 100644
--- a/firmware/target/arm/tms320dm320/mrobe-500/button-target.h
+++ b/firmware/target/arm/tms320dm320/mrobe-500/button-target.h
@@ -29,6 +29,14 @@ bool button_hold(void);
29void button_init_device(void); 29void button_init_device(void);
30int button_read_device(void); 30int button_read_device(void);
31 31
32struct touch_calibration_point {
33 short px_x; /* known pixel value */
34 short px_y;
35 short val_x; /* touchpad value at the known pixel */
36 short val_y;
37};
38void use_calibration(bool enable);
39
32/* m:robe 500 specific button codes */ 40/* m:robe 500 specific button codes */
33 41
34#define BUTTON_POWER 0x00000001 42#define BUTTON_POWER 0x00000001