Skip to content

Commit ca61baf

Browse files
committed
Use GxEPD2/extras/sw_spi to probe controller and switch between legacy
and modern epaper displays.
1 parent 33af033 commit ca61baf

File tree

4 files changed

+265
-245
lines changed

4 files changed

+265
-245
lines changed

seedtool/hardware.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,11 @@
33
#ifndef HARDWARE_H
44
#define HARDWARE_H
55

6-
#include <GxEPD2_BW.h>
6+
#include <GxEPD2_GFX.h>
77
#include <Keypad.h>
88

9-
// Around April 2020 Waveshare started shipping a new version of the
10-
// "Waveshare 200x200, 1.54inch E-Ink display module". The new
11-
// versions have "Rev2.1" printed under the title on the circuit side
12-
// of the display. This new version requires a different driver
13-
// module from GxEPD2.
14-
//
15-
// If you have an *older* display (doesn't have "Rev2.1") uncomment
16-
// the following line:
17-
//
18-
// #define LEGACY_WAVESHARE
19-
20-
#if !defined(LEGACY_WAVESHARE)
21-
#define EPD_DRIVER GxEPD2_154_D67
22-
#else
23-
#define EPD_DRIVER GxEPD2_154
24-
#endif
25-
269
// This is hard to hide/encapsulate.
27-
extern GxEPD2_BW<EPD_DRIVER, EPD_DRIVER::HEIGHT> g_display;
10+
extern GxEPD2_GFX *g_display;
2811

2912
void hw_setup();
3013
void hw_green_led(int value);

seedtool/hardware.ino

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#undef ESP32
55
#define SAMD51 1
66

7+
#define ENABLE_GxEPD2_GFX 1
8+
#include <GxEPD2_BW.h>
9+
710
#include "hardware.h"
811
#include "util.h"
912

@@ -64,6 +67,8 @@ extern "C" {
6467
#define GREEN_LED 4
6568
#endif
6669

70+
GxEPD2_GFX *g_display;
71+
6772
// Display
6873
#if defined(ESP32)
6974
GxEPD2_BW<EPD_DRIVER, EPD_DRIVER::HEIGHT>
@@ -72,11 +77,28 @@ g_display(EPD_DRIVER(/*CS=*/ 21,
7277
/*RST=*/ 16,
7378
/*BUSY=*/ 4));
7479
#elif defined(SAMD51)
75-
GxEPD2_BW<EPD_DRIVER, EPD_DRIVER::HEIGHT>
76-
g_display(EPD_DRIVER(/*CS=*/ PIN_A4,
77-
/*DC=*/ PIN_A3,
78-
/*RST=*/ PIN_A2,
79-
/*BUSY=*/ PIN_A1));
80+
81+
// Around April 2020 Waveshare started shipping a new version of the
82+
// "Waveshare 200x200, 1.54inch E-Ink display module". The new
83+
// versions have "Rev2.1" printed under the title on the circuit side
84+
// of the display. This new version requires a different driver
85+
// module from GxEPD2 (GxEPD2_154_D67).
86+
//
87+
// We declare and initialize both modules and then probe the
88+
// controller at runtime to see which is connected.
89+
//
90+
GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT>
91+
display_legacy(GxEPD2_154(/*CS=*/ PIN_A4,
92+
/*DC=*/ PIN_A3,
93+
/*RST=*/ PIN_A2,
94+
/*BUSY=*/ PIN_A1));
95+
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT>
96+
display_modern(GxEPD2_154_D67(/*CS=*/ PIN_A4,
97+
/*DC=*/ PIN_A3,
98+
/*RST=*/ PIN_A2,
99+
/*BUSY=*/ PIN_A1));
100+
#define SW_SCK 24
101+
#define SW_MOSI 23
80102
#endif
81103

82104
// Keypad
@@ -101,15 +123,30 @@ Keypad g_keypad = Keypad(makeKeymap(keys_), rowPins_, colPins_, rows_, cols_);
101123
void hw_setup() {
102124
pinMode(BLUE_LED, OUTPUT); // Blue LED
103125
digitalWrite(BLUE_LED, HIGH);
104-
126+
105127
pinMode(GREEN_LED, OUTPUT); // Green LED
106128
digitalWrite(GREEN_LED, LOW);
107-
108-
g_display.init(115200);
109-
g_display.setRotation(1);
110129

111130
Serial.begin(115200);
112-
131+
132+
// Initialize both versions of the display instance.
133+
display_modern.epd2.init(SW_SCK, SW_MOSI, 115200, true, false);
134+
display_modern.init(115200);
135+
display_legacy.epd2.init(SW_SCK, SW_MOSI, 115200, true, false);
136+
display_legacy.init(115200);
137+
138+
// Read a byte from the display instance to pick a version.
139+
uint8_t read_legacy = display_legacy.epd2._readData();
140+
serial_printf("read_legacy: readData=0x%02x\n", read_legacy);
141+
g_display = read_legacy
142+
? static_cast<GxEPD2_GFX *>(&display_legacy)
143+
: static_cast<GxEPD2_GFX *>(&display_modern);
144+
145+
// Switch back to HW SPI for performance.
146+
g_display->epd2.init(-1, -1, 115200, true, false);
147+
148+
g_display->setRotation(1);
149+
113150
#if defined(SAMD51)
114151
trngInit();
115152
#endif

seedtool/seedtool.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void setup() {
1717
// monitor launched before the tests run.
1818
//
1919
// delay(5000);
20-
20+
2121
ui_reset_into_state(SELF_TEST);
2222

2323
Serial.println("seedtool starting");

0 commit comments

Comments
 (0)