Library for MI0283QT-2 LCD
Embed:
(wiki syntax)
Show/hide line numbers
Touchlib.h
00001 /* mbed TouchScreen ADS7846 library. 00002 00003 Copyright (c) 2011 NXP 3803 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 00024 #ifndef __TOOUCH_H 00025 #define __TOOUCH_H 00026 00027 #include "mbed.h" 00028 #include "calibrate.h" 00029 00030 /* Define per la compilazione del codice di gestione del PENIRQ */ 00031 #define SW_PENIRQ 00032 /* */ 00033 #define cTS_STARTBIT 0x80 00034 #define cTS_MODE 0x00 00035 #define cTS_SERDFR 0x00 /* SER/DFR =1 -> 0x04, */ 00036 #define cTS_PWRUP 0x03 /* Device is powered ON, PENIRQ OFF */ 00037 #define cTS_PWRDWN 0x00 /* Device is powered OFF, PENIRQ ON */ 00038 /* */ 00039 #define cTS_GETY (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x10) 00040 #define cTS_GETX (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x50) 00041 #define cTS_GETZ1 (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x30) 00042 #define cTS_GETZ2 (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x40) 00043 #define cTS_VBAT (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x20) 00044 #define cTS_END (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRDWN|0x50) 00045 /* */ 00046 #define cTS_CMDSIZE 17 00047 #define cTS_CROCINO 16 00048 /* */ 00049 #define cTS_DEBOUNCE 2 /* 3ms di debounce x la pressione del touch */ 00050 /* FSM per la lettura del touch */ 00051 #define cTS_INIT 6 00052 #define cTS_START 1 00053 #define cTS_READ 2 00054 #define cTS_RELEASING 3 00055 #define cTS_RELEASED 4 00056 #define cTS_STOP 5 00057 00058 #define TS_SPEED 1000000 /* 1Mbit */ 00059 #define BUS_MODE 3 00060 00061 /* We read the sample MAX_SAMPLES times*/ 00062 #define MAX_SAMPLES 8 00063 00064 00065 /* Data structure: x, y and pressure */ 00066 struct _TS_COORD { 00067 unsigned int x; 00068 unsigned int y; 00069 int z; 00070 }; 00071 00072 /* Collection of data about the touch... */ 00073 struct _TS_VALUE { 00074 _TS_COORD coord; /* tap's coord. */ 00075 volatile unsigned char touched; /* == 1 pen down. */ 00076 unsigned char calibration_done; /* calibration done. */ 00077 }; 00078 00079 /** TouchScreen ADS7846 Library 00080 * From the DS: 00081 * The ADS7846 is a classic successive approximation register 00082 * (SAR) analog-to-digital converter (ADC). The architecture is 00083 * based on capacitive redistribution which inherently includes 00084 * a sample-and-hold function. The converter is fabricated on a 00085 * 0.6μm CMOS process. 00086 * 00087 * The device features an internal 2.5V reference and an 00088 * external clock. Operation is maintained from a single supply 00089 * of 2.7V to 5.25V. The internal reference can be overdriven 00090 * with an external, low impedance source between 1V and 00091 * +VCC. The value of the reference voltage directly sets the 00092 * input range of the converter. 00093 * The analog input (X-, Y-, and Z-position coordinates, auxiliary 00094 * input, battery voltage, and chip temperature) to the 00095 * converter is provided via a multiplexer. A unique configuration 00096 * of low on-resistance touch panel driver switches allows 00097 * an unselected ADC input channel to provide power and its 00098 * accompanying pin to provide ground for an external device, 00099 * such as a touch screen 00100 * 00101 * Example: 00102 * @code 00103 * // Please the main.c code as an elabora example. 00104 * 00105 * @endcode 00106 */ 00107 00108 // 00109 class TOUCHS { 00110 00111 public: 00112 00113 /** Create the touch object 00114 * 00115 * @param pin mosi, pin miso, pin sclk, pin chip select and pin penirq 00116 */ 00117 TOUCHS( PinName mosi, PinName miso, PinName sclk, PinName cs, PinName penirq); 00118 00119 /** Initalize the touchscreen chip. 00120 * 00121 * @param none 00122 */ 00123 void init( void); 00124 00125 /** This function computes a matrix of data to be used for the conversion from touch to screen coord. 00126 * 00127 * @param the coord of each crocino tapped by the user. 00128 */ 00129 unsigned int setcalibration( _TS_COORD *ts); 00130 00131 /** I use a pool metod to read the touch. Each time I need to read the touch I loop until this function 00132 * set a flag. It's also possible to configure this fuction as an handle of a Ticker class, checkin for 00133 * the flag inside the main loop. 00134 */ 00135 void do_tap( void); 00136 00137 /** Get the x coord of the crocino speicifyed by idx. There are three crocino defined inside the crocino.h header file 00138 * 00139 * @param idx One of the three crocino. 00140 * @return the x coord. 00141 */ 00142 unsigned int getcrocino_x( unsigned char idx); 00143 00144 /** Get the y coord of the crocino speicifyed by idx. There are three crocino defined inside the crocino.h header file 00145 * 00146 * @param idx One of the three crocino. 00147 * @return the x coord. 00148 */ 00149 unsigned int getcrocino_y( unsigned char idx); 00150 00151 /** Get the pixel size of the crocino. 00152 * 00153 * @return the pixel size of the crocino. 00154 */ 00155 unsigned int crocino_size( void); 00156 00157 /** Return the size of the TS_Matrix size. 00158 * 00159 * @return the size of the TS_Matrix 00160 */ 00161 unsigned int gettsmatrixsize( void); 00162 00163 /** Get the TS_Matrix 00164 * 00165 * @param pmatrix Pointer to an area of RAM where the function store the content of the TS_Matrix 00166 */ 00167 void gettsmatrix( unsigned char *pmatrix); 00168 00169 /** Set the TS_Matrix with the content of the buffer. 00170 * 00171 * @param pmatrix Pointer to a buffer 00172 */ 00173 void settsmatrix( unsigned char *pmatrix); 00174 00175 // 00176 _TS_VALUE ts_val; 00177 00178 protected: 00179 /** 00180 */ 00181 unsigned int pressure( void); 00182 00183 /** This function convert from touch to screen coord. 00184 * The value are stored inside the struct ts_val 00185 */ 00186 unsigned int calibrate( void); 00187 00188 /** Read the raw coordinate from the touchscreen 00189 * 00190 * @param struct ts that will old the data. 00191 */ 00192 void read( _TS_COORD *ts); 00193 00194 _TS_VALUE TS_value; 00195 _TS_COORD TS_coord; 00196 SPI _spi; 00197 DigitalOut _cs; 00198 InterruptIn _penirq; 00199 }; 00200 00201 #endif
Generated on Fri Jul 15 2022 19:54:13 by 1.7.2