SPI Library for 240x320 TFT LCD with ILI9320, ILI9325 and ILI9328 chip

Dependencies:   BurstSPI

Dependents:   KL25Z_ILI9320_Demo Mini-DK

Other LCD drivers

05-30-2014
Device initialization for ILI9325 and ILI9328 has been added to the library.
The library will auto-detect what driver chip is connected (ILI9320, ILI9325 or ILI9328) and use the appropriate init sequence.
Please use the Issues tab to report any problems.

SPI TFT library for LPC1768, LPC11U24 and KL25Z

Loading fonts

When using this libary, don't forget to load the TFT_FONTS library from Peter Drescher at http://mbed.org/users/dreschpe/code/TFT_fonts/

KL25Z : limitations

The filetoflash function (see below) is not available.
Writing to the LCD is a little slower as the KL25Z only supports 8-bit SPI communication.

LPC1768 and LPC11U24 : filetoflash (SD to CPU flash)

This library contains a function to copy an image from the SD card to the CPU flash memory.
It allows you to use an image as background without speed loss when writing other text and graphics.
By default, this option is enabled.
It can be disabled by adding following instruction BEFORE you load the library:

#define NO_FLASH_BUFFER

Since the flash memory has limited write endurance, DO NOT use this feature when you intend to read multiple images from the SD card (eg: when used as a photo frame).

Sample code

#include "mbed.h"

// SPI TFT demo
// NOTES
// - Connect the LCD reset pin to the reset pin of the CPU board or connect a
//   separate reset circuit to the LCD reset pin (pull-up 10k to 3v3 + 100nf capacitor to GND).
// - When using the mbed LPC1768 board, following hardware modifications are needed:
//       Connect the LCD reset pin to the nR input.
//       Connect a 100nF capacitor between the nR input and GND.
//       Connect a pushbutton parallel to the 100nF capacitor.
//   Use the new pushbutton as the reset button (instead of the LPC1768 on-board reset button).
#define NO_FLASH_BUFFER         // Do not use CPU flash for storing bitmaps
#include "SPI_TFT_ILI9320.h"
#include "Arial12x12.h"
#include "Arial24x23.h"
#include "Arial28x28.h"
#include "font_big.h"
SPI_TFT TFT(p11, p12, p13, p14,"TFT");  //mosi, miso, clk, cs

int main (void)
{

    TFT.claim(stdout);        // send stdout to the TFT display
    // Disable stdout buffering, allows us to omit \n with printf.
    // More info at http://www.cplusplus.com/reference/cstdio/setvbuf/
    setvbuf ( stdout , NULL , _IONBF , NULL );
    TFT.background(Black);    // set background to black
    TFT.foreground(White);    // set chars to white
    TFT.cls();                // clear the screen
    TFT.set_font((unsigned char*) Arial12x12);  // select the font

    TFT.locate(0,0);
    printf("ILI9320 SPI TFT library\n");
    printf("Simple demo\n");
}



Demo code LPC1768 (Mini-DK board)

Import programLPC1768_Mini-DK

LPC1768 Mini-DK board with 2.8" SPI TFT and SPI touch


Demo code FRDM-KL25Z board

Import programKL25Z_ILI9320_Demo

KL25Z driving an ILI9320 LCD board with touch panel (HY28A-LCDB SPI)

Committer:
frankvnk
Date:
Fri Jan 11 16:10:06 2013 +0000
Revision:
0:630b4da97968
Child:
1:1fba7e67ec94
Extracted from Mini-DK to create separate library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 0:630b4da97968 1 /**************************************************************************************************
frankvnk 0:630b4da97968 2 ***** *****
frankvnk 0:630b4da97968 3 ***** Name: SPI_TFT.h *****
frankvnk 0:630b4da97968 4 ***** Ver.: 1.0 *****
frankvnk 0:630b4da97968 5 ***** Date: 04/01/2013 *****
frankvnk 0:630b4da97968 6 ***** Auth: Frank Vannieuwkerke *****
frankvnk 0:630b4da97968 7 ***** Erik Olieman *****
frankvnk 0:630b4da97968 8 ***** Func: library for 240*320 pixel TFT with ILI9320 LCD Controller *****
frankvnk 0:630b4da97968 9 ***** *****
frankvnk 0:630b4da97968 10 ***** Rewrite from Peter Drescher code - http://mbed.org/cookbook/SPI-driven-QVGA-TFT *****
frankvnk 0:630b4da97968 11 ***** *****
frankvnk 0:630b4da97968 12 **************************************************************************************************/
frankvnk 0:630b4da97968 13
frankvnk 0:630b4da97968 14 #ifndef MBED_SPI_TFT_H
frankvnk 0:630b4da97968 15 #define MBED_SPI_TFT_H
frankvnk 0:630b4da97968 16
frankvnk 0:630b4da97968 17 /* This library allows you to store a background image on the local flash memory of the microcontroller,
frankvnk 0:630b4da97968 18 from any filesystem (such as SD cards). This allows very fast writing of this specific image, and it allows
frankvnk 0:630b4da97968 19 you to write text in a nice way over the image. However it does cost the last 5 flash sectors of the LPC1768.
frankvnk 0:630b4da97968 20 Generally that won't be a problem, if it is a problem, add #define NO_FLASH_BUFFER before including this file.
frankvnk 0:630b4da97968 21 */
frankvnk 0:630b4da97968 22
frankvnk 0:630b4da97968 23
frankvnk 0:630b4da97968 24 #include "GraphicsDisplay.h"
frankvnk 0:630b4da97968 25 #include "BurstSPI.h"
frankvnk 0:630b4da97968 26 #include "mbed.h"
frankvnk 0:630b4da97968 27
frankvnk 0:630b4da97968 28 #ifndef NO_FLASH_BUFFER
frankvnk 0:630b4da97968 29 #include "IAP.h"
frankvnk 0:630b4da97968 30 #endif
frankvnk 0:630b4da97968 31
frankvnk 0:630b4da97968 32
frankvnk 0:630b4da97968 33 #define incx() x++, dxt += d2xt, t += dxt
frankvnk 0:630b4da97968 34 #define incy() y--, dyt += d2yt, t += dyt
frankvnk 0:630b4da97968 35
frankvnk 0:630b4da97968 36 #define SPI_F_LO 10000000
frankvnk 0:630b4da97968 37 #define SPI_F_HI 48000000
frankvnk 0:630b4da97968 38
frankvnk 0:630b4da97968 39 /* some RGB565 color definitions */
frankvnk 0:630b4da97968 40 #define Black 0x0000 /* 0, 0, 0 */
frankvnk 0:630b4da97968 41 #define Navy 0x000F /* 0, 0, 128 */
frankvnk 0:630b4da97968 42 #define DarkGreen 0x03E0 /* 0, 128, 0 */
frankvnk 0:630b4da97968 43 #define DarkCyan 0x03EF /* 0, 128, 128 */
frankvnk 0:630b4da97968 44 #define Maroon 0x7800 /* 128, 0, 0 */
frankvnk 0:630b4da97968 45 #define Purple 0x780F /* 128, 0, 128 */
frankvnk 0:630b4da97968 46 #define Olive 0x7BE0 /* 128, 128, 0 */
frankvnk 0:630b4da97968 47 #define LightGrey 0xC618 /* 192, 192, 192 */
frankvnk 0:630b4da97968 48 #define DarkGrey 0x7BEF /* 128, 128, 128 */
frankvnk 0:630b4da97968 49 #define Blue 0x001F /* 0, 0, 255 */
frankvnk 0:630b4da97968 50 #define Green 0x07E0 /* 0, 255, 0 */
frankvnk 0:630b4da97968 51 #define Cyan 0x07FF /* 0, 255, 255 */
frankvnk 0:630b4da97968 52 #define Red 0xF800 /* 255, 0, 0 */
frankvnk 0:630b4da97968 53 #define Magenta 0xF81F /* 255, 0, 255 */
frankvnk 0:630b4da97968 54 #define Yellow 0xFFE0 /* 255, 255, 0 */
frankvnk 0:630b4da97968 55 #define White 0xFFFF /* 255, 255, 255 */
frankvnk 0:630b4da97968 56 #define Orange 0xFD20 /* 255, 165, 0 */
frankvnk 0:630b4da97968 57 #define GreenYellow 0xAFE5 /* 173, 255, 47 */
frankvnk 0:630b4da97968 58
frankvnk 0:630b4da97968 59 class SPI_TFT : public GraphicsDisplay {
frankvnk 0:630b4da97968 60 public:
frankvnk 0:630b4da97968 61
frankvnk 0:630b4da97968 62 /** Create a SPI_TFT object connected to SPI and two pins
frankvnk 0:630b4da97968 63 *
frankvnk 0:630b4da97968 64 * @param mosi,miso,sclk SPI
frankvnk 0:630b4da97968 65 * @param cs pin connected to CS of display
frankvnk 0:630b4da97968 66 * @param reset pin connected to RESET of display
frankvnk 0:630b4da97968 67 *
frankvnk 0:630b4da97968 68 */
frankvnk 0:630b4da97968 69 SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name ="TFT");
frankvnk 0:630b4da97968 70
frankvnk 0:630b4da97968 71 /** Write a value to the to a LCD register
frankvnk 0:630b4da97968 72 *
frankvnk 0:630b4da97968 73 * @param reg register to be written
frankvnk 0:630b4da97968 74 * @param val data to be written
frankvnk 0:630b4da97968 75 */
frankvnk 0:630b4da97968 76 void wr_reg (unsigned char reg, unsigned short val);
frankvnk 0:630b4da97968 77
frankvnk 0:630b4da97968 78 /** Get the width of the screen in pixels
frankvnk 0:630b4da97968 79 *
frankvnk 0:630b4da97968 80 * @param
frankvnk 0:630b4da97968 81 * @returns width of screen in pixels
frankvnk 0:630b4da97968 82 *
frankvnk 0:630b4da97968 83 */
frankvnk 0:630b4da97968 84 virtual int width();
frankvnk 0:630b4da97968 85
frankvnk 0:630b4da97968 86 /** Get the height of the screen in pixels
frankvnk 0:630b4da97968 87 *
frankvnk 0:630b4da97968 88 * @returns height of screen in pixels
frankvnk 0:630b4da97968 89 *
frankvnk 0:630b4da97968 90 */
frankvnk 0:630b4da97968 91 virtual int height();
frankvnk 0:630b4da97968 92
frankvnk 0:630b4da97968 93 /** Draw a pixel at x,y with color
frankvnk 0:630b4da97968 94 *
frankvnk 0:630b4da97968 95 * @param x (horizontal position)
frankvnk 0:630b4da97968 96 * @param y (vertical position)
frankvnk 0:630b4da97968 97 * @param color (16 bit pixel color)
frankvnk 0:630b4da97968 98 */
frankvnk 0:630b4da97968 99 virtual void pixel(int x, int y,int colour);
frankvnk 0:630b4da97968 100
frankvnk 0:630b4da97968 101 /** Set draw window region to whole screen
frankvnk 0:630b4da97968 102 *
frankvnk 0:630b4da97968 103 */
frankvnk 0:630b4da97968 104 void WindowMax (void);
frankvnk 0:630b4da97968 105
frankvnk 0:630b4da97968 106 /** draw a 1 pixel line
frankvnk 0:630b4da97968 107 *
frankvnk 0:630b4da97968 108 * @param x0,y0 start point
frankvnk 0:630b4da97968 109 * @param x1,y1 stop point
frankvnk 0:630b4da97968 110 * @param color 16 bit color
frankvnk 0:630b4da97968 111 *
frankvnk 0:630b4da97968 112 */
frankvnk 0:630b4da97968 113 void line(int x0, int y0, int x1, int y1, int colour);
frankvnk 0:630b4da97968 114
frankvnk 0:630b4da97968 115 /** draw a rect
frankvnk 0:630b4da97968 116 *
frankvnk 0:630b4da97968 117 * @param x0,y0 top left corner
frankvnk 0:630b4da97968 118 * @param w,h width and height
frankvnk 0:630b4da97968 119 * @param color 16 bit color
frankvnk 0:630b4da97968 120 * *
frankvnk 0:630b4da97968 121 */
frankvnk 0:630b4da97968 122 void rect(int x0, int y0, int w, int h, int colour);
frankvnk 0:630b4da97968 123
frankvnk 0:630b4da97968 124 /** draw a filled rect
frankvnk 0:630b4da97968 125 *
frankvnk 0:630b4da97968 126 * @param x0,y0 top left corner
frankvnk 0:630b4da97968 127 * @param w,h width and height
frankvnk 0:630b4da97968 128 * @param color 16 bit color
frankvnk 0:630b4da97968 129 *
frankvnk 0:630b4da97968 130 */
frankvnk 0:630b4da97968 131 void fillrect(int x0, int y0, int w, int h, int colour);
frankvnk 0:630b4da97968 132
frankvnk 0:630b4da97968 133 /** draw an ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
frankvnk 0:630b4da97968 134 *
frankvnk 0:630b4da97968 135 * @param xc,yc center point
frankvnk 0:630b4da97968 136 * @param a,b semi-major axis and semi-minor axis
frankvnk 0:630b4da97968 137 * @param color 16 bit color
frankvnk 0:630b4da97968 138 *
frankvnk 0:630b4da97968 139 */
frankvnk 0:630b4da97968 140 void draw_ellipse(int xc, int yc, int a, int b, unsigned int color);
frankvnk 0:630b4da97968 141
frankvnk 0:630b4da97968 142 /** draw a filled ellipse - source : http://enchantia.com/graphapp/doc/tech/ellipses.html
frankvnk 0:630b4da97968 143 *
frankvnk 0:630b4da97968 144 * @param xc,yc center point
frankvnk 0:630b4da97968 145 * @param a,b semi-major axis and semi-minor axis
frankvnk 0:630b4da97968 146 * @param color 16 bit color
frankvnk 0:630b4da97968 147 *
frankvnk 0:630b4da97968 148 */
frankvnk 0:630b4da97968 149 void fill_ellipse(int xc, int yc, int a, int b, unsigned int color);
frankvnk 0:630b4da97968 150
frankvnk 0:630b4da97968 151 /** setup cursor position
frankvnk 0:630b4da97968 152 *
frankvnk 0:630b4da97968 153 * @param x x-position (top left)
frankvnk 0:630b4da97968 154 * @param y y-position
frankvnk 0:630b4da97968 155 */
frankvnk 0:630b4da97968 156 virtual void locate(int x, int y);
frankvnk 0:630b4da97968 157
frankvnk 0:630b4da97968 158 /** Fill the screen with _background color
frankvnk 0:630b4da97968 159 *
frankvnk 0:630b4da97968 160 */
frankvnk 0:630b4da97968 161 virtual void cls (void);
frankvnk 0:630b4da97968 162
frankvnk 0:630b4da97968 163 /** Read ILI9320 ID
frankvnk 0:630b4da97968 164 *
frankvnk 0:630b4da97968 165 * @returns LCD ID code
frankvnk 0:630b4da97968 166 *
frankvnk 0:630b4da97968 167 */
frankvnk 0:630b4da97968 168 unsigned short Read_ID(void);
frankvnk 0:630b4da97968 169
frankvnk 0:630b4da97968 170 /** calculate the max number of char in a line
frankvnk 0:630b4da97968 171 *
frankvnk 0:630b4da97968 172 * @returns max columns
frankvnk 0:630b4da97968 173 * depends on actual font size
frankvnk 0:630b4da97968 174 *
frankvnk 0:630b4da97968 175 */
frankvnk 0:630b4da97968 176 virtual int columns(void);
frankvnk 0:630b4da97968 177
frankvnk 0:630b4da97968 178 /** calculate the max number of rows
frankvnk 0:630b4da97968 179 *
frankvnk 0:630b4da97968 180 * @returns max rows
frankvnk 0:630b4da97968 181 * depends on actual font size
frankvnk 0:630b4da97968 182 *
frankvnk 0:630b4da97968 183 */
frankvnk 0:630b4da97968 184 virtual int rows(void);
frankvnk 0:630b4da97968 185
frankvnk 0:630b4da97968 186 /** put a char on the screen
frankvnk 0:630b4da97968 187 *
frankvnk 0:630b4da97968 188 * @param value char to print
frankvnk 0:630b4da97968 189 * @returns printed char
frankvnk 0:630b4da97968 190 *
frankvnk 0:630b4da97968 191 */
frankvnk 0:630b4da97968 192 virtual int _putc(int value);
frankvnk 0:630b4da97968 193
frankvnk 0:630b4da97968 194 /** draw a character on given position out of the active font to the TFT
frankvnk 0:630b4da97968 195 *
frankvnk 0:630b4da97968 196 * @param x x-position of char (top left)
frankvnk 0:630b4da97968 197 * @param y y-position
frankvnk 0:630b4da97968 198 * @param c char to print
frankvnk 0:630b4da97968 199 *
frankvnk 0:630b4da97968 200 */
frankvnk 0:630b4da97968 201 virtual void character(int x, int y, int c);
frankvnk 0:630b4da97968 202
frankvnk 0:630b4da97968 203 /** paint a bitmap on the TFT
frankvnk 0:630b4da97968 204 *
frankvnk 0:630b4da97968 205 * @param x,y : upper left corner
frankvnk 0:630b4da97968 206 * @param w width of bitmap
frankvnk 0:630b4da97968 207 * @param h high of bitmap
frankvnk 0:630b4da97968 208 * @param *bitmap pointer to the bitmap data
frankvnk 0:630b4da97968 209 *
frankvnk 0:630b4da97968 210 * bitmap format: 16 bit R5 G6 B5
frankvnk 0:630b4da97968 211 *
frankvnk 0:630b4da97968 212 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
frankvnk 0:630b4da97968 213 * use winhex to load this file and mark data stating at offset 0x46 to end
frankvnk 0:630b4da97968 214 * use edit -> copy block -> C Source to export C array
frankvnk 0:630b4da97968 215 * paste this array into your program
frankvnk 0:630b4da97968 216 *
frankvnk 0:630b4da97968 217 * define the array as static const unsigned char to put it into flash memory
frankvnk 0:630b4da97968 218 * cast the pointer to (unsigned char *) :
frankvnk 0:630b4da97968 219 * tft.Bitmap(10,40,309,50,(unsigned char *)scala);
frankvnk 0:630b4da97968 220 */
frankvnk 0:630b4da97968 221 void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *Name_BMP);
frankvnk 0:630b4da97968 222
frankvnk 0:630b4da97968 223
frankvnk 0:630b4da97968 224 /** paint a BMP (16/24 bit) from filesytem on the TFT (slow)
frankvnk 0:630b4da97968 225 *
frankvnk 0:630b4da97968 226 * The 16-bit format is RGB-565. Using 16-bit is faster than 24-bit, however every program can
frankvnk 0:630b4da97968 227 * output 24 bit BMPs (including MS paint), while it is hard to get them in the correct 16-bit format.
frankvnk 0:630b4da97968 228 *
frankvnk 0:630b4da97968 229 * @param x,y : upper left corner
frankvnk 0:630b4da97968 230 * @param *Name_BMP location of the BMP file (for example "/sd/test.bmp")
frankvnk 0:630b4da97968 231 * @returns 1 if bmp file was found and stored
frankvnk 0:630b4da97968 232 * @returns 0 if file was not found
frankvnk 0:630b4da97968 233 * @returns -1 if file was not a bmp
frankvnk 0:630b4da97968 234 * @returns -2 if bmp file is not 16/24bit
frankvnk 0:630b4da97968 235 * @returns -3 if bmp file is wrong for screen
frankvnk 0:630b4da97968 236 * @returns -4 if buffer malloc goes wrong
frankvnk 0:630b4da97968 237 *
frankvnk 0:630b4da97968 238 */
frankvnk 0:630b4da97968 239
frankvnk 0:630b4da97968 240 int Bitmap(unsigned int x, unsigned int y, const char *Name_BMP);
frankvnk 0:630b4da97968 241
frankvnk 0:630b4da97968 242
frankvnk 0:630b4da97968 243
frankvnk 0:630b4da97968 244 /** select the font to use
frankvnk 0:630b4da97968 245 *
frankvnk 0:630b4da97968 246 * @param f pointer to font array
frankvnk 0:630b4da97968 247 *
frankvnk 0:630b4da97968 248 * font array can be created with GLCD Font Creator from http://www.mikroe.com
frankvnk 0:630b4da97968 249 * you have to add 4 parameter at the beginning of the font array to use:
frankvnk 0:630b4da97968 250 * - the number of bytes / char
frankvnk 0:630b4da97968 251 * - the vertial size in pixels
frankvnk 0:630b4da97968 252 * - the horizontal size in pixels
frankvnk 0:630b4da97968 253 * - the number of bytes per vertical line
frankvnk 0:630b4da97968 254 * you also have to change the array to char[]
frankvnk 0:630b4da97968 255 *
frankvnk 0:630b4da97968 256 */
frankvnk 0:630b4da97968 257 void set_font(unsigned char* f);
frankvnk 0:630b4da97968 258
frankvnk 0:630b4da97968 259 /** Set the orientation of the screen
frankvnk 0:630b4da97968 260 * x,y: 0,0 is always top left
frankvnk 0:630b4da97968 261 *
frankvnk 0:630b4da97968 262 * @param o direction to use the screen (0-3) 90� Steps
frankvnk 0:630b4da97968 263 *
frankvnk 0:630b4da97968 264 */
frankvnk 0:630b4da97968 265 void set_orientation(unsigned int o);
frankvnk 0:630b4da97968 266
frankvnk 0:630b4da97968 267
frankvnk 0:630b4da97968 268 /** Modify the orientation of the screen
frankvnk 0:630b4da97968 269 * x,y: 0,0 is always top left
frankvnk 0:630b4da97968 270 *
frankvnk 0:630b4da97968 271 * @param none
frankvnk 0:630b4da97968 272 *
frankvnk 0:630b4da97968 273 * ILI9320 limitation: The orientation can only be used with a window command (registers 0x50..0x53)
frankvnk 0:630b4da97968 274 *
frankvnk 0:630b4da97968 275 * reg 03h (Entry Mode) : BGR = 1 - ORG = 1 - ID0, ID1 and AM are set according to the orientation variable.
frankvnk 0:630b4da97968 276 * IMPORTANT : when ORG = 1, the GRAM writing direction follows the orientation (ID0, ID1, AM bits)
frankvnk 0:630b4da97968 277 * AND we need to use the window command (reg 50h..53h) to write to an area on the display
frankvnk 0:630b4da97968 278 * because we cannot change reg 20h and 21h to set the GRAM address (they both remain at 00h).
frankvnk 0:630b4da97968 279 * This means that the pixel routine does not work when ORG = 1.
frankvnk 0:630b4da97968 280 * Routines relying on the pixel routine first need to set reg 03h = 0x1030
frankvnk 0:630b4da97968 281 * (cls, circle and line do so) AND need to write the data according to the orientation variable.
frankvnk 0:630b4da97968 282 */
frankvnk 0:630b4da97968 283 void mod_orientation(void);
frankvnk 0:630b4da97968 284
frankvnk 0:630b4da97968 285 #ifndef NO_FLASH_BUFFER
frankvnk 0:630b4da97968 286 /** Move an image to the background buffer
frankvnk 0:630b4da97968 287 *
frankvnk 0:630b4da97968 288 * The image must fit exactly on the screen (240x320). This function takes quite some time, depending on source filesystem.
frankvnk 0:630b4da97968 289 *
frankvnk 0:630b4da97968 290 * @param *Name_BMP location of the BMP file (for example "/sd/test.bmp")
frankvnk 0:630b4da97968 291 * @returns 1 if bmp file was found and stored
frankvnk 0:630b4da97968 292 * @returns 0 if file was not found
frankvnk 0:630b4da97968 293 * @returns -1 if file was not a bmp
frankvnk 0:630b4da97968 294 * @returns -2 if bmp file is not 16/24bit
frankvnk 0:630b4da97968 295 * @returns -3 if bmp file is wrong for screen
frankvnk 0:630b4da97968 296 * @returns -4 if buffer malloc goes wrong
frankvnk 0:630b4da97968 297 */
frankvnk 0:630b4da97968 298 int fileToFlash(const char *Name_BMP);
frankvnk 0:630b4da97968 299
frankvnk 0:630b4da97968 300 /** Use the image on the flash memory as background
frankvnk 0:630b4da97968 301 *
frankvnk 0:630b4da97968 302 * @param active - true to use the image, false to use static color
frankvnk 0:630b4da97968 303 */
frankvnk 0:630b4da97968 304 void backgroundImage(bool active);
frankvnk 0:630b4da97968 305 #endif
frankvnk 0:630b4da97968 306
frankvnk 0:630b4da97968 307
frankvnk 0:630b4da97968 308
frankvnk 0:630b4da97968 309
frankvnk 0:630b4da97968 310
frankvnk 0:630b4da97968 311 // ------------------ PROTECTED PART ------------------
frankvnk 0:630b4da97968 312 protected:
frankvnk 0:630b4da97968 313
frankvnk 0:630b4da97968 314 /** draw a horizontal line
frankvnk 0:630b4da97968 315 *
frankvnk 0:630b4da97968 316 * @param x0 horizontal start
frankvnk 0:630b4da97968 317 * @param x1 horizontal stop
frankvnk 0:630b4da97968 318 * @param y vertical position
frankvnk 0:630b4da97968 319 * @param color 16 bit color
frankvnk 0:630b4da97968 320 *
frankvnk 0:630b4da97968 321 */
frankvnk 0:630b4da97968 322 void hline(int x0, int x1, int y, int colour);
frankvnk 0:630b4da97968 323
frankvnk 0:630b4da97968 324 /** draw a vertical line
frankvnk 0:630b4da97968 325 *
frankvnk 0:630b4da97968 326 * @param x horizontal position
frankvnk 0:630b4da97968 327 * @param y0 vertical start
frankvnk 0:630b4da97968 328 * @param y1 vertical stop
frankvnk 0:630b4da97968 329 * @param color 16 bit color
frankvnk 0:630b4da97968 330 */
frankvnk 0:630b4da97968 331 void vline(int y0, int y1, int x, int colour);
frankvnk 0:630b4da97968 332
frankvnk 0:630b4da97968 333 /** Set draw window region
frankvnk 0:630b4da97968 334 *
frankvnk 0:630b4da97968 335 * @param x horizontal position
frankvnk 0:630b4da97968 336 * @param y vertical position
frankvnk 0:630b4da97968 337 * @param w window width in pixel
frankvnk 0:630b4da97968 338 * @param h window height in pixels
frankvnk 0:630b4da97968 339 */
frankvnk 0:630b4da97968 340 virtual void window (int x, int y, int w, int h);
frankvnk 0:630b4da97968 341
frankvnk 0:630b4da97968 342 /** Init the ILI9320 controller
frankvnk 0:630b4da97968 343 *
frankvnk 0:630b4da97968 344 */
frankvnk 0:630b4da97968 345 void tft_reset();
frankvnk 0:630b4da97968 346
frankvnk 0:630b4da97968 347 /** Write data to the LCD controller
frankvnk 0:630b4da97968 348 *
frankvnk 0:630b4da97968 349 * @param dat data written to LCD controller
frankvnk 0:630b4da97968 350 *
frankvnk 0:630b4da97968 351 */
frankvnk 0:630b4da97968 352 void wr_dat(unsigned short value);
frankvnk 0:630b4da97968 353
frankvnk 0:630b4da97968 354 /** Start data sequence to the LCD controller
frankvnk 0:630b4da97968 355 *
frankvnk 0:630b4da97968 356 */
frankvnk 0:630b4da97968 357 void wr_dat_start(void);
frankvnk 0:630b4da97968 358
frankvnk 0:630b4da97968 359 /** Write a command the LCD controller
frankvnk 0:630b4da97968 360 *
frankvnk 0:630b4da97968 361 * @param cmd: command to be written
frankvnk 0:630b4da97968 362 *
frankvnk 0:630b4da97968 363 */
frankvnk 0:630b4da97968 364 void wr_cmd(unsigned char value);
frankvnk 0:630b4da97968 365
frankvnk 0:630b4da97968 366 /** Read data from the LCD controller
frankvnk 0:630b4da97968 367 *
frankvnk 0:630b4da97968 368 * @returns data from LCD controller
frankvnk 0:630b4da97968 369 *
frankvnk 0:630b4da97968 370 */
frankvnk 0:630b4da97968 371 unsigned short rd_dat(void);
frankvnk 0:630b4da97968 372
frankvnk 0:630b4da97968 373 /** Read a LCD register
frankvnk 0:630b4da97968 374 *
frankvnk 0:630b4da97968 375 * @param reg register to be read
frankvnk 0:630b4da97968 376 * @returns value of the register
frankvnk 0:630b4da97968 377 */
frankvnk 0:630b4da97968 378 unsigned short rd_reg (unsigned char reg);
frankvnk 0:630b4da97968 379
frankvnk 0:630b4da97968 380 /** Set the cursor position
frankvnk 0:630b4da97968 381 *
frankvnk 0:630b4da97968 382 * @param x (horizontal position)
frankvnk 0:630b4da97968 383 * @param y (vertical position)
frankvnk 0:630b4da97968 384 *
frankvnk 0:630b4da97968 385 * Can only be used when reg 03h = 0x1030 (see note in mod_orientation).
frankvnk 0:630b4da97968 386 *
frankvnk 0:630b4da97968 387 */
frankvnk 0:630b4da97968 388 void SetCursor( unsigned short Xpos, unsigned short Ypos );
frankvnk 0:630b4da97968 389
frankvnk 0:630b4da97968 390 struct bitmapData {
frankvnk 0:630b4da97968 391 int return_code;
frankvnk 0:630b4da97968 392 int width, height;
frankvnk 0:630b4da97968 393 int bits, pad;
frankvnk 0:630b4da97968 394 int start_data;
frankvnk 0:630b4da97968 395 FILE *file;
frankvnk 0:630b4da97968 396 };
frankvnk 0:630b4da97968 397
frankvnk 0:630b4da97968 398 /** Get bitmap info
frankvnk 0:630b4da97968 399 *
frankvnk 0:630b4da97968 400 * @param *Name_BMP Bitmap filename
frankvnk 0:630b4da97968 401 * @returns structure: return_code 1 if bmp file was found and stored
frankvnk 0:630b4da97968 402 * 0 if file was not found
frankvnk 0:630b4da97968 403 * -1 if file was not a bmp
frankvnk 0:630b4da97968 404 * -2 if bmp file is not 16/24bit
frankvnk 0:630b4da97968 405 * -3 if bmp file is wrong for screen
frankvnk 0:630b4da97968 406 * width, height Bitmap size
frankvnk 0:630b4da97968 407 * bits, pad BPP, padding (multiple of 4 bytes)
frankvnk 0:630b4da97968 408 * start_data Starting address of the byte where the bitmap image data (pixel array) can be found
frankvnk 0:630b4da97968 409 * *file Bitmap filename
frankvnk 0:630b4da97968 410 */
frankvnk 0:630b4da97968 411 bitmapData getBitmapData(const char *Name_BMP);
frankvnk 0:630b4da97968 412
frankvnk 0:630b4da97968 413 unsigned int orientation;
frankvnk 0:630b4da97968 414 unsigned int char_x;
frankvnk 0:630b4da97968 415 unsigned int char_y;
frankvnk 0:630b4da97968 416 bool backgroundimage;
frankvnk 0:630b4da97968 417 BurstSPI _spi;
frankvnk 0:630b4da97968 418 DigitalOut _cs;
frankvnk 0:630b4da97968 419 unsigned char* font;
frankvnk 0:630b4da97968 420 #ifndef NO_FLASH_BUFFER
frankvnk 0:630b4da97968 421 IAP iap;
frankvnk 0:630b4da97968 422 int backgroundOrientation;
frankvnk 0:630b4da97968 423 #endif
frankvnk 0:630b4da97968 424
frankvnk 0:630b4da97968 425 };
frankvnk 0:630b4da97968 426
frankvnk 0:630b4da97968 427 #endif