A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.
Dependencies: FATFileSystem
Fork of EALib by
Diff: TSC2046.h
- Revision:
- 4:b32cf4ef45c5
- Parent:
- 0:0fdadbc3d852
- Child:
- 5:3290d7b766d5
--- a/TSC2046.h Wed Oct 09 07:51:52 2013 +0000 +++ b/TSC2046.h Fri Oct 18 12:48:58 2013 +0200 @@ -2,18 +2,16 @@ #ifndef TSC2046_H #define TSC2046_H +#include "TouchPanel.h" + +#define TSC2046_NUM_CALIB_POINTS (3) /** * Texas Instruments Touch Screen Controller (TSC2046). */ -class TSC2046 { +class TSC2046 : public TouchPanel { public: - typedef struct { - int32_t x; - int32_t y; - int32_t z; - } touchCoordinate_t; /** * Constructor @@ -25,34 +23,41 @@ */ TSC2046(PinName mosi, PinName miso, PinName sck, PinName cs); - /** - * Read coordinates from the touch panel. - * - * Before calibrate() is called this function will return uncalibrated - * values. If there is no touch active the coordinate values will be 0. - * - * @param coord pointer to coordinate object. The read coordinates will be - * written to this object. - */ - void read(touchCoordinate_t &coord); + bool init(uint16_t width, uint16_t height); + + bool read(touchCoordinate_t &coord); + bool calibrateStart(); + bool getNextCalibratePoint(uint16_t* x, uint16_t* y); + bool waitForCalibratePoint(bool* morePoints, uint32_t timeout); /** - * Calibrate touch screen based on three reference points and - * three actual readings. This means that the user must be presented - * with three points (one at a time) and asked to press on these points - * to get an actual reading. + * Calibrate the touch panel with already gathered calibration values. + * The list with calibration points must at one point have been retrieved + * by calling getCalibrationValues; + * + * @param values list with calibration values + * @param numValues the size of the list must match the number of + * calibration points needed for this touch panel (TSC2046_NUM_CALIB_POINTS) + * + * @return true if the request was successful; otherwise false */ - void calibrate(touchCoordinate_t &ref1, - touchCoordinate_t &ref2, - touchCoordinate_t &ref3, - touchCoordinate_t &scr1, - touchCoordinate_t &scr2, - touchCoordinate_t &scr3); + bool calibrate(touchCoordinate_t* values, int numValues); /** - * Reset a previous calibration (in order to do a new calibration) + * Get calibration values for the calibration points used by this touch + * panel. This method may only be called after a successful calibration + * has been performed. + * + * The list with values can be written to persistent storage and used + * to calibrate the display without involving the user. + * + * @param values calibration values will be written to this list + * @param numValues the size of the list must match the number of + * calibration points needed for this touch panel (TSC2046_NUM_CALIB_POINTS) + * + * @return true if the request was successful; otherwise false */ - void uncalibrate(); + bool getCalibrationValues(touchCoordinate_t* values, int numValues); private: @@ -78,11 +83,27 @@ bool _initialized; calibMatrix_t _calibMatrix; - void init(); + uint16_t _width; + uint16_t _height; + int _calibPoint; + int _insetPx; + + touchCoordinate_t _calibrateValues[TSC2046_NUM_CALIB_POINTS][2]; + void readAndFilter(touchCoordinate_t &coord); int32_t getFilteredValue(int cmd); uint16_t spiTransfer(uint8_t cmd); + void calibrate(touchCoordinate_t &ref1, + touchCoordinate_t &ref2, + touchCoordinate_t &ref3, + touchCoordinate_t &scr1, + touchCoordinate_t &scr2, + touchCoordinate_t &scr3); + + void getCalibratePoint(int pointNum, int32_t* x, int32_t *y); + int waitForTouch(int32_t* x, int32_t* y, uint32_t timeout); + int setCalibrationMatrix( calibPoint_t * displayPtr, @@ -92,8 +113,8 @@ calibPoint_t * screenPtr, calibMatrix_t * matrixPtr ); + + }; #endif - -