diff --git a/BMLite_example/inc/platform.h b/BMLite_example/inc/platform.h index 1962de3..c64a3b6 100644 --- a/BMLite_example/inc/platform.h +++ b/BMLite_example/inc/platform.h @@ -44,7 +44,7 @@ typedef enum { } platform_led_status_t; /** - * @brief Initializes board functions + * @brief Initializes board * * @param[in] speed_hz Baudrate. */ diff --git a/HAL_Driver/src/platform.c b/HAL_Driver/src/platform.c index c814aff..890f892 100644 --- a/HAL_Driver/src/platform.c +++ b/HAL_Driver/src/platform.c @@ -90,8 +90,3 @@ void platform_set_led(platform_led_status_t color) { board_set_led(color); } - -uint32_t platform_get_button_press_time(void) -{ - return board_get_button_press_time(); -} diff --git a/HAL_Driver/src/platform_btns_leds.c b/HAL_Driver/src/platform_btns_leds.c index 072baf1..b01b96f 100644 --- a/HAL_Driver/src/platform_btns_leds.c +++ b/HAL_Driver/src/platform_btns_leds.c @@ -28,8 +28,6 @@ /** Board button used for app control */ #define BMLITE_BUTTON 3 -static uint32_t btn_press_start; -static uint32_t btn_pressed; static void _board_set_leds(uint8_t color) { @@ -48,45 +46,4 @@ static void _board_set_leds(uint8_t color) void board_set_led(platform_led_status_t color) { _board_set_leds(color); - // if (status == FPC_HAL_LED_STATUS_OFF) { - // board_set_leds(0); - // } else if (status == FPC_HAL_LED_STATUS_SOLID) { - // board_set_leds(color); - // platform_timebase_busy_wait(LED_SOLID_ON_TIME_MS); - // board_set_leds(0); - // } else if (status == FPC_HAL_LED_STATUS_ON) { - // board_set_leds(color); - // } else { - // uint32_t led_status = (uint32_t)(status - FPC_HAL_LED_STATUS_ONE_BLINK + 1); - // for (uint32_t i = 0; i < (led_status * 2); i++) { - // if (i % 2 == 0) { - // board_set_leds(0x8 + color); - // } else { - // board_set_leds(0x8); - // } - // platform_timebase_busy_wait(LED_BLINK_TIME_MS); - // } - // } -} - -uint32_t board_get_button_press_time() -{ - uint32_t time = 0; - if (bsp_board_button_state_get(BMLITE_BUTTON)) { - if (btn_pressed == 0) { - btn_press_start = platform_timebase_get_tick(); - btn_pressed = 1; - } - } else { // Btn released - if (btn_pressed) { - uint32_t curr_time = platform_timebase_get_tick(); - if (curr_time > btn_press_start) { - time = curr_time - btn_press_start; - } else { - time = curr_time + ~btn_press_start + 1; - } - btn_pressed = 0; - } - } - return time; } diff --git a/HAL_Driver/src/platform_timebase.c b/HAL_Driver/src/platform_timebase.c index 0d8ae22..f6a4f92 100755 --- a/HAL_Driver/src/platform_timebase.c +++ b/HAL_Driver/src/platform_timebase.c @@ -26,10 +26,19 @@ #include "nrf.h" #include "nrf_drv_timer.h" #include "nrfx_config.h" +#include "boards.h" const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0); static volatile uint32_t systick; +volatile uint32_t button_pressed_time = 0; + +static uint32_t btn_press_start; +static uint32_t btn_pressed = 0; + +#define BMLITE_BUTTON 3 + +static void check_buttons(); /** * @brief Handler for timer events. @@ -41,6 +50,7 @@ static void timer_event_handler(nrf_timer_event_t event_type, void* p_context) { case NRF_TIMER_EVENT_COMPARE0: systick++; + check_buttons(); break; default: @@ -49,7 +59,6 @@ static void timer_event_handler(nrf_timer_event_t event_type, void* p_context) } } - void platform_timebase_init(void) { uint32_t time_ms = 1; //Time (in miliseconds) between consecutive compare events. @@ -66,7 +75,6 @@ void platform_timebase_init(void) &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); nrf_drv_timer_enable(&TIMER_LED); - } void platform_timebase_busy_wait(uint32_t delay) @@ -87,3 +95,29 @@ uint32_t platform_timebase_get_tick(void) { return systick; } + +static void check_buttons() +{ + if (bsp_board_button_state_get(BMLITE_BUTTON)) { + if (btn_pressed == 0) { + btn_press_start = systick; + btn_pressed = 1; + } + } else { // Btn released + if (btn_pressed) { + if (systick > btn_press_start) { + button_pressed_time = systick - btn_press_start; + } else { + button_pressed_time = systick + ~btn_press_start + 1; + } + btn_pressed = 0; + } + } +} + +uint32_t platform_get_button_press_time() +{ + uint32_t time = button_pressed_time; + button_pressed_time = 0; + return time; +}