TFTLCD with FastIO

Fork of TFTLCD by en 129

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hx8340bs.h Source File

hx8340bs.h

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