This is a port of Henning Kralsen's UTFT library for Arduino/chipKIT to mbed, refactored to make full use of C++ inheritance and access control, in order to reduce work when implementing new drivers and at the same time make the code more readable and easier to maintain. As of now supported are SSD1289 (16-bit interface), HX8340-B (serial interface) and ST7735 (serial interface). Drivers for other controllers will be added as time and resources to acquire the displays to test the code permit.
Dependents: test SDCard capstone_display capstone_display_2 ... more
ili9328.h
00001 /** \file ili9328.h 00002 * \brief mbed LCD driver for displays with the ILI9328 controller. 00003 * \copyright GNU Public License, v2. or later 00004 * 00005 * This library is based on the Arduino/chipKIT UTFT library by Henning 00006 * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52 00007 * 00008 * Copyright (C)2010-2012 Henning Karlsen. All right reserved. 00009 * 00010 * Copyright (C)2012-2013 Todor Todorov. 00011 * 00012 * This library is free software; you can redistribute it and/or 00013 * modify it under the terms of the GNU Lesser General Public 00014 * License as published by the Free Software Foundation; either 00015 * version 2.1 of the License, or (at your option) any later version. 00016 * 00017 * This library is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 * Lesser General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this library; if not, write to: 00024 * 00025 * Free Software Foundation, Inc. 00026 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA 00027 * 00028 *********************************************************************/ 00029 #ifndef TFTLCD_ILI9328_H 00030 #define TFTLCD_ILI9328_H 00031 00032 #include "lcd_base.h" 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 /** Represents a LCD instance. 00039 * 00040 * This is the utility class, through which the display can be manipulated 00041 * and graphics objects can be shown to the user. A known display, which 00042 * works with this library is the INANBO-T24-ILI9328-V11 - a RGB TFT 00043 * with 240x320 pixels resolution and 65K/262K colors, using 8/16-bit interface. 00044 * 00045 * The display works with a supply voltage of 2.8-3.3 volts for both logic and 00046 * backlight. It can be driven in 8bit or 16bit interface mode. (Current 00047 * version of the driver works only in 16bit mode for now.) 00048 * 00049 * How to use: 00050 * \code 00051 * // include the library, this will also pull in the header for the provided fonts 00052 * #include "ili9328.h" 00053 * 00054 * // prepare the data bus for writing commands and pixel data 00055 * BusOut dataBus( p30, p29, p28, p27, p26, p25, p24, p23, p22, p21, p20, p19, p18, p17, p16, p15 ); // 16 pins 00056 * // create the lcd instance 00057 * ILI9328_LCD lcd( p14, p13, p12, p11, &dataBus ); // control pins and data bus 00058 * 00059 * int main() 00060 * { 00061 * // initialize display - place it in standard portrait mode and set background to black and 00062 * // foreground to white color. 00063 * lcd.Initialize(); 00064 * // set current font to the smallest 8x12 pixels font. 00065 * lcd.SetFont( Font8x12 ); 00066 * // print something on the screen 00067 * lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors 00068 * 00069 * while ( 1 ) { } 00070 * } 00071 * 00072 * \endcode 00073 * \version 0.1 00074 * \author Todor Todorov 00075 */ 00076 class ILI9328_LCD : public LCD 00077 { 00078 public: 00079 /** Creates a new instance of the class. 00080 * 00081 * \param CS Pin for the ChipSelect signal. 00082 * \param RESET Pin for the RESET line. 00083 * \param RS Pin for the RS signal. 00084 * \param WR Pin for the WR signal. 00085 * \param DATA_PORT Address of the data bus for transfer of commands and pixel data. 00086 * \param BL Pin for controlling the backlight. By default not used. 00087 * \param RD Pin for the RD signal. This line is not needed by the driver, so if you would like to 00088 * use the pin on the mbed for something else, just pull-up the respective pin on the LCD high, 00089 * and do not assign a value to this parameter when creating the controller instance. 00090 * \param blType The backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch 00091 * \param defaultBacklightLevel If using PWM to control backlight, this would be the default brightness in percent after LCD initialization. 00092 */ 00093 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 ); 00094 00095 /** Initialize display. 00096 * 00097 * Wakes up the display from sleep, initializes power parameters. 00098 * This function must be called first, befor any painting on the 00099 * display is done, otherwise the positioning of graphical elements 00100 * will not work properly and any paynt operation will not be visible 00101 * or produce garbage. 00102 * 00103 * \param oritentation The display orientation, landscape is default. 00104 * \param colors The correct color depth to use for the pixel data. Value is disregarded. 00105 */ 00106 virtual void Initialize( orientation_t orientation = LANDSCAPE, colordepth_t colors = RGB16 ); 00107 00108 /** Puts the display to sleep. 00109 * 00110 * When the display is in sleep mode, its power consumption is 00111 * minimized. Before new pixel data can be written to the display 00112 * memory, the controller needs to be brought out of sleep mode. 00113 * \sa #WakeUp( void ); 00114 * \remarks The result of this operation might not be exactly as 00115 * expected. Putting the display to sleep will cause the 00116 * controller to switch to the standard color of the LCD, 00117 * so depending on whether the display is normally white, 00118 * or normally dark, the screen might or might not go 00119 * dark. Additional power saving can be achieved, if 00120 * the backlight of the used display is not hardwired on 00121 * the PCB and can be controlled via the BL pin. 00122 */ 00123 virtual void Sleep( void ); 00124 00125 /** Wakes up the display from sleep mode. 00126 * 00127 * This function needs to be called before any other, when the 00128 * display has been put into sleep mode by a previois call to 00129 * #Sleep( void ). 00130 */ 00131 virtual void WakeUp( void ); 00132 00133 protected: 00134 /** Sends a command to the display. 00135 * 00136 * \param cmd The display command. 00137 * \remarks Commands are controller-specific and this function needs to 00138 * be implemented separately for each available controller. 00139 */ 00140 virtual void WriteCmd( unsigned short cmd ); 00141 00142 /** Sends pixel data to the display. 00143 * 00144 * \param data The display data. 00145 * \remarks Sending data is controller-specific and this function needs to 00146 * be implemented separately for each available controller. 00147 */ 00148 virtual void WriteData( unsigned short data ); 00149 00150 /** Assigns a chunk of the display memory to receive data. 00151 * 00152 * When data is sent to the display after this function completes, the opertion will 00153 * start from the begining of the assigned address (pixel position) and the pointer 00154 * will be automatically incremented so that the next data write operation will continue 00155 * with the next pixel from the memory block. If more data is written than available 00156 * pixels, at the end of the block the pointer will jump back to its beginning and 00157 * commence again, until the next address change command is sent to the display. 00158 * 00159 * \param x1 The X coordinate of the pixel at the beginning of the block. 00160 * \param y1 The Y coordinate of the pixel at the beginning of the block. 00161 * \param x2 The X coordinate of the pixel at the end of the block. 00162 * \param y2 The Y coordinate of the pixel at the end of the block. 00163 * \remarks Addressing commands are controller-specific and this function needs to be 00164 * implemented separately for each available controller. 00165 */ 00166 virtual void SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ); 00167 00168 /** Sets the color of the pixel at the address pointer of the controller. 00169 * 00170 * This function is to be provided by each implementation separately in 00171 * order to account for different color depth used by the controller. 00172 * \param color The color of the pixel. 00173 * \param mode The depth (palette) of the color. 00174 */ 00175 virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 ); 00176 00177 private: 00178 DigitalOut _lcd_pin_wr; 00179 BusOut* _lcd_port; 00180 DigitalOut* _lcd_pin_bl; 00181 DigitalOut* _lcd_pin_rd; 00182 }; 00183 00184 #ifdef __cplusplus 00185 } 00186 #endif 00187 00188 #endif /* TFTLCD_ILI9328_H */
Generated on Thu Jul 14 2022 02:02:54 by 1.7.2