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