A modifiedversion of TFTLCD by Todor Todorov with ultra-fast operation for SSD1289 controller. TODO: speed-up fonts, add my own fonts Can work out-of-the-box with ST Nucleo F401RE

Dependents:   TFT_320QVT_Window_Drag_Demo TFT_320QVT_HelloWorld

Fork of TFTLCD by Todor Todorov

Committer:
rpocc
Date:
Mon Jan 11 09:35:06 2016 +0000
Revision:
28:2f24de90cb46
Parent:
24:ac6e35658037
All changes are valid for ssd1289; Overloaded constructors added;; _fast_fill_16 protected methods are added for fast rectangle fill;; DrawHLine and DrawVLine are now Public.; Changes made by Dmitry Shtatnov

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ttodorov 4:3ac4239f6c9c 1 /** \file ssd1289.h
ttodorov 0:881ff0b71102 2 * \brief mbed TFT LCD controller for displays with the SSD1289 IC.
ttodorov 0:881ff0b71102 3 * \copyright GNU Public License, v2. or later
ttodorov 0:881ff0b71102 4 *
ttodorov 0:881ff0b71102 5 * A known display with this type of controller chip is the ITDB02-3.2S
ttodorov 0:881ff0b71102 6 * from http://imall.iteadstudio.com
ttodorov 0:881ff0b71102 7 *
ttodorov 0:881ff0b71102 8 * This library is based on the Arduino/chipKIT UTFT library by Henning
ttodorov 0:881ff0b71102 9 * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52
ttodorov 0:881ff0b71102 10 *
rpocc 28:2f24de90cb46 11 * Optimized fast version for SSD1289 by Dmitry Shtatnov
rpocc 28:2f24de90cb46 12 *
ttodorov 0:881ff0b71102 13 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
ttodorov 5:09b6d228ceea 14 *
ttodorov 0:881ff0b71102 15 * Copyright (C)2012 Todor Todorov.
ttodorov 0:881ff0b71102 16 *
rpocc 28:2f24de90cb46 17 * Copyright (C)2016 Dmitry Shtatnov
rpocc 28:2f24de90cb46 18 *
ttodorov 0:881ff0b71102 19 * This library is free software; you can redistribute it and/or
ttodorov 0:881ff0b71102 20 * modify it under the terms of the GNU Lesser General Public
ttodorov 0:881ff0b71102 21 * License as published by the Free Software Foundation; either
ttodorov 0:881ff0b71102 22 * version 2.1 of the License, or (at your option) any later version.
ttodorov 0:881ff0b71102 23 *
ttodorov 0:881ff0b71102 24 * This library is distributed in the hope that it will be useful,
ttodorov 0:881ff0b71102 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ttodorov 0:881ff0b71102 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ttodorov 0:881ff0b71102 27 * Lesser General Public License for more details.
ttodorov 0:881ff0b71102 28 *
ttodorov 0:881ff0b71102 29 * You should have received a copy of the GNU Lesser General Public
ttodorov 0:881ff0b71102 30 * License along with this library; if not, write to:
ttodorov 0:881ff0b71102 31 *
ttodorov 0:881ff0b71102 32 * Free Software Foundation, Inc.
ttodorov 0:881ff0b71102 33 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
ttodorov 0:881ff0b71102 34 *
ttodorov 0:881ff0b71102 35 *********************************************************************/
ttodorov 3:64a5b67d5b51 36 #ifndef TFTLCD_SSD1289_H
ttodorov 3:64a5b67d5b51 37 #define TFTLCD_SSD1289_H
ttodorov 0:881ff0b71102 38
ttodorov 0:881ff0b71102 39 #include "lcd_base.h"
ttodorov 0:881ff0b71102 40
ttodorov 6:059ca1648211 41 #ifdef __cplusplus
ttodorov 6:059ca1648211 42 extern "C" {
ttodorov 6:059ca1648211 43 #endif
ttodorov 6:059ca1648211 44
ttodorov 3:64a5b67d5b51 45 /** Represents a LCD instance.
ttodorov 3:64a5b67d5b51 46 *
ttodorov 3:64a5b67d5b51 47 * This is the utility class, through which the display can be manipulated
ttodorov 3:64a5b67d5b51 48 * and graphics objects can be shown to the user. A known display, which
ttodorov 3:64a5b67d5b51 49 * works with this library is the ITDB02-3.2S from iTeadStudio - a RGB TFT
ttodorov 3:64a5b67d5b51 50 * with 240x320 pixels resolution and 65K colors, using 16-bit interface.
ttodorov 3:64a5b67d5b51 51 *
ttodorov 4:3ac4239f6c9c 52 * The display needs 20 to 22 pins to work with mbed, so it is possibly not
ttodorov 3:64a5b67d5b51 53 * the best of choices out there, but other than that it uses +3.3V for
ttodorov 3:64a5b67d5b51 54 * power and logic, as well as the backlight, thus can be interfaced directly
ttodorov 3:64a5b67d5b51 55 * to the mbed without the need of shields or level shifters as with Arduino.
ttodorov 3:64a5b67d5b51 56 *
ttodorov 3:64a5b67d5b51 57 * How to use:
ttodorov 3:64a5b67d5b51 58 * \code
ttodorov 3:64a5b67d5b51 59 * // include the library, this will also pull in the header for the provided fonts
ttodorov 3:64a5b67d5b51 60 * #include "ssd1289.h"
ttodorov 3:64a5b67d5b51 61 *
rpocc 28:2f24de90cb46 62 * // prepare the data bus for writing commands and pixel data (LSB..MSB)
ttodorov 3:64a5b67d5b51 63 * BusOut dataBus( p30, p29, p28, p27, p26, p25, p24, p23, p22, p21, p20, p19, p18, p17, p16, p15 ); // 16 pins
ttodorov 3:64a5b67d5b51 64 * // create the lcd instance
ttodorov 4:3ac4239f6c9c 65 * SSD1289_LCD lcd( p14, p13, p12, p11, &dataBus ); // control pins and data bus
rpocc 28:2f24de90cb46 66 * // You can also prepare a PortOut for faster operation:
rpocc 28:2f24de90cb46 67 * // PortOut dataPort(PortC, 0xFFFF); // 16 pins
rpocc 28:2f24de90cb46 68 * // SSD1289_LCD lcd( p14, p13, p12, p11, &dataPort ); // control pins and data bus
rpocc 28:2f24de90cb46 69 * //
rpocc 28:2f24de90cb46 70 * // Or, you can use separated port, which is usefull with some platforms such as ST Nucleo F401RE,
rpocc 28:2f24de90cb46 71 * // having no ports with all 16 pins available for output. (by default)
rpocc 28:2f24de90cb46 72 * // PortOut dataPortA(PortA, 0xFF00); // 16 pins
rpocc 28:2f24de90cb46 73 * // PortOut dataPortC(PortC, 0x00FF); // 16 pins
rpocc 28:2f24de90cb46 74 * // SSD1289_LCD lcd( p14, p13, p12, p11, &dataPortA, &dataPortC ); // control pins and data bus
rpocc 28:2f24de90cb46 75
ttodorov 3:64a5b67d5b51 76 *
ttodorov 3:64a5b67d5b51 77 * int main()
ttodorov 3:64a5b67d5b51 78 * {
ttodorov 3:64a5b67d5b51 79 * // initialize display - place it in standard portrait mode and set background to black and
ttodorov 3:64a5b67d5b51 80 * // foreground to white color.
ttodorov 3:64a5b67d5b51 81 * lcd.Initialize();
ttodorov 3:64a5b67d5b51 82 * // set current font to the smallest 8x12 pixels font.
rpocc 28:2f24de90cb46 83 * lcd.SetFont( &TerminusFont );
ttodorov 3:64a5b67d5b51 84 * // print something on the screen
ttodorov 3:64a5b67d5b51 85 * lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors
ttodorov 3:64a5b67d5b51 86 *
ttodorov 3:64a5b67d5b51 87 * while ( 1 ) { }
ttodorov 3:64a5b67d5b51 88 * }
ttodorov 3:64a5b67d5b51 89 *
ttodorov 3:64a5b67d5b51 90 * \endcode
ttodorov 3:64a5b67d5b51 91 * \version 0.1
ttodorov 3:64a5b67d5b51 92 * \author Todor Todorov
ttodorov 3:64a5b67d5b51 93 */
ttodorov 4:3ac4239f6c9c 94 class SSD1289_LCD : public LCD
ttodorov 0:881ff0b71102 95 {
ttodorov 0:881ff0b71102 96 public:
ttodorov 0:881ff0b71102 97 /** Creates a new instance of the class.
ttodorov 0:881ff0b71102 98 *
ttodorov 0:881ff0b71102 99 * \param CS Pin for the ChipSelect signal.
ttodorov 0:881ff0b71102 100 * \param RESET Pin for the RESET line.
ttodorov 0:881ff0b71102 101 * \param RS Pin for the RS signal.
ttodorov 0:881ff0b71102 102 * \param WR Pin for the WR signal.
ttodorov 0:881ff0b71102 103 * \param DATA_PORT Address of the data bus for transfer of commands and pixel data.
ttodorov 4:3ac4239f6c9c 104 * \param BL Pin for controlling the backlight. By default not used.
ttodorov 0:881ff0b71102 105 * \param RD Pin for the RD signal. This line is not needed by the driver, so if you would like to
ttodorov 0:881ff0b71102 106 * use the pin on the mbed for something else, just pull-up the respective pin on the LCD high,
ttodorov 0:881ff0b71102 107 * and do not assign a value to this parameter when creating the controller instance.
ttodorov 22:4c169297f374 108 * \param blType The backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch
ttodorov 22:4c169297f374 109 * \param defaultBacklightLevel If using PWM to control backlight, this would be the default brightness in percent after LCD initialization.
ttodorov 0:881ff0b71102 110 */
ttodorov 22:4c169297f374 111 SSD1289_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 );
rpocc 28:2f24de90cb46 112
rpocc 28:2f24de90cb46 113 /** Creates a new instance of the class.
rpocc 28:2f24de90cb46 114 *
rpocc 28:2f24de90cb46 115 * \param CS Pin for the ChipSelect signal.
rpocc 28:2f24de90cb46 116 * \param RESET Pin for the RESET line.
rpocc 28:2f24de90cb46 117 * \param RS Pin for the RS signal.
rpocc 28:2f24de90cb46 118 * \param WR Pin for the WR signal.
rpocc 28:2f24de90cb46 119 * \param FAST_DATA_PORT_H High Byte Address of the data port for transfer of commands and pixel data. Should have 0xFF00 mask
rpocc 28:2f24de90cb46 120 * \param FAST_DATA_PORT_L Low Byte Address of the data port for transfer of commands and pixel data. Should have 0x00FF mask
rpocc 28:2f24de90cb46 121 * \param BL Pin for controlling the backlight. By default not used.
rpocc 28:2f24de90cb46 122 * \param RD Pin for the RD signal. This line is not needed by the driver, so if you would like to
rpocc 28:2f24de90cb46 123 * use the pin on the mbed for something else, just pull-up the respective pin on the LCD high,
rpocc 28:2f24de90cb46 124 * and do not assign a value to this parameter when creating the controller instance.
rpocc 28:2f24de90cb46 125 * \param blType The backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch
rpocc 28:2f24de90cb46 126 * \param defaultBacklightLevel If using PWM to control backlight, this would be the default brightness in percent after LCD initialization.
rpocc 28:2f24de90cb46 127 */
rpocc 28:2f24de90cb46 128 SSD1289_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, PortOut* FAST_DATA_PORT_H, PortOut* FAST_DATA_PORT_L, PinName BL = NC, PinName RD = NC, backlight_t blType = Constant, float defaultBackLightLevel = 1.0 );
rpocc 28:2f24de90cb46 129
rpocc 28:2f24de90cb46 130 /** Creates a new instance of the class.
rpocc 28:2f24de90cb46 131 *
rpocc 28:2f24de90cb46 132 * \param CS Pin for the ChipSelect signal.
rpocc 28:2f24de90cb46 133 * \param RESET Pin for the RESET line.
rpocc 28:2f24de90cb46 134 * \param RS Pin for the RS signal.
rpocc 28:2f24de90cb46 135 * \param WR Pin for the WR signal.
rpocc 28:2f24de90cb46 136 * \param FAST_DATA_PORT Address of the data port for transfer of commands and pixel data.
rpocc 28:2f24de90cb46 137 * \param BL Pin for controlling the backlight. By default not used.
rpocc 28:2f24de90cb46 138 * \param RD Pin for the RD signal. This line is not needed by the driver, so if you would like to
rpocc 28:2f24de90cb46 139 * use the pin on the mbed for something else, just pull-up the respective pin on the LCD high,
rpocc 28:2f24de90cb46 140 * and do not assign a value to this parameter when creating the controller instance.
rpocc 28:2f24de90cb46 141 * \param blType The backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch
rpocc 28:2f24de90cb46 142 * \param defaultBacklightLevel If using PWM to control backlight, this would be the default brightness in percent after LCD initialization.
rpocc 28:2f24de90cb46 143 */
rpocc 28:2f24de90cb46 144 SSD1289_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, PortOut* FAST_DATA_PORT, PinName BL = NC, PinName RD = NC, backlight_t blType = Constant, float defaultBackLightLevel = 1.0 );
ttodorov 0:881ff0b71102 145
ttodorov 0:881ff0b71102 146 /** Initialize display.
ttodorov 0:881ff0b71102 147 *
ttodorov 0:881ff0b71102 148 * Wakes up the display from sleep, initializes power parameters.
ttodorov 0:881ff0b71102 149 * This function must be called first, befor any painting on the
ttodorov 0:881ff0b71102 150 * display is done, otherwise the positioning of graphical elements
ttodorov 0:881ff0b71102 151 * will not work properly and any paynt operation will not be visible
ttodorov 0:881ff0b71102 152 * or produce garbage.
ttodorov 0:881ff0b71102 153 *
ttodorov 0:881ff0b71102 154 * \param oritentation The display orientation, landscape is default.
ttodorov 12:d0978272a340 155 * \param colors The correct color depth to use for the pixel data. Value is disregarded.
ttodorov 0:881ff0b71102 156 */
ttodorov 12:d0978272a340 157 virtual void Initialize( orientation_t orientation = LANDSCAPE, colordepth_t colors = RGB16 );
ttodorov 0:881ff0b71102 158
ttodorov 4:3ac4239f6c9c 159 /** Puts the display to sleep.
ttodorov 4:3ac4239f6c9c 160 *
ttodorov 4:3ac4239f6c9c 161 * When the display is in sleep mode, its power consumption is
ttodorov 4:3ac4239f6c9c 162 * minimized. Before new pixel data can be written to the display
ttodorov 4:3ac4239f6c9c 163 * memory, the controller needs to be brought out of sleep mode.
ttodorov 4:3ac4239f6c9c 164 * \sa #WakeUp( void );
ttodorov 4:3ac4239f6c9c 165 * \remarks The result of this operation might not be exactly as
ttodorov 4:3ac4239f6c9c 166 * expected. Putting the display to sleep will cause the
ttodorov 4:3ac4239f6c9c 167 * controller to switch to the standard color of the LCD,
ttodorov 4:3ac4239f6c9c 168 * so depending on whether the display is normally white,
ttodorov 4:3ac4239f6c9c 169 * or normally dark, the screen might or might not go
ttodorov 4:3ac4239f6c9c 170 * dark. Additional power saving can be achieved, if
ttodorov 4:3ac4239f6c9c 171 * the backlight of the used display is not hardwired on
ttodorov 4:3ac4239f6c9c 172 * the PCB and can be controlled via the BL pin.
ttodorov 4:3ac4239f6c9c 173 */
ttodorov 4:3ac4239f6c9c 174 virtual void Sleep( void );
ttodorov 4:3ac4239f6c9c 175
ttodorov 4:3ac4239f6c9c 176 /** Wakes up the display from sleep mode.
ttodorov 4:3ac4239f6c9c 177 *
ttodorov 4:3ac4239f6c9c 178 * This function needs to be called before any other, when the
ttodorov 4:3ac4239f6c9c 179 * display has been put into sleep mode by a previois call to
ttodorov 4:3ac4239f6c9c 180 * #Sleep( void ).
ttodorov 4:3ac4239f6c9c 181 */
ttodorov 4:3ac4239f6c9c 182 virtual void WakeUp( void );
ttodorov 4:3ac4239f6c9c 183
rpocc 28:2f24de90cb46 184 virtual void FillScreen( int color );
rpocc 28:2f24de90cb46 185
rpocc 28:2f24de90cb46 186 virtual void FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color );
rpocc 28:2f24de90cb46 187
rpocc 28:2f24de90cb46 188 virtual void DrawVLine( unsigned short x, unsigned short y, unsigned short len, int color = -2);
rpocc 28:2f24de90cb46 189
rpocc 28:2f24de90cb46 190 virtual void DrawHLine( unsigned short x, unsigned short y, unsigned short len, int color = -2);
rpocc 28:2f24de90cb46 191
ttodorov 0:881ff0b71102 192 protected:
ttodorov 4:3ac4239f6c9c 193 /** Sends a command to the display.
ttodorov 4:3ac4239f6c9c 194 *
ttodorov 4:3ac4239f6c9c 195 * \param cmd The display command.
ttodorov 4:3ac4239f6c9c 196 * \remarks Commands are controller-specific and this function needs to
ttodorov 4:3ac4239f6c9c 197 * be implemented separately for each available controller.
ttodorov 4:3ac4239f6c9c 198 */
ttodorov 2:81ed304b7e9b 199 virtual void WriteCmd( unsigned short cmd );
ttodorov 4:3ac4239f6c9c 200
ttodorov 4:3ac4239f6c9c 201 /** Sends pixel data to the display.
ttodorov 4:3ac4239f6c9c 202 *
ttodorov 4:3ac4239f6c9c 203 * \param data The display data.
ttodorov 24:ac6e35658037 204 * \remarks Sending data is controller-specific and this function needs to
ttodorov 4:3ac4239f6c9c 205 * be implemented separately for each available controller.
ttodorov 4:3ac4239f6c9c 206 */
ttodorov 2:81ed304b7e9b 207 virtual void WriteData( unsigned short data );
ttodorov 4:3ac4239f6c9c 208
rpocc 28:2f24de90cb46 209 virtual void _fast_fill_16(int color, long pix);
rpocc 28:2f24de90cb46 210
ttodorov 4:3ac4239f6c9c 211 /** Assigns a chunk of the display memory to receive data.
ttodorov 4:3ac4239f6c9c 212 *
ttodorov 4:3ac4239f6c9c 213 * When data is sent to the display after this function completes, the opertion will
ttodorov 4:3ac4239f6c9c 214 * start from the begining of the assigned address (pixel position) and the pointer
ttodorov 4:3ac4239f6c9c 215 * will be automatically incremented so that the next data write operation will continue
ttodorov 4:3ac4239f6c9c 216 * with the next pixel from the memory block. If more data is written than available
ttodorov 4:3ac4239f6c9c 217 * pixels, at the end of the block the pointer will jump back to its beginning and
ttodorov 4:3ac4239f6c9c 218 * commence again, until the next address change command is sent to the display.
ttodorov 4:3ac4239f6c9c 219 *
ttodorov 4:3ac4239f6c9c 220 * \param x1 The X coordinate of the pixel at the beginning of the block.
ttodorov 4:3ac4239f6c9c 221 * \param y1 The Y coordinate of the pixel at the beginning of the block.
ttodorov 4:3ac4239f6c9c 222 * \param x2 The X coordinate of the pixel at the end of the block.
ttodorov 4:3ac4239f6c9c 223 * \param y2 The Y coordinate of the pixel at the end of the block.
ttodorov 4:3ac4239f6c9c 224 * \remarks Addressing commands are controller-specific and this function needs to be
ttodorov 4:3ac4239f6c9c 225 * implemented separately for each available controller.
ttodorov 4:3ac4239f6c9c 226 */
ttodorov 20:4bdca8d8dadc 227 virtual void SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 );
ttodorov 0:881ff0b71102 228
ttodorov 10:69571adcfad5 229 /** Sets the color of the pixel at the address pointer of the controller.
ttodorov 10:69571adcfad5 230 *
ttodorov 10:69571adcfad5 231 * This function is to be provided by each implementation separately in
ttodorov 10:69571adcfad5 232 * order to account for different color depth used by the controller.
ttodorov 10:69571adcfad5 233 * \param color The color of the pixel.
ttodorov 20:4bdca8d8dadc 234 * \param mode The depth (palette) of the color.
ttodorov 10:69571adcfad5 235 */
ttodorov 20:4bdca8d8dadc 236 virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 );
ttodorov 10:69571adcfad5 237
ttodorov 0:881ff0b71102 238 private:
ttodorov 4:3ac4239f6c9c 239 DigitalOut _lcd_pin_wr;
ttodorov 4:3ac4239f6c9c 240 BusOut* _lcd_port;
ttodorov 4:3ac4239f6c9c 241 DigitalOut* _lcd_pin_bl;
ttodorov 0:881ff0b71102 242 DigitalOut* _lcd_pin_rd;
rpocc 28:2f24de90cb46 243 PortOut* _hp;
rpocc 28:2f24de90cb46 244 PortOut* _lp;
rpocc 28:2f24de90cb46 245 bool _use_fast_port, _use_separate_port;
ttodorov 0:881ff0b71102 246 };
ttodorov 0:881ff0b71102 247
ttodorov 6:059ca1648211 248 #ifdef __cplusplus
ttodorov 6:059ca1648211 249 }
ttodorov 6:059ca1648211 250 #endif
ttodorov 6:059ca1648211 251
ttodorov 3:64a5b67d5b51 252 #endif /* TFTLCD_SSD1289_H */