forked from xiaozhi/xiaozhi-esp32
fix compile warnings
This commit is contained in:
@@ -24,8 +24,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
int width_ = 0;
|
int width_ = 0;
|
||||||
int height_ = 0;
|
int height_ = 0;
|
||||||
int offset_x_ = 0;
|
|
||||||
int offset_y_ = 0;
|
|
||||||
|
|
||||||
lv_disp_t *disp_ = nullptr;
|
lv_disp_t *disp_ = nullptr;
|
||||||
|
|
||||||
@@ -43,7 +41,7 @@ protected:
|
|||||||
esp_timer_handle_t update_timer_ = nullptr;
|
esp_timer_handle_t update_timer_ = nullptr;
|
||||||
|
|
||||||
friend class DisplayLockGuard;
|
friend class DisplayLockGuard;
|
||||||
virtual void Lock() = 0;
|
virtual bool Lock(int timeout_ms = 0) = 0;
|
||||||
virtual void Unlock() = 0;
|
virtual void Unlock() = 0;
|
||||||
|
|
||||||
virtual void Update();
|
virtual void Update();
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ NoDisplay::NoDisplay() {}
|
|||||||
|
|
||||||
NoDisplay::~NoDisplay() {}
|
NoDisplay::~NoDisplay() {}
|
||||||
|
|
||||||
void NoDisplay::Lock() {}
|
bool NoDisplay::Lock(int timeout_ms) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void NoDisplay::Unlock() {}
|
void NoDisplay::Unlock() {}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class NoDisplay : public Display {
|
class NoDisplay : public Display {
|
||||||
private:
|
private:
|
||||||
virtual void Lock() override;
|
virtual bool Lock(int timeout_ms = 0) override;
|
||||||
virtual void Unlock() override;
|
virtual void Unlock() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -126,8 +126,8 @@ Ssd1306Display::~Ssd1306Display() {
|
|||||||
lvgl_port_deinit();
|
lvgl_port_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ssd1306Display::Lock() {
|
bool Ssd1306Display::Lock(int timeout_ms) {
|
||||||
lvgl_port_lock(0);
|
return lvgl_port_lock(timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ssd1306Display::Unlock() {
|
void Ssd1306Display::Unlock() {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ private:
|
|||||||
lv_obj_t* container_ = nullptr;
|
lv_obj_t* container_ = nullptr;
|
||||||
lv_obj_t* side_bar_ = nullptr;
|
lv_obj_t* side_bar_ = nullptr;
|
||||||
|
|
||||||
virtual void Lock() override;
|
virtual bool Lock(int timeout_ms = 0) override;
|
||||||
virtual void Unlock() override;
|
virtual void Unlock() override;
|
||||||
|
|
||||||
void SetupUI_128x64();
|
void SetupUI_128x64();
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_err.h>
|
#include <esp_err.h>
|
||||||
#include <esp_lvgl_port.h>
|
|
||||||
#include <driver/ledc.h>
|
#include <driver/ledc.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ LV_FONT_DECLARE(font_puhui_14_1);
|
|||||||
LV_FONT_DECLARE(font_awesome_30_1);
|
LV_FONT_DECLARE(font_awesome_30_1);
|
||||||
LV_FONT_DECLARE(font_awesome_14_1);
|
LV_FONT_DECLARE(font_awesome_14_1);
|
||||||
|
|
||||||
static SemaphoreHandle_t lvgl_mux = NULL;
|
|
||||||
static lv_disp_drv_t disp_drv;
|
static lv_disp_drv_t disp_drv;
|
||||||
static void st7789_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
|
static void st7789_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_color_t *color_map)
|
||||||
{
|
{
|
||||||
@@ -83,36 +81,17 @@ static void st7789_lvgl_port_update_callback(lv_disp_drv_t *drv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void st7789_increase_lvgl_tick(void *arg)
|
|
||||||
{
|
|
||||||
/* Tell LVGL how many milliseconds has elapsed */
|
|
||||||
lv_tick_inc(ST7789_LVGL_TICK_PERIOD_MS);
|
|
||||||
}
|
|
||||||
static bool st7789_lvgl_lock(int timeout_ms)
|
|
||||||
{
|
|
||||||
// Convert timeout in milliseconds to FreeRTOS ticks
|
|
||||||
// If `timeout_ms` is set to -1, the program will block until the condition is met
|
|
||||||
const TickType_t timeout_ticks = (timeout_ms == -1) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
|
|
||||||
return xSemaphoreTakeRecursive(lvgl_mux, timeout_ticks) == pdTRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void st7789_lvgl_unlock(void)
|
void St7789Display::LvglTask() {
|
||||||
{
|
|
||||||
xSemaphoreGiveRecursive(lvgl_mux);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void st7789_lvgl_port_task(void *arg)
|
|
||||||
{
|
|
||||||
ESP_LOGI(TAG, "Starting LVGL task");
|
ESP_LOGI(TAG, "Starting LVGL task");
|
||||||
uint32_t task_delay_ms = ST7789_LVGL_TASK_MAX_DELAY_MS;
|
uint32_t task_delay_ms = ST7789_LVGL_TASK_MAX_DELAY_MS;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
// Lock the mutex due to the LVGL APIs are not thread-safe
|
// Lock the mutex due to the LVGL APIs are not thread-safe
|
||||||
if (st7789_lvgl_lock(-1))
|
if (Lock())
|
||||||
{
|
{
|
||||||
task_delay_ms = lv_timer_handler();
|
task_delay_ms = lv_timer_handler();
|
||||||
// Release the mutex
|
Unlock();
|
||||||
st7789_lvgl_unlock();
|
|
||||||
}
|
}
|
||||||
if (task_delay_ms > ST7789_LVGL_TASK_MAX_DELAY_MS)
|
if (task_delay_ms > ST7789_LVGL_TASK_MAX_DELAY_MS)
|
||||||
{
|
{
|
||||||
@@ -173,21 +152,29 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
|
|||||||
disp_drv.draw_buf = &disp_buf;
|
disp_drv.draw_buf = &disp_buf;
|
||||||
disp_drv.user_data = panel_;
|
disp_drv.user_data = panel_;
|
||||||
|
|
||||||
lv_disp_t *disp = lv_disp_drv_register(&disp_drv);
|
lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Install LVGL tick timer");
|
ESP_LOGI(TAG, "Install LVGL tick timer");
|
||||||
// Tick interface for LVGL (using esp_timer to generate 2ms periodic event)
|
// Tick interface for LVGL (using esp_timer to generate 2ms periodic event)
|
||||||
const esp_timer_create_args_t lvgl_tick_timer_args = {
|
const esp_timer_create_args_t lvgl_tick_timer_args = {
|
||||||
.callback = &st7789_increase_lvgl_tick,
|
.callback = [](void* arg) {
|
||||||
.name = "lvgl_tick"};
|
lv_tick_inc(ST7789_LVGL_TICK_PERIOD_MS);
|
||||||
esp_timer_handle_t lvgl_tick_timer = NULL;
|
},
|
||||||
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer));
|
.arg = NULL,
|
||||||
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer, ST7789_LVGL_TICK_PERIOD_MS * 1000));
|
.dispatch_method = ESP_TIMER_TASK,
|
||||||
|
.name = "LVGL Tick Timer",
|
||||||
|
.skip_unhandled_events = false
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_timer_create(&lvgl_tick_timer_args, &lvgl_tick_timer_));
|
||||||
|
ESP_ERROR_CHECK(esp_timer_start_periodic(lvgl_tick_timer_, ST7789_LVGL_TICK_PERIOD_MS * 1000));
|
||||||
|
|
||||||
lvgl_mux = xSemaphoreCreateRecursiveMutex();
|
lvgl_mutex_ = xSemaphoreCreateRecursiveMutex();
|
||||||
assert(lvgl_mux);
|
assert(lvgl_mutex_ != nullptr);
|
||||||
ESP_LOGI(TAG, "Create LVGL task");
|
ESP_LOGI(TAG, "Create LVGL task");
|
||||||
xTaskCreate(st7789_lvgl_port_task, "LVGL", ST7789_LVGL_TASK_STACK_SIZE, NULL, ST7789_LVGL_TASK_PRIORITY, NULL);
|
xTaskCreate([](void *arg) {
|
||||||
|
static_cast<St7789Display*>(arg)->LvglTask();
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}, "LVGL", ST7789_LVGL_TASK_STACK_SIZE, this, ST7789_LVGL_TASK_PRIORITY, NULL);
|
||||||
|
|
||||||
SetBacklight(100);
|
SetBacklight(100);
|
||||||
|
|
||||||
@@ -195,6 +182,9 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
|
|||||||
}
|
}
|
||||||
|
|
||||||
St7789Display::~St7789Display() {
|
St7789Display::~St7789Display() {
|
||||||
|
ESP_ERROR_CHECK(esp_timer_stop(lvgl_tick_timer_));
|
||||||
|
ESP_ERROR_CHECK(esp_timer_delete(lvgl_tick_timer_));
|
||||||
|
|
||||||
if (content_ != nullptr) {
|
if (content_ != nullptr) {
|
||||||
lv_obj_del(content_);
|
lv_obj_del(content_);
|
||||||
}
|
}
|
||||||
@@ -214,7 +204,7 @@ St7789Display::~St7789Display() {
|
|||||||
if (panel_io_ != nullptr) {
|
if (panel_io_ != nullptr) {
|
||||||
esp_lcd_panel_io_del(panel_io_);
|
esp_lcd_panel_io_del(panel_io_);
|
||||||
}
|
}
|
||||||
lvgl_port_deinit();
|
vSemaphoreDelete(lvgl_mutex_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void St7789Display::InitializeBacklight(gpio_num_t backlight_pin) {
|
void St7789Display::InitializeBacklight(gpio_num_t backlight_pin) {
|
||||||
@@ -264,21 +254,21 @@ void St7789Display::SetBacklight(uint8_t brightness) {
|
|||||||
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LCD_LEDC_CH));
|
ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LCD_LEDC_CH));
|
||||||
}
|
}
|
||||||
|
|
||||||
void St7789Display::Lock() {
|
bool St7789Display::Lock(int timeout_ms) {
|
||||||
// lvgl_port_lock(0);
|
// Convert timeout in milliseconds to FreeRTOS ticks
|
||||||
st7789_lvgl_lock(0);
|
// If `timeout_ms` is set to 0, the program will block until the condition is met
|
||||||
|
const TickType_t timeout_ticks = (timeout_ms == 0) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
|
||||||
|
return xSemaphoreTakeRecursive(lvgl_mutex_, timeout_ticks) == pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void St7789Display::Unlock() {
|
void St7789Display::Unlock() {
|
||||||
// lvgl_port_unlock();
|
xSemaphoreGiveRecursive(lvgl_mutex_);
|
||||||
st7789_lvgl_unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void St7789Display::SetupUI() {
|
void St7789Display::SetupUI() {
|
||||||
DisplayLockGuard lock(this);
|
DisplayLockGuard lock(this);
|
||||||
|
|
||||||
auto screen = lv_disp_get_scr_act(lv_disp_get_default());
|
auto screen = lv_disp_get_scr_act(lv_disp_get_default());
|
||||||
// auto screen = lv_scr_act();
|
|
||||||
lv_obj_set_style_text_font(screen, &font_puhui_14_1, 0);
|
lv_obj_set_style_text_font(screen, &font_puhui_14_1, 0);
|
||||||
lv_obj_set_style_text_color(screen, lv_color_black(), 0);
|
lv_obj_set_style_text_color(screen, lv_color_black(), 0);
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,12 @@
|
|||||||
|
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/semphr.h>
|
||||||
#include <driver/gpio.h>
|
#include <driver/gpio.h>
|
||||||
#include <esp_lcd_panel_io.h>
|
#include <esp_lcd_panel_io.h>
|
||||||
#include <esp_lcd_panel_ops.h>
|
#include <esp_lcd_panel_ops.h>
|
||||||
|
#include <esp_timer.h>
|
||||||
|
|
||||||
class St7789Display : public Display {
|
class St7789Display : public Display {
|
||||||
private:
|
private:
|
||||||
@@ -16,6 +19,10 @@ private:
|
|||||||
bool mirror_x_ = false;
|
bool mirror_x_ = false;
|
||||||
bool mirror_y_ = false;
|
bool mirror_y_ = false;
|
||||||
bool swap_xy_ = false;
|
bool swap_xy_ = false;
|
||||||
|
int offset_x_ = 0;
|
||||||
|
int offset_y_ = 0;
|
||||||
|
SemaphoreHandle_t lvgl_mutex_ = nullptr;
|
||||||
|
esp_timer_handle_t lvgl_tick_timer_ = nullptr;
|
||||||
|
|
||||||
lv_obj_t* status_bar_ = nullptr;
|
lv_obj_t* status_bar_ = nullptr;
|
||||||
lv_obj_t* content_ = nullptr;
|
lv_obj_t* content_ = nullptr;
|
||||||
@@ -25,8 +32,9 @@ private:
|
|||||||
void InitializeBacklight(gpio_num_t backlight_pin);
|
void InitializeBacklight(gpio_num_t backlight_pin);
|
||||||
void SetBacklight(uint8_t brightness);
|
void SetBacklight(uint8_t brightness);
|
||||||
void SetupUI();
|
void SetupUI();
|
||||||
|
void LvglTask();
|
||||||
|
|
||||||
virtual void Lock() override;
|
virtual bool Lock(int timeout_ms = 0) override;
|
||||||
virtual void Unlock() override;
|
virtual void Unlock() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user