Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Termocamera_ironblack
GraphicsDisplay.h
00001 /* mbed GraphicsDisplay Display Library Base Class 00002 * Copyright (c) 2007-2009 sford 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 * 00005 * A library for providing a common base class for Graphics displays 00006 * To port a new display, derive from this class and implement 00007 * the constructor (setup the display), pixel (put a pixel 00008 * at a location), width and height functions. Everything else 00009 * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) 00010 * will come for free. You can also provide a specialised implementation 00011 * of window and putp to speed up the results 00012 */ 00013 00014 #ifndef MBED_GRAPHICSDISPLAY_H 00015 #define MBED_GRAPHICSDISPLAY_H 00016 00017 #include "TextDisplay.h" 00018 #include "Terminal6x8.h" 00019 00020 00021 00022 /* some RGB color definitions */ 00023 #define Black 0x0000 /* 0, 0, 0 */ 00024 #define Navy 0x000F /* 0, 0, 128 */ 00025 #define DarkGreen 0x03E0 /* 0, 128, 0 */ 00026 #define DarkCyan 0x03EF /* 0, 128, 128 */ 00027 #define Maroon 0x7800 /* 128, 0, 0 */ 00028 #define Purple 0x780F /* 128, 0, 128 */ 00029 #define Olive 0x7BE0 /* 128, 128, 0 */ 00030 #define LightGrey 0xC618 /* 192, 192, 192 */ 00031 #define DarkGrey 0x7BEF /* 128, 128, 128 */ 00032 #define Blue 0x001F /* 0, 0, 255 */ 00033 #define Green 0x07E0 /* 0, 255, 0 */ 00034 #define Cyan 0x07FF /* 0, 255, 255 */ 00035 #define Red 0xF800 /* 255, 0, 0 */ 00036 #define Magenta 0xF81F /* 255, 0, 255 */ 00037 #define Yellow 0xFFE0 /* 255, 255, 0 */ 00038 #define White 0xFFFF /* 255, 255, 255 */ 00039 #define Orange 0xFD20 /* 255, 165, 0 */ 00040 #define GreenYellow 0xAFE5 /* 173, 255, 47 */ 00041 00042 //Grey Scale color 00043 00044 00045 00046 00047 00048 #define color1 0x0000 00049 #define color2 0x0004 00050 #define color3 0x0006 00051 #define color4 0x0008 00052 #define color5 0x000A 00053 #define color6 0x000B 00054 #define color7 0x000C 00055 #define color8 0x000D 00056 #define color9 0x080E 00057 #define color10 0x080E 00058 #define color11 0x100F 00059 #define color12 0x1810 00060 #define color13 0x2010 00061 #define color14 0x2811 00062 #define color15 0x3011 00063 #define color16 0x3011 00064 #define color17 0x3812 00065 #define color18 0x4012 00066 #define color19 0x4812 00067 #define color20 0x4812 00068 #define color21 0x5013 00069 #define color22 0x5813 00070 #define color23 0x6013 00071 #define color24 0x6813 00072 #define color25 0x6813 00073 #define color26 0x7013 00074 #define color27 0x7813 00075 #define color28 0x8013 00076 #define color29 0x8013 00077 #define color30 0x8813 00078 #define color31 0x9013 00079 #define color32 0x9813 00080 #define color33 0x9813 00081 #define color34 0xA013 00082 #define color35 0xA013 00083 #define color36 0xA813 00084 #define color37 0xA813 00085 #define color38 0xB012 00086 #define color39 0xB012 00087 #define color40 0xB832 00088 #define color41 0xB832 00089 #define color42 0xB832 00090 #define color43 0xC052 00091 #define color44 0xC051 00092 #define color45 0xC071 00093 #define color46 0xC890 00094 #define color47 0xC8B0 00095 #define color48 0xC8AF 00096 #define color49 0xD0CF 00097 #define color50 0xD0EE 00098 #define color51 0xD10D 00099 #define color52 0xD12C 00100 #define color53 0xD94C 00101 #define color54 0xD96B 00102 #define color55 0xD989 00103 #define color56 0xD9A8 00104 #define color57 0xE1C6 00105 #define color58 0xE1E5 00106 #define color59 0xE203 00107 #define color60 0xE223 00108 #define color61 0xE242 00109 #define color62 0xEA62 00110 #define color63 0xEA61 00111 #define color64 0xEA81 00112 #define color65 0xEAA1 00113 #define color66 0xEAC0 00114 #define color67 0xEAE0 00115 #define color68 0xEB00 00116 #define color69 0xF320 00117 #define color70 0xF320 00118 #define color71 0xF340 00119 #define color72 0xF360 00120 #define color73 0xF380 00121 #define color74 0xF3A0 00122 #define color75 0xF3C0 00123 #define color76 0xF3E0 00124 #define color77 0xF400 00125 #define color78 0xF420 00126 #define color79 0xFC40 00127 #define color80 0xFC40 00128 #define color81 0xFC60 00129 #define color82 0xFC80 00130 #define color83 0xFCA0 00131 #define color84 0xFCC0 00132 #define color85 0xFCE0 00133 #define color86 0xFD00 00134 #define color87 0xFD40 00135 #define color88 0xFD60 00136 #define color89 0xFD80 00137 #define color90 0xFD80 00138 #define color91 0xFDC0 00139 #define color92 0xFDC0 00140 #define color93 0xFDE0 00141 #define color94 0xFE00 00142 #define color95 0xFE20 00143 #define color96 0xFE40 00144 #define color97 0xFE60 00145 #define color98 0xFE80 00146 #define color99 0xFEA1 00147 #define color100 0xFEC1 00148 #define color101 0xFEC1 00149 #define color102 0xFEE2 00150 #define color103 0xFF04 00151 #define color104 0xFF04 00152 #define color105 0xFF26 00153 #define color106 0xFF47 00154 #define color107 0xFF49 00155 #define color108 0xFF6B 00156 #define color109 0xFF6C 00157 #define color110 0xFF8E 00158 #define color111 0xFF90 00159 #define color112 0xFFB2 00160 #define color113 0xFFB4 00161 #define color114 0xFFB6 00162 #define color115 0xFFD8 00163 #define color116 0xFFD9 00164 #define color117 0xFFDB 00165 #define color118 0xFFFC 00166 #define color119 0xFFFD 00167 #define color120 0xFFFF 00168 00169 00170 00171 00172 00173 00174 /** Bitmap 00175 */ 00176 struct Bitmap_s{ 00177 int xSize; 00178 int ySize; 00179 int Byte_in_Line; 00180 char* data; 00181 }; 00182 00183 /** A common base class for Graphics displays 00184 */ 00185 class GraphicsDisplay : public TextDisplay { 00186 00187 public: 00188 00189 /** Create a GraphicsDisplay interface 00190 * @param name The name used by the parent class to access the interface 00191 */ 00192 GraphicsDisplay(const char* name); 00193 00194 ////// functions needing implementation in derived implementation class /////////////////////////////////////// 00195 ////// ---------------------------------------------------------------- /////////////////////////////////////// 00196 00197 /** Draw a pixel in the specified color. 00198 * @note this method must be supported in the derived class. 00199 * @param x is the horizontal offset to this pixel. 00200 * @param y is the vertical offset to this pixel. 00201 * @param color defines the color for the pixel. 00202 */ 00203 virtual void pixel(int x, int y, unsigned short color) = 0; 00204 00205 /** Set the window, which controls where items are written to the screen. 00206 * When something hits the window width, it wraps back to the left side 00207 * and down a row. If the initial write is outside the window, it will 00208 * be captured into the window when it crosses a boundary. 00209 * @param x is the left edge in pixels. 00210 * @param y is the top edge in pixels. 00211 * @param w is the window width in pixels. 00212 * @param h is the window height in pixels. 00213 * @note this method must be overridden in a derived class. 00214 */ 00215 virtual void window(int x, int y, int w, int h) = 0; 00216 00217 /** Push a single pixel into the window and increment position. 00218 * You may first call window() then push pixels in loop. 00219 * @param color is the pixel color. 00220 * @note this method must be overridden in a derived class. 00221 */ 00222 virtual void window_pushpixel(unsigned short color) = 0; 00223 00224 /** Push some pixels of the same color into the window and increment position. 00225 * You must first call window() then push pixels. 00226 * @param color is the pixel color. 00227 * @param count: how many 00228 */ 00229 virtual void window_pushpixel(unsigned short color, unsigned int count) = 0; 00230 00231 /** Push array of pixel colors into the window and increment position. 00232 * You must first call window() then push pixels. 00233 * @param color is the pixel color. 00234 */ 00235 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght) = 0; 00236 00237 /** If framebuffer is used, it needs to be sent to LCD from time to time 00238 @note this method must be overridden in a derived class. 00239 @note real function for LCD, dummy for TFT 00240 */ 00241 virtual void copy_to_lcd() = 0; 00242 00243 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// 00244 /////// ----------------------------------------------------/////////////////////////////////////////////////// 00245 00246 /** Set window to max possible size 00247 * May be overridden in a derived class. 00248 */ 00249 virtual void WindowMax(void); 00250 00251 /** clear the entire screen 00252 * Basically it sets windomax then fill with background color 00253 * May be overridden in a derived class. 00254 */ 00255 virtual void cls(); 00256 00257 /** draw a circle 00258 * 00259 * @param x0,y0 center 00260 * @param r radius 00261 * @param color 16 bit color * 00262 * 00263 */ 00264 virtual void circle(int x, int y, int r, unsigned short color); 00265 00266 /** draw a filled circle 00267 * 00268 * @param x0,y0 center 00269 * @param r radius 00270 * @param color 16 bit color * 00271 */ 00272 virtual void fillcircle(int x, int y, int r, unsigned short color); 00273 00274 00275 /** draw a 1 pixel line 00276 * 00277 * @param x0,y0 start point 00278 * @param x1,y1 stop point 00279 * @param color 16 bit color 00280 * 00281 */ 00282 virtual void line(int x0, int y0, int x1, int y1, unsigned short color); 00283 00284 /** draw a horizontal line 00285 * 00286 * @param x0 horizontal start 00287 * @param x1 horizontal stop 00288 * @param y vertical position 00289 * @param color 16 bit color 00290 * 00291 */ 00292 void hline(int x0, int x1, int y, unsigned short color); 00293 00294 /** draw a vertical line 00295 * 00296 * @param x horizontal position 00297 * @param y0 vertical start 00298 * @param y1 vertical stop 00299 * @param color 16 bit color 00300 */ 00301 void vline(int y0, int y1, int x, unsigned short color); 00302 00303 /** draw a rect 00304 * 00305 * @param x0,y0 top left corner 00306 * @param x1,y1 down right corner 00307 * @param color 16 bit color 00308 * * 00309 */ 00310 virtual void rect(int x0, int y0, int x1, int y1, unsigned short color); 00311 00312 /** draw a filled rect 00313 * 00314 * @param x0,y0 top left corner 00315 * @param x1,y1 down right corner 00316 * @param color 16 bit color 00317 * 00318 */ 00319 virtual void fillrect(int x0, int y0, int x1, int y1, unsigned short color); 00320 00321 /** setup cursor position for text 00322 * 00323 * @param x x-position (top left) 00324 * @param y y-position 00325 */ 00326 virtual void locate(int x, int y); 00327 00328 /** put a char on the screen 00329 * 00330 * @param value char to print 00331 * @returns printed char 00332 * 00333 */ 00334 virtual int _putc(int value); 00335 00336 /** draw a character on given position out of the active font to the TFT 00337 * 00338 * @param x x-position of char (top left) 00339 * @param y y-position 00340 * @param c char to print 00341 * 00342 */ 00343 virtual void character(int x, int y, int c); 00344 00345 /** paint a bitmap on the TFT 00346 * 00347 * @param x,y : upper left corner 00348 * @param w width of bitmap 00349 * @param h high of bitmap 00350 * @param *bitmap pointer to the bitmap data 00351 * 00352 * bitmap format: 16 bit R5 G6 B5 00353 * 00354 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00355 * use winhex to load this file and mark data stating at offset 0x46 to end 00356 * use edit -> copy block -> C Source to export C array 00357 * paste this array into your program 00358 * 00359 * define the array as static const unsigned char to put it into flash memory 00360 * cast the pointer to (unsigned char *) : 00361 * tft.Bitmap(10,40,309,50,(unsigned char *)scala); 00362 */ 00363 void Bitmap(int x, int y, int w, int h,unsigned char *bitmap); 00364 00365 /** paint monochrome bitmap to screen 00366 * 00367 * @param bm Bitmap in flash 00368 * @param x x start 00369 * @param y y start 00370 * 00371 */ 00372 void Bitmap_BW(Bitmap_s bm, int x, int y); 00373 00374 /** paint a 16 bit BMP from filesytem on the TFT (slow) 00375 * 00376 * @param x,y : position of upper left corner 00377 * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp" 00378 * 00379 * @returns 1 if bmp file was found and painted 00380 * @returns 0 if bmp file was found not found 00381 * @returns -1 if file is no bmp 00382 * @returns -2 if bmp file is no 16 bit bmp 00383 * @returns -3 if bmp file is to big for screen 00384 * @returns -4 if buffer malloc go wrong 00385 * 00386 * bitmap format: 16 bit R5 G6 B5 00387 * 00388 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00389 * copy to internal file system or SD card 00390 */ 00391 int BMP_16(int x, int y, const char *Name_BMP); 00392 00393 00394 00395 /** select the font to use 00396 * 00397 * @param f pointer to font array 00398 * @param firstascii first ascii code present in font array, default 32 (space) 00399 * @param lastascii last ascii code present in font array, default 127 (DEL) 00400 * @param proportional enable/disable variable font width (default enabled) 00401 * 00402 * font array can created with GLCD Font Creator from http://www.mikroe.com 00403 * you have to add 4 parameter at the beginning of the font array to use: 00404 * - the number of byte / char (not used in this revision, set to whatever) 00405 * - the vertial size in pixel 00406 * - the horizontal size in pixel 00407 * - the number of byte per vertical line (not used in this revision, set to whatever) 00408 * you also have to change the array to cont unsigned char[] and __align(2) 00409 * 00410 */ 00411 void set_font(unsigned char* f, unsigned char firstascii=32, unsigned char lastascii=127, bool proportional = true); 00412 00413 /** Zoom fount 00414 * 00415 * @param x_mul horizontal size multiplier 00416 * @param y_mul vertical size multiplier 00417 */ 00418 void set_font_zoom(unsigned char x_mul, unsigned char y_mul); 00419 00420 /** Get the number of columns based on the currently active font. 00421 * @returns number of columns. 00422 * @note this method may be overridden in a derived class. 00423 */ 00424 virtual int columns(); 00425 00426 /** Get the number of rows based on the currently active font. 00427 * @returns number of rows. 00428 * @note this method may be overridden in a derived class. 00429 */ 00430 virtual int rows(); 00431 00432 /** get the current oriented screen width in pixels 00433 * @returns screen width in pixels. 00434 */ 00435 int width(); 00436 00437 /** get the current oriented screen height in pixels 00438 * @returns screen height in pixels. 00439 */ 00440 int height(); 00441 00442 /** set the current oriented screen width in pixels 00443 * @param width screen width in pixels. 00444 */ 00445 void set_width(int width); 00446 00447 /** set the current oriented screen height in pixels 00448 * @param height screen height in pixels. 00449 */ 00450 void set_height(int height); 00451 00452 /** setup auto update of screen 00453 * 00454 * @param up 1 = on , 0 = off 00455 * if switched off the program has to call copy_to_lcd() 00456 * to update screen from framebuffer 00457 */ 00458 void set_auto_up(bool up); 00459 00460 /** get status of the auto update function 00461 * 00462 * @returns if auto update is on 00463 */ 00464 bool get_auto_up(void); 00465 00466 00467 00468 private: 00469 00470 unsigned char* font; 00471 // display width and height related to current orientation 00472 int oriented_width; 00473 int oriented_height; 00474 00475 // text char location 00476 int char_x; 00477 int char_y; 00478 00479 int fontoffset;// bytes / char (short) 00480 int fonthor; // hor size of font (char) 00481 int fontvert; // ver size of font (char) 00482 int fontbpl; // bytes per line (char) 00483 int fontzoomver; // size multiplier 00484 int fontzoomhor; // size multiplier 00485 unsigned char firstch; // first ascii code present in font array (usually 32) 00486 unsigned char lastch; // last ascii code present in font array (usually 127) 00487 bool auto_up; // autoupdate flag for LCD 00488 bool fontprop; 00489 00490 00491 }; 00492 00493 #endif
Generated on Wed Jul 13 2022 02:58:03 by
1.7.2