Add panel.h, panel.cpp.
This commit is contained in:
parent
64d817e362
commit
6493988324
@ -1,5 +1,5 @@
|
|||||||
idf_component_register(
|
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 .
|
INCLUDE_DIRS .
|
||||||
REQUIRES driver
|
REQUIRES driver
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
// LVGL library is not thread-safe, this example calls LVGL APIs from tasks.
|
// LVGL library is not thread-safe, this example calls LVGL APIs from tasks.
|
||||||
// We must use a mutex to protect it.
|
// We must use a mutex to protect it.
|
||||||
_lock_t ScopedLock::lock_;
|
_lock_t Display::ScopedLock::lock_;
|
||||||
|
|
||||||
Display::Display(IPanelDevice *device) :
|
Display::Display(IPanelDevice *device) :
|
||||||
panel_(device)
|
panel_(device)
|
||||||
@ -163,30 +163,3 @@ void Display::lvgl_increase_tick(void *)
|
|||||||
usleep(1000 * time_till_next_ms);
|
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));
|
|
||||||
}
|
|
||||||
|
@ -13,38 +13,12 @@
|
|||||||
#include "display/lv_display.h"
|
#include "display/lv_display.h"
|
||||||
#include "widgets/label/lv_label.h"
|
#include "widgets/label/lv_label.h"
|
||||||
|
|
||||||
#include "panel_device.h"
|
#include "panel.h"
|
||||||
|
|
||||||
#define LVGL_TICK_PERIOD_MS 5
|
#define LVGL_TICK_PERIOD_MS 5
|
||||||
#define LVGL_TASK_STACK_SIZE (4 * 1024)
|
#define LVGL_TASK_STACK_SIZE (4 * 1024)
|
||||||
#define LVGL_TASK_PRIORITY 2
|
#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 {
|
class Display {
|
||||||
public:
|
public:
|
||||||
explicit Display(IPanelDevice *device);
|
explicit Display(IPanelDevice *device);
|
||||||
@ -88,6 +62,16 @@ private:
|
|||||||
// @sa Display::set_text
|
// @sa Display::set_text
|
||||||
// @sa lv_display_get_screen_active
|
// @sa lv_display_get_screen_active
|
||||||
std::unordered_map<const char *, lv_obj_t *> objects_;
|
std::unordered_map<const char *, lv_obj_t *> 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
|
#endif // DISPLAY_H
|
||||||
|
29
esp/cpp/07_lcd-panel/main/panel.cpp
Normal file
29
esp/cpp/07_lcd-panel/main/panel.cpp
Normal file
@ -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));
|
||||||
|
}
|
22
esp/cpp/07_lcd-panel/main/panel.h
Normal file
22
esp/cpp/07_lcd-panel/main/panel.h
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user