More cleanup.

This commit is contained in:
Shaun Reed 2025-02-16 07:21:16 -05:00
parent 5c61fbd378
commit c9ec16d70c
8 changed files with 48 additions and 28 deletions

View File

@ -13,7 +13,8 @@
_lock_t Display::ScopedLock::lv_lock_;
Display::Display(IPanelDevice &device) :
panel_(device)
panel_(device),
lv_tick_timer_(nullptr)
{
if (!lv_is_initialized()) {
ESP_LOGI(TAG, "Initialize LVGL");
@ -47,19 +48,11 @@ Display::Display(IPanelDevice &device) :
.on_color_trans_done = Display::lvgl_flush_ready,
};
ESP_ERROR_CHECK(
esp_lcd_panel_io_register_event_callbacks(panel_.esp_io_handle_, &cbs,
esp_lcd_panel_io_register_event_callbacks(panel_.esp_io_, &cbs,
lv_display_));
register_lvgl_tick_timer();
ESP_LOGI(TAG, "Use esp_timer to increase LVGL tick");
const esp_timer_create_args_t lvgl_tick_timer_args = {
.callback = &Display::lvgl_increase_tick,
.name = "lvgl_tick"
};
esp_timer_handle_t lvgl_tick_timer = nullptr;
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer,
LVGL_TICK_PERIOD_MS * 1000));
// TODO: What is this
ESP_LOGI(TAG, "Create LVGL task");
xTaskCreate(Display::lvgl_port_task, "LVGL", LVGL_TASK_STACK_SIZE,
nullptr, LVGL_TASK_PRIORITY, nullptr);
@ -98,7 +91,7 @@ bool Display::lvgl_flush_ready(esp_lcd_panel_io_handle_t,
}
void Display::lvgl_flush_cb(lv_display_t *display, const lv_area_t *area,
uint8_t *px_map)
uint8_t *px_map) // NOLINT(*-non-const-parameter)
{
auto panel_handle =
(esp_lcd_panel_handle_t) lv_display_get_user_data(display);
@ -158,3 +151,16 @@ void Display::lvgl_increase_tick(void *)
usleep(1000 * time_till_next_ms);
}
}
void Display::register_lvgl_tick_timer() // NOLINT(*-convert-member-functions-to-static)
{
ESP_LOGI(TAG, "Use esp_timer to increase LVGL tick");
const esp_timer_create_args_t lvgl_tick_timer_args = {
.callback = &Display::lvgl_increase_tick,
.name = "lvgl_tick"
};
esp_timer_handle_t lvgl_tick_timer = nullptr;
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer,
LVGL_TICK_PERIOD_MS * 1000));
}

View File

@ -4,6 +4,7 @@
#include <widgets/label/lv_label.h>
#include <unordered_map>
#include <esp_timer.h>
#include "panel.h"
@ -43,6 +44,8 @@ public:
[[noreturn]] static void lvgl_port_task(void *arg);
private:
void register_lvgl_tick_timer();
Panel panel_;
lv_display_t *lv_display_;
@ -55,6 +58,9 @@ private:
// @sa lv_display_get_screen_active
std::unordered_map<const char *, lv_obj_t *> lv_objects_;
// TODO: This could be a private struct
esp_timer_handle_t lv_tick_timer_;
struct ScopedLock {
explicit ScopedLock() { _lock_acquire(&lv_lock_); }

View File

@ -30,6 +30,7 @@ struct I2C {
~I2C() = default;
// TODO: Can you use the I2C get_master_bus API in a static method?
i2c_master_bus_handle_t esp_i2c_bus_;
int rst_num_;

View File

@ -4,7 +4,7 @@
// Pin may vary based on your schematic.
#define PIN_SDA GPIO_NUM_21
#define PIN_SCL GPIO_NUM_22
#define PIN_RST -1
#define PIN_RST (-1)
I2C i2c(PIN_SDA, PIN_SCL, PIN_RST);

View File

@ -3,7 +3,7 @@
Panel::Panel(IPanelDevice &device) :
device_(&device),
esp_io_handle_(nullptr),
esp_io_(nullptr),
esp_panel_(nullptr),
esp_panel_config_(
(esp_lcd_panel_dev_config_t) {
@ -13,9 +13,9 @@ Panel::Panel(IPanelDevice &device) :
}
)
{
esp_io_handle_ = device_->create_io_handle();
esp_io_ = device_->create_io_handle();
device_->create_panel(esp_panel_config_, esp_io_handle_, esp_panel_);
device_->create_panel(esp_panel_config_, esp_io_, esp_panel_);
ESP_LOGI(TAG, "Resetting panel display");
ESP_ERROR_CHECK(esp_lcd_panel_reset(esp_panel_));

View File

@ -11,7 +11,7 @@ public:
IPanelDevice *device_;
esp_lcd_panel_io_handle_t esp_io_handle_;
esp_lcd_panel_io_handle_t esp_io_;
esp_lcd_panel_handle_t esp_panel_;

View File

@ -22,12 +22,3 @@ SSD1306::SSD1306(I2C& i2c,
),
ssd1306_config_(config)
{ }
void SSD1306::init_panel(esp_lcd_panel_dev_config_t &config,
esp_lcd_panel_io_handle_t io,
esp_lcd_panel_handle_t &panel)
{
// Allocate SSD1306 panel handle.
config.vendor_config = &ssd1306_config_;
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io, &config, &panel));
}

View File

@ -1,3 +1,16 @@
/*
* https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/peripherals/lcd/index.html#functional-overview
*
* Implementing the interface draw to an LCD using various interface modes.
* I2C interface mode is SSD1306
* SPI interface mode is ST7789
* I80 interface mode is NT35510 or ST7789
*
* Actually, I think any driver can be used with any interface mode
* Along with additional third party drivers via the component manager
* https://github.com/espressif/esp-idf/tree/0d6099ec533c4b647fb7a7b0b8942bc7aeb82f90/examples/peripherals/lcd/spi_lcd_touch#spi-lcd-and-touch-panel-example
*/
#ifndef SSD1306_H
#define SSD1306_H
@ -45,7 +58,10 @@ public:
private:
void init_panel(esp_lcd_panel_dev_config_t &config,
esp_lcd_panel_io_handle_t io,
esp_lcd_panel_handle_t &panel) override;
esp_lcd_panel_handle_t &panel) override
{
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io, &config, &panel));
}
};
#endif // SSD1306_H