From 2adff0f1af89cc9714646c8a9e2a52ff15c42538 Mon Sep 17 00:00:00 2001 From: paul Date: Mon, 11 Sep 2023 23:56:33 -0400 Subject: [PATCH 1/3] fix backlight --- Platformio/HAL/Targets/ESP32/HardwareRevX.cpp | 47 ++----------------- Platformio/HAL/Targets/ESP32/HardwareRevX.hpp | 1 - .../HAL/Targets/ESP32/display/display.cpp | 41 +++++++++++++--- .../HAL/Targets/ESP32/display/display.hpp | 1 + 4 files changed, 39 insertions(+), 51 deletions(-) diff --git a/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp index af34996..aa08903 100644 --- a/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp +++ b/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp @@ -1,7 +1,6 @@ #include "HardwareRevX.hpp" #include "display.hpp" #include "wifihandler.hpp" -#include "driver/ledc.h" std::shared_ptr HardwareRevX::mInstance = nullptr; @@ -70,19 +69,17 @@ HardwareRevX::WakeReason getWakeReason() { void HardwareRevX::init() { // Make sure ESP32 is running at full speed setCpuFrequencyMhz(240); + wakeup_reason = getWakeReason(); + initIO(); + Serial.begin(115200); mDisplay = Display::getInstance(); mBattery = std::make_shared(ADC_BAT,CRG_STAT); mWifiHandler = wifiHandler::getInstance(); + restorePreferences(); mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;}); - wakeup_reason = getWakeReason(); - initIO(); - setupBacklight(); - Serial.begin(115200); - restorePreferences(); - slowDisplayWakeup(); setupIMU(); setupIR(); @@ -254,29 +251,6 @@ void HardwareRevX::configIMUInterrupts() { IMU.writeRegister(LIS3DH_CTRL_REG3, dataToWrite); } -// TODO move to display -void HardwareRevX::setupBacklight() { - // Configure the backlight PWM - // Manual setup because ledcSetup() briefly turns on the backlight - ledc_channel_config_t ledc_channel_left; - ledc_channel_left.gpio_num = (gpio_num_t)LCD_BL; - ledc_channel_left.speed_mode = LEDC_HIGH_SPEED_MODE; - ledc_channel_left.channel = LEDC_CHANNEL_5; - ledc_channel_left.intr_type = LEDC_INTR_DISABLE; - ledc_channel_left.timer_sel = LEDC_TIMER_1; - ledc_channel_left.flags.output_invert = 1; // Can't do this with ledcSetup() - ledc_channel_left.duty = 0; - - ledc_timer_config_t ledc_timer; - ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE; - ledc_timer.duty_resolution = LEDC_TIMER_8_BIT; - ledc_timer.timer_num = LEDC_TIMER_1; - ledc_timer.freq_hz = 640; - - ledc_channel_config(&ledc_channel_left); - ledc_timer_config(&ledc_timer); -} - void HardwareRevX::restorePreferences() { // Restore settings from internal flash memory int backlight_brightness = 255; @@ -304,19 +278,6 @@ void HardwareRevX::setupIMU() { IMU.readRegister(&intDataRead, LIS3DH_INT1_SRC); // clear interrupt } -// TODO move to display -void HardwareRevX::slowDisplayWakeup() { - // Slowly charge the VSW voltage to prevent a brownout - // Workaround for hardware rev 1! - for (int i = 0; i < 100; i++) { - digitalWrite(LCD_EN, HIGH); // LCD Logic off - delayMicroseconds(1); - digitalWrite(LCD_EN, LOW); // LCD Logic on - } - - delay(100); // Wait for the LCD driver to power on -} - void HardwareRevX::setupIR() { // Setup IR IrSender.begin(); diff --git a/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp index e34b140..249f8ad 100644 --- a/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp +++ b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp @@ -43,7 +43,6 @@ public: protected: // Init Functions to setup hardware void initIO(); - void setupBacklight(); void restorePreferences(); void slowDisplayWakeup(); void setupIMU(); diff --git a/Platformio/HAL/Targets/ESP32/display/display.cpp b/Platformio/HAL/Targets/ESP32/display/display.cpp index 854acdd..403ee98 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.cpp +++ b/Platformio/HAL/Targets/ESP32/display/display.cpp @@ -2,6 +2,7 @@ #include "display.hpp" #include "omoteconfig.h" #include "Wire.h" +#include "driver/ledc.h" std::shared_ptr Display::getInstance() { @@ -23,11 +24,12 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(), pinMode(mBacklightPin, OUTPUT); digitalWrite(mBacklightPin, HIGH); - ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION); - ledcAttachPin(mBacklightPin, LCD_BACKLIGHT_LEDC_CHANNEL); - ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0); + setupBacklight(); // This eliminates the flash of the backlight - setupTFT(); + // This backlight init causes the backlight to come on full during startup + // ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION); + // ledcAttachPin(mBacklightPin, LCD_BACKLIGHT_LEDC_CHANNEL); + // ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0); // Slowly charge the VSW voltage to prevent a brownout // Workaround for hardware rev 1! @@ -37,16 +39,40 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(), digitalWrite(this->mEnablePin, LOW); // LCD Logic on } + setupTFT(); setupTouchScreen(); mFadeTaskMutex = xSemaphoreCreateBinary(); xSemaphoreGive(mFadeTaskMutex); } +void Display::setupBacklight() { + // Configure the backlight PWM + // Manual setup because ledcSetup() briefly turns on the backlight + ledc_channel_config_t ledc_channel_left; + ledc_channel_left.gpio_num = (gpio_num_t)mBacklightPin; + ledc_channel_left.speed_mode = LEDC_HIGH_SPEED_MODE; + ledc_channel_left.channel = LEDC_CHANNEL_5; + ledc_channel_left.intr_type = LEDC_INTR_DISABLE; + ledc_channel_left.timer_sel = LEDC_TIMER_1; + ledc_channel_left.flags.output_invert = 1; // Can't do this with ledcSetup() + ledc_channel_left.duty = 0; + ledc_channel_left.hpoint = 0; + ledc_timer_config_t ledc_timer; + ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE; + ledc_timer.duty_resolution = LEDC_TIMER_8_BIT; + ledc_timer.timer_num = LEDC_TIMER_1; + ledc_timer.clk_cfg = LEDC_AUTO_CLK; + ledc_timer.freq_hz = 640; + ledc_channel_config(&ledc_channel_left); + ledc_timer_config(&ledc_timer); +} + void Display::onTouch(Notification::HandlerTy aTouchHandler){ mTouchEvent.onNotify(std::move(aTouchHandler)); } void Display::setupTFT() { + delay(100); tft.init(); tft.initDMA(); tft.setRotation(0); @@ -74,10 +100,11 @@ uint8_t Display::getBrightness(){ void Display::setCurrentBrightness(uint8_t brightness){ mBrightness = brightness; - auto duty = abs(255 - static_cast(mBrightness)); + // auto duty = abs(255 - static_cast(mBrightness)); + auto duty = abs(static_cast(mBrightness)); ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, duty); - Serial.print("Current Brightness:"); - Serial.println(mBrightness); + // Serial.print("Current Brightness:"); + // Serial.println(mBrightness); } void Display::turnOff() diff --git a/Platformio/HAL/Targets/ESP32/display/display.hpp b/Platformio/HAL/Targets/ESP32/display/display.hpp index 51b29d7..214c8b8 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.hpp +++ b/Platformio/HAL/Targets/ESP32/display/display.hpp @@ -52,6 +52,7 @@ class Display: public DisplayAbstract Display(int backlight_pin, int enable_pin); void setupTFT(); void setupTouchScreen(); + void setupBacklight(); int mEnablePin; int mBacklightPin; From f8ed2efacb68ad83b073ff6896816de1c6b67cc9 Mon Sep 17 00:00:00 2001 From: Paul Hortiatis Date: Tue, 12 Sep 2023 10:10:21 -0400 Subject: [PATCH 2/3] Cleanup --- Platformio/HAL/Targets/ESP32/display/display.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Platformio/HAL/Targets/ESP32/display/display.cpp b/Platformio/HAL/Targets/ESP32/display/display.cpp index 403ee98..f169b62 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.cpp +++ b/Platformio/HAL/Targets/ESP32/display/display.cpp @@ -100,8 +100,7 @@ uint8_t Display::getBrightness(){ void Display::setCurrentBrightness(uint8_t brightness){ mBrightness = brightness; - // auto duty = abs(255 - static_cast(mBrightness)); - auto duty = abs(static_cast(mBrightness)); + auto duty = static_cast(mBrightness); ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, duty); // Serial.print("Current Brightness:"); // Serial.println(mBrightness); @@ -197,4 +196,4 @@ void Display::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_ tft.endWrite(); lv_disp_flush_ready(disp); -} \ No newline at end of file +} From 8f84423f7e7735ddf098fa95a1195006a20c63e2 Mon Sep 17 00:00:00 2001 From: Paul Hortiatis Date: Tue, 12 Sep 2023 12:02:53 -0400 Subject: [PATCH 3/3] Remove dead code --- Platformio/HAL/Targets/ESP32/display/display.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Platformio/HAL/Targets/ESP32/display/display.cpp b/Platformio/HAL/Targets/ESP32/display/display.cpp index f169b62..a8941cc 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.cpp +++ b/Platformio/HAL/Targets/ESP32/display/display.cpp @@ -26,11 +26,6 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(), setupBacklight(); // This eliminates the flash of the backlight - // This backlight init causes the backlight to come on full during startup - // ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION); - // ledcAttachPin(mBacklightPin, LCD_BACKLIGHT_LEDC_CHANNEL); - // ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0); - // Slowly charge the VSW voltage to prevent a brownout // Workaround for hardware rev 1! for(int i = 0; i < 100; i++){