some ts support, currently for Pico only
authornotaz <notasas@gmail.com>
Sun, 6 Jul 2008 22:39:21 +0000 (22:39 +0000)
committernotaz <notasas@gmail.com>
Sun, 6 Jul 2008 22:39:21 +0000 (22:39 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@531 be3aeb3a-fb24-0410-a615-afba39da0efa

platform/gp2x/emu.c
platform/gp2x/gp2x.c
platform/gp2x/gp2x.h
platform/linux/gp2x.c

index 19f3c67..570b0fc 100644 (file)
@@ -436,13 +436,16 @@ static void emu_msg_tray_open(void)
 \r
 static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
 {\r
+       int ret, px, py;\r
+       static int pdown_frames = 0;\r
+\r
        emu_RunEventsPico(events);\r
 \r
        if (pico_inp_mode != 0)\r
        {\r
                PicoPad[0] &= ~0x0f; // release UDLR\r
-               if (gp2x_keys & GP2X_UP)   { pico_pen_y--; if (pico_pen_y < 0) pico_pen_y = 0; }\r
-               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; }\r
+               if (gp2x_keys & GP2X_UP)   { pico_pen_y--; if (pico_pen_y < 8) pico_pen_y = 8; }\r
+               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; }\r
                if (gp2x_keys & GP2X_LEFT) { pico_pen_x--; if (pico_pen_x < 0) pico_pen_x = 0; }\r
                if (gp2x_keys & GP2X_RIGHT) {\r
                        int lim = (Pico.video.reg[12]&1) ? 319 : 255;\r
@@ -455,6 +458,29 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)
                PicoPicohw.pen_pos[0] += 0x3c;\r
                PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
        }\r
+\r
+       // for F200\r
+       ret = gp2x_touchpad_read(&px, &py);\r
+       if (ret >= 0) {\r
+               if (ret > 5000) {\r
+                       if (pdown_frames++ > 5)\r
+                               PicoPad[0] |= 0x20;\r
+\r
+                       pico_pen_x = px;\r
+                       pico_pen_y = py;\r
+                       if (!(Pico.video.reg[12]&1)) {\r
+                               pico_pen_x -= 32;\r
+                               if (pico_pen_x <   0) pico_pen_x = 0;\r
+                               if (pico_pen_x > 248) pico_pen_x = 248;\r
+                       }\r
+                       if (pico_pen_y > 224) pico_pen_y = 224;\r
+               }\r
+               else\r
+                       pdown_frames= 0;\r
+\r
+               //if (ret == 0)\r
+               //      PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
+       }\r
 }\r
 \r
 static void update_volume(int has_changed, int is_up)\r
index 7706e41..78e8561 100644 (file)
@@ -44,7 +44,8 @@ static void *gp2x_screens[4];
 static int screensel = 0;\r
 //static\r
 int memdev = 0;\r
-static int sounddev = 0, mixerdev = 0;\r
+static int sounddev = -1, mixerdev = -1, touchdev = -1;\r
+static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };\r
 \r
 void *gp2x_screen;\r
 \r
@@ -218,6 +219,36 @@ unsigned long gp2x_joystick_read(int allow_usb_joy)
        return value;\r
 }\r
 \r
+typedef struct ucb1x00_ts_event\r
+{\r
+       unsigned short pressure;\r
+       unsigned short x;\r
+       unsigned short y;\r
+       unsigned short pad;\r
+       struct timeval stamp;\r
+} UCB1X00_TS_EVENT;\r
+\r
+int gp2x_touchpad_read(int *x, int *y)\r
+{\r
+       UCB1X00_TS_EVENT event;\r
+       int retval;\r
+\r
+       if (touchdev < 0) return -1;\r
+\r
+       retval = read(touchdev, &event, sizeof(event));\r
+       if (retval < 0) {\r
+               printf("touch read failed %i %i\n", retval, errno);\r
+               return -1;\r
+       }\r
+\r
+       if (x) *x = (event.x * touchcal[0] + touchcal[2]) >> 16;\r
+       if (y) *y = (event.y * touchcal[4] + touchcal[5]) >> 16;\r
+       // printf("read %i %i %i\n", event.pressure, *x, *y);\r
+\r
+       return event.pressure;\r
+}\r
+\r
+\r
 static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0;\r
 \r
 void gp2x_start_sound(int rate, int bits, int stereo)\r
@@ -364,6 +395,18 @@ void gp2x_init(void)
        /* init usb joys -GnoStiC */\r
        gp2x_usbjoy_init();\r
 \r
+       // touchscreen\r
+       touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY);\r
+       if (touchdev >= 0) {\r
+               FILE *pcf = fopen("/etc/pointercal", "r");\r
+               if (pcf) {\r
+                       fscanf(pcf, "%d %d %d %d %d %d %d", &touchcal[0], &touchcal[1],\r
+                               &touchcal[2], &touchcal[3], &touchcal[4], &touchcal[5], &touchcal[6]);\r
+                       fclose(pcf);\r
+               }\r
+               printf("found touchscreen/wm97xx\n");\r
+       }\r
+\r
        /* disable Linux read-ahead */\r
        proc_set("/proc/sys/vm/max-readahead", "0\n");\r
        proc_set("/proc/sys/vm/min-readahead", "0\n");\r
@@ -388,7 +431,8 @@ void gp2x_deinit(void)
        munmap((void *)gp2x_memregs, 0x10000);\r
        close(memdev);\r
        close(mixerdev);\r
-       if (sounddev > 0) close(sounddev);\r
+       if (sounddev >= 0) close(sounddev);\r
+       if (touchdev >= 0) close(touchdev);\r
 \r
        gp2x_usbjoy_deinit();\r
 \r
index 2d2e535..f9aa851 100644 (file)
@@ -25,8 +25,9 @@ void gp2x_start_sound(int rate, int bits, int stereo);
 void gp2x_sound_write(void *buff, int len);\r
 void gp2x_sound_volume(int l, int r);\r
 \r
-/* joy */\r
+/* input */\r
 unsigned long gp2x_joystick_read(int allow_usb_joy);\r
+int gp2x_touchpad_read(int *x, int *y);\r
 \r
 /* 940 core */\r
 void Pause940(int yes);\r
index c552ad1..ef21a67 100644 (file)
@@ -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)