Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.

Dependents:   afero_poc15_180216 afero_poc15_180223 afero_poc15_180302 afero_poc15_180403R ... more

Fork of UniGraphic by GraphicsDisplay

UniGraphic for La Suno Version.
To go with La Suno, WatchDog Reset functions were added in ILI9341.

Committer:
Geremia
Date:
Thu Feb 12 22:22:47 2015 +0000
Revision:
0:75ec1b3cde17
Child:
2:713844a55c4e
Initial tests, LCD par and spi ok

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Geremia 0:75ec1b3cde17 1 /* mbed GraphicsDisplay Display Library Base Class
Geremia 0:75ec1b3cde17 2 * Copyright (c) 2007-2009 sford
Geremia 0:75ec1b3cde17 3 * Released under the MIT License: http://mbed.org/license/mit
Geremia 0:75ec1b3cde17 4 *
Geremia 0:75ec1b3cde17 5 * A library for providing a common base class for Graphics displays
Geremia 0:75ec1b3cde17 6 * To port a new display, derive from this class and implement
Geremia 0:75ec1b3cde17 7 * the constructor (setup the display), pixel (put a pixel
Geremia 0:75ec1b3cde17 8 * at a location), width and height functions. Everything else
Geremia 0:75ec1b3cde17 9 * (locate, printf, putc, cls, window, putp, fill, blit, blitbit)
Geremia 0:75ec1b3cde17 10 * will come for free. You can also provide a specialised implementation
Geremia 0:75ec1b3cde17 11 * of window and putp to speed up the results
Geremia 0:75ec1b3cde17 12 */
Geremia 0:75ec1b3cde17 13
Geremia 0:75ec1b3cde17 14 #ifndef MBED_GRAPHICSDISPLAY_H
Geremia 0:75ec1b3cde17 15 #define MBED_GRAPHICSDISPLAY_H
Geremia 0:75ec1b3cde17 16
Geremia 0:75ec1b3cde17 17 #include "TextDisplay.h"
Geremia 0:75ec1b3cde17 18 #include "Terminal6x8.h"
Geremia 0:75ec1b3cde17 19
Geremia 0:75ec1b3cde17 20 /** Bitmap
Geremia 0:75ec1b3cde17 21 */
Geremia 0:75ec1b3cde17 22 struct Bitmap_s{
Geremia 0:75ec1b3cde17 23 int xSize;
Geremia 0:75ec1b3cde17 24 int ySize;
Geremia 0:75ec1b3cde17 25 int Byte_in_Line;
Geremia 0:75ec1b3cde17 26 char* data;
Geremia 0:75ec1b3cde17 27 };
Geremia 0:75ec1b3cde17 28
Geremia 0:75ec1b3cde17 29 /** A common base class for Graphics displays
Geremia 0:75ec1b3cde17 30 */
Geremia 0:75ec1b3cde17 31 class GraphicsDisplay : public TextDisplay {
Geremia 0:75ec1b3cde17 32
Geremia 0:75ec1b3cde17 33 public:
Geremia 0:75ec1b3cde17 34
Geremia 0:75ec1b3cde17 35 /** Create a GraphicsDisplay interface
Geremia 0:75ec1b3cde17 36 * @param name The name used by the parent class to access the interface
Geremia 0:75ec1b3cde17 37 */
Geremia 0:75ec1b3cde17 38 GraphicsDisplay(const char* name);
Geremia 0:75ec1b3cde17 39
Geremia 0:75ec1b3cde17 40 ////// functions needing implementation in derived implementation class ///////////////////////////////////////
Geremia 0:75ec1b3cde17 41 ////// ---------------------------------------------------------------- ///////////////////////////////////////
Geremia 0:75ec1b3cde17 42
Geremia 0:75ec1b3cde17 43 /** Draw a pixel in the specified color.
Geremia 0:75ec1b3cde17 44 * @note this method must be supported in the derived class.
Geremia 0:75ec1b3cde17 45 * @param x is the horizontal offset to this pixel.
Geremia 0:75ec1b3cde17 46 * @param y is the vertical offset to this pixel.
Geremia 0:75ec1b3cde17 47 * @param color defines the color for the pixel.
Geremia 0:75ec1b3cde17 48 */
Geremia 0:75ec1b3cde17 49 virtual void pixel(int x, int y, unsigned short color) = 0;
Geremia 0:75ec1b3cde17 50
Geremia 0:75ec1b3cde17 51
Geremia 0:75ec1b3cde17 52
Geremia 0:75ec1b3cde17 53
Geremia 0:75ec1b3cde17 54 /** Set the window, which controls where items are written to the screen.
Geremia 0:75ec1b3cde17 55 * When something hits the window width, it wraps back to the left side
Geremia 0:75ec1b3cde17 56 * and down a row. If the initial write is outside the window, it will
Geremia 0:75ec1b3cde17 57 * be captured into the window when it crosses a boundary.
Geremia 0:75ec1b3cde17 58 * @param x is the left edge in pixels.
Geremia 0:75ec1b3cde17 59 * @param y is the top edge in pixels.
Geremia 0:75ec1b3cde17 60 * @param w is the window width in pixels.
Geremia 0:75ec1b3cde17 61 * @param h is the window height in pixels.
Geremia 0:75ec1b3cde17 62 * @note this method must be overridden in a derived class.
Geremia 0:75ec1b3cde17 63 */
Geremia 0:75ec1b3cde17 64 virtual void window(int x, int y, int w, int h) = 0;
Geremia 0:75ec1b3cde17 65
Geremia 0:75ec1b3cde17 66 /** Push a single pixel into the window and increment position.
Geremia 0:75ec1b3cde17 67 * You may first call window() then push pixels in loop.
Geremia 0:75ec1b3cde17 68 * @param color is the pixel color.
Geremia 0:75ec1b3cde17 69 * @note this method must be overridden in a derived class.
Geremia 0:75ec1b3cde17 70 */
Geremia 0:75ec1b3cde17 71 virtual void window_pushpixel(unsigned short color) = 0;
Geremia 0:75ec1b3cde17 72
Geremia 0:75ec1b3cde17 73 /** If framebuffer is used, it needs to be sent to LCD from time to time
Geremia 0:75ec1b3cde17 74 @note this method must be overridden in a derived class.
Geremia 0:75ec1b3cde17 75 @note real function for LCD, dummy for TFT
Geremia 0:75ec1b3cde17 76 */
Geremia 0:75ec1b3cde17 77 virtual void copy_to_lcd() = 0;
Geremia 0:75ec1b3cde17 78
Geremia 0:75ec1b3cde17 79 /////// functions that come for free, but can be overwritten///////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 80 /////// ----------------------------------------------------///////////////////////////////////////////////////
Geremia 0:75ec1b3cde17 81
Geremia 0:75ec1b3cde17 82 /** Set window to max possible size
Geremia 0:75ec1b3cde17 83 * May be overridden in a derived class.
Geremia 0:75ec1b3cde17 84 */
Geremia 0:75ec1b3cde17 85 virtual void WindowMax(void);
Geremia 0:75ec1b3cde17 86
Geremia 0:75ec1b3cde17 87 /** clear the entire screen
Geremia 0:75ec1b3cde17 88 * Basically it sets windomax then fill with background color
Geremia 0:75ec1b3cde17 89 * May be overridden in a derived class.
Geremia 0:75ec1b3cde17 90 */
Geremia 0:75ec1b3cde17 91 virtual void cls();
Geremia 0:75ec1b3cde17 92
Geremia 0:75ec1b3cde17 93 /** draw a circle
Geremia 0:75ec1b3cde17 94 *
Geremia 0:75ec1b3cde17 95 * @param x0,y0 center
Geremia 0:75ec1b3cde17 96 * @param r radius
Geremia 0:75ec1b3cde17 97 * @param color 16 bit color *
Geremia 0:75ec1b3cde17 98 *
Geremia 0:75ec1b3cde17 99 */
Geremia 0:75ec1b3cde17 100 virtual void circle(int x, int y, int r, unsigned short color);
Geremia 0:75ec1b3cde17 101
Geremia 0:75ec1b3cde17 102 /** draw a filled circle
Geremia 0:75ec1b3cde17 103 *
Geremia 0:75ec1b3cde17 104 * @param x0,y0 center
Geremia 0:75ec1b3cde17 105 * @param r radius
Geremia 0:75ec1b3cde17 106 * @param color 16 bit color *
Geremia 0:75ec1b3cde17 107 */
Geremia 0:75ec1b3cde17 108 virtual void fillcircle(int x, int y, int r, unsigned short color);
Geremia 0:75ec1b3cde17 109
Geremia 0:75ec1b3cde17 110
Geremia 0:75ec1b3cde17 111 /** draw a 1 pixel line
Geremia 0:75ec1b3cde17 112 *
Geremia 0:75ec1b3cde17 113 * @param x0,y0 start point
Geremia 0:75ec1b3cde17 114 * @param x1,y1 stop point
Geremia 0:75ec1b3cde17 115 * @param color 16 bit color
Geremia 0:75ec1b3cde17 116 *
Geremia 0:75ec1b3cde17 117 */
Geremia 0:75ec1b3cde17 118 virtual void line(int x0, int y0, int x1, int y1, unsigned short color);
Geremia 0:75ec1b3cde17 119
Geremia 0:75ec1b3cde17 120 /** draw a horizontal line
Geremia 0:75ec1b3cde17 121 *
Geremia 0:75ec1b3cde17 122 * @param x0 horizontal start
Geremia 0:75ec1b3cde17 123 * @param x1 horizontal stop
Geremia 0:75ec1b3cde17 124 * @param y vertical position
Geremia 0:75ec1b3cde17 125 * @param color 16 bit color
Geremia 0:75ec1b3cde17 126 *
Geremia 0:75ec1b3cde17 127 */
Geremia 0:75ec1b3cde17 128 void hline(int x0, int x1, int y, unsigned short color);
Geremia 0:75ec1b3cde17 129
Geremia 0:75ec1b3cde17 130 /** draw a vertical line
Geremia 0:75ec1b3cde17 131 *
Geremia 0:75ec1b3cde17 132 * @param x horizontal position
Geremia 0:75ec1b3cde17 133 * @param y0 vertical start
Geremia 0:75ec1b3cde17 134 * @param y1 vertical stop
Geremia 0:75ec1b3cde17 135 * @param color 16 bit color
Geremia 0:75ec1b3cde17 136 */
Geremia 0:75ec1b3cde17 137 void vline(int y0, int y1, int x, unsigned short color);
Geremia 0:75ec1b3cde17 138
Geremia 0:75ec1b3cde17 139 /** draw a rect
Geremia 0:75ec1b3cde17 140 *
Geremia 0:75ec1b3cde17 141 * @param x0,y0 top left corner
Geremia 0:75ec1b3cde17 142 * @param x1,y1 down right corner
Geremia 0:75ec1b3cde17 143 * @param color 16 bit color
Geremia 0:75ec1b3cde17 144 * *
Geremia 0:75ec1b3cde17 145 */
Geremia 0:75ec1b3cde17 146 virtual void rect(int x0, int y0, int x1, int y1, unsigned short color);
Geremia 0:75ec1b3cde17 147
Geremia 0:75ec1b3cde17 148 /** draw a filled rect
Geremia 0:75ec1b3cde17 149 *
Geremia 0:75ec1b3cde17 150 * @param x0,y0 top left corner
Geremia 0:75ec1b3cde17 151 * @param x1,y1 down right corner
Geremia 0:75ec1b3cde17 152 * @param color 16 bit color
Geremia 0:75ec1b3cde17 153 *
Geremia 0:75ec1b3cde17 154 */
Geremia 0:75ec1b3cde17 155 virtual void fillrect(int x0, int y0, int x1, int y1, unsigned short color);
Geremia 0:75ec1b3cde17 156
Geremia 0:75ec1b3cde17 157 /** setup cursor position for text
Geremia 0:75ec1b3cde17 158 *
Geremia 0:75ec1b3cde17 159 * @param x x-position (top left)
Geremia 0:75ec1b3cde17 160 * @param y y-position
Geremia 0:75ec1b3cde17 161 */
Geremia 0:75ec1b3cde17 162 virtual void locate(int x, int y);
Geremia 0:75ec1b3cde17 163
Geremia 0:75ec1b3cde17 164 /** put a char on the screen
Geremia 0:75ec1b3cde17 165 *
Geremia 0:75ec1b3cde17 166 * @param value char to print
Geremia 0:75ec1b3cde17 167 * @returns printed char
Geremia 0:75ec1b3cde17 168 *
Geremia 0:75ec1b3cde17 169 */
Geremia 0:75ec1b3cde17 170 virtual int _putc(int value);
Geremia 0:75ec1b3cde17 171
Geremia 0:75ec1b3cde17 172 /** draw a character on given position out of the active font to the TFT
Geremia 0:75ec1b3cde17 173 *
Geremia 0:75ec1b3cde17 174 * @param x x-position of char (top left)
Geremia 0:75ec1b3cde17 175 * @param y y-position
Geremia 0:75ec1b3cde17 176 * @param c char to print
Geremia 0:75ec1b3cde17 177 *
Geremia 0:75ec1b3cde17 178 */
Geremia 0:75ec1b3cde17 179 virtual void character(int x, int y, int c);
Geremia 0:75ec1b3cde17 180
Geremia 0:75ec1b3cde17 181 /** paint a bitmap on the TFT
Geremia 0:75ec1b3cde17 182 *
Geremia 0:75ec1b3cde17 183 * @param x,y : upper left corner
Geremia 0:75ec1b3cde17 184 * @param w width of bitmap
Geremia 0:75ec1b3cde17 185 * @param h high of bitmap
Geremia 0:75ec1b3cde17 186 * @param *bitmap pointer to the bitmap data
Geremia 0:75ec1b3cde17 187 *
Geremia 0:75ec1b3cde17 188 * bitmap format: 16 bit R5 G6 B5
Geremia 0:75ec1b3cde17 189 *
Geremia 0:75ec1b3cde17 190 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
Geremia 0:75ec1b3cde17 191 * use winhex to load this file and mark data stating at offset 0x46 to end
Geremia 0:75ec1b3cde17 192 * use edit -> copy block -> C Source to export C array
Geremia 0:75ec1b3cde17 193 * paste this array into your program
Geremia 0:75ec1b3cde17 194 *
Geremia 0:75ec1b3cde17 195 * define the array as static const unsigned char to put it into flash memory
Geremia 0:75ec1b3cde17 196 * cast the pointer to (unsigned char *) :
Geremia 0:75ec1b3cde17 197 * tft.Bitmap(10,40,309,50,(unsigned char *)scala);
Geremia 0:75ec1b3cde17 198 */
Geremia 0:75ec1b3cde17 199 void Bitmap(int x, int y, int w, int h,unsigned char *bitmap);
Geremia 0:75ec1b3cde17 200
Geremia 0:75ec1b3cde17 201 /** paint monochrome bitmap to screen
Geremia 0:75ec1b3cde17 202 *
Geremia 0:75ec1b3cde17 203 * @param bm Bitmap in flash
Geremia 0:75ec1b3cde17 204 * @param x x start
Geremia 0:75ec1b3cde17 205 * @param y y start
Geremia 0:75ec1b3cde17 206 *
Geremia 0:75ec1b3cde17 207 */
Geremia 0:75ec1b3cde17 208 void Bitmap_BW(Bitmap_s bm, int x, int y);
Geremia 0:75ec1b3cde17 209
Geremia 0:75ec1b3cde17 210 /** paint a 16 bit BMP from filesytem on the TFT (slow)
Geremia 0:75ec1b3cde17 211 *
Geremia 0:75ec1b3cde17 212 * @param x,y : position of upper left corner
Geremia 0:75ec1b3cde17 213 * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp"
Geremia 0:75ec1b3cde17 214 *
Geremia 0:75ec1b3cde17 215 * @returns 1 if bmp file was found and painted
Geremia 0:75ec1b3cde17 216 * @returns 0 if bmp file was found not found
Geremia 0:75ec1b3cde17 217 * @returns -1 if file is no bmp
Geremia 0:75ec1b3cde17 218 * @returns -2 if bmp file is no 16 bit bmp
Geremia 0:75ec1b3cde17 219 * @returns -3 if bmp file is to big for screen
Geremia 0:75ec1b3cde17 220 * @returns -4 if buffer malloc go wrong
Geremia 0:75ec1b3cde17 221 *
Geremia 0:75ec1b3cde17 222 * bitmap format: 16 bit R5 G6 B5
Geremia 0:75ec1b3cde17 223 *
Geremia 0:75ec1b3cde17 224 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
Geremia 0:75ec1b3cde17 225 * copy to internal file system or SD card
Geremia 0:75ec1b3cde17 226 */
Geremia 0:75ec1b3cde17 227 int BMP_16(int x, int y, const char *Name_BMP);
Geremia 0:75ec1b3cde17 228
Geremia 0:75ec1b3cde17 229
Geremia 0:75ec1b3cde17 230
Geremia 0:75ec1b3cde17 231 /** select the font to use
Geremia 0:75ec1b3cde17 232 *
Geremia 0:75ec1b3cde17 233 * @param f pointer to font array
Geremia 0:75ec1b3cde17 234 * @param firstascii first ascii code present in font array, default 32 (space)
Geremia 0:75ec1b3cde17 235 * @param lastascii last ascii code present in font array, default 127 (DEL)
Geremia 0:75ec1b3cde17 236 *
Geremia 0:75ec1b3cde17 237 * font array can created with GLCD Font Creator from http://www.mikroe.com
Geremia 0:75ec1b3cde17 238 * you have to add 4 parameter at the beginning of the font array to use:
Geremia 0:75ec1b3cde17 239 * - the number of byte / char (not used in this revision, set to whatever)
Geremia 0:75ec1b3cde17 240 * - the vertial size in pixel
Geremia 0:75ec1b3cde17 241 * - the horizontal size in pixel
Geremia 0:75ec1b3cde17 242 * - the number of byte per vertical line (not used in this revision, set to whatever)
Geremia 0:75ec1b3cde17 243 * you also have to change the array to cont unsigned char[] and __align(2)
Geremia 0:75ec1b3cde17 244 *
Geremia 0:75ec1b3cde17 245 */
Geremia 0:75ec1b3cde17 246 void set_font(unsigned char* f, unsigned char firstascii=32, unsigned char lastascii=127);
Geremia 0:75ec1b3cde17 247
Geremia 0:75ec1b3cde17 248 /** Get the number of columns based on the currently active font.
Geremia 0:75ec1b3cde17 249 * @returns number of columns.
Geremia 0:75ec1b3cde17 250 * @note this method may be overridden in a derived class.
Geremia 0:75ec1b3cde17 251 */
Geremia 0:75ec1b3cde17 252 virtual int columns();
Geremia 0:75ec1b3cde17 253
Geremia 0:75ec1b3cde17 254 /** Get the number of rows based on the currently active font.
Geremia 0:75ec1b3cde17 255 * @returns number of rows.
Geremia 0:75ec1b3cde17 256 * @note this method may be overridden in a derived class.
Geremia 0:75ec1b3cde17 257 */
Geremia 0:75ec1b3cde17 258 virtual int rows();
Geremia 0:75ec1b3cde17 259
Geremia 0:75ec1b3cde17 260 /** get the current oriented screen width in pixels
Geremia 0:75ec1b3cde17 261 * @returns screen width in pixels.
Geremia 0:75ec1b3cde17 262 */
Geremia 0:75ec1b3cde17 263 int width();
Geremia 0:75ec1b3cde17 264
Geremia 0:75ec1b3cde17 265 /** get the current oriented screen height in pixels
Geremia 0:75ec1b3cde17 266 * @returns screen height in pixels.
Geremia 0:75ec1b3cde17 267 */
Geremia 0:75ec1b3cde17 268 int height();
Geremia 0:75ec1b3cde17 269
Geremia 0:75ec1b3cde17 270 /** set the current oriented screen width in pixels
Geremia 0:75ec1b3cde17 271 * @param width screen width in pixels.
Geremia 0:75ec1b3cde17 272 */
Geremia 0:75ec1b3cde17 273 void set_width(int width);
Geremia 0:75ec1b3cde17 274
Geremia 0:75ec1b3cde17 275 /** set the current oriented screen height in pixels
Geremia 0:75ec1b3cde17 276 * @param height screen height in pixels.
Geremia 0:75ec1b3cde17 277 */
Geremia 0:75ec1b3cde17 278 void set_height(int height);
Geremia 0:75ec1b3cde17 279
Geremia 0:75ec1b3cde17 280
Geremia 0:75ec1b3cde17 281 protected:
Geremia 0:75ec1b3cde17 282
Geremia 0:75ec1b3cde17 283
Geremia 0:75ec1b3cde17 284
Geremia 0:75ec1b3cde17 285 bool auto_up; // autoupdate flag for LCD
Geremia 0:75ec1b3cde17 286
Geremia 0:75ec1b3cde17 287
Geremia 0:75ec1b3cde17 288
Geremia 0:75ec1b3cde17 289 private:
Geremia 0:75ec1b3cde17 290
Geremia 0:75ec1b3cde17 291 unsigned char* font;
Geremia 0:75ec1b3cde17 292 // display width and height related to current orientation
Geremia 0:75ec1b3cde17 293 int oriented_width;
Geremia 0:75ec1b3cde17 294 int oriented_height;
Geremia 0:75ec1b3cde17 295
Geremia 0:75ec1b3cde17 296 // text char location
Geremia 0:75ec1b3cde17 297 int char_x;
Geremia 0:75ec1b3cde17 298 int char_y;
Geremia 0:75ec1b3cde17 299
Geremia 0:75ec1b3cde17 300 int fontoffset;// bytes / char (short)
Geremia 0:75ec1b3cde17 301 int fonthor; // hor size of font (char)
Geremia 0:75ec1b3cde17 302 int fontvert; // ver size of font (char)
Geremia 0:75ec1b3cde17 303 int fontbpl; // bytes per line (char)
Geremia 0:75ec1b3cde17 304 unsigned char firstch; // first ascii code present in font array (usually 32)
Geremia 0:75ec1b3cde17 305 unsigned char lastch; // last ascii code present in font array (usually 127)
Geremia 0:75ec1b3cde17 306
Geremia 0:75ec1b3cde17 307
Geremia 0:75ec1b3cde17 308
Geremia 0:75ec1b3cde17 309
Geremia 0:75ec1b3cde17 310 };
Geremia 0:75ec1b3cde17 311
Geremia 0:75ec1b3cde17 312 #endif