Library for MI0283QT-2 LCD

Committer:
clemente
Date:
Wed May 23 06:25:31 2012 +0000
Revision:
0:7ad454fed160

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
clemente 0:7ad454fed160 1 /* mbed TouchScreen ADS7846 library.
clemente 0:7ad454fed160 2
clemente 0:7ad454fed160 3 Copyright (c) 2011 NXP 3803
clemente 0:7ad454fed160 4
clemente 0:7ad454fed160 5 Permission is hereby granted, free of charge, to any person obtaining a copy
clemente 0:7ad454fed160 6 of this software and associated documentation files (the "Software"), to deal
clemente 0:7ad454fed160 7 in the Software without restriction, including without limitation the rights
clemente 0:7ad454fed160 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
clemente 0:7ad454fed160 9 copies of the Software, and to permit persons to whom the Software is
clemente 0:7ad454fed160 10 furnished to do so, subject to the following conditions:
clemente 0:7ad454fed160 11
clemente 0:7ad454fed160 12 The above copyright notice and this permission notice shall be included in
clemente 0:7ad454fed160 13 all copies or substantial portions of the Software.
clemente 0:7ad454fed160 14
clemente 0:7ad454fed160 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
clemente 0:7ad454fed160 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
clemente 0:7ad454fed160 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
clemente 0:7ad454fed160 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
clemente 0:7ad454fed160 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
clemente 0:7ad454fed160 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
clemente 0:7ad454fed160 21 THE SOFTWARE.
clemente 0:7ad454fed160 22 */
clemente 0:7ad454fed160 23
clemente 0:7ad454fed160 24 #ifndef __TOOUCH_H
clemente 0:7ad454fed160 25 #define __TOOUCH_H
clemente 0:7ad454fed160 26
clemente 0:7ad454fed160 27 #include "mbed.h"
clemente 0:7ad454fed160 28 #include "calibrate.h"
clemente 0:7ad454fed160 29
clemente 0:7ad454fed160 30 /* Define per la compilazione del codice di gestione del PENIRQ */
clemente 0:7ad454fed160 31 #define SW_PENIRQ
clemente 0:7ad454fed160 32 /* */
clemente 0:7ad454fed160 33 #define cTS_STARTBIT 0x80
clemente 0:7ad454fed160 34 #define cTS_MODE 0x00
clemente 0:7ad454fed160 35 #define cTS_SERDFR 0x00 /* SER/DFR =1 -> 0x04, */
clemente 0:7ad454fed160 36 #define cTS_PWRUP 0x03 /* Device is powered ON, PENIRQ OFF */
clemente 0:7ad454fed160 37 #define cTS_PWRDWN 0x00 /* Device is powered OFF, PENIRQ ON */
clemente 0:7ad454fed160 38 /* */
clemente 0:7ad454fed160 39 #define cTS_GETY (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x10)
clemente 0:7ad454fed160 40 #define cTS_GETX (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x50)
clemente 0:7ad454fed160 41 #define cTS_GETZ1 (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x30)
clemente 0:7ad454fed160 42 #define cTS_GETZ2 (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x40)
clemente 0:7ad454fed160 43 #define cTS_VBAT (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRUP|0x20)
clemente 0:7ad454fed160 44 #define cTS_END (cTS_STARTBIT|cTS_MODE|cTS_SERDFR|cTS_PWRDWN|0x50)
clemente 0:7ad454fed160 45 /* */
clemente 0:7ad454fed160 46 #define cTS_CMDSIZE 17
clemente 0:7ad454fed160 47 #define cTS_CROCINO 16
clemente 0:7ad454fed160 48 /* */
clemente 0:7ad454fed160 49 #define cTS_DEBOUNCE 2 /* 3ms di debounce x la pressione del touch */
clemente 0:7ad454fed160 50 /* FSM per la lettura del touch */
clemente 0:7ad454fed160 51 #define cTS_INIT 6
clemente 0:7ad454fed160 52 #define cTS_START 1
clemente 0:7ad454fed160 53 #define cTS_READ 2
clemente 0:7ad454fed160 54 #define cTS_RELEASING 3
clemente 0:7ad454fed160 55 #define cTS_RELEASED 4
clemente 0:7ad454fed160 56 #define cTS_STOP 5
clemente 0:7ad454fed160 57
clemente 0:7ad454fed160 58 #define TS_SPEED 1000000 /* 1Mbit */
clemente 0:7ad454fed160 59 #define BUS_MODE 3
clemente 0:7ad454fed160 60
clemente 0:7ad454fed160 61 /* We read the sample MAX_SAMPLES times*/
clemente 0:7ad454fed160 62 #define MAX_SAMPLES 8
clemente 0:7ad454fed160 63
clemente 0:7ad454fed160 64
clemente 0:7ad454fed160 65 /* Data structure: x, y and pressure */
clemente 0:7ad454fed160 66 struct _TS_COORD {
clemente 0:7ad454fed160 67 unsigned int x;
clemente 0:7ad454fed160 68 unsigned int y;
clemente 0:7ad454fed160 69 int z;
clemente 0:7ad454fed160 70 };
clemente 0:7ad454fed160 71
clemente 0:7ad454fed160 72 /* Collection of data about the touch... */
clemente 0:7ad454fed160 73 struct _TS_VALUE {
clemente 0:7ad454fed160 74 _TS_COORD coord; /* tap's coord. */
clemente 0:7ad454fed160 75 volatile unsigned char touched; /* == 1 pen down. */
clemente 0:7ad454fed160 76 unsigned char calibration_done; /* calibration done. */
clemente 0:7ad454fed160 77 };
clemente 0:7ad454fed160 78
clemente 0:7ad454fed160 79 /** TouchScreen ADS7846 Library
clemente 0:7ad454fed160 80 * From the DS:
clemente 0:7ad454fed160 81 * The ADS7846 is a classic successive approximation register
clemente 0:7ad454fed160 82 * (SAR) analog-to-digital converter (ADC). The architecture is
clemente 0:7ad454fed160 83 * based on capacitive redistribution which inherently includes
clemente 0:7ad454fed160 84 * a sample-and-hold function. The converter is fabricated on a
clemente 0:7ad454fed160 85 * 0.6μm CMOS process.
clemente 0:7ad454fed160 86 *
clemente 0:7ad454fed160 87 * The device features an internal 2.5V reference and an
clemente 0:7ad454fed160 88 * external clock. Operation is maintained from a single supply
clemente 0:7ad454fed160 89 * of 2.7V to 5.25V. The internal reference can be overdriven
clemente 0:7ad454fed160 90 * with an external, low impedance source between 1V and
clemente 0:7ad454fed160 91 * +VCC. The value of the reference voltage directly sets the
clemente 0:7ad454fed160 92 * input range of the converter.
clemente 0:7ad454fed160 93 * The analog input (X-, Y-, and Z-position coordinates, auxiliary
clemente 0:7ad454fed160 94 * input, battery voltage, and chip temperature) to the
clemente 0:7ad454fed160 95 * converter is provided via a multiplexer. A unique configuration
clemente 0:7ad454fed160 96 * of low on-resistance touch panel driver switches allows
clemente 0:7ad454fed160 97 * an unselected ADC input channel to provide power and its
clemente 0:7ad454fed160 98 * accompanying pin to provide ground for an external device,
clemente 0:7ad454fed160 99 * such as a touch screen
clemente 0:7ad454fed160 100 *
clemente 0:7ad454fed160 101 * Example:
clemente 0:7ad454fed160 102 * @code
clemente 0:7ad454fed160 103 * // Please the main.c code as an elabora example.
clemente 0:7ad454fed160 104 *
clemente 0:7ad454fed160 105 * @endcode
clemente 0:7ad454fed160 106 */
clemente 0:7ad454fed160 107
clemente 0:7ad454fed160 108 //
clemente 0:7ad454fed160 109 class TOUCHS {
clemente 0:7ad454fed160 110
clemente 0:7ad454fed160 111 public:
clemente 0:7ad454fed160 112
clemente 0:7ad454fed160 113 /** Create the touch object
clemente 0:7ad454fed160 114 *
clemente 0:7ad454fed160 115 * @param pin mosi, pin miso, pin sclk, pin chip select and pin penirq
clemente 0:7ad454fed160 116 */
clemente 0:7ad454fed160 117 TOUCHS( PinName mosi, PinName miso, PinName sclk, PinName cs, PinName penirq);
clemente 0:7ad454fed160 118
clemente 0:7ad454fed160 119 /** Initalize the touchscreen chip.
clemente 0:7ad454fed160 120 *
clemente 0:7ad454fed160 121 * @param none
clemente 0:7ad454fed160 122 */
clemente 0:7ad454fed160 123 void init( void);
clemente 0:7ad454fed160 124
clemente 0:7ad454fed160 125 /** This function computes a matrix of data to be used for the conversion from touch to screen coord.
clemente 0:7ad454fed160 126 *
clemente 0:7ad454fed160 127 * @param the coord of each crocino tapped by the user.
clemente 0:7ad454fed160 128 */
clemente 0:7ad454fed160 129 unsigned int setcalibration( _TS_COORD *ts);
clemente 0:7ad454fed160 130
clemente 0:7ad454fed160 131 /** I use a pool metod to read the touch. Each time I need to read the touch I loop until this function
clemente 0:7ad454fed160 132 * set a flag. It's also possible to configure this fuction as an handle of a Ticker class, checkin for
clemente 0:7ad454fed160 133 * the flag inside the main loop.
clemente 0:7ad454fed160 134 */
clemente 0:7ad454fed160 135 void do_tap( void);
clemente 0:7ad454fed160 136
clemente 0:7ad454fed160 137 /** Get the x coord of the crocino speicifyed by idx. There are three crocino defined inside the crocino.h header file
clemente 0:7ad454fed160 138 *
clemente 0:7ad454fed160 139 * @param idx One of the three crocino.
clemente 0:7ad454fed160 140 * @return the x coord.
clemente 0:7ad454fed160 141 */
clemente 0:7ad454fed160 142 unsigned int getcrocino_x( unsigned char idx);
clemente 0:7ad454fed160 143
clemente 0:7ad454fed160 144 /** Get the y coord of the crocino speicifyed by idx. There are three crocino defined inside the crocino.h header file
clemente 0:7ad454fed160 145 *
clemente 0:7ad454fed160 146 * @param idx One of the three crocino.
clemente 0:7ad454fed160 147 * @return the x coord.
clemente 0:7ad454fed160 148 */
clemente 0:7ad454fed160 149 unsigned int getcrocino_y( unsigned char idx);
clemente 0:7ad454fed160 150
clemente 0:7ad454fed160 151 /** Get the pixel size of the crocino.
clemente 0:7ad454fed160 152 *
clemente 0:7ad454fed160 153 * @return the pixel size of the crocino.
clemente 0:7ad454fed160 154 */
clemente 0:7ad454fed160 155 unsigned int crocino_size( void);
clemente 0:7ad454fed160 156
clemente 0:7ad454fed160 157 /** Return the size of the TS_Matrix size.
clemente 0:7ad454fed160 158 *
clemente 0:7ad454fed160 159 * @return the size of the TS_Matrix
clemente 0:7ad454fed160 160 */
clemente 0:7ad454fed160 161 unsigned int gettsmatrixsize( void);
clemente 0:7ad454fed160 162
clemente 0:7ad454fed160 163 /** Get the TS_Matrix
clemente 0:7ad454fed160 164 *
clemente 0:7ad454fed160 165 * @param pmatrix Pointer to an area of RAM where the function store the content of the TS_Matrix
clemente 0:7ad454fed160 166 */
clemente 0:7ad454fed160 167 void gettsmatrix( unsigned char *pmatrix);
clemente 0:7ad454fed160 168
clemente 0:7ad454fed160 169 /** Set the TS_Matrix with the content of the buffer.
clemente 0:7ad454fed160 170 *
clemente 0:7ad454fed160 171 * @param pmatrix Pointer to a buffer
clemente 0:7ad454fed160 172 */
clemente 0:7ad454fed160 173 void settsmatrix( unsigned char *pmatrix);
clemente 0:7ad454fed160 174
clemente 0:7ad454fed160 175 //
clemente 0:7ad454fed160 176 _TS_VALUE ts_val;
clemente 0:7ad454fed160 177
clemente 0:7ad454fed160 178 protected:
clemente 0:7ad454fed160 179 /**
clemente 0:7ad454fed160 180 */
clemente 0:7ad454fed160 181 unsigned int pressure( void);
clemente 0:7ad454fed160 182
clemente 0:7ad454fed160 183 /** This function convert from touch to screen coord.
clemente 0:7ad454fed160 184 * The value are stored inside the struct ts_val
clemente 0:7ad454fed160 185 */
clemente 0:7ad454fed160 186 unsigned int calibrate( void);
clemente 0:7ad454fed160 187
clemente 0:7ad454fed160 188 /** Read the raw coordinate from the touchscreen
clemente 0:7ad454fed160 189 *
clemente 0:7ad454fed160 190 * @param struct ts that will old the data.
clemente 0:7ad454fed160 191 */
clemente 0:7ad454fed160 192 void read( _TS_COORD *ts);
clemente 0:7ad454fed160 193
clemente 0:7ad454fed160 194 _TS_VALUE TS_value;
clemente 0:7ad454fed160 195 _TS_COORD TS_coord;
clemente 0:7ad454fed160 196 SPI _spi;
clemente 0:7ad454fed160 197 DigitalOut _cs;
clemente 0:7ad454fed160 198 InterruptIn _penirq;
clemente 0:7ad454fed160 199 };
clemente 0:7ad454fed160 200
clemente 0:7ad454fed160 201 #endif