23 #include "nrf_error.h"
25 #include "nrf_gpiote.h"
27 #include "app_timer.h"
28 #include "app_util_platform.h"
31 #define GPIOTE_CHANNEL_NUMBER_BUTTON_PRESS 0
32 #define GPIOTE_CHANNEL_NUMBER_BUTTON_RELEASE 1
33 #define DFU_BUTTON_PIN 17
34 #define GPIOTE_IRQ_INTENCLR_ALL_VAL 0xffffffff
35 #define GPIOTE_IRQ_ENABLE_VAL 3
37 static uint32_t m_button_press_duration_ms;
38 static uint8_t m_app_timer_prescaler;
40 void common_hal_buttons_init(uint32_t button_press_duration_ms, uint8_t app_timer_prescaler)
50 NVIC_ClearPendingIRQ(GPIOTE_IRQn);
51 NVIC_SetPriority(GPIOTE_IRQn, APP_IRQ_PRIORITY_LOW);
52 NVIC_EnableIRQ(GPIOTE_IRQn);
59 static uint32_t ticks_at_button_release, ticks_at_button_press;
60 uint32_t diff, err_code;
65 err_code = app_timer_cnt_get(&ticks_at_button_press);
66 APP_ERROR_CHECK(err_code);
74 err_code = app_timer_cnt_get(&ticks_at_button_release);
75 APP_ERROR_CHECK(err_code);
77 diff =
ticks_diff(ticks_at_button_release, ticks_at_button_press);
uint32_t ticks_diff(uint32_t ticks_now, uint32_t ticks_old)
bool dfu_check(void)
Needs to be implemented by application. Check if it is OK to jump to the DFU application.
void dfu_start(void)
Starts DFU mode. The function writes a special value to retention register to tell bootloader to star...
void terminate(void)
Needs to be implemented by application. Perform all requried actions before jump to DFU application c...