From c6d2fa7097cb45e76751c757221cdc52b371669f Mon Sep 17 00:00:00 2001 From: Todd Herbert Date: Sat, 29 Jul 2023 23:21:58 +1200 Subject: [PATCH] refactor: store LUTs in PROGMEM --- src/Displays/DEPG0150BNS810/DEPG0150BNS810.h | 3 +-- src/Displays/DEPG0150BNS810/hardware.cpp | 22 ++++++++++++-------- src/Displays/DEPG0154BNS800/DEPG0154BNS800.h | 5 ++--- src/Displays/DEPG0154BNS800/hardware.cpp | 20 +++++++++++------- src/Displays/DEPG0290BNS75A/DEPG0290BNS75A.h | 2 +- src/Displays/DEPG0290BNS75A/hardware.cpp | 8 +++++-- src/Displays/DEPG0290BNS800/DEPG0290BNS800.h | 2 +- src/Displays/DEPG0290BNS800/hardware.cpp | 6 +++++- src/Displays/GDE029A1/GDE029A1.h | 4 ++-- src/Displays/GDE029A1/hardware.cpp | 9 ++++++-- src/Displays/GDEP015OC1/GDEP015OC1.h | 4 ++-- src/Displays/GDEP015OC1/hardware.cpp | 9 ++++++-- 12 files changed, 59 insertions(+), 35 deletions(-) diff --git a/src/Displays/DEPG0150BNS810/DEPG0150BNS810.h b/src/Displays/DEPG0150BNS810/DEPG0150BNS810.h index 4d6a720..e093228 100644 --- a/src/Displays/DEPG0150BNS810/DEPG0150BNS810.h +++ b/src/Displays/DEPG0150BNS810/DEPG0150BNS810.h @@ -18,7 +18,7 @@ class DEPG0150BNS810 : public GFX { // Look Up Table for the "partial refresh" operation // Modified from original Heltec source - const unsigned char lut_partial[159] = { + PROGMEM static constexpr uint8_t lut_partial[153] = { 0x40,0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x40,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, @@ -38,7 +38,6 @@ class DEPG0150BNS810 : public GFX { 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0, - 0x02,0x17,0x41,0xB0,0x32,0x28, }; diff --git a/src/Displays/DEPG0150BNS810/hardware.cpp b/src/Displays/DEPG0150BNS810/hardware.cpp index 7c29c8d..a6d2a6a 100644 --- a/src/Displays/DEPG0150BNS810/hardware.cpp +++ b/src/Displays/DEPG0150BNS810/hardware.cpp @@ -1,5 +1,9 @@ #include "DEPG0150BNS810.h" +// Out-of-line definition for LUT +// Required for an in-class PROGMEM definition +PROGMEM constexpr uint8_t DEPG0150BNS810::lut_partial[]; + // Constructor DEPG0150BNS810::DEPG0150BNS810( uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t page_height) : GFX(panel_width, panel_height) { @@ -154,23 +158,23 @@ void DEPG0150BNS810::setFastmode(FastmodeList::Fastmode mode) { // ----------------------------------------------- unsigned char count; sendCommand(0x32); // "LUT" - for(count=0;count<153;count++) - sendData(lut_partial[count]); + for(count=0; count < sizeof(lut_partial); count++) + sendData(pgm_read_byte_near(lut_partial + count)); wait(); sendCommand(0x3F); // "Option for LUT end" - sendData(lut_partial[153]); + sendData(0x02); sendCommand(0x03); // "Gate voltage" - sendData(lut_partial[154]); + sendData(0x17); sendCommand(0x04); // "Source voltage" - sendData(lut_partial[155]); - sendData(lut_partial[156]); - sendData(lut_partial[157]); + sendData(0x41); + sendData(0xB0); + sendData(0x32); - sendCommand(0x2C); // allegedly: vcom - sendData(lut_partial[158]); + sendCommand(0x2C); // vcom + sendData(0x28); sendCommand(0x37); // "Write Register for Display Option" sendData(0x00); // Heltec comment: "Local flash function is enabled, pingpong mode is enabled" diff --git a/src/Displays/DEPG0154BNS800/DEPG0154BNS800.h b/src/Displays/DEPG0154BNS800/DEPG0154BNS800.h index 248e5e3..109f8db 100644 --- a/src/Displays/DEPG0154BNS800/DEPG0154BNS800.h +++ b/src/Displays/DEPG0154BNS800/DEPG0154BNS800.h @@ -18,7 +18,7 @@ class DEPG0154BNS800 : public GFX { // Look Up Table for the "partial refresh" operation // Unmodified from Heltec source - const unsigned char lut_partial[159] = { + PROGMEM static constexpr uint8_t lut_partial[153] = { 0x0,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x80,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x40,0x40,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, @@ -36,8 +36,7 @@ class DEPG0154BNS800 : public GFX { 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0, - 0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0, - 0x02,0x17,0x41,0xB0,0x32,0x28 + 0x22,0x22,0x22,0x22,0x22,0x22,0x0,0x0,0x0 }; diff --git a/src/Displays/DEPG0154BNS800/hardware.cpp b/src/Displays/DEPG0154BNS800/hardware.cpp index 7bd8e39..fbfb95d 100644 --- a/src/Displays/DEPG0154BNS800/hardware.cpp +++ b/src/Displays/DEPG0154BNS800/hardware.cpp @@ -1,5 +1,9 @@ #include "DEPG0154BNS800.h" +// Out-of-line definition for LUT +// Required for an in-class PROGMEM definition +PROGMEM constexpr uint8_t DEPG0154BNS800::lut_partial[]; + // Constructor DEPG0154BNS800::DEPG0154BNS800(uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t page_height) : GFX(panel_width, panel_height) { @@ -154,23 +158,23 @@ void DEPG0154BNS800::setFastmode(FastmodeList::Fastmode mode) { // ----------------------------------------------- unsigned char count; sendCommand(0x32); // "LUT" - for(count=0;count<153;count++) - sendData(lut_partial[count]); + for(count=0; count < sizeof(lut_partial); count++) + sendData(pgm_read_byte_near(lut_partial + count)); wait(); sendCommand(0x3F); // "Option for LUT end" - sendData(lut_partial[153]); + sendData(0x02); sendCommand(0x03); // "Gate voltage" - sendData(lut_partial[154]); + sendData(0x17); sendCommand(0x04); // "Source voltage" - sendData(lut_partial[155]); - sendData(lut_partial[156]); - sendData(lut_partial[157]); + sendData(0x41); + sendData(0xB0); + sendData(0x32); sendCommand(0x2C); // allegedly: vcom - sendData(lut_partial[158]); + sendData(0x28); sendCommand(0x37); // "Write Register for Display Option" sendData(0x00); // Heltec comment: "Local flash function is enabled, pingpong mode is enabled" diff --git a/src/Displays/DEPG0290BNS75A/DEPG0290BNS75A.h b/src/Displays/DEPG0290BNS75A/DEPG0290BNS75A.h index a9782a7..1b99eac 100644 --- a/src/Displays/DEPG0290BNS75A/DEPG0290BNS75A.h +++ b/src/Displays/DEPG0290BNS75A/DEPG0290BNS75A.h @@ -18,7 +18,7 @@ class DEPG0290BNS75A : public GFX { // Look Up Table for the "partial refresh" operation // Composite of data from ZinggJM/GxEPD2 - const unsigned char lut_partial[70] = { + PROGMEM static constexpr uint8_t lut_partial[70] = { 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, //LUT0: BB: VS 0 ~7 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, //LUT1: BW: VS 0 ~7 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, //LUT2: WB: VS 0 ~7 diff --git a/src/Displays/DEPG0290BNS75A/hardware.cpp b/src/Displays/DEPG0290BNS75A/hardware.cpp index d123274..1cfd2ad 100644 --- a/src/Displays/DEPG0290BNS75A/hardware.cpp +++ b/src/Displays/DEPG0290BNS75A/hardware.cpp @@ -1,5 +1,9 @@ #include "DEPG0290BNS75A.h" +// Out-of-line definition for LUT +// Required for an in-class PROGMEM definition +PROGMEM constexpr uint8_t DEPG0290BNS75A::lut_partial[]; + // Have to initialize because of GFX class DEPG0290BNS75A::DEPG0290BNS75A( uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t page_height) : GFX(panel_width, panel_height) { // Store the config @@ -195,8 +199,8 @@ void DEPG0290BNS75A::setFastmode(FastmodeList::Fastmode mode) { // Load the fastmode lut sendCommand(0x32); - for(uint8_t i=0;i < sizeof(lut_partial); i++) - sendData(lut_partial[i]); + for(uint8_t i=0;i < sizeof(lut_partial); i++) + sendData(pgm_read_byte_near(lut_partial + i)); wait(); diff --git a/src/Displays/DEPG0290BNS800/DEPG0290BNS800.h b/src/Displays/DEPG0290BNS800/DEPG0290BNS800.h index dbd8946..67e54e3 100644 --- a/src/Displays/DEPG0290BNS800/DEPG0290BNS800.h +++ b/src/Displays/DEPG0290BNS800/DEPG0290BNS800.h @@ -18,7 +18,7 @@ class DEPG0290BNS800 : public GFX { // Look Up Table for the "partial refresh" operation // Modified from Heltec source - const unsigned char lut_partial[153] = { + PROGMEM static constexpr uint8_t lut_partial[153] = { 0x40, 0x0, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, diff --git a/src/Displays/DEPG0290BNS800/hardware.cpp b/src/Displays/DEPG0290BNS800/hardware.cpp index 42f732e..51d97f5 100644 --- a/src/Displays/DEPG0290BNS800/hardware.cpp +++ b/src/Displays/DEPG0290BNS800/hardware.cpp @@ -1,5 +1,9 @@ #include "DEPG0290BNS800.h" +// Out-of-line definition for LUT +// Required for an in-class PROGMEM definition +PROGMEM constexpr uint8_t DEPG0290BNS800::lut_partial[]; + // Have to initialize because of GFX class DEPG0290BNS800::DEPG0290BNS800( uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t page_height) : GFX(panel_width, panel_height) { // Store the config @@ -159,7 +163,7 @@ void DEPG0290BNS800::setFastmode(FastmodeList::Fastmode mode) { // Load the fastmode lut sendCommand(0x32); for(uint8_t i=0;i < sizeof(lut_partial); i++) - sendData(lut_partial[i]); + sendData(pgm_read_byte_near(lut_partial+i)); wait(); diff --git a/src/Displays/GDE029A1/GDE029A1.h b/src/Displays/GDE029A1/GDE029A1.h index a1653e7..3e9248f 100644 --- a/src/Displays/GDE029A1/GDE029A1.h +++ b/src/Displays/GDE029A1/GDE029A1.h @@ -19,14 +19,14 @@ class GDE029A1 : public GFX { // Look Up Table for both "refresh" operations // lut_full operation lengthened slightly, to prevent ghost images forming // From Heltec source - const unsigned char lut_full[30] = { + PROGMEM static constexpr uint8_t lut_full[30] = { 0x50, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00 }; - const unsigned char lut_partial[30] = { + PROGMEM static constexpr uint8_t lut_partial[30] = { 0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/Displays/GDE029A1/hardware.cpp b/src/Displays/GDE029A1/hardware.cpp index b822fdc..20b7eed 100644 --- a/src/Displays/GDE029A1/hardware.cpp +++ b/src/Displays/GDE029A1/hardware.cpp @@ -1,5 +1,10 @@ #include "GDE029A1.h" +// Out-of-line definition for LUT +// Required for an in-class PROGMEM definition +PROGMEM constexpr uint8_t GDE029A1::lut_full[]; +PROGMEM constexpr uint8_t GDE029A1::lut_partial[]; + // Constructor GDE029A1::GDE029A1( uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t page_height) : GFX(panel_width, panel_height) { // Store the config @@ -161,7 +166,7 @@ void GDE029A1::reset() { // Load the Look Up Table (LUT) for full update sendCommand(0x32); for(uint8_t i=0;i < sizeof(lut_full); i++) - sendData(lut_full[i]); + sendData(pgm_read_byte_near(lut_full + i)); wait(); } @@ -224,7 +229,7 @@ void GDE029A1::setFastmode(FastmodeList::Fastmode mode) { // Load the LUT for partial update sendCommand(0x32); for(uint8_t i=0;i < sizeof(lut_partial); i++) - sendData(lut_partial[i]); + sendData(pgm_read_byte_near(lut_partial + i)); wait(); diff --git a/src/Displays/GDEP015OC1/GDEP015OC1.h b/src/Displays/GDEP015OC1/GDEP015OC1.h index 6d650ca..0b702d2 100644 --- a/src/Displays/GDEP015OC1/GDEP015OC1.h +++ b/src/Displays/GDEP015OC1/GDEP015OC1.h @@ -18,14 +18,14 @@ class GDEP015OC1 : public GFX { // Look Up Table for "refresh" operations // Unmodified from Heltec source - const unsigned char lut_full[30] = { + PROGMEM static constexpr uint8_t lut_full[30] = { 0x50, 0xAA, 0x55, 0xAA, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - const unsigned char lut_partial[30] = { + PROGMEM static constexpr uint8_t lut_partial[30] = { 0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/Displays/GDEP015OC1/hardware.cpp b/src/Displays/GDEP015OC1/hardware.cpp index d60994f..4b62054 100644 --- a/src/Displays/GDEP015OC1/hardware.cpp +++ b/src/Displays/GDEP015OC1/hardware.cpp @@ -1,5 +1,10 @@ #include "GDEP015OC1.h" +// Out-of-line definition for LUT +// Required for an in-class PROGMEM definition +PROGMEM constexpr uint8_t GDEP015OC1::lut_full[]; +PROGMEM constexpr uint8_t GDEP015OC1::lut_partial[]; + // Constructor GDEP015OC1::GDEP015OC1( uint8_t pin_dc, uint8_t pin_cs, uint8_t pin_busy, uint8_t page_height) : GFX(panel_width, panel_height) { // Store the config @@ -164,7 +169,7 @@ void GDEP015OC1::reset() { // Load the Look Up Table (LUT) for full update sendCommand(0x32); for(uint8_t i=0;i < sizeof(lut_full); i++) - sendData(lut_full[i]); + sendData(pgm_read_byte_near(lut_full + i)); wait(); } @@ -227,7 +232,7 @@ void GDEP015OC1::setFastmode(FastmodeList::Fastmode mode) { // Load the LUT for partial update sendCommand(0x32); for(uint8_t i=0;i < sizeof(lut_partial); i++) - sendData(lut_partial[i]); + sendData(pgm_read_byte_near(lut_partial + i)); wait();