landtiger with ili9325 lcd controller based on the TFTLCD libary from Todor Todorov

Committer:
casval
Date:
Mon Jun 08 09:59:17 2015 +0000
Revision:
1:1a3dd94e13cf
Parent:
0:0099ad246127
Mutex form for other project was still there

Who changed what in which revision?

UserRevisionLine numberNew contents of line
casval 0:0099ad246127 1 /** \file lcd_base.h
casval 0:0099ad246127 2 * \brief Base class for all LCD controller implementations.
casval 0:0099ad246127 3 * \copyright GNU Public License, v2. or later
casval 0:0099ad246127 4 *
casval 0:0099ad246127 5 * Generic object painting and screen control.
casval 0:0099ad246127 6 *
casval 0:0099ad246127 7 * This library is based on the Arduino/chipKIT UTFT library by Henning
casval 0:0099ad246127 8 * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52
casval 0:0099ad246127 9 *
casval 0:0099ad246127 10 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
casval 0:0099ad246127 11 *
casval 0:0099ad246127 12 * Copyright (C)2012 Todor Todorov.
casval 0:0099ad246127 13 *
casval 0:0099ad246127 14 * This library is free software; you can redistribute it and/or
casval 0:0099ad246127 15 * modify it under the terms of the GNU Lesser General Public
casval 0:0099ad246127 16 * License as published by the Free Software Foundation; either
casval 0:0099ad246127 17 * version 2.1 of the License, or (at your option) any later version.
casval 0:0099ad246127 18 *
casval 0:0099ad246127 19 * This library is distributed in the hope that it will be useful,
casval 0:0099ad246127 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
casval 0:0099ad246127 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
casval 0:0099ad246127 22 * Lesser General Public License for more details.
casval 0:0099ad246127 23 *
casval 0:0099ad246127 24 * You should have received a copy of the GNU Lesser General Public
casval 0:0099ad246127 25 * License along with this library; if not, write to:
casval 0:0099ad246127 26 *
casval 0:0099ad246127 27 * Free Software Foundation, Inc.
casval 0:0099ad246127 28 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
casval 0:0099ad246127 29 *
casval 0:0099ad246127 30 *********************************************************************/
casval 0:0099ad246127 31 #ifndef TFTLCD_BASE_H
casval 0:0099ad246127 32 #define TFTLCD_BASE_H
casval 0:0099ad246127 33
casval 0:0099ad246127 34 #include "mbed.h"
casval 0:0099ad246127 35 #include "terminus.h"
casval 0:0099ad246127 36
casval 0:0099ad246127 37
casval 0:0099ad246127 38
casval 0:0099ad246127 39 #ifdef __cplusplus
casval 0:0099ad246127 40 extern "C" {
casval 0:0099ad246127 41 #endif
casval 0:0099ad246127 42
casval 0:0099ad246127 43 /** \def RGB(r,g,b)
casval 0:0099ad246127 44 * \brief Creates a RGB color from distinct bytes for the red, green and blue components.
casval 0:0099ad246127 45 *
casval 0:0099ad246127 46 * Displays which use 16 bits to assign colors to a specific pixel, use
casval 0:0099ad246127 47 * 5 bits for the red component, 6 bits for the green component and 5
casval 0:0099ad246127 48 * bits for the blue component. Displays which have 18-bit color depth
casval 0:0099ad246127 49 * use 6 bits for red, 6 bits for green and 6 bits for blue component.
casval 0:0099ad246127 50 * This macro preserves the full 24-bit color depth, but it is the responsibility
casval 0:0099ad246127 51 * of the respective driver to convert the color value to the correct format.
casval 0:0099ad246127 52 */
casval 0:0099ad246127 53 #define RGB( r, g, b ) ( ( r ) << 16 ) | ( ( g ) << 8 ) | ( b )
casval 0:0099ad246127 54 /** \def COLOR_BLACK
casval 0:0099ad246127 55 * \brief Shorthand for RGB( 0, 0, 0 ).
casval 0:0099ad246127 56 */
casval 0:0099ad246127 57 #define COLOR_BLACK RGB( 0x00, 0x00, 0x00 )
casval 0:0099ad246127 58 /** \def COLOR_WHITE
casval 0:0099ad246127 59 * \brief Shorthand for RGB( 255, 255, 255 ).
casval 0:0099ad246127 60 */
casval 0:0099ad246127 61 #define COLOR_WHITE RGB( 0xFF, 0xFF, 0xFF )
casval 0:0099ad246127 62 /** \def COLOR_RED
casval 0:0099ad246127 63 * \brief Shorthand for RGB( 255, 0, 0 ).
casval 0:0099ad246127 64 */
casval 0:0099ad246127 65 #define COLOR_RED RGB( 0xFF, 0x00, 0x00 )
casval 0:0099ad246127 66 /** \def COLOR_GREEN
casval 0:0099ad246127 67 * \brief Shorthand for RGB( 0, 255, 0 ).
casval 0:0099ad246127 68 */
casval 0:0099ad246127 69 #define COLOR_GREEN RGB( 0x00, 0xFF, 0x00 )
casval 0:0099ad246127 70 /** \def COLOR_BLUE
casval 0:0099ad246127 71 * \brief Shorthand for RGB( 0, 0, 255 ).
casval 0:0099ad246127 72 */
casval 0:0099ad246127 73 #define COLOR_BLUE RGB( 0x00, 0x00, 0xFF )
casval 0:0099ad246127 74 /** \def COLOR_CYAN
casval 0:0099ad246127 75 * \brief Shorthand for RGB( 0, 255, 255 )
casval 0:0099ad246127 76 */
casval 0:0099ad246127 77 #define COLOR_CYAN RGB( 0x00, 0xFF, 0xFF )
casval 0:0099ad246127 78 /** \def COLOR_MAGENTA
casval 0:0099ad246127 79 * \brief Shorthand for RGB( 255, 0, 255 )
casval 0:0099ad246127 80 */
casval 0:0099ad246127 81 #define COLOR_MAGENTA RGB( 0xFF, 0x00, 0xFF )
casval 0:0099ad246127 82 /** \def COLOR_YELLOW
casval 0:0099ad246127 83 * \brief Shorthand for RGB( 255, 255, 0 )
casval 0:0099ad246127 84 */
casval 0:0099ad246127 85 #define COLOR_YELLOW RGB( 0xFF, 0xFF, 0x00 )
casval 0:0099ad246127 86
casval 0:0099ad246127 87
casval 0:0099ad246127 88 /** \enum Orientation_enum
casval 0:0099ad246127 89 * \brief Display orientation.
casval 0:0099ad246127 90 */
casval 0:0099ad246127 91 enum Orientation_enum
casval 0:0099ad246127 92 {
casval 0:0099ad246127 93 PORTRAIT = 0, /**< Top row of the screen is at 12 o'clock. */
casval 0:0099ad246127 94 LANDSCAPE = 1, /**< Top row of the screen is at 9 o'clock. */
casval 0:0099ad246127 95 PORTRAIT_REV = 2, /**< Top row of the screen is at 6 o'clock. */
casval 0:0099ad246127 96 LANDSCAPE_REV = 3, /**< Top row of the screen is at 3 o'clock. */
casval 0:0099ad246127 97 };
casval 0:0099ad246127 98 /** \typedef orientation_t
casval 0:0099ad246127 99 * \brief Convenience shortcut for display orientation.
casval 0:0099ad246127 100 */
casval 0:0099ad246127 101 typedef enum Orientation_enum orientation_t;
casval 0:0099ad246127 102
casval 0:0099ad246127 103 /** \enum ColorDepth_enum
casval 0:0099ad246127 104 * \brief Color depth
casval 0:0099ad246127 105 */
casval 0:0099ad246127 106 enum ColorDepth_enum
casval 0:0099ad246127 107 {
casval 0:0099ad246127 108 RGB16, /**< 16-bit colors, pixels can have 65K+ distinct color values */
casval 0:0099ad246127 109 RGB18, /**< 18-bit colors, pixels can have 262K+ distinct color values */
casval 0:0099ad246127 110 RGB24, /**< 24-bit colors, full 8 bits per component, 16M+ distinct color values */
casval 0:0099ad246127 111 };
casval 0:0099ad246127 112 /** \typedef colordepth_t
casval 0:0099ad246127 113 * \brief Convenience shortcut for display color depth.
casval 0:0099ad246127 114 */
casval 0:0099ad246127 115 typedef enum ColorDepth_enum colordepth_t;
casval 0:0099ad246127 116
casval 0:0099ad246127 117 /** \enum Alignment_enum
casval 0:0099ad246127 118 * \brief Horizontal text alignment on the line.
casval 0:0099ad246127 119 */
casval 0:0099ad246127 120 enum Alignment_enum
casval 0:0099ad246127 121 {
casval 0:0099ad246127 122 LEFT = 0, /**< Left-oriented, naturally gravitate closer to the left edge of the screen. */
casval 0:0099ad246127 123 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. */
casval 0:0099ad246127 124 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. */
casval 0:0099ad246127 125 };
casval 0:0099ad246127 126 /** \typedef align_t
casval 0:0099ad246127 127 * \brief Convenience shortcut for text alignment.
casval 0:0099ad246127 128 */
casval 0:0099ad246127 129 typedef enum Alignment_enum align_t;
casval 0:0099ad246127 130
casval 0:0099ad246127 131 ///** \struct Font_struct
casval 0:0099ad246127 132 // * \brief Describes fonts and their properties.
casval 0:0099ad246127 133 // * \sa Comments in fonts.h
casval 0:0099ad246127 134 // */
casval 0:0099ad246127 135 //struct Font_struct
casval 0:0099ad246127 136 //{
casval 0:0099ad246127 137 // const char* font; /**< A pointer to the first byte in the font. */
casval 0:0099ad246127 138 // unsigned char width; /**< The width of each character, in pixels. */
casval 0:0099ad246127 139 // unsigned char height; /**< Height of each character, in pixels. */
casval 0:0099ad246127 140 // unsigned char offset; /**< Offset of the first character in the font. */
casval 0:0099ad246127 141 // unsigned char numchars; /**< Count of the available characters in the font. */
casval 0:0099ad246127 142 //};
casval 0:0099ad246127 143 ///** \typedef font_metrics_t
casval 0:0099ad246127 144 // * \brief Convenience shortcut for fonts properties.
casval 0:0099ad246127 145 // */
casval 0:0099ad246127 146 //typedef struct Font_struct font_metrics_t;
casval 0:0099ad246127 147
casval 0:0099ad246127 148 /** \struct Bitmap_struct
casval 0:0099ad246127 149 * \brief Describes an image.
casval 0:0099ad246127 150 */
casval 0:0099ad246127 151 struct Bitmap_struct
casval 0:0099ad246127 152 {
casval 0:0099ad246127 153 colordepth_t Format; /**< Color depth of the image. */
casval 0:0099ad246127 154 unsigned short Width; /**< Width of the image in pixels. */
casval 0:0099ad246127 155 unsigned short Height; /**< Height of the image in pixels. */
casval 0:0099ad246127 156 const void* PixelData; /**< Image pixel data. */
casval 0:0099ad246127 157 };
casval 0:0099ad246127 158 /** \typedef bitmap_t
casval 0:0099ad246127 159 * \brief Convenience shortcut bitmap type.
casval 0:0099ad246127 160 */
casval 0:0099ad246127 161 typedef struct Bitmap_struct bitmap_t;
casval 0:0099ad246127 162
casval 0:0099ad246127 163 /** \struct BacklightPwmCtrl_enum
casval 0:0099ad246127 164 * \brief Type of backlight control for the LCD.
casval 0:0099ad246127 165 *
casval 0:0099ad246127 166 * When the selected type is \c Constant, the pin is simply on or off - there is no gradation in the intensity of the display.
casval 0:0099ad246127 167 * In this case any free pin can be used to control the backlight. On the other hand, when PWM is used to control brightness,
casval 0:0099ad246127 168 * take care to use only PWM-able mbed pins (p21, p22, p23, p24, p25, and p26), any other pins won't work. It is assumed that
casval 0:0099ad246127 169 * you know what you are doing, so no check is done to prevent using a non-PWM pin as assigned control pin, when either \c Direct
casval 0:0099ad246127 170 * or \c Indirect option is used.
casval 0:0099ad246127 171 *
casval 0:0099ad246127 172 * \version 0.1
casval 0:0099ad246127 173 * \remark When choosing PWM to control the backlight, you have the option to choose the pin to either source (\c Direct) or sink
casval 0:0099ad246127 174 * (\c Indirect) the current for LCD brightness control. Be aware that the mbed pins can source (and probably sink when
casval 0:0099ad246127 175 * configured as inputs) only 4 mA @+3V3 VDD. So if you are intending to use a bigger LCD, whith more LEDs in its backlight
casval 0:0099ad246127 176 * implementation, you probably want to interface it through a small signal transistor or a small MOSFET, in order to be able
casval 0:0099ad246127 177 * to handle a higher current without damaging your mbed.
casval 0:0099ad246127 178 * \remark As of version 0.1 (2013-01-25) the Indirect method of PWM has not been implemented yet.
casval 0:0099ad246127 179 */
casval 0:0099ad246127 180 enum BacklightPwmCtrl_enum
casval 0:0099ad246127 181 {
casval 0:0099ad246127 182 Constant, /**< When the pin is a simple on/off switch. */
casval 0:0099ad246127 183 Direct, /**< Control the brightness with PWM, as the control pin is sourcing the current to drive the backlight LEDs. */
casval 0:0099ad246127 184 Indirect, /**< Control the brightness with PWM, as the control pin is sinking the current which drives the backlight LEDs. */
casval 0:0099ad246127 185 };
casval 0:0099ad246127 186 /** \typedef backlight_t
casval 0:0099ad246127 187 * \brief Convenience shortcut for the backlight control type.
casval 0:0099ad246127 188 */
casval 0:0099ad246127 189 typedef BacklightPwmCtrl_enum backlight_t;
casval 0:0099ad246127 190
casval 0:0099ad246127 191
casval 0:0099ad246127 192 /** Base class for LCD implementations.
casval 0:0099ad246127 193 *
casval 0:0099ad246127 194 * All separate LCD controller implementations have to subclass this one.
casval 0:0099ad246127 195 *
casval 0:0099ad246127 196 * \version 0.1
casval 0:0099ad246127 197 * \author Todor Todorov
casval 0:0099ad246127 198 */
casval 0:0099ad246127 199 class LCD
casval 0:0099ad246127 200 {
casval 0:0099ad246127 201 public:
casval 0:0099ad246127 202
casval 0:0099ad246127 203 /** Initialize display.
casval 0:0099ad246127 204 *
casval 0:0099ad246127 205 * Wakes up the display from sleep, initializes power parameters.
casval 0:0099ad246127 206 * This function must be called first, befor any painting on the
casval 0:0099ad246127 207 * display is done, otherwise the positioning of graphical elements
casval 0:0099ad246127 208 * will not work properly and any paynt operation will not be visible
casval 0:0099ad246127 209 * or produce garbage.
casval 0:0099ad246127 210 *
casval 0:0099ad246127 211 * This function is controller-specific and needs to be implemented
casval 0:0099ad246127 212 * separately for each available display.
casval 0:0099ad246127 213 * \param oritentation The display orientation, landscape is default.
casval 0:0099ad246127 214 * \param colors The correct color depth to use for the pixel data.
casval 0:0099ad246127 215 */
casval 0:0099ad246127 216 virtual void Initialize( orientation_t orientation, colordepth_t colors ) = 0;
casval 0:0099ad246127 217
casval 0:0099ad246127 218 /** Puts the display to sleep.
casval 0:0099ad246127 219 *
casval 0:0099ad246127 220 * When the display is in sleep mode, its power consumption is
casval 0:0099ad246127 221 * minimized. Before new pixel data can be written to the display
casval 0:0099ad246127 222 * memory, the controller needs to be brought out of sleep mode.
casval 0:0099ad246127 223 * \sa #WakeUp( void );
casval 0:0099ad246127 224 * \remarks The result of this operation might not be exactly as
casval 0:0099ad246127 225 * expected. Putting the display to sleep will cause the
casval 0:0099ad246127 226 * controller to switch to the standard color of the LCD,
casval 0:0099ad246127 227 * so depending on whether the display is normally white,
casval 0:0099ad246127 228 * or normally dark, the screen might or might not go
casval 0:0099ad246127 229 * dark. Additional power saving can be achieved, if
casval 0:0099ad246127 230 * the backlight of the used display is not hardwired on
casval 0:0099ad246127 231 * the PCB and can be controlled via the BL pin.
casval 0:0099ad246127 232 * \remarks This function is controller-specific and needs to be
casval 0:0099ad246127 233 * implemented separately for each available display.
casval 0:0099ad246127 234 */
casval 0:0099ad246127 235 virtual void Sleep( void );
casval 0:0099ad246127 236
casval 0:0099ad246127 237 /** Wakes up the display from sleep mode.
casval 0:0099ad246127 238 *
casval 0:0099ad246127 239 * This function needs to be called before any other, when the
casval 0:0099ad246127 240 * display has been put into sleep mode by a previois call to
casval 0:0099ad246127 241 * #Sleep( void ).
casval 0:0099ad246127 242 * \remarks This function is controller-specific and needs to be
casval 0:0099ad246127 243 * implemented separately for each available display.
casval 0:0099ad246127 244 */
casval 0:0099ad246127 245 virtual void WakeUp( void );
casval 0:0099ad246127 246
casval 0:0099ad246127 247 /** Set the foreground color for painting.
casval 0:0099ad246127 248 *
casval 0:0099ad246127 249 * This is the default foreground color to be used in painting operations.
casval 0:0099ad246127 250 * If a specific output function allows for a different color to be specified
casval 0:0099ad246127 251 * in place, the new setting will be used for that single operation only and
casval 0:0099ad246127 252 * will not change this value.
casval 0:0099ad246127 253 *
casval 0:0099ad246127 254 * \param color The color to be used (24-bit color depth).
casval 0:0099ad246127 255 * \sa #RGB(r,g,b)
casval 0:0099ad246127 256 */
casval 0:0099ad246127 257 virtual void SetForeground( unsigned int color = COLOR_WHITE);
casval 0:0099ad246127 258
casval 0:0099ad246127 259 /** Set the background color for painting.
casval 0:0099ad246127 260 *
casval 0:0099ad246127 261 * This is the default color to be used for "empty" pixels while painting.
casval 0:0099ad246127 262 * If a particular function allows for a different value to be specified
casval 0:0099ad246127 263 * when the function is called, the new value will be used only for this
casval 0:0099ad246127 264 * single call and will not change this setting.
casval 0:0099ad246127 265 *
casval 0:0099ad246127 266 * \param color The background color (24-bit color depth).
casval 0:0099ad246127 267 * \sa #RGB(r,g,b)
casval 0:0099ad246127 268 */
casval 0:0099ad246127 269 virtual void SetBackground( unsigned int color = COLOR_BLACK );
casval 0:0099ad246127 270
casval 0:0099ad246127 271 /** Sets the font to be used for painting of text on the screen.
casval 0:0099ad246127 272 * \param font A pointer to the font data.
casval 0:0099ad246127 273 * \sa Comments in file fonts.h
casval 0:0099ad246127 274 */
casval 0:0099ad246127 275 virtual void SetFont( const font_t* font );
casval 0:0099ad246127 276
casval 0:0099ad246127 277 /** Gets the display width.
casval 0:0099ad246127 278 * \return Display width in pixels.
casval 0:0099ad246127 279 */
casval 0:0099ad246127 280 unsigned short GetWidth( void );
casval 0:0099ad246127 281
casval 0:0099ad246127 282 /** Gets the display height.
casval 0:0099ad246127 283 * \return Display height in pixels.
casval 0:0099ad246127 284 */
casval 0:0099ad246127 285 unsigned short GetHeight( void );
casval 0:0099ad246127 286
casval 0:0099ad246127 287 /** Gets the font width.
casval 0:0099ad246127 288 * \return The current font width.
casval 0:0099ad246127 289 */
casval 0:0099ad246127 290 uint8_t GetFontWidth( void );
casval 0:0099ad246127 291
casval 0:0099ad246127 292 /** Gets the font height.
casval 0:0099ad246127 293 * \return The current font height.
casval 0:0099ad246127 294 */
casval 0:0099ad246127 295 uint8_t GetFontHeight( void );
casval 0:0099ad246127 296
casval 0:0099ad246127 297 /** Fills the whole screen with a single color.
casval 0:0099ad246127 298 * \param color The color to be used. The value must be in RGB-565 format.
casval 0:0099ad246127 299 * \remarks The special values -1 and -2 signify the preset background and foreground colors, respectively.
casval 0:0099ad246127 300 * The backround color is the default.
casval 0:0099ad246127 301 */
casval 0:0099ad246127 302 virtual void FillScreen( int color = -1 );
casval 0:0099ad246127 303
casval 0:0099ad246127 304 /** Sets the backlight intensity in percent as a float value in the range [0.0,1.0].
casval 0:0099ad246127 305 * \param level The backligh intensity in percent, where 0.0 is off and 1.0 is full brightness.
casval 0:0099ad246127 306 */
casval 0:0099ad246127 307
casval 0:0099ad246127 308 virtual void SetBacklightLevel( float level );
casval 0:0099ad246127 309
casval 0:0099ad246127 310 /** Clears the screen.
casval 0:0099ad246127 311 *
casval 0:0099ad246127 312 * This is the same as calling #FillScreen() or #FillScreen( -1 ) to use the background color.
casval 0:0099ad246127 313 */
casval 0:0099ad246127 314 virtual void ClearScreen( void );
casval 0:0099ad246127 315
casval 0:0099ad246127 316 /** Draws a pixel at the specified location.
casval 0:0099ad246127 317 *
casval 0:0099ad246127 318 * By default the function will use the preset foreground color, but the background
casval 0:0099ad246127 319 * or a custom color could be used as well.
casval 0:0099ad246127 320 *
casval 0:0099ad246127 321 * \param x The horizontal offset of the pixel from the upper left corner of the screen.
casval 0:0099ad246127 322 * \param y The vertical offset of the pixel from the upper left corner of the screen.
casval 0:0099ad246127 323 * \param color The color to be used. Use a custom color, or -1 for background and -2 for foreground color.
casval 0:0099ad246127 324 */
casval 0:0099ad246127 325 virtual void DrawPixel( unsigned short x, unsigned short y, int color = -2 );
casval 0:0099ad246127 326
casval 0:0099ad246127 327 /** Draws a line.
casval 0:0099ad246127 328 *
casval 0:0099ad246127 329 * \param x1 Horizontal offset of the beginning point of the line.
casval 0:0099ad246127 330 * \param y1 Vertical offset of the beginning point of the line.
casval 0:0099ad246127 331 * \param x2 Horizontal offset of the end point of the line.
casval 0:0099ad246127 332 * \param y2 Verical offset of the end point of the line.
casval 0:0099ad246127 333 * \param color The color to use for painting, or -1 for background, or -2 for foreground.
casval 0:0099ad246127 334 */
casval 0:0099ad246127 335 virtual void DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
casval 0:0099ad246127 336
casval 0:0099ad246127 337 /** Paints a rectangle.
casval 0:0099ad246127 338 *
casval 0:0099ad246127 339 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 340 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 341 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 342 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 343 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color.
casval 0:0099ad246127 344 */
casval 0:0099ad246127 345 virtual void DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
casval 0:0099ad246127 346
casval 0:0099ad246127 347 /** Paints a rectangle and fills it with the paint color.
casval 0:0099ad246127 348 *
casval 0:0099ad246127 349 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 350 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 351 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 352 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 353 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color.
casval 0:0099ad246127 354 */
casval 0:0099ad246127 355 virtual void DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
casval 0:0099ad246127 356
casval 0:0099ad246127 357 /** Paints a rectangle with rounded corners.
casval 0:0099ad246127 358 *
casval 0:0099ad246127 359 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 360 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 361 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 362 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 363 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color.
casval 0:0099ad246127 364 */
casval 0:0099ad246127 365 virtual void FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
casval 0:0099ad246127 366
casval 0:0099ad246127 367 /** Paints a rectangle with rounded corners and fills it with the paint color.
casval 0:0099ad246127 368 *
casval 0:0099ad246127 369 * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 370 * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals.
casval 0:0099ad246127 371 * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 372 * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals.
casval 0:0099ad246127 373 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color.
casval 0:0099ad246127 374 */
casval 0:0099ad246127 375 virtual void FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 );
casval 0:0099ad246127 376
casval 0:0099ad246127 377 /** Paints a circle.
casval 0:0099ad246127 378 *
casval 0:0099ad246127 379 * \param x The offset of the circle's center from the left edge of the screen.
casval 0:0099ad246127 380 * \param y The offset of the circle's center from the top edge of the screen.
casval 0:0099ad246127 381 * \param radius The circle's radius.
casval 0:0099ad246127 382 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color.
casval 0:0099ad246127 383 */
casval 0:0099ad246127 384 virtual void DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 );
casval 0:0099ad246127 385
casval 0:0099ad246127 386 /** Paints a circle and fills it with the paint color.
casval 0:0099ad246127 387 *
casval 0:0099ad246127 388 * \param x The offset of the circle's center from the left edge of the screen.
casval 0:0099ad246127 389 * \param y The offset of the circle's center from the top edge of the screen.
casval 0:0099ad246127 390 * \param radius The circle's radius.
casval 0:0099ad246127 391 * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color.
casval 0:0099ad246127 392 */
casval 0:0099ad246127 393 virtual void FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 );
casval 0:0099ad246127 394
casval 0:0099ad246127 395 /** Print a text on the screen.
casval 0:0099ad246127 396 *
casval 0:0099ad246127 397 * \param str The text.
casval 0:0099ad246127 398 * \param x The horizontal offset form the left edge of the screen. The special values LEFT, CENTER,
casval 0:0099ad246127 399 * or RIGHT can be used instead of pixel offset to indicate the text's horizontal alignment.
casval 0:0099ad246127 400 * \param y The vertical offset of the text from the top of the screen.
casval 0:0099ad246127 401 * \param fgColor The foreground to use for painting the text; -1 indicates background color, -2 the foreground setting, or custom color.
casval 0:0099ad246127 402 * \param bgColor The color to use for painting the empty pixels; -1 indicates the background color, -2 the foreground setting, or custom color.
casval 0:0099ad246127 403 * \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.
casval 0:0099ad246127 404 */
casval 0:0099ad246127 405 virtual void Print( const char *str, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 );
casval 0:0099ad246127 406
casval 0:0099ad246127 407 /** Draw an image on the screen.
casval 0:0099ad246127 408 *
casval 0:0099ad246127 409 * The pixels of the picture must be in the RGB-565 format. The data can be provided
casval 0:0099ad246127 410 * as an array in a source or a header file. To convert an image file to the appropriate
casval 0:0099ad246127 411 * format, a special utility must be utilized. One such tool is provided by Henning Karlsen,
casval 0:0099ad246127 412 * the author of the UTFT display liberary and can be downloaded for free from his web site:
casval 0:0099ad246127 413 * http://henningkarlsen.com/electronics/library.php?id=52
casval 0:0099ad246127 414 *
casval 0:0099ad246127 415 * \param x Horizontal offset of the first pixel of the image.
casval 0:0099ad246127 416 * \param y Vertical offset of the first pixel of the image.
casval 0:0099ad246127 417 * \param img Image data pointer.
casval 0:0099ad246127 418 * \param scale A value of 1 will produce an image with its original size, while a different value will scale the image.
casval 0:0099ad246127 419 */
casval 0:0099ad246127 420 virtual void DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned char scale = 1 );
casval 0:0099ad246127 421
casval 0:0099ad246127 422 /** Draw an image on the screen.
casval 0:0099ad246127 423 *
casval 0:0099ad246127 424 * The pixels of the picture must be in the RGB-565 format. The data can be provided
casval 0:0099ad246127 425 * as an array in a source or a header file. To convert an image file to the appropriate
casval 0:0099ad246127 426 * format, a special utility must be utilized. One such tool is provided by Henning Karlsen,
casval 0:0099ad246127 427 * the author of the UTFT display liberary and can be downloaded for free from his web site:
casval 0:0099ad246127 428 * http://henningkarlsen.com/electronics/library.php?id=52
casval 0:0099ad246127 429 *
casval 0:0099ad246127 430 * \param x Horizontal offset of the first pixel of the image.
casval 0:0099ad246127 431 * \param y Vertical offset of the first pixel of the image.
casval 0:0099ad246127 432 * \param img Image data pointer.
casval 0:0099ad246127 433 * \param deg Angle to rotate the image before painting on screen, in degrees.
casval 0:0099ad246127 434 * \param rox
casval 0:0099ad246127 435 * \param roy
casval 0:0099ad246127 436 */
casval 0:0099ad246127 437 virtual void DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned short deg, unsigned short rox, unsigned short roy );
casval 0:0099ad246127 438
casval 0:0099ad246127 439 /** Sends both command and data to the display controller.
casval 0:0099ad246127 440 *
casval 0:0099ad246127 441 * This is a helper utility function which combines the 2 functions above
casval 0:0099ad246127 442 * into one single convenience step.
casval 0:0099ad246127 443 *
casval 0:0099ad246127 444 * \param cmd The display command.
casval 0:0099ad246127 445 * \param data The display pixel data.
casval 0:0099ad246127 446 */
casval 0:0099ad246127 447 virtual void WriteCmdData( unsigned short cmd, unsigned short data );
casval 0:0099ad246127 448
casval 0:0099ad246127 449 protected:
casval 0:0099ad246127 450 /** Creates an instance of the class.
casval 0:0099ad246127 451 *
casval 0:0099ad246127 452 * \param width Width of the display in pixels.
casval 0:0099ad246127 453 * \param height Height of the display in pixels.
casval 0:0099ad246127 454 * \param CS Pin connected to the CS input of the display.
casval 0:0099ad246127 455 * \param RS Pin connected to the RS input of the display.
casval 0:0099ad246127 456 * \param RESET Pin connected to the RESET input of the display.
casval 0:0099ad246127 457 * \param BL Pin connected to the circuit controlling the LCD's backlight.
casval 0:0099ad246127 458 * \param blType The type of backlight to be used.
casval 0:0099ad246127 459 * \param defaultBacklight The standard backlight intensity (if using PWM control), expressed in percent as float value from 0.0 to 1.0
casval 0:0099ad246127 460 */
casval 0:0099ad246127 461 LCD( unsigned short width, unsigned short height, PinName CS, PinName RS, PinName DIR, PinName EN, PinName LE, PinName BL, backlight_t blType, float defaultBacklight );
casval 0:0099ad246127 462
casval 0:0099ad246127 463 /** Activates the display for command/data transfer.
casval 0:0099ad246127 464 *
casval 0:0099ad246127 465 * Usually achieved by pulling the CS pin of the display low.
casval 0:0099ad246127 466 */
casval 0:0099ad246127 467 virtual void Activate( void );
casval 0:0099ad246127 468
casval 0:0099ad246127 469 /** Deactivates the display after data has been transmitted.
casval 0:0099ad246127 470 *
casval 0:0099ad246127 471 * Usually achieved by pulling the CS pin of the display high.
casval 0:0099ad246127 472 */
casval 0:0099ad246127 473 virtual void Deactivate( void );
casval 0:0099ad246127 474
casval 0:0099ad246127 475 /** Sends a command to the display.
casval 0:0099ad246127 476 *
casval 0:0099ad246127 477 * \param cmd The display command.
casval 0:0099ad246127 478 * \remarks Commands are controller-specific and this function needs to
casval 0:0099ad246127 479 * be implemented separately for each available controller.
casval 0:0099ad246127 480 */
casval 0:0099ad246127 481 virtual void WriteCmd( unsigned short cmd ) = 0;
casval 0:0099ad246127 482
casval 0:0099ad246127 483 /** Sends pixel data to the display.
casval 0:0099ad246127 484 *
casval 0:0099ad246127 485 * \param data The display data.
casval 0:0099ad246127 486 * \remarks Sendin data is controller-specific and this function needs to
casval 0:0099ad246127 487 * be implemented separately for each available controller.
casval 0:0099ad246127 488 */
casval 0:0099ad246127 489 virtual void WriteData( unsigned short data ) = 0;
casval 0:0099ad246127 490
casval 0:0099ad246127 491
casval 0:0099ad246127 492
casval 0:0099ad246127 493 /** Assigns a chunk of the display memory to receive data.
casval 0:0099ad246127 494 *
casval 0:0099ad246127 495 * When data is sent to the display after this function completes, the opertion will
casval 0:0099ad246127 496 * start from the begining of the assigned address (pixel position) and the pointer
casval 0:0099ad246127 497 * will be automatically incremented so that the next data write operation will continue
casval 0:0099ad246127 498 * with the next pixel from the memory block. If more data is written than available
casval 0:0099ad246127 499 * pixels, at the end of the block the pointer will jump back to its beginning and
casval 0:0099ad246127 500 * commence again, until the next address change command is sent to the display.
casval 0:0099ad246127 501 *
casval 0:0099ad246127 502 * \param x1 The X coordinate of the pixel at the beginning of the block.
casval 0:0099ad246127 503 * \param y1 The Y coordinate of the pixel at the beginning of the block.
casval 0:0099ad246127 504 * \param x2 The X coordinate of the pixel at the end of the block.
casval 0:0099ad246127 505 * \param y2 The Y coordinate of the pixel at the end of the block.
casval 0:0099ad246127 506 * \remarks Addressing commands are controller-specific and this function needs to be
casval 0:0099ad246127 507 * implemented separately for each available controller.
casval 0:0099ad246127 508 */
casval 0:0099ad246127 509 virtual void SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 ) = 0;
casval 0:0099ad246127 510
casval 0:0099ad246127 511 /** Resets the memory address for the next display write operation to the screen origins (0,0).
casval 0:0099ad246127 512 */
casval 0:0099ad246127 513 virtual void ClearXY( void );
casval 0:0099ad246127 514
casval 0:0099ad246127 515 /** Sets the color of the pixel at the address pointer of the controller.
casval 0:0099ad246127 516 *
casval 0:0099ad246127 517 * This function is to be provided by each implementation separately in
casval 0:0099ad246127 518 * order to account for different color depths used by the controller.
casval 0:0099ad246127 519 * \param color The color of the pixel.
casval 0:0099ad246127 520 * \param mode The depth (palette) of the color.
casval 0:0099ad246127 521 */
casval 0:0099ad246127 522 virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 ) = 0;
casval 0:0099ad246127 523
casval 0:0099ad246127 524 /** Draws a horizontal line.
casval 0:0099ad246127 525 *
casval 0:0099ad246127 526 * This is a utility function to draw horizontal-only lines
casval 0:0099ad246127 527 * for reduced code complexity and faster execution.
casval 0:0099ad246127 528 *
casval 0:0099ad246127 529 * \param x X coordinate of the starting point of the line.
casval 0:0099ad246127 530 * \param y Y coordinate of the starting point of the line.
casval 0:0099ad246127 531 * \param len Length of the line.
casval 0:0099ad246127 532 * \param color The color to use to draw the line. By default the global foreground color is used ( -2 ),
casval 0:0099ad246127 533 * -1 switches to the default background color, or any custom color can be used.
casval 0:0099ad246127 534 */
casval 0:0099ad246127 535 virtual void DrawHLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 );
casval 0:0099ad246127 536
casval 0:0099ad246127 537 /** Draws a vertical line.
casval 0:0099ad246127 538 *
casval 0:0099ad246127 539 * This is a utility function to draw vertical-only lines
casval 0:0099ad246127 540 * for reduced code complexity and faster execution.
casval 0:0099ad246127 541 *
casval 0:0099ad246127 542 * \param x X coordinate of the starting point of the line.
casval 0:0099ad246127 543 * \param y Y coordinate of the starting point of the line.
casval 0:0099ad246127 544 * \param len Height of the line.
casval 0:0099ad246127 545 * \param color The color to use to draw the line. By default the global foreground color is used ( -2 ),
casval 0:0099ad246127 546 * -1 switches to the default background color, or any custom color can be used.
casval 0:0099ad246127 547 */
casval 0:0099ad246127 548 virtual void DrawVLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 );
casval 0:0099ad246127 549
casval 0:0099ad246127 550 /** Prints a character at the given position and using the given color.
casval 0:0099ad246127 551 *
casval 0:0099ad246127 552 * \param c The character.
casval 0:0099ad246127 553 * \param x X coordinate of the character position.
casval 0:0099ad246127 554 * \param y Y coordinate of the character position.
casval 0:0099ad246127 555 * \param fgColor Foreground color for drawing. By default the global foreground color is used ( -2 ),
casval 0:0099ad246127 556 * -1 switches to the default background color, or any custom color can be used.
casval 0:0099ad246127 557 * \param bgColor Background color for drawing. By default the global background color is used ( -1 ),
casval 0:0099ad246127 558 * -2 switches to the default foreground color, or any custom color can be used.
casval 0:0099ad246127 559 */
casval 0:0099ad246127 560 virtual void PrintChar( char c, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1 );
casval 0:0099ad246127 561
casval 0:0099ad246127 562 /** Prints a character at the given position and using the given color and with the given rotation.
casval 0:0099ad246127 563 *
casval 0:0099ad246127 564 * \param c The character.
casval 0:0099ad246127 565 * \param x X coordinate of the character position.
casval 0:0099ad246127 566 * \param y Y coordinate of the character position.
casval 0:0099ad246127 567 * \param pos Position of the character in the string from which it originates (used to rotate a whole string).
casval 0:0099ad246127 568 * \param fgColor Foreground color for drawing. By default the global foreground color is used ( -2 ),
casval 0:0099ad246127 569 * -1 switches to the default background color, or any custom color can be used.
casval 0:0099ad246127 570 * \param bgColor Background color for drawing. By default the global background color is used ( -1 ),
casval 0:0099ad246127 571 * -2 switches to the default foreground color, or any custom color can be used.
casval 0:0099ad246127 572 * \param deg The angle at which to rotate.
casval 0:0099ad246127 573 */
casval 0:0099ad246127 574 virtual void RotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 );
casval 0:0099ad246127 575
casval 0:0099ad246127 576 protected:
casval 0:0099ad246127 577 unsigned short _disp_width, _disp_height;
casval 0:0099ad246127 578 DigitalOut _lcd_pin_cs, _lcd_pin_rs, _lcd_pin_dir, _lcd_pin_en, _lcd_pin_le;
casval 0:0099ad246127 579 orientation_t _orientation;
casval 0:0099ad246127 580 colordepth_t _colorDepth;
casval 0:0099ad246127 581 unsigned int _foreground, _background;
casval 0:0099ad246127 582 const font_t* _font;
casval 0:0099ad246127 583 DigitalOut* _lcd_pin_bl;
casval 0:0099ad246127 584 PwmOut* _bl_pwm;
casval 0:0099ad246127 585 backlight_t _bl_type;
casval 0:0099ad246127 586 float _bl_pwm_default, _bl_pwm_current;
casval 0:0099ad246127 587 };
casval 0:0099ad246127 588
casval 0:0099ad246127 589 #ifdef __cplusplus
casval 0:0099ad246127 590 }
casval 0:0099ad246127 591 #endif
casval 0:0099ad246127 592
casval 0:0099ad246127 593 #endif /* TFTLCD_BASE_H */