Skip to content

Commit 56792df

Browse files
Merge pull request #511 from espressif/feat/lvgl_port_button_v4_new
feat(lvgl_port): Update LVGL port for using button v4
2 parents 35a10dc + f05983f commit 56792df

8 files changed

+106
-39
lines changed

components/esp_lvgl_port/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 2.5.0
4+
5+
### Features (Functional change for button v4 users)
6+
- 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)
7+
8+
### Fixes
9+
- Fixed buffer size by selected color format
10+
311
## 2.4.4
412

513
### Features

components/esp_lvgl_port/README.md

+27-24
Original file line numberDiff line numberDiff line change
@@ -113,35 +113,35 @@ Add touch input to the LVGL. It can be called more times for adding more touch i
113113
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.
114114
``` c
115115
/* Buttons configuration structure */
116-
const button_config_t bsp_button_config[] = {
116+
const button_gpio_config_t bsp_button_config[] = {
117117
{
118-
.type = BUTTON_TYPE_ADC,
119-
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
120-
.adc_button_config.button_index = 0,
121-
.adc_button_config.min = 2310, // middle is 2410mV
122-
.adc_button_config.max = 2510
118+
.gpio_num = GPIO_NUM_37,
119+
.active_level = 0,
123120
},
124121
{
125-
.type = BUTTON_TYPE_ADC,
126-
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
127-
.adc_button_config.button_index = 1,
128-
.adc_button_config.min = 1880, // middle is 1980mV
129-
.adc_button_config.max = 2080
122+
.gpio_num = GPIO_NUM_38,
123+
.active_level = 0,
130124
},
131125
{
132-
.type = BUTTON_TYPE_ADC,
133-
.adc_button_config.adc_channel = ADC_CHANNEL_0, // ADC1 channel 0 is GPIO1
134-
.adc_button_config.button_index = 2,
135-
.adc_button_config.min = 720, // middle is 820mV
136-
.adc_button_config.max = 920
126+
.gpio_num = GPIO_NUM_39,
127+
.active_level = 0,
137128
},
138129
};
139130

131+
132+
const button_config_t btn_cfg = {0};
133+
button_handle_t prev_btn_handle = NULL;
134+
button_handle_t next_btn_handle = NULL;
135+
button_handle_t enter_btn_handle = NULL;
136+
iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[0], &prev_btn_handle);
137+
iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[1], &next_btn_handle);
138+
iot_button_new_gpio_device(&btn_cfg, &bsp_button_config[2], &enter_btn_handle);
139+
140140
const lvgl_port_nav_btns_cfg_t btns = {
141141
.disp = disp_handle,
142-
.button_prev = &bsp_button_config[0],
143-
.button_next = &bsp_button_config[1],
144-
.button_enter = &bsp_button_config[2]
142+
.button_prev = prev_btn_handle,
143+
.button_next = next_btn_handle,
144+
.button_enter = enter_btn_handle
145145
};
146146

147147
/* Add buttons input (for selected screen) */
@@ -160,10 +160,9 @@ Add buttons input to the LVGL. It can be called more times for adding more butto
160160
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.
161161
``` c
162162
163-
const button_config_t encoder_btn_config = {
164-
.type = BUTTON_TYPE_GPIO,
165-
.gpio_button_config.active_level = false,
166-
.gpio_button_config.gpio_num = GPIO_BTN_PRESS,
163+
static const button_gpio_config_t encoder_btn_config = {
164+
.gpio_num = GPIO_BTN_PRESS,
165+
.active_level = 0,
167166
};
168167
169168
const knob_config_t encoder_a_b_config = {
@@ -172,11 +171,15 @@ Add encoder input to the LVGL. It can be called more times for adding more encod
172171
.gpio_encoder_b = GPIO_ENCODER_B,
173172
};
174173
174+
const button_config_t btn_cfg = {0};
175+
button_handle_t encoder_btn_handle = NULL;
176+
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &encoder_btn_config, &encoder_btn_handle));
177+
175178
/* Encoder configuration structure */
176179
const lvgl_port_encoder_cfg_t encoder = {
177180
.disp = disp_handle,
178181
.encoder_a_b = &encoder_a_b_config,
179-
.encoder_enter = &encoder_btn_config
182+
.encoder_enter = encoder_btn_handle
180183
};
181184
182185
/* Add encoder input (for selected screen) */

components/esp_lvgl_port/include/esp_lvgl_port_button.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -32,10 +32,16 @@ extern "C" {
3232
* @brief Configuration of the navigation buttons structure
3333
*/
3434
typedef struct {
35-
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
35+
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
36+
#if BUTTON_VER_MAJOR < 4
3637
const button_config_t *button_prev; /*!< Navigation button for previous */
3738
const button_config_t *button_next; /*!< Navigation button for next */
3839
const button_config_t *button_enter; /*!< Navigation button for enter */
40+
#else
41+
button_handle_t button_prev; /*!< Handle for navigation button for previous */
42+
button_handle_t button_next; /*!< Handle for navigation button for next */
43+
button_handle_t button_enter; /*!< Handle for navigation button for enter */
44+
#endif
3945
} lvgl_port_nav_btns_cfg_t;
4046

4147
/**

components/esp_lvgl_port/include/esp_lvgl_port_knob.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -36,9 +36,13 @@ extern "C" {
3636
* @brief Configuration of the encoder structure
3737
*/
3838
typedef struct {
39-
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
40-
const knob_config_t *encoder_a_b;
39+
lv_display_t *disp; /*!< LVGL display handle (returned from lvgl_port_add_disp) */
40+
const knob_config_t *encoder_a_b; /*!< Encoder knob configuration */
41+
#if BUTTON_VER_MAJOR < 4
4142
const button_config_t *encoder_enter; /*!< Navigation button for enter */
43+
#else
44+
button_handle_t encoder_enter; /*!< Handle for enter button */
45+
#endif
4246
} lvgl_port_encoder_cfg_t;
4347

4448
/**

components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_button.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -56,6 +56,7 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
5656
return NULL;
5757
}
5858

59+
#if BUTTON_VER_MAJOR < 4
5960
/* Previous button */
6061
if (buttons_cfg->button_prev != NULL) {
6162
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = iot_button_create(buttons_cfg->button_prev);
@@ -73,11 +74,23 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
7374
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = iot_button_create(buttons_cfg->button_enter);
7475
ESP_GOTO_ON_FALSE(buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER], ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
7576
}
77+
#else
78+
ESP_GOTO_ON_FALSE(buttons_cfg->button_prev && buttons_cfg->button_next && buttons_cfg->button_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid some button handler!");
79+
80+
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = buttons_cfg->button_prev;
81+
buttons_ctx->btn[LVGL_PORT_NAV_BTN_NEXT] = buttons_cfg->button_next;
82+
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = buttons_cfg->button_enter;
83+
#endif
7684

7785
/* Button handlers */
7886
for (int i = 0; i < LVGL_PORT_NAV_BTN_CNT; i++) {
87+
#if BUTTON_VER_MAJOR < 4
7988
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, lvgl_port_btn_down_handler, buttons_ctx));
8089
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, lvgl_port_btn_up_handler, buttons_ctx));
90+
#else
91+
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, NULL, lvgl_port_btn_down_handler, buttons_ctx));
92+
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, NULL, lvgl_port_btn_up_handler, buttons_ctx));
93+
#endif
8194
}
8295

8396
buttons_ctx->btn_prev = false;

components/esp_lvgl_port/src/lvgl8/esp_lvgl_port_knob.c

+10
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,22 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg)
6363

6464
/* Encoder Enter */
6565
if (encoder_cfg->encoder_enter != NULL) {
66+
#if BUTTON_VER_MAJOR < 4
6667
encoder_ctx->btn_handle = iot_button_create(encoder_cfg->encoder_enter);
6768
ESP_GOTO_ON_FALSE(encoder_ctx->btn_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
69+
#else
70+
ESP_GOTO_ON_FALSE(encoder_cfg->encoder_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid button handler!");
71+
encoder_ctx->btn_handle = encoder_cfg->encoder_enter;
72+
#endif
6873
}
6974

75+
#if BUTTON_VER_MAJOR < 4
7076
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, lvgl_port_encoder_btn_down_handler, encoder_ctx));
7177
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, lvgl_port_encoder_btn_up_handler, encoder_ctx));
78+
#else
79+
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, NULL, lvgl_port_encoder_btn_down_handler, encoder_ctx));
80+
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, NULL, lvgl_port_encoder_btn_up_handler, encoder_ctx));
81+
#endif
7282

7383
encoder_ctx->btn_enter = false;
7484
encoder_ctx->diff = 0;

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_button.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -56,6 +56,7 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
5656
return NULL;
5757
}
5858

59+
#if BUTTON_VER_MAJOR < 4
5960
/* Previous button */
6061
if (buttons_cfg->button_prev != NULL) {
6162
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = iot_button_create(buttons_cfg->button_prev);
@@ -73,11 +74,23 @@ lv_indev_t *lvgl_port_add_navigation_buttons(const lvgl_port_nav_btns_cfg_t *but
7374
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = iot_button_create(buttons_cfg->button_enter);
7475
ESP_GOTO_ON_FALSE(buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER], ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
7576
}
77+
#else
78+
ESP_GOTO_ON_FALSE(buttons_cfg->button_prev && buttons_cfg->button_next && buttons_cfg->button_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid some button handler!");
79+
80+
buttons_ctx->btn[LVGL_PORT_NAV_BTN_PREV] = buttons_cfg->button_prev;
81+
buttons_ctx->btn[LVGL_PORT_NAV_BTN_NEXT] = buttons_cfg->button_next;
82+
buttons_ctx->btn[LVGL_PORT_NAV_BTN_ENTER] = buttons_cfg->button_enter;
83+
#endif
7684

7785
/* Button handlers */
7886
for (int i = 0; i < LVGL_PORT_NAV_BTN_CNT; i++) {
87+
#if BUTTON_VER_MAJOR < 4
7988
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, lvgl_port_btn_down_handler, buttons_ctx));
8089
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, lvgl_port_btn_up_handler, buttons_ctx));
90+
#else
91+
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_DOWN, NULL, lvgl_port_btn_down_handler, buttons_ctx));
92+
ESP_ERROR_CHECK(iot_button_register_cb(buttons_ctx->btn[i], BUTTON_PRESS_UP, NULL, lvgl_port_btn_up_handler, buttons_ctx));
93+
#endif
8194
}
8295

8396
buttons_ctx->btn_prev = false;

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_knob.c

+18-8
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ typedef struct {
2828
*******************************************************************************/
2929

3030
static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data);
31-
static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2);
32-
static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2);
31+
static void lvgl_port_encoder_btn_down_handler(void *button_handle, void *usr_data);
32+
static void lvgl_port_encoder_btn_up_handler(void *button_handle, void *usr_data);
3333
static void lvgl_port_encoder_left_handler(void *arg, void *arg2);
3434
static void lvgl_port_encoder_right_handler(void *arg, void *arg2);
3535
static int32_t lvgl_port_calculate_diff(knob_handle_t knob, knob_event_t event);
@@ -63,12 +63,22 @@ lv_indev_t *lvgl_port_add_encoder(const lvgl_port_encoder_cfg_t *encoder_cfg)
6363

6464
/* Encoder Enter */
6565
if (encoder_cfg->encoder_enter != NULL) {
66+
#if BUTTON_VER_MAJOR < 4
6667
encoder_ctx->btn_handle = iot_button_create(encoder_cfg->encoder_enter);
6768
ESP_GOTO_ON_FALSE(encoder_ctx->btn_handle, ESP_ERR_NO_MEM, err, TAG, "Not enough memory for button create!");
69+
#else
70+
ESP_GOTO_ON_FALSE(encoder_cfg->encoder_enter, ESP_ERR_INVALID_ARG, err, TAG, "Invalid button handler!");
71+
encoder_ctx->btn_handle = encoder_cfg->encoder_enter;
72+
#endif
6873
}
6974

75+
#if BUTTON_VER_MAJOR < 4
7076
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, lvgl_port_encoder_btn_down_handler, encoder_ctx));
7177
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, lvgl_port_encoder_btn_up_handler, encoder_ctx));
78+
#else
79+
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_DOWN, NULL, lvgl_port_encoder_btn_down_handler, encoder_ctx));
80+
ESP_ERROR_CHECK(iot_button_register_cb(encoder_ctx->btn_handle, BUTTON_PRESS_UP, NULL, lvgl_port_encoder_btn_up_handler, encoder_ctx));
81+
#endif
7282

7383
encoder_ctx->btn_enter = false;
7484
encoder_ctx->diff = 0;
@@ -143,10 +153,10 @@ static void lvgl_port_encoder_read(lv_indev_t *indev_drv, lv_indev_data_t *data)
143153
ctx->diff = 0;
144154
}
145155

146-
static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2)
156+
static void lvgl_port_encoder_btn_down_handler(void *button_handle, void *usr_data)
147157
{
148-
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
149-
button_handle_t button = (button_handle_t)arg;
158+
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) usr_data;
159+
button_handle_t button = (button_handle_t)button_handle;
150160
if (ctx && button) {
151161
/* ENTER */
152162
if (button == ctx->btn_handle) {
@@ -158,10 +168,10 @@ static void lvgl_port_encoder_btn_down_handler(void *arg, void *arg2)
158168
lvgl_port_task_wake(LVGL_PORT_EVENT_TOUCH, ctx->indev);
159169
}
160170

161-
static void lvgl_port_encoder_btn_up_handler(void *arg, void *arg2)
171+
static void lvgl_port_encoder_btn_up_handler(void *button_handle, void *usr_data)
162172
{
163-
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) arg2;
164-
button_handle_t button = (button_handle_t)arg;
173+
lvgl_port_encoder_ctx_t *ctx = (lvgl_port_encoder_ctx_t *) usr_data;
174+
button_handle_t button = (button_handle_t)button_handle;
165175
if (ctx && button) {
166176
/* ENTER */
167177
if (button == ctx->btn_handle) {

0 commit comments

Comments
 (0)