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