-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay_epd.cpp
More file actions
73 lines (63 loc) · 2.45 KB
/
Copy pathdisplay_epd.cpp
File metadata and controls
73 lines (63 loc) · 2.45 KB
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
#include "display_epd.h"
#include "config.h"
#include "palette.h"
#include <GxEPD2_7C.h>
#include "GxEPD2_T133A01_1200x1600.h"
#include <Fonts/FreeSansBold18pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
// 4 bits/pixel for 7-colour panels -> WIDTH/2 bytes per row. A ~32 KB paged
// buffer keeps internal RAM free for Wi-Fi/web while still only needing a few
// passes per refresh.
#define MAX_DISPLAY_BUFFER_SIZE 32000u
#define MAX_HEIGHT(EPD) \
(EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) \
? EPD::HEIGHT \
: (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
// XIAO EE02 + 13.3" T133A01 dual-chip panel (chip0=CS left half, chip1=CS1 right
// half). The driver drives EPD_ENABLE high to power the panel and polls BUSY.
static GxEPD2_7C<GxEPD2_T133A01_1200x1600, MAX_HEIGHT(GxEPD2_T133A01_1200x1600)>
display(GxEPD2_T133A01_1200x1600(EPD_CS, EPD_DC, EPD_RST, EPD_BUSY, EPD_CS1, EPD_ENABLE));
// E6 palette index -> T133A01 native color7 code (0=Blk 1=Wht 2=Grn 3=Blu 4=Red 5=Yel).
static const uint8_t kE6toC7[8] = { 1, 2, 4, 5, 3, 0, 1, 1 };
void epd::begin(SPIClass& spi) {
// The T133A01 driver.init() sets up all pins (CS/CS1/DC/RST/BUSY/ENABLE), drives
// ENABLE high to power the panel, and initialises both controllers.
display.epd2.selectSPI(spi, SPISettings(10000000, MSBFIRST, SPI_MODE0));
display.init(115200);
display.setRotation(0);
}
void epd::setBusyCallback(void (*cb)(const void*)) {
display.epd2.setBusyCallback(cb);
}
void epd::showIndexed(const uint8_t* idx) {
// Single-pass pack straight into the driver framebuffer (vs. ~31 paged
// drawPixel re-scans), then one full refresh.
display.epd2.packIndexed(idx, kE6toC7);
display.epd2.refresh();
display.epd2.hibernate();
}
void epd::showMessage(const char* title, const String& body) {
display.setFullWindow();
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeSansBold18pt7b);
display.setCursor(48, 90);
display.print(title);
display.setFont(&FreeSans12pt7b);
int y = 170;
int start = 0;
while (start <= body.length()) {
int nl = body.indexOf('\n', start);
String line = (nl < 0) ? body.substring(start) : body.substring(start, nl);
display.setCursor(48, y);
display.print(line);
y += 46;
if (nl < 0) break;
start = nl + 1;
}
} while (display.nextPage());
display.hibernate();
}
void epd::hibernate() { display.hibernate(); }