Button Input¶
The button module (zephyr input) is responsible for:
- detects button press and release events
- has an enum for its current state:
BUTTON_STATE::PRESSEDwhen the button is pressed.
BUTTON_STATE::RELEASEDwhen the button is released.
BUTTON_STATE::ENGAGE_SEQUENCEwhen a long press is detected. - querrying the initial state of the button on boot
Dependencies¶
The module is dependent on the
Input subsystem which provides
api's for dispatching input events from input devices (e.g., gpios) to the application.
Usage¶
This module provides a simple interface for handling button events within a Zephyr-based system.
The button node must be defined in the device tree. Take a look at the following example from the
bms.dts:
/{
user_button: user_button {
compatible = "gpio-keys";
debounce-interval-ms = <20>;
polling-mode;
sw0: sw0 {
gpios = <&gpioa 0 GPIO_ACTIVE_HIGH>;
label = "External Button";
zephyr,code = <INPUT_KEY_0>;
};
};
longpress: longpress {
input = <&user_button>;
compatible = "zephyr,input-longpress";
input-codes = <INPUT_KEY_0>;
long-codes = <INPUT_KEY_1>;
long-delay-ms = <1000>;
};
aliases {
sw0 = &sw0;
};
};
Take a look at the
properties
applies to the gpio-keys compatible nodes.
Take a look at the
properties
applies to the zephyr,input-longpress compatible nodes.