Button Peripheral

To control application flow you may use buttons connected and read through the ESP32 GPIOs. This API provides functions to initialize sepecifc GPIOs and obtain information on button events such as when it has been pressed, when released, when pressed for a long time and released after long press. To get information on particular event, establish a callback function with button_dev_add_tap_cb() or button_dev_add_press_cb().

Application Example

Implementation of this API is demonstrated in recorder/pipeline_raw_http example.

API Reference

Header File

Functions

esp_periph_handle_t periph_button_init(periph_button_cfg_t *but_cfg)

Create the button peripheral handle for esp_peripherals.

Note

The handle was created by this function automatically destroy when esp_periph_destroy is called

Return

The esp peripheral handle

Parameters
  • but_cfg: The but configuration

Structures

struct periph_button_cfg_t

The Button peripheral configuration.

Public Members

uint64_t gpio_mask

GPIO Mask using for this Button peripheral, it is BIT(GPIO_NUM), ex: GPIO_SEL_36 | GPIO_SEL_36

int long_press_time_ms

Long press duration in milliseconds, default is 2000ms

Enumerations

enum periph_button_event_id_t

Peripheral button event id.

Values:

PERIPH_BUTTON_UNCHANGE = 0

No event

PERIPH_BUTTON_PRESSED

When button is pressed

PERIPH_BUTTON_RELEASE

When button is released

PERIPH_BUTTON_LONG_PRESSED

When button is pressed and kept for more than long_press_time_ms

PERIPH_BUTTON_LONG_RELEASE

When button is released and event PERIPH_BUTTON_LONG_PRESSED happened