From f4dbfb295a3d2742b3bb3ab10d8c627b44a041fc Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Thu, 10 Feb 2022 02:18:07 +0100 Subject: [PATCH] Update PWM resolution for ESP32S2 #250 --- src/dev/esp32/esp32.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index c9de5408..c030e0ce 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -185,7 +185,11 @@ void Esp32Device::set_backlight_pin(uint8_t pin) /* Setup Backlight Control Pin */ if(pin < GPIO_NUM_MAX) { LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin); +#ifndef ESP32S2 ledcSetup(BACKLIGHT_CHANNEL, 20000, 12); +#else + ledcSetup(BACKLIGHT_CHANNEL, 20000, 10); +#endif ledcAttachPin(pin, BACKLIGHT_CHANNEL); update_backlight(); } else { @@ -218,9 +222,15 @@ bool Esp32Device::get_backlight_power() void Esp32Device::update_backlight() { if(_backlight_pin < GPIO_NUM_MAX) { +#ifndef ESP32S2 uint32_t duty = _backlight_power ? map(_backlight_level, 0, 255, 0, 4095) : 0; if(_backlight_invert) duty = 4095 - duty; ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value +#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 +#endif } // haspTft.tft.writecommand(0x53); // Write CTRL Display