Fork of SSD1289 lib for Landtiger board
ssd1289.h@2:799c4fb113c5, 2012-11-22 (annotated)
- Committer:
- ttodorov
- Date:
- Thu Nov 22 08:42:01 2012 +0000
- Revision:
- 2:799c4fb113c5
- Parent:
- 1:f4f77e6729cd
- fixed constructor for redundant pin; - added doxygen comments, ready for publishing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ttodorov | 2:799c4fb113c5 | 1 | /** \file ssd1289.h |
ttodorov | 2:799c4fb113c5 | 2 | * \brief mbed TFT LCD library for displays with the SSD1289 LCD controller. |
ttodorov | 2:799c4fb113c5 | 3 | * |
ttodorov | 2:799c4fb113c5 | 4 | * A known display with this type of controller chip is the ITDB02-3.2S from |
ttodorov | 2:799c4fb113c5 | 5 | * http://imall.iteadstudio.com |
ttodorov | 2:799c4fb113c5 | 6 | * |
ttodorov | 2:799c4fb113c5 | 7 | * This library is based on the Arduino/chipKIT UTFT library by Henning |
ttodorov | 2:799c4fb113c5 | 8 | * Karlsen, http://henningkarlsen.com/electronics/library.php?id=52 |
ttodorov | 2:799c4fb113c5 | 9 | * |
ttodorov | 2:799c4fb113c5 | 10 | * Copyright (C)2010-2012 Henning Karlsen. All right reserved. |
ttodorov | 2:799c4fb113c5 | 11 | * Copyright (C)2012 Todor Todorov. |
ttodorov | 2:799c4fb113c5 | 12 | * |
ttodorov | 2:799c4fb113c5 | 13 | * This library is free software; you can redistribute it and/or |
ttodorov | 2:799c4fb113c5 | 14 | * modify it under the terms of the GNU Lesser General Public |
ttodorov | 2:799c4fb113c5 | 15 | * License as published by the Free Software Foundation; either |
ttodorov | 2:799c4fb113c5 | 16 | * version 2.1 of the License, or (at your option) any later version. |
ttodorov | 2:799c4fb113c5 | 17 | * |
ttodorov | 2:799c4fb113c5 | 18 | * This library is distributed in the hope that it will be useful, |
ttodorov | 2:799c4fb113c5 | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ttodorov | 2:799c4fb113c5 | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ttodorov | 2:799c4fb113c5 | 21 | * Lesser General Public License for more details. |
ttodorov | 2:799c4fb113c5 | 22 | * |
ttodorov | 2:799c4fb113c5 | 23 | * You should have received a copy of the GNU Lesser General Public |
ttodorov | 2:799c4fb113c5 | 24 | * License along with this library; if not, write to: |
ttodorov | 2:799c4fb113c5 | 25 | * |
ttodorov | 2:799c4fb113c5 | 26 | * Free Software Foundation, Inc. |
ttodorov | 2:799c4fb113c5 | 27 | * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA |
ttodorov | 2:799c4fb113c5 | 28 | * |
ttodorov | 2:799c4fb113c5 | 29 | *********************************************************************/ |
ttodorov | 2:799c4fb113c5 | 30 | |
ttodorov | 1:f4f77e6729cd | 31 | #ifndef SSD1289_H |
ttodorov | 0:d7202c9fc5db | 32 | #define SSD1289_H |
ttodorov | 0:d7202c9fc5db | 33 | |
ttodorov | 0:d7202c9fc5db | 34 | #include "mbed.h" |
ttodorov | 1:f4f77e6729cd | 35 | #include "fonts.h" |
ttodorov | 0:d7202c9fc5db | 36 | |
ttodorov | 2:799c4fb113c5 | 37 | /** \def RGB(r,g,b) |
ttodorov | 2:799c4fb113c5 | 38 | * \brief Creates a RGB-565 color value. |
ttodorov | 2:799c4fb113c5 | 39 | * |
ttodorov | 2:799c4fb113c5 | 40 | * Displays which use 16 bits to assign colors to a specific pixel, use |
ttodorov | 2:799c4fb113c5 | 41 | * 5 bits for the red component, 6 bits for the green component and 5 |
ttodorov | 2:799c4fb113c5 | 42 | * bits for the blue component. This macro converts the 3 full-size |
ttodorov | 2:799c4fb113c5 | 43 | * RGB bytes into one 16-bit RGB-565 value. |
ttodorov | 2:799c4fb113c5 | 44 | */ |
ttodorov | 1:f4f77e6729cd | 45 | #define RGB( r, g, b ) ( ( ( ( r ) & 248 ) | ( ( g ) >> 5 ) ) << 8 ) | ( ( ( ( g ) & 28 ) << 3 ) | ( ( b ) >> 3 ) ) |
ttodorov | 2:799c4fb113c5 | 46 | /** \def COLOR_BLACK |
ttodorov | 2:799c4fb113c5 | 47 | * \brief Shorthand for RGB( 0, 0, 0 ). |
ttodorov | 2:799c4fb113c5 | 48 | */ |
ttodorov | 1:f4f77e6729cd | 49 | #define COLOR_BLACK RGB( 0x00, 0x00, 0x00 ) |
ttodorov | 2:799c4fb113c5 | 50 | /** \def COLOR_WHITE |
ttodorov | 2:799c4fb113c5 | 51 | * \brief Shorthand for RGB( 255, 255, 255 ). |
ttodorov | 2:799c4fb113c5 | 52 | */ |
ttodorov | 1:f4f77e6729cd | 53 | #define COLOR_WHITE RGB( 0xFF, 0xFF, 0xFF ) |
ttodorov | 2:799c4fb113c5 | 54 | /** \def COLOR_RED |
ttodorov | 2:799c4fb113c5 | 55 | * \brief Shorthand for RGB( 255, 0, 0 ). |
ttodorov | 2:799c4fb113c5 | 56 | */ |
ttodorov | 1:f4f77e6729cd | 57 | #define COLOR_RED RGB( 0xFF, 0x00, 0x00 ) |
ttodorov | 2:799c4fb113c5 | 58 | /** \def COLOR_GREEN |
ttodorov | 2:799c4fb113c5 | 59 | * \brief Shorthand for RGB( 255, 255, 255 ). |
ttodorov | 2:799c4fb113c5 | 60 | */ |
ttodorov | 1:f4f77e6729cd | 61 | #define COLOR_GREEN RGB( 0x00, 0xFF, 0x00 ) |
ttodorov | 2:799c4fb113c5 | 62 | /** \def COLOR_BLIUE |
ttodorov | 2:799c4fb113c5 | 63 | * \brief Shorthand for RGB( 0, 255, 0 ). |
ttodorov | 2:799c4fb113c5 | 64 | */ |
ttodorov | 1:f4f77e6729cd | 65 | #define COLOR_BLIUE RGB( 0x00, 0x00, 0xFF ) |
ttodorov | 1:f4f77e6729cd | 66 | |
ttodorov | 2:799c4fb113c5 | 67 | /** \typedef orientation_t |
ttodorov | 2:799c4fb113c5 | 68 | * \brief Display orientation. |
ttodorov | 2:799c4fb113c5 | 69 | */ |
ttodorov | 1:f4f77e6729cd | 70 | typedef enum Orientation_enum |
ttodorov | 0:d7202c9fc5db | 71 | { |
ttodorov | 2:799c4fb113c5 | 72 | PORTRAIT = 0, /**< Display height is bigger than its width. */ |
ttodorov | 2:799c4fb113c5 | 73 | LANDSCAPE = 1, /**< Display width is bigger than its height. */ |
ttodorov | 0:d7202c9fc5db | 74 | } orientation_t; |
ttodorov | 0:d7202c9fc5db | 75 | |
ttodorov | 2:799c4fb113c5 | 76 | /** \typedef align_t |
ttodorov | 2:799c4fb113c5 | 77 | * \brief Horizontal text alignment on the line. |
ttodorov | 2:799c4fb113c5 | 78 | */ |
ttodorov | 1:f4f77e6729cd | 79 | typedef enum Alignment_enum |
ttodorov | 1:f4f77e6729cd | 80 | { |
ttodorov | 2:799c4fb113c5 | 81 | LEFT = 0, /**< Left-oriented, naturally gravitate closer to the left edge of the screen. */ |
ttodorov | 2:799c4fb113c5 | 82 | 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 | 2:799c4fb113c5 | 83 | 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 | 1:f4f77e6729cd | 84 | } align_t; |
ttodorov | 1:f4f77e6729cd | 85 | |
ttodorov | 2:799c4fb113c5 | 86 | /** \typedef font_metrics_t |
ttodorov | 2:799c4fb113c5 | 87 | * \brief Describes fonts and their properties. |
ttodorov | 2:799c4fb113c5 | 88 | * \sa Comments in fonts.h |
ttodorov | 2:799c4fb113c5 | 89 | */ |
ttodorov | 1:f4f77e6729cd | 90 | typedef struct Font_struct |
ttodorov | 0:d7202c9fc5db | 91 | { |
ttodorov | 2:799c4fb113c5 | 92 | const char* font; /**< A pointer to the first byte in the font. */ |
ttodorov | 2:799c4fb113c5 | 93 | unsigned char width; /**< The width of each character, in pixels. */ |
ttodorov | 2:799c4fb113c5 | 94 | unsigned char height; /**< Height of each character, in pixels. */ |
ttodorov | 2:799c4fb113c5 | 95 | unsigned char offset; /**< Offset of the first character in the font. */ |
ttodorov | 2:799c4fb113c5 | 96 | unsigned char numchars; /**< Count of the available characters in the font. */ |
ttodorov | 0:d7202c9fc5db | 97 | } font_metrics_t; |
ttodorov | 0:d7202c9fc5db | 98 | |
ttodorov | 2:799c4fb113c5 | 99 | /** \typedef bitmap_t |
ttodorov | 2:799c4fb113c5 | 100 | * \brief Pointer to the start of a block of pixel data, describing a picture. |
ttodorov | 2:799c4fb113c5 | 101 | */ |
ttodorov | 1:f4f77e6729cd | 102 | typedef unsigned short* bitmap_t; |
ttodorov | 1:f4f77e6729cd | 103 | |
ttodorov | 2:799c4fb113c5 | 104 | /** Represents a LCD instance. |
ttodorov | 2:799c4fb113c5 | 105 | * |
ttodorov | 2:799c4fb113c5 | 106 | * This is the utility class, through which the display can be manipulated |
ttodorov | 2:799c4fb113c5 | 107 | * and graphics objects can be shown to the user. A known display, which |
ttodorov | 2:799c4fb113c5 | 108 | * works with this library is the ITDB02-3.2S from iTeadStudio - a RGB TFT |
ttodorov | 2:799c4fb113c5 | 109 | * with 240x320 pixels resolution and 65K colors, using 16-bit interface. |
ttodorov | 2:799c4fb113c5 | 110 | * |
ttodorov | 2:799c4fb113c5 | 111 | * The display needs 20 or 21 pins to work with mbed, so it is possibly not |
ttodorov | 2:799c4fb113c5 | 112 | * the best of choices out there, but other than that it uses +3.3V for |
ttodorov | 2:799c4fb113c5 | 113 | * power and logic, as well as the backlight, thus can be interfaced directly |
ttodorov | 2:799c4fb113c5 | 114 | * to the mbed without the need of shields or level shifters as with Arduino. |
ttodorov | 2:799c4fb113c5 | 115 | * |
ttodorov | 2:799c4fb113c5 | 116 | * How to use: |
ttodorov | 2:799c4fb113c5 | 117 | * \code |
ttodorov | 2:799c4fb113c5 | 118 | * // include the library, this will also pull in the header for the provided fonts |
ttodorov | 2:799c4fb113c5 | 119 | * #include "ssd1289.h" |
ttodorov | 2:799c4fb113c5 | 120 | * |
ttodorov | 2:799c4fb113c5 | 121 | * // prepare the data bus for writing commands and pixel data |
ttodorov | 2:799c4fb113c5 | 122 | * BusOut dataBus( p30, p29, p28, p27, p26, p25, p24, p23, p22, p21, p20, p19, p18, p17, p16, p15 ); // 16 pins |
ttodorov | 2:799c4fb113c5 | 123 | * // create the lcd instance |
ttodorov | 2:799c4fb113c5 | 124 | * SSD1289 lcd( p14, p13, p12, p11, &dataBus ); // control pins and data bus |
ttodorov | 2:799c4fb113c5 | 125 | * |
ttodorov | 2:799c4fb113c5 | 126 | * int main() |
ttodorov | 2:799c4fb113c5 | 127 | * { |
ttodorov | 2:799c4fb113c5 | 128 | * // initialize display - place it in standard portrait mode and set background to black and |
ttodorov | 2:799c4fb113c5 | 129 | * // foreground to white color. |
ttodorov | 2:799c4fb113c5 | 130 | * lcd.Initialize(); |
ttodorov | 2:799c4fb113c5 | 131 | * // set current font to the smallest 8x12 pixels font. |
ttodorov | 2:799c4fb113c5 | 132 | * lcd.SetFont( Font8x12 ); |
ttodorov | 2:799c4fb113c5 | 133 | * // print something on the screen |
ttodorov | 2:799c4fb113c5 | 134 | * lcd.Print( "Hello, World!", CENTER, 25 ); // align text to center horizontally and use starndard colors |
ttodorov | 2:799c4fb113c5 | 135 | * |
ttodorov | 2:799c4fb113c5 | 136 | * while ( 1 ) { } |
ttodorov | 2:799c4fb113c5 | 137 | * } |
ttodorov | 2:799c4fb113c5 | 138 | * |
ttodorov | 2:799c4fb113c5 | 139 | * \endcode |
ttodorov | 2:799c4fb113c5 | 140 | */ |
ttodorov | 2:799c4fb113c5 | 141 | class SSD1289 |
ttodorov | 0:d7202c9fc5db | 142 | { |
ttodorov | 0:d7202c9fc5db | 143 | public: |
ttodorov | 2:799c4fb113c5 | 144 | /** Creates a new instance of the class. |
ttodorov | 2:799c4fb113c5 | 145 | * |
ttodorov | 2:799c4fb113c5 | 146 | * \param CS_PIN Pin for the ChipSelect signal. |
ttodorov | 2:799c4fb113c5 | 147 | * \param RESET_PIN Pin for the RESET line. |
ttodorov | 2:799c4fb113c5 | 148 | * \param RS_PIN Pin for the RS signal. |
ttodorov | 2:799c4fb113c5 | 149 | * \param WR_PIN Pin for the WR signal. |
ttodorov | 2:799c4fb113c5 | 150 | * \param DATA_PORT Address of the data bus for transfer of commands and pixel data. |
ttodorov | 2:799c4fb113c5 | 151 | * \param RD_PIN Pin for the RD signal. This line is not needed by the driver, so if you would like to |
ttodorov | 2:799c4fb113c5 | 152 | * use the pin on the mbed for something else, just pull-up the respective pin on the LCD high, |
ttodorov | 2:799c4fb113c5 | 153 | * and do not assign a value to this parameter when creating the controller instance. |
ttodorov | 2:799c4fb113c5 | 154 | */ |
ttodorov | 2:799c4fb113c5 | 155 | SSD1289( PinName CS_PIN, PinName RESET_PIN, PinName RS_PIN, PinName WR_PIN, BusOut* DATA_PORT, PinName RD_PIN = NC ); |
ttodorov | 2:799c4fb113c5 | 156 | |
ttodorov | 2:799c4fb113c5 | 157 | /** Initialize display. |
ttodorov | 2:799c4fb113c5 | 158 | * |
ttodorov | 2:799c4fb113c5 | 159 | * Wakes up the display from sleep, initializes power parameters. |
ttodorov | 2:799c4fb113c5 | 160 | * This function must be called first, befor any painting on the |
ttodorov | 2:799c4fb113c5 | 161 | * display is done, otherwise the positioning of graphical elements |
ttodorov | 2:799c4fb113c5 | 162 | * will not work properly and any paynt operation will not be visible |
ttodorov | 2:799c4fb113c5 | 163 | * or produce garbage. |
ttodorov | 2:799c4fb113c5 | 164 | * |
ttodorov | 2:799c4fb113c5 | 165 | * \param oritentation The display orientation, landscape is default. |
ttodorov | 2:799c4fb113c5 | 166 | */ |
ttodorov | 1:f4f77e6729cd | 167 | void Initialize( orientation_t orientation = LANDSCAPE ); |
ttodorov | 1:f4f77e6729cd | 168 | |
ttodorov | 2:799c4fb113c5 | 169 | /** Set the foreground color for painting. |
ttodorov | 2:799c4fb113c5 | 170 | * |
ttodorov | 2:799c4fb113c5 | 171 | * This is the default foreground color to be used in painting operations. |
ttodorov | 2:799c4fb113c5 | 172 | * If a specific output function allows for a different color to be specified |
ttodorov | 2:799c4fb113c5 | 173 | * in place, the new setting will be used for that single operation only and |
ttodorov | 2:799c4fb113c5 | 174 | * will not change this value. |
ttodorov | 2:799c4fb113c5 | 175 | * |
ttodorov | 2:799c4fb113c5 | 176 | * \param color The color to be used. The value must be in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 177 | * \sa #RGB(r,g,b) |
ttodorov | 2:799c4fb113c5 | 178 | */ |
ttodorov | 1:f4f77e6729cd | 179 | void SetForeground( unsigned short color = COLOR_WHITE ); |
ttodorov | 2:799c4fb113c5 | 180 | |
ttodorov | 2:799c4fb113c5 | 181 | /** Set the background color for painting. |
ttodorov | 2:799c4fb113c5 | 182 | * |
ttodorov | 2:799c4fb113c5 | 183 | * This is the default color to be used for "empty" pixels while painting. |
ttodorov | 2:799c4fb113c5 | 184 | * If a particular function allows for a different value to be specified |
ttodorov | 2:799c4fb113c5 | 185 | * when the function is called, the new value will be used only for this |
ttodorov | 2:799c4fb113c5 | 186 | * single call and will not change this setting. |
ttodorov | 2:799c4fb113c5 | 187 | * |
ttodorov | 2:799c4fb113c5 | 188 | * \param color The background color as RGB-565 value. |
ttodorov | 2:799c4fb113c5 | 189 | * \sa #RGB(r,g,b) |
ttodorov | 2:799c4fb113c5 | 190 | */ |
ttodorov | 1:f4f77e6729cd | 191 | void SetBackground( unsigned short color = COLOR_BLACK ); |
ttodorov | 2:799c4fb113c5 | 192 | |
ttodorov | 2:799c4fb113c5 | 193 | /** Sets the font to be used for painting of text on the screen. |
ttodorov | 2:799c4fb113c5 | 194 | * \param font A pointer to the font data. |
ttodorov | 2:799c4fb113c5 | 195 | * \sa Comments in file fonts.h |
ttodorov | 2:799c4fb113c5 | 196 | */ |
ttodorov | 1:f4f77e6729cd | 197 | void SetFont( const char* font ); |
ttodorov | 1:f4f77e6729cd | 198 | |
ttodorov | 2:799c4fb113c5 | 199 | /** Fills the whole screen with a single color. |
ttodorov | 2:799c4fb113c5 | 200 | * \param color The color to be used. The value must be in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 201 | * \remarks The special values -1 and -2 signify the preset background and foreground colors, respectively. |
ttodorov | 2:799c4fb113c5 | 202 | * The backround color is the default. |
ttodorov | 2:799c4fb113c5 | 203 | */ |
ttodorov | 1:f4f77e6729cd | 204 | void FillScreen( int color = -1 ); |
ttodorov | 2:799c4fb113c5 | 205 | |
ttodorov | 2:799c4fb113c5 | 206 | /** Clears the screen. |
ttodorov | 2:799c4fb113c5 | 207 | * |
ttodorov | 2:799c4fb113c5 | 208 | * This is the same as calling #FillScreen() or #FillScreen( -1 ) to use the background color. |
ttodorov | 2:799c4fb113c5 | 209 | */ |
ttodorov | 1:f4f77e6729cd | 210 | void ClearScreen( void ); |
ttodorov | 2:799c4fb113c5 | 211 | |
ttodorov | 2:799c4fb113c5 | 212 | /** Draws a pixel at the specified location. |
ttodorov | 2:799c4fb113c5 | 213 | * |
ttodorov | 2:799c4fb113c5 | 214 | * By default the function will use the preset foreground color, but the background |
ttodorov | 2:799c4fb113c5 | 215 | * or a custom color could be used as well. |
ttodorov | 2:799c4fb113c5 | 216 | * |
ttodorov | 2:799c4fb113c5 | 217 | * \param x The horizontal offset of the pixel from the upper left corner of the screen. |
ttodorov | 2:799c4fb113c5 | 218 | * \param y The vertical offset of the pixel from the upper left corner of the screen. |
ttodorov | 2:799c4fb113c5 | 219 | * \param color The color to be used. Must be in RGB-565 format, or -1 for background and -2 for foreground color. |
ttodorov | 2:799c4fb113c5 | 220 | */ |
ttodorov | 1:f4f77e6729cd | 221 | void DrawPixel( unsigned short x, unsigned short y, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 222 | |
ttodorov | 2:799c4fb113c5 | 223 | /** Draws a line. |
ttodorov | 2:799c4fb113c5 | 224 | * |
ttodorov | 2:799c4fb113c5 | 225 | * \param x1 Horizontal offset of the beginning point of the line. |
ttodorov | 2:799c4fb113c5 | 226 | * \param y1 Vertical offset of the beginning point of the line. |
ttodorov | 2:799c4fb113c5 | 227 | * \param x2 Horizontal offset of the end point of the line. |
ttodorov | 2:799c4fb113c5 | 228 | * \param y2 Verical offset of the end point of the line. |
ttodorov | 2:799c4fb113c5 | 229 | * \param color The color to use for painting, in RGB-565 format, or -1 for background, or -2 for foreground. |
ttodorov | 2:799c4fb113c5 | 230 | */ |
ttodorov | 1:f4f77e6729cd | 231 | void DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 232 | |
ttodorov | 2:799c4fb113c5 | 233 | /** Paints a rectangle. |
ttodorov | 2:799c4fb113c5 | 234 | * |
ttodorov | 2:799c4fb113c5 | 235 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 236 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 237 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 238 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 239 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 240 | */ |
ttodorov | 1:f4f77e6729cd | 241 | void DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 242 | |
ttodorov | 2:799c4fb113c5 | 243 | /** Paints a rectangle and fills it with the paint color. |
ttodorov | 2:799c4fb113c5 | 244 | * |
ttodorov | 2:799c4fb113c5 | 245 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 246 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 247 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 248 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 249 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 250 | */ |
ttodorov | 1:f4f77e6729cd | 251 | void DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 252 | |
ttodorov | 2:799c4fb113c5 | 253 | /** Paints a rectangle with rounded corners. |
ttodorov | 2:799c4fb113c5 | 254 | * |
ttodorov | 2:799c4fb113c5 | 255 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 256 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 257 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 258 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 259 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 260 | */ |
ttodorov | 1:f4f77e6729cd | 261 | void FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 262 | |
ttodorov | 2:799c4fb113c5 | 263 | /** Paints a rectangle with rounded corners and fills it with the paint color. |
ttodorov | 2:799c4fb113c5 | 264 | * |
ttodorov | 2:799c4fb113c5 | 265 | * \param x1 The horizontal offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 266 | * \param y1 The vertical offset of the beginning point of one of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 267 | * \param x2 The horizontal offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 268 | * \param y2 The vertical offset of the end point of the same of the rectangle's diagonals. |
ttodorov | 2:799c4fb113c5 | 269 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 270 | */ |
ttodorov | 1:f4f77e6729cd | 271 | void FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 272 | |
ttodorov | 2:799c4fb113c5 | 273 | /** Paints a circle. |
ttodorov | 2:799c4fb113c5 | 274 | * |
ttodorov | 2:799c4fb113c5 | 275 | * \param x The offset of the circle's center from the left edge of the screen. |
ttodorov | 2:799c4fb113c5 | 276 | * \param y The offset of the circle's center from the top edge of the screen. |
ttodorov | 2:799c4fb113c5 | 277 | * \param radius The circle's radius. |
ttodorov | 2:799c4fb113c5 | 278 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 279 | */ |
ttodorov | 1:f4f77e6729cd | 280 | void DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 281 | |
ttodorov | 2:799c4fb113c5 | 282 | /** Paints a circle and fills it with the paint color. |
ttodorov | 2:799c4fb113c5 | 283 | * |
ttodorov | 2:799c4fb113c5 | 284 | * \param x The offset of the circle's center from the left edge of the screen. |
ttodorov | 2:799c4fb113c5 | 285 | * \param y The offset of the circle's center from the top edge of the screen. |
ttodorov | 2:799c4fb113c5 | 286 | * \param radius The circle's radius. |
ttodorov | 2:799c4fb113c5 | 287 | * \param color The color to use for painting. -1 indicated background, -2 foreground, or custom color in RGB-565 format. |
ttodorov | 2:799c4fb113c5 | 288 | */ |
ttodorov | 1:f4f77e6729cd | 289 | void FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color = -2 ); |
ttodorov | 2:799c4fb113c5 | 290 | |
ttodorov | 2:799c4fb113c5 | 291 | /** Print a text on the screen. |
ttodorov | 2:799c4fb113c5 | 292 | * |
ttodorov | 2:799c4fb113c5 | 293 | * \param str The text. |
ttodorov | 2:799c4fb113c5 | 294 | * \param x The horizontal offset form the left edge of the screen. The special values LEFT, CENTER, |
ttodorov | 2:799c4fb113c5 | 295 | * or RIGHT can be used instead of pixel offset to indicate the text's horizontal alignment. |
ttodorov | 2:799c4fb113c5 | 296 | * \param y The vertical offset of the text from the top of the screen. |
ttodorov | 2:799c4fb113c5 | 297 | * \param fgColor The foreground to use for painting the text; -1 indicates background color, -2 the foreground setting, or custom color. |
ttodorov | 2:799c4fb113c5 | 298 | * \param bgColor The color to use for painting the empty pixels; -1 indicates the background color, -2 the foreground setting, or custom color. |
ttodorov | 2:799c4fb113c5 | 299 | * \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 | 2:799c4fb113c5 | 300 | */ |
ttodorov | 1:f4f77e6729cd | 301 | void Print( const char *str, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 ); |
ttodorov | 2:799c4fb113c5 | 302 | |
ttodorov | 2:799c4fb113c5 | 303 | /** Draw an image on the screen. |
ttodorov | 2:799c4fb113c5 | 304 | * |
ttodorov | 2:799c4fb113c5 | 305 | * The pixels of the picture must be in the RGB-565 format. The data can be provided |
ttodorov | 2:799c4fb113c5 | 306 | * as an array in a source or a header file. To convert an image file to the appropriate |
ttodorov | 2:799c4fb113c5 | 307 | * format, a special utility must be utilized. One such tool is provided by Henning Karlsen, |
ttodorov | 2:799c4fb113c5 | 308 | * the author of the UTFT display liberary and can be downloaded for free from his web site: |
ttodorov | 2:799c4fb113c5 | 309 | * http://henningkarlsen.com/electronics/library.php?id=52 |
ttodorov | 2:799c4fb113c5 | 310 | * |
ttodorov | 2:799c4fb113c5 | 311 | * \param x Horizontal offset of the first pixel of the image. |
ttodorov | 2:799c4fb113c5 | 312 | * \param y Vertical offset of the first pixel of the image |
ttodorov | 2:799c4fb113c5 | 313 | * \param sx Width of the image. |
ttodorov | 2:799c4fb113c5 | 314 | * \param sy Height of the image. |
ttodorov | 2:799c4fb113c5 | 315 | * \param data Image pixel array. |
ttodorov | 2:799c4fb113c5 | 316 | * \param scale A value of 1 will produce an image with its original size, while a different value will scale the image. |
ttodorov | 2:799c4fb113c5 | 317 | */ |
ttodorov | 1:f4f77e6729cd | 318 | void DrawBitmap( unsigned short x, unsigned short y, unsigned short sx, unsigned short sy, bitmap_t data, unsigned char scale = 1 ); |
ttodorov | 2:799c4fb113c5 | 319 | |
ttodorov | 2:799c4fb113c5 | 320 | /** Draw an image on the screen. |
ttodorov | 2:799c4fb113c5 | 321 | * |
ttodorov | 2:799c4fb113c5 | 322 | * The pixels of the picture must be in the RGB-565 format. The data can be provided |
ttodorov | 2:799c4fb113c5 | 323 | * as an array in a source or a header file. To convert an image file to the appropriate |
ttodorov | 2:799c4fb113c5 | 324 | * format, a special utility must be utilized. One such tool is provided by Henning Karlsen, |
ttodorov | 2:799c4fb113c5 | 325 | * the author of the UTFT display liberary and can be downloaded for free from his web site: |
ttodorov | 2:799c4fb113c5 | 326 | * http://henningkarlsen.com/electronics/library.php?id=52 |
ttodorov | 2:799c4fb113c5 | 327 | * |
ttodorov | 2:799c4fb113c5 | 328 | * \param x Horizontal offset of the first pixel of the image. |
ttodorov | 2:799c4fb113c5 | 329 | * \param y Vertical offset of the first pixel of the image |
ttodorov | 2:799c4fb113c5 | 330 | * \param sx Width of the image. |
ttodorov | 2:799c4fb113c5 | 331 | * \param sy Height of the image. |
ttodorov | 2:799c4fb113c5 | 332 | * \param data Image pixel array. |
ttodorov | 2:799c4fb113c5 | 333 | * \param deg Angle to rotate the image before painting on screen, in degrees. |
ttodorov | 2:799c4fb113c5 | 334 | * \param rox |
ttodorov | 2:799c4fb113c5 | 335 | * \param roy |
ttodorov | 2:799c4fb113c5 | 336 | */ |
ttodorov | 1:f4f77e6729cd | 337 | 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 | 1:f4f77e6729cd | 338 | |
ttodorov | 0:d7202c9fc5db | 339 | private: |
ttodorov | 2:799c4fb113c5 | 340 | DigitalOut _lcd_pin_cs, _lcd_pin_reset, _lcd_pin_rs, _lcd_pin_wr; |
ttodorov | 0:d7202c9fc5db | 341 | BusOut* _lcd_port; |
ttodorov | 2:799c4fb113c5 | 342 | DigitalOut* _lcd_pin_rd; |
ttodorov | 0:d7202c9fc5db | 343 | orientation_t _orientation; |
ttodorov | 1:f4f77e6729cd | 344 | static const long _disp_width = 239; |
ttodorov | 1:f4f77e6729cd | 345 | static const long _disp_height = 319; |
ttodorov | 1:f4f77e6729cd | 346 | unsigned short _foreground, _background; |
ttodorov | 1:f4f77e6729cd | 347 | font_metrics_t _font; |
ttodorov | 0:d7202c9fc5db | 348 | |
ttodorov | 0:d7202c9fc5db | 349 | private: |
ttodorov | 0:d7202c9fc5db | 350 | virtual void writeCmd( unsigned short cmd ); |
ttodorov | 0:d7202c9fc5db | 351 | virtual void writeData( unsigned short data ); |
ttodorov | 0:d7202c9fc5db | 352 | virtual void writeCmdData( unsigned short cmd, unsigned short data ); |
ttodorov | 1:f4f77e6729cd | 353 | |
ttodorov | 1:f4f77e6729cd | 354 | void setXY( uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2 ); |
ttodorov | 1:f4f77e6729cd | 355 | void clearXY( void ); |
ttodorov | 1:f4f77e6729cd | 356 | void drawHLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 ); |
ttodorov | 1:f4f77e6729cd | 357 | void drawVLine( unsigned short x, unsigned short y, unsigned short len, int color = -2 ); |
ttodorov | 1:f4f77e6729cd | 358 | |
ttodorov | 1:f4f77e6729cd | 359 | void printChar( char c, unsigned short x, unsigned short y, int fgColor = -2, int bgColor = -1 ); |
ttodorov | 1:f4f77e6729cd | 360 | void rotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor = -2, int bgColor = -1, unsigned short deg = 0 ); |
ttodorov | 0:d7202c9fc5db | 361 | }; |
ttodorov | 0:d7202c9fc5db | 362 | |
ttodorov | 0:d7202c9fc5db | 363 | #endif /* SSD1289_H */ |