From 2a568846bd8f1c9e23e86e7570557eed6f18cf9f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 7 Jun 2023 10:30:33 +1000 Subject: Cute brightness fade to avoid ugly startup :) --- src/drivers/display.cpp | 20 +++++++++++++++++--- src/drivers/include/display.hpp | 6 ++++++ 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index 7a49e02b..dd4cecb8 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -123,9 +123,11 @@ auto Display::Create(GpioExpander* expander, .hpoint = 0}; ESP_ERROR_CHECK(ledc_channel_config(&led_channel)); - ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 4096)); + ESP_ERROR_CHECK(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0)); ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0)); + ledc_fade_func_install(0); + // Next, init the SPI device spi_device_interface_config_t spi_cfg = { .command_bits = 0, // No command phase @@ -180,9 +182,21 @@ auto Display::Create(GpioExpander* expander, Display::Display(GpioExpander* gpio, spi_device_handle_t handle) : gpio_(gpio), handle_(handle), - worker_task_(tasks::Worker::Start()) {} + worker_task_(tasks::Worker::Start()), + display_on_(false), + brightness_(4096) {} + +Display::~Display() { + ledc_fade_func_uninstall(); +} -Display::~Display() {} +auto Display::SetDisplayOn(bool enabled) -> void { + display_on_ = enabled; + + int new_duty = display_on_ ? brightness_ : 0; + ledc_set_fade_with_time(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, new_duty, 250); + ledc_fade_start(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT); +} void Display::SendInitialisationSequence(const uint8_t* data) { // Hold onto the bus for the entire sequence so that we're not interrupted diff --git a/src/drivers/include/display.hpp b/src/drivers/include/display.hpp index d2e0c14b..b394dd9e 100644 --- a/src/drivers/include/display.hpp +++ b/src/drivers/include/display.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -35,6 +36,8 @@ class Display { Display(GpioExpander* gpio, spi_device_handle_t handle); ~Display(); + auto SetDisplayOn(bool) -> void; + /* Driver callback invoked by LVGL when there is new data to display. */ void OnLvglFlush(lv_disp_drv_t* disp_drv, const lv_area_t* area, @@ -46,6 +49,9 @@ class Display { std::unique_ptr worker_task_; + bool display_on_; + uint32_t brightness_; + lv_disp_draw_buf_t buffers_; lv_disp_drv_t driver_; lv_disp_t* display_ = nullptr; -- cgit v1.2.3