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