Skip to content

Commit 01268e0

Browse files
authored
Merge pull request #500 from espressif/feat/lvgl_port_button_v4
bsp: Update BSPs for using button v4
2 parents 23d3a43 + 43d1158 commit 01268e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+595
-468
lines changed

bsp/esp-box-3/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ ESP32-S3-BOX-3 also uses a Type-C USB connector that provides 5 V of power input
1616

1717
<!-- Autogenerated start: Dependencies -->
1818
### Capabilities and dependencies
19-
| Capability | Available | Component | Version |
20-
|-------------|------------------|----------------------------------------------------------------------------------------------------------|----------|
21-
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341) | ^1 |
22-
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
23-
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_gt911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911)| ^1 |
24-
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) |>=2.5,<4.0|
25-
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.3.1 |
26-
|AUDIO_SPEAKER|:heavy_check_mark:| | |
27-
| AUDIO_MIC |:heavy_check_mark:| | |
28-
| SDCARD |:heavy_check_mark:| idf | >=5.3 |
29-
| IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.1 |
19+
| Capability | Available | Component |Version|
20+
|-------------|------------------|----------------------------------------------------------------------------------------------------------|-------|
21+
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341) | ^1 |
22+
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
23+
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_gt911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911)| ^1 |
24+
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) | ^4 |
25+
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.3.1|
26+
|AUDIO_SPEAKER|:heavy_check_mark:| | |
27+
| AUDIO_MIC |:heavy_check_mark:| | |
28+
| SDCARD |:heavy_check_mark:| idf | >=5.3 |
29+
| IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.1|
3030
<!-- Autogenerated end: Dependencies -->

bsp/esp-box-3/esp-box-3.c

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "esp_vfs_fat.h"
1818

1919
#include "iot_button.h"
20+
#include "button_gpio.h"
2021
#include "bsp/esp-box-3.h"
2122
#include "bsp/display.h"
2223
#include "bsp/touch.h"
@@ -73,27 +74,44 @@ static i2c_master_bus_handle_t i2c_handle = NULL;
7374
static bool i2c_initialized = false;
7475

7576
// This is just a wrapper to get function signature for espressif/button API callback
76-
static uint8_t bsp_get_main_button(void *param);
77-
static esp_err_t bsp_init_main_button(void *param);
78-
79-
static const button_config_t bsp_button_config[BSP_BUTTON_NUM] = {
77+
static uint8_t bsp_get_main_button(button_driver_t *button_driver);
78+
79+
typedef enum {
80+
BSP_BUTTON_TYPE_GPIO,
81+
BSP_BUTTON_TYPE_CUSTOM
82+
} bsp_button_type_t;
83+
84+
typedef struct {
85+
bsp_button_type_t type;
86+
union {
87+
button_gpio_config_t gpio;
88+
button_driver_t custom;
89+
} cfg;
90+
} bsp_button_config_t;
91+
92+
static const bsp_button_config_t bsp_button_config[BSP_BUTTON_NUM] = {
8093
{
81-
.type = BUTTON_TYPE_GPIO,
82-
.gpio_button_config.gpio_num = BSP_BUTTON_CONFIG_IO,
83-
.gpio_button_config.active_level = 0,
94+
.type = BSP_BUTTON_TYPE_GPIO,
95+
.cfg.gpio = {
96+
.gpio_num = BSP_BUTTON_CONFIG_IO,
97+
.active_level = 0,
98+
}
8499
},
85100
{
86-
.type = BUTTON_TYPE_GPIO,
87-
.gpio_button_config.gpio_num = BSP_BUTTON_MUTE_IO,
88-
.gpio_button_config.active_level = 0,
101+
.type = BSP_BUTTON_TYPE_GPIO,
102+
.cfg.gpio = {
103+
.gpio_num = BSP_BUTTON_MUTE_IO,
104+
.active_level = 0,
105+
}
89106
},
90107
{
91-
.type = BUTTON_TYPE_CUSTOM,
92-
.custom_button_config.button_custom_init = bsp_init_main_button,
93-
.custom_button_config.button_custom_get_key_value = bsp_get_main_button,
94-
.custom_button_config.button_custom_deinit = NULL,
95-
.custom_button_config.active_level = 1,
96-
.custom_button_config.priv = (void *) BSP_BUTTON_MAIN,
108+
.type = BSP_BUTTON_TYPE_CUSTOM,
109+
.cfg.custom = {
110+
.enable_power_save = false,
111+
.get_key_level = bsp_get_main_button,
112+
.enter_power_save = NULL,
113+
.del = NULL
114+
}
97115
}
98116
};
99117

@@ -630,7 +648,7 @@ esp_err_t bsp_display_exit_sleep(void)
630648
}
631649
#endif // (BSP_CONFIG_NO_GRAPHIC_LIB == 0)
632650

633-
static uint8_t bsp_get_main_button(void *param)
651+
static uint8_t bsp_get_main_button(button_driver_t *button_driver)
634652
{
635653
assert(tp);
636654
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
@@ -643,17 +661,10 @@ static uint8_t bsp_get_main_button(void *param)
643661
#endif
644662
}
645663

646-
static esp_err_t bsp_init_main_button(void *param)
647-
{
648-
if (tp == NULL) {
649-
BSP_ERROR_CHECK_RETURN_ERR(bsp_touch_new(NULL, &tp));
650-
}
651-
return ESP_OK;
652-
}
653-
654664
esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int btn_array_size)
655665
{
656666
esp_err_t ret = ESP_OK;
667+
const button_config_t btn_config = {0};
657668
if ((btn_array_size < BSP_BUTTON_NUM) ||
658669
(btn_array == NULL)) {
659670
return ESP_ERR_INVALID_ARG;
@@ -663,10 +674,15 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
663674
*btn_cnt = 0;
664675
}
665676
for (int i = 0; i < BSP_BUTTON_NUM; i++) {
666-
btn_array[i] = iot_button_create(&bsp_button_config[i]);
667-
if (btn_array[i] == NULL) {
668-
ret = ESP_FAIL;
669-
break;
677+
if (bsp_button_config[i].type == BSP_BUTTON_TYPE_CUSTOM) {
678+
if (tp == NULL) {
679+
BSP_ERROR_CHECK_RETURN_ERR(bsp_touch_new(NULL, &tp));
680+
}
681+
ret |= iot_button_create(&btn_config, &bsp_button_config[i].cfg.custom, &btn_array[i]);
682+
} else if (bsp_button_config[i].type == BSP_BUTTON_TYPE_GPIO) {
683+
ret |= iot_button_new_gpio_device(&btn_config, &bsp_button_config[i].cfg.gpio, &btn_array[i]);
684+
} else {
685+
ESP_LOGW(TAG, "Unsupported button type!");
670686
}
671687
if (btn_cnt) {
672688
(*btn_cnt)++;

bsp/esp-box-3/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies:
2525
public: true
2626

2727
button:
28-
version: ">=2.5,<4.0"
28+
version: "^4"
2929
public: true
3030

3131
icm42670:

bsp/esp32_azure_iot_kit/README.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ ESP32-Azure IoT Kit has integrated an ESP32-WROVER-B module, serial port-to-USB
1919

2020
<!-- Autogenerated start: Dependencies -->
2121
### Capabilities and dependencies
22-
| Capability | Available | Component | Version |
23-
|------------------|------------------|----------------------------------------------------------------------------------------------|----------|
24-
| DISPLAY |:heavy_check_mark:| idf | >=4.4.5 |
25-
| LVGL_PORT |:heavy_check_mark:|[espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port)| ^2 |
26-
| TOUCH | :x: | | |
27-
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) |>=2.5,<4.0|
28-
| AUDIO | :x: | | |
29-
| AUDIO_SPEAKER | :x: | | |
30-
| AUDIO_MIC | :x: | | |
31-
| LED |:heavy_check_mark:| idf | >=4.4.5 |
32-
| SDCARD |:heavy_check_mark:| idf | >=4.4.5 |
33-
| IMU |:heavy_check_mark:| [espressif/mpu6050](https://components.espressif.com/components/espressif/mpu6050) | ^1.0.0 |
34-
|SENSOR_TEMPERATURE|:heavy_check_mark:| [espressif/hts221](https://components.espressif.com/components/espressif/hts221) | ^1.1.1 |
35-
| SENSOR_HUMIDITY |:heavy_check_mark:| [espressif/hts221](https://components.espressif.com/components/espressif/hts221) | ^1.1.1 |
36-
| SENSOR_PRESSURE |:heavy_check_mark:| [espressif/fbm320](https://components.espressif.com/components/espressif/fbm320) | ^1.0.0 |
37-
| SENSOR_LIGHT |:heavy_check_mark:| [espressif/bh1750](https://components.espressif.com/components/espressif/bh1750) | ^1.0.0 |
38-
| SENSOR_MAG |:heavy_check_mark:| [espressif/mag3110](https://components.espressif.com/components/espressif/mag3110) | ^1.0.0 |
22+
| Capability | Available | Component |Version|
23+
|------------------|------------------|----------------------------------------------------------------------------------------------|-------|
24+
| DISPLAY |:heavy_check_mark:| idf |>=4.4.5|
25+
| LVGL_PORT |:heavy_check_mark:|[espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port)| ^2 |
26+
| TOUCH | :x: | | |
27+
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) | ^4 |
28+
| AUDIO | :x: | | |
29+
| AUDIO_SPEAKER | :x: | | |
30+
| AUDIO_MIC | :x: | | |
31+
| LED |:heavy_check_mark:| idf |>=4.4.5|
32+
| SDCARD |:heavy_check_mark:| idf |>=4.4.5|
33+
| IMU |:heavy_check_mark:| [espressif/mpu6050](https://components.espressif.com/components/espressif/mpu6050) | ^1.0.0|
34+
|SENSOR_TEMPERATURE|:heavy_check_mark:| [espressif/hts221](https://components.espressif.com/components/espressif/hts221) | ^1.1.1|
35+
| SENSOR_HUMIDITY |:heavy_check_mark:| [espressif/hts221](https://components.espressif.com/components/espressif/hts221) | ^1.1.1|
36+
| SENSOR_PRESSURE |:heavy_check_mark:| [espressif/fbm320](https://components.espressif.com/components/espressif/fbm320) | ^1.0.0|
37+
| SENSOR_LIGHT |:heavy_check_mark:| [espressif/bh1750](https://components.espressif.com/components/espressif/bh1750) | ^1.0.0|
38+
| SENSOR_MAG |:heavy_check_mark:| [espressif/mag3110](https://components.espressif.com/components/espressif/mag3110) | ^1.0.0|
3939
<!-- Autogenerated end: Dependencies -->
4040
<!-- Autogenerated start: Dependencies -->
4141
### Capabilities and dependencies

bsp/esp32_azure_iot_kit/esp32_azure_iot_kit.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -16,18 +16,18 @@
1616
#include "bsp/display.h"
1717
#include "esp_lvgl_port.h"
1818
#include "bsp_err_check.h"
19+
#include "button_gpio.h"
1920

2021
static const char *TAG = "Azure-IoT";
2122

2223
static lv_display_t *disp;
2324
sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler
2425
static bool i2c_initialized = false;
2526

26-
static const button_config_t bsp_button_config[BSP_BUTTON_NUM] = {
27+
static const button_gpio_config_t bsp_button_config[BSP_BUTTON_NUM] = {
2728
{
28-
.type = BUTTON_TYPE_GPIO,
29-
.gpio_button_config.gpio_num = BSP_BUTTON_MAIN_IO,
30-
.gpio_button_config.active_level = 0,
29+
.gpio_num = BSP_BUTTON_MAIN_IO,
30+
.active_level = 0,
3131
}
3232
};
3333

@@ -382,6 +382,7 @@ bool bsp_button_get(void)
382382
esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int btn_array_size)
383383
{
384384
esp_err_t ret = ESP_OK;
385+
const button_config_t btn_config = {0};
385386
if ((btn_array_size < BSP_BUTTON_NUM) ||
386387
(btn_array == NULL)) {
387388
return ESP_ERR_INVALID_ARG;
@@ -391,11 +392,7 @@ esp_err_t bsp_iot_button_create(button_handle_t btn_array[], int *btn_cnt, int b
391392
*btn_cnt = 0;
392393
}
393394
for (int i = 0; i < BSP_BUTTON_NUM; i++) {
394-
btn_array[i] = iot_button_create(&bsp_button_config[i]);
395-
if (btn_array[i] == NULL) {
396-
ret = ESP_FAIL;
397-
break;
398-
}
395+
ret |= iot_button_new_gpio_device(&btn_config, &bsp_button_config[i], &btn_array[i]);
399396
if (btn_cnt) {
400397
(*btn_cnt)++;
401398
}

bsp/esp32_azure_iot_kit/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
override_path: "../../components/esp_lvgl_port"
1818

1919
button:
20-
version: ">=2.5,<4.0"
20+
version: "^4"
2121
public: true
2222

2323
hts221:

bsp/esp32_c3_lcdkit/esp32_c3_lcdkit.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -23,6 +23,7 @@
2323
#include "bsp_err_check.h"
2424
#include "esp_lcd_gc9a01.h"
2525
#include "iot_knob.h"
26+
#include "button_gpio.h"
2627
#include "esp_lvgl_port.h"
2728
#include "esp_codec_dev_defaults.h"
2829

@@ -78,10 +79,9 @@ static const led_strip_rmt_config_t bsp_rmt_config = {
7879
.flags.with_dma = false,
7980
};
8081

81-
static const button_config_t bsp_encoder_btn_config = {
82-
.type = BUTTON_TYPE_GPIO,
83-
.gpio_button_config.active_level = false,
84-
.gpio_button_config.gpio_num = BSP_BTN_PRESS,
82+
static const button_gpio_config_t bsp_encoder_btn_config = {
83+
.gpio_num = BSP_BTN_PRESS,
84+
.active_level = 0,
8585
};
8686

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

242242
static lv_indev_t *bsp_display_indev_init(lv_display_t *disp)
243243
{
244+
245+
const button_config_t btn_cfg = {0};
246+
button_handle_t encoder_btn = NULL;
247+
BSP_ERROR_CHECK_RETURN_NULL(iot_button_new_gpio_device(&btn_cfg, &bsp_encoder_btn_config, &encoder_btn));
248+
244249
const lvgl_port_encoder_cfg_t encoder = {
245250
.disp = disp,
246251
.encoder_a_b = &bsp_encoder_a_b_config,
247-
.encoder_enter = &bsp_encoder_btn_config
252+
.encoder_enter = encoder_btn
248253
};
249254

250255
return lvgl_port_add_encoder(&encoder);

bsp/esp32_c3_lcdkit/idf_component.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.1.0~1"
1+
version: "2.0.0"
22
description: Board Support Package (BSP) for esp32_c3_lcdkit
33
url: https://github.com/espressif/esp-bsp/tree/master/bsp/esp32_c3_lcdkit
44

@@ -26,7 +26,7 @@ dependencies:
2626

2727
button:
2828
public: true
29-
version: ">=2,<4.0"
29+
version: "^4"
3030

3131
knob:
3232
version: "^0.1.3"

bsp/esp32_lyrat/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The ESP32-LyraT is a stereo audio board. If you are looking for a mono audio boa
1818
|-------------|------------------|----------------------------------------------------------------------------------------------|-----------|
1919
| DISPLAY | :x: | | |
2020
| TOUCH | :x: | | |
21-
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) | >=2.5,<4.0|
21+
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) | ^4 |
2222
| AUDIO |:heavy_check_mark:|[espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev)|^1.0.3,<1.2|
2323
|AUDIO_SPEAKER|:heavy_check_mark:| | |
2424
| AUDIO_MIC |:heavy_check_mark:| | |

0 commit comments

Comments
 (0)