From 541623f21acf25986aa897c185e6318cef7b7acd Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 13 Sep 2025 17:24:37 +0200 Subject: [PATCH 01/10] V2 brightness control --- include/graphics/LGFX/LGFX_ELECROW70.h | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index d3f03159..d4000250 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -6,6 +6,8 @@ #include #include +#define ELECROW_V2_ADDR 0x30 + #ifndef FREQ_WRITE #define FREQ_WRITE 14000000 #endif @@ -15,6 +17,8 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device lgfx::Bus_RGB _bus_instance; lgfx::Panel_RGB _panel_instance; lgfx::Touch_GT911 _touch_instance; + uint8_t brightness = 153; + bool isV2 = false; public: const uint16_t screenWidth = 800; @@ -43,9 +47,35 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device delay(100); pinMode(1, INPUT); + // check crowpanel version + Wire.beginTransmission(ELECROW_V2_ADDR); + if (Wire.endTransmission() == 0) { + isV2 = true; + setBrightness(brightness); + } + return LGFX_Device::init_impl(use_reset, use_clear); } + // crowpanel V2 allows 5 brightness levels + // 0: off (0x05) + // 1 .. 51: (0x06) + // 52 .. 102: (0x07) + // 103 .. 154: (0x08) + // 155 .. 206: (0x09) + // 207 .. 255: (0x10) + void setBrightness(uint8_t brightness) + { + if (isV2) { + Wire.beginTransmission(ELECROW_V2_ADDR); + Wire.write((brightness + 50) / 51 + 5); + Wire.endTransmission(); + this->brightness = brightness; + } + } + + uint8_t getBrightness(void) const { return brightness; } + LGFX_ELECROW70(void) { { From b91421f28a69946fe971a637e49e4c7eab31cb16 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 13 Sep 2025 17:31:48 +0200 Subject: [PATCH 02/10] update comment --- include/graphics/LGFX/LGFX_ELECROW70.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index d4000250..e98a11f8 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -61,9 +61,9 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device // 0: off (0x05) // 1 .. 51: (0x06) // 52 .. 102: (0x07) - // 103 .. 154: (0x08) - // 155 .. 206: (0x09) - // 207 .. 255: (0x10) + // 103 .. 153: (0x08) + // 154 .. 204: (0x09) + // 205 .. 255: (0x10) void setBrightness(uint8_t brightness) { if (isV2) { From e71fe455d674d0a758394fc2a2c55cf578ec0088 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sat, 13 Sep 2025 18:08:48 +0200 Subject: [PATCH 03/10] added light() which is used by LGFXdriver --- include/graphics/LGFX/LGFX_ELECROW70.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index e98a11f8..f3fb774e 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -57,6 +57,11 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device return LGFX_Device::init_impl(use_reset, use_clear); } + lgfx::ILight* light(void) const { + static lgfx::Light_PWM light_instance; + return isV2 ? &light_instance : nullptr; // pointer is used by LGFXdriver to check for hasLight() + } + // crowpanel V2 allows 5 brightness levels // 0: off (0x05) // 1 .. 51: (0x06) From f142bdf3efe230f244e9efff65346313a2cb1d7f Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Mon, 15 Sep 2025 18:38:11 +0200 Subject: [PATCH 04/10] update initialisation --- include/graphics/LGFX/LGFX_ELECROW70.h | 68 +++++++++++++++++--------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index f3fb774e..c54f450b 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -6,6 +6,7 @@ #include #include +#define ELECROW_V1_ADDR 0x18 #define ELECROW_V2_ADDR 0x30 #ifndef FREQ_WRITE @@ -20,6 +21,14 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device uint8_t brightness = 153; bool isV2 = false; + // for V2 microcontroller control + uint8_t sendI2CCommand(uint8_t command) + { + Wire.beginTransmission(ELECROW_V2_ADDR); + Wire.write(cmd); + return Wire.endTransmission(); + } + public: const uint16_t screenWidth = 800; const uint16_t screenHeight = 480; @@ -28,28 +37,37 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device bool init_impl(bool use_reset, bool use_clear) override { - ioex.attach(Wire); - ioex.setDeviceAddress(0x18); - ioex.config(1, TCA9534::Config::OUT); - ioex.config(2, TCA9534::Config::OUT); - ioex.config(3, TCA9534::Config::OUT); - ioex.config(4, TCA9534::Config::OUT); + Wire.beginTransmission(ELECROW_V1_ADDR); + if (Wire.endTransmission() == 0) { + ioex.attach(Wire); + ioex.setDeviceAddress(ELECROW_V1_ADDR); + ioex.config(1, TCA9534::Config::OUT); + ioex.config(2, TCA9534::Config::OUT); + ioex.config(3, TCA9534::Config::OUT); + ioex.config(4, TCA9534::Config::OUT); + + ioex.output(1, TCA9534::Level::H); + ioex.output(3, TCA9534::Level::L); + ioex.output(4, TCA9534::Level::H); + + pinMode(1, OUTPUT); + digitalWrite(1, LOW); + ioex.output(2, TCA9534::Level::L); + delay(20); + ioex.output(2, TCA9534::Level::H); + delay(100); + pinMode(1, INPUT); + } - ioex.output(1, TCA9534::Level::H); - ioex.output(3, TCA9534::Level::L); - ioex.output(4, TCA9534::Level::H); - - pinMode(1, OUTPUT); - digitalWrite(1, LOW); - ioex.output(2, TCA9534::Level::L); - delay(20); - ioex.output(2, TCA9534::Level::H); - delay(100); - pinMode(1, INPUT); - - // check crowpanel version Wire.beginTransmission(ELECROW_V2_ADDR); if (Wire.endTransmission() == 0) { + sendI2CCommand(0x19); + pinMode(1, OUTPUT); + digitalWrite(1, LOW); + delay(120); + pinMode(1, INPUT); + delay(100); + isV2 = true; setBrightness(brightness); } @@ -57,14 +75,15 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device return LGFX_Device::init_impl(use_reset, use_clear); } - lgfx::ILight* light(void) const { + lgfx::ILight *light(void) const + { static lgfx::Light_PWM light_instance; return isV2 ? &light_instance : nullptr; // pointer is used by LGFXdriver to check for hasLight() } // crowpanel V2 allows 5 brightness levels // 0: off (0x05) - // 1 .. 51: (0x06) + // 1 .. 51: (0x06) // 52 .. 102: (0x07) // 103 .. 153: (0x08) // 154 .. 204: (0x09) @@ -72,9 +91,10 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device void setBrightness(uint8_t brightness) { if (isV2) { - Wire.beginTransmission(ELECROW_V2_ADDR); - Wire.write((brightness + 50) / 51 + 5); - Wire.endTransmission(); + uint8_t cmd = (brightness + 50) / 51 + 5; + if (brightness >= 205) + cmd = 0x10; + sendI2CCommand(cmd); this->brightness = brightness; } } From 83681f4f1d90fc4bb021f3adf404384f7c9c1d18 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Mon, 15 Sep 2025 18:43:04 +0200 Subject: [PATCH 05/10] add 0x18 command at the end acc. factory example --- include/graphics/LGFX/LGFX_ELECROW70.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index c54f450b..0fc5a564 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -67,6 +67,7 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device delay(120); pinMode(1, INPUT); delay(100); + sendI2CCommand(0x18); isV2 = true; setBrightness(brightness); From 9603b1d37fd8b22ddd5a6ea9352d3bd26020b999 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Tue, 16 Sep 2025 08:26:12 +0200 Subject: [PATCH 06/10] fix error --- include/graphics/LGFX/LGFX_ELECROW70.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index 0fc5a564..a5d2e929 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -22,7 +22,7 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device bool isV2 = false; // for V2 microcontroller control - uint8_t sendI2CCommand(uint8_t command) + uint8_t sendI2CCommand(uint8_t cmd) { Wire.beginTransmission(ELECROW_V2_ADDR); Wire.write(cmd); From c8be3ccd6df3fef977abfd4d16a8f77e8f05f0d5 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Sun, 5 Oct 2025 11:11:07 +0200 Subject: [PATCH 07/10] set brightness after initialization --- include/graphics/LGFX/LGFX_ELECROW70.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index a5d2e929..0737cf7d 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -68,12 +68,10 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device pinMode(1, INPUT); delay(100); sendI2CCommand(0x18); - isV2 = true; - setBrightness(brightness); } - return LGFX_Device::init_impl(use_reset, use_clear); + return LGFX_Device::init_impl(use_reset, use_clear) && setBrightness(brightness); } lgfx::ILight *light(void) const From 816ac867fdc45965da5fba7184d4c24619e81d6b Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Sun, 5 Oct 2025 22:30:19 +0200 Subject: [PATCH 08/10] brightness fix, increase default frequency --- include/graphics/LGFX/LGFX_ELECROW70.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index 0737cf7d..8907d44a 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -10,7 +10,7 @@ #define ELECROW_V2_ADDR 0x30 #ifndef FREQ_WRITE -#define FREQ_WRITE 14000000 +#define FREQ_WRITE 15000000 #endif class LGFX_ELECROW70 : public lgfx::LGFX_Device @@ -71,7 +71,9 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device isV2 = true; } - return LGFX_Device::init_impl(use_reset, use_clear) && setBrightness(brightness); + bool result = LGFX_Device::init_impl(use_reset, use_clear); + setBrightness(brightness); + return result; } lgfx::ILight *light(void) const From 33fae73d0010c7424e95d2ff712dcf459e0f0780 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:18:53 +0200 Subject: [PATCH 09/10] add Elecrow_V2_Light class --- include/graphics/LGFX/LGFX_ELECROW70.h | 131 ++++++++++++++++--------- 1 file changed, 83 insertions(+), 48 deletions(-) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index 8907d44a..250b3db3 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -10,25 +10,82 @@ #define ELECROW_V2_ADDR 0x30 #ifndef FREQ_WRITE -#define FREQ_WRITE 15000000 +#define FREQ_WRITE 16000000 #endif -class LGFX_ELECROW70 : public lgfx::LGFX_Device + +class Elecrow_V2_Light : public lgfx::v1::ILight { - lgfx::Bus_RGB _bus_instance; - lgfx::Panel_RGB _panel_instance; - lgfx::Touch_GT911 _touch_instance; - uint8_t brightness = 153; - bool isV2 = false; + public: + struct config_t { + bool isV2 = false; + bool isV3 = false; + uint8_t brightness = 153; // 60% + }; + + const config_t &config(void) const { return _cfg; } + void config(const config_t &cfg) { _cfg = cfg; } + + bool init(uint8_t brightness) override { + Wire.beginTransmission(ELECROW_V2_ADDR); + if (Wire.endTransmission() == 0) { + sendI2CCommand(0x08); + _cfg.isV2 = true; + } + return true; + } + + // crowpanel V2 allows 5 brightness levels + // 0: off (0x05) + // 1 .. 51: (0x06) + // 52 .. 102: (0x07) + // 103 .. 153: (0x08) + // 154 .. 204: (0x09) + // 205 .. 255: (0x10) + // crowpanel V3 has level 0 (brightest) .. 245 (off) + void setBrightness(uint8_t brightness) override + { + if (_cfg.isV2) { + uint8_t cmd = (brightness + 50) / 51 + 5; + if (brightness >= 205) + cmd = 0x10; + sendI2CCommand(cmd); + _cfg.brightness = brightness; + } + else if (_cfg.isV3) { + uint8_t brightnessV3 = 244 - (uint32_t(brightness) * 244 / 255); + sendI2CCommand(brightnessV3); + } + _cfg.brightness = brightness; + } + + uint8_t getBrightness(void) const { return _cfg.brightness; } + + virtual ~Elecrow_V2_Light(void) = default; - // for V2 microcontroller control + private: + // for V2/V3 microcontroller control uint8_t sendI2CCommand(uint8_t cmd) { Wire.beginTransmission(ELECROW_V2_ADDR); Wire.write(cmd); - return Wire.endTransmission(); + uint8_t error = Wire.endTransmission(); + if (error != 0) + ILOG_ERROR("failed to send command 0x%02x: %d", cmd, error); + return error; } + config_t _cfg; +}; + + +class LGFX_ELECROW70 : public lgfx::LGFX_Device +{ + lgfx::Bus_RGB _bus_instance; + lgfx::Panel_RGB _panel_instance; + lgfx::Touch_GT911 _touch_instance; + Elecrow_V2_Light _light_instance; + public: const uint16_t screenWidth = 800; const uint16_t screenHeight = 480; @@ -59,49 +116,15 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device pinMode(1, INPUT); } - Wire.beginTransmission(ELECROW_V2_ADDR); - if (Wire.endTransmission() == 0) { - sendI2CCommand(0x19); - pinMode(1, OUTPUT); - digitalWrite(1, LOW); - delay(120); - pinMode(1, INPUT); - delay(100); - sendI2CCommand(0x18); - isV2 = true; - } - - bool result = LGFX_Device::init_impl(use_reset, use_clear); - setBrightness(brightness); - return result; + return LGFX_Device::init_impl(use_reset, use_clear); } lgfx::ILight *light(void) const { - static lgfx::Light_PWM light_instance; - return isV2 ? &light_instance : nullptr; // pointer is used by LGFXdriver to check for hasLight() + // pointer is used by LGFXDriver to check for hasLight() + return _light_instance.config().isV2 || _light_instance.config().isV3 ? (lgfx::ILight *)&_light_instance : nullptr; } - // crowpanel V2 allows 5 brightness levels - // 0: off (0x05) - // 1 .. 51: (0x06) - // 52 .. 102: (0x07) - // 103 .. 153: (0x08) - // 154 .. 204: (0x09) - // 205 .. 255: (0x10) - void setBrightness(uint8_t brightness) - { - if (isV2) { - uint8_t cmd = (brightness + 50) / 51 + 5; - if (brightness >= 205) - cmd = 0x10; - sendI2CCommand(cmd); - this->brightness = brightness; - } - } - - uint8_t getBrightness(void) const { return brightness; } - LGFX_ELECROW70(void) { { @@ -188,18 +211,30 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device _panel_instance.setTouch(&_touch_instance); } + // Set the backlight control + { + auto cfg = _light_instance.config(); + _light_instance.config(cfg); + _panel_instance.setLight(&_light_instance); + } + setPanel(&_panel_instance); } void sleep(void) { - ioex.output(1, TCA9534::Level::L); + if (!_light_instance.config().isV2 && !_light_instance.config().isV3) { + ioex.output(1, TCA9534::Level::L); + } _panel->setSleep(true); } + void wakeup(void) { - ioex.output(1, TCA9534::Level::H); _panel->setSleep(false); + if (!_light_instance.config().isV2 &&!_light_instance.config().isV3) { + ioex.output(1, TCA9534::Level::H); + } } private: From a4fb22ff4e636176e77cc6f44eceba84c411710f Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Sat, 11 Oct 2025 23:29:46 +0200 Subject: [PATCH 10/10] send 0x10 to enable V2 display --- include/graphics/LGFX/LGFX_ELECROW70.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/include/graphics/LGFX/LGFX_ELECROW70.h b/include/graphics/LGFX/LGFX_ELECROW70.h index 250b3db3..a9b8e8d4 100644 --- a/include/graphics/LGFX/LGFX_ELECROW70.h +++ b/include/graphics/LGFX/LGFX_ELECROW70.h @@ -13,7 +13,6 @@ #define FREQ_WRITE 16000000 #endif - class Elecrow_V2_Light : public lgfx::v1::ILight { public: @@ -26,10 +25,11 @@ class Elecrow_V2_Light : public lgfx::v1::ILight const config_t &config(void) const { return _cfg; } void config(const config_t &cfg) { _cfg = cfg; } - bool init(uint8_t brightness) override { + bool init(uint8_t brightness) override + { Wire.beginTransmission(ELECROW_V2_ADDR); if (Wire.endTransmission() == 0) { - sendI2CCommand(0x08); + sendI2CCommand(0x10); _cfg.isV2 = true; } return true; @@ -50,9 +50,8 @@ class Elecrow_V2_Light : public lgfx::v1::ILight if (brightness >= 205) cmd = 0x10; sendI2CCommand(cmd); - _cfg.brightness = brightness; - } - else if (_cfg.isV3) { + _cfg.brightness = brightness; + } else if (_cfg.isV3) { uint8_t brightnessV3 = 244 - (uint32_t(brightness) * 244 / 255); sendI2CCommand(brightnessV3); } @@ -78,7 +77,6 @@ class Elecrow_V2_Light : public lgfx::v1::ILight config_t _cfg; }; - class LGFX_ELECROW70 : public lgfx::LGFX_Device { lgfx::Bus_RGB _bus_instance; @@ -232,7 +230,7 @@ class LGFX_ELECROW70 : public lgfx::LGFX_Device void wakeup(void) { _panel->setSleep(false); - if (!_light_instance.config().isV2 &&!_light_instance.config().isV3) { + if (!_light_instance.config().isV2 && !_light_instance.config().isV3) { ioex.output(1, TCA9534::Level::H); } }