Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lvgl_port): Update LVGL port for using button v4 (breaking change!) #500

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions bsp/esp32_c3_lcdkit/esp32_c3_lcdkit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -23,6 +23,7 @@
#include "bsp_err_check.h"
#include "esp_lcd_gc9a01.h"
#include "iot_knob.h"
#include "button_gpio.h"
#include "esp_lvgl_port.h"
#include "esp_codec_dev_defaults.h"

Expand Down Expand Up @@ -78,10 +79,9 @@ static const led_strip_rmt_config_t bsp_rmt_config = {
.flags.with_dma = false,
};

static const button_config_t bsp_encoder_btn_config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config.active_level = false,
.gpio_button_config.gpio_num = BSP_BTN_PRESS,
static const button_gpio_config_t bsp_encoder_btn_config = {
.gpio_num = BSP_BTN_PRESS,
.active_level = 0,
};

static const knob_config_t bsp_encoder_a_b_config = {
Expand Down Expand Up @@ -241,10 +241,15 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)

static lv_indev_t *bsp_display_indev_init(lv_display_t *disp)
{

const button_config_t btn_cfg = {0};
button_handle_t encoder_btn = NULL;
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &bsp_encoder_btn_config, &encoder_btn));

const lvgl_port_encoder_cfg_t encoder = {
.disp = disp,
.encoder_a_b = &bsp_encoder_a_b_config,
.encoder_enter = &bsp_encoder_btn_config
.encoder_enter = encoder_btn
};

return lvgl_port_add_encoder(&encoder);
Expand Down
4 changes: 2 additions & 2 deletions bsp/esp32_c3_lcdkit/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.1.0~1"
version: "1.2.0"
description: Board Support Package (BSP) for esp32_c3_lcdkit
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_c3_lcdkit

Expand Down Expand Up @@ -26,7 +26,7 @@ dependencies:

button:
public: true
version: ">=2,<4.0"
version: ">=4,<5.0"

knob:
version: "^0.1.3"
Expand Down
2 changes: 1 addition & 1 deletion bsp/m5dial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ M5Dial provides versatile power supply options to cater to various needs. It acc
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_gc9a01](https://components.espressif.com/components/espressif/esp_lcd_gc9a01) | ^1 |
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_ft5x06](https://components.espressif.com/components/espressif/esp_lcd_touch_ft5x06)| ^1 |
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) |>=2,<4.0|
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) |>=4,<5.0|
| KNOB |:heavy_check_mark:| [espressif/knob](https://components.espressif.com/components/espressif/knob) | ^0.1.3 |
| AUDIO | :x: | | |
|AUDIO_SPEAKER| :x: | | |
Expand Down
5 changes: 3 additions & 2 deletions bsp/m5dial/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.0"
version: "1.1.0"
description: Board Support Package (BSP) for M5Dial
url: https://github.com/espressif/esp-bsp/tree/master/bsp/m5dial

Expand All @@ -16,10 +16,11 @@ dependencies:
espressif/esp_lvgl_port:
version: "^2"
public: true
override_path: "../../components/esp_lvgl_port"

button:
public: true
version: ">=2,<4.0"
version: ">=4,<5.0"

knob:
version: "^0.1.3"
Expand Down
17 changes: 11 additions & 6 deletions bsp/m5dial/m5dial.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -21,6 +21,7 @@
#include "bsp/display.h"
#include "bsp/touch.h"
#include "iot_knob.h"
#include "button_gpio.h"
#include "esp_lcd_gc9a01.h"
#include "esp_lcd_touch_ft5x06.h"
#include "esp_lvgl_port.h"
Expand All @@ -37,10 +38,9 @@ static esp_lcd_touch_handle_t tp; // LCD touch handle
static bool i2c_initialized = false;
static bool spi_initialized = false;

static const button_config_t bsp_encoder_btn_config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config.active_level = false,
.gpio_button_config.gpio_num = BSP_BTN_PRESS,
static const button_gpio_config_t bsp_encoder_btn_config = {
.gpio_num = BSP_BTN_PRESS,
.active_level = 0,
};

static const knob_config_t bsp_encoder_a_b_config = {
Expand Down Expand Up @@ -307,10 +307,15 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)

static lv_indev_t *bsp_display_indev_encoder_init(lv_display_t *disp)
{

const button_config_t btn_cfg = {0};
button_handle_t encoder_btn = NULL;
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &bsp_encoder_btn_config, &encoder_btn));

const lvgl_port_encoder_cfg_t encoder = {
.disp = disp,
.encoder_a_b = &bsp_encoder_a_b_config,
.encoder_enter = &bsp_encoder_btn_config
.encoder_enter = encoder_btn
};

return lvgl_port_add_encoder(&encoder);
Expand Down
22 changes: 11 additions & 11 deletions bsp/m5stack_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ M5Stack Core is a development board based on ESP32 microcontroller. It features:

<!-- Autogenerated start: Dependencies -->
### Capabilities and dependencies
| Capability | Available | Component |Version|
|-------------|------------------|--------------------------------------------------------------------------------------------------|-------|
| DISPLAY |:heavy_check_mark:|[espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341)| ^1 |
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
| TOUCH | :x: | | |
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) | ^2.4 |
| AUDIO | :x: | | |
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC | :x: | | |
| SDCARD |:heavy_check_mark:| idf | >=5.2 |
| IMU | :x: | | |
| Capability | Available | Component | Version|
|-------------|------------------|--------------------------------------------------------------------------------------------------|--------|
| DISPLAY |:heavy_check_mark:|[espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341)| ^1 |
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
| TOUCH | :x: | | |
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) |>=4,<5.0|
| AUDIO | :x: | | |
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC | :x: | | |
| SDCARD |:heavy_check_mark:| idf | >=5.2 |
| IMU | :x: | | |
<!-- Autogenerated end: Dependencies -->
7 changes: 4 additions & 3 deletions bsp/m5stack_core/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.0"
version: "1.1.0"
description: Board Support Package (BSP) for M5Stack Core
url: https://github.com/espressif/esp-bsp/tree/master/bsp/m5stack_core

Expand All @@ -13,9 +13,10 @@ dependencies:
esp_lcd_ili9341: "^1"

button:
version: "^2.4"
version: ">=4,<5.0"
public: true

espressif/esp_lvgl_port:
version: "^2"
public: true
override_path: "../../components/esp_lvgl_port"
37 changes: 22 additions & 15 deletions bsp/m5stack_core/m5stack_core.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -25,6 +25,7 @@
#include "bsp/display.h"
#include "esp_lcd_ili9341.h"
#include "bsp_err_check.h"
#include "button_gpio.h"

static const char *TAG = "M5Stack";

Expand Down Expand Up @@ -363,31 +364,36 @@ static lv_display_t *bsp_display_lcd_init(const bsp_display_cfg_t *cfg)
return lvgl_port_add_disp(&disp_cfg);
}

static const button_config_t bsp_button_config[BSP_BUTTON_NUM] = {
static const button_gpio_config_t bsp_button_config[BSP_BUTTON_NUM] = {
{
.type = BUTTON_TYPE_GPIO,
.gpio_button_config.active_level = false,
.gpio_button_config.gpio_num = BSP_BUTTON_LEFT,
.gpio_num = BSP_BUTTON_LEFT,
.active_level = 0,
},
{
.type = BUTTON_TYPE_GPIO,
.gpio_button_config.active_level = false,
.gpio_button_config.gpio_num = BSP_BUTTON_MIDDLE,
.gpio_num = BSP_BUTTON_MIDDLE,
.active_level = 0,
},
{
.type = BUTTON_TYPE_GPIO,
.gpio_button_config.active_level = false,
.gpio_button_config.gpio_num = BSP_BUTTON_RIGHT,
.gpio_num = BSP_BUTTON_RIGHT,
.active_level = 0,
},
};

static lv_indev_t *bsp_display_indev_init(lv_display_t *disp)
{
const button_config_t btn_cfg = {0};
button_handle_t prev_btn = NULL;
button_handle_t next_btn = NULL;
button_handle_t enter_btn = NULL;
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[BSP_BUTTON_PREV], &prev_btn));
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[BSP_BUTTON_NEXT], &next_btn));
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[BSP_BUTTON_ENTER], &enter_btn));

const lvgl_port_nav_btns_cfg_t btns = {
.disp = disp,
.button_prev = &bsp_button_config[BSP_BUTTON_PREV],
.button_next = &bsp_button_config[BSP_BUTTON_NEXT],
.button_enter = &bsp_button_config[BSP_BUTTON_ENTER]
.button_prev = prev_btn,
.button_next = next_btn,
.button_enter = enter_btn
};

return lvgl_port_add_navigation_buttons(&btns);
Expand Down Expand Up @@ -455,8 +461,9 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
if (btn_cnt) {
*btn_cnt = 0;
}
const button_config_t btn_cfg = {0};
for (int i = 0; i < BSP_BUTTON_NUM; i++) {
btn_array[i] = iot_button_create(&bsp_button_config[i]);
ret |= iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[i], &btn_array[i]);
if (btn_array[i] == NULL) {
ret = ESP_FAIL;
break;
Expand Down
8 changes: 8 additions & 0 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 2.5.0

### Features (Breaking change)
- Updated LVGL port for using IoT button component v4 (LVGL port not anymore creating button, need to be created in app and included handle to LVGL port)

### Fixes
- Fixed buffer size by selected color format

## 2.4.4

### Features
Expand Down
14 changes: 14 additions & 0 deletions components/esp_lvgl_port/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ idf_build_get_property(build_components BUILD_COMPONENTS)
if("espressif__button" IN_LIST build_components)
list(APPEND ADD_SRCS "${PORT_PATH}/esp_lvgl_port_button.c")
list(APPEND ADD_LIBS idf::espressif__button)

idf_component_get_property(button_ver espressif__button COMPONENT_VERSION) # Get the version from esp-idf build system
endif()
if("button" IN_LIST build_components)
list(APPEND ADD_SRCS "${PORT_PATH}/esp_lvgl_port_button.c")
list(APPEND ADD_LIBS idf::button)

idf_component_get_property(button_ver button COMPONENT_VERSION) # Get the version from esp-idf build system
endif()
if("espressif__esp_lcd_touch" IN_LIST build_components)
list(APPEND ADD_SRCS "${PORT_PATH}/esp_lvgl_port_touch.c")
Expand All @@ -76,6 +80,16 @@ if("usb_host_hid" IN_LIST build_components)
list(APPEND ADD_LIBS idf::usb_host_hid)
endif()

if (NOT button_ver)
message("IOT button version is not set or empty!")
set(button_ver "4.0.0")
endif()

#Get component button major version
string(REPLACE "." ";" BUTTON_VERSION_LIST ${button_ver})
list(GET BUTTON_VERSION_LIST 0 button_ver_major)
add_definitions( "-DCOMPONENT_BUTTON_VERSION_MAJOR=${button_ver_major}" )

# Include SIMD assembly source code for rendering, only for (9.1.0 <= LVG_version < 9.2.0) and only for esp32 and esp32s3
if((lvgl_ver VERSION_GREATER_EQUAL "9.1.0") AND (lvgl_ver VERSION_LESS "9.2.0"))
if(CONFIG_IDF_TARGET_ESP32 OR CONFIG_IDF_TARGET_ESP32S3)
Expand Down
51 changes: 27 additions & 24 deletions components/esp_lvgl_port/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,35 @@ Add touch input to the LVGL. It can be called more times for adding more touch i
Add buttons input to the LVGL. It can be called more times for adding more buttons inputs for different displays. This feature is available only when the component `espressif/button` was added into the project.
``` c
/* Buttons configuration structure */
const button_config_t bsp_button_config[] = {
const button_gpio_config_t bsp_button_config[] = {
{
.type = BUTTON_TYPE_ADC,
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = 0,
.adc_button_config.min = 2310, // middle is 2410mV
.adc_button_config.max = 2510
.gpio_num = GPIO_NUM_37,
.active_level = 0,
},
{
.type = BUTTON_TYPE_ADC,
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = 1,
.adc_button_config.min = 1880, // middle is 1980mV
.adc_button_config.max = 2080
.gpio_num = GPIO_NUM_38,
.active_level = 0,
},
{
.type = BUTTON_TYPE_ADC,
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
.adc_button_config.button_index = 2,
.adc_button_config.min = 720, // middle is 820mV
.adc_button_config.max = 920
.gpio_num = GPIO_NUM_39,
.active_level = 0,
},
};


const button_config_t btn_cfg = {0};
button_handle_t prev_btn_handle = NULL;
button_handle_t next_btn_handle = NULL;
button_handle_t enter_btn_handle = NULL;
iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[0], &prev_btn_handle);
iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[1], &next_btn_handle);
iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[2], &enter_btn_handle);

const lvgl_port_nav_btns_cfg_t btns = {
.disp = disp_handle,
.button_prev = &bsp_button_config[0],
.button_next = &bsp_button_config[1],
.button_enter = &bsp_button_config[2]
.button_prev = prev_btn_handle,
.button_next = next_btn_handle,
.button_enter = enter_btn_handle
};

/* Add buttons input (for selected screen) */
Expand All @@ -160,10 +160,9 @@ Add buttons input to the LVGL. It can be called more times for adding more butto
Add encoder input to the LVGL. It can be called more times for adding more encoder inputs for different displays. This feature is available only when the component `espressif/knob` was added into the project.
``` c

const button_config_t encoder_btn_config = {
.type = BUTTON_TYPE_GPIO,
.gpio_button_config.active_level = false,
.gpio_button_config.gpio_num = GPIO_BTN_PRESS,
static const button_gpio_config_t encoder_btn_config = {
.gpio_num = GPIO_BTN_PRESS,
.active_level = 0,
};

const knob_config_t encoder_a_b_config = {
Expand All @@ -172,11 +171,15 @@ Add encoder input to the LVGL. It can be called more times for adding more encod
.gpio_encoder_b = GPIO_ENCODER_B,
};

const button_config_t btn_cfg = {0};
button_handle_t encoder_btn_handle = NULL;
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &encoder_btn_config, &encoder_btn_handle));

/* Encoder configuration structure */
const lvgl_port_encoder_cfg_t encoder = {
.disp = disp_handle,
.encoder_a_b = &encoder_a_b_config,
.encoder_enter = &encoder_btn_config
.encoder_enter = encoder_btn_handle
};

/* Add encoder input (for selected screen) */
Expand Down
2 changes: 1 addition & 1 deletion components/esp_lvgl_port/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.4.4"
version: "2.5.0"
description: ESP LVGL port
url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port
dependencies:
Expand Down
Loading