I decided to optimize the library to improve drawing speed. The same display I use comes with a 4-wire resistive touch-screen as well.
Weight Loss Solution (Step by step) - Jason Fung
I decided to write a simple library for the touch-screen and give Protothreads a try. To incorporate all this, I thought it would be cool if I used these to make a simple game. Tic-tac-toe came to mind as a fun little demo.
I'm sure everyone's familiar with the game so I won't explain the rules there. The touch-screen is simply two resistive sheets placed on top of each other on top of the TFT screen.
When it is pressed down at a given place, the two sheets make contact and a voltage divider is formed. Every time the IO pin switches state, a long delay is provided to allow the outputs to stabilize.
Alternately, the ADC is significantly slowed down to negate effects of capacitive charging by high source impedance.
The library is written in the form of a simple state machine cycling through its states every few milliseconds, decided by the application calling the library functions. In my application, I use 5 milliseconds.
To organize the game, I've made use of the Protothreads threading library. Protothreads is a very light-weight, stackless, threading library written entirely as C macros by Adam Dunkels.
There is a third thread used to retrieve touch information. It is spawned by the main game thread when touch input is required.