# eGalax USB driver (UEP) modifications - swap x and y axes



## DontPanic (Sep 11, 2010)

Hi all,

I'm a FreeBSD newbie trying to work out how to run an eGalax Touch Screen in X11 on a very standard looking install of FreeBSD 8.1 (and X server 1.7.5). I have no Unix or Linux background, so I may be missing something fundamental and overcomplicating my touch screen problem.

Having enabled HALD, DBUS, and UEP modules, I installed the eGalax X11 driver and succeeded in getting the screen to move the cursor. The problem is that the x and y axes are inverted - i.e. movement up/down on the screen results in left/right cursor movement, and vice versa.

I have the following questions:
1. Is it possible to invert the x and y axes of an input device within X11?
2. Where could I find the source for the eGalax X11 driver?
3. Is there any good documentation for explaining the interface between device nodes (i.e. /dev/uep0) and X11 device drivers (i.e. eGalax)?
4. Any other advice? Is there anything obvious that I am missing, or anywhere else I should be looking?

Below are details of what I have tried...

I tried exploring 'xinput' to see if I could make the change within X11, but couldn't find anything there that could help me. The X11 driver has no options to swap x and y within xorg.conf (only 'invert y', which doesn't solve the issue), so I though I'd have a crack at modifying it but I have not been able to track down the source for it (ok, I know it's out there, but evidently I'm too much of a newbie to know where to find it!). Failing there, I decided to have had a crack at the UEP driver. A copy of UEP.c can be viewed here: http://code.bsd64.org/browse/freebsd/RELENG_8/src/sys/dev/usb/input/uep.c

I found the function 'uep_process_pkt' and thought I'd hit the jackpot - the comment clearly explains how the packets look and what they mean - so I first tried swapping the variables 'x' and 'y'. That did nothing. So I tried a full swap of the relevant bytes in the buffer within that function, and this time it had an effect: the cursor generally did the same thing, but acted 'jumpy'. I concluded that this function is actually populating a log file somewhere, and then sending the 'confirmed' data back to the screen (I think?). So my new thinking is that I need to change the data as soon as it comes in, and this is when I go cross-eyed...

Obviously everything is happening in 'uep_intr_callback', and the data is read by the function 'usbd_copy_out'. I only want to change uep, so I haven't gone any deeper than this. Because the data can be read in whole packets or partial packets, I don't want to _always_ swap those x and y bytes. I only want to do it when they're stored into _where-ever-the-x11-driver-reads-the-data-from_... This is where I'm really in over my head - I don't understand the x11-egalax-driver / uep interface. I assumed that - somehow - x11 was reading the raw data placed into the 'uep_softc' structure ("sc"). But then this logically doesn't work because this buffer is not used _at all_ if a complete packet comes in.


So after all that I am left scratching my head. How can I feed reversed information to the eGalax x11 driver? If anyone can offer some direction it would be greatly appreciated.

Thanks.


----------



## segfault (Sep 15, 2010)

VERY interested in your progress here. I am looking to find a way to make a FreeBSD touchscreen tablet out of a broken Toshiba laptop. Interesting to here the eGalax addon has X11 drivers (your IS an addon kit no?).

Sadly I'm not much help for the axis problem although I did have one amusing thought:
If your "up" is "right" and your "down is "left", what would happen if you turned the panel clockwise 90 degrees? 

In seriousness,perhaps this will help you:
http://www.mp3car.com/vbulletin/linuxice/138078-elo-touchscreen.html

Please post back with your results, I am thinking about trying to buy eGalax.


----------



## SirDice (Sep 15, 2010)

DontPanic said:
			
		

> 1. Is it possible to invert the x and y axes of an input device within X11?


That depends on the X11 input driver



> 2. Where could I find the source for the eGalax X11 driver?


Have a look at the port's Makefile. Tip: Make use of *make extract*.



> 3. Is there any good documentation for explaining the interface between device nodes (i.e. /dev/uep0) and X11 device drivers (i.e. eGalax)?


That depends on the developer of said driver.



> 4. Any other advice? Is there anything obvious that I am missing, or anywhere else I should be looking?



The X11 driver is the place to change things. I have no idea who developed it but you could try contacting them.


----------

