30 #include <mraa/aio.hpp>
31 #include <mraa/common.hpp>
33 #include <mraa/gpio.hpp>
35 #include <mraa/spi.hpp>
38 #define INITR_GREENTAB 0x0
39 #define INITR_REDTAB 0x1
40 #define INITR_BLACKTAB 0x2
42 #define ST7735_TFTWIDTH 128
43 #define ST7735_TFTHEIGHT 160
45 #define ST7735_NOP 0x00
46 #define ST7735_SWRESET 0x01
47 #define ST7735_RDDID 0x04
48 #define ST7735_RDDST 0x09
50 #define ST7735_SLPIN 0x10
51 #define ST7735_SLPOUT 0x11
52 #define ST7735_PTLON 0x12
53 #define ST7735_NORON 0x13
55 #define ST7735_INVOFF 0x20
56 #define ST7735_INVON 0x21
57 #define ST7735_DISPOFF 0x28
58 #define ST7735_DISPON 0x29
59 #define ST7735_CASET 0x2A
60 #define ST7735_RASET 0x2B
61 #define ST7735_RAMWR 0x2C
62 #define ST7735_RAMRD 0x2E
64 #define ST7735_PTLAR 0x30
65 #define ST7735_COLMOD 0x3A
66 #define ST7735_MADCTL 0x36
68 #define ST7735_FRMCTR1 0xB1
69 #define ST7735_FRMCTR2 0xB2
70 #define ST7735_FRMCTR3 0xB3
71 #define ST7735_INVCTR 0xB4
72 #define ST7735_DISSET5 0xB6
74 #define ST7735_PWCTR1 0xC0
75 #define ST7735_PWCTR2 0xC1
76 #define ST7735_PWCTR3 0xC2
77 #define ST7735_PWCTR4 0xC3
78 #define ST7735_PWCTR5 0xC4
79 #define ST7735_VMCTR1 0xC5
81 #define ST7735_RDID1 0xDA
82 #define ST7735_RDID2 0xDB
83 #define ST7735_RDID3 0xDC
84 #define ST7735_RDID4 0xDD
86 #define ST7735_PWCTR6 0xFC
88 #define ST7735_GMCTRP1 0xE0
89 #define ST7735_GMCTRN1 0xE1
92 #define ST7735_BLACK 0x0000
93 #define ST7735_BLUE 0x001F
94 #define ST7735_RED 0xF800
95 #define ST7735_GREEN 0x07E0
96 #define ST7735_CYAN 0x07FF
97 #define ST7735_MAGENTA 0xF81F
98 #define ST7735_YELLOW 0xFFE0
99 #define ST7735_WHITE 0xFFFF
108 static const uint8_t Bcmd[] = {
111 ST7735_SWRESET, DELAY,
113 ST7735_SLPOUT , DELAY,
115 ST7735_COLMOD , 1+DELAY,
118 ST7735_FRMCTR1, 3+DELAY,
131 ST7735_PWCTR1 , 2+DELAY,
140 ST7735_VMCTR1 , 2+DELAY,
147 0x09, 0x16, 0x09, 0x20,
148 0x21, 0x1B, 0x13, 0x19,
149 0x17, 0x15, 0x1E, 0x2B,
150 0x04, 0x05, 0x02, 0x0E,
151 ST7735_GMCTRN1,16+DELAY,
152 0x0B, 0x14, 0x08, 0x1E,
153 0x22, 0x1D, 0x18, 0x1E,
154 0x1B, 0x1A, 0x24, 0x2B,
155 0x06, 0x06, 0x02, 0x0F,
163 ST7735_NORON , DELAY,
165 ST7735_DISPON , DELAY,
170 ST7735_SWRESET, DELAY,
172 ST7735_SLPOUT , DELAY,
225 0x02, 0x1c, 0x07, 0x12,
226 0x37, 0x32, 0x29, 0x2d,
227 0x29, 0x25, 0x2B, 0x39,
228 0x00, 0x01, 0x03, 0x10,
230 0x03, 0x1d, 0x07, 0x06,
231 0x2E, 0x2C, 0x29, 0x2D,
232 0x2E, 0x2E, 0x37, 0x3F,
233 0x00, 0x00, 0x02, 0x10,
234 ST7735_NORON , DELAY,
236 ST7735_DISPON , DELAY,
239 #define swap(a, b) { int16_t t = a; a = b; b = t; }
241 const unsigned char font[] = {
242 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
244 0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
245 0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
246 0x18, 0x3C, 0x7E, 0x3C, 0x18,
247 0x1C, 0x57, 0x7D, 0x57, 0x1C,
248 0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
249 0x00, 0x18, 0x3C, 0x18, 0x00,
250 0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
251 0x00, 0x18, 0x24, 0x18, 0x00,
252 0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
253 0x30, 0x48, 0x3A, 0x06, 0x0E,
254 0x26, 0x29, 0x79, 0x29, 0x26,
255 0x40, 0x7F, 0x05, 0x05, 0x07,
256 0x40, 0x7F, 0x05, 0x25, 0x3F,
257 0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
258 0x7F, 0x3E, 0x1C, 0x1C, 0x08,
259 0x08, 0x1C, 0x1C, 0x3E, 0x7F,
260 0x14, 0x22, 0x7F, 0x22, 0x14,
261 0x5F, 0x5F, 0x00, 0x5F, 0x5F,
262 0x06, 0x09, 0x7F, 0x01, 0x7F,
263 0x00, 0x66, 0x89, 0x95, 0x6A,
264 0x60, 0x60, 0x60, 0x60, 0x60,
265 0x94, 0xA2, 0xFF, 0xA2, 0x94,
266 0x08, 0x04, 0x7E, 0x04, 0x08,
267 0x10, 0x20, 0x7E, 0x20, 0x10,
268 0x08, 0x08, 0x2A, 0x1C, 0x08,
269 0x08, 0x1C, 0x2A, 0x08, 0x08,
270 0x1E, 0x10, 0x10, 0x10, 0x10,
271 0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
272 0x30, 0x38, 0x3E, 0x38, 0x30,
273 0x06, 0x0E, 0x3E, 0x0E, 0x06,
274 0x00, 0x00, 0x00, 0x00, 0x00,
275 0x00, 0x00, 0x5F, 0x00, 0x00,
276 0x00, 0x07, 0x00, 0x07, 0x00,
277 0x14, 0x7F, 0x14, 0x7F, 0x14,
278 0x24, 0x2A, 0x7F, 0x2A, 0x12,
279 0x23, 0x13, 0x08, 0x64, 0x62,
280 0x36, 0x49, 0x56, 0x20, 0x50,
281 0x00, 0x08, 0x07, 0x03, 0x00,
282 0x00, 0x1C, 0x22, 0x41, 0x00,
283 0x00, 0x41, 0x22, 0x1C, 0x00,
284 0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
285 0x08, 0x08, 0x3E, 0x08, 0x08,
286 0x00, 0x80, 0x70, 0x30, 0x00,
287 0x08, 0x08, 0x08, 0x08, 0x08,
288 0x00, 0x00, 0x60, 0x60, 0x00,
289 0x20, 0x10, 0x08, 0x04, 0x02,
290 0x3E, 0x51, 0x49, 0x45, 0x3E,
291 0x00, 0x42, 0x7F, 0x40, 0x00,
292 0x72, 0x49, 0x49, 0x49, 0x46,
293 0x21, 0x41, 0x49, 0x4D, 0x33,
294 0x18, 0x14, 0x12, 0x7F, 0x10,
295 0x27, 0x45, 0x45, 0x45, 0x39,
296 0x3C, 0x4A, 0x49, 0x49, 0x31,
297 0x41, 0x21, 0x11, 0x09, 0x07,
298 0x36, 0x49, 0x49, 0x49, 0x36,
299 0x46, 0x49, 0x49, 0x29, 0x1E,
300 0x00, 0x00, 0x14, 0x00, 0x00,
301 0x00, 0x40, 0x34, 0x00, 0x00,
302 0x00, 0x08, 0x14, 0x22, 0x41,
303 0x14, 0x14, 0x14, 0x14, 0x14,
304 0x00, 0x41, 0x22, 0x14, 0x08,
305 0x02, 0x01, 0x59, 0x09, 0x06,
306 0x3E, 0x41, 0x5D, 0x59, 0x4E,
307 0x7C, 0x12, 0x11, 0x12, 0x7C,
308 0x7F, 0x49, 0x49, 0x49, 0x36,
309 0x3E, 0x41, 0x41, 0x41, 0x22,
310 0x7F, 0x41, 0x41, 0x41, 0x3E,
311 0x7F, 0x49, 0x49, 0x49, 0x41,
312 0x7F, 0x09, 0x09, 0x09, 0x01,
313 0x3E, 0x41, 0x41, 0x51, 0x73,
314 0x7F, 0x08, 0x08, 0x08, 0x7F,
315 0x00, 0x41, 0x7F, 0x41, 0x00,
316 0x20, 0x40, 0x41, 0x3F, 0x01,
317 0x7F, 0x08, 0x14, 0x22, 0x41,
318 0x7F, 0x40, 0x40, 0x40, 0x40,
319 0x7F, 0x02, 0x1C, 0x02, 0x7F,
320 0x7F, 0x04, 0x08, 0x10, 0x7F,
321 0x3E, 0x41, 0x41, 0x41, 0x3E,
322 0x7F, 0x09, 0x09, 0x09, 0x06,
323 0x3E, 0x41, 0x51, 0x21, 0x5E,
324 0x7F, 0x09, 0x19, 0x29, 0x46,
325 0x26, 0x49, 0x49, 0x49, 0x32,
326 0x03, 0x01, 0x7F, 0x01, 0x03,
327 0x3F, 0x40, 0x40, 0x40, 0x3F,
328 0x1F, 0x20, 0x40, 0x20, 0x1F,
329 0x3F, 0x40, 0x38, 0x40, 0x3F,
330 0x63, 0x14, 0x08, 0x14, 0x63,
331 0x03, 0x04, 0x78, 0x04, 0x03,
332 0x61, 0x59, 0x49, 0x4D, 0x43,
333 0x00, 0x7F, 0x41, 0x41, 0x41,
334 0x02, 0x04, 0x08, 0x10, 0x20,
335 0x00, 0x41, 0x41, 0x41, 0x7F,
336 0x04, 0x02, 0x01, 0x02, 0x04,
337 0x40, 0x40, 0x40, 0x40, 0x40,
338 0x00, 0x03, 0x07, 0x08, 0x00,
339 0x20, 0x54, 0x54, 0x78, 0x40,
340 0x7F, 0x28, 0x44, 0x44, 0x38,
341 0x38, 0x44, 0x44, 0x44, 0x28,
342 0x38, 0x44, 0x44, 0x28, 0x7F,
343 0x38, 0x54, 0x54, 0x54, 0x18,
344 0x00, 0x08, 0x7E, 0x09, 0x02,
345 0x18, 0xA4, 0xA4, 0x9C, 0x78,
346 0x7F, 0x08, 0x04, 0x04, 0x78,
347 0x00, 0x44, 0x7D, 0x40, 0x00,
348 0x20, 0x40, 0x40, 0x3D, 0x00,
349 0x7F, 0x10, 0x28, 0x44, 0x00,
350 0x00, 0x41, 0x7F, 0x40, 0x00,
351 0x7C, 0x04, 0x78, 0x04, 0x78,
352 0x7C, 0x08, 0x04, 0x04, 0x78,
353 0x38, 0x44, 0x44, 0x44, 0x38,
354 0xFC, 0x18, 0x24, 0x24, 0x18,
355 0x18, 0x24, 0x24, 0x18, 0xFC,
356 0x7C, 0x08, 0x04, 0x04, 0x08,
357 0x48, 0x54, 0x54, 0x54, 0x24,
358 0x04, 0x04, 0x3F, 0x44, 0x24,
359 0x3C, 0x40, 0x40, 0x20, 0x7C,
360 0x1C, 0x20, 0x40, 0x20, 0x1C,
361 0x3C, 0x40, 0x30, 0x40, 0x3C,
362 0x44, 0x28, 0x10, 0x28, 0x44,
363 0x4C, 0x90, 0x90, 0x90, 0x7C,
364 0x44, 0x64, 0x54, 0x4C, 0x44,
365 0x00, 0x08, 0x36, 0x41, 0x00,
366 0x00, 0x00, 0x77, 0x00, 0x00,
367 0x00, 0x41, 0x36, 0x08, 0x00,
368 0x02, 0x01, 0x02, 0x04, 0x02,
369 0x3C, 0x26, 0x23, 0x26, 0x3C,
370 0x1E, 0xA1, 0xA1, 0x61, 0x12,
371 0x3A, 0x40, 0x40, 0x20, 0x7A,
372 0x38, 0x54, 0x54, 0x55, 0x59,
373 0x21, 0x55, 0x55, 0x79, 0x41,
374 0x21, 0x54, 0x54, 0x78, 0x41,
375 0x21, 0x55, 0x54, 0x78, 0x40,
376 0x20, 0x54, 0x55, 0x79, 0x40,
377 0x0C, 0x1E, 0x52, 0x72, 0x12,
378 0x39, 0x55, 0x55, 0x55, 0x59,
379 0x39, 0x54, 0x54, 0x54, 0x59,
380 0x39, 0x55, 0x54, 0x54, 0x58,
381 0x00, 0x00, 0x45, 0x7C, 0x41,
382 0x00, 0x02, 0x45, 0x7D, 0x42,
383 0x00, 0x01, 0x45, 0x7C, 0x40,
384 0xF0, 0x29, 0x24, 0x29, 0xF0,
385 0xF0, 0x28, 0x25, 0x28, 0xF0,
386 0x7C, 0x54, 0x55, 0x45, 0x00,
387 0x20, 0x54, 0x54, 0x7C, 0x54,
388 0x7C, 0x0A, 0x09, 0x7F, 0x49,
389 0x32, 0x49, 0x49, 0x49, 0x32,
390 0x32, 0x48, 0x48, 0x48, 0x32,
391 0x32, 0x4A, 0x48, 0x48, 0x30,
392 0x3A, 0x41, 0x41, 0x21, 0x7A,
393 0x3A, 0x42, 0x40, 0x20, 0x78,
394 0x00, 0x9D, 0xA0, 0xA0, 0x7D,
395 0x39, 0x44, 0x44, 0x44, 0x39,
396 0x3D, 0x40, 0x40, 0x40, 0x3D,
397 0x3C, 0x24, 0xFF, 0x24, 0x24,
398 0x48, 0x7E, 0x49, 0x43, 0x66,
399 0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
400 0xFF, 0x09, 0x29, 0xF6, 0x20,
401 0xC0, 0x88, 0x7E, 0x09, 0x03,
402 0x20, 0x54, 0x54, 0x79, 0x41,
403 0x00, 0x00, 0x44, 0x7D, 0x41,
404 0x30, 0x48, 0x48, 0x4A, 0x32,
405 0x38, 0x40, 0x40, 0x22, 0x7A,
406 0x00, 0x7A, 0x0A, 0x0A, 0x72,
407 0x7D, 0x0D, 0x19, 0x31, 0x7D,
408 0x26, 0x29, 0x29, 0x2F, 0x28,
409 0x26, 0x29, 0x29, 0x29, 0x26,
410 0x30, 0x48, 0x4D, 0x40, 0x20,
411 0x38, 0x08, 0x08, 0x08, 0x08,
412 0x08, 0x08, 0x08, 0x08, 0x38,
413 0x2F, 0x10, 0xC8, 0xAC, 0xBA,
414 0x2F, 0x10, 0x28, 0x34, 0xFA,
415 0x00, 0x00, 0x7B, 0x00, 0x00,
416 0x08, 0x14, 0x2A, 0x14, 0x22,
417 0x22, 0x14, 0x2A, 0x14, 0x08,
418 0xAA, 0x00, 0x55, 0x00, 0xAA,
419 0xAA, 0x55, 0xAA, 0x55, 0xAA,
420 0x00, 0x00, 0x00, 0xFF, 0x00,
421 0x10, 0x10, 0x10, 0xFF, 0x00,
422 0x14, 0x14, 0x14, 0xFF, 0x00,
423 0x10, 0x10, 0xFF, 0x00, 0xFF,
424 0x10, 0x10, 0xF0, 0x10, 0xF0,
425 0x14, 0x14, 0x14, 0xFC, 0x00,
426 0x14, 0x14, 0xF7, 0x00, 0xFF,
427 0x00, 0x00, 0xFF, 0x00, 0xFF,
428 0x14, 0x14, 0xF4, 0x04, 0xFC,
429 0x14, 0x14, 0x17, 0x10, 0x1F,
430 0x10, 0x10, 0x1F, 0x10, 0x1F,
431 0x14, 0x14, 0x14, 0x1F, 0x00,
432 0x10, 0x10, 0x10, 0xF0, 0x00,
433 0x00, 0x00, 0x00, 0x1F, 0x10,
434 0x10, 0x10, 0x10, 0x1F, 0x10,
435 0x10, 0x10, 0x10, 0xF0, 0x10,
436 0x00, 0x00, 0x00, 0xFF, 0x10,
437 0x10, 0x10, 0x10, 0x10, 0x10,
438 0x10, 0x10, 0x10, 0xFF, 0x10,
439 0x00, 0x00, 0x00, 0xFF, 0x14,
440 0x00, 0x00, 0xFF, 0x00, 0xFF,
441 0x00, 0x00, 0x1F, 0x10, 0x17,
442 0x00, 0x00, 0xFC, 0x04, 0xF4,
443 0x14, 0x14, 0x17, 0x10, 0x17,
444 0x14, 0x14, 0xF4, 0x04, 0xF4,
445 0x00, 0x00, 0xFF, 0x00, 0xF7,
446 0x14, 0x14, 0x14, 0x14, 0x14,
447 0x14, 0x14, 0xF7, 0x00, 0xF7,
448 0x14, 0x14, 0x14, 0x17, 0x14,
449 0x10, 0x10, 0x1F, 0x10, 0x1F,
450 0x14, 0x14, 0x14, 0xF4, 0x14,
451 0x10, 0x10, 0xF0, 0x10, 0xF0,
452 0x00, 0x00, 0x1F, 0x10, 0x1F,
453 0x00, 0x00, 0x00, 0x1F, 0x14,
454 0x00, 0x00, 0x00, 0xFC, 0x14,
455 0x00, 0x00, 0xF0, 0x10, 0xF0,
456 0x10, 0x10, 0xFF, 0x10, 0xFF,
457 0x14, 0x14, 0x14, 0xFF, 0x14,
458 0x10, 0x10, 0x10, 0x1F, 0x00,
459 0x00, 0x00, 0x00, 0xF0, 0x10,
460 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
461 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
462 0xFF, 0xFF, 0xFF, 0x00, 0x00,
463 0x00, 0x00, 0x00, 0xFF, 0xFF,
464 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
465 0x38, 0x44, 0x44, 0x38, 0x44,
466 0x7C, 0x2A, 0x2A, 0x3E, 0x14,
467 0x7E, 0x02, 0x02, 0x06, 0x06,
468 0x02, 0x7E, 0x02, 0x7E, 0x02,
469 0x63, 0x55, 0x49, 0x41, 0x63,
470 0x38, 0x44, 0x44, 0x3C, 0x04,
471 0x40, 0x7E, 0x20, 0x1E, 0x20,
472 0x06, 0x02, 0x7E, 0x02, 0x02,
473 0x99, 0xA5, 0xE7, 0xA5, 0x99,
474 0x1C, 0x2A, 0x49, 0x2A, 0x1C,
475 0x4C, 0x72, 0x01, 0x72, 0x4C,
476 0x30, 0x4A, 0x4D, 0x4D, 0x30,
477 0x30, 0x48, 0x78, 0x48, 0x30,
478 0xBC, 0x62, 0x5A, 0x46, 0x3D,
479 0x3E, 0x49, 0x49, 0x49, 0x00,
480 0x7E, 0x01, 0x01, 0x01, 0x7E,
481 0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
482 0x44, 0x44, 0x5F, 0x44, 0x44,
483 0x40, 0x51, 0x4A, 0x44, 0x40,
484 0x40, 0x44, 0x4A, 0x51, 0x40,
485 0x00, 0x00, 0xFF, 0x01, 0x03,
486 0xE0, 0x80, 0xFF, 0x00, 0x00,
487 0x08, 0x08, 0x6B, 0x6B, 0x08,
488 0x36, 0x12, 0x36, 0x24, 0x36,
489 0x06, 0x0F, 0x09, 0x0F, 0x06,
490 0x00, 0x00, 0x18, 0x18, 0x00,
491 0x00, 0x00, 0x10, 0x10, 0x00,
492 0x30, 0x40, 0xFF, 0x01, 0x01,
493 0x00, 0x1F, 0x01, 0x01, 0x1E,
494 0x00, 0x19, 0x1D, 0x17, 0x12,
495 0x00, 0x3C, 0x3C, 0x3C, 0x3C,
496 0x00, 0x00, 0x00, 0x00, 0x00
530 ST7735 (uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst);
555 void write (uint8_t value);
562 void data (uint8_t value);
580 void setAddrWindow (uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
589 void drawPixel (int16_t x, int16_t y, uint16_t color);
624 mraa::Result
rsLOW ();
629 uint8_t m_spiBuffer[32];
631 mraa::Gpio m_csLCDPinCtx;
632 mraa::Gpio m_cSDPinCtx;
633 mraa::Gpio m_rSTPinCtx;
634 mraa::Gpio m_rSPinCtx;
void setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1)
Definition: st7735.cxx:120
mraa::Result sdCSOn()
Definition: st7735.cxx:220
void configModule()
Definition: st7735.cxx:165
API for the ST7735 LCD.
Definition: st7735.h:520
void initModule()
Definition: st7735.cxx:46
GFX helper class.
Definition: gfx.h:38
std::string name()
Definition: st7735.h:535
void data(uint8_t value)
Definition: st7735.cxx:89
ST7735(uint8_t csLCD, uint8_t cSD, uint8_t rs, uint8_t rst)
Definition: st7735.cxx:37
mraa::Result rsHIGH()
Definition: st7735.cxx:249
void executeCMDList(const uint8_t *addr)
Definition: st7735.cxx:95
mraa::Result sdCSOff()
Definition: st7735.cxx:237
void refresh()
Definition: st7735.cxx:155
void write(uint8_t value)
Definition: st7735.cxx:83
mraa::Result rsLOW()
Definition: st7735.cxx:261
mraa::Result lcdCSOn()
Definition: st7735.cxx:191
uint8_t m_map[160 *128 *2]
Definition: st7735.h:626
mraa::Result lcdCSOff()
Definition: st7735.cxx:208
void drawPixel(int16_t x, int16_t y, uint16_t color)
Definition: st7735.cxx:146