A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.
Fork of EALib by
TSC2046.h@21:5ac242986175, 2017-05-22 (annotated)
- Committer:
- msamadani
- Date:
- Mon May 22 19:58:24 2017 +0000
- Revision:
- 21:5ac242986175
- Parent:
- 12:15597e45eea0
Working version of the library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 12:15597e45eea0 | 1 | /* |
embeddedartists | 12:15597e45eea0 | 2 | * Copyright 2013 Embedded Artists AB |
embeddedartists | 12:15597e45eea0 | 3 | * |
embeddedartists | 12:15597e45eea0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 12:15597e45eea0 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 12:15597e45eea0 | 6 | * You may obtain a copy of the License at |
embeddedartists | 12:15597e45eea0 | 7 | * |
embeddedartists | 12:15597e45eea0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 12:15597e45eea0 | 9 | * |
embeddedartists | 12:15597e45eea0 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 12:15597e45eea0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 12:15597e45eea0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 12:15597e45eea0 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 12:15597e45eea0 | 14 | * limitations under the License. |
embeddedartists | 12:15597e45eea0 | 15 | */ |
embeddedartists | 0:0fdadbc3d852 | 16 | |
embeddedartists | 0:0fdadbc3d852 | 17 | #ifndef TSC2046_H |
embeddedartists | 0:0fdadbc3d852 | 18 | #define TSC2046_H |
embeddedartists | 0:0fdadbc3d852 | 19 | |
embeddedartists | 4:b32cf4ef45c5 | 20 | #include "TouchPanel.h" |
embeddedartists | 4:b32cf4ef45c5 | 21 | |
embeddedartists | 4:b32cf4ef45c5 | 22 | #define TSC2046_NUM_CALIB_POINTS (3) |
embeddedartists | 0:0fdadbc3d852 | 23 | |
embeddedartists | 0:0fdadbc3d852 | 24 | /** |
embeddedartists | 0:0fdadbc3d852 | 25 | * Texas Instruments Touch Screen Controller (TSC2046). |
embeddedartists | 0:0fdadbc3d852 | 26 | */ |
embeddedartists | 4:b32cf4ef45c5 | 27 | class TSC2046 : public TouchPanel { |
embeddedartists | 0:0fdadbc3d852 | 28 | public: |
embeddedartists | 0:0fdadbc3d852 | 29 | |
embeddedartists | 0:0fdadbc3d852 | 30 | |
embeddedartists | 0:0fdadbc3d852 | 31 | /** |
embeddedartists | 0:0fdadbc3d852 | 32 | * Constructor |
embeddedartists | 0:0fdadbc3d852 | 33 | * |
embeddedartists | 0:0fdadbc3d852 | 34 | * @param mosi SPI MOSI pin |
embeddedartists | 0:0fdadbc3d852 | 35 | * @param miso SPI MISO pin |
embeddedartists | 0:0fdadbc3d852 | 36 | * @param sck SPI SCK pin |
embeddedartists | 0:0fdadbc3d852 | 37 | * @param cs chip-select pin |
embeddedartists | 0:0fdadbc3d852 | 38 | */ |
embeddedartists | 0:0fdadbc3d852 | 39 | TSC2046(PinName mosi, PinName miso, PinName sck, PinName cs); |
embeddedartists | 0:0fdadbc3d852 | 40 | |
embeddedartists | 5:3290d7b766d5 | 41 | virtual bool init(uint16_t width, uint16_t height); |
embeddedartists | 4:b32cf4ef45c5 | 42 | |
embeddedartists | 5:3290d7b766d5 | 43 | virtual bool read(touchCoordinate_t &coord); |
embeddedartists | 5:3290d7b766d5 | 44 | virtual bool calibrateStart(); |
embeddedartists | 5:3290d7b766d5 | 45 | virtual bool getNextCalibratePoint(uint16_t* x, uint16_t* y); |
embeddedartists | 5:3290d7b766d5 | 46 | virtual bool waitForCalibratePoint(bool* morePoints, uint32_t timeout); |
embeddedartists | 0:0fdadbc3d852 | 47 | |
embeddedartists | 0:0fdadbc3d852 | 48 | /** |
embeddedartists | 4:b32cf4ef45c5 | 49 | * Calibrate the touch panel with already gathered calibration values. |
embeddedartists | 4:b32cf4ef45c5 | 50 | * The list with calibration points must at one point have been retrieved |
embeddedartists | 4:b32cf4ef45c5 | 51 | * by calling getCalibrationValues; |
embeddedartists | 4:b32cf4ef45c5 | 52 | * |
embeddedartists | 4:b32cf4ef45c5 | 53 | * @param values list with calibration values |
embeddedartists | 4:b32cf4ef45c5 | 54 | * @param numValues the size of the list must match the number of |
embeddedartists | 4:b32cf4ef45c5 | 55 | * calibration points needed for this touch panel (TSC2046_NUM_CALIB_POINTS) |
embeddedartists | 4:b32cf4ef45c5 | 56 | * |
embeddedartists | 4:b32cf4ef45c5 | 57 | * @return true if the request was successful; otherwise false |
embeddedartists | 0:0fdadbc3d852 | 58 | */ |
embeddedartists | 4:b32cf4ef45c5 | 59 | bool calibrate(touchCoordinate_t* values, int numValues); |
embeddedartists | 0:0fdadbc3d852 | 60 | |
embeddedartists | 0:0fdadbc3d852 | 61 | /** |
embeddedartists | 4:b32cf4ef45c5 | 62 | * Get calibration values for the calibration points used by this touch |
embeddedartists | 4:b32cf4ef45c5 | 63 | * panel. This method may only be called after a successful calibration |
embeddedartists | 4:b32cf4ef45c5 | 64 | * has been performed. |
embeddedartists | 4:b32cf4ef45c5 | 65 | * |
embeddedartists | 4:b32cf4ef45c5 | 66 | * The list with values can be written to persistent storage and used |
embeddedartists | 4:b32cf4ef45c5 | 67 | * to calibrate the display without involving the user. |
embeddedartists | 4:b32cf4ef45c5 | 68 | * |
embeddedartists | 4:b32cf4ef45c5 | 69 | * @param values calibration values will be written to this list |
embeddedartists | 4:b32cf4ef45c5 | 70 | * @param numValues the size of the list must match the number of |
embeddedartists | 4:b32cf4ef45c5 | 71 | * calibration points needed for this touch panel (TSC2046_NUM_CALIB_POINTS) |
embeddedartists | 4:b32cf4ef45c5 | 72 | * |
embeddedartists | 4:b32cf4ef45c5 | 73 | * @return true if the request was successful; otherwise false |
embeddedartists | 0:0fdadbc3d852 | 74 | */ |
embeddedartists | 4:b32cf4ef45c5 | 75 | bool getCalibrationValues(touchCoordinate_t* values, int numValues); |
embeddedartists | 0:0fdadbc3d852 | 76 | |
embeddedartists | 0:0fdadbc3d852 | 77 | |
embeddedartists | 0:0fdadbc3d852 | 78 | private: |
embeddedartists | 0:0fdadbc3d852 | 79 | |
embeddedartists | 0:0fdadbc3d852 | 80 | typedef struct { |
embeddedartists | 0:0fdadbc3d852 | 81 | int64_t x; |
embeddedartists | 0:0fdadbc3d852 | 82 | int64_t y; |
embeddedartists | 0:0fdadbc3d852 | 83 | } calibPoint_t; |
embeddedartists | 0:0fdadbc3d852 | 84 | |
embeddedartists | 0:0fdadbc3d852 | 85 | typedef struct { |
embeddedartists | 0:0fdadbc3d852 | 86 | int64_t An; |
embeddedartists | 0:0fdadbc3d852 | 87 | int64_t Bn; |
embeddedartists | 0:0fdadbc3d852 | 88 | int64_t Cn; |
embeddedartists | 0:0fdadbc3d852 | 89 | int64_t Dn; |
embeddedartists | 0:0fdadbc3d852 | 90 | int64_t En; |
embeddedartists | 0:0fdadbc3d852 | 91 | int64_t Fn; |
embeddedartists | 0:0fdadbc3d852 | 92 | int64_t Divider; |
embeddedartists | 0:0fdadbc3d852 | 93 | } calibMatrix_t; |
embeddedartists | 0:0fdadbc3d852 | 94 | |
embeddedartists | 0:0fdadbc3d852 | 95 | SPI _spi; |
embeddedartists | 0:0fdadbc3d852 | 96 | DigitalOut _cs; |
embeddedartists | 0:0fdadbc3d852 | 97 | bool _calibrated; |
embeddedartists | 0:0fdadbc3d852 | 98 | bool _initialized; |
embeddedartists | 0:0fdadbc3d852 | 99 | calibMatrix_t _calibMatrix; |
embeddedartists | 0:0fdadbc3d852 | 100 | |
embeddedartists | 4:b32cf4ef45c5 | 101 | uint16_t _width; |
embeddedartists | 4:b32cf4ef45c5 | 102 | uint16_t _height; |
embeddedartists | 4:b32cf4ef45c5 | 103 | int _calibPoint; |
embeddedartists | 4:b32cf4ef45c5 | 104 | int _insetPx; |
embeddedartists | 4:b32cf4ef45c5 | 105 | |
embeddedartists | 4:b32cf4ef45c5 | 106 | touchCoordinate_t _calibrateValues[TSC2046_NUM_CALIB_POINTS][2]; |
embeddedartists | 4:b32cf4ef45c5 | 107 | |
embeddedartists | 0:0fdadbc3d852 | 108 | void readAndFilter(touchCoordinate_t &coord); |
embeddedartists | 0:0fdadbc3d852 | 109 | int32_t getFilteredValue(int cmd); |
embeddedartists | 0:0fdadbc3d852 | 110 | uint16_t spiTransfer(uint8_t cmd); |
embeddedartists | 0:0fdadbc3d852 | 111 | |
embeddedartists | 4:b32cf4ef45c5 | 112 | void calibrate(touchCoordinate_t &ref1, |
embeddedartists | 4:b32cf4ef45c5 | 113 | touchCoordinate_t &ref2, |
embeddedartists | 4:b32cf4ef45c5 | 114 | touchCoordinate_t &ref3, |
embeddedartists | 4:b32cf4ef45c5 | 115 | touchCoordinate_t &scr1, |
embeddedartists | 4:b32cf4ef45c5 | 116 | touchCoordinate_t &scr2, |
embeddedartists | 4:b32cf4ef45c5 | 117 | touchCoordinate_t &scr3); |
embeddedartists | 4:b32cf4ef45c5 | 118 | |
embeddedartists | 4:b32cf4ef45c5 | 119 | void getCalibratePoint(int pointNum, int32_t* x, int32_t *y); |
embeddedartists | 4:b32cf4ef45c5 | 120 | int waitForTouch(int32_t* x, int32_t* y, uint32_t timeout); |
embeddedartists | 4:b32cf4ef45c5 | 121 | |
embeddedartists | 0:0fdadbc3d852 | 122 | |
embeddedartists | 0:0fdadbc3d852 | 123 | |
embeddedartists | 0:0fdadbc3d852 | 124 | int setCalibrationMatrix( calibPoint_t * displayPtr, |
embeddedartists | 0:0fdadbc3d852 | 125 | calibPoint_t * screenPtr, |
embeddedartists | 0:0fdadbc3d852 | 126 | calibMatrix_t * matrixPtr); |
embeddedartists | 0:0fdadbc3d852 | 127 | int getDisplayPoint( calibPoint_t * displayPtr, |
embeddedartists | 0:0fdadbc3d852 | 128 | calibPoint_t * screenPtr, |
embeddedartists | 0:0fdadbc3d852 | 129 | calibMatrix_t * matrixPtr ); |
embeddedartists | 0:0fdadbc3d852 | 130 | |
embeddedartists | 4:b32cf4ef45c5 | 131 | |
embeddedartists | 4:b32cf4ef45c5 | 132 | |
embeddedartists | 0:0fdadbc3d852 | 133 | }; |
embeddedartists | 0:0fdadbc3d852 | 134 | |
embeddedartists | 0:0fdadbc3d852 | 135 | #endif |