made lvgl part of nb_platform

This commit is contained in:
Ken Van Hoeylandt 2023-12-25 12:55:08 +01:00
parent 6fd12b2160
commit d9a938e9be
4 changed files with 65 additions and 59 deletions

View File

@ -2,5 +2,5 @@ idf_component_register(
SRC_DIRS "src"
INCLUDE_DIRS "inc"
PRIV_INCLUDE_DIRS "src"
REQUIRES esp_lcd esp_lcd_touch driver
REQUIRES esp_lvgl_port esp_lcd esp_lcd_touch driver
)

View File

@ -4,6 +4,7 @@
#include "nb_display.h"
#include "nb_touch.h"
#include <esp_err.h>
#include <lvgl.h>
typedef struct nb_platform_config nb_platform_config_t;
struct nb_platform_config {
@ -11,10 +12,17 @@ struct nb_platform_config {
nb_touch_driver_t touch_driver;
};
typedef struct nb_lvgl nb_lvgl_t;
struct nb_lvgl {
lv_disp_t* disp;
lv_indev_t* touch_indev;
};
typedef struct nb_platform nb_platform_t;
struct nb_platform {
nb_display_t display;
nb_touch_t touch;
nb_lvgl_t lvgl;
};
esp_err_t nb_platform_create(nb_platform_config_t config, nb_platform_t* platform);

View File

@ -4,8 +4,57 @@
#include "nb_touch.h"
#include "nb_internal.h"
#include <esp_lvgl_port.h>
static const char* TAG = "nb_platform";
static esp_err_t prv_nb_lvgl_init(
nb_platform_t* platform
) {
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = 4,
.task_stack = 4096,
.task_affinity = -1, // core pinning
.task_max_sleep_ms = 500,
.timer_period_ms = 5
};
ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "lvgl port init failed");
// Add display
ESP_LOGD(TAG, "lvgl add display");
const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = platform->display.io_handle,
.panel_handle = platform->display.display_handle,
.buffer_size = platform->display.horizontal_resolution * platform->display.draw_buffer_height * (platform->display.bits_per_pixel / 8),
.double_buffer = 1,
.hres = platform->display.horizontal_resolution,
.vres = platform->display.vertical_resolution,
.monochrome = false,
/* Rotation values must be same as used in esp_lcd for initial settings of the screen */
.rotation = {
.swap_xy = false,
.mirror_x = true,
.mirror_y = false,
},
.flags = {
.buff_dma = true,
}
};
platform->lvgl.disp = lvgl_port_add_disp(&disp_cfg);
// Add touch
if (platform->touch.io_handle != NULL && platform->touch.touch_handle != NULL) {
const lvgl_port_touch_cfg_t touch_cfg = {
.disp = platform->lvgl.disp,
.handle = platform->touch.touch_handle,
};
platform->lvgl.touch_indev = lvgl_port_add_touch(&touch_cfg);
ESP_RETURN_ON_FALSE(platform->lvgl.touch_indev != NULL, ESP_FAIL, TAG, "failed to add touch to lvgl");
}
return ESP_OK;
}
esp_err_t nb_platform_create(nb_platform_config_t config, nb_platform_t* platform) {
ESP_LOGI(TAG, "display with driver %s", config.display_driver.name);
ESP_RETURN_ON_ERROR(
@ -21,5 +70,11 @@ esp_err_t nb_platform_create(nb_platform_config_t config, nb_platform_t* platfor
"touch driver init failed"
);
ESP_RETURN_ON_ERROR(
prv_nb_lvgl_init(platform),
nbi_tag,
"lvgl init failed"
);
return ESP_OK;
}

View File

@ -1,70 +1,15 @@
#include <esp_err.h>
#include <esp_log.h>
#include <esp_check.h>
#include <esp_lcd_panel_io.h>
#include <esp_lvgl_port.h>
#include <nanobake.h>
// Nanobake board support with drivers:
#include <board_2432s024_touch.h>
#include <board_2432s024_display.h>
#define EXAMPLE_LCD_DRAW_BUFF_DOUBLE (1)
#define EXAMPLE_LCD_DRAW_BUFF_HEIGHT (50)
#include <esp_lvgl_port.h>
static const char *TAG = "main";
// LVGL
static lv_disp_t* lvgl_disp = NULL;
static lv_indev_t* lvgl_touch_indev = NULL;
static esp_err_t app_lvgl_init(
nb_platform_t* platform
) {
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = 4,
.task_stack = 4096,
.task_affinity = -1, // core pinning
.task_max_sleep_ms = 500,
.timer_period_ms = 5
};
ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "lvgl port init failed");
// Add display
ESP_LOGD(TAG, "lvgl add display");
const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = platform->display.io_handle,
.panel_handle = platform->display.display_handle,
.buffer_size = platform->display.horizontal_resolution * platform->display.draw_buffer_height * (platform->display.bits_per_pixel / 8),
.double_buffer = EXAMPLE_LCD_DRAW_BUFF_DOUBLE,
.hres = platform->display.horizontal_resolution,
.vres = platform->display.vertical_resolution,
.monochrome = false,
/* Rotation values must be same as used in esp_lcd for initial settings of the screen */
.rotation = {
.swap_xy = false,
.mirror_x = true,
.mirror_y = false,
},
.flags = {
.buff_dma = true,
}
};
lvgl_disp = lvgl_port_add_disp(&disp_cfg);
// Add touch
const lvgl_port_touch_cfg_t touch_cfg = {
.disp = lvgl_disp,
.handle = platform->touch.touch_handle,
};
lvgl_touch_indev = lvgl_port_add_touch(&touch_cfg);
ESP_RETURN_ON_FALSE(lvgl_touch_indev != NULL, ESP_FAIL, TAG, "failed to add touch to lvgl");
return ESP_OK;
}
static void app_button_cb(lv_event_t* e) {
ESP_LOGI(TAG, "tap");
}
@ -99,7 +44,5 @@ void app_main(void) {
static nb_platform_t platform;
ESP_ERROR_CHECK(nb_platform_create(platform_config, &platform));
ESP_ERROR_CHECK(app_lvgl_init(&platform));
app_main_lvgl(&platform);
}