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
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
+ static int zero_seen = 0;\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
+ // this is to ignore the messed-up 4.1.x driver\r
+ if (event.pressure == 0) zero_seen = 1;\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 zero_seen ? event.pressure : 0;\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
/* 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
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