From 13c1c02d666b96bb989e586d44aef6c4eb89eba5 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sun, 3 Apr 2022 01:38:46 +0200 Subject: [PATCH] Add backlight_invert --- src/dev/device.h | 6 ++++ src/dev/esp32/esp32.cpp | 62 +++++++++++++++++++++--------------- src/dev/esp32/esp32.h | 2 ++ src/dev/esp8266/esp8266.cpp | 11 +++++++ src/dev/esp8266/esp8266.h | 2 ++ src/dev/posix/hasp_posix.cpp | 11 +++++++ src/dev/posix/hasp_posix.h | 2 ++ src/dev/stm32f4/stm32f4.cpp | 11 +++++++ src/dev/stm32f4/stm32f4.h | 2 ++ src/dev/stm32f7/stm32f7.cpp | 15 +++++++-- src/dev/stm32f7/stm32f7.h | 4 ++- src/dev/win32/hasp_win32.cpp | 11 +++++++ src/dev/win32/hasp_win32.h | 2 ++ 13 files changed, 113 insertions(+), 28 deletions(-) diff --git a/src/dev/device.h b/src/dev/device.h index 4e87240d..32ad1dc7 100644 --- a/src/dev/device.h +++ b/src/dev/device.h @@ -77,6 +77,8 @@ class BaseDevice { {} virtual void set_backlight_pin(uint8_t pin) {} + virtual void set_backlight_invert(bool override) + {} virtual void set_backlight_level(uint8_t level) {} virtual uint8_t get_backlight_level() @@ -85,6 +87,10 @@ class BaseDevice { } virtual void set_backlight_power(bool power) {} + virtual bool get_backlight_invert() + { + return false; + } virtual bool get_backlight_power() { return true; diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index 4d77075a..b41838f2 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -197,6 +197,17 @@ void Esp32Device::set_backlight_pin(uint8_t pin) } } +void Esp32Device::set_backlight_invert(bool invert) +{ + _backlight_invert = invert; + update_backlight(); +} + +bool Esp32Device::get_backlight_invert() +{ + return _backlight_invert; +} + void Esp32Device::set_backlight_level(uint8_t level) { _backlight_level = level; @@ -229,7 +240,7 @@ void Esp32Device::update_backlight() #else uint32_t duty = _backlight_power ? map(_backlight_level, 0, 255, 0, 1023) : 0; if(_backlight_invert) duty = 1023 - duty; - ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value + ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value #endif } @@ -283,31 +294,32 @@ uint16_t Esp32Device::get_cpu_frequency() bool Esp32Device::is_system_pin(uint8_t pin) { - //Also see esp32.cpp / hasp_gpio.cpp - #if defined(ESP32S2) //Arduino NUM_DIGITAL_PINS = 48 (but espressif says it only has 46) - //From https://hggh.github.io/esp32/2021/01/06/ESP32-S2-pinout.html, it looks like IO26 is for PSRAM - //More info https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/_images/esp32-s2_saola1-pinout.jpg - //Datasheet https://www.espressif.com/sites/default/files/documentation/esp32-s2-wroom_esp32-s2-wroom-i_datasheet_en.pdf +// Also see esp32.cpp / hasp_gpio.cpp +#if defined(ESP32S2) // Arduino NUM_DIGITAL_PINS = 48 (but espressif says it only has 46) + // From https://hggh.github.io/esp32/2021/01/06/ESP32-S2-pinout.html, it looks like IO26 is for PSRAM + // More info https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/_images/esp32-s2_saola1-pinout.jpg + // Datasheet + // https://www.espressif.com/sites/default/files/documentation/esp32-s2-wroom_esp32-s2-wroom-i_datasheet_en.pdf - //From the ESP32S2-Wroom pdf, the flash appears to be on the upper set of IO. - //SPICS0 = IO10 or IO34 ? - //SPICLK = IO12 or IO36 - //SPIHD = IO9 or IO33 - //SPID = IO11 or IO35 - //SPIQ = IO13 or IO37 - //SPIWP = IO14 or IO38 - if((pin >= 33) && (pin <= 38)) return true; // SPI flash + // From the ESP32S2-Wroom pdf, the flash appears to be on the upper set of IO. + // SPICS0 = IO10 or IO34 ? + // SPICLK = IO12 or IO36 + // SPIHD = IO9 or IO33 + // SPID = IO11 or IO35 + // SPIQ = IO13 or IO37 + // SPIWP = IO14 or IO38 + if((pin >= 33) && (pin <= 38)) return true; // SPI flash - if(psramFound()) { - if((pin == 26) ) return true; // PSRAM. IO26 = SPICS1, the rest are shared with the flash - } - #else - if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash - if((pin == 37) || (pin == 38)) return true; // unavailable - if(psramFound()) { - if((pin == 16) || (pin == 17)) return true; // PSRAM - } - #endif + if(psramFound()) { + if((pin == 26)) return true; // PSRAM. IO26 = SPICS1, the rest are shared with the flash + } +#else + if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash + if((pin == 37) || (pin == 38)) return true; // unavailable + if(psramFound()) { + if((pin == 16) || (pin == 17)) return true; // PSRAM + } +#endif return false; } @@ -360,7 +372,7 @@ long Esp32Device::get_uptime() // #warning Building for Lanbon L8 #include "dev/esp32/lanbonl8.h" #elif defined(M5STACK) - // #warning Building for M5Stack core2 + // #warning Building for M5Stack core2 #include "dev/esp32/m5stackcore2.h" #else dev::Esp32Device haspDevice; diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 71fc307c..61b80e7a 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -40,9 +40,11 @@ class Esp32Device : public BaseDevice { const char* get_hardware_id(); void set_backlight_pin(uint8_t pin) override; + void set_backlight_invert(bool invert) override; void set_backlight_level(uint8_t val) override; uint8_t get_backlight_level() override; void set_backlight_power(bool power) override; + bool get_backlight_invert() override; bool get_backlight_power() override; size_t get_free_max_block() override; diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index 48c799b0..be671830 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -82,6 +82,17 @@ void Esp8266Device::set_backlight_pin(uint8_t pin) } } +void Esp8266Device::set_backlight_invert(bool invert) +{ + _backlight_invert = invert; + update_backlight(); +} + +bool Esp8266Device::get_backlight_invert() +{ + return _backlight_invert; +} + void Esp8266Device::set_backlight_level(uint8_t level) { _backlight_level = level; diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 9f5ee144..04087798 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -26,9 +26,11 @@ class Esp8266Device : public BaseDevice { const char* get_hardware_id(); void set_backlight_pin(uint8_t pin) override; + void set_backlight_invert(bool invert) override; void set_backlight_level(uint8_t val) override; uint8_t get_backlight_level() override; void set_backlight_power(bool power) override; + bool get_backlight_invert() override; bool get_backlight_power() override; size_t get_free_max_block() override; diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index d6eec80e..a70ff4e2 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -105,6 +105,17 @@ void PosixDevice::set_backlight_pin(uint8_t pin) // PosixDevice::backlight_pin = pin; } +void PosixDevice::set_backlight_invert(bool invert) +{ + _backlight_invert = invert; + update_backlight(); +} + +bool PosixDevice::get_backlight_invert() +{ + return _backlight_invert; +} + void PosixDevice::set_backlight_level(uint8_t level) { uint8_t new_level = level; diff --git a/src/dev/posix/hasp_posix.h b/src/dev/posix/hasp_posix.h index 98b5d9e5..9dc8ad9f 100644 --- a/src/dev/posix/hasp_posix.h +++ b/src/dev/posix/hasp_posix.h @@ -41,9 +41,11 @@ class PosixDevice : public BaseDevice { const char* get_hardware_id(); void set_backlight_pin(uint8_t pin); + void set_backlight_invert(bool invert) override; void set_backlight_level(uint8_t val); uint8_t get_backlight_level(); void set_backlight_power(bool power); + bool get_backlight_invert() override; bool get_backlight_power(); size_t get_free_max_block(); diff --git a/src/dev/stm32f4/stm32f4.cpp b/src/dev/stm32f4/stm32f4.cpp index 00a25235..d735891a 100644 --- a/src/dev/stm32f4/stm32f4.cpp +++ b/src/dev/stm32f4/stm32f4.cpp @@ -77,6 +77,17 @@ const char* Stm32f4Device::get_chip_model() #endif } +void Stm32f4Device::set_backlight_invert(bool invert) +{ + _backlight_invert = invert; + update_backlight(); +} + +bool Stm32f4Device::get_backlight_invert() +{ + return _backlight_invert; +} + void Stm32f4Device::set_backlight_level(uint8_t level) { _backlight_level = level; diff --git a/src/dev/stm32f4/stm32f4.h b/src/dev/stm32f4/stm32f4.h index cffcf426..89af1699 100644 --- a/src/dev/stm32f4/stm32f4.h +++ b/src/dev/stm32f4/stm32f4.h @@ -33,9 +33,11 @@ class Stm32f4Device : public BaseDevice { const char* get_hardware_id(); void set_backlight_pin(uint8_t pin) override; + void set_backlight_invert(bool invert) override; void set_backlight_level(uint8_t val) override; uint8_t get_backlight_level() override; void set_backlight_power(bool power) override; + bool get_backlight_invert() override; bool get_backlight_power() override; size_t get_free_max_block() override; diff --git a/src/dev/stm32f7/stm32f7.cpp b/src/dev/stm32f7/stm32f7.cpp index b3eab8d2..11497812 100644 --- a/src/dev/stm32f7/stm32f7.cpp +++ b/src/dev/stm32f7/stm32f7.cpp @@ -12,9 +12,9 @@ #define BACKLIGHT_CHANNEL 0 -int _gettimeofday(struct timeval *tv, struct timezone *tz) +int _gettimeofday(struct timeval* tv, struct timezone* tz) { - return 0; + return 0; } namespace dev { @@ -82,6 +82,17 @@ const char* Stm32f7Device::get_chip_model() #endif } +void Stm32f7Device::set_backlight_invert(bool invert) +{ + _backlight_invert = invert; + update_backlight(); +} + +bool Stm32f7Device::get_backlight_invert() +{ + return _backlight_invert; +} + void Stm32f7Device::set_backlight_level(uint8_t level) { _backlight_level = level; diff --git a/src/dev/stm32f7/stm32f7.h b/src/dev/stm32f7/stm32f7.h index a2bfd0ad..1254acb5 100644 --- a/src/dev/stm32f7/stm32f7.h +++ b/src/dev/stm32f7/stm32f7.h @@ -9,7 +9,7 @@ #if defined(STM32F7xx) extern "C" { - int _gettimeofday(struct timeval *tv, struct timezone *tz); +int _gettimeofday(struct timeval* tv, struct timezone* tz); } namespace dev { @@ -36,9 +36,11 @@ class Stm32f7Device : public BaseDevice { const char* get_hardware_id(); void set_backlight_pin(uint8_t pin) override; + void set_backlight_invert(bool invert) override; void set_backlight_level(uint8_t val) override; uint8_t get_backlight_level() override; void set_backlight_power(bool power) override; + bool get_backlight_invert() override; bool get_backlight_power() override; size_t get_free_max_block() override; diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index f82e0710..61fce87d 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -71,6 +71,17 @@ void Win32Device::set_backlight_pin(uint8_t pin) // Win32Device::_backlight_pin = pin; } +void Win32Device::set_backlight_invert(bool invert) +{ + _backlight_invert = invert; + update_backlight(); +} + +bool Win32Device::get_backlight_invert() +{ + return _backlight_invert; +} + void Win32Device::set_backlight_level(uint8_t level) { uint8_t new_level = level; diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index b50bc61f..3c2edb23 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -62,9 +62,11 @@ class Win32Device : public BaseDevice { const char* get_hardware_id(); void set_backlight_pin(uint8_t pin); + void set_backlight_invert(bool invert) override; void set_backlight_level(uint8_t val); uint8_t get_backlight_level(); void set_backlight_power(bool power); + bool get_backlight_invert() override; bool get_backlight_power(); size_t get_free_max_block();