GP2X F-200; Touchscreen W/o Sdl, And What Caused Crashes?


skeezix

Internal Development
Joined
Mar 11, 2003
Messages
8,070
Website
www.codejedi.com
Since I didn't have an f-200 I didn't care so much about these things.. now that I have one, time to find out. Hopefully you fine lads can save me some time (time is ever tight these days :()

1) Without using SDL, how is the touchscreen read? (theres a thread on the first page still from oct 2007 where no one had an f2-- yet.. so not a lot of on-message-board chatter about it I guess). I'm assuming either an ioctl or a /dev/foo read .. anyone know the particulars? (need to detect when a tap occurs, and of course where. How accurate is it anyway?)

2) I seem to recall that when the f-200 came out, MAME and numerous others crashed; some screen oddity? Does anyone recall the circumstances, so that I can avoid it?

Still severely sleep deprived, so help me out.. my memory is gone :)

jeff
 
<edit> Surely it didn't take me that long to type out... you're own reply wasn't there when I started.
Be warned, the device will flood you with events whilst the screen is being touched, plus the values you get are erratic to say the least. That code I did in ts_lib.cpp is a static version of tslib, it does a decent-ish job of smoothing the coords but it still jumps a bit - especially on releasing the touchscreen.
</edit>

Reading the touchscreen:
Open the device CODE
touchscreen_dev = open("/dev/touchscreen/wm97xx", O_RDONLY)

Read an event into a ucb1x100 style struct CODE
typedef struct ucb1x00_ts_event {
unsigned short pressure;
unsigned short x;
unsigned short y;
unsigned short pad;
struct timeval stamp;
} UCB1X00_TS_EVENT;

UCB1X00_TS_EVENT event;
retval = read(touchscreen_dev, &event, sizeof(event));


pressure will == 0 on release, != 0 when touching
pad is just padding to align stamp, which is the timestamp of the event
x and y are the coordinates as the device sees them you need to scale them according to the scaling factors in /etc/pointercal

/etc/pointercal contains seven numbers, read them into an array and use them like below to convert the device coords into screen coords
CODE
screenX = ((event.x * p[0] + event.y * p[1]) + p[2]) / p[6];
screenY = ((event.x * p[3] + event.y * p[4]) + p[5]) / p[6];

This is a generic formula that allows for rotation which the gp2x doesn't use so p[1] and p[3] are 0, and the gp2x uses 16:16 fixedpoint so the scale p[6] is always 65536. So the formula can be reduced toCODE

screenX = (event.x * p[0] + p[2]) >> 16;
screenY = (event.y * p[4] + p[5]) >> 16;

Typical values for pointercal are (taken from my f-200):
p[0] = 6203, p[2] = -1501397
p[4] = -4200, p[5] = 16132680
 
paeryn said:
As to programs crashing, the f-200 doesn't like playing sound at certain frequencies (not sure off the top of my head what they are).
With Kevcals help I tested the following frequencies as safe to use with the F-200:

8000
11025
16000
22050
32000
44100
48000

Regards,
Stephan
 
Last edited by a moderator:
Awesome, thanks for the tips guys :) Very helpfull!

It seems the touchscreen is _Extremely_ eratic? Hopefully it can be tamed.

Anyone tried tricks like .. averaging a series of fetches, verswus discarding results beyond a threshold or deviation, etc?

It seems to update .. every fetch? I would've assumed there would be a timer doing updates while pressed, but nomatter how fast you fetch results you always get a different response?

I'll see what I can do :)

jeff
 
Back
Top