-
Notifications
You must be signed in to change notification settings - Fork 0
/
TFTDriver.ino
88 lines (77 loc) · 1.92 KB
/
TFTDriver.ino
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
//
//
//#include "WROVER_KIT_LCD.h"
#define LGFX_ESP_WROVER_KIT
#define LGFX_AUTODETECT
#include <LovyanGFX.hpp>
//#include "WROVER_KIT_LCD.h"
#include <esp_task_wdt.h>
#include <byteswap.h>
#define LCD_MAX_HEIGHT 320L
#define LCD_MAX_WIDTH 240L
/* create a hardware timer */
hw_timer_t* timer = NULL;
uint16_t colr = 0, * bmp, decay[100], st = 63, sl = 31, vl, * px;
int ix, iy, tflag = 1;
uint8_t* bitmap, *bm;
void IRAM_ATTR TFTEvent() {
tflag = 0;
}
void fade()
{
int fflag = 0;
for (iy = 0, px = bmp, bm=bitmap; iy < 320; iy++)
for (ix = 0; ix < 240; ix++, px++, bm++)
if (*bm) {
vl = decay[*bm];
//tft.drawPixel(40+iy, 240-ix, vl);
*bm = vl ? *bm + 1 : 0;
*px = vl;
fflag++;
}
if (!fflag) // Screen is blank
return;
tft.startWrite();
tft.setAddrWindow(0, 0, LCD_MAX_HEIGHT, LCD_MAX_WIDTH);
tft.writePixels(bmp, 320 * 240, false);
//tft.pushColors(bmp, 240 * 320, false);
tft.endWrite();
}
void TFTsetup(void* pvParameters) {
uint16_t cmap;
esp_task_wdt_init(30, false);
psramInit();
bmp = (uint16_t*)ps_malloc(320 * 240 * 2);
bitmap = (uint8_t*)ps_malloc(320 * 240);
memset(bmp, 0, 320 * 240 * 2);
memset(bitmap, 0, 320 * 240);
// for (i = 0; i < 300; i++)
// bmp[i*240 + 120] = 1;
for (i = 1; i < 100; i++) {
cmap = (uint16_t)(st << 5);
cmap |= (st / 2 << 11);
cmap |= sl;
decay[i] = __bswap_16(cmap);
st *= 0.9;
sl *= 0.6;
}
/* Use 1st timer of 4 */
/* 1 tick take 1/(80MHZ/80) = 1us so we set divider 80 and count up */
timer = timerBegin(0, 80, true);
/* Attach onTimer function to our timer */
timerAttachInterrupt(timer, &TFTEvent, true);
/* Set alarm to call onTimer function every second 1 tick is 1us
=> 1 second is 1000000us */
/* Repeat the alarm (third parameter) */
timerAlarmWrite(timer, 100000, true);
/* Start an alarm */
timerAlarmEnable(timer);
while (1) {
while (tflag)
yield();
tflag = 1;
fade();
if (!tflag)
Serial.printf(".");
}
}