ZinggJM 8 лет назад
Родитель
Сommit
a209806494

+ 105 - 31
examples/GxEPD2_Example/GxEPD2_Example.ino

@@ -97,8 +97,8 @@
 #endif
 
 #if defined(_BOARD_GENERIC_STM32F103C_H_)
-#define MAX_DISPAY_BUFFER_SIZE (400 * 300) // ~5k is a good compromise
-#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH)
+#define MAX_DISPAY_BUFFER_SIZE (400 * 300) // ~15k is a good compromise
+#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
 // select one and adapt to your mapping
 //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
@@ -107,17 +107,18 @@
 //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 // 3-color e-papers
-//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+#define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
+//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 #endif
 
 #if defined(__AVR)
-#define MAX_DISPAY_BUFFER_SIZE 1000 // half of available RAM as a compromise
-#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH)
+#define MAX_DISPAY_BUFFER_SIZE 800 // 
+#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
 // select one and adapt to your mapping
 //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
@@ -126,12 +127,47 @@
 //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 // 3-color e-papers
-//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+#define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
+//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+#endif
+
+#if !defined(__AVR)
+
+// comment out unused bitmaps to reduce code space used
+#include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
+#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
+#include "bitmaps/Bitmaps128x296.h" // 2.9"  b/w
+#include "bitmaps/Bitmaps176x264.h" // 2.7"  b/w
+#include "bitmaps/Bitmaps400x300.h" // 4.2"  b/w
+#include "bitmaps/Bitmaps640x384.h" // 7.5"  b/w
+// 3-color
+#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
+#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
+#include "bitmaps/Bitmaps3c128x296.h" // 2.9"  b/w/r
+#include "bitmaps/Bitmaps3c176x264.h" // 2.7"  b/w/r
+#include "bitmaps/Bitmaps3c400x300.h" // 4.2"  b/w/r
+
+#else
+
+// select only one to fit in code space
+//#include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
+//#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
+//#include "bitmaps/Bitmaps128x296.h" // 2.9"  b/w
+//#include "bitmaps/Bitmaps176x264.h" // 2.7"  b/w
+////#include "bitmaps/Bitmaps400x300.h" // 4.2"  b/w // not enough code space
+////#include "bitmaps/Bitmaps640x384.h" // 7.5"  b/w // not enough code space
+// 3-color
+//#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
+//#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
+//#include "bitmaps/Bitmaps3c128x296.h" // 2.9"  b/w/r
+//#include "bitmaps/Bitmaps3c176x264.h" // 2.7"  b/w/r
+////#include "bitmaps/Bitmaps3c400x300.h" // 4.2"  b/w/r // not enough code space
+
 #endif
 
 void setup()
@@ -139,7 +175,7 @@ void setup()
   Serial.begin(115200);
   Serial.println();
   Serial.println("setup");
-  display.init();
+  display.init(115200);
   // first update should be full refresh
   helloWorld();
   delay(1000);
@@ -178,6 +214,7 @@ void helloWorld()
   display.setTextColor(GxEPD_BLACK);
   uint16_t x = (display.width() - 160) / 2;
   uint16_t y = display.height() / 2;
+  display.setFullWindow();
   display.firstPage();
   do
   {
@@ -412,20 +449,6 @@ void showPartialUpdate()
   }
 }
 
-// comment out unused bitmaps to reduce code space used
-
-#include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
-#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
-#include "bitmaps/Bitmaps128x296.h" // 2.9"  b/w
-#include "bitmaps/Bitmaps176x264.h" // 2.7"  b/w
-#include "bitmaps/Bitmaps400x300.h" // 4.2"  b/w
-#include "bitmaps/Bitmaps640x384.h" // 7.5"  b/w
-// 3-color
-#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
-#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
-#include "bitmaps/Bitmaps3c128x296.h" // 2.9"  b/w/r
-#include "bitmaps/Bitmaps3c176x264.h" // 2.7"  b/w/r
-#include "bitmaps/Bitmaps3c400x300.h" // 4.2"  b/w/r
 
 void drawBitmaps()
 {
@@ -471,10 +494,17 @@ void drawBitmaps()
 #ifdef _GxBitmaps200x200_H_
 void drawBitmaps200x200()
 {
+#if !defined(__AVR)
   const unsigned char* bitmaps[] =
   {
     logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
   };
+#else
+  const unsigned char* bitmaps[] =
+  {
+    logo200x200, first200x200 //, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
+  };
+#endif
   if (display.epd2.panel == GxEPD2::GDEP015OC1)
   {
     bool m = display.mirror(true);
@@ -532,10 +562,17 @@ void drawBitmaps200x200()
 #ifdef _GxBitmaps128x250_H_
 void drawBitmaps128x250()
 {
+#if !defined(__AVR)
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
+  };
+#else
   const unsigned char* bitmaps[] =
   {
     Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
   };
+#endif
   if (display.epd2.panel == GxEPD2::GDE0213B1)
   {
     bool m = display.mirror(true);
@@ -558,10 +595,17 @@ void drawBitmaps128x250()
 #ifdef _GxBitmaps128x296_H_
 void drawBitmaps128x296()
 {
+#if !defined(__AVR)
   const unsigned char* bitmaps[] =
   {
     Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
   };
+#else
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
+  };
+#endif
   if (display.epd2.panel == GxEPD2::GDEH029A1)
   {
     bool m = display.mirror(true);
@@ -608,10 +652,14 @@ void drawBitmaps176x264()
 #ifdef _GxBitmaps400x300_H_
 void drawBitmaps400x300()
 {
+#if !defined(__AVR)
   const unsigned char* bitmaps[] =
   {
     Bitmap400x300_1, Bitmap400x300_2
   };
+#else
+  const unsigned char* bitmaps[] = {}; // not enough code space
+#endif
   if (display.epd2.panel == GxEPD2::GDEW042T2)
   {
     for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
@@ -632,10 +680,14 @@ void drawBitmaps400x300()
 #ifdef _GxBitmaps640x384_H_
 void drawBitmaps640x384()
 {
+#if !defined(__AVR)
   const unsigned char* bitmaps[] =
   {
     Bitmap640x384_1, Bitmap640x384_2
   };
+#else
+  const unsigned char* bitmaps[] = {}; // not enough code space
+#endif
   if (display.epd2.panel == GxEPD2::GDEW075T8)
   {
     for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
@@ -750,12 +802,21 @@ void drawBitmaps3c200x200()
 #ifdef _GxBitmaps3c104x212_H_
 void drawBitmaps3c104x212()
 {
+#if !defined(__AVR)
   bitmap_pair bitmap_pairs[] =
   {
     {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
     {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
     {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
   };
+#else
+  bitmap_pair bitmap_pairs[] =
+  {
+    {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
+    //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
+    {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
+  };
+#endif
   if (display.epd2.panel == GxEPD2::GDEW0213Z16)
   {
     for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
@@ -781,12 +842,21 @@ void drawBitmaps3c104x212()
 #ifdef _GxBitmaps3c128x296_H_
 void drawBitmaps3c128x296()
 {
+#if !defined(__AVR)
   bitmap_pair bitmap_pairs[] =
   {
     {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
     {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
     {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
   };
+#else
+  bitmap_pair bitmap_pairs[] =
+  {
+    //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
+    //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
+    {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
+  };
+#endif
   if (display.epd2.panel == GxEPD2::GDEW029Z10)
   {
     for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
@@ -837,12 +907,16 @@ void drawBitmaps3c176x264()
 #ifdef _GxBitmaps3c400x300_H_
 void drawBitmaps3c400x300()
 {
+#if !defined(__AVR)
   bitmap_pair bitmap_pairs[] =
   {
     {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
     {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
     {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
   };
+#else
+  bitmap_pair bitmap_pairs[] = {}; // not enough code space
+#endif
   if (display.epd2.panel == GxEPD2::GDEW042Z15)
   {
     for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)

+ 898 - 0
examples/GxEPD2_PagedDisplayUsingCallback/GxEPD2_PagedDisplayUsingCallback.ino

@@ -0,0 +1,898 @@
+// Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
+// Requires HW SPI and Adafruit_GFX. Caution: these e-papers require 3.3V supply AND data lines!
+//
+// Display Library based on Demo Example from Good Display: http://www.good-display.com/download_list/downloadcategoryid=34&isMode=false.html
+//
+// Author: Jean-Marc Zingg
+//
+// Version: see library.properties
+//
+// Library: https://github.com/ZinggJM/GxEPD2
+
+// Supporting Arduino Forum Topics:
+// Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
+// Good Dispay ePaper for Arduino : https://forum.arduino.cc/index.php?topic=436411.0
+
+// mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
+// BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
+
+// mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
+// BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
+
+// mapping of Waveshare e-Paper ESP8266 Driver Board
+// BUSY -> GPIO16, RST -> GPIO5, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
+
+// mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
+// NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
+// BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
+
+// new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
+// BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
+
+// mapping suggestion for AVR, UNO, NANO etc.
+// BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
+
+#include <GxEPD2_BW.h>
+#include <GxEPD2_3C.h>
+#include <Fonts/FreeMonoBold9pt7b.h>
+
+#if defined (ESP8266)
+// select one and adapt to your mapping, can use full buffer size (full HEIGHT)
+//GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+// can use only half buffer size
+//GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+// 3-color e-papers
+//GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+// can use only half buffer size
+//GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+// can use only quarter buffer size
+//GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+//GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+
+// ***** for mapping of Waveshare e-Paper ESP8266 Driver Board *****
+// select one , can use full buffer size (full HEIGHT)
+//GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+// can use only half buffer size
+//GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+// 3-color e-papers
+//GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+// can use only half buffer size
+//GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+// can use only quarter buffer size
+//GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+//GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+#endif
+
+#if defined(ESP32)
+// select one and adapt to your mapping, can use full buffer size (full HEIGHT)
+//GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+// 3-color e-papers
+//GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+//GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+#endif
+
+#if defined(_BOARD_GENERIC_STM32F103C_H_)
+#define MAX_DISPAY_BUFFER_SIZE (400 * 300) // ~15k is a good compromise
+#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
+// select one and adapt to your mapping
+//GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+// 3-color e-papers
+#define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
+//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+#endif
+
+#if defined(__AVR)
+#define MAX_DISPAY_BUFFER_SIZE 800 // 
+#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
+// select one and adapt to your mapping
+//GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+// 3-color e-papers
+#define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
+//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+#endif
+
+#if !defined(__AVR)
+
+// comment out unused bitmaps to reduce code space used
+#include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
+#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
+#include "bitmaps/Bitmaps128x296.h" // 2.9"  b/w
+#include "bitmaps/Bitmaps176x264.h" // 2.7"  b/w
+#include "bitmaps/Bitmaps400x300.h" // 4.2"  b/w
+#include "bitmaps/Bitmaps640x384.h" // 7.5"  b/w
+// 3-color
+#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
+#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
+#include "bitmaps/Bitmaps3c128x296.h" // 2.9"  b/w/r
+#include "bitmaps/Bitmaps3c176x264.h" // 2.7"  b/w/r
+#include "bitmaps/Bitmaps3c400x300.h" // 4.2"  b/w/r
+
+#else
+
+// select only one to fit in code space
+//#include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
+//#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
+//#include "bitmaps/Bitmaps128x296.h" // 2.9"  b/w
+//#include "bitmaps/Bitmaps176x264.h" // 2.7"  b/w
+////#include "bitmaps/Bitmaps400x300.h" // 4.2"  b/w // not enough code space
+////#include "bitmaps/Bitmaps640x384.h" // 7.5"  b/w // not enough code space
+// 3-color
+//#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
+//#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
+//#include "bitmaps/Bitmaps3c128x296.h" // 2.9"  b/w/r
+//#include "bitmaps/Bitmaps3c176x264.h" // 2.7"  b/w/r
+////#include "bitmaps/Bitmaps3c400x300.h" // 4.2"  b/w/r // not enough code space
+
+#endif
+
+void setup()
+{
+  Serial.begin(115200);
+  Serial.println();
+  Serial.println("setup");
+  display.init(115200);
+  // first update should be full refresh
+  helloWorld();
+  delay(1000);
+  // partial refresh mode can be used to full screen,
+  // effective if display panel hasFastPartialUpdate
+  helloFullScreenPartialMode();
+  delay(1000);
+  helloArduino();
+  delay(1000);
+  helloEpaper();
+  delay(1000);
+  showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
+  delay(1000);
+  drawBitmaps();
+  if (display.epd2.hasPartialUpdate)
+  {
+    showPartialUpdate();
+    delay(1000);
+  } // else // on GDEW0154Z04 only full update available, doesn't look nice
+  //drawCornerTest();
+  //showBox(16, 16, 48, 32, false);
+  //showBox(16, 56, 48, 32, true);
+  display.powerOff();
+  Serial.println("setup done");
+}
+
+void loop()
+{
+}
+
+void helloWorldCallback(const void*)
+{
+  uint16_t x = (display.width() - 160) / 2;
+  uint16_t y = display.height() / 2;
+  display.fillScreen(GxEPD_WHITE);
+  display.setCursor(x, y);
+  display.println("Hello World!");
+}
+
+void helloWorld()
+{
+  //Serial.println("helloWorld");
+  uint16_t x = (display.width() - 160) / 2;
+  uint16_t y = display.height() / 2;
+  display.setRotation(1);
+  display.setFont(&FreeMonoBold9pt7b);
+  display.setTextColor(GxEPD_BLACK);
+  display.setFullWindow();
+  display.drawPaged(helloWorldCallback, 0);
+  //Serial.println("helloWorld done");
+}
+
+void helloFullScreenPartialModeCallback(const void*)
+{
+  uint16_t x = (display.width() - 160) / 2;
+  uint16_t y = display.height() / 2;
+  display.fillScreen(GxEPD_WHITE);
+  display.setCursor(x, y);
+  display.println("Hello World!");
+  y = display.height() / 4;
+  display.setCursor(x, y);
+  display.println("full screen");
+  y = display.height() * 3 / 4;
+  if (display.width() <= 200) x = 0;
+  display.setCursor(x, y);
+  if (display.epd2.hasFastPartialUpdate)
+  {
+    display.println("fast partial mode");
+  }
+  else if (display.epd2.hasPartialUpdate)
+  {
+    display.println("slow partial mode");
+  }
+  else
+  {
+    display.println("no partial mode");
+  }
+}
+
+void helloFullScreenPartialMode()
+{
+  //Serial.println("helloFullScreenPartialMode");
+  display.setPartialWindow(0, 0, display.width(), display.height());
+  display.setRotation(1);
+  display.setFont(&FreeMonoBold9pt7b);
+  display.setTextColor(GxEPD_BLACK);
+  display.drawPaged(helloFullScreenPartialModeCallback, 0);
+  //Serial.println("helloFullScreenPartialMode done");
+}
+
+void helloArduinoCallback(const void*)
+{
+  uint16_t x = (display.width() - 160) / 2;
+  uint16_t y = display.height() / 4;
+  display.fillScreen(GxEPD_WHITE);
+  display.setCursor(x, y);
+  display.println("Hello Arduino!");
+}
+
+void helloArduino()
+{
+  //Serial.println("helloArduino");
+  uint16_t x = (display.width() - 160) / 2;
+  uint16_t y = display.height() / 4;
+  display.setRotation(1);
+  display.setFont(&FreeMonoBold9pt7b);
+  display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
+  display.setPartialWindow(0, y - 14, display.width(), 20);
+  display.drawPaged(helloArduinoCallback, 0);
+  delay(1000);
+  //Serial.println("helloArduino done");
+}
+
+void helloEpaperCallback(const void*)
+{
+  uint16_t x = (display.width() - 160) / 2;
+  uint16_t y = display.height() * 3 / 4;
+  display.fillScreen(GxEPD_WHITE);
+  display.setCursor(x, y);
+  display.println("Hello E-Paper!");
+}
+
+void helloEpaper()
+{
+  //Serial.println("helloEpaper");
+  uint16_t x = (display.width() - 160) / 2;
+  uint16_t y = display.height() * 3 / 4;
+  display.setRotation(1);
+  display.setFont(&FreeMonoBold9pt7b);
+  display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
+  display.setPartialWindow(0, y - 14, display.width(), 20);
+  display.drawPaged(helloEpaperCallback, 0);
+  //Serial.println("helloEpaper done");
+}
+
+struct DrawFontParameters
+{
+  const char* name;
+  const GFXfont* f;
+};
+
+void showFont(const char name[], const GFXfont* f)
+{
+  DrawFontParameters fontParameters{name, f};
+  display.setFullWindow();
+  display.setRotation(0);
+  display.setTextColor(GxEPD_BLACK);
+  display.drawPaged(drawFontCallback, &fontParameters);
+}
+
+void drawFontCallback(const void* parameters)
+{
+  const DrawFontParameters* p = reinterpret_cast<const DrawFontParameters*>(parameters);
+  //display.setRotation(0);
+  display.fillScreen(GxEPD_WHITE);
+  display.setTextColor(GxEPD_BLACK);
+  display.setFont(p->f);
+  display.setCursor(0, 0);
+  display.println();
+  display.println(p->name);
+  display.println(" !\"#$%&'()*+,-./");
+  display.println("0123456789:;<=>?");
+  display.println("@ABCDEFGHIJKLMNO");
+  display.println("PQRSTUVWXYZ[\\]^_");
+  if (display.epd2.hasColor)
+  {
+    display.setTextColor(GxEPD_RED);
+  }
+  display.println("`abcdefghijklmno");
+  display.println("pqrstuvwxyz{|}~ ");
+}
+
+struct ShowBoxParameters
+{
+  uint16_t x, y, w, h;
+  uint16_t color;
+};
+
+struct ShowValueParameters
+{
+  uint16_t x, y, w, h, cursor_y;
+  float value;
+};
+
+void showBoxCallback(const void* parameters)
+{
+  const ShowBoxParameters* p = reinterpret_cast<const ShowBoxParameters*>(parameters);
+  display.fillRect(p->x, p->y, p->w, p->h, p->color);
+}
+
+void showValueBoxCallback(const void* parameters)
+{
+  const ShowValueParameters* p = reinterpret_cast<const ShowValueParameters*>(parameters);
+  display.fillRect(p->x, p->y, p->w, p->h, GxEPD_WHITE);
+  display.setCursor(p->x, p->cursor_y);
+  display.print(p->value);
+}
+
+void showPartialUpdate()
+{
+  // some useful background
+  helloWorld();
+  // use asymmetric values for test
+  ShowBoxParameters boxParameters{10, 15, 70, 20, GxEPD_WHITE};
+  ShowValueParameters valueParameters{10, 15, 70, 20, 13.95};
+  valueParameters.cursor_y = valueParameters.y + valueParameters.h - 6;
+  float value = 13.95;
+  uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
+  display.setFont(&FreeMonoBold9pt7b);
+  display.setTextColor(GxEPD_BLACK);
+  // show where the update box is
+  for (uint16_t r = 0; r < 4; r++)
+  {
+    display.setRotation(r);
+    display.setPartialWindow(boxParameters.x, boxParameters.y, boxParameters.w, boxParameters.h);
+    boxParameters.color = GxEPD_BLACK;
+    display.drawPaged(showBoxCallback, &boxParameters);
+    delay(2000);
+    boxParameters.color = GxEPD_WHITE;
+    display.drawPaged(showBoxCallback, &boxParameters);
+    while (display.nextPage());
+    delay(1000);
+  }
+  // show updates in the update box
+  for (uint16_t r = 0; r < 4; r++)
+  {
+    display.setRotation(r);
+    display.setPartialWindow(boxParameters.x, boxParameters.y, boxParameters.w, boxParameters.h);
+    for (uint16_t i = 1; i <= 10; i += incr)
+    {
+      valueParameters.value = value * i;
+      display.drawPaged(showValueBoxCallback, &valueParameters);
+      delay(500);
+    }
+    delay(1000);
+    boxParameters.color = GxEPD_WHITE;
+    display.drawPaged(showBoxCallback, &boxParameters);
+    delay(1000);
+  }
+}
+
+void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
+{
+  //Serial.println("showBox");
+  ShowBoxParameters boxParameters{x, y, w, h, GxEPD_BLACK};
+  display.setRotation(1);
+  if (partial)
+  {
+    display.setPartialWindow(x, y, w, h);
+  }
+  else
+  {
+    display.setFullWindow();
+  }
+  display.drawPaged(showBoxCallback, &boxParameters);
+  //Serial.println("showBox done");
+}
+
+void drawCornerTestCallback(const void*)
+{
+  display.fillScreen(GxEPD_WHITE);
+  display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
+  display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
+  display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
+  display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
+  display.setCursor(display.width() / 2, display.height() / 2);
+  display.print(display.getRotation());
+}
+
+void drawCornerTest()
+{
+  display.setFullWindow();
+  display.setFont(&FreeMonoBold9pt7b);
+  display.setTextColor(GxEPD_BLACK);
+  for (uint16_t r = 0; r <= 4; r++)
+  {
+    display.setRotation(r);
+    display.drawPaged(drawCornerTestCallback, 0);
+    delay(2000);
+  }
+}
+
+void drawBitmaps()
+{
+  display.setFullWindow();
+#ifdef _GxBitmaps128x250_H_
+  drawBitmaps128x250();
+#endif
+#ifdef _GxBitmaps128x296_H_
+  drawBitmaps128x296();
+#endif
+#ifdef _GxBitmaps176x264_H_
+  drawBitmaps176x264();
+#endif
+#ifdef _GxBitmaps400x300_H_
+  drawBitmaps400x300();
+#endif
+#ifdef _GxBitmaps640x384_H_
+  drawBitmaps640x384();
+#endif
+  // 3-color
+#ifdef _GxBitmaps3c104x212_H_
+  drawBitmaps3c104x212();
+#endif
+#ifdef _GxBitmaps3c128x296_H_
+  drawBitmaps3c128x296();
+#endif
+#ifdef _GxBitmaps3c176x264_H_
+  drawBitmaps3c176x264();
+#endif
+#ifdef _GxBitmaps3c400x300_H_
+  drawBitmaps3c400x300();
+#endif
+  // show these after the specific bitmaps
+#ifdef _GxBitmaps200x200_H_
+  drawBitmaps200x200();
+#endif
+  // 3-color
+#ifdef _GxBitmaps3c200x200_H_
+  drawBitmaps3c200x200();
+#endif
+}
+
+void drawInvertedBitmapCallback(const void* parameter)
+{
+  const uint8_t* bitmap = reinterpret_cast<const uint8_t*>(parameter);
+  display.fillScreen(GxEPD_WHITE);
+  display.drawInvertedBitmap(0, 0, bitmap, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
+}
+
+#ifdef _GxBitmaps200x200_H_
+void drawBitmaps200x200()
+{
+#if defined(__AVR)
+  const unsigned char* bitmaps[] =
+  {
+    logo200x200, first200x200 //, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
+  };
+#else
+  const unsigned char* bitmaps[] =
+  {
+    logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
+  };
+#endif
+  if (display.epd2.panel == GxEPD2::GDEP015OC1)
+  {
+    bool m = display.mirror(true);
+    for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+    {
+      display.drawPaged(drawInvertedBitmapCallback, bitmaps[i]);
+      delay(2000);
+    }
+    display.mirror(m);
+  }
+  //else
+  {
+    bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
+    display.clearScreen(); // use default for white
+    uint16_t x = (display.epd2.WIDTH - 200) / 2;
+    uint16_t y = (display.epd2.HEIGHT - 200) / 2;
+    for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+    {
+      display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
+      delay(2000);
+    }
+  }
+  bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
+  for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+  {
+    int16_t x = -60;
+    int16_t y = -60;
+    for (uint16_t j = 0; j < 10; j++)
+    {
+      display.writeScreenBuffer(); // use default for white
+      display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
+      display.refresh(true);
+      delay(2000);
+      x += 40;
+      y += 40;
+      if ((x >= display.epd2.WIDTH) || (y >= display.epd2.HEIGHT)) break;
+    }
+    if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
+    break; // comment out for full show
+  }
+  display.writeScreenBuffer(); // use default for white
+  display.writeImage(bitmaps[0], 0, 0, 200, 200, false, mirror_y, true);
+  display.writeImage(bitmaps[0], display.epd2.WIDTH - 200, display.epd2.HEIGHT - 200, 200, 200, false, mirror_y, true);
+  display.refresh(true);
+  delay(2000);
+}
+#endif
+
+#ifdef _GxBitmaps128x250_H_
+void drawBitmaps128x250()
+{
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
+  };
+  if (display.epd2.panel == GxEPD2::GDE0213B1)
+  {
+    bool m = display.mirror(true);
+    for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+    {
+      display.drawPaged(drawInvertedBitmapCallback, bitmaps[i]);
+      delay(2000);
+    }
+    display.mirror(m);
+  }
+}
+#endif
+
+#ifdef _GxBitmaps128x296_H_
+void drawBitmaps128x296()
+{
+#if !defined(__AVR)
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
+  };
+#else
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
+  };
+#endif
+  if (display.epd2.panel == GxEPD2::GDEH029A1)
+  {
+    bool m = display.mirror(true);
+    for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+    {
+      display.drawPaged(drawInvertedBitmapCallback, bitmaps[i]);
+      delay(2000);
+    }
+    display.mirror(m);
+  }
+}
+#endif
+
+#ifdef _GxBitmaps176x264_H_
+void drawBitmaps176x264()
+{
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap176x264_1, Bitmap176x264_2
+  };
+  if (display.epd2.panel == GxEPD2::GDEW027W3)
+  {
+    for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+    {
+      display.drawPaged(drawInvertedBitmapCallback, bitmaps[i]);
+      delay(2000);
+    }
+  }
+}
+#endif
+
+#ifdef _GxBitmaps400x300_H_
+void drawBitmaps400x300()
+{
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap400x300_1, Bitmap400x300_2
+  };
+  if (display.epd2.panel == GxEPD2::GDEW042T2)
+  {
+    for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+    {
+      display.drawPaged(drawInvertedBitmapCallback, bitmaps[i]);
+      delay(2000);
+    }
+  }
+}
+#endif
+
+#ifdef _GxBitmaps640x384_H_
+void drawBitmaps640x384()
+{
+  const unsigned char* bitmaps[] =
+  {
+    Bitmap640x384_1, Bitmap640x384_2
+  };
+  if (display.epd2.panel == GxEPD2::GDEW075T8)
+  {
+    for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
+    {
+      display.drawPaged(drawInvertedBitmapCallback, bitmaps[i]);
+      delay(2000);
+    }
+  }
+}
+#endif
+
+struct bitmap_pair
+{
+  const unsigned char* black;
+  const unsigned char* red;
+};
+
+void drawBitmapPairCallback(const void* parameters)
+{
+  const bitmap_pair* bitmaps = reinterpret_cast<const bitmap_pair*>(parameters);
+  display.fillScreen(GxEPD_WHITE);
+  display.drawBitmap(0, 0, bitmaps->black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
+  display.drawBitmap(0, 0, bitmaps->red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
+}
+
+void drawInvertedBitmapPairCallback(const void* parameters)
+{
+  const bitmap_pair* bitmaps = reinterpret_cast<const bitmap_pair*>(parameters);
+  display.fillScreen(GxEPD_WHITE);
+  display.drawInvertedBitmap(0, 0, bitmaps->black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
+  display.drawInvertedBitmap(0, 0, bitmaps->red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
+}
+
+void drawSpecialBitmapPairCallback(const void* parameters)
+{
+  const bitmap_pair* bitmaps = reinterpret_cast<const bitmap_pair*>(parameters);
+  display.fillScreen(GxEPD_WHITE);
+  // Bitmap3c200x200_black has 2 bits per pixel
+  // taken from Adafruit_GFX.cpp, modified
+  int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
+  uint8_t byte = 0;
+  for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
+  {
+    for (int16_t i = 0; i < display.epd2.WIDTH; i++)
+    {
+      if (i & 3) byte <<= 2;
+      else
+      {
+#if defined(__AVR) || defined(ESP8266) || defined(ESP32)
+        byte = pgm_read_byte(&bitmaps->black[j * byteWidth * 2 + i / 4]);
+#else
+        byte = bitmaps->black[j * byteWidth * 2 + i / 4];
+#endif
+      }
+      if (!(byte & 0x80))
+      {
+        display.drawPixel(i, j, GxEPD_BLACK);
+      }
+    }
+  }
+  display.drawInvertedBitmap(0, 0, bitmaps->red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
+}
+
+#ifdef _GxBitmaps3c200x200_H_
+void drawBitmaps3c200x200()
+{
+  bitmap_pair bitmap_pairs[] =
+  {
+    //{Bitmap3c200x200_black, Bitmap3c200x200_red}, // special
+    {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
+  };
+  bitmap_pair special_bitmap{Bitmap3c200x200_black, Bitmap3c200x200_red};
+  if (display.epd2.panel == GxEPD2::GDEW0154Z04)
+  {
+    display.drawPaged(drawSpecialBitmapPairCallback, &special_bitmap);
+    delay(2000);
+    for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
+    {
+      display.drawPaged(drawInvertedBitmapPairCallback, &bitmap_pairs[i]);
+      delay(2000);
+    }
+  }
+  if (display.epd2.hasColor)
+  {
+    display.clearScreen(); // use default for white
+    uint16_t x = (display.epd2.WIDTH - 200) / 2;
+    uint16_t y = (display.epd2.HEIGHT - 200) / 2;
+    for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
+    {
+      display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
+      delay(2000);
+    }
+    for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
+    {
+      int16_t x = -60;
+      int16_t y = -60;
+      for (uint16_t j = 0; j < 10; j++)
+      {
+        display.writeScreenBuffer(); // use default for white
+        display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
+        display.refresh();
+        delay(2000);
+        x += 40;
+        y += 40;
+        if ((x >= display.epd2.WIDTH) || (y >= display.epd2.HEIGHT)) break;
+      }
+    }
+    display.writeScreenBuffer(); // use default for white
+    display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
+    display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, display.epd2.WIDTH - 200, display.epd2.HEIGHT - 200, 200, 200, false, false, true);
+    display.refresh();
+    delay(2000);
+  }
+}
+#endif
+
+#ifdef _GxBitmaps3c104x212_H_
+void drawBitmapPairCallback3c104x212(const void* parameters)
+{
+  const bitmap_pair* bitmaps = reinterpret_cast<const bitmap_pair*>(parameters);
+  display.fillScreen(GxEPD_WHITE);
+  display.drawInvertedBitmap(0, 0, bitmaps->black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
+  if (bitmaps->red == WS_Bitmap3c104x212_red)
+  {
+    display.drawInvertedBitmap(0, 0, bitmaps->red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
+  }
+  else display.drawBitmap(0, 0, bitmaps->red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
+}
+void drawBitmaps3c104x212()
+{
+#if !defined(__AVR)
+  bitmap_pair bitmap_pairs[] =
+  {
+    {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
+    {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
+    {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
+  };
+#else
+  bitmap_pair bitmap_pairs[] =
+  {
+    {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
+    //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
+    {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
+  };
+#endif
+  if (display.epd2.panel == GxEPD2::GDEW0213Z16)
+  {
+    for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
+    {
+      display.drawPaged(drawBitmapPairCallback3c104x212, &bitmap_pairs[i]);
+      delay(2000);
+    }
+  }
+}
+#endif
+
+#ifdef _GxBitmaps3c128x296_H_
+void drawBitmapPairCallback3c128x296(const void* parameters)
+{
+  const bitmap_pair* bitmaps = reinterpret_cast<const bitmap_pair*>(parameters);
+  display.fillScreen(GxEPD_WHITE);
+  display.drawInvertedBitmap(0, 0, bitmaps->black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
+  if (bitmaps->red == WS_Bitmap3c128x296_red)
+  {
+    display.drawInvertedBitmap(0, 0, bitmaps->red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
+  }
+  else display.drawBitmap(0, 0, bitmaps->red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
+}
+void drawBitmaps3c128x296()
+{
+#if !defined(__AVR)
+  bitmap_pair bitmap_pairs[] =
+  {
+    {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
+    {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
+    {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
+  };
+#else
+  bitmap_pair bitmap_pairs[] =
+  {
+    //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
+    //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
+    {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
+  };
+#endif
+  if (display.epd2.panel == GxEPD2::GDEW029Z10)
+  {
+    for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
+    {
+      display.drawPaged(drawBitmapPairCallback3c128x296, &bitmap_pairs[i]);
+      delay(2000);
+    }
+  }
+}
+#endif
+
+#ifdef _GxBitmaps3c176x264_H_
+void drawBitmaps3c176x264()
+{
+  bitmap_pair bitmap_pairs[] =
+  {
+    {Bitmap3c176x264_black, Bitmap3c176x264_red}
+  };
+  if (display.epd2.panel == GxEPD2::GDEW027C44)
+  {
+    for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
+    {
+      display.drawPaged(drawBitmapPairCallback, &bitmap_pairs[i]);
+      delay(2000);
+    }
+  }
+}
+#endif
+
+#ifdef _GxBitmaps3c400x300_H_
+void drawBitmaps3c400x300()
+{
+#if !defined(__AVR)
+  bitmap_pair bitmap_pairs[] =
+  {
+    {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
+    {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
+    {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
+  };
+#else
+  bitmap_pair bitmap_pairs[] = {}; // not enough code space
+#endif
+  if (display.epd2.panel == GxEPD2::GDEW042Z15)
+  {
+    for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
+    {
+      display.drawPaged(drawInvertedBitmapPairCallback, &bitmap_pairs[i]);
+      delay(2000);
+    }
+  }
+}
+#endif
+

+ 22 - 20
examples/GxEPD2_SD_Example/GxEPD2_SD_Example.ino

@@ -74,7 +74,7 @@ SdFat SD;
 //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 // 3-color e-papers
-//GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
+// !!! can't be used for this // GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
 //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
@@ -95,7 +95,7 @@ SdFat SD;
 //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
 //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
 // 3-color e-papers
-//GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
+// !!! can't be used for this //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
 //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
 //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
 //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
@@ -117,7 +117,7 @@ SdFat SD;
 //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
 //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
 // 3-color e-papers
-//GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
+// !!! can't be used for this //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
 //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
 //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
 //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
@@ -126,8 +126,8 @@ SdFat SD;
 #endif
 
 #if defined(_BOARD_GENERIC_STM32F103C_H_)
-#define MAX_DISPAY_BUFFER_SIZE (400 * 300) // ~5k is a good compromise
-#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH)
+#define MAX_DISPAY_BUFFER_SIZE (400 * 300) // ~15k is a good compromise
+#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
 // select one and adapt to your mapping
 //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
@@ -136,17 +136,18 @@ SdFat SD;
 //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 // 3-color e-papers
-//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
-//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+#define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
+// !!! can't be used for this //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
+//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
 #endif
 
 #if defined(__AVR)
-#define MAX_DISPAY_BUFFER_SIZE 1000 // half of available RAM as a compromise
-#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / 8 / EPD::WIDTH)
+#define MAX_DISPAY_BUFFER_SIZE 800 // 
+#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
 // select one and adapt to your mapping
 //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
@@ -155,12 +156,13 @@ SdFat SD;
 //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 // 3-color e-papers
-//GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
-//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+#define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
+// !!! can't be used for this //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
+//GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
 #endif
 
 // function declaration with default parameter
@@ -172,7 +174,7 @@ void setup()
   Serial.println();
   Serial.println("setup");
 
-  display.init();
+  display.init(115200);
 
   Serial.print("Initializing SD card...");
   if (!SD.begin(SD_CS))

+ 9 - 13
src/GxEPD2_3C.h

@@ -31,7 +31,6 @@ class GxEPD2_3C : public Adafruit_GFX
     {
       _page_height = page_height;
       _pages = (HEIGHT / _page_height) + ((HEIGHT % _page_height) > 0);
-      _reverse = (epd2_instance.panel == GxEPD2::GDE0213B1);
       _using_partial_mode = false;
       _current_page = 0;
       setFullWindow();
@@ -63,16 +62,13 @@ class GxEPD2_3C : public Adafruit_GFX
           y = HEIGHT - y - 1;
           break;
       }
+      // transpose partial window to 0,0
+      x -= _pw_x;
+      y -= _pw_y;
       // adjust for current page
       y -= _current_page * _page_height;
-      // adjust for partial window
-      x -= _pw_x;
-      y -= _pw_y % _page_height;
-      if (_reverse) y = _pw_h - y - 1;
       // check if in current page
-      if (y >= _page_height) return;
-      // check if in (partial) window
-      if ((x < 0) || (x >= _pw_w) || (y < 0) || (y >= _pw_h)) return;
+      if ((y < 0) || (y >= _page_height)) return;
       uint16_t i = x / 8 + y * (_pw_w / 8);
       _black_buffer[i] = (_black_buffer[i] | (1 << (7 - x % 8))); // white
       _color_buffer[i] = _color_buffer[i] = (_color_buffer[i] | (1 << (7 - x % 8)));
@@ -149,8 +145,8 @@ class GxEPD2_3C : public Adafruit_GFX
         //Serial.print("  nextPage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(_pw_y); Serial.print(", ");
         //Serial.print(_pw_w); Serial.print(", "); Serial.print(_pw_h); Serial.print(") P"); Serial.println(_current_page);
         uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
-        uint16_t dest_ys = gx_uint16_max(_pw_y, page_ys);
-        uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, page_ye);
+        uint16_t dest_ys = _pw_y + page_ys; // transposed
+        uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
         if (dest_ye > dest_ys)
         {
           //Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
@@ -216,8 +212,8 @@ class GxEPD2_3C : public Adafruit_GFX
         {
           uint16_t page_ys = _current_page * _page_height;
           uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
-          uint16_t dest_ys = gx_uint16_max(_pw_y, page_ys);
-          uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, page_ye);
+          uint16_t dest_ys = _pw_y + page_ys; // transposed
+          uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
           if (dest_ye > dest_ys)
           {
             fillScreen(GxEPD_WHITE);
@@ -355,7 +351,7 @@ class GxEPD2_3C : public Adafruit_GFX
   private:
     uint8_t _black_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
     uint8_t _color_buffer[(GxEPD2_Type::WIDTH / 8) * page_height];
-    bool _using_partial_mode, _second_phase, _mirror, _reverse;
+    bool _using_partial_mode, _second_phase, _mirror;
     uint16_t _width_bytes, _pixel_bytes;
     int16_t _current_page;
     uint16_t _pages, _page_height;

+ 38 - 21
src/GxEPD2_BW.h

@@ -63,16 +63,14 @@ class GxEPD2_BW : public Adafruit_GFX
           y = HEIGHT - y - 1;
           break;
       }
+      // transpose partial window to 0,0
+      x -= _pw_x;
+      y -= _pw_y;
       // adjust for current page
       y -= _current_page * _page_height;
-      // adjust for partial window
-      x -= _pw_x;
-      y -= _pw_y % _page_height;
-      if (_reverse) y = _pw_h - y - 1;
+      if (_reverse) y = _page_height - y - 1;
       // check if in current page
-      if (y >= _page_height) return;
-      // check if in (partial) window
-      if ((x < 0) || (x >= _pw_w) || (y < 0) || (y >= _pw_h)) return;
+      if ((y < 0) || (y >= _page_height)) return;
       uint16_t i = x / 8 + y * (_pw_w / 8);
       if (color)
         _buffer[i] = (_buffer[i] | (1 << (7 - x % 8)));
@@ -142,13 +140,14 @@ class GxEPD2_BW : public Adafruit_GFX
         //Serial.print("  nextPage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(_pw_y); Serial.print(", ");
         //Serial.print(_pw_w); Serial.print(", "); Serial.print(_pw_h); Serial.print(") P"); Serial.println(_current_page);
         uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
-        uint16_t dest_ys = gx_uint16_max(_pw_y, page_ys);
-        uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, page_ye);
+        uint16_t dest_ys = _pw_y + page_ys; // transposed
+        uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
         if (dest_ye > dest_ys)
         {
           //Serial.print("writeImage("); Serial.print(_pw_x); Serial.print(", "); Serial.print(dest_ys); Serial.print(", ");
           //Serial.print(_pw_w); Serial.print(", "); Serial.print(dest_ye - dest_ys); Serial.println(")");
-          epd2.writeImage(_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
+          uint32_t offset = _reverse ? (_page_height - (dest_ye - dest_ys)) * _pw_w / 8 : 0;
+          epd2.writeImage(_buffer + offset, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
         }
         else
         {
@@ -205,20 +204,26 @@ class GxEPD2_BW : public Adafruit_GFX
     {
       if (_using_partial_mode)
       {
-        for (_current_page = 0; _current_page < _pages; _current_page++)
+        for (uint16_t phase = 1; phase <= 2; phase++)
         {
-          uint16_t page_ys = _current_page * _page_height;
-          uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
-          uint16_t dest_ys = gx_uint16_max(_pw_y, page_ys);
-          uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, page_ye);
-          if (dest_ye > dest_ys)
+          for (_current_page = 0; _current_page < _pages; _current_page++)
           {
-            fillScreen(GxEPD_WHITE);
-            drawCallback(pv);
-            epd2.writeImage(_buffer, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
+            uint16_t page_ys = _current_page * _page_height;
+            uint16_t page_ye = _current_page < (_pages - 1) ? page_ys + _page_height : HEIGHT;
+            uint16_t dest_ys = _pw_y + page_ys; // transposed
+            uint16_t dest_ye = gx_uint16_min(_pw_y + _pw_h, _pw_y + page_ye);
+            if (dest_ye > dest_ys)
+            {
+              fillScreen(GxEPD_WHITE);
+              drawCallback(pv);
+              uint32_t offset = _reverse ? (_page_height - (dest_ye - dest_ys)) * _pw_w / 8 : 0;
+              epd2.writeImage(_buffer + offset, _pw_x, dest_ys, _pw_w, dest_ye - dest_ys);
+            }
           }
+          epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
+          if (!epd2.hasFastPartialUpdate) break;
+          // else make both controller buffers have equal content
         }
-        epd2.refresh(_pw_x, _pw_y, _pw_w, _pw_h);
       }
       else
       {
@@ -229,7 +234,19 @@ class GxEPD2_BW : public Adafruit_GFX
           drawCallback(pv);
           epd2.writeImage(_buffer, 0, page_ys, WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
         }
-        epd2.refresh();
+        epd2.refresh(false);
+        if (epd2.hasFastPartialUpdate)
+        {
+          // make both controller buffers have equal content
+          for (_current_page = 0; _current_page < _pages; _current_page++)
+          {
+            uint16_t page_ys = _current_page * _page_height;
+            fillScreen(GxEPD_WHITE);
+            drawCallback(pv);
+            epd2.writeImage(_buffer, 0, page_ys, WIDTH, gx_uint16_min(_page_height, HEIGHT - page_ys));
+          }
+          epd2.refresh(true);
+        }
       }
       _current_page = 0;
     }

+ 21 - 12
src/GxEPD2_EPD.cpp

@@ -12,7 +12,8 @@
 #include "GxEPD2_EPD.h"
 
 GxEPD2_EPD::GxEPD2_EPD(int8_t cs, int8_t dc, int8_t rst, int8_t busy, int8_t busy_level, uint32_t busy_timeout) :
-  _cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout)
+  _cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout), _diag_enabled(false),
+  _spi_settings(4000000, MSBFIRST, SPI_MODE0)
 {
 }
 
@@ -48,17 +49,17 @@ void GxEPD2_EPD::init(uint32_t serial_diag_bitrate)
     pinMode(_busy, INPUT);
   }
   SPI.begin();
-  SPI.setDataMode(SPI_MODE0);
-  SPI.setBitOrder(MSBFIRST);
-#if defined(SPI_HAS_TRANSACTION)
-  // true also for STM32F1xx Boards
-  SPISettings settings(4000000, MSBFIRST, SPI_MODE0);
-  SPI.beginTransaction(settings);
-  SPI.endTransaction();
-  //Serial.println("SPI has Transaction");
-#elif defined(ESP8266) || defined(ESP32)
-  SPI.setFrequency(4000000);
-#endif
+//  SPI.setDataMode(SPI_MODE0);
+//  SPI.setBitOrder(MSBFIRST);
+//#if defined(SPI_HAS_TRANSACTION)
+//  // true also for STM32F1xx Boards
+//  SPISettings settings(4000000, MSBFIRST, SPI_MODE0);
+//  SPI.beginTransaction(settings);
+//  SPI.endTransaction();
+//  //Serial.println("SPI has Transaction");
+//#elif defined(ESP8266) || defined(ESP32)
+//  SPI.setFrequency(4000000);
+//#endif
 }
 
 void GxEPD2_EPD::_waitWhileBusy(const char* comment, uint16_t busy_time)
@@ -95,32 +96,39 @@ void GxEPD2_EPD::_waitWhileBusy(const char* comment, uint16_t busy_time)
 
 void GxEPD2_EPD::_writeCommand(uint8_t c)
 {
+  SPI.beginTransaction(_spi_settings);
   if (_dc >= 0) digitalWrite(_dc, LOW);
   if (_cs >= 0) digitalWrite(_cs, LOW);
   SPI.transfer(c);
   if (_cs >= 0) digitalWrite(_cs, HIGH);
   if (_dc >= 0) digitalWrite(_dc, HIGH);
+  SPI.endTransaction();
 }
 
 void GxEPD2_EPD::_writeData(uint8_t d)
 {
+  SPI.beginTransaction(_spi_settings);
   if (_cs >= 0) digitalWrite(_cs, LOW);
   SPI.transfer(d);
   if (_cs >= 0) digitalWrite(_cs, HIGH);
+  SPI.endTransaction();
 }
 
 void GxEPD2_EPD::_writeData(const uint8_t* data, uint16_t n)
 {
+  SPI.beginTransaction(_spi_settings);
   if (_cs >= 0) digitalWrite(_cs, LOW);
   for (uint8_t i = 0; i < n; i++)
   {
     SPI.transfer(*data++);
   }
   if (_cs >= 0) digitalWrite(_cs, HIGH);
+  SPI.endTransaction();
 }
 
 void GxEPD2_EPD::_writeCommandData(const uint8_t* pCommandData, uint8_t datalen)
 {
+  SPI.beginTransaction(_spi_settings);
   if (_dc >= 0) digitalWrite(_dc, LOW);
   if (_cs >= 0) digitalWrite(_cs, LOW);
   SPI.transfer(*pCommandData++);
@@ -130,6 +138,7 @@ void GxEPD2_EPD::_writeCommandData(const uint8_t* pCommandData, uint8_t datalen)
     SPI.transfer(*pCommandData++);
   }
   if (_cs >= 0) digitalWrite(_cs, HIGH);
+  SPI.endTransaction();
 }
 
 

+ 1 - 0
src/GxEPD2_EPD.h

@@ -81,6 +81,7 @@ class GxEPD2_EPD
     int8_t _cs, _dc, _rst, _busy, _busy_level;
     uint32_t _busy_timeout;
     bool _diag_enabled;
+    SPISettings _spi_settings;
 };
 
 #endif

+ 2 - 0
src/epd3c/GxEPD2_270c.cpp

@@ -208,12 +208,14 @@ void GxEPD2_270c::powerOff()
 
 void GxEPD2_270c::_writeData_nCS(const uint8_t* data, uint16_t n)
 {
+  SPI.beginTransaction(_spi_settings);
   for (uint8_t i = 0; i < n; i++)
   {
     if (_cs >= 0) digitalWrite(_cs, LOW);
     SPI.transfer(*data++);
     if (_cs >= 0) digitalWrite(_cs, HIGH);
   }
+  SPI.endTransaction();
 }
 
 void GxEPD2_270c::_setPartialRamArea_270c(uint8_t cmd, uint16_t x, uint16_t y, uint16_t w, uint16_t h)