From 3f2aaff20c940e90e970c008e56f5253d494a92c Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 6 Jul 2008 22:39:21 +0000 Subject: [PATCH] some ts support, currently for Pico only git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@531 be3aeb3a-fb24-0410-a615-afba39da0efa --- gp2x/emu.c | 30 ++++++++++++++++++++++++++++-- gp2x/gp2x.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- gp2x/gp2x.h | 3 ++- linux/gp2x.c | 5 +++++ 4 files changed, 81 insertions(+), 5 deletions(-) diff --git a/gp2x/emu.c b/gp2x/emu.c index 19f3c67..570b0fc 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -436,13 +436,16 @@ static void emu_msg_tray_open(void) static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) { + int ret, px, py; + static int pdown_frames = 0; + emu_RunEventsPico(events); if (pico_inp_mode != 0) { PicoPad[0] &= ~0x0f; // release UDLR - if (gp2x_keys & GP2X_UP) { pico_pen_y--; if (pico_pen_y < 0) pico_pen_y = 0; } - if (gp2x_keys & GP2X_DOWN) { pico_pen_y++; if (pico_pen_y > 239-PICO_PEN_ADJUST_Y) pico_pen_y = 239-PICO_PEN_ADJUST_Y; } + if (gp2x_keys & GP2X_UP) { pico_pen_y--; if (pico_pen_y < 8) pico_pen_y = 8; } + if (gp2x_keys & GP2X_DOWN) { pico_pen_y++; if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y; } if (gp2x_keys & GP2X_LEFT) { pico_pen_x--; if (pico_pen_x < 0) pico_pen_x = 0; } if (gp2x_keys & GP2X_RIGHT) { int lim = (Pico.video.reg[12]&1) ? 319 : 255; @@ -455,6 +458,29 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys) PicoPicohw.pen_pos[0] += 0x3c; PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y); } + + // for F200 + ret = gp2x_touchpad_read(&px, &py); + if (ret >= 0) { + if (ret > 5000) { + if (pdown_frames++ > 5) + PicoPad[0] |= 0x20; + + pico_pen_x = px; + pico_pen_y = py; + if (!(Pico.video.reg[12]&1)) { + pico_pen_x -= 32; + if (pico_pen_x < 0) pico_pen_x = 0; + if (pico_pen_x > 248) pico_pen_x = 248; + } + if (pico_pen_y > 224) pico_pen_y = 224; + } + else + pdown_frames= 0; + + //if (ret == 0) + // PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000; + } } static void update_volume(int has_changed, int is_up) diff --git a/gp2x/gp2x.c b/gp2x/gp2x.c index 7706e41..78e8561 100644 --- a/gp2x/gp2x.c +++ b/gp2x/gp2x.c @@ -44,7 +44,8 @@ static void *gp2x_screens[4]; static int screensel = 0; //static int memdev = 0; -static int sounddev = 0, mixerdev = 0; +static int sounddev = -1, mixerdev = -1, touchdev = -1; +static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 }; void *gp2x_screen; @@ -218,6 +219,36 @@ unsigned long gp2x_joystick_read(int allow_usb_joy) return value; } +typedef struct ucb1x00_ts_event +{ + unsigned short pressure; + unsigned short x; + unsigned short y; + unsigned short pad; + struct timeval stamp; +} UCB1X00_TS_EVENT; + +int gp2x_touchpad_read(int *x, int *y) +{ + UCB1X00_TS_EVENT event; + int retval; + + if (touchdev < 0) return -1; + + retval = read(touchdev, &event, sizeof(event)); + if (retval < 0) { + printf("touch read failed %i %i\n", retval, errno); + return -1; + } + + if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16; + if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16; + // printf("read %i %i %i\n", event.pressure, *x, *y); + + return event.pressure; +} + + static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0; void gp2x_start_sound(int rate, int bits, int stereo) @@ -364,6 +395,18 @@ void gp2x_init(void) /* init usb joys -GnoStiC */ gp2x_usbjoy_init(); + // touchscreen + touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY); + if (touchdev >= 0) { + FILE *pcf = fopen("/etc/pointercal", "r"); + if (pcf) { + fscanf(pcf, "%d %d %d %d %d %d %d", &touchcal[0], &touchcal[1], + &touchcal[2], &touchcal[3], &touchcal[4], &touchcal[5], &touchcal[6]); + fclose(pcf); + } + printf("found touchscreen/wm97xx\n"); + } + /* disable Linux read-ahead */ proc_set("/proc/sys/vm/max-readahead", "0\n"); proc_set("/proc/sys/vm/min-readahead", "0\n"); @@ -388,7 +431,8 @@ void gp2x_deinit(void) munmap((void *)gp2x_memregs, 0x10000); close(memdev); close(mixerdev); - if (sounddev > 0) close(sounddev); + if (sounddev >= 0) close(sounddev); + if (touchdev >= 0) close(touchdev); gp2x_usbjoy_deinit(); diff --git a/gp2x/gp2x.h b/gp2x/gp2x.h index 2d2e535..f9aa851 100644 --- a/gp2x/gp2x.h +++ b/gp2x/gp2x.h @@ -25,8 +25,9 @@ void gp2x_start_sound(int rate, int bits, int stereo); void gp2x_sound_write(void *buff, int len); void gp2x_sound_volume(int l, int r); -/* joy */ +/* input */ unsigned long gp2x_joystick_read(int allow_usb_joy); +int gp2x_touchpad_read(int *x, int *y); /* 940 core */ void Pause940(int yes); diff --git a/linux/gp2x.c b/linux/gp2x.c index c552ad1..ef21a67 100644 --- a/linux/gp2x.c +++ b/linux/gp2x.c @@ -368,6 +368,11 @@ unsigned long gp2x_joystick_read(int allow_usb_joy) return value; } +int gp2x_touchpad_read(int *x, int *y) +{ + return -1; +} + /* 940 */ int crashed_940 = 0; void Pause940(int yes) -- 2.39.5