TFT working with Nucleo L476

Dependencies:   SPI_TFT_ILI9341

Fork of SeeedStudioTFTv2 by Components

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SeeedStudioTFTv2.h Source File

SeeedStudioTFTv2.h

00001 /* mbed library for touchscreen connected to 4 mbed pins
00002  * derive from SPI_TFT lib
00003  * Copyright (c) 2011 Peter Drescher - DC2PD
00004  *
00005  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00006  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00007  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00008  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00009  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00010  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00011  * THE SOFTWARE.
00012  */
00013 
00014 #ifndef MBED_TOUCH_H
00015 #define MBED_TOUCH_H
00016 
00017 #include "mbed.h"
00018 #include "SPI_TFT_ILI9341.h"
00019 #ifdef USE_SDCARD
00020 #include "SDFileSystem.h" // import the SDFileSystem library 
00021 #endif
00022 
00023 struct point {
00024     int x;
00025     int y;
00026 };
00027 
00028 class SeeedStudioTFTv2 : public  
00029 #ifdef USE_SDCARD
00030     SDFileSystem,
00031 #endif
00032     SPI_TFT_ILI9341
00033 {
00034 public:
00035     /** create a TFT with touch object connected to the pins:
00036      *
00037      * @param pin xp resistiv touch x+
00038      * @param pin xm resistiv touch x-
00039      * @param pin yp resistiv touch y+
00040      * @param pin ym resistiv touch y-
00041      * @param mosi,miso,sclk SPI connection to TFT
00042      * @param cs pin connected to CS of display
00043      * @param reset pin connected to RESET of display
00044      * based on my SPI_TFT lib
00045      */
00046     SeeedStudioTFTv2(PinName xp, PinName xm, PinName yp, PinName ym,
00047                      PinName mosi, PinName miso, PinName sclk,
00048                      PinName csTft, PinName dcTft, PinName blTft,
00049                      PinName csSd);
00050 
00051     void setBacklight(bool enabled);
00052     
00053     /** calibrate the touch display
00054      *
00055      * User is asked to touch on two points on the screen
00056      */
00057     void calibrate(void);
00058 
00059     /** read x and y coord on screen
00060      *
00061      * @returns point(x,y)
00062      */
00063     bool
00064     getPixel(point& p);
00065 
00066     /** calculate coord on screen
00067     *
00068     * @param a_point point(analog x, analog y)
00069     * @returns point(pixel x, pixel y)
00070     *
00071     */
00072     point toPixel(point p);
00073 
00074 protected:
00075     PinName _xm;
00076     PinName _ym;
00077     PinName _xp;
00078     PinName _yp;
00079     DigitalOut bl;
00080 
00081     typedef enum { YES, MAYBE, NO } TOUCH;
00082     TOUCH getTouch(point& p);
00083     int readTouch(PinName p, PinName m, PinName a, PinName i);
00084 
00085     int x_off,y_off;
00086     int pp_tx,pp_ty;
00087 };
00088 
00089 #endif