Robert Fischer / TFTLCD

Dependents:   TFTLCD_Fork_Test

Fork of TFTLCD by Todor Todorov

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hx8352a.h Source File

hx8352a.h

00001 /** \file hx8352.h
00002  *  \brief mbed TFT LCD controller for displays with the HX8352-A IC (serial interface).
00003  *  \copyright GNU Public License, v2. or later
00004  *
00005  * A known display with this type of controller chip is the 
00006  * 3.2" Width 400*240 TFT LCD Module Display
00007  *
00008  * This library is based on the Arduino/chipKIT UTFT library by Henning
00009  * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52
00010  *
00011  * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
00012  *
00013  * Copyright (C)2012 Todor Todorov.
00014  *
00015  * Copyright (C)2012 Robert Fischer.
00016  *
00017  * This library is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU Lesser General Public
00019  * License as published by the Free Software Foundation; either
00020  * version 2.1 of the License, or (at your option) any later version.
00021  *
00022  * This library is distributed in the hope that it will be useful,
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * Lesser General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU Lesser General Public
00028  * License along with this library; if not, write to:
00029  *
00030  * Free Software Foundation, Inc.
00031  * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
00032  *
00033  *********************************************************************/
00034 #ifndef TFTLCD_HX8352A
00035 #define TFTLCD_HX8352A
00036 
00037 #include "lcd_base.h"
00038 
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042 
00043 /** Represents a LCD instance.
00044  *
00045  * This is the utility class, through which the display can be manipulated
00046  * and graphics objects can be shown to the user.  A known display, which
00047  * works with this library is the ITDB02-2.2SP from iTeadStudio - a RGB TFT
00048  * with 176x220 pixels resolution and 65K/256K colors, using serial interface.
00049  *
00050  * The display needs 4 or 5 pins to work with mbed. As it uses +3.3V for power
00051  * and logic, as well as the backlight, interfacing could happen directly
00052  * to the mbed without the need of shields or level shifters as with Arduino.
00053  *
00054  * How to use:
00055  * \code
00056  * // include the library, this will also pull in the header for the provided fonts
00057  * #include "hx8352a.h"
00058  * 
00059  * // create the lcd instance
00060  * HX8352A_LCD lcd( p14, p13, p12, p11 ); // control pins
00061  *
00062  * int main()
00063  * {
00064  *     // initialize display - place it in standard portrait mode and set background to black and
00065  *     //                      foreground to white color.
00066  *     lcd.Initialize();
00067  *     // set current font to the smallest 8x12 pixels font.
00068  *     lcd.SetFont( Font8x12 );
00069  *     // print something on the screen
00070  *     lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors
00071  *
00072  *     while ( 1 ) { }
00073  * }
00074  *
00075  * \endcode
00076  * \version 0.1
00077  * \author Todor Todorov
00078  */
00079 class HX8352A_LCD : public LCD
00080 {
00081 public:
00082     /** Creates a new instance of the class.
00083      *
00084      * \param CS Pin for the ChipSelect signal.
00085      * \param RESET Pin for the RESET line.
00086      * \param SCL Pin for the serial clock signal.
00087      * \param SDI Pin for the serial data signal.
00088      * \param BL Pin for controlling the backlight. By default not used.
00089      * \param blType The backlight type, the default is to utilize the pin - if supplied - as a simple on/off switch
00090      * \param defaultBacklightLevel If using PWM to control backlight, this would be the default brightness in percent after LCD initialization.
00091      */
00092     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 );
00093     
00094     /** Initialize display.
00095      *
00096      * Wakes up the display from sleep, initializes power parameters.
00097      * This function must be called first, befor any painting on the
00098      * display is done, otherwise the positioning of graphical elements
00099      * will not work properly and any paynt operation will not be visible
00100      * or produce garbage.
00101      *
00102      * \param oritentation The display orientation, landscape is default.
00103      * \param colors The correct color depth to use for the pixel data.
00104      */
00105     virtual void Initialize( orientation_t orientation = PORTRAIT, colordepth_t colors = RGB16 );
00106     
00107     /** Puts the display to sleep.
00108      *
00109      * When the display is in sleep mode, its power consumption is
00110      * minimized.  Before new pixel data can be written to the display
00111      * memory, the controller needs to be brought out of sleep mode.
00112      * \sa #WakeUp( void );
00113      * \remarks The result of this operation might not be exactly as
00114      *          expected. Putting the display to sleep will cause the
00115      *          controller to switch to the standard color of the LCD,
00116      *          so depending on whether the display is normally white,
00117      *          or normally dark, the screen might or might not go
00118      *          dark.  Additional power saving can be achieved, if
00119      *          the backlight of the used display is not hardwired on
00120      *          the PCB and can be controlled via the BL pin.
00121      */
00122     //virtual void Sleep( void );
00123     
00124     /** Wakes up the display from sleep mode.
00125      *
00126      * This function needs to be called before any other, when the
00127      * display has been put into sleep mode by a previois call to
00128      * #Sleep( void ).
00129      */
00130     //virtual void WakeUp( void );
00131     
00132 protected:
00133     /** Sends a command to the display.
00134      *
00135      * \param cmd The display command.
00136      * \remarks Commands are controller-specific and this function needs to
00137      *          be implemented separately for each available controller.
00138      */
00139     virtual void WriteCmd( unsigned short cmd );
00140     
00141     /** Sends pixel data to the display.
00142      *
00143      * \param data The display data.
00144      * \remarks Sendin data is controller-specific and this function needs to
00145      *          be implemented separately for each available controller.
00146      */
00147     virtual void WriteData( unsigned short data );
00148         
00149     /** Assigns a chunk of the display memory to receive data.
00150      *
00151      * When data is sent to the display after this function completes, the opertion will
00152      * start from the begining of the assigned address (pixel position) and the pointer
00153      * will be automatically incremented so that the next data write operation will continue
00154      * with the next pixel from the memory block.  If more data is written than available
00155      * pixels, at the end of the block the pointer will jump back to its beginning and
00156      * commence again, until the next address change command is sent to the display.
00157      *
00158      * \param x1 The X coordinate of the pixel at the beginning of the block.
00159      * \param y1 The Y coordinate of the pixel at the beginning of the block.
00160      * \param x2 The X coordinate of the pixel at the end of the block.
00161      * \param y2 The Y coordinate of the pixel at the end of the block.
00162      * \remarks Addressing commands are controller-specific and this function needs to be
00163      *          implemented separately for each available controller.
00164      */
00165     virtual void SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 );
00166     
00167     /** Sets the color of the pixel at the address pointer of the controller.
00168      *
00169      * This function is to be provided by each implementation separately in
00170      * order to account for different color depth used by the controller.
00171      * \param color The color of the pixel.
00172      * \param mode The depth (palette) of the color.
00173      */
00174     virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB16 );
00175     
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_HX8352A */