Update version of EALib.

Dependencies:   FATFileSystem

Fork of EALib by IONX

Committer:
embeddedartists
Date:
Thu Sep 26 06:37:02 2013 +0000
Revision:
0:0fdadbc3d852
Child:
4:b32cf4ef45c5
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:0fdadbc3d852 1
embeddedartists 0:0fdadbc3d852 2 #ifndef TSC2046_H
embeddedartists 0:0fdadbc3d852 3 #define TSC2046_H
embeddedartists 0:0fdadbc3d852 4
embeddedartists 0:0fdadbc3d852 5
embeddedartists 0:0fdadbc3d852 6 /**
embeddedartists 0:0fdadbc3d852 7 * Texas Instruments Touch Screen Controller (TSC2046).
embeddedartists 0:0fdadbc3d852 8 */
embeddedartists 0:0fdadbc3d852 9 class TSC2046 {
embeddedartists 0:0fdadbc3d852 10 public:
embeddedartists 0:0fdadbc3d852 11
embeddedartists 0:0fdadbc3d852 12 typedef struct {
embeddedartists 0:0fdadbc3d852 13 int32_t x;
embeddedartists 0:0fdadbc3d852 14 int32_t y;
embeddedartists 0:0fdadbc3d852 15 int32_t z;
embeddedartists 0:0fdadbc3d852 16 } touchCoordinate_t;
embeddedartists 0:0fdadbc3d852 17
embeddedartists 0:0fdadbc3d852 18 /**
embeddedartists 0:0fdadbc3d852 19 * Constructor
embeddedartists 0:0fdadbc3d852 20 *
embeddedartists 0:0fdadbc3d852 21 * @param mosi SPI MOSI pin
embeddedartists 0:0fdadbc3d852 22 * @param miso SPI MISO pin
embeddedartists 0:0fdadbc3d852 23 * @param sck SPI SCK pin
embeddedartists 0:0fdadbc3d852 24 * @param cs chip-select pin
embeddedartists 0:0fdadbc3d852 25 */
embeddedartists 0:0fdadbc3d852 26 TSC2046(PinName mosi, PinName miso, PinName sck, PinName cs);
embeddedartists 0:0fdadbc3d852 27
embeddedartists 0:0fdadbc3d852 28 /**
embeddedartists 0:0fdadbc3d852 29 * Read coordinates from the touch panel.
embeddedartists 0:0fdadbc3d852 30 *
embeddedartists 0:0fdadbc3d852 31 * Before calibrate() is called this function will return uncalibrated
embeddedartists 0:0fdadbc3d852 32 * values. If there is no touch active the coordinate values will be 0.
embeddedartists 0:0fdadbc3d852 33 *
embeddedartists 0:0fdadbc3d852 34 * @param coord pointer to coordinate object. The read coordinates will be
embeddedartists 0:0fdadbc3d852 35 * written to this object.
embeddedartists 0:0fdadbc3d852 36 */
embeddedartists 0:0fdadbc3d852 37 void read(touchCoordinate_t &coord);
embeddedartists 0:0fdadbc3d852 38
embeddedartists 0:0fdadbc3d852 39 /**
embeddedartists 0:0fdadbc3d852 40 * Calibrate touch screen based on three reference points and
embeddedartists 0:0fdadbc3d852 41 * three actual readings. This means that the user must be presented
embeddedartists 0:0fdadbc3d852 42 * with three points (one at a time) and asked to press on these points
embeddedartists 0:0fdadbc3d852 43 * to get an actual reading.
embeddedartists 0:0fdadbc3d852 44 */
embeddedartists 0:0fdadbc3d852 45 void calibrate(touchCoordinate_t &ref1,
embeddedartists 0:0fdadbc3d852 46 touchCoordinate_t &ref2,
embeddedartists 0:0fdadbc3d852 47 touchCoordinate_t &ref3,
embeddedartists 0:0fdadbc3d852 48 touchCoordinate_t &scr1,
embeddedartists 0:0fdadbc3d852 49 touchCoordinate_t &scr2,
embeddedartists 0:0fdadbc3d852 50 touchCoordinate_t &scr3);
embeddedartists 0:0fdadbc3d852 51
embeddedartists 0:0fdadbc3d852 52 /**
embeddedartists 0:0fdadbc3d852 53 * Reset a previous calibration (in order to do a new calibration)
embeddedartists 0:0fdadbc3d852 54 */
embeddedartists 0:0fdadbc3d852 55 void uncalibrate();
embeddedartists 0:0fdadbc3d852 56
embeddedartists 0:0fdadbc3d852 57
embeddedartists 0:0fdadbc3d852 58 private:
embeddedartists 0:0fdadbc3d852 59
embeddedartists 0:0fdadbc3d852 60 typedef struct {
embeddedartists 0:0fdadbc3d852 61 int64_t x;
embeddedartists 0:0fdadbc3d852 62 int64_t y;
embeddedartists 0:0fdadbc3d852 63 } calibPoint_t;
embeddedartists 0:0fdadbc3d852 64
embeddedartists 0:0fdadbc3d852 65 typedef struct {
embeddedartists 0:0fdadbc3d852 66 int64_t An;
embeddedartists 0:0fdadbc3d852 67 int64_t Bn;
embeddedartists 0:0fdadbc3d852 68 int64_t Cn;
embeddedartists 0:0fdadbc3d852 69 int64_t Dn;
embeddedartists 0:0fdadbc3d852 70 int64_t En;
embeddedartists 0:0fdadbc3d852 71 int64_t Fn;
embeddedartists 0:0fdadbc3d852 72 int64_t Divider;
embeddedartists 0:0fdadbc3d852 73 } calibMatrix_t;
embeddedartists 0:0fdadbc3d852 74
embeddedartists 0:0fdadbc3d852 75 SPI _spi;
embeddedartists 0:0fdadbc3d852 76 DigitalOut _cs;
embeddedartists 0:0fdadbc3d852 77 bool _calibrated;
embeddedartists 0:0fdadbc3d852 78 bool _initialized;
embeddedartists 0:0fdadbc3d852 79 calibMatrix_t _calibMatrix;
embeddedartists 0:0fdadbc3d852 80
embeddedartists 0:0fdadbc3d852 81 void init();
embeddedartists 0:0fdadbc3d852 82 void readAndFilter(touchCoordinate_t &coord);
embeddedartists 0:0fdadbc3d852 83 int32_t getFilteredValue(int cmd);
embeddedartists 0:0fdadbc3d852 84 uint16_t spiTransfer(uint8_t cmd);
embeddedartists 0:0fdadbc3d852 85
embeddedartists 0:0fdadbc3d852 86
embeddedartists 0:0fdadbc3d852 87
embeddedartists 0:0fdadbc3d852 88 int setCalibrationMatrix( calibPoint_t * displayPtr,
embeddedartists 0:0fdadbc3d852 89 calibPoint_t * screenPtr,
embeddedartists 0:0fdadbc3d852 90 calibMatrix_t * matrixPtr);
embeddedartists 0:0fdadbc3d852 91 int getDisplayPoint( calibPoint_t * displayPtr,
embeddedartists 0:0fdadbc3d852 92 calibPoint_t * screenPtr,
embeddedartists 0:0fdadbc3d852 93 calibMatrix_t * matrixPtr );
embeddedartists 0:0fdadbc3d852 94
embeddedartists 0:0fdadbc3d852 95 };
embeddedartists 0:0fdadbc3d852 96
embeddedartists 0:0fdadbc3d852 97 #endif
embeddedartists 0:0fdadbc3d852 98
embeddedartists 0:0fdadbc3d852 99