Forked from TFTLCD_8bit by Thiha Electronics

Dependents:   GR-PEACH_TFTLCD_8bit

Fork of TFTLCD_8bit by Thiha Electronics

Committer:
ThihaElectronics
Date:
Wed Dec 03 16:35:25 2014 +0000
Revision:
32:155abe4126e3
sorry if i broken any of your code by recent check in. please enlighten me how to unlink library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThihaElectronics 32:155abe4126e3 1 /** \file ili9328.h
ThihaElectronics 32:155abe4126e3 2 * \brief mbed LCD driver for displays with the ILI9328 controller.
ThihaElectronics 32:155abe4126e3 3 * \copyright GNU Public License, v2. or later
ThihaElectronics 32:155abe4126e3 4 *
ThihaElectronics 32:155abe4126e3 5 * This library is based on the Arduino/chipKIT UTFT library by Henning
ThihaElectronics 32:155abe4126e3 6 * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52
ThihaElectronics 32:155abe4126e3 7 *
ThihaElectronics 32:155abe4126e3 8 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
ThihaElectronics 32:155abe4126e3 9 *
ThihaElectronics 32:155abe4126e3 10 * Copyright (C)2012-2013 Todor Todorov.
ThihaElectronics 32:155abe4126e3 11 *
ThihaElectronics 32:155abe4126e3 12 * This library is free software; you can redistribute it and/or
ThihaElectronics 32:155abe4126e3 13 * modify it under the terms of the GNU Lesser General Public
ThihaElectronics 32:155abe4126e3 14 * License as published by the Free Software Foundation; either
ThihaElectronics 32:155abe4126e3 15 * version 2.1 of the License, or (at your option) any later version.
ThihaElectronics 32:155abe4126e3 16 *
ThihaElectronics 32:155abe4126e3 17 * This library is distributed in the hope that it will be useful,
ThihaElectronics 32:155abe4126e3 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ThihaElectronics 32:155abe4126e3 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ThihaElectronics 32:155abe4126e3 20 * Lesser General Public License for more details.
ThihaElectronics 32:155abe4126e3 21 *
ThihaElectronics 32:155abe4126e3 22 * You should have received a copy of the GNU Lesser General Public
ThihaElectronics 32:155abe4126e3 23 * License along with this library; if not, write to:
ThihaElectronics 32:155abe4126e3 24 *
ThihaElectronics 32:155abe4126e3 25 * Free Software Foundation, Inc.
ThihaElectronics 32:155abe4126e3 26 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
ThihaElectronics 32:155abe4126e3 27 *
ThihaElectronics 32:155abe4126e3 28 *********************************************************************/
ThihaElectronics 32:155abe4126e3 29 #ifndef TFTLCD_ILI9328_H
ThihaElectronics 32:155abe4126e3 30 #define TFTLCD_ILI9328_H
ThihaElectronics 32:155abe4126e3 31
ThihaElectronics 32:155abe4126e3 32 #include "lcd_base.h"
ThihaElectronics 32:155abe4126e3 33
ThihaElectronics 32:155abe4126e3 34 #ifdef __cplusplus
ThihaElectronics 32:155abe4126e3 35 extern "C" {
ThihaElectronics 32:155abe4126e3 36 #endif
ThihaElectronics 32:155abe4126e3 37
ThihaElectronics 32:155abe4126e3 38 /** Represents a LCD instance.
ThihaElectronics 32:155abe4126e3 39 *
ThihaElectronics 32:155abe4126e3 40 * This is the utility class, through which the display can be manipulated
ThihaElectronics 32:155abe4126e3 41 * and graphics objects can be shown to the user. A known display, which
ThihaElectronics 32:155abe4126e3 42 * works with this library is the INANBO-T24-ILI9328-V11 - a RGB TFT
ThihaElectronics 32:155abe4126e3 43 * with 240x320 pixels resolution and 65K/262K colors, using 8/16-bit interface.
ThihaElectronics 32:155abe4126e3 44 *
ThihaElectronics 32:155abe4126e3 45 * The display works with a supply voltage of 2.8-3.3 volts for both logic and
ThihaElectronics 32:155abe4126e3 46 * backlight. It can be driven in 8bit or 16bit interface mode. (Current
ThihaElectronics 32:155abe4126e3 47 * version of the driver works only in 16bit mode for now.)
ThihaElectronics 32:155abe4126e3 48 *
ThihaElectronics 32:155abe4126e3 49 * How to use:
ThihaElectronics 32:155abe4126e3 50 * \code
ThihaElectronics 32:155abe4126e3 51 * // include the library, this will also pull in the header for the provided fonts
ThihaElectronics 32:155abe4126e3 52 * #include "ili9328.h"
ThihaElectronics 32:155abe4126e3 53 *
ThihaElectronics 32:155abe4126e3 54 * // prepare the data bus for writing commands and pixel data
ThihaElectronics 32:155abe4126e3 55 * BusOut dataBus( p30, p29, p28, p27, p26, p25, p24, p23, p22, p21, p20, p19, p18, p17, p16, p15 ); // 16 pins
ThihaElectronics 32:155abe4126e3 56 * // create the lcd instance
ThihaElectronics 32:155abe4126e3 57 * ILI9328_LCD lcd( p14, p13, p12, p11, &dataBus ); // control pins and data bus
ThihaElectronics 32:155abe4126e3 58 *
ThihaElectronics 32:155abe4126e3 59 * int main()
ThihaElectronics 32:155abe4126e3 60 * {
ThihaElectronics 32:155abe4126e3 61 * // initialize display - place it in standard portrait mode and set background to black and
ThihaElectronics 32:155abe4126e3 62 * // foreground to white color.
ThihaElectronics 32:155abe4126e3 63 * lcd.Initialize();
ThihaElectronics 32:155abe4126e3 64 * // set current font to the smallest 8x12 pixels font.
ThihaElectronics 32:155abe4126e3 65 * lcd.SetFont( Font8x12 );
ThihaElectronics 32:155abe4126e3 66 * // print something on the screen
ThihaElectronics 32:155abe4126e3 67 * lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors
ThihaElectronics 32:155abe4126e3 68 *
ThihaElectronics 32:155abe4126e3 69 * while ( 1 ) { }
ThihaElectronics 32:155abe4126e3 70 * }
ThihaElectronics 32:155abe4126e3 71 *
ThihaElectronics 32:155abe4126e3 72 * \endcode
ThihaElectronics 32:155abe4126e3 73 * \version 0.1
ThihaElectronics 32:155abe4126e3 74 * \author Todor Todorov
ThihaElectronics 32:155abe4126e3 75 */
ThihaElectronics 32:155abe4126e3 76 class ILI9328_LCD : public LCD
ThihaElectronics 32:155abe4126e3 77 {
ThihaElectronics 32:155abe4126e3 78 public:
ThihaElectronics 32:155abe4126e3 79 /** Creates a new instance of the class.
ThihaElectronics 32:155abe4126e3 80 *
ThihaElectronics 32:155abe4126e3 81 * \param CS Pin for the ChipSelect signal.
ThihaElectronics 32:155abe4126e3 82 * \param RESET Pin for the RESET line.
ThihaElectronics 32:155abe4126e3 83 * \param RS Pin for the RS signal.
ThihaElectronics 32:155abe4126e3 84 * \param WR Pin for the WR signal.
ThihaElectronics 32:155abe4126e3 85 * \param DATA_PORT Address of the data bus for transfer of commands and pixel data.
ThihaElectronics 32:155abe4126e3 86 * \param BL Pin for controlling the backlight. By default not used.
ThihaElectronics 32:155abe4126e3 87 * \param RD Pin for the RD signal. This line is not needed by the driver, so if you would like to
ThihaElectronics 32:155abe4126e3 88 * use the pin on the mbed for something else, just pull-up the respective pin on the LCD high,
ThihaElectronics 32:155abe4126e3 89 * and do not assign a value to this parameter when creating the controller instance.
ThihaElectronics 32:155abe4126e3 90 * \param blType The backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch
ThihaElectronics 32:155abe4126e3 91 * \param defaultBacklightLevel If using PWM to control backlight, this would be the default brightness in percent after LCD initialization.
ThihaElectronics 32:155abe4126e3 92 */
ThihaElectronics 32:155abe4126e3 93 ILI9328_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL = NC, PinName RD = NC, backlight_t blType = Constant, float defaultBackLightLevel = 1.0 );
ThihaElectronics 32:155abe4126e3 94
ThihaElectronics 32:155abe4126e3 95 /** Initialize display.
ThihaElectronics 32:155abe4126e3 96 *
ThihaElectronics 32:155abe4126e3 97 * Wakes up the display from sleep, initializes power parameters.
ThihaElectronics 32:155abe4126e3 98 * This function must be called first, befor any painting on the
ThihaElectronics 32:155abe4126e3 99 * display is done, otherwise the positioning of graphical elements
ThihaElectronics 32:155abe4126e3 100 * will not work properly and any paynt operation will not be visible
ThihaElectronics 32:155abe4126e3 101 * or produce garbage.
ThihaElectronics 32:155abe4126e3 102 *
ThihaElectronics 32:155abe4126e3 103 * \param oritentation The display orientation, landscape is default.
ThihaElectronics 32:155abe4126e3 104 * \param colors The correct color depth to use for the pixel data. Value is disregarded.
ThihaElectronics 32:155abe4126e3 105 */
ThihaElectronics 32:155abe4126e3 106 virtual void Initialize( orientation_t orientation = LANDSCAPE, colordepth_t colors = RGB16 );
ThihaElectronics 32:155abe4126e3 107
ThihaElectronics 32:155abe4126e3 108 /** Puts the display to sleep.
ThihaElectronics 32:155abe4126e3 109 *
ThihaElectronics 32:155abe4126e3 110 * When the display is in sleep mode, its power consumption is
ThihaElectronics 32:155abe4126e3 111 * minimized. Before new pixel data can be written to the display
ThihaElectronics 32:155abe4126e3 112 * memory, the controller needs to be brought out of sleep mode.
ThihaElectronics 32:155abe4126e3 113 * \sa #WakeUp( void );
ThihaElectronics 32:155abe4126e3 114 * \remarks The result of this operation might not be exactly as
ThihaElectronics 32:155abe4126e3 115 * expected. Putting the display to sleep will cause the
ThihaElectronics 32:155abe4126e3 116 * controller to switch to the standard color of the LCD,
ThihaElectronics 32:155abe4126e3 117 * so depending on whether the display is normally white,
ThihaElectronics 32:155abe4126e3 118 * or normally dark, the screen might or might not go
ThihaElectronics 32:155abe4126e3 119 * dark. Additional power saving can be achieved, if
ThihaElectronics 32:155abe4126e3 120 * the backlight of the used display is not hardwired on
ThihaElectronics 32:155abe4126e3 121 * the PCB and can be controlled via the BL pin.
ThihaElectronics 32:155abe4126e3 122 */
ThihaElectronics 32:155abe4126e3 123 virtual void Sleep( void );
ThihaElectronics 32:155abe4126e3 124
ThihaElectronics 32:155abe4126e3 125 /** Wakes up the display from sleep mode.
ThihaElectronics 32:155abe4126e3 126 *
ThihaElectronics 32:155abe4126e3 127 * This function needs to be called before any other, when the
ThihaElectronics 32:155abe4126e3 128 * display has been put into sleep mode by a previois call to
ThihaElectronics 32:155abe4126e3 129 * #Sleep( void ).
ThihaElectronics 32:155abe4126e3 130 */
ThihaElectronics 32:155abe4126e3 131 virtual void WakeUp( void );
ThihaElectronics 32:155abe4126e3 132
ThihaElectronics 32:155abe4126e3 133 protected:
ThihaElectronics 32:155abe4126e3 134 /** Sends a command to the display.
ThihaElectronics 32:155abe4126e3 135 *
ThihaElectronics 32:155abe4126e3 136 * \param cmd The display command.
ThihaElectronics 32:155abe4126e3 137 * \remarks Commands are controller-specific and this function needs to
ThihaElectronics 32:155abe4126e3 138 * be implemented separately for each available controller.
ThihaElectronics 32:155abe4126e3 139 */
ThihaElectronics 32:155abe4126e3 140 virtual void WriteCmd( unsigned short cmd );
ThihaElectronics 32:155abe4126e3 141
ThihaElectronics 32:155abe4126e3 142 /** Sends pixel data to the display.
ThihaElectronics 32:155abe4126e3 143 *
ThihaElectronics 32:155abe4126e3 144 * \param data The display data.
ThihaElectronics 32:155abe4126e3 145 * \remarks Sending data is controller-specific and this function needs to
ThihaElectronics 32:155abe4126e3 146 * be implemented separately for each available controller.
ThihaElectronics 32:155abe4126e3 147 */
ThihaElectronics 32:155abe4126e3 148 virtual void WriteData( unsigned short data );
ThihaElectronics 32:155abe4126e3 149
ThihaElectronics 32:155abe4126e3 150 /** Assigns a chunk of the display memory to receive data.
ThihaElectronics 32:155abe4126e3 151 *
ThihaElectronics 32:155abe4126e3 152 * When data is sent to the display after this function completes, the opertion will
ThihaElectronics 32:155abe4126e3 153 * start from the begining of the assigned address (pixel position) and the pointer
ThihaElectronics 32:155abe4126e3 154 * will be automatically incremented so that the next data write operation will continue
ThihaElectronics 32:155abe4126e3 155 * with the next pixel from the memory block. If more data is written than available
ThihaElectronics 32:155abe4126e3 156 * pixels, at the end of the block the pointer will jump back to its beginning and
ThihaElectronics 32:155abe4126e3 157 * commence again, until the next address change command is sent to the display.
ThihaElectronics 32:155abe4126e3 158 *
ThihaElectronics 32:155abe4126e3 159 * \param x1 The X coordinate of the pixel at the beginning of the block.
ThihaElectronics 32:155abe4126e3 160 * \param y1 The Y coordinate of the pixel at the beginning of the block.
ThihaElectronics 32:155abe4126e3 161 * \param x2 The X coordinate of the pixel at the end of the block.
ThihaElectronics 32:155abe4126e3 162 * \param y2 The Y coordinate of the pixel at the end of the block.
ThihaElectronics 32:155abe4126e3 163 * \remarks Addressing commands are controller-specific and this function needs to be
ThihaElectronics 32:155abe4126e3 164 * implemented separately for each available controller.
ThihaElectronics 32:155abe4126e3 165 */
ThihaElectronics 32:155abe4126e3 166 virtual void SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 );
ThihaElectronics 32:155abe4126e3 167
ThihaElectronics 32:155abe4126e3 168 /** Sets the color of the pixel at the address pointer of the controller.
ThihaElectronics 32:155abe4126e3 169 *
ThihaElectronics 32:155abe4126e3 170 * This function is to be provided by each implementation separately in
ThihaElectronics 32:155abe4126e3 171 * order to account for different color depth used by the controller.
ThihaElectronics 32:155abe4126e3 172 * \param color The color of the pixel.
ThihaElectronics 32:155abe4126e3 173 * \param mode The depth (palette) of the color.
ThihaElectronics 32:155abe4126e3 174 */
ThihaElectronics 32:155abe4126e3 175 virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 );
ThihaElectronics 32:155abe4126e3 176
ThihaElectronics 32:155abe4126e3 177 private:
ThihaElectronics 32:155abe4126e3 178 DigitalOut _lcd_pin_wr;
ThihaElectronics 32:155abe4126e3 179 BusOut* _lcd_port;
ThihaElectronics 32:155abe4126e3 180 DigitalOut* _lcd_pin_bl;
ThihaElectronics 32:155abe4126e3 181 DigitalOut* _lcd_pin_rd;
ThihaElectronics 32:155abe4126e3 182 };
ThihaElectronics 32:155abe4126e3 183
ThihaElectronics 32:155abe4126e3 184 #ifdef __cplusplus
ThihaElectronics 32:155abe4126e3 185 }
ThihaElectronics 32:155abe4126e3 186 #endif
ThihaElectronics 32:155abe4126e3 187
ThihaElectronics 32:155abe4126e3 188 #endif /* TFTLCD_ILI9328_H */