Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/ws-s3-geek/include/ws-s3-geek.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "base_component.hpp"
#include "interrupt.hpp"
#include "led.hpp"
#include "st7789.hpp"

namespace espp {
Expand Down Expand Up @@ -103,10 +104,12 @@ class WsS3Geek : public BaseComponent {

/// Set the brightness of the backlight
/// \param brightness The brightness of the backlight as a percentage (0 - 100)
/// \note This function will only work after initialize_lcd() has been called
void brightness(float brightness);

/// Get the brightness of the backlight
/// \return The brightness of the backlight as a percentage (0 - 100)
/// \note This function will only work after initialize_lcd() has been called
float brightness() const;

/// Get the VRAM 0 pointer (DMA memory used by LVGL)
Expand Down Expand Up @@ -247,6 +250,8 @@ class WsS3Geek : public BaseComponent {

// display
std::shared_ptr<Display<Pixel>> display_;
std::vector<Led::ChannelConfig> backlight_channel_configs_{};
std::shared_ptr<Led> backlight_{};
/// SPI bus for communication with the LCD
spi_bus_config_t lcd_spi_bus_config_;
spi_device_interface_config_t lcd_config_;
Expand Down
32 changes: 24 additions & 8 deletions components/ws-s3-geek/src/ws-s3-geek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ static void IRAM_ATTR lcd_spi_post_transfer_callback(spi_transaction_t *t) {
}

bool WsS3Geek::initialize_lcd() {
if (lcd_handle_) {
if (lcd_handle_ || backlight_) {
logger_.warn("LCD already initialized, not initializing again!");
return false;
}

logger_.info("Initializing LCD...");

// Initialize backlight PWM (moved out of Display)
backlight_channel_configs_.push_back({.gpio = static_cast<size_t>(backlight_io),
.channel = LEDC_CHANNEL_0,
.timer = LEDC_TIMER_0,
.output_invert = !backlight_value});
backlight_ = std::make_shared<Led>((Led::Config{.timer = LEDC_TIMER_0,
.frequency_hz = 5000,
.channels = backlight_channel_configs_,
.duty_resolution = LEDC_TIMER_10_BIT}));
brightness(100.0f);

esp_err_t ret;

memset(&lcd_spi_bus_config_, 0, sizeof(lcd_spi_bus_config_));
Expand Down Expand Up @@ -142,8 +153,9 @@ bool WsS3Geek::initialize_display(size_t pixel_buffer_size) {
.flush_callback = DisplayDriver::flush,
.rotation_callback = DisplayDriver::rotate,
.rotation = rotation},
Display<Pixel>::LcdConfig{.backlight_pin = backlight_io,
.backlight_on_value = backlight_value},
Display<Pixel>::OledConfig{
.set_brightness_callback = [this](float brightness) { this->brightness(brightness); },
.get_brightness_callback = [this]() { return this->brightness(); }},
Display<Pixel>::DynamicMemoryConfig{
.pixel_buffer_size = pixel_buffer_size,
.double_buffered = true,
Expand Down Expand Up @@ -298,12 +310,16 @@ WsS3Geek::Pixel *WsS3Geek::vram1() const {
}

void WsS3Geek::brightness(float brightness) {
brightness = std::clamp(brightness, 0.0f, 100.0f) / 100.0f;
// display expects a value between 0 and 1
display_->set_brightness(brightness);
brightness = std::clamp(brightness, 0.0f, 100.0f);
if (backlight_)
backlight_->set_duty(backlight_channel_configs_[0].channel, brightness);
}

float WsS3Geek::brightness() const {
// display returns a value between 0 and 1
return display_->get_brightness() * 100.0f;
if (backlight_) {
auto d = backlight_->get_duty(backlight_channel_configs_[0].channel);
if (d.has_value())
return d.value();
}
return 0.0f;
}
Loading