mcufriend 2.4 TFT LCD Shield Lib

Dependents:   Nucleo_LCD_mcufriend_test

Fork of 24_TFT_STMNUCLEO by Carlos Silva

mcufriend 2.4" TFT LCD Shield

front back

Import program

00001 #include "mbed.h"
00002 #include "ili9328.h"
00003 
00004 // prepare the data bus for writing commands and pixel data
00005 BusOut dataBus( D8, D9, D2, D3, D4, D5, D6, D7 ); // 8 pins
00006 // create the lcd instance
00007 ILI9328_LCD lcd( A3,  A4, A2,A1, &dataBus, NC, A0); // control pins and data bus
00008 //ILI9328_LCD(  CS,  RESET,  RS, WR, BusOut* DATA_PORT, PinName BL = NC,  RD );
00009    
00010 int main()
00011 {
00012     int ii,height,width;
00013     
00014     height = lcd.GetHeight();
00015     width =  lcd.GetWidth();
00016     // initialize display - place it in standard portrait mode and set background to black and
00017     //                      foreground to white color.
00018     lcd.Initialize();
00019 
00020     // print something on the screen
00021     lcd.Print( "Hello, World!", CENTER, 50); // align text to center horizontally and use starndard colors
00022  
00023     wait(2);
00024    
00025     lcd.ClearScreen();
00026  
00027     for(ii=0;ii<width;ii++)
00028     {
00029         lcd.DrawLine(0, 0, height, ii,COLOR_GREEN);
00030         ii = ii+10;    
00031     }
00032     wait(2);
00033  
00034     lcd.DrawCircle(height/4, width/4, 20, COLOR_GREEN);
00035     wait(2);
00036  
00037     lcd.FillCircle(height/2, width/2, 50, COLOR_GREEN);
00038     wait(2);
00039  
00040     lcd.FillTriangle(height/4, width/4,(height/4)+20, (width/4)+40,(height/4)-20, (width/4)+40, COLOR_RED);
00041  
00042     while ( 1 ) { }
00043 }

HW information about the mcufriend LCD Shield

Committer:
ttodorov
Date:
Tue Dec 11 16:50:09 2012 +0000
Revision:
11:aeceefc5f9f2
Parent:
10:69571adcfad5
Child:
12:d0978272a340
- intermediate

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ttodorov 0:881ff0b71102 1 /** \file lcd_base.h
ttodorov 0:881ff0b71102 2 * \brief Base class for all LCD controller implementations.
ttodorov 0:881ff0b71102 3 * \copyright GNU Public License, v2. or later
ttodorov 0:881ff0b71102 4 *
ttodorov 0:881ff0b71102 5 * Generic object painting and screen control.
ttodorov 0:881ff0b71102 6 *
ttodorov 0:881ff0b71102 7 * This library is based on the Arduino/chipKIT UTFT library by Henning
ttodorov 0:881ff0b71102 8 * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52
ttodorov 0:881ff0b71102 9 *
ttodorov 0:881ff0b71102 10 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
ttodorov 5:09b6d228ceea 11 *
ttodorov 0:881ff0b71102 12 * Copyright (C)2012 Todor Todorov.
ttodorov 0:881ff0b71102 13 *
ttodorov 0:881ff0b71102 14 * This library is free software; you can redistribute it and/or
ttodorov 0:881ff0b71102 15 * modify it under the terms of the GNU Lesser General Public
ttodorov 0:881ff0b71102 16 * License as published by the Free Software Foundation; either
ttodorov 0:881ff0b71102 17 * version 2.1 of the License, or (at your option) any later version.
ttodorov 0:881ff0b71102 18 *
ttodorov 0:881ff0b71102 19 * This library is distributed in the hope that it will be useful,
ttodorov 0:881ff0b71102 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ttodorov 0:881ff0b71102 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ttodorov 0:881ff0b71102 22 * Lesser General Public License for more details.
ttodorov 0:881ff0b71102 23 *
ttodorov 0:881ff0b71102 24 * You should have received a copy of the GNU Lesser General Public
ttodorov 0:881ff0b71102 25 * License along with this library; if not, write to:
ttodorov 0:881ff0b71102 26 *
ttodorov 0:881ff0b71102 27 * Free Software Foundation, Inc.
ttodorov 0:881ff0b71102 28 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
ttodorov 0:881ff0b71102 29 *
ttodorov 0:881ff0b71102 30 *********************************************************************/
ttodorov 3:64a5b67d5b51 31 #ifndef TFTLCD_BASE_H
ttodorov 3:64a5b67d5b51 32 #define TFTLCD_BASE_H
ttodorov 0:881ff0b71102 33
ttodorov 0:881ff0b71102 34 #include "mbed.h"
ttodorov 0:881ff0b71102 35 #include "fonts.h"
ttodorov 0:881ff0b71102 36
ttodorov 6:059ca1648211 37 #ifdef __cplusplus
ttodorov 6:059ca1648211 38 extern "C" {
ttodorov 6:059ca1648211 39 #endif
ttodorov 6:059ca1648211 40
ttodorov 0:881ff0b71102 41 /** \def RGB(r,g,b)
ttodorov 0:881ff0b71102 42 * \brief Creates a RGB-565 color value.
ttodorov 0:881ff0b71102 43 *
ttodorov 0:881ff0b71102 44 * Displays which use 16 bits to assign colors to a specific pixel, use
ttodorov 0:881ff0b71102 45 * 5 bits for the red component, 6 bits for the green component and 5
ttodorov 0:881ff0b71102 46 * bits for the blue component. This macro converts the 3 full-size
ttodorov 0:881ff0b71102 47 * RGB bytes into one 16-bit RGB-565 value.
ttodorov 0:881ff0b71102 48 */
ttodorov 0:881ff0b71102 49 #define RGB( r, g, b ) ( ( ( ( r ) & 248 ) | ( ( g ) >> 5 ) ) << 8 ) | ( ( ( ( g ) & 28 ) << 3 ) | ( ( b ) >> 3 ) )
ttodorov 0:881ff0b71102 50 /** \def COLOR_BLACK
ttodorov 0:881ff0b71102 51 * \brief Shorthand for RGB( 0, 0, 0 ).
ttodorov 0:881ff0b71102 52 */
ttodorov 0:881ff0b71102 53 #define COLOR_BLACK RGB( 0x00, 0x00, 0x00 )
ttodorov 0:881ff0b71102 54 /** \def COLOR_WHITE
ttodorov 0:881ff0b71102 55 * \brief Shorthand for RGB( 255, 255, 255 ).
ttodorov 0:881ff0b71102 56 */
ttodorov 0:881ff0b71102 57 #define COLOR_WHITE RGB( 0xFF, 0xFF, 0xFF )
ttodorov 0:881ff0b71102 58 /** \def COLOR_RED
ttodorov 0:881ff0b71102 59 * \brief Shorthand for RGB( 255, 0, 0 ).
ttodorov 0:881ff0b71102 60 */
ttodorov 0:881ff0b71102 61 #define COLOR_RED RGB( 0xFF, 0x00, 0x00 )
ttodorov 0:881ff0b71102 62 /** \def COLOR_GREEN
ttodorov 0:881ff0b71102 63 * \brief Shorthand for RGB( 0, 255, 0 ).
ttodorov 0:881ff0b71102 64 */
ttodorov 0:881ff0b71102 65 #define COLOR_GREEN RGB( 0x00, 0xFF, 0x00 )
ttodorov 0:881ff0b71102 66 /** \def COLOR_BLUE
ttodorov 0:881ff0b71102 67 * \brief Shorthand for RGB( 0, 0, 255 ).
ttodorov 0:881ff0b71102 68 */
ttodorov 0:881ff0b71102 69 #define COLOR_BLUE RGB( 0x00, 0x00, 0xFF )
ttodorov 0:881ff0b71102 70
ttodorov 10:69571adcfad5 71 /** \enum Orientation_enum
ttodorov 0:881ff0b71102 72 * \brief Display orientation.
ttodorov 0:881ff0b71102 73 */
ttodorov 10:69571adcfad5 74 enum Orientation_enum
ttodorov 0:881ff0b71102 75 {
ttodorov 0:881ff0b71102 76 PORTRAIT = 0, /**< Display height is bigger than its width. */
ttodorov 0:881ff0b71102 77 LANDSCAPE = 1, /**< Display width is bigger than its height. */
ttodorov 10:69571adcfad5 78 };
ttodorov 10:69571adcfad5 79 /** \typedef orientation_t
ttodorov 10:69571adcfad5 80 * \brief Convenience shortcut for display orientation.
ttodorov 10:69571adcfad5 81 */
ttodorov 10:69571adcfad5 82 typedef enum Orientation_enum orientation_t;
ttodorov 0:881ff0b71102 83
ttodorov 10:69571adcfad5 84 /** \enum ColorDepth_enum
ttodorov 10:69571adcfad5 85 * \brief Color depth
ttodorov 10:69571adcfad5 86 */
ttodorov 10:69571adcfad5 87 enum ColorDepth_enum
ttodorov 10:69571adcfad5 88 {
ttodorov 10:69571adcfad5 89 RGB16, /**< 16-bit colors, pixels can have 65K distinct color values */
ttodorov 10:69571adcfad5 90 RGB18, /**< 18-bit colors, pixels can have 262K distinct color values */
ttodorov 10:69571adcfad5 91 };
ttodorov 10:69571adcfad5 92 /** \typedef colordepth_t
ttodorov 10:69571adcfad5 93 * \brief Convenience shortcut for display color depth.
ttodorov 10:69571adcfad5 94 */
ttodorov 10:69571adcfad5 95 typedef enum ColorDepth_enum colordepth_t;
ttodorov 10:69571adcfad5 96
ttodorov 10:69571adcfad5 97 /** \enum Alignment_enum
ttodorov 0:881ff0b71102 98 * \brief Horizontal text alignment on the line.
ttodorov 0:881ff0b71102 99 */
ttodorov 10:69571adcfad5 100 enum Alignment_enum
ttodorov 0:881ff0b71102 101 {
ttodorov 0:881ff0b71102 102 LEFT = 0, /**< Left-oriented, naturally gravitate closer to the left edge of the screen. */
ttodorov 0:881ff0b71102 103 CENTER = 9998, /**< Center-oriented, try to fit in the middle of the available space with equal free space to the left and right of the text. */
ttodorov 0:881ff0b71102 104 RIGHT = 9999, /**< Right-oriented, naturally gravitate closer to the right edge of the screen, leaving any remaining free space to the left of the text. */
ttodorov 10:69571adcfad5 105 };
ttodorov 10:69571adcfad5 106 /** \typedef align_t
ttodorov 10:69571adcfad5 107 * \brief Convenience shortcut for text alignment.
ttodorov 10:69571adcfad5 108 */
ttodorov 10:69571adcfad5 109 typedef enum Alignment_enum align_t;
ttodorov 0:881ff0b71102 110
ttodorov 10:69571adcfad5 111 /** \struct Font_struct
ttodorov 0:881ff0b71102 112 * \brief Describes fonts and their properties.
ttodorov 0:881ff0b71102 113 * \sa Comments in fonts.h
ttodorov 0:881ff0b71102 114 */
ttodorov 10:69571adcfad5 115 struct Font_struct
ttodorov 0:881ff0b71102 116 {
ttodorov 0:881ff0b71102 117 const char* font; /**< A pointer to the first byte in the font. */
ttodorov 0:881ff0b71102 118 unsigned char width; /**< The width of each character, in pixels. */
ttodorov 0:881ff0b71102 119 unsigned char height; /**< Height of each character, in pixels. */
ttodorov 0:881ff0b71102 120 unsigned char offset; /**< Offset of the first character in the font. */
ttodorov 0:881ff0b71102 121 unsigned char numchars; /**< Count of the available characters in the font. */
ttodorov 10:69571adcfad5 122 };
ttodorov 10:69571adcfad5 123 /** \typedef font_metrics_t
ttodorov 10:69571adcfad5 124 * \brief Convenience shortcut for fonts properties.
ttodorov 10:69571adcfad5 125 */
ttodorov 10:69571adcfad5 126 typedef struct Font_struct font_metrics_t;
ttodorov 0:881ff0b71102 127
ttodorov 11:aeceefc5f9f2 128
ttodorov 0:881ff0b71102 129 /** Base class for LCD implementations.
ttodorov 0:881ff0b71102 130 *
ttodorov 0:881ff0b71102 131 * All separate LCD controller implementations have to subclass this one.
ttodorov 0:881ff0b71102 132 *
ttodorov 0:881ff0b71102 133 * \version 0.1
ttodorov 0:881ff0b71102 134 * \author Todor Todorov
ttodorov 0:881ff0b71102 135 */
ttodorov 0:881ff0b71102 136 class LCD
ttodorov 0:881ff0b71102 137 {
ttodorov 0:881ff0b71102 138 public:
ttodorov 0:881ff0b71102 139
ttodorov 0:881ff0b71102 140 /** Initialize display.
ttodorov 0:881ff0b71102 141 *
ttodorov 0:881ff0b71102 142 * Wakes up the display from sleep, initializes power parameters.
ttodorov 0:881ff0b71102 143 * This function must be called first, befor any painting on the
ttodorov 0:881ff0b71102 144 * display is done, otherwise the positioning of graphical elements
ttodorov 0:881ff0b71102 145 * will not work properly and any paynt operation will not be visible
ttodorov 0:881ff0b71102 146 * or produce garbage.
ttodorov 0:881ff0b71102 147 *
ttodorov 0:881ff0b71102 148 * This function is controller-specific and needs to be implemented
ttodorov 4:3ac4239f6c9c 149 * separately for each available display.
ttodorov 0:881ff0b71102 150 * \param oritentation The display orientation, landscape is default.
ttodorov 0:881ff0b71102 151 */
ttodorov 0:881ff0b71102 152 virtual void Initialize( orientation_t orientation ) = 0;
ttodorov 0:881ff0b71102 153
ttodorov 4:3ac4239f6c9c 154 /** Puts the display to sleep.
ttodorov 4:3ac4239f6c9c 155 *
ttodorov 4:3ac4239f6c9c 156 * When the display is in sleep mode, its power consumption is
ttodorov 4:3ac4239f6c9c 157 * minimized. Before new pixel data can be written to the display
ttodorov 4:3ac4239f6c9c 158 * memory, the controller needs to be brought out of sleep mode.
ttodorov 4:3ac4239f6c9c 159 * \sa #WakeUp( void );
ttodorov 4:3ac4239f6c9c 160 * \remarks The result of this operation might not be exactly as
ttodorov 4:3ac4239f6c9c 161 * expected. Putting the display to sleep will cause the
ttodorov 4:3ac4239f6c9c 162 * controller to switch to the standard color of the LCD,
ttodorov 4:3ac4239f6c9c 163 * so depending on whether the display is normally white,
ttodorov 4:3ac4239f6c9c 164 * or normally dark, the screen might or might not go
ttodorov 4:3ac4239f6c9c 165 * dark. Additional power saving can be achieved, if
ttodorov 4:3ac4239f6c9c 166 * the backlight of the used display is not hardwired on
ttodorov 4:3ac4239f6c9c 167 * the PCB and can be controlled via the BL pin.
ttodorov 4:3ac4239f6c9c 168 * \remarks This function is controller-specific and needs to be
ttodorov 4:3ac4239f6c9c 169 * implemented separately for each available display.
ttodorov 4:3ac4239f6c9c 170 */
ttodorov 4:3ac4239f6c9c 171 virtual void Sleep( void ) = 0;
ttodorov 4:3ac4239f6c9c 172
ttodorov 4:3ac4239f6c9c 173 /** Wakes up the display from sleep mode.
ttodorov 4:3ac4239f6c9c 174 *
ttodorov 4:3ac4239f6c9c 175 * This function needs to be called before any other, when the
ttodorov 4:3ac4239f6c9c 176 * display has been put into sleep mode by a previois call to
ttodorov 4:3ac4239f6c9c 177 * #Sleep( void ).
ttodorov 4:3ac4239f6c9c 178 * \remarks This function is controller-specific and needs to be
ttodorov 4:3ac4239f6c9c 179 * implemented separately for each available display.
ttodorov 4:3ac4239f6c9c 180 */
ttodorov 4:3ac4239f6c9c 181 virtual void WakeUp( void ) = 0;
ttodorov 4:3ac4239f6c9c 182
ttodorov 0:881ff0b71102 183 /** Set the foreground color for painting.
ttodorov 0:881ff0b71102 184 *
ttodorov 0:881ff0b71102 185 * This is the default foreground color to be used in painting operations.
ttodorov 0:881ff0b71102 186 * If a specific output function allows for a different color to be specified
ttodorov 0:881ff0b71102 187 * in place, the new setting will be used for that single operation only and
ttodorov 0:881ff0b71102 188 * will not change this value.
ttodorov 0:881ff0b71102 189 *
ttodorov 9:58b328831d0a 190 * \param color The color to be used. The value must be in RGB-565 format.
ttodorov 0:881ff0b71102 191 * \sa #RGB(r,g,b)
ttodorov 0:881ff0b71102 192 */
ttodorov 9:58b328831d0a 193 virtual void SetForeground( unsigned short color = COLOR_WHITE );
ttodorov 0:881ff0b71102 194
ttodorov 0:881ff0b71102 195 /** Set the background color for painting.
ttodorov 0:881ff0b71102 196 *
ttodorov 0:881ff0b71102 197 * This is the default color to be used for "empty" pixels while painting.
ttodorov 0:881ff0b71102 198 * If a particular function allows for a different value to be specified
ttodorov 0:881ff0b71102 199 * when the function is called, the new value will be used only for this
ttodorov 0:881ff0b71102 200 * single call and will not change this setting.
ttodorov 0:881ff0b71102 201 *
ttodorov 9:58b328831d0a 202 * \param color The background color as RGB-565 value.
ttodorov 0:881ff0b71102 203 * \sa #RGB(r,g,b)
ttodorov 0:881ff0b71102 204 */
ttodorov 9:58b328831d0a 205 virtual void SetBackground( unsigned short color = COLOR_BLACK );
ttodorov 0:881ff0b71102 206
ttodorov 0:881ff0b71102 207 /** Sets the font to be used for painting of text on the screen.
ttodorov 0:881ff0b71102 208 * \param font A pointer to the font data.
ttodorov 0:881ff0b71102 209 * \sa Comments in file fonts.h
ttodorov 0:881ff0b71102 210 */
ttodorov 0:881ff0b71102 211 virtual void SetFont( const char* font );
ttodorov 0:881ff0b71102 212
ttodorov 0:881ff0b71102 213 /** Gets the display width.
ttodorov 0:881ff0b71102 214 * \return Display width in pixels.
ttodorov 0:881ff0b71102 215 */
ttodorov 0:881ff0b71102 216 unsigned short GetWidth( void );
ttodorov 0:881ff0b71102 217
ttodorov 0:881ff0b71102 218 /** Gets the display height.
ttodorov 0:881ff0b71102 219 * \return Display height in pixels.
ttodorov 0:881ff0b71102 220 */
ttodorov 0:881ff0b71102 221 unsigned short GetHeight( void );
ttodorov 0:881ff0b71102 222
ttodorov 0:881ff0b71102 223 /** Fills the whole screen with a single color.
ttodorov 9:58b328831d0a 224 * \param color The color to be used. The value must be in RGB-565 format.
ttodorov 9:58b328831d0a 225 * \remarks The special values -1 and -2 signify the preset background and foreground colors, respectively.
ttodorov 9:58b328831d0a 226 * The backround color is the default.
ttodorov 0:881ff0b71102 227 */
ttodorov 0:881ff0b71102 228 virtual void FillScreen( int color = -1 );
ttodorov 0:881ff0b71102 229
ttodorov 0:881ff0b71102 230 /** Clears the screen.
ttodorov 0:881ff0b71102 231 *
ttodorov 0:881ff0b71102 232 * This is the same as calling #FillScreen() or #FillScreen( -1 ) to use the background color.
ttodorov 0:881ff0b71102 233 */
ttodorov 0:881ff0b71102 234 virtual void ClearScreen( void );
ttodorov 0:881ff0b71102 235
ttodorov 0:881ff0b71102 236 /** Draws a pixel at the specified location.
ttodorov 0:881ff0b71102 237 *
ttodorov 0:881ff0b71102 238 * By default the function will use the preset foreground color, but the background
ttodorov 0:881ff0b71102 239 * or a custom color could be used as well.
ttodorov 0:881ff0b71102 240 *
ttodorov 0:881ff0b71102 241 * \param x The horizontal offset of the pixel from the upper left corner of the screen.
ttodorov 0:881ff0b71102 242 * \param y The vertical offset of the pixel from the upper left corner of the screen.
ttodorov 9:58b328831d0a 243 * \param color The color to be used. Must be in RGB-565 format, or -1 for background and -2 for foreground color.
ttodorov 0:881ff0b71102 244 */
ttodorov 0:881ff0b71102 245 virtual void DrawPixel( unsigned short x, unsigned short y, int color = -2 );
ttodorov 0:881ff0b71102 246
ttodorov 0:881ff0b71102 247 /** Draws a line.
ttodorov 0:881ff0b71102 248 *
ttodorov 0:881ff0b71102 249 * \param x1 Horizontal offset of the beginning point of the line.
ttodorov 0:881ff0b71102 250 * \param y1 Vertical offset of the beginning point of the line.
ttodorov 0:881ff0b71102 251 * \param x2 Horizontal offset of the end point of the line.
ttodorov 0:881ff0b71102 252 * \param y2 Verical offset of the end point of the line.
ttodorov 9:58b328831d0a 253 * \param color The color to use for painting, in RGB-565 format, or -1 for background, or -2 for foreground.
ttodorov 0:881ff0b71102 254 */
ttodorov 0:881ff0b71102 255 virtual void DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
ttodorov 0:881ff0b71102 256
ttodorov 0:881ff0b71102 257 /** Paints a rectangle.
ttodorov 0:881ff0b71102 258 *
ttodorov 0:881ff0b71102 259 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 260 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 261 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
ttodorov 0:881ff0b71102 262 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
ttodorov 9:58b328831d0a 263 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format.
ttodorov 0:881ff0b71102 264 */
ttodorov 0:881ff0b71102 265 virtual void DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
ttodorov 0:881ff0b71102 266
ttodorov 0:881ff0b71102 267 /** Paints a rectangle and fills it with the paint color.
ttodorov 0:881ff0b71102 268 *
ttodorov 0:881ff0b71102 269 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 270 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 271 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
ttodorov 0:881ff0b71102 272 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
ttodorov 9:58b328831d0a 273 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format.
ttodorov 0:881ff0b71102 274 */
ttodorov 0:881ff0b71102 275 virtual void DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
ttodorov 0:881ff0b71102 276
ttodorov 0:881ff0b71102 277 /** Paints a rectangle with rounded corners.
ttodorov 0:881ff0b71102 278 *
ttodorov 0:881ff0b71102 279 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 280 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 281 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
ttodorov 0:881ff0b71102 282 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
ttodorov 9:58b328831d0a 283 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format.
ttodorov 0:881ff0b71102 284 */
ttodorov 0:881ff0b71102 285 virtual void FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
ttodorov 0:881ff0b71102 286
ttodorov 0:881ff0b71102 287 /** Paints a rectangle with rounded corners and fills it with the paint color.
ttodorov 0:881ff0b71102 288 *
ttodorov 0:881ff0b71102 289 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 290 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
ttodorov 0:881ff0b71102 291 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
ttodorov 0:881ff0b71102 292 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
ttodorov 9:58b328831d0a 293 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format.
ttodorov 0:881ff0b71102 294 */
ttodorov 0:881ff0b71102 295 virtual void FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
ttodorov 0:881ff0b71102 296
ttodorov 0:881ff0b71102 297 /** Paints a circle.
ttodorov 0:881ff0b71102 298 *
ttodorov 0:881ff0b71102 299 * \param x The offset of the circle's center from the left edge of the screen.
ttodorov 0:881ff0b71102 300 * \param y The offset of the circle's center from the top edge of the screen.
ttodorov 0:881ff0b71102 301 * \param radius The circle's radius.
ttodorov 9:58b328831d0a 302 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format.
ttodorov 0:881ff0b71102 303 */
ttodorov 0:881ff0b71102 304 virtual void DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 );
ttodorov 0:881ff0b71102 305
ttodorov 0:881ff0b71102 306 /** Paints a circle and fills it with the paint color.
ttodorov 0:881ff0b71102 307 *
ttodorov 0:881ff0b71102 308 * \param x The offset of the circle's center from the left edge of the screen.
ttodorov 0:881ff0b71102 309 * \param y The offset of the circle's center from the top edge of the screen.
ttodorov 0:881ff0b71102 310 * \param radius The circle's radius.
ttodorov 9:58b328831d0a 311 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format.
ttodorov 0:881ff0b71102 312 */
ttodorov 0:881ff0b71102 313 virtual void FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 );
ttodorov 0:881ff0b71102 314
ttodorov 0:881ff0b71102 315 /** Print a text on the screen.
ttodorov 0:881ff0b71102 316 *
ttodorov 0:881ff0b71102 317 * \param str The text.
ttodorov 0:881ff0b71102 318 * \param x The horizontal offset form the left edge of the screen. The special values LEFT, CENTER,
ttodorov 0:881ff0b71102 319 * or RIGHT can be used instead of pixel offset to indicate the text's horizontal alignment.
ttodorov 0:881ff0b71102 320 * \param y The vertical offset of the text from the top of the screen.
ttodorov 0:881ff0b71102 321 * \param fgColor The foreground to use for painting the text; -1 indicates background color, -2 the foreground setting, or custom color.
ttodorov 0:881ff0b71102 322 * \param bgColor The color to use for painting the empty pixels; -1 indicates the background color, -2 the foreground setting, or custom color.
ttodorov 0:881ff0b71102 323 * \param deg If different than 0, the text will be rotated at an angle this many degrees around its starting point. Default is not to ratate.
ttodorov 0:881ff0b71102 324 */
ttodorov 0:881ff0b71102 325 virtual void Print( const char *str, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 );
ttodorov 0:881ff0b71102 326
ttodorov 0:881ff0b71102 327 /** Draw an image on the screen.
ttodorov 0:881ff0b71102 328 *
ttodorov 0:881ff0b71102 329 * The pixels of the picture must be in the RGB-565 format. The data can be provided
ttodorov 0:881ff0b71102 330 * as an array in a source or a header file. To convert an image file to the appropriate
ttodorov 0:881ff0b71102 331 * format, a special utility must be utilized. One such tool is provided by Henning Karlsen,
ttodorov 0:881ff0b71102 332 * the author of the UTFT display liberary and can be downloaded for free from his web site:
ttodorov 0:881ff0b71102 333 * http://henningkarlsen.com/electronics/library.php?id=52
ttodorov 0:881ff0b71102 334 *
ttodorov 0:881ff0b71102 335 * \param x Horizontal offset of the first pixel of the image.
ttodorov 0:881ff0b71102 336 * \param y Vertical offset of the first pixel of the image
ttodorov 0:881ff0b71102 337 * \param sx Width of the image.
ttodorov 0:881ff0b71102 338 * \param sy Height of the image.
ttodorov 7:5c418fc1879f 339 * \param imgPixelData Image pixel array.
ttodorov 0:881ff0b71102 340 * \param scale A value of 1 will produce an image with its original size, while a different value will scale the image.
ttodorov 0:881ff0b71102 341 */
ttodorov 7:5c418fc1879f 342 virtual void DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, const unsigned short* imgPixelData, unsigned char scale = 1 );
ttodorov 0:881ff0b71102 343
ttodorov 0:881ff0b71102 344 /** Draw an image on the screen.
ttodorov 0:881ff0b71102 345 *
ttodorov 0:881ff0b71102 346 * The pixels of the picture must be in the RGB-565 format. The data can be provided
ttodorov 0:881ff0b71102 347 * as an array in a source or a header file. To convert an image file to the appropriate
ttodorov 0:881ff0b71102 348 * format, a special utility must be utilized. One such tool is provided by Henning Karlsen,
ttodorov 0:881ff0b71102 349 * the author of the UTFT display liberary and can be downloaded for free from his web site:
ttodorov 0:881ff0b71102 350 * http://henningkarlsen.com/electronics/library.php?id=52
ttodorov 0:881ff0b71102 351 *
ttodorov 0:881ff0b71102 352 * \param x Horizontal offset of the first pixel of the image.
ttodorov 0:881ff0b71102 353 * \param y Vertical offset of the first pixel of the image
ttodorov 0:881ff0b71102 354 * \param sx Width of the image.
ttodorov 0:881ff0b71102 355 * \param sy Height of the image.
ttodorov 7:5c418fc1879f 356 * \param imgPixelData Image pixel array.
ttodorov 0:881ff0b71102 357 * \param deg Angle to rotate the image before painting on screen, in degrees.
ttodorov 0:881ff0b71102 358 * \param rox
ttodorov 0:881ff0b71102 359 * \param roy
ttodorov 0:881ff0b71102 360 */
ttodorov 7:5c418fc1879f 361 virtual void DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, const unsigned short* imgPixelData, unsigned short deg, unsigned short rox, unsigned short roy );
ttodorov 0:881ff0b71102 362
ttodorov 0:881ff0b71102 363 protected:
ttodorov 0:881ff0b71102 364 /** Creates an instance of the class.
ttodorov 0:881ff0b71102 365 *
ttodorov 0:881ff0b71102 366 * \param width Width of the display in pixels.
ttodorov 0:881ff0b71102 367 * \param height Height of the display in pixels.
ttodorov 0:881ff0b71102 368 * \param CS Pin connected to the CS input of the display.
ttodorov 0:881ff0b71102 369 * \param RS Pin connected to the RS input of the display.
ttodorov 4:3ac4239f6c9c 370 * \param RESET Pin connected to the RESET input of the display.
ttodorov 0:881ff0b71102 371 */
ttodorov 4:3ac4239f6c9c 372 LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS, PinName RESET );
ttodorov 4:3ac4239f6c9c 373
ttodorov 4:3ac4239f6c9c 374 /** Activates the display for command/data transfer.
ttodorov 4:3ac4239f6c9c 375 *
ttodorov 4:3ac4239f6c9c 376 * Usually achieved by pulling the CS pin of the display low.
ttodorov 4:3ac4239f6c9c 377 */
ttodorov 4:3ac4239f6c9c 378 virtual void Activate( void );
ttodorov 4:3ac4239f6c9c 379
ttodorov 4:3ac4239f6c9c 380 /** Deactivates the display after data has been transmitted.
ttodorov 4:3ac4239f6c9c 381 *
ttodorov 4:3ac4239f6c9c 382 * Usually achieved by pulling the CS pin of the display high.
ttodorov 4:3ac4239f6c9c 383 */
ttodorov 4:3ac4239f6c9c 384 virtual void Deactivate( void );
ttodorov 0:881ff0b71102 385
ttodorov 0:881ff0b71102 386 /** Sends a command to the display.
ttodorov 0:881ff0b71102 387 *
ttodorov 0:881ff0b71102 388 * \param cmd The display command.
ttodorov 0:881ff0b71102 389 * \remarks Commands are controller-specific and this function needs to
ttodorov 0:881ff0b71102 390 * be implemented separately for each available controller.
ttodorov 0:881ff0b71102 391 */
ttodorov 2:81ed304b7e9b 392 virtual void WriteCmd( unsigned short cmd ) = 0;
ttodorov 0:881ff0b71102 393
ttodorov 0:881ff0b71102 394 /** Sends pixel data to the display.
ttodorov 0:881ff0b71102 395 *
ttodorov 0:881ff0b71102 396 * \param data The display data.
ttodorov 0:881ff0b71102 397 * \remarks Sendin data is controller-specific and this function needs to
ttodorov 0:881ff0b71102 398 * be implemented separately for each available controller.
ttodorov 0:881ff0b71102 399 */
ttodorov 2:81ed304b7e9b 400 virtual void WriteData( unsigned short data ) = 0;
ttodorov 0:881ff0b71102 401
ttodorov 0:881ff0b71102 402 /** Sends both command and data to the display controller.
ttodorov 0:881ff0b71102 403 *
ttodorov 0:881ff0b71102 404 * This is a helper utility function which combines the 2 functions above
ttodorov 0:881ff0b71102 405 * into one single convenience step.
ttodorov 0:881ff0b71102 406 *
ttodorov 0:881ff0b71102 407 * \param cmd The display command.
ttodorov 0:881ff0b71102 408 * \param data The display pixel data.
ttodorov 0:881ff0b71102 409 */
ttodorov 2:81ed304b7e9b 410 virtual void WriteCmdData( unsigned short cmd, unsigned short data );
ttodorov 0:881ff0b71102 411
ttodorov 0:881ff0b71102 412 /** Assigns a chunk of the display memory to receive data.
ttodorov 0:881ff0b71102 413 *
ttodorov 0:881ff0b71102 414 * When data is sent to the display after this function completes, the opertion will
ttodorov 0:881ff0b71102 415 * start from the begining of the assigned address (pixel position) and the pointer
ttodorov 0:881ff0b71102 416 * will be automatically incremented so that the next data write operation will continue
ttodorov 0:881ff0b71102 417 * with the next pixel from the memory block. If more data is written than available
ttodorov 0:881ff0b71102 418 * pixels, at the end of the block the pointer will jump back to its beginning and
ttodorov 0:881ff0b71102 419 * commence again, until the next address change command is sent to the display.
ttodorov 0:881ff0b71102 420 *
ttodorov 0:881ff0b71102 421 * \param x1 The X coordinate of the pixel at the beginning of the block.
ttodorov 0:881ff0b71102 422 * \param y1 The Y coordinate of the pixel at the beginning of the block.
ttodorov 0:881ff0b71102 423 * \param x2 The X coordinate of the pixel at the end of the block.
ttodorov 0:881ff0b71102 424 * \param y2 The Y coordinate of the pixel at the end of the block.
ttodorov 0:881ff0b71102 425 * \remarks Addressing commands are controller-specific and this function needs to be
ttodorov 0:881ff0b71102 426 * implemented separately for each available controller.
ttodorov 0:881ff0b71102 427 */
ttodorov 2:81ed304b7e9b 428 virtual void SetXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ) = 0;
ttodorov 0:881ff0b71102 429
ttodorov 0:881ff0b71102 430 /** Resets the memory address for the next display write operation to the screen origins (0,0).
ttodorov 0:881ff0b71102 431 */
ttodorov 2:81ed304b7e9b 432 virtual void ClearXY( void );
ttodorov 2:81ed304b7e9b 433
ttodorov 10:69571adcfad5 434 /** Sets the color of the pixel at the address pointer of the controller.
ttodorov 10:69571adcfad5 435 *
ttodorov 10:69571adcfad5 436 * This function is to be provided by each implementation separately in
ttodorov 10:69571adcfad5 437 * order to account for different color depth used by the controller.
ttodorov 10:69571adcfad5 438 * \param color The color of the pixel.
ttodorov 10:69571adcfad5 439 */
ttodorov 10:69571adcfad5 440 virtual void SetPixelColor( unsigned short color ) = 0;
ttodorov 10:69571adcfad5 441
ttodorov 2:81ed304b7e9b 442 /** Draws a horizontal line.
ttodorov 2:81ed304b7e9b 443 *
ttodorov 2:81ed304b7e9b 444 * This is a utility function to draw horizontal-only lines
ttodorov 2:81ed304b7e9b 445 * for reduced code complexity and faster execution.
ttodorov 2:81ed304b7e9b 446 *
ttodorov 2:81ed304b7e9b 447 * \param x X coordinate of the starting point of the line.
ttodorov 2:81ed304b7e9b 448 * \param y Y coordinate of the starting point of the line.
ttodorov 2:81ed304b7e9b 449 * \param len Length of the line.
ttodorov 2:81ed304b7e9b 450 * \param color The color to use to draw the line. By default the global foreground color is used ( -2 ),
ttodorov 9:58b328831d0a 451 * -1 switches to the default background color, or any other RGB-565 color can be used.
ttodorov 2:81ed304b7e9b 452 */
ttodorov 2:81ed304b7e9b 453 virtual void DrawHLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 );
ttodorov 0:881ff0b71102 454
ttodorov 2:81ed304b7e9b 455 /** Draws a vertical line.
ttodorov 2:81ed304b7e9b 456 *
ttodorov 2:81ed304b7e9b 457 * This is a utility function to draw vertical-only lines
ttodorov 2:81ed304b7e9b 458 * for reduced code complexity and faster execution.
ttodorov 2:81ed304b7e9b 459 *
ttodorov 2:81ed304b7e9b 460 * \param x X coordinate of the starting point of the line.
ttodorov 2:81ed304b7e9b 461 * \param y Y coordinate of the starting point of the line.
ttodorov 2:81ed304b7e9b 462 * \param len Height of the line.
ttodorov 2:81ed304b7e9b 463 * \param color The color to use to draw the line. By default the global foreground color is used ( -2 ),
ttodorov 9:58b328831d0a 464 * -1 switches to the default background color, or any other RGB-565 color can be used.
ttodorov 2:81ed304b7e9b 465 */
ttodorov 2:81ed304b7e9b 466 virtual void DrawVLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 );
ttodorov 2:81ed304b7e9b 467
ttodorov 2:81ed304b7e9b 468 /** Prints a character at the given position and using the given color.
ttodorov 2:81ed304b7e9b 469 *
ttodorov 2:81ed304b7e9b 470 * \param c The character.
ttodorov 2:81ed304b7e9b 471 * \param x X coordinate of the character position.
ttodorov 2:81ed304b7e9b 472 * \param y Y coordinate of the character position.
ttodorov 2:81ed304b7e9b 473 * \param fgColor Foreground color for drawing. By default the global foreground color is used ( -2 ),
ttodorov 9:58b328831d0a 474 * -1 switches to the default background color, or any other RGB-565 color can be used.
ttodorov 2:81ed304b7e9b 475 * \param bgColor Background color for drawing. By default the global background color is used ( -1 ),
ttodorov 9:58b328831d0a 476 * -2 switches to the default foreground color, or any other RGB-565 color can be used.
ttodorov 2:81ed304b7e9b 477 */
ttodorov 2:81ed304b7e9b 478 virtual void PrintChar( char c, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1 );
ttodorov 2:81ed304b7e9b 479
ttodorov 2:81ed304b7e9b 480 /** Prints a character at the given position and using the given color and with the given rotation.
ttodorov 2:81ed304b7e9b 481 *
ttodorov 2:81ed304b7e9b 482 * \param c The character.
ttodorov 2:81ed304b7e9b 483 * \param x X coordinate of the character position.
ttodorov 2:81ed304b7e9b 484 * \param y Y coordinate of the character position.
ttodorov 2:81ed304b7e9b 485 * \param pos Position of the character in the string from which it originates (used to rotate a whole string).
ttodorov 2:81ed304b7e9b 486 * \param fgColor Foreground color for drawing. By default the global foreground color is used ( -2 ),
ttodorov 9:58b328831d0a 487 * -1 switches to the default background color, or any other RGB-565 color can be used.
ttodorov 2:81ed304b7e9b 488 * \param bgColor Background color for drawing. By default the global background color is used ( -1 ),
ttodorov 9:58b328831d0a 489 * -2 switches to the default foreground color, or any other RGB-565 color can be used.
ttodorov 2:81ed304b7e9b 490 * \param deg The angle at which to rotate.
ttodorov 2:81ed304b7e9b 491 */
ttodorov 2:81ed304b7e9b 492 virtual void RotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 );
ttodorov 0:881ff0b71102 493
ttodorov 0:881ff0b71102 494 protected:
ttodorov 4:3ac4239f6c9c 495 unsigned short _disp_width, _disp_height;
ttodorov 4:3ac4239f6c9c 496 DigitalOut _lcd_pin_cs, _lcd_pin_rs, _lcd_pin_reset;
ttodorov 4:3ac4239f6c9c 497 orientation_t _orientation;
ttodorov 9:58b328831d0a 498 unsigned short _foreground, _background;
ttodorov 4:3ac4239f6c9c 499 font_metrics_t _font;
ttodorov 0:881ff0b71102 500 };
ttodorov 0:881ff0b71102 501
ttodorov 6:059ca1648211 502 #ifdef __cplusplus
ttodorov 6:059ca1648211 503 }
ttodorov 6:059ca1648211 504 #endif
ttodorov 6:059ca1648211 505
ttodorov 3:64a5b67d5b51 506 #endif /* TFTLCD_BASE_H */