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)
6974GxEPD2_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_);
101123void 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
0 commit comments