A library with drivers for different peripherals on the LPC4088 QuickStart Board or related add-on boards.
Dependents: LPC4088test LPC4088test_ledonly LPC4088test_deleteall LPC4088_RAMtest ... more
TSC2046.h
00001 /* 00002 * Copyright 2013 Embedded Artists AB 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef TSC2046_H 00018 #define TSC2046_H 00019 00020 #include "TouchPanel.h" 00021 00022 #define TSC2046_NUM_CALIB_POINTS (3) 00023 00024 /** 00025 * Texas Instruments Touch Screen Controller (TSC2046). 00026 */ 00027 class TSC2046 : public TouchPanel { 00028 public: 00029 00030 00031 /** 00032 * Constructor 00033 * 00034 * @param mosi SPI MOSI pin 00035 * @param miso SPI MISO pin 00036 * @param sck SPI SCK pin 00037 * @param cs chip-select pin 00038 */ 00039 TSC2046(PinName mosi, PinName miso, PinName sck, PinName cs); 00040 00041 virtual bool init(uint16_t width, uint16_t height); 00042 00043 virtual bool read(touchCoordinate_t &coord); 00044 virtual bool calibrateStart(); 00045 virtual bool getNextCalibratePoint(uint16_t* x, uint16_t* y); 00046 virtual bool waitForCalibratePoint(bool* morePoints, uint32_t timeout); 00047 00048 /** 00049 * Calibrate the touch panel with already gathered calibration values. 00050 * The list with calibration points must at one point have been retrieved 00051 * by calling getCalibrationValues; 00052 * 00053 * @param values list with calibration values 00054 * @param numValues the size of the list must match the number of 00055 * calibration points needed for this touch panel (TSC2046_NUM_CALIB_POINTS) 00056 * 00057 * @return true if the request was successful; otherwise false 00058 */ 00059 bool calibrate(touchCoordinate_t* values, int numValues); 00060 00061 /** 00062 * Get calibration values for the calibration points used by this touch 00063 * panel. This method may only be called after a successful calibration 00064 * has been performed. 00065 * 00066 * The list with values can be written to persistent storage and used 00067 * to calibrate the display without involving the user. 00068 * 00069 * @param values calibration values will be written to this list 00070 * @param numValues the size of the list must match the number of 00071 * calibration points needed for this touch panel (TSC2046_NUM_CALIB_POINTS) 00072 * 00073 * @return true if the request was successful; otherwise false 00074 */ 00075 bool getCalibrationValues(touchCoordinate_t* values, int numValues); 00076 00077 00078 private: 00079 00080 typedef struct { 00081 int64_t x; 00082 int64_t y; 00083 } calibPoint_t; 00084 00085 typedef struct { 00086 int64_t An; 00087 int64_t Bn; 00088 int64_t Cn; 00089 int64_t Dn; 00090 int64_t En; 00091 int64_t Fn; 00092 int64_t Divider; 00093 } calibMatrix_t; 00094 00095 SPI _spi; 00096 DigitalOut _cs; 00097 bool _calibrated; 00098 bool _initialized; 00099 calibMatrix_t _calibMatrix; 00100 00101 uint16_t _width; 00102 uint16_t _height; 00103 int _calibPoint; 00104 int _insetPx; 00105 00106 touchCoordinate_t _calibrateValues[TSC2046_NUM_CALIB_POINTS][2]; 00107 00108 void readAndFilter(touchCoordinate_t &coord); 00109 int32_t getFilteredValue(int cmd); 00110 uint16_t spiTransfer(uint8_t cmd); 00111 00112 void calibrate(touchCoordinate_t &ref1, 00113 touchCoordinate_t &ref2, 00114 touchCoordinate_t &ref3, 00115 touchCoordinate_t &scr1, 00116 touchCoordinate_t &scr2, 00117 touchCoordinate_t &scr3); 00118 00119 void getCalibratePoint(int pointNum, int32_t* x, int32_t *y); 00120 int waitForTouch(int32_t* x, int32_t* y, uint32_t timeout); 00121 00122 00123 00124 int setCalibrationMatrix( calibPoint_t * displayPtr, 00125 calibPoint_t * screenPtr, 00126 calibMatrix_t * matrixPtr); 00127 int getDisplayPoint( calibPoint_t * displayPtr, 00128 calibPoint_t * screenPtr, 00129 calibMatrix_t * matrixPtr ); 00130 00131 00132 00133 }; 00134 00135 #endif
Generated on Fri Jul 15 2022 02:16:08 by 1.7.2