diff -urN -X exclude xserver-old/xserver/hw/kdrive/linux/Imakefile xserver/xserver/hw/kdrive/linux/Imakefile --- xserver-old/xserver/hw/kdrive/linux/Imakefile 2003-07-07 21:12:59.000000000 +0200 +++ xserver/xserver/hw/kdrive/linux/Imakefile 2003-12-03 17:54:50.000000000 +0100 @@ -12,10 +12,14 @@ TSOBJS = ts.o #endif #endif +#if STOUCH +STSRCS = stouch.c +STOBJS = stouch.o +#endif -SRCS = keyboard.c linux.c mouse.c ps2.c bus.c ms.c agp.c $(TSSRCS) +SRCS = keyboard.c linux.c mouse.c ps2.c bus.c ms.c agp.c $(TSSRCS) $(STSRCS) -OBJS = keyboard.o linux.o mouse.o ps2.o bus.o ms.o agp.o $(TSOBJS) +OBJS = keyboard.o linux.o mouse.o ps2.o bus.o ms.o agp.o $(TSOBJS) $(STOBJS) INCLUDES = -I. $(KDINCS) diff -urN -X exclude xserver-old/xserver/hw/kdrive/linux/Makefile.am xserver/xserver/hw/kdrive/linux/Makefile.am --- xserver-old/xserver/hw/kdrive/linux/Makefile.am 2003-11-11 06:46:10.000000000 +0100 +++ xserver/xserver/hw/kdrive/linux/Makefile.am 2003-12-04 09:08:43.000000000 +0100 @@ -13,6 +13,10 @@ TS_C = ts.c endif +if STOUCH +ST_C = stouch.c +endif + liblinux_a_SOURCES = \ agp.c \ agp.h \ @@ -24,7 +28,8 @@ ms.c \ ps2.c \ $(TSLIB_C) \ - $(TS_C) + $(TS_C) \ + $(ST_C) liblinux_a_DEPENDENCIES = \ agp.c \ @@ -35,5 +40,5 @@ ms.c \ ps2.c \ $(TSLIB_C) \ - $(TS_C) - + $(TS_C) \ + $(ST_C) diff -urN -X exclude xserver-old/xserver/hw/kdrive/linux/stouch.c xserver/xserver/hw/kdrive/linux/stouch.c --- xserver-old/xserver/hw/kdrive/linux/stouch.c 1970-01-01 01:00:00.000000000 +0100 +++ xserver/xserver/hw/kdrive/linux/stouch.c 2003-12-04 17:47:06.000000000 +0100 @@ -0,0 +1,268 @@ +/* + * Derived from ts.c by Keith Packard + * + * Copyright © 2003 Andrew Christian + * Copyright © 2003 Hewlett-Packard Company + * + * Maintained by Robert Woerle + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Andrew Christian or HP not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Andrew Christian and HP makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * ANDREW CHRISTIAN AND HP DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, + * IN NO EVENT SHALL ANDREW CHRISTIAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#define NEED_EVENTS +#include +#include +#include "inputstr.h" +#include "scrnintstr.h" +#include "kdrive.h" +#include +#include +#include + +#include +#include + +#include "stouch.h" +/*typedef struct _Tc_SoftButton { + unsigned char scancode; + int xmin; + int xmax; +} Tc_SoftButton; +*/ +/*static Tc_SoftButton soft_buttons[] = { + { 113, 1140, 1500 }, */ /* F13 */ + /* { 114, 1640, 1960 }, */ /* F14 */ + /* { 117, 2120, 2450 } */ /* F17 */ +/*};*/ + +#define NUM_SOFTBUTTONS 3 + +typedef struct _Tc_Calibration { + int width; + int height; + int x; + int y; +} Tc_Calibration; + +static Tc_Calibration TcCal = { 1008, 995, 19, 42}; + +extern ScreenPtr KdTsPhyScreenPtr; + +void +KdSetTcCalibration( int width, int height, int x, int y ) +{ + printf(" Set calib\n"); + + if ( width > 0 ) + TcCal.width = width; + if ( height > 0 ) + TcCal.height = height; + TcCal.x = x; + TcCal.y = y; +} + +/* + The TC1000 touchscreen packet is five bytes: + FLAG HIGHX LOWX HIGHY LOWY + Only the FLAG byte has the high bit set. +*/ + +static int +STouchReadBytes (int fd, char *buf, int len) +{ + int n, tot; + fd_set set; + struct timeval tv; + int min; + + min = len; + tot = 0; + while (len) + { + n = read (fd, buf, len); + if (n > 0) + { + tot += n; + buf += n; + len -= n; + } + if (tot % min == 0) + break; + FD_ZERO (&set); + FD_SET (fd, &set); + tv.tv_sec = 0; + tv.tv_usec = 100 * 1000; + n = select (fd + 1, &set, 0, 0, &tv); + if (n <= 0) + break; + } + return tot; +} + +#define STOUCH_EVENT_SIZE 5 +#define MESSAGE_START_FLAG 0x80 +#define SWITCH_STATUS_CHANGE 0x40 /* Set when switch will change */ +#define PROXIMITY_START 0x20 /* Only 0 on first event */ +#define SOFT_BUTTONS 0x10 /* Set when in soft button area */ +#define PEN_SIDE_SWITCH 0x02 +#define TOUCH_SWITCH1 0xff +#define TOUCH_SWTICH2 0xbf + +int g_lastbutton = -1; +/* +static int +TcUpdateSoftButtons( int btn ) +{ + if ( btn == g_lastbutton ) + return; + + if ( g_lastbutton >= 0 ) + KdEnqueueKeyboardEvent( soft_buttons[g_lastbutton].scancode, 1);*/ /* Release old */ +/* + if ( btn >= 0 ) + KdEnqueueKeyboardEvent( soft_buttons[btn].scancode, 0);*/ /* Press new */ + + /* g_lastbutton = btn; +} +*/ +void +STouchRead (int tsPort, void *closure) +{ + /* KdMouseInfo *mi=closure; + */ unsigned char buf[STOUCH_EVENT_SIZE]; + int n, trans; + long x, y, tmp; + int width, height; + unsigned long flags; + n = STouchReadBytes (tsPort, buf, STOUCH_EVENT_SIZE ); + if (n == STOUCH_EVENT_SIZE) + { + + x = (buf[1] & 0x7f) | (((unsigned int) (buf[2] & 0x7f)) << 7); + y = (buf[3] & 0x7f) | (((unsigned int) (buf[4] & 0x7f)) << 7); + + fprintf(stderr,"\t%x \n",buf[0]); + /* This is remarkably ugly + TODO: Get orientattion from randr IF we need ? do we ? */ + if ( KdTsPhyScreenPtr->width < KdTsPhyScreenPtr->height ) { + height = KdTsPhyScreenPtr->width; + width = KdTsPhyScreenPtr->height; + } + else { + width = KdTsPhyScreenPtr->width; + height = KdTsPhyScreenPtr->height; + } + + /* fprintf(stderr,"X %d Y %d\n",x,y); + */ x = ((x - TcCal.x) * width) / (TcCal.width - TcCal.x); + y = ((y - TcCal.y) * height) / (TcCal.height - TcCal.y); + /* fprintf(stderr,"calib X %d Y %d\n",x,y); + */ /* Never send raw coord`s */ +/* if (kdMouseInfo->transformCoordinates == 0) { + trans = 0 ; + kdMouseInfo->transformCoordinates = 1; + } + */ flags = 0; + if (buf[0] == TOUCH_SWITCH1) + { + flags = KD_BUTTON_1; + KdEnqueueMouseEvent (kdMouseInfo, flags, x,y); + /* fprintf(stderr,"Flagt %x \n\n",flags); + */ tmp = buf[0]; + } + else + { + if (tmp == TOUCH_SWITCH1) + flags = 0; + KdEnqueueMouseEvent (kdMouseInfo, flags, x, y); +/* fprintf(stderr,"Flag %d\n\n",flags); +*/ tmp = buf[0]; + } + /* write back orig transform flag */ + if (trans == 0 ) { + /* kdMouseInfo->transformCoordinates = 0; + */ } + } +} + +void +STouchInitPort (int fd) +{ + struct termios t; + + tcgetattr (fd, &t); + + t.c_cflag = CS8 | CREAD | HUPCL | CLOCAL; + t.c_iflag = IGNBRK | IGNPAR; + t.c_oflag = 0; + t.c_lflag = 0; + t.c_cc[VMIN ] = 10; + t.c_cc[VTIME] = 0; + + cfsetispeed (&t, B19200); + cfsetospeed (&t, B19200); + + tcsetattr (fd, TCSANOW, &t); +} + +int STouchInputType; + +int +STouchInit (void) +{ + int fd; + char *device = "/dev/ttyS0"; + + if (!STouchInputType) + STouchInputType = KdAllocInputType (); + + fd = open (device, O_RDONLY | O_NONBLOCK); + if (fd < 0) { + fprintf(stderr,"Couldn't open %s (%d)\n", device, (int)errno); + return 0; + } + + if (fd == 0) { + fprintf(stderr,"Opening %s returned 0!\n", device); + goto bail; + } + + if (!isatty(fd)) { + fprintf(stderr,"%s is not a tty\n", device); + goto bail; + } + STouchInitPort (fd); + + if (KdRegisterFd (STouchInputType, fd, STouchRead, (void *) 0)) + return 1; + + bail: + close(fd); + return 0; +} + +void +STouchFini (void) +{ + KdUnregisterFds (STouchInputType, TRUE); +} + +KdMouseFuncs STouchFuncs = { + STouchInit, + STouchFini +}; diff -urN -X exclude xserver-old/xserver/hw/kdrive/linux/stouch.h xserver/xserver/hw/kdrive/linux/stouch.h --- xserver-old/xserver/hw/kdrive/linux/stouch.h 1970-01-01 01:00:00.000000000 +0100 +++ xserver/xserver/hw/kdrive/linux/stouch.h 2003-12-04 17:47:40.000000000 +0100 @@ -0,0 +1,19 @@ +#ifndef _STOUCH_H_ +#define _STOUCH_H_ + +void +STouchFini(void); + +int +STouchInit(void); + +void +STouchInitPort(int fd); + +void +STouchRead(int tsport, void *closure); + +void +KdSetTcCalibration(int width, int height, int x, int y); + +#endif