diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-07 10:30:33 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-07 10:30:33 +1000 |
| commit | 2a568846bd8f1c9e23e86e7570557eed6f18cf9f (patch) | |
| tree | 3c152311311233eda762bb8b441ad44b50800cb8 /src/drivers | |
| parent | 610991455d335663de1dd6c0c6a3e0247ffd46df (diff) | |
| download | tangara-fw-2a568846bd8f1c9e23e86e7570557eed6f18cf9f.tar.gz | |
Cute brightness fade to avoid ugly startup :)
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/display.cpp | 20 | ||||
| -rw-r--r-- | src/drivers/include/display.hpp | 6 |
2 files changed, 23 insertions, 3 deletions
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<tasks::Type::kUiFlush>()) {} + worker_task_(tasks::Worker::Start<tasks::Type::kUiFlush>()), + 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 <stdint.h> #include <cstdint> #include <memory> @@ -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<tasks::Worker> worker_task_; + bool display_on_; + uint32_t brightness_; + lv_disp_draw_buf_t buffers_; lv_disp_drv_t driver_; lv_disp_t* display_ = nullptr; |
