From 6493988324437d389cb3983aceecfe5e12d320ef Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sat, 15 Feb 2025 17:51:57 -0500 Subject: [PATCH] Add panel.h, panel.cpp. --- esp/cpp/07_lcd-panel/main/CMakeLists.txt | 2 +- esp/cpp/07_lcd-panel/main/display.cpp | 29 +----------------- esp/cpp/07_lcd-panel/main/display.h | 38 +++++++----------------- esp/cpp/07_lcd-panel/main/panel.cpp | 29 ++++++++++++++++++ esp/cpp/07_lcd-panel/main/panel.h | 22 ++++++++++++++ 5 files changed, 64 insertions(+), 56 deletions(-) create mode 100644 esp/cpp/07_lcd-panel/main/panel.cpp create mode 100644 esp/cpp/07_lcd-panel/main/panel.h diff --git a/esp/cpp/07_lcd-panel/main/CMakeLists.txt b/esp/cpp/07_lcd-panel/main/CMakeLists.txt index 300bcbb..5032c42 100644 --- a/esp/cpp/07_lcd-panel/main/CMakeLists.txt +++ b/esp/cpp/07_lcd-panel/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register( - SRCS main.cpp display.cpp panel_device.cpp ssd1306.cpp + SRCS main.cpp i2c.h display.cpp panel.cpp panel_device.cpp ssd1306.cpp INCLUDE_DIRS . REQUIRES driver ) diff --git a/esp/cpp/07_lcd-panel/main/display.cpp b/esp/cpp/07_lcd-panel/main/display.cpp index b0f5a5d..4c0fea8 100644 --- a/esp/cpp/07_lcd-panel/main/display.cpp +++ b/esp/cpp/07_lcd-panel/main/display.cpp @@ -14,7 +14,7 @@ // LVGL library is not thread-safe, this example calls LVGL APIs from tasks. // We must use a mutex to protect it. -_lock_t ScopedLock::lock_; +_lock_t Display::ScopedLock::lock_; Display::Display(IPanelDevice *device) : panel_(device) @@ -163,30 +163,3 @@ void Display::lvgl_increase_tick(void *) usleep(1000 * time_till_next_ms); } } - -Panel::Panel(IPanelDevice *device) : - device_(device), - io_handle_(nullptr), - esp_panel_(nullptr), - // According to SSD1306 datasheet - panel_config_( - (esp_lcd_panel_dev_config_t) { - .reset_gpio_num = PIN_RST, - .bits_per_pixel = 1, - // .vendor_config should be set in IPanelDevice::init_panel override - } - ) -{ - ESP_LOGI(TAG, "Install panel IO"); - ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c( - device_->i2c_bus_, &device_->io_config_, &io_handle_)); - - device_->create_panel(panel_config_, io_handle_, esp_panel_); - - ESP_LOGI(TAG, "Resetting panel display"); - ESP_ERROR_CHECK(esp_lcd_panel_reset(esp_panel_)); - ESP_LOGI(TAG, "Initializing panel display"); - ESP_ERROR_CHECK(esp_lcd_panel_init(esp_panel_)); - ESP_LOGI(TAG, "Turning on panel display"); - ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(esp_panel_, true)); -} diff --git a/esp/cpp/07_lcd-panel/main/display.h b/esp/cpp/07_lcd-panel/main/display.h index f587322..f31fdcb 100644 --- a/esp/cpp/07_lcd-panel/main/display.h +++ b/esp/cpp/07_lcd-panel/main/display.h @@ -13,38 +13,12 @@ #include "display/lv_display.h" #include "widgets/label/lv_label.h" -#include "panel_device.h" +#include "panel.h" #define LVGL_TICK_PERIOD_MS 5 #define LVGL_TASK_STACK_SIZE (4 * 1024) #define LVGL_TASK_PRIORITY 2 -struct ScopedLock { - explicit ScopedLock() { _lock_acquire(&lock_); } - - ~ScopedLock() { _lock_release(&lock_); } - - // LVGL library is not thread-safe, this example calls LVGL APIs from tasks. - // We must use a mutex to protect it. - static _lock_t lock_; -}; - -class Panel { -public: - explicit Panel(IPanelDevice *device); - - ~Panel() = default; - - IPanelDevice *device_; - - esp_lcd_panel_io_handle_t io_handle_; - - esp_lcd_panel_handle_t esp_panel_; - -private: - esp_lcd_panel_dev_config_t panel_config_; -}; - class Display { public: explicit Display(IPanelDevice *device); @@ -88,6 +62,16 @@ private: // @sa Display::set_text // @sa lv_display_get_screen_active std::unordered_map objects_; + + struct ScopedLock { + explicit ScopedLock() { _lock_acquire(&lock_); } + + ~ScopedLock() { _lock_release(&lock_); } + + // LVGL library is not thread-safe, this example calls LVGL APIs from tasks. + // We must use a mutex to protect it. + static _lock_t lock_; + }; }; #endif // DISPLAY_H diff --git a/esp/cpp/07_lcd-panel/main/panel.cpp b/esp/cpp/07_lcd-panel/main/panel.cpp new file mode 100644 index 0000000..94dc302 --- /dev/null +++ b/esp/cpp/07_lcd-panel/main/panel.cpp @@ -0,0 +1,29 @@ + +#include "panel.h" + +Panel::Panel(IPanelDevice *device) : + device_(device), + io_handle_(nullptr), + esp_panel_(nullptr), + // According to SSD1306 datasheet + panel_config_( + (esp_lcd_panel_dev_config_t) { + .reset_gpio_num = -1, // TODO: PIN_RST, + .bits_per_pixel = 1, + // .vendor_config should be set in IPanelDevice::init_panel override + } + ) +{ + ESP_LOGI(TAG, "Install panel IO"); + ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c( + device_->i2c_bus_, &device_->io_config_, &io_handle_)); + + device_->create_panel(panel_config_, io_handle_, esp_panel_); + + ESP_LOGI(TAG, "Resetting panel display"); + ESP_ERROR_CHECK(esp_lcd_panel_reset(esp_panel_)); + ESP_LOGI(TAG, "Initializing panel display"); + ESP_ERROR_CHECK(esp_lcd_panel_init(esp_panel_)); + ESP_LOGI(TAG, "Turning on panel display"); + ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(esp_panel_, true)); +} diff --git a/esp/cpp/07_lcd-panel/main/panel.h b/esp/cpp/07_lcd-panel/main/panel.h new file mode 100644 index 0000000..eebd2b6 --- /dev/null +++ b/esp/cpp/07_lcd-panel/main/panel.h @@ -0,0 +1,22 @@ +#ifndef PANEL_H +#define PANEL_H + +#include "panel_device.h" + +class Panel { +public: + explicit Panel(IPanelDevice *device); + + ~Panel() = default; + + IPanelDevice *device_; + + esp_lcd_panel_io_handle_t io_handle_; + + esp_lcd_panel_handle_t esp_panel_; + +private: + esp_lcd_panel_dev_config_t panel_config_; +}; + +#endif //PANEL_H