From c87aadc390bead4413decf20392d9c72ffc08ad8 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 17 Mar 2018 22:05:56 +0000 Subject: [PATCH] Change function to get button state to non-static --- os/dev/button-hal.c | 28 ++++++++++++++-------------- os/dev/button-hal.h | 8 ++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/os/dev/button-hal.c b/os/dev/button-hal.c index 8109739d6..4dff3c2c4 100644 --- a/os/dev/button-hal.c +++ b/os/dev/button-hal.c @@ -56,19 +56,6 @@ extern button_hal_button_t *button_hal_buttons[]; /* Common handler for all handler events, and register it with the GPIO HAL */ static gpio_hal_event_handler_t button_event_handler; /*---------------------------------------------------------------------------*/ -static uint8_t -get_state(button_hal_button_t *button) -{ - uint8_t pin_state = gpio_hal_arch_read_pin(button->pin); - - if((pin_state == 0 && button->negative_logic == true) || - (pin_state == 1 && button->negative_logic == false)) { - return BUTTON_HAL_STATE_PRESSED; - } - - return BUTTON_HAL_STATE_RELEASED; -} -/*---------------------------------------------------------------------------*/ static void duration_exceeded_callback(void *btn) { @@ -99,7 +86,7 @@ debounce_handler(void *btn) expired = ctimer_expired(&button->duration_ctimer); - button_state = get_state(button); + button_state = button_hal_get_state(button); /* * A debounce timer expired. Inspect the button's state. If the button's @@ -164,6 +151,19 @@ button_hal_get_by_id(uint8_t unique_id) return NULL; } /*---------------------------------------------------------------------------*/ +uint8_t +button_hal_get_state(button_hal_button_t *button) +{ + uint8_t pin_state = gpio_hal_arch_read_pin(button->pin); + + if((pin_state == 0 && button->negative_logic == true) || + (pin_state == 1 && button->negative_logic == false)) { + return BUTTON_HAL_STATE_PRESSED; + } + + return BUTTON_HAL_STATE_RELEASED; +} +/*---------------------------------------------------------------------------*/ void button_hal_init() { diff --git a/os/dev/button-hal.h b/os/dev/button-hal.h index 7d38994f7..02fa8555f 100644 --- a/os/dev/button-hal.h +++ b/os/dev/button-hal.h @@ -239,6 +239,14 @@ void button_hal_init(void); * \return A pointer to the button or NULL if not found */ button_hal_button_t *button_hal_get_by_id(uint8_t unique_id); + +/** + * \brief Get the state of a button (pressed / released) + * \param button A pointer to the button + * \retval BUTTON_HAL_STATE_RELEASED The button is currently released + * \retval BUTTON_HAL_STATE_PRESSED The button is currently pressed + */ +uint8_t button_hal_get_state(button_hal_button_t *button); /*---------------------------------------------------------------------------*/ #endif /* BUTTON_HAL_H_ */ /*---------------------------------------------------------------------------*/