-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEADOG.h
385 lines (348 loc) · 9.97 KB
/
EADOG.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/* mbed library for the EA DOGM128 (128x64), DOGM132 (132x32), DOGL128 (128x64) pixel LCD
* use ST7565R controller
* Copyright (c) 2016 Stefan Staub
* Released under the MIT License: http://mbed.org/license/mit
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef EADOG_H
#define EADOG_H
#include "mbed.h"
/** display type
*
* @param DOGM128 128x64 2.3''
* @param DOGM132 132x32 2.1''
* @param DOGL128 128x64 2.8''
*
*/
enum {DOGM128, DOGM132, DOGL128};
/** update modes
*
* @param AUTO default
* @param MANUELL
*
*/
enum {MANUAL, AUTO};
/** display settings
*
* @param ON display on, default
* @param OFF display off
* @param SLEEP sets the display to sleep mode
* @param DEFAULT default
* @param INVERT inverts display
* @param BOTTOM default 0°
* @param TOPVIEW rotate the screento 180°
*
*/
enum {ON, OFF, SLEEP, DEFAULT, INVERT, BOTTOM, TOPVIEW, CONTRAST};
/** bitmap
*
*/
struct Bitmap {
int xSize;
int ySize;
int byte_in_Line;
char *data;
};
/** Library for the EADOG LCD displays from electronic assembly
*
* Example for EA DOGM132x-5 with STM32F401RE Nucleo
* @code
* // display test for EA DOGM132x-5 with STM32F401RE Nucleo
* // sstaub(c)2016
*
* #include "mbed.h"
* #include "EADOG.h"
* #include "Small_7.h"
* #include "Fonts/ArialR12x14.h"
*
* // DOGM132x-5 Wide Range
* // Pins for STM32F401RE Nucleo
*
* // DOG Pin Purpose ST Pin
* // 40 CS PB_6(D10)
* // 39 Reset PC_7(D9)
* // 38 A0 PA_9(D8)
* // 37 SCK PA_5(D13, SCK)
* // 36 MOSI PA_7(D11, MOSI)
* // 35 VDD 3.3V
* // 34 VDD2 3.3V
* // 33 VSS GND
* // 32 VOUT 1uF -> GND
* // 31 CAP3P 1uF -> CAP1N
* // 30 CAP1N 1uF -> CAP1P
* // 29 CAP1P
* // 28 CAP2P 1uF -> CAP2N
* // 27 CAP2N
* // 26 VSS GND
* // 25 V4 1uF -> GND
* // 24 V3 1uF -> GND
* // 23 V2 1uF -> GND
* // 22 V1 1uF -> GND
* // 21 V0 1uF -> GND
*
*
* EADOG lcd(PA_7, PA_5, PC_7, PA_9, PB_6, DOGM132); // MOSI, SCK, Reset, A0, CS
*
* int main() {
* // create logo
* lcd.update(MANUAL);
* lcd.rectangle(0, 0, 131, 31, 1);
* lcd.fillrect(2, 2, 4, 4, 1);
* lcd.fillrect(2, 27, 4, 29, 1);
* lcd.fillrect(61, 2, 63, 4, 1);
* lcd.fillrect(61, 27, 63, 29, 1);
* lcd.line(65, 0, 65, 31, 1);
* lcd.circle(33, 15, 10, 1);
* lcd.circle(33, 15, 6, 1);
* lcd.fillcircle(33, 15, 3, 1);
* lcd.update();
* lcd.update(AUTO);
* // create description text
* lcd.locate(70, 1);
* lcd.font((unsigned char*)ArialR12x14);
* lcd.printf("mbed");
* lcd.locate(70, 13);
* lcd.font((unsigned char*)Small_7);
* lcd.printf("EA");
* lcd.locate(70, 22);
* lcd.printf("DOGM132x-5");
*
* wait(1);
* lcd.display(CONTRAST, 16); // contrast low
* wait(1);
* lcd.display(CONTRAST, 40); // contrast high
* wait(1);
* lcd.display(CONTRAST); // contrast default
* wait(1);
* lcd.display(OFF); // display off
* wait(1);
* lcd.display(ON); // display on
* wait(1);
* lcd.display(SLEEP); // display sleep
* wait(1);
* lcd.display(ON); // display wake up
*
* while(1) { // main loop
* lcd.display(INVERT); // display inverted
* lcd.display(BOTTOM); // display normal orientation
* wait(2);
* lcd.display(DEFAULT); // display
* lcd.display(TOPVIEW); // display rotated
* wait(2);
* }
* }
* @endcode
*/
class EADOG : public Stream {
public:
/** create a EADOG object connected to SPI
*
* @param mosi pinname
* @param sck pinname
* @param reset pinname
* @param a0 pinname
* @param cs pinname
* @param type DOGM128, DOGM132, DOGL128
*
*/
EADOG(PinName mosi, PinName sck, PinName reset, PinName a0, PinName cs, uint8_t type);
/** draw a pixel in buffer at x, y black or white
*
* @param x horizontal position
* @param y vertical position
* @param colour 1 set pixel, 0 erase pixel
* there is no update, it writes the pixel only in the buffer
*/
void pixel(int x, int y, uint8_t colour);
/** draw a single point
*
* @param x horizontal position
* @param y vertical position
* @param colour 1 set pixel, 0 erase pixel
*
*/
void point(int x, int y, uint8_t colour);
/** draw a 1 pixel line
*
* @param x0,y0 start point
* @param x1,y1 end point
* @param color 1 set pixel, 0 erase pixel
*
*/
void line(int x0, int y0, int x1, int y1, uint8_t colour);
/** draw a rect
*
* @param x0,y0 top left corner
* @param x1,y1 down right corner
* @param color 1 set pixel, 0 erase pixel
*
*/
void rectangle(int x0, int y0, int x1, int y1, uint8_t colour);
/** draw a filled rect
*
* @param x0,y0 top left corner
* @param x1,y1 down right corner
* @param color 1 set pixel, 0 erase pixel
*
*/
void fillrect(int x0, int y0, int x1, int y1, uint8_t colour);
/** draw a rounded rect
*
* @param x0,y0 top left corner
* @param x1,y1 down right corner
* @param rnd radius of the rounding
* @param color 1 set pixel, 0 erase pixel
*
*/
void roundrect(int x0, int y0, int x1, int y1, int rnd, uint8_t colour);
/** draw a filled rounded rect
*
* @param x0,y0 top left corner
* @param x1,y1 down right corner
* @param rnd radius of the rounding
* @param color 1 set pixel, 0 erase pixel
*
*/
void fillrrect(int x0, int y0, int x1, int y1, int rnd, uint8_t colour);
/** draw a circle
*
* @param x0,y0 center
* @param r radius
* @param colour 1 set pixel, 0 erase pixel
*
*/
void circle(int x, int y, int r, uint8_t colour);
/** draw a filled circle
*
* @param x0,y0 center
* @param r radius
* @param color 1 set pixel, 0 erase pixel
*
* use circle with different radius,
* can miss some pixel
*
*/
void fillcircle(int x, int y, int r, uint8_t colour);
/** update copy display buffer to lcd
*
* @param AUTO set update mode to auto, default
* @param MANUELL the update function must manually set
* update() copy display buffer to lcd
*/
void update();
void update(uint8_t mode);
/** display functions
*
* @param display ON switch display on, or wake up from sleep
* @param display OFF set display off
* @param display SLEEP set display off and to sleep mode
* @param display BOTTOM (default) set display orientation 0°
* @param display TOPVIEW draw display oriention to 180°
* @param display INVERT invert the pixels
* @param display DEFAULT normal pixel display
* @param display CONTRAST set display contrast to default
*
*/
void display(uint8_t display);
/** display functions
*
* @param display CONTRAST set display contrast with value,
* @param value sets display contrast 0 - 63, default 31
*
*/
void display(uint8_t display, uint8_t value);
/** clear the screen
*
*/
void cls();
/** draw a character on given position out of the active font to the LCD
*
* @param x x-position of char (top left)
* @param y y-position
* @param c char to print
*
*/
void character(uint8_t x, uint8_t y, uint8_t c);
/** set top left position of char/printf
*
* @param x x-position
* @param y y-position
*
*/
void locate(uint8_t x, uint8_t y);
/** select the font to use
*
* @param f pointer to font array
*
* font array can created with GLCD Font Creator from http://www.mikroe.com
* you have to add 4 parameter at the beginning of the font array to use:
* - the number of byte / char
* - the vertial size in pixel
* - the horizontal size in pixel
* - the number of byte per vertical line
* you also have to change the array to char[]
* @code
* lcd.font((unsigned char*)Small_7);
* @endcode
*/
void font(uint8_t *f);
/** print bitmap to buffer
*
* @param bm Bitmap in flash
* @param x x start
* @param y y start
*
*/
void bitmap(Bitmap bm, int x, int y);
// declarations
SPI _spi;
DigitalOut _reset;
DigitalOut _a0;
DigitalOut _cs;
protected:
/** stream class, put a char on the screen
*
* @param value char to print
* @returns printed char
*
*/
virtual int _putc(int value);
/** stream class, dummy
*
*/
virtual int _getc();
/** init the DOGM132 LCD controller
*
*/
void init(); //Init the ST7565R LCD controller
/** write data to the LCD controller
*
* @param dat data written to LCD controller
*
*/
void write_data(uint8_t data); // Write data to the LCD controller
/** Write a command the LCD controller
*
* @param cmd command to be written
*
*/
void write_command(uint8_t command); // Write a command the LCD controller
// Variables
uint8_t *font_buffer;
uint8_t char_x;
uint8_t char_y;
uint8_t auto_update;
uint8_t width;
uint8_t height;
uint8_t _type;
uint8_t *graphic_buffer;
uint32_t graphic_buffer_size;
};
#endif