Fork of TFTLCD with new support for SSD1963 ad HX8352-A controller.

Dependents:   TFTLCD_Fork_Test

Fork of TFTLCD by Todor Todorov

Committer:
RobertFischer
Date:
Fri May 30 08:39:59 2014 +0000
Revision:
28:fe9a2e0ce659
First test of TFTLCD with new support for SSD1963 and HX8352-A display controller. Still some scrambled output

Who changed what in which revision?

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