Hi, I attach a patch with an updated driver and keyboard events driver. Now they autodetect the first available event driver of the correct kind. I tested them with microwindows 0.92. They should work also with nano-X + nxlib + fltk. Please note that this driver is a much simpler (and less powerful) alternative to tslib. Unlike tslib it doesn't provide filtering nor decimation, so the source must generate clean events. The good thing is that it's already integrated with mw. This patch includes also some other minor corrections to mw code. Any feedback/opinion is welcome Davide Rizzo
2011/7/23 <nanogui-digest-h...@linuxhacker.org> > > nanogui Digest 22 Jul 2011 23:34:15 -0000 Issue 1694 > > Topics (messages 13055 through 13055) > > microwindows touch screen using input event0 not working > 13055 by: Larry Samuels > > Administrivia: > > To subscribe to the digest, e-mail: > nanogui-digest-subscr...@linuxhacker.org > > To unsubscribe from the digest, e-mail: > nanogui-digest-unsubscr...@linuxhacker.org > > To post to the list, e-mail: > nanogui@linuxhacker.org > > > ---------------------------------------------------------------------- > > > > ---------- Messaggio inoltrato ---------- > From: Larry Samuels <lsamu...@pacemaster.com> > To: "nanogui@linuxhacker.org" <nanogui@linuxhacker.org> > Date: Fri, 22 Jul 2011 19:31:47 -0400 > Subject: microwindows touch screen using input event0 not working > Hello, > I am porting microwindows to an embedded system, and I am trying to get > the touchscreen to be read from microwindows demo apps. > I am using a patched file on microwindows v 0.92 to connect the > /dev/input/event0 to microwindows. > The patch is from: > http://www.linuxhacker.org/cgi-bin/ezmlm-cgi?5:msn:10843 > I can run microwindows apps on the target with debug info printed to the > console. > I see mouse touch events coming from mou_event.c (the new driver instead of > mou_touchscreen.c). > I see mouse touch events coming from devmouse.c (GrReadMouse displays new > x,y positions). > But, nxcal, nxscribble do not show any mouse events or movement. > Can you help me troubleshoot how to get applications to see the mouse > position, when the engine sees it? > My target is Samsung S3C2440 ARM9 processor with built in touch sensor. > > Regards, > Larry Samuels > > -- All difficult problems have a simple solution. That is wrong. [A. Einstein]
diff -urNp microwindows-0.92/src/config microwindows-0.92.eidos/src/config --- microwindows-0.92/src/config 2011-06-04 19:44:07.000000000 +0200 +++ microwindows-0.92.eidos/src/config 2011-06-21 12:59:58.428065350 +0200 @@ -316,6 +311,7 @@ PSP = N # NOMOUSE no mouse driver # # Touchscreen drivers +# EVENTMOUSE Standard event interface (/dev/input/event0) # IPAQMOUSE Compaq iPAQ, Intel Assabet (/dev/h3600_tsraw) # ZAURUSMOUSE Sharp Zaurus (/dev/sharp_ts) # TUXMOUSE TuxScreen (/dev/ucb1x00-ts) @@ -331,9 +327,10 @@ PSP = N # TTMOUSE TomTom GO and ONE (/dev/ts) #################################################################### GPMMOUSE = N -SERMOUSE = Y +SERMOUSE = N SUNMOUSE = N NOMOUSE = N +EVENTMOUSE = Y IPAQMOUSE = N ZAURUSMOUSE = N TUXMOUSE = N @@ -347,15 +344,16 @@ YOPYMOUSE = N HARRIERMOUSE = N LIRCMOUSE = N TSLIBMOUSE = N -TTMOUSE = N +TTMOUSE = N PSPMOUSE = N # keyboard or null kbd driver TTYKBD = N -SCANKBD = Y +SCANKBD = N PIPEKBD = N IPAQKBD = N LIRCKBD = N +EVENTKBD = Y NOKBD = N endif diff -urNp microwindows-0.92/src/drivers/genfont.hbf.c microwindows-0.92.eidos/src/drivers/genfont.hbf.c --- microwindows-0.92/src/drivers/genfont.hbf.c 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/drivers/genfont.hbf.c 2011-06-10 17:27:38.573099202 +0200 @@ -41,7 +41,10 @@ extern MWCFONT font_X5x7, font_X6x13; /* handling routines for MWCOREFONT*/ static MWFONTPROCS fontprocs = { + 0, MWTF_ASCII, /* routines expect ascii*/ + NULL, + NULL, gen_getfontinfo, gen_gettextsize, gen_gettextbits, @@ -50,6 +53,7 @@ static MWFONTPROCS fontprocs = { NULL, /* setfontsize*/ NULL, /* setfontrotation*/ NULL, /* setfontattr*/ + NULL }; /* diff -urNp microwindows-0.92/src/drivers/kbd_event.c microwindows-0.92.eidos/src/drivers/kbd_event.c --- microwindows-0.92/src/drivers/kbd_event.c 1970-01-01 01:00:00.000000000 +0100 +++ microwindows-0.92.eidos/src/drivers/kbd_event.c 2011-06-21 16:38:04.190565618 +0200 @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2008 Davide Rizzo <dav...@elpa.it> + * + * Keyboard Driver, standard input events version + */ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <linux/input.h> +#include "device.h" +#include "keymap_standard.h" + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +static int fd = -1; +static MWKEYMOD curmodif = 0, allmodif = 0; + +/* + * Open the keyboard. + */ +static int KBD_Open(KBDDEVICE *pkd) +{ + int i, r; + char fname[64]; + for (i = 0; i < 32; i++) + { + sprintf(fname, "/sys/class/input/event%d/device/capabilities/ev", i); + fd = open(fname, O_RDONLY); + if (fd < 0) + continue; + r = read(fd, fname, sizeof(fname)); + close(fd); + if (r <= 0) + continue; + fname[r - 1] = '\0'; + if ((strtoul(fname, NULL, 16) & (1 << EV_MSC)) == 0) + continue; + sprintf(fname, "/dev/input/event%d", i); + fd = open(fname, O_RDONLY | O_NONBLOCK); + if (fd < 0) + continue; + curmodif = 0; + /* TODO: Assign allmodif */ + allmodif = MWKMOD_LSHIFT | MWKMOD_RSHIFT| MWKMOD_LCTRL | + MWKMOD_RCTRL | MWKMOD_LALT | MWKMOD_RALT | + MWKMOD_LMETA | MWKMOD_RMETA | MWKMOD_NUM | + MWKMOD_CAPS | MWKMOD_ALTGR | MWKMOD_SCR; + return fd; + } + EPRINTF("Error %d opening keyboard input device\n", errno); + return errno; +} + +/* + * Close the keyboard. + */ +static void KBD_Close(void) +{ + if(fd >= 0) + close(fd); + fd = -1; +} + +/* + * Return the possible modifiers for the keyboard. + */ +static void KBD_GetModifierInfo(MWKEYMOD *modifiers, MWKEYMOD *curmodifiers) +{ + curmodif &= allmodif; + if (modifiers) + *modifiers = allmodif; + if (curmodifiers) + *curmodifiers = curmodif; +} + +/* + * This reads one keystroke from the keyboard, and the current state of + * the mode keys (ALT, SHIFT, CTRL). Returns -1 on error, 0 if no data + * is ready, and 1 if data was read. This is a non-blocking call. + */ +static int KBD_Read(MWKEY *buf, MWKEYMOD *modifiers, MWSCANCODE *pscancode) +{ + struct input_event event; + int bytes_read; + /* read a data point */ + while ((bytes_read = read(fd, &event, sizeof(event))) == sizeof(event)) + { + if (event.type == EV_KEY) + { + if (event.value) + { + switch (event.code) + { + case KEY_LEFTSHIFT: + curmodif |= MWKMOD_LSHIFT; + break; + case KEY_RIGHTSHIFT: + curmodif |= MWKMOD_RSHIFT; + break; + case KEY_LEFTCTRL: + curmodif |= MWKMOD_LCTRL; + break; + case KEY_RIGHTCTRL: + curmodif |= MWKMOD_RCTRL; + break; + case KEY_LEFTALT: + curmodif |= MWKMOD_LALT; + break; + case KEY_RIGHTALT: + curmodif |= MWKMOD_RALT; + break; + case KEY_LEFTMETA: + curmodif |= MWKMOD_LMETA; + break; + case KEY_RIGHTMETA: + curmodif |= MWKMOD_RMETA; + break; + case KEY_NUMLOCK: + curmodif |= MWKMOD_NUM; + break; + case KEY_CAPSLOCK: + curmodif |= MWKMOD_CAPS; + break; + case KEY_SCROLLLOCK: + curmodif |= MWKMOD_SCR; + break; + } + } + else + { + switch (event.code) + { + case KEY_LEFTSHIFT: + curmodif &= ~MWKMOD_LSHIFT; + break; + case KEY_RIGHTSHIFT: + curmodif &= ~MWKMOD_RSHIFT; + break; + case KEY_LEFTCTRL: + curmodif &= ~MWKMOD_LCTRL; + break; + case KEY_RIGHTCTRL: + curmodif &= ~MWKMOD_RCTRL; + break; + case KEY_LEFTALT: + curmodif &= ~MWKMOD_LALT; + break; + case KEY_RIGHTALT: + curmodif &= ~MWKMOD_RALT; + break; + case KEY_LEFTMETA: + curmodif &= ~MWKMOD_LMETA; + break; + case KEY_RIGHTMETA: + curmodif &= ~MWKMOD_RMETA; + break; + case KEY_NUMLOCK: + curmodif &= ~MWKMOD_NUM; + break; + case KEY_CAPSLOCK: + curmodif &= ~MWKMOD_CAPS; + break; + case KEY_SCROLLLOCK: + curmodif &= ~MWKMOD_SCR; + break; + } + } + if (*modifiers) + *modifiers = curmodif; + if (event.code < ARRAY_SIZE(keymap)) + { + *buf = keymap[event.code]; + *pscancode = event.code; + if (*buf == MWKEY_ESCAPE) + return -2; + return event.value ? 1 : 2; + } + } + } + if(bytes_read == -1) + { + if (errno == EINTR || errno == EAGAIN) return 0; + EPRINTF("Error %d reading from keyboard\n", errno); + return -1; + } + if(bytes_read != 0) + { + EPRINTF("Wrong number of bytes %d read from keyboard " + "(expected %d)\n", bytes_read, sizeof(event)); + return -1; + } + return 0; +} + +KBDDEVICE kbddev = { + KBD_Open, + KBD_Close, + KBD_GetModifierInfo, + KBD_Read, + NULL +}; + diff -urNp microwindows-0.92/src/drivers/mou_event.c microwindows-0.92.eidos/src/drivers/mou_event.c --- microwindows-0.92/src/drivers/mou_event.c 1970-01-01 01:00:00.000000000 +0100 +++ microwindows-0.92.eidos/src/drivers/mou_event.c 2011-06-21 16:38:04.200567377 +0200 @@ -0,0 +1,127 @@ +/* + * Generic event touchscreen driver + * + * Copyright (c) 2008, ELPA sas + * Written by Davide Rizzo <dav...@elpa.it> + */ + +#include <stdio.h> +#include <errno.h> +#include <unistd.h> +#include <fcntl.h> +#include <linux/input.h> +#include "device.h" + +#define TS_DEVICE "/dev/input/event0" + +extern SCREENDEVICE scrdev; +static int fd = -1; + +static int PD_Open(MOUSEDEVICE *pmd) +{ + int i, r; + char fname[64]; + for(i = 0; i < 32; i++) + { + sprintf(fname, "/sys/class/input/event%d/device/capabilities/ev", i); + fd = open(fname, O_RDONLY); + if(fd < 0) + continue; + r = read(fd, fname, sizeof(fname)); + close(fd); + if(r <= 0) + continue; + fname[r - 1] = '\0'; + if((strtoul(fname, NULL, 16) & (1 << EV_ABS)) == 0) + continue; + sprintf(fname, "/dev/input/event%d", i); + fd = open(fname, O_RDONLY | O_NONBLOCK); + if(fd < 0) + continue; + GdHideCursor(&scrdev); + return fd; + } + EPRINTF("Error %d opening keyboard input device\n", errno); + return errno; +} + +static void PD_Close(void) +{ + if(fd < 0) + return; + close(fd); + fd = -1; +} + +static int PD_GetButtonInfo(void) +{ + /* get "mouse" buttons supported */ + return MWBUTTON_L; +} + +static void PD_GetDefaultAccel(int *pscale,int *pthresh) +{ + *pscale = 3; + *pthresh = 5; +} + +static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb) +{ + struct input_event event; + int bytes_read; + static int x, y, z; + /* read a data point */ + while((bytes_read = read(fd, &event, sizeof(event))) == sizeof(event)) + { + switch(event.type) + { + case EV_ABS: + switch(event.code) + { + case ABS_X: + x = event.value; + break; + case ABS_Y: + y = event.value; + break; + } + break; + case EV_KEY: + if(event.code == BTN_TOUCH) + z = event.value; + break; + case EV_SYN: + *px = x; + *py = y; + *pb = z ? MWBUTTON_L : 0; + *pz = z; + if(!*pb) + return 3; + return 2; + break; + } + } + if(bytes_read == -1) + { + if(errno == EINTR || errno == EAGAIN) return 0; + EPRINTF("[%s] Error %d reading from touch panel\n", TS_DEVICE, errno); + return -1; + } + if(bytes_read != 0) + { + EPRINTF("[%s] Wrong number of bytes %d read from touch panel " + "(expected %d)\n", TS_DEVICE, bytes_read, sizeof(event)); + return -1; + } + return 0; +} + +MOUSEDEVICE mousedev = { + PD_Open, + PD_Close, + PD_GetButtonInfo, + PD_GetDefaultAccel, + PD_Read, + NULL, + MOUSE_TRANSFORM /* Input filter flags */ +}; diff -urNp microwindows-0.92/src/drivers/nofont.c microwindows-0.92.eidos/src/drivers/nofont.c --- microwindows-0.92/src/drivers/nofont.c 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/drivers/nofont.c 2011-06-10 17:31:13.905599450 +0200 @@ -17,6 +17,7 @@ static MWCFONT nullfont = { /* handling routines for MWCOREFONT*/ static MWFONTPROCS fontprocs = { + 0, MWTF_ASCII, /* routines expect ascii*/ NULL, /* getfontinfo*/ NULL, /* gettextsize*/ diff -urNp microwindows-0.92/src/drivers/Objects.rules microwindows-0.92.eidos/src/drivers/Objects.rules --- microwindows-0.92/src/drivers/Objects.rules 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/drivers/Objects.rules 2011-06-21 13:02:01.828065546 +0200 @@ -176,6 +176,11 @@ CFLAGS += -DTOUCHSCREEN_ADS7846=1 MW_CORE_OBJS += $(MW_DIR_OBJ)/drivers/mou_touchscreen.o endif +ifeq ($(EVENTMOUSE), Y) +CFLAGS += -DTOUCHSCREEN_EVENT=1 +MW_CORE_OBJS += $(MW_DIR_OBJ)/drivers/mou_event.o +endif + ifeq ($(IPAQMOUSE), Y) CFLAGS += -DTOUCHSCREEN_IPAQ=1 MW_CORE_OBJS += $(MW_DIR_OBJ)/drivers/mou_touchscreen.o @@ -272,6 +277,10 @@ ifeq ($(SCANKBD), Y) MW_CORE_OBJS += $(MW_DIR_OBJ)/drivers/kbd_ttyscan.o endif +ifeq ($(EVENTKBD), Y) +MW_CORE_OBJS += $(MW_DIR_OBJ)/drivers/kbd_event.o +endif + ifeq ($(ARCH), FREEBSD-X86) #MW_CORE_OBJS += $(MW_DIR_OBJ)/drivers/kbd_fbsd.o MW_CORE_OBJS += $(MW_DIR_OBJ)/drivers/kbd_tty.o diff -urNp microwindows-0.92/src/drivers/romfont.c microwindows-0.92.eidos/src/drivers/romfont.c --- microwindows-0.92/src/drivers/romfont.c 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/drivers/romfont.c 2011-06-10 17:32:07.985598882 +0200 @@ -23,7 +23,10 @@ FARADDR rom_char_addr; /* handling routines for core rom fonts*/ static MWFONTPROCS fontprocs = { + 0, MWTF_ASCII, /* routines expect ascii*/ + NULL, + NULL, pcrom_getfontinfo, pcrom_gettextsize, pcrom_gettextbits, @@ -32,6 +35,7 @@ static MWFONTPROCS fontprocs = { NULL, /* setfontsize*/ NULL, /* setfontrotation*/ NULL, /* setfontattr*/ + NULL }; /* first font is default font*/ diff -urNp microwindows-0.92/src/engine/devfont.c microwindows-0.92.eidos/src/engine/devfont.c --- microwindows-0.92/src/engine/devfont.c 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/engine/devfont.c 2011-04-26 14:02:24.862755946 +0200 @@ -473,6 +473,8 @@ GdText(PSD psd, MWCOORD x, MWCOORD y, co /* allocate enough for output string utf8/uc32 is max 4 bytes, uc16 max 2*/ buf = ALLOCA(cc * 4); cc = GdConvertEncoding(str, flags, cc, buf, defencoding); + if(cc <= 0) + return; flags &= ~MWTF_PACKMASK; /* keep DBCS bits for drawtext*/ flags |= defencoding; text = buf; diff -urNp microwindows-0.92/src/engine/devmouse.c microwindows-0.92.eidos/src/engine/devmouse.c --- microwindows-0.92/src/engine/devmouse.c 2010-05-24 02:31:25.000000000 +0200 +++ microwindows-0.92.eidos/src/engine/devmouse.c 2011-04-26 14:03:45.312756505 +0200 @@ -526,7 +526,7 @@ GdFixCursor(PSD psd) } /* Input filter routines - global mouse filtering is cool */ -#define JITTER_SHIFT_BITS 2 +#define JITTER_SHIFT_BITS 0 #define JITTER_DEPTH (1 << (JITTER_SHIFT_BITS)) static MWTRANSFORM g_trans; /* current transform*/ @@ -639,7 +639,7 @@ filter_absrotate(int state, int *xpos, i break; case MWPORTRAIT_DOWN: - *xpos = x; + *xpos = scrdev.xres - x - 1; *ypos = scrdev.yres - y - 1; break; diff -urNp microwindows-0.92/src/engine/font_eucjp.c microwindows-0.92.eidos/src/engine/font_eucjp.c --- microwindows-0.92/src/engine/font_eucjp.c 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/engine/font_eucjp.c 2011-05-24 17:51:12.156103882 +0200 @@ -56,6 +56,7 @@ static void eucjp_destroyfont(PMWFONT pf /* handling routines for MWEUCJPFONT*/ static MWFONTPROCS eucjp_procs = { + 0, MWTF_UC16, /* routines expect unicode index*/ NULL, /* init*/ eucjp_createfont, diff -urNp microwindows-0.92/src/engine/font_freetype.cache.c microwindows-0.92.eidos/src/engine/font_freetype.cache.c --- microwindows-0.92/src/engine/font_freetype.cache.c 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/engine/font_freetype.cache.c 2011-06-10 17:34:09.823100812 +0200 @@ -352,6 +352,7 @@ static int freetype_setfontattr(PMWFONT /* handling routines for MWFREETYPEFONT*/ static MWFONTPROCS freetype_procs = { + 0, MWTF_UC16, /* routines expect unicode 16*/ freetype_init, freetype_createfont, diff -urNp microwindows-0.92/src/mwin/winuser.c microwindows-0.92.eidos/src/mwin/winuser.c --- microwindows-0.92/src/mwin/winuser.c 2010-11-23 05:06:23.000000000 +0100 +++ microwindows-0.92.eidos/src/mwin/winuser.c 2011-05-24 16:53:59.128604164 +0200 @@ -462,8 +462,8 @@ MwDestroyWindow(HWND hwnd,BOOL bSendMsg) if (wp == rootwp) return; -DPRINTF("DESTROY %d\n", wp); -DPRINTF("ROOT CHILD %d\n", rootwp->children); +//DPRINTF("DESTROY %d\n", wp); +//DPRINTF("ROOT CHILD %d\n", rootwp->children); /* * Unmap the window. */
--------------------------------------------------------------------- To unsubscribe, e-mail: nanogui-unsubscr...@linuxhacker.org For additional commands, e-mail: nanogui-h...@linuxhacker.org