landtiger with ili9325 lcd controller based on the TFTLCD libary from Todor Todorov

Committer:
casval
Date:
Mon Jun 08 09:59:17 2015 +0000
Revision:
1:1a3dd94e13cf
Parent:
0:0099ad246127
Mutex form for other project was still there

Who changed what in which revision?

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