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:
0:630b4da97968
Added  ILI9325 and ILI9328 initialization

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frankvnk 0:630b4da97968 1 /* mbed TextDisplay Library Base Class
frankvnk 0:630b4da97968 2 * Copyright (c) 2007-2009 sford
frankvnk 0:630b4da97968 3 * Released under the MIT License: http://mbed.org/license/mit
frankvnk 0:630b4da97968 4 *
frankvnk 0:630b4da97968 5 * A common base class for Text displays
frankvnk 0:630b4da97968 6 * To port a new display, derive from this class and implement
frankvnk 0:630b4da97968 7 * the constructor (setup the display), character (put a character
frankvnk 0:630b4da97968 8 * at a location), rows and columns (number of rows/cols) functions.
frankvnk 0:630b4da97968 9 * Everything else (locate, printf, putc, cls) will come for free
frankvnk 0:630b4da97968 10 *
frankvnk 0:630b4da97968 11 * The model is the display will wrap at the right and bottom, so you can
frankvnk 0:630b4da97968 12 * keep writing and will always get valid characters. The location is
frankvnk 0:630b4da97968 13 * maintained internally to the class to make this easy
frankvnk 0:630b4da97968 14 */
frankvnk 0:630b4da97968 15
frankvnk 0:630b4da97968 16 #ifndef MBED_TEXTDISPLAY_H
frankvnk 0:630b4da97968 17 #define MBED_TEXTDISPLAY_H
frankvnk 0:630b4da97968 18
frankvnk 0:630b4da97968 19 #include "mbed.h"
frankvnk 0:630b4da97968 20
frankvnk 0:630b4da97968 21 class TextDisplay : public Stream {
frankvnk 0:630b4da97968 22 public:
frankvnk 0:630b4da97968 23
frankvnk 0:630b4da97968 24 // functions needing implementation in derived implementation class
frankvnk 0:630b4da97968 25 /** Create a TextDisplay interface
frankvnk 0:630b4da97968 26 *
frankvnk 0:630b4da97968 27 * @param name The name used in the path to access the strean through the filesystem
frankvnk 0:630b4da97968 28 */
frankvnk 0:630b4da97968 29 TextDisplay(const char *name = NULL);
frankvnk 0:630b4da97968 30
frankvnk 0:630b4da97968 31 /** output a character at the given position
frankvnk 0:630b4da97968 32 *
frankvnk 0:630b4da97968 33 * @param column column where charater must be written
frankvnk 0:630b4da97968 34 * @param row where character must be written
frankvnk 0:630b4da97968 35 * @param c the character to be written to the TextDisplay
frankvnk 0:630b4da97968 36 */
frankvnk 0:630b4da97968 37 virtual void character(int column, int row, int c) = 0;
frankvnk 0:630b4da97968 38
frankvnk 0:630b4da97968 39 /** return number if rows on TextDisplay
frankvnk 0:630b4da97968 40 * @result number of rows
frankvnk 0:630b4da97968 41 */
frankvnk 0:630b4da97968 42 virtual int rows() = 0;
frankvnk 0:630b4da97968 43
frankvnk 0:630b4da97968 44 /** return number if columns on TextDisplay
frankvnk 0:630b4da97968 45 * @result number of rows
frankvnk 0:630b4da97968 46 */
frankvnk 0:630b4da97968 47 virtual int columns() = 0;
frankvnk 0:630b4da97968 48
frankvnk 0:630b4da97968 49 // functions that come for free, but can be overwritten
frankvnk 0:630b4da97968 50
frankvnk 0:630b4da97968 51 /** redirect output from a stream (stoud, sterr) to display
frankvnk 0:630b4da97968 52 * @param stream stream that shall be redirected to the TextDisplay
frankvnk 0:630b4da97968 53 */
frankvnk 0:630b4da97968 54 virtual bool claim (FILE *stream);
frankvnk 0:630b4da97968 55
frankvnk 0:630b4da97968 56 /** clear screen
frankvnk 0:630b4da97968 57 */
frankvnk 0:630b4da97968 58 virtual void cls();
frankvnk 0:630b4da97968 59 virtual void locate(int column, int row);
frankvnk 0:630b4da97968 60 virtual void foreground(uint16_t colour);
frankvnk 0:630b4da97968 61 virtual void background(uint16_t colour);
frankvnk 0:630b4da97968 62 // putc (from Stream)
frankvnk 0:630b4da97968 63 // printf (from Stream)
frankvnk 0:630b4da97968 64
frankvnk 0:630b4da97968 65 protected:
frankvnk 0:630b4da97968 66
frankvnk 0:630b4da97968 67 virtual int _putc(int value);
frankvnk 0:630b4da97968 68 virtual int _getc();
frankvnk 0:630b4da97968 69
frankvnk 0:630b4da97968 70 // character location
frankvnk 0:630b4da97968 71 uint16_t _column;
frankvnk 0:630b4da97968 72 uint16_t _row;
frankvnk 0:630b4da97968 73
frankvnk 0:630b4da97968 74 // colours
frankvnk 0:630b4da97968 75 uint16_t _foreground;
frankvnk 0:630b4da97968 76 uint16_t _background;
frankvnk 0:630b4da97968 77 char *_path;
frankvnk 0:630b4da97968 78 };
frankvnk 0:630b4da97968 79
frankvnk 0:630b4da97968 80 #endif