Library to support using the 2.8" TFT Touch Shield v1.0 - made by Seeed Studio - for Arduino This shield uses either the SPFD5408A or ST7781R display chip.

Committer:
tj4shee
Date:
Thu Feb 05 19:39:58 2015 +0000
Revision:
0:93976d4026d3
Initial version of library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tj4shee 0:93976d4026d3 1 /*
tj4shee 0:93976d4026d3 2 SPFD5408A or ST7781R TFT Library.
tj4shee 0:93976d4026d3 3
tj4shee 0:93976d4026d3 4 2015 Copyright (c) Bluegrass Digital Inc.
tj4shee 0:93976d4026d3 5
tj4shee 0:93976d4026d3 6 Authors: TJ Forshee (with initializtion code from TFT vendor)
tj4shee 0:93976d4026d3 7
tj4shee 0:93976d4026d3 8 This library is free software; you can redistribute it and/or
tj4shee 0:93976d4026d3 9 modify it under the terms of the GNU Lesser General Public
tj4shee 0:93976d4026d3 10 License as published by the Free Software Foundation; either
tj4shee 0:93976d4026d3 11 version 2.1 of the License, or (at your option) any later version.
tj4shee 0:93976d4026d3 12
tj4shee 0:93976d4026d3 13 This library is distributed in the hope that it will be useful,
tj4shee 0:93976d4026d3 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
tj4shee 0:93976d4026d3 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
tj4shee 0:93976d4026d3 16 Lesser General Public License for more details.
tj4shee 0:93976d4026d3 17
tj4shee 0:93976d4026d3 18 You should have received a copy of the GNU Lesser General Public
tj4shee 0:93976d4026d3 19 License along with this library; if not, write to the Free Software
tj4shee 0:93976d4026d3 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
tj4shee 0:93976d4026d3 21
tj4shee 0:93976d4026d3 22 */
tj4shee 0:93976d4026d3 23
tj4shee 0:93976d4026d3 24 #ifndef TFT_h
tj4shee 0:93976d4026d3 25 #define TFT_h
tj4shee 0:93976d4026d3 26
tj4shee 0:93976d4026d3 27 #include "mbed.h"
tj4shee 0:93976d4026d3 28
tj4shee 0:93976d4026d3 29 //Basic Colors
tj4shee 0:93976d4026d3 30 #define RED 0xf800
tj4shee 0:93976d4026d3 31 #define GREEN 0x7e00
tj4shee 0:93976d4026d3 32 #define BLUE 0x001f
tj4shee 0:93976d4026d3 33 #define BLACK 0x0000
tj4shee 0:93976d4026d3 34 #define YELLOW 0xffe0
tj4shee 0:93976d4026d3 35 #define WHITE 0xffff
tj4shee 0:93976d4026d3 36
tj4shee 0:93976d4026d3 37 //Other Colors
tj4shee 0:93976d4026d3 38 #define CYAN 0x07ff
tj4shee 0:93976d4026d3 39 #define BRIGHT_RED 0xf810
tj4shee 0:93976d4026d3 40 #define GRAY1 0x8410
tj4shee 0:93976d4026d3 41 #define GRAY2 0x4208
tj4shee 0:93976d4026d3 42
tj4shee 0:93976d4026d3 43 //TFT resolution 240*320
tj4shee 0:93976d4026d3 44 #define MIN_X 0
tj4shee 0:93976d4026d3 45 #define MIN_Y 0
tj4shee 0:93976d4026d3 46 #define MAX_X 239
tj4shee 0:93976d4026d3 47 #define MAX_Y 319
tj4shee 0:93976d4026d3 48
tj4shee 0:93976d4026d3 49 //========================================
tj4shee 0:93976d4026d3 50 //#define DDR_CS DDRB
tj4shee 0:93976d4026d3 51 //#define PORT_CS PORTB
tj4shee 0:93976d4026d3 52 //#define CS_BIT 0x04 // B.2 = D10
tj4shee 0:93976d4026d3 53 // {DDR_CS|=CS_BIT;}
tj4shee 0:93976d4026d3 54 // {PORT_CS|=CS_BIT;}
tj4shee 0:93976d4026d3 55 // {PORT_CS&=~CS_BIT;}
tj4shee 0:93976d4026d3 56
tj4shee 0:93976d4026d3 57 //-----------------------------------------
tj4shee 0:93976d4026d3 58
tj4shee 0:93976d4026d3 59 //#define DDR_RS DDRB
tj4shee 0:93976d4026d3 60 //#define PORT_RS PORTB
tj4shee 0:93976d4026d3 61 //#define RS_BIT 0x08 // B.3 = D11
tj4shee 0:93976d4026d3 62 // {DDR_RS|=RS_BIT;}
tj4shee 0:93976d4026d3 63 // {PORT_RS|=RS_BIT;}
tj4shee 0:93976d4026d3 64 // {PORT_RS&=~RS_BIT;}
tj4shee 0:93976d4026d3 65
tj4shee 0:93976d4026d3 66 //-----------------------------------------
tj4shee 0:93976d4026d3 67
tj4shee 0:93976d4026d3 68 //#define DDR_WR DDRB
tj4shee 0:93976d4026d3 69 //#define PORT_WR PORTB
tj4shee 0:93976d4026d3 70 //#define WR_BIT 0x10 // B.4 = D12
tj4shee 0:93976d4026d3 71 // {DDR_WR|=WR_BIT;}
tj4shee 0:93976d4026d3 72 // {PORT_WR|=WR_BIT;}
tj4shee 0:93976d4026d3 73 // {PORT_WR&=~WR_BIT;}
tj4shee 0:93976d4026d3 74 // {PORT_WR|=WR_BIT;PORT_WR&=~WR_BIT;}
tj4shee 0:93976d4026d3 75
tj4shee 0:93976d4026d3 76 //-----------------------------------------
tj4shee 0:93976d4026d3 77
tj4shee 0:93976d4026d3 78 //#define DDR_RD DDRB
tj4shee 0:93976d4026d3 79 //#define PORT_RD PORTB
tj4shee 0:93976d4026d3 80 //#define RD_BIT 0x20 // B.5 = D13
tj4shee 0:93976d4026d3 81 // {DDR_RD|=RD_BIT;}
tj4shee 0:93976d4026d3 82 // {PORT_RD|=RD_BIT;}
tj4shee 0:93976d4026d3 83 // {PORT_RD&=~RD_BIT;}
tj4shee 0:93976d4026d3 84 // {PORT_RD|=RD_BIT;PORT_RD&=~RD_BIT;}
tj4shee 0:93976d4026d3 85 //========================================
tj4shee 0:93976d4026d3 86
tj4shee 0:93976d4026d3 87 extern unsigned char simpleFont[][8];
tj4shee 0:93976d4026d3 88
tj4shee 0:93976d4026d3 89 class TFT
tj4shee 0:93976d4026d3 90 {
tj4shee 0:93976d4026d3 91 public:
tj4shee 0:93976d4026d3 92
tj4shee 0:93976d4026d3 93 unsigned int IC_CODE; //Stores Driver IC ID (either SPFD5408A or ST7781R)
tj4shee 0:93976d4026d3 94
tj4shee 0:93976d4026d3 95 void init (void);
tj4shee 0:93976d4026d3 96 void sendCommand(unsigned int index);
tj4shee 0:93976d4026d3 97 void sendData(unsigned int data);
tj4shee 0:93976d4026d3 98 void pushData(unsigned char data);
tj4shee 0:93976d4026d3 99 unsigned char getData(void);
tj4shee 0:93976d4026d3 100 unsigned int readRegister(unsigned int index);
tj4shee 0:93976d4026d3 101
tj4shee 0:93976d4026d3 102 unsigned int constrain(unsigned int val2chk, unsigned int lowval, unsigned int highval);
tj4shee 0:93976d4026d3 103 void setXY(unsigned int poX, unsigned int poY);
tj4shee 0:93976d4026d3 104 void setPixel(unsigned int poX, unsigned int poY,unsigned int color);
tj4shee 0:93976d4026d3 105 void drawLine(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color);
tj4shee 0:93976d4026d3 106 void drawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color);
tj4shee 0:93976d4026d3 107 void drawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color);
tj4shee 0:93976d4026d3 108 void drawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color);
tj4shee 0:93976d4026d3 109 void fillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color);
tj4shee 0:93976d4026d3 110 void drawCircle(int poX, int poY, int r,unsigned int color);
tj4shee 0:93976d4026d3 111 void fillCircle(int poX, int poY, int r,unsigned int color);
tj4shee 0:93976d4026d3 112 void drawChar(unsigned char ascii,unsigned int poX, unsigned int poY,unsigned int size, unsigned int fgcolor);
tj4shee 0:93976d4026d3 113 void drawString(char *string,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor);
tj4shee 0:93976d4026d3 114 unsigned char drawNumber(long long_num,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor);
tj4shee 0:93976d4026d3 115 unsigned char drawFloat(float floatNumber,unsigned char decimal,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor);
tj4shee 0:93976d4026d3 116 unsigned char drawFloat(float floatNumber,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor);
tj4shee 0:93976d4026d3 117
tj4shee 0:93976d4026d3 118 void all_pin_input(void);
tj4shee 0:93976d4026d3 119 void all_pin_output(void);
tj4shee 0:93976d4026d3 120 void all_pin_low(void);
tj4shee 0:93976d4026d3 121 void CS_HIGH(void);
tj4shee 0:93976d4026d3 122 void CS_LOW(void);
tj4shee 0:93976d4026d3 123 void RS_HIGH(void);
tj4shee 0:93976d4026d3 124 void RS_LOW(void);
tj4shee 0:93976d4026d3 125 void WR_HIGH(void);
tj4shee 0:93976d4026d3 126 void WR_LOW(void);
tj4shee 0:93976d4026d3 127 void WR_RISING(void);
tj4shee 0:93976d4026d3 128 void RD_HIGH(void);
tj4shee 0:93976d4026d3 129 void RD_LOW(void);
tj4shee 0:93976d4026d3 130 void RD_RISING(void);
tj4shee 0:93976d4026d3 131
tj4shee 0:93976d4026d3 132 void setOrientation(unsigned int HV);
tj4shee 0:93976d4026d3 133 };
tj4shee 0:93976d4026d3 134
tj4shee 0:93976d4026d3 135 extern TFT Tft;
tj4shee 0:93976d4026d3 136
tj4shee 0:93976d4026d3 137 #endif