button.h
Sifli button library interface.
- Author
Sifli software development team
Unnamed Group
-
enum button_action_t
button action type
Values:
-
enumerator BUTTON_PRESSED
Indicates that a button is pressed
-
enumerator BUTTON_RELEASED
Indicates that a button is released
-
enumerator BUTTON_LONG_PRESSED
Indicates that a button is long released
-
enumerator BUTTON_CLICKED
Indicates that a button is clicked
-
enumerator BUTTON_PRESSED
-
enum button_active_state_t
button active level
Values:
-
enumerator BUTTON_ACTIVE_LOW
state is low when button is pressed
-
enumerator BUTTON_ACTIVE_HIGH
state is high when button is pressed
-
enumerator BUTTON_ACTIVE_LOW
-
typedef void (*button_handler_t)(int32_t pin, button_action_t button_action)
Button event handler type.
-
int32_t button_init(button_cfg_t *cfg)
Initialize the button.
- 参数:
cfg – [in] button config
- 返回:
button id. >=0 on success, otherwise an error code.
-
sf_err_t button_enable(int32_t id)
Enable specified button detection.
- 参数:
id – [in] button id allocated by button_init
- 返回值:
SF_EOK – button successfully enabled.
-
sf_err_t button_disable(int32_t id)
Disable specified button detection.
- 参数:
id – [in] button id allocated by button_init
- 返回值:
SF_EOK – Button detection successfully disabled. Error code otherwise.
-
bool button_is_pressed(int32_t id)
Check if specified button is currently being pressed.
- 参数:
id – [in] button id allocated by button_init
- 返回:
true: pressed, false: not pressed
-
void button_irq_trigger(int32_t pin)
Emulate the pin IRQ
- 参数:
pin – [in] pin
- 返回:
void
-
sf_err_t button_update_handler(int32_t id, button_handler_t new_handler)
Update button handler
- 参数:
id – [in] button id allocated by button_init
new_handler – [in] new button handler
- 返回:
SF_EOK handler update succesfully
-
struct button_cfg_t
- #include <button.h>
Button configuration structure.
Public Members
-
int32_t pin
Pin to be used as a button. Its range is same as pin argument of rt pin device
-
button_active_state_t active_state
pin state when button is pressed
-
uint32_t mode
Pull-up or -down mode, such as PIN_MODE_INPUT, PIN_MODE_INPUT_PULLUP or PIN_MODE_INPUT_PULLDOWN
-
button_handler_t button_handler
Handler to be called when button is pushed.
-
uint16_t debounce_time
debounce time in millisecond
-
int32_t pin