button - Driver for GPIO buttons with anti-jitter and auto repeat

group button

ESP-IDF driver for simple GPIO buttons.

Supports anti-jitter, auto repeat, long press.

Copyright (c) 2021 Ruslan V. Uss unclerus@gmail.com

MIT Licensed as described in the file LICENSE

Typedefs

typedef struct button_s button_t

Typedef of button descriptor.

typedef void (*button_event_cb_t)(button_t *btn, button_state_t state)

Callback prototype.

Param btn

Pointer to button descriptor

Param state

Button action (new state)

Enums

enum button_state_t

Button states/events.

Values:

enumerator BUTTON_PRESSED
enumerator BUTTON_RELEASED
enumerator BUTTON_CLICKED
enumerator BUTTON_PRESSED_LONG

Functions

esp_err_t button_init(button_t *btn)

Init button.

Parameters

btn – Pointer to button descriptor

Returns

ESP_OK on success

esp_err_t button_done(button_t *btn)

Deinit button.

Parameters

btn – Pointer to button descriptor

Returns

ESP_OK on success

struct button_s
#include <button.h>

Button descriptor struct.

Public Members

gpio_num_t gpio

GPIO.

bool internal_pull

Enable internal pull-up/pull-down.

uint8_t pressed_level

Logic level of pressed button.

bool autorepeat

Enable autorepeat.

button_event_cb_t callback

Button callback.

void *ctx

User data.

struct button_s::[anonymous] internal

Internal button state.