1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Jonathan Gordon 2007-10-01 07:52:39 +00:00
parent f8ada4b9c1
commit 274c2b8d69
3 changed files with 99 additions and 20 deletions

View file

@ -41,9 +41,59 @@
#include "spi.h"
#include "uart-target.h"
#include "tsc2100.h"
#include "time.h"
extern int line;
struct touch_calibration_point tl, br;
void touchpad_get_one_point(struct touch_calibration_point *p)
{
int data = 0;
int start = current_tick;
while (TIME_AFTER(start+(HZ/3), current_tick))
{
if (button_read_device()&BUTTON_TOUCHPAD)
{
data = button_get_last_touch();
p->val_x = data>>16;
p->val_y = data&0xffff;
start = current_tick;
}
else if (data == 0)
start = current_tick;
}
}
#define MARGIN 25
#define LEN 7
void touchpad_calibrate_screen(void)
{
reset_screen();
printf("touch the center of the crosshairs to calibrate");
/* get the topleft value */
lcd_hline(MARGIN-LEN, MARGIN+LEN, MARGIN);
lcd_vline(MARGIN, MARGIN-LEN, MARGIN+LEN);
lcd_update();
tl.px_x = MARGIN; tl.px_y = MARGIN;
touchpad_get_one_point(&tl);
reset_screen();
printf("touch the center of the crosshairs to calibrate");
/* get the topright value */
lcd_hline(LCD_WIDTH-MARGIN-LEN, LCD_WIDTH-MARGIN+LEN, LCD_HEIGHT-MARGIN);
lcd_vline(LCD_WIDTH-MARGIN, LCD_HEIGHT-MARGIN-LEN, LCD_HEIGHT-MARGIN+LEN);
lcd_update();
br.px_x = LCD_WIDTH-MARGIN; br.px_y = LCD_HEIGHT-MARGIN;
touchpad_get_one_point(&br);
reset_screen();
line++;
printf("tl %d %d", tl.val_x, tl.val_y);
printf("br %d %d", br.val_x, br.val_y);
line++;
set_calibration_points(&tl, &br);
}
void main(void)
{
unsigned char* loadbuffer;
@ -101,8 +151,14 @@ void main(void)
}
#if 0
int button=0, *address=0x0, count=0;
use_calibration(false);
touchpad_calibrate_screen();
use_calibration(true);
while(true)
{
struct tm *t = get_time();
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);
printf("time: %d", mktime(t));
button = button_read_device();
if (button == BUTTON_POWER)
{
@ -119,26 +175,11 @@ void main(void)
address-=0x1000;
if (button&BUTTON_TOUCHPAD)
{
int touch = button_get_last_touch();
printf("x: %d, y: %d", (touch>>16), touch&0xffff);
line--;
unsigned int data = button_get_last_touch();
printf("x: %d, y: %d", data>>16, data&0xffff);
line-=3;
}
// if ((IO_GIO_BITSET0&(1<<14) == 0)
// {
// short x,y,z1,z2, reg;
// extern int uart1count;
// tsc2100_read_values(&x, &y, &z1, &z2);
// printf("x: %04x y: %04x z1: %04x z2: %04x", x, y, z1, z2);
// printf("tsadc: %4x", tsc2100_readreg(TSADC_PAGE, TSADC_ADDRESS)&0xffff);
// printf("current tick: %04x", current_tick);
// printf("Address: 0x%08x Data: 0x%08x", address, *address);
// printf("Address: 0x%08x Data: 0x%08x", address+1, *(address+1));
// printf("Address: 0x%08x Data: 0x%08x", address+2, *(address+2));
// printf("uart1count: %d", uart1count);
// printf("%x %x", IO_UART1_RFCR & 0x3f, IO_UART1_DTRR & 0xff);
// tsc2100_keyclick(); /* doesnt work :( */
// line -= 8;
// }
else line -=2;
}
#endif
printf("ATA");

View file

@ -38,6 +38,36 @@
/* but always the same one for the session? */
static short last_x, last_y, last_z1, last_z2; /* for the touch screen */
static int last_touch;
static struct touch_calibration_point topleft, bottomright;
static bool using_calibration = false;
void use_calibration(bool enable)
{
using_calibration = enable;
}
void set_calibration_points(struct touch_calibration_point *tl,
struct touch_calibration_point *br)
{
memcpy(&topleft, tl, sizeof(struct touch_calibration_point));
memcpy(&bottomright, br, sizeof(struct touch_calibration_point));
}
static int touch_to_pixels(short val_x, short val_y)
{
short x,y;
int x1,x2;
if (!using_calibration)
return (val_x<<16)|val_y;
x1 = topleft.val_x; x2 = bottomright.val_x;
x = (val_x-x1)*(bottomright.px_x - topleft.px_x) / (x2 - x1) + topleft.px_x;
x1 = topleft.val_y; x2 = bottomright.val_y;
y = (val_y-x1)*(bottomright.px_y - topleft.px_y) / (x2 - x1) + topleft.px_y;
if (x < 0)
x = 0;
if (y < 0)
y = 0;
return (x<<16)|y;
}
void button_init_device(void)
{
last_touch = 0;
@ -128,6 +158,6 @@ void GIO14(void)
{
tsc2100_read_values(&last_x, &last_y,
&last_z1, &last_z2);
last_touch = (last_x<<16)|last_y;
last_touch = touch_to_pixels(last_x, last_y);
IO_INTC_IRQ2 = (1<<3);
}

View file

@ -29,6 +29,14 @@ bool button_hold(void);
void button_init_device(void);
int button_read_device(void);
struct touch_calibration_point {
short px_x; /* known pixel value */
short px_y;
short val_x; /* touchpad value at the known pixel */
short val_y;
};
void use_calibration(bool enable);
/* m:robe 500 specific button codes */
#define BUTTON_POWER 0x00000001