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 May 30 13:35:24 2014 +0000
Revision:
4:2519f2e680af
Parent:
3:a016fe71ed72
Added  ILI9325 and ILI9328 initialization

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