Forked from TFTLCD_8bit by Thiha Electronics
Dependents: GR-PEACH_TFTLCD_8bit
Fork of TFTLCD_8bit by
lcd_base.h@0:881ff0b71102, 2012-12-01 (annotated)
- Committer:
- ttodorov
- Date:
- Sat Dec 01 19:38:53 2012 +0000
- Revision:
- 0:881ff0b71102
- Child:
- 2:81ed304b7e9b
- first version of a standardized TFT library, which is to provide support for multiple LCD controllers and different data buses.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:881ff0b71102 | 11 | * Copyright (C)2012 Todor Todorov. |
ttodorov | 0:881ff0b71102 | 12 | * |
ttodorov | 0:881ff0b71102 | 13 | * This library is free software; you can redistribute it and/or |
ttodorov | 0:881ff0b71102 | 14 | * modify it under the terms of the GNU Lesser General Public |
ttodorov | 0:881ff0b71102 | 15 | * License as published by the Free Software Foundation; either |
ttodorov | 0:881ff0b71102 | 16 | * version 2.1 of the License, or (at your option) any later version. |
ttodorov | 0:881ff0b71102 | 17 | * |
ttodorov | 0:881ff0b71102 | 18 | * This library is distributed in the hope that it will be useful, |
ttodorov | 0:881ff0b71102 | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ttodorov | 0:881ff0b71102 | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ttodorov | 0:881ff0b71102 | 21 | * Lesser General Public License for more details. |
ttodorov | 0:881ff0b71102 | 22 | * |
ttodorov | 0:881ff0b71102 | 23 | * You should have received a copy of the GNU Lesser General Public |
ttodorov | 0:881ff0b71102 | 24 | * License along with this library; if not, write to: |
ttodorov | 0:881ff0b71102 | 25 | * |
ttodorov | 0:881ff0b71102 | 26 | * Free Software Foundation, Inc. |
ttodorov | 0:881ff0b71102 | 27 | * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA |
ttodorov | 0:881ff0b71102 | 28 | * |
ttodorov | 0:881ff0b71102 | 29 | *********************************************************************/ |
ttodorov | 0:881ff0b71102 | 30 | #ifndef LCD_BASE_H |
ttodorov | 0:881ff0b71102 | 31 | #define LCD_BASE_H |
ttodorov | 0:881ff0b71102 | 32 | |
ttodorov | 0:881ff0b71102 | 33 | #include "mbed.h" |
ttodorov | 0:881ff0b71102 | 34 | #include "fonts.h" |
ttodorov | 0:881ff0b71102 | 35 | |
ttodorov | 0:881ff0b71102 | 36 | #define HIGH 1 |
ttodorov | 0:881ff0b71102 | 37 | #define LOW 0 |
ttodorov | 0:881ff0b71102 | 38 | |
ttodorov | 0:881ff0b71102 | 39 | #define swap( type, a, b ) { type tmp = ( a ); ( a ) = ( b ); ( b ) = tmp; } |
ttodorov | 0:881ff0b71102 | 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 | 0:881ff0b71102 | 71 | /** \typedef orientation_t |
ttodorov | 0:881ff0b71102 | 72 | * \brief Display orientation. |
ttodorov | 0:881ff0b71102 | 73 | */ |
ttodorov | 0:881ff0b71102 | 74 | typedef 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 | 0:881ff0b71102 | 78 | } orientation_t; |
ttodorov | 0:881ff0b71102 | 79 | |
ttodorov | 0:881ff0b71102 | 80 | /** \typedef align_t |
ttodorov | 0:881ff0b71102 | 81 | * \brief Horizontal text alignment on the line. |
ttodorov | 0:881ff0b71102 | 82 | */ |
ttodorov | 0:881ff0b71102 | 83 | typedef enum Alignment_enum |
ttodorov | 0:881ff0b71102 | 84 | { |
ttodorov | 0:881ff0b71102 | 85 | LEFT = 0, /**< Left-oriented, naturally gravitate closer to the left edge of the screen. */ |
ttodorov | 0:881ff0b71102 | 86 | 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 | 87 | 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 | 0:881ff0b71102 | 88 | } align_t; |
ttodorov | 0:881ff0b71102 | 89 | |
ttodorov | 0:881ff0b71102 | 90 | /** \typedef font_metrics_t |
ttodorov | 0:881ff0b71102 | 91 | * \brief Describes fonts and their properties. |
ttodorov | 0:881ff0b71102 | 92 | * \sa Comments in fonts.h |
ttodorov | 0:881ff0b71102 | 93 | */ |
ttodorov | 0:881ff0b71102 | 94 | typedef struct Font_struct |
ttodorov | 0:881ff0b71102 | 95 | { |
ttodorov | 0:881ff0b71102 | 96 | const char* font; /**< A pointer to the first byte in the font. */ |
ttodorov | 0:881ff0b71102 | 97 | unsigned char width; /**< The width of each character, in pixels. */ |
ttodorov | 0:881ff0b71102 | 98 | unsigned char height; /**< Height of each character, in pixels. */ |
ttodorov | 0:881ff0b71102 | 99 | unsigned char offset; /**< Offset of the first character in the font. */ |
ttodorov | 0:881ff0b71102 | 100 | unsigned char numchars; /**< Count of the available characters in the font. */ |
ttodorov | 0:881ff0b71102 | 101 | } font_metrics_t; |
ttodorov | 0:881ff0b71102 | 102 | |
ttodorov | 0:881ff0b71102 | 103 | /** \typedef bitmap_t |
ttodorov | 0:881ff0b71102 | 104 | * \brief Pointer to the start of a block of pixel data, describing a picture. |
ttodorov | 0:881ff0b71102 | 105 | */ |
ttodorov | 0:881ff0b71102 | 106 | typedef unsigned short* bitmap_t; |
ttodorov | 0:881ff0b71102 | 107 | |
ttodorov | 0:881ff0b71102 | 108 | /** Base class for LCD implementations. |
ttodorov | 0:881ff0b71102 | 109 | * |
ttodorov | 0:881ff0b71102 | 110 | * All separate LCD controller implementations have to subclass this one. |
ttodorov | 0:881ff0b71102 | 111 | * |
ttodorov | 0:881ff0b71102 | 112 | * \version 0.1 |
ttodorov | 0:881ff0b71102 | 113 | * \author Todor Todorov |
ttodorov | 0:881ff0b71102 | 114 | */ |
ttodorov | 0:881ff0b71102 | 115 | class LCD |
ttodorov | 0:881ff0b71102 | 116 | { |
ttodorov | 0:881ff0b71102 | 117 | public: |
ttodorov | 0:881ff0b71102 | 118 | |
ttodorov | 0:881ff0b71102 | 119 | /** Initialize display. |
ttodorov | 0:881ff0b71102 | 120 | * |
ttodorov | 0:881ff0b71102 | 121 | * Wakes up the display from sleep, initializes power parameters. |
ttodorov | 0:881ff0b71102 | 122 | * This function must be called first, befor any painting on the |
ttodorov | 0:881ff0b71102 | 123 | * display is done, otherwise the positioning of graphical elements |
ttodorov | 0:881ff0b71102 | 124 | * will not work properly and any paynt operation will not be visible |
ttodorov | 0:881ff0b71102 | 125 | * or produce garbage. |
ttodorov | 0:881ff0b71102 | 126 | * |
ttodorov | 0:881ff0b71102 | 127 | * This function is controller-specific and needs to be implemented |
ttodorov | 0:881ff0b71102 | 128 | * separately for each available implementation. |
ttodorov | 0:881ff0b71102 | 129 | * \param oritentation The display orientation, landscape is default. |
ttodorov | 0:881ff0b71102 | 130 | */ |
ttodorov | 0:881ff0b71102 | 131 | virtual void Initialize( orientation_t orientation ) = 0; |
ttodorov | 0:881ff0b71102 | 132 | |
ttodorov | 0:881ff0b71102 | 133 | /** Set the foreground color for painting. |
ttodorov | 0:881ff0b71102 | 134 | * |
ttodorov | 0:881ff0b71102 | 135 | * This is the default foreground color to be used in painting operations. |
ttodorov | 0:881ff0b71102 | 136 | * If a specific output function allows for a different color to be specified |
ttodorov | 0:881ff0b71102 | 137 | * in place, the new setting will be used for that single operation only and |
ttodorov | 0:881ff0b71102 | 138 | * will not change this value. |
ttodorov | 0:881ff0b71102 | 139 | * |
ttodorov | 0:881ff0b71102 | 140 | * \param color The color to be used. The value must be in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 141 | * \sa #RGB(r,g,b) |
ttodorov | 0:881ff0b71102 | 142 | */ |
ttodorov | 0:881ff0b71102 | 143 | virtual void SetForeground( unsigned short color = COLOR_WHITE ); |
ttodorov | 0:881ff0b71102 | 144 | |
ttodorov | 0:881ff0b71102 | 145 | /** Set the background color for painting. |
ttodorov | 0:881ff0b71102 | 146 | * |
ttodorov | 0:881ff0b71102 | 147 | * This is the default color to be used for "empty" pixels while painting. |
ttodorov | 0:881ff0b71102 | 148 | * If a particular function allows for a different value to be specified |
ttodorov | 0:881ff0b71102 | 149 | * when the function is called, the new value will be used only for this |
ttodorov | 0:881ff0b71102 | 150 | * single call and will not change this setting. |
ttodorov | 0:881ff0b71102 | 151 | * |
ttodorov | 0:881ff0b71102 | 152 | * \param color The background color as RGB-565 value. |
ttodorov | 0:881ff0b71102 | 153 | * \sa #RGB(r,g,b) |
ttodorov | 0:881ff0b71102 | 154 | */ |
ttodorov | 0:881ff0b71102 | 155 | virtual void SetBackground( unsigned short color = COLOR_BLACK ); |
ttodorov | 0:881ff0b71102 | 156 | |
ttodorov | 0:881ff0b71102 | 157 | /** Sets the font to be used for painting of text on the screen. |
ttodorov | 0:881ff0b71102 | 158 | * \param font A pointer to the font data. |
ttodorov | 0:881ff0b71102 | 159 | * \sa Comments in file fonts.h |
ttodorov | 0:881ff0b71102 | 160 | */ |
ttodorov | 0:881ff0b71102 | 161 | virtual void SetFont( const char* font ); |
ttodorov | 0:881ff0b71102 | 162 | |
ttodorov | 0:881ff0b71102 | 163 | /** Gets the display width. |
ttodorov | 0:881ff0b71102 | 164 | * \return Display width in pixels. |
ttodorov | 0:881ff0b71102 | 165 | */ |
ttodorov | 0:881ff0b71102 | 166 | unsigned short GetWidth( void ); |
ttodorov | 0:881ff0b71102 | 167 | |
ttodorov | 0:881ff0b71102 | 168 | /** Gets the display height. |
ttodorov | 0:881ff0b71102 | 169 | * \return Display height in pixels. |
ttodorov | 0:881ff0b71102 | 170 | */ |
ttodorov | 0:881ff0b71102 | 171 | unsigned short GetHeight( void ); |
ttodorov | 0:881ff0b71102 | 172 | |
ttodorov | 0:881ff0b71102 | 173 | /** Fills the whole screen with a single color. |
ttodorov | 0:881ff0b71102 | 174 | * \param color The color to be used. The value must be in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 175 | * \remarks The special values -1 and -2 signify the preset background and foreground colors, respectively. |
ttodorov | 0:881ff0b71102 | 176 | * The backround color is the default. |
ttodorov | 0:881ff0b71102 | 177 | */ |
ttodorov | 0:881ff0b71102 | 178 | virtual void FillScreen( int color = -1 ); |
ttodorov | 0:881ff0b71102 | 179 | |
ttodorov | 0:881ff0b71102 | 180 | /** Clears the screen. |
ttodorov | 0:881ff0b71102 | 181 | * |
ttodorov | 0:881ff0b71102 | 182 | * This is the same as calling #FillScreen() or #FillScreen( -1 ) to use the background color. |
ttodorov | 0:881ff0b71102 | 183 | */ |
ttodorov | 0:881ff0b71102 | 184 | virtual void ClearScreen( void ); |
ttodorov | 0:881ff0b71102 | 185 | |
ttodorov | 0:881ff0b71102 | 186 | /** Draws a pixel at the specified location. |
ttodorov | 0:881ff0b71102 | 187 | * |
ttodorov | 0:881ff0b71102 | 188 | * By default the function will use the preset foreground color, but the background |
ttodorov | 0:881ff0b71102 | 189 | * or a custom color could be used as well. |
ttodorov | 0:881ff0b71102 | 190 | * |
ttodorov | 0:881ff0b71102 | 191 | * \param x The horizontal offset of the pixel from the upper left corner of the screen. |
ttodorov | 0:881ff0b71102 | 192 | * \param y The vertical offset of the pixel from the upper left corner of the screen. |
ttodorov | 0:881ff0b71102 | 193 | * \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 | 194 | */ |
ttodorov | 0:881ff0b71102 | 195 | virtual void DrawPixel( unsigned short x, unsigned short y, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 196 | |
ttodorov | 0:881ff0b71102 | 197 | /** Draws a line. |
ttodorov | 0:881ff0b71102 | 198 | * |
ttodorov | 0:881ff0b71102 | 199 | * \param x1 Horizontal offset of the beginning point of the line. |
ttodorov | 0:881ff0b71102 | 200 | * \param y1 Vertical offset of the beginning point of the line. |
ttodorov | 0:881ff0b71102 | 201 | * \param x2 Horizontal offset of the end point of the line. |
ttodorov | 0:881ff0b71102 | 202 | * \param y2 Verical offset of the end point of the line. |
ttodorov | 0:881ff0b71102 | 203 | * \param color The color to use for painting, in RGB-565 format, or -1 for background, or -2 for foreground. |
ttodorov | 0:881ff0b71102 | 204 | */ |
ttodorov | 0:881ff0b71102 | 205 | virtual void DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 206 | |
ttodorov | 0:881ff0b71102 | 207 | /** Paints a rectangle. |
ttodorov | 0:881ff0b71102 | 208 | * |
ttodorov | 0:881ff0b71102 | 209 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 210 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 211 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 212 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 213 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 214 | */ |
ttodorov | 0:881ff0b71102 | 215 | virtual void DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 216 | |
ttodorov | 0:881ff0b71102 | 217 | /** Paints a rectangle and fills it with the paint color. |
ttodorov | 0:881ff0b71102 | 218 | * |
ttodorov | 0:881ff0b71102 | 219 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 220 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 221 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 222 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 223 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 224 | */ |
ttodorov | 0:881ff0b71102 | 225 | virtual void DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 226 | |
ttodorov | 0:881ff0b71102 | 227 | /** Paints a rectangle with rounded corners. |
ttodorov | 0:881ff0b71102 | 228 | * |
ttodorov | 0:881ff0b71102 | 229 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 230 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 231 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 232 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 233 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 234 | */ |
ttodorov | 0:881ff0b71102 | 235 | virtual void FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 236 | |
ttodorov | 0:881ff0b71102 | 237 | /** Paints a rectangle with rounded corners and fills it with the paint color. |
ttodorov | 0:881ff0b71102 | 238 | * |
ttodorov | 0:881ff0b71102 | 239 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 240 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 241 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 242 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 0:881ff0b71102 | 243 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 244 | */ |
ttodorov | 0:881ff0b71102 | 245 | virtual void FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 246 | |
ttodorov | 0:881ff0b71102 | 247 | /** Paints a circle. |
ttodorov | 0:881ff0b71102 | 248 | * |
ttodorov | 0:881ff0b71102 | 249 | * \param x The offset of the circle's center from the left edge of the screen. |
ttodorov | 0:881ff0b71102 | 250 | * \param y The offset of the circle's center from the top edge of the screen. |
ttodorov | 0:881ff0b71102 | 251 | * \param radius The circle's radius. |
ttodorov | 0:881ff0b71102 | 252 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 253 | */ |
ttodorov | 0:881ff0b71102 | 254 | virtual void DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 255 | |
ttodorov | 0:881ff0b71102 | 256 | /** Paints a circle and fills it with the paint color. |
ttodorov | 0:881ff0b71102 | 257 | * |
ttodorov | 0:881ff0b71102 | 258 | * \param x The offset of the circle's center from the left edge of the screen. |
ttodorov | 0:881ff0b71102 | 259 | * \param y The offset of the circle's center from the top edge of the screen. |
ttodorov | 0:881ff0b71102 | 260 | * \param radius The circle's radius. |
ttodorov | 0:881ff0b71102 | 261 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 0:881ff0b71102 | 262 | */ |
ttodorov | 0:881ff0b71102 | 263 | virtual void FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 264 | |
ttodorov | 0:881ff0b71102 | 265 | /** Print a text on the screen. |
ttodorov | 0:881ff0b71102 | 266 | * |
ttodorov | 0:881ff0b71102 | 267 | * \param str The text. |
ttodorov | 0:881ff0b71102 | 268 | * \param x The horizontal offset form the left edge of the screen. The special values LEFT, CENTER, |
ttodorov | 0:881ff0b71102 | 269 | * or RIGHT can be used instead of pixel offset to indicate the text's horizontal alignment. |
ttodorov | 0:881ff0b71102 | 270 | * \param y The vertical offset of the text from the top of the screen. |
ttodorov | 0:881ff0b71102 | 271 | * \param fgColor The foreground to use for painting the text; -1 indicates background color, -2 the foreground setting, or custom color. |
ttodorov | 0:881ff0b71102 | 272 | * \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 | 273 | * \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 | 274 | */ |
ttodorov | 0:881ff0b71102 | 275 | 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 | 276 | |
ttodorov | 0:881ff0b71102 | 277 | /** Draw an image on the screen. |
ttodorov | 0:881ff0b71102 | 278 | * |
ttodorov | 0:881ff0b71102 | 279 | * The pixels of the picture must be in the RGB-565 format. The data can be provided |
ttodorov | 0:881ff0b71102 | 280 | * as an array in a source or a header file. To convert an image file to the appropriate |
ttodorov | 0:881ff0b71102 | 281 | * format, a special utility must be utilized. One such tool is provided by Henning Karlsen, |
ttodorov | 0:881ff0b71102 | 282 | * the author of the UTFT display liberary and can be downloaded for free from his web site: |
ttodorov | 0:881ff0b71102 | 283 | * http://henningkarlsen.com/electronics/library.php?id=52 |
ttodorov | 0:881ff0b71102 | 284 | * |
ttodorov | 0:881ff0b71102 | 285 | * \param x Horizontal offset of the first pixel of the image. |
ttodorov | 0:881ff0b71102 | 286 | * \param y Vertical offset of the first pixel of the image |
ttodorov | 0:881ff0b71102 | 287 | * \param sx Width of the image. |
ttodorov | 0:881ff0b71102 | 288 | * \param sy Height of the image. |
ttodorov | 0:881ff0b71102 | 289 | * \param data Image pixel array. |
ttodorov | 0:881ff0b71102 | 290 | * \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 | 291 | */ |
ttodorov | 0:881ff0b71102 | 292 | virtual void DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, bitmap_t data, unsigned char scale = 1 ); |
ttodorov | 0:881ff0b71102 | 293 | |
ttodorov | 0:881ff0b71102 | 294 | /** Draw an image on the screen. |
ttodorov | 0:881ff0b71102 | 295 | * |
ttodorov | 0:881ff0b71102 | 296 | * The pixels of the picture must be in the RGB-565 format. The data can be provided |
ttodorov | 0:881ff0b71102 | 297 | * as an array in a source or a header file. To convert an image file to the appropriate |
ttodorov | 0:881ff0b71102 | 298 | * format, a special utility must be utilized. One such tool is provided by Henning Karlsen, |
ttodorov | 0:881ff0b71102 | 299 | * the author of the UTFT display liberary and can be downloaded for free from his web site: |
ttodorov | 0:881ff0b71102 | 300 | * http://henningkarlsen.com/electronics/library.php?id=52 |
ttodorov | 0:881ff0b71102 | 301 | * |
ttodorov | 0:881ff0b71102 | 302 | * \param x Horizontal offset of the first pixel of the image. |
ttodorov | 0:881ff0b71102 | 303 | * \param y Vertical offset of the first pixel of the image |
ttodorov | 0:881ff0b71102 | 304 | * \param sx Width of the image. |
ttodorov | 0:881ff0b71102 | 305 | * \param sy Height of the image. |
ttodorov | 0:881ff0b71102 | 306 | * \param data Image pixel array. |
ttodorov | 0:881ff0b71102 | 307 | * \param deg Angle to rotate the image before painting on screen, in degrees. |
ttodorov | 0:881ff0b71102 | 308 | * \param rox |
ttodorov | 0:881ff0b71102 | 309 | * \param roy |
ttodorov | 0:881ff0b71102 | 310 | */ |
ttodorov | 0:881ff0b71102 | 311 | virtual void DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, bitmap_t data, unsigned short deg, unsigned short rox, unsigned short roy ); |
ttodorov | 0:881ff0b71102 | 312 | |
ttodorov | 0:881ff0b71102 | 313 | protected: |
ttodorov | 0:881ff0b71102 | 314 | /** Creates an instance of the class. |
ttodorov | 0:881ff0b71102 | 315 | * |
ttodorov | 0:881ff0b71102 | 316 | * \param width Width of the display in pixels. |
ttodorov | 0:881ff0b71102 | 317 | * \param height Height of the display in pixels. |
ttodorov | 0:881ff0b71102 | 318 | * \param CS Pin connected to the CS input of the display. |
ttodorov | 0:881ff0b71102 | 319 | * \param RS Pin connected to the RS input of the display. |
ttodorov | 0:881ff0b71102 | 320 | */ |
ttodorov | 0:881ff0b71102 | 321 | LCD( unsigned short width, unsigned short height ,PinName CS, PinName RS ); |
ttodorov | 0:881ff0b71102 | 322 | |
ttodorov | 0:881ff0b71102 | 323 | /** Sends a command to the display. |
ttodorov | 0:881ff0b71102 | 324 | * |
ttodorov | 0:881ff0b71102 | 325 | * \param cmd The display command. |
ttodorov | 0:881ff0b71102 | 326 | * \remarks Commands are controller-specific and this function needs to |
ttodorov | 0:881ff0b71102 | 327 | * be implemented separately for each available controller. |
ttodorov | 0:881ff0b71102 | 328 | */ |
ttodorov | 0:881ff0b71102 | 329 | virtual void writeCmd( unsigned short cmd ) = 0; |
ttodorov | 0:881ff0b71102 | 330 | |
ttodorov | 0:881ff0b71102 | 331 | /** Sends pixel data to the display. |
ttodorov | 0:881ff0b71102 | 332 | * |
ttodorov | 0:881ff0b71102 | 333 | * \param data The display data. |
ttodorov | 0:881ff0b71102 | 334 | * \remarks Sendin data is controller-specific and this function needs to |
ttodorov | 0:881ff0b71102 | 335 | * be implemented separately for each available controller. |
ttodorov | 0:881ff0b71102 | 336 | */ |
ttodorov | 0:881ff0b71102 | 337 | virtual void writeData( unsigned short data ) = 0; |
ttodorov | 0:881ff0b71102 | 338 | |
ttodorov | 0:881ff0b71102 | 339 | /** Sends both command and data to the display controller. |
ttodorov | 0:881ff0b71102 | 340 | * |
ttodorov | 0:881ff0b71102 | 341 | * This is a helper utility function which combines the 2 functions above |
ttodorov | 0:881ff0b71102 | 342 | * into one single convenience step. |
ttodorov | 0:881ff0b71102 | 343 | * |
ttodorov | 0:881ff0b71102 | 344 | * \param cmd The display command. |
ttodorov | 0:881ff0b71102 | 345 | * \param data The display pixel data. |
ttodorov | 0:881ff0b71102 | 346 | */ |
ttodorov | 0:881ff0b71102 | 347 | virtual void writeCmdData( unsigned short cmd, unsigned short data ); |
ttodorov | 0:881ff0b71102 | 348 | |
ttodorov | 0:881ff0b71102 | 349 | /** Assigns a chunk of the display memory to receive data. |
ttodorov | 0:881ff0b71102 | 350 | * |
ttodorov | 0:881ff0b71102 | 351 | * When data is sent to the display after this function completes, the opertion will |
ttodorov | 0:881ff0b71102 | 352 | * start from the begining of the assigned address (pixel position) and the pointer |
ttodorov | 0:881ff0b71102 | 353 | * will be automatically incremented so that the next data write operation will continue |
ttodorov | 0:881ff0b71102 | 354 | * with the next pixel from the memory block. If more data is written than available |
ttodorov | 0:881ff0b71102 | 355 | * pixels, at the end of the block the pointer will jump back to its beginning and |
ttodorov | 0:881ff0b71102 | 356 | * commence again, until the next address change command is sent to the display. |
ttodorov | 0:881ff0b71102 | 357 | * |
ttodorov | 0:881ff0b71102 | 358 | * \param x1 The X coordinate of the pixel at the beginning of the block. |
ttodorov | 0:881ff0b71102 | 359 | * \param y1 The Y coordinate of the pixel at the beginning of the block. |
ttodorov | 0:881ff0b71102 | 360 | * \param x2 The X coordinate of the pixel at the end of the block. |
ttodorov | 0:881ff0b71102 | 361 | * \param y2 The Y coordinate of the pixel at the end of the block. |
ttodorov | 0:881ff0b71102 | 362 | * \remarks Addressing commands are controller-specific and this function needs to be |
ttodorov | 0:881ff0b71102 | 363 | * implemented separately for each available controller. |
ttodorov | 0:881ff0b71102 | 364 | */ |
ttodorov | 0:881ff0b71102 | 365 | virtual void setXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ) = 0; |
ttodorov | 0:881ff0b71102 | 366 | |
ttodorov | 0:881ff0b71102 | 367 | /** Resets the memory address for the next display write operation to the screen origins (0,0). |
ttodorov | 0:881ff0b71102 | 368 | */ |
ttodorov | 0:881ff0b71102 | 369 | virtual void clearXY( void ); |
ttodorov | 0:881ff0b71102 | 370 | |
ttodorov | 0:881ff0b71102 | 371 | virtual void drawHLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 372 | virtual void drawVLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 ); |
ttodorov | 0:881ff0b71102 | 373 | virtual void printChar( char c, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1 ); |
ttodorov | 0:881ff0b71102 | 374 | 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 | 375 | |
ttodorov | 0:881ff0b71102 | 376 | protected: |
ttodorov | 0:881ff0b71102 | 377 | unsigned short _disp_width, _disp_height; |
ttodorov | 0:881ff0b71102 | 378 | DigitalOut _lcd_pin_cs, _lcd_pin_rs; |
ttodorov | 0:881ff0b71102 | 379 | orientation_t _orientation; |
ttodorov | 0:881ff0b71102 | 380 | unsigned short _foreground, _background; |
ttodorov | 0:881ff0b71102 | 381 | font_metrics_t _font; |
ttodorov | 0:881ff0b71102 | 382 | }; |
ttodorov | 0:881ff0b71102 | 383 | |
ttodorov | 0:881ff0b71102 | 384 | #endif /* LCD_BASE_H */ |