From 745e2dff517ef721ae8ddc578e0e5409239e4a7f Mon Sep 17 00:00:00 2001 From: Thomas Bittner Date: Fri, 4 Aug 2023 21:45:47 +0200 Subject: [PATCH] Updated initialization of LEDC module Firmware is now not using the ledcsetup function but is directly setting up the ledc hardware. This enables the LEDC output to be inverted as needed for the OMOTE hardware. --- Platformio/src/display/display.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Platformio/src/display/display.cpp b/Platformio/src/display/display.cpp index c051892..f7fae92 100644 --- a/Platformio/src/display/display.cpp +++ b/Platformio/src/display/display.cpp @@ -83,9 +83,25 @@ void Display::setup() digitalWrite(this->backlight_pin, HIGH); this->tft = TFT_eSPI(); - ledcSetup(LCD_BACKLIGHT_LEDC_CHANNEL, LCD_BACKLIGHT_LEDC_FREQUENCY, LCD_BACKLIGHT_LEDC_BIT_RESOLUTION); - ledcAttachPin(this->backlight_pin, LCD_BACKLIGHT_LEDC_CHANNEL); - ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, 0); + // 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)this->backlight_pin; + 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); // Slowly charge the VSW voltage to prevent a brownout // Workaround for hardware rev 1!