Skip to content

Support for no button #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/boards/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#endif

//------------- IMPLEMENTATION -------------//

#if defined(BUTTON_DFU) || defined(BUTTON_FRESET)

void button_init(uint32_t pin)
{
if ( BUTTON_PULL == NRF_GPIO_PIN_PULLDOWN )
Expand All @@ -62,6 +65,8 @@ bool button_pressed(uint32_t pin)
return nrf_gpio_pin_read(pin) == active_state;
}

#endif

// This is declared so that a board specific init can be called from here.
void __attribute__((weak)) board_init_extra(void) { }
void board_init(void)
Expand All @@ -73,8 +78,12 @@ void board_init(void)
NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC;
NRF_CLOCK->TASKS_LFCLKSTART = 1UL;

#ifdef BUTTON_DFU
button_init(BUTTON_DFU);
#endif
#ifdef BUTTON_FRESET
button_init(BUTTON_FRESET);
#endif
NRFX_DELAY_US(100); // wait for the pin state is stable

#if LEDS_NUMBER > 0
Expand Down
10 changes: 4 additions & 6 deletions src/boards/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#define UF2_VOLUME_LABEL "NRF52BOOT "
#endif

#ifndef BUTTON_DFU
#if !defined(BUTTON_DFU) && defined(BUTTON_1)
#define BUTTON_DFU BUTTON_1
#endif

#ifndef BUTTON_FRESET
#if !defined(BUTTON_FRESET) && defined(BUTTON_2)
#define BUTTON_FRESET BUTTON_2
#endif

Expand Down Expand Up @@ -104,13 +104,11 @@ void led_tick(void);
//--------------------------------------------------------------------+
// BUTTONS
//--------------------------------------------------------------------+
// Make sure we have at least two buttons (DFU + FRESET since DFU+FRST=OTA)
#if BUTTONS_NUMBER < 2
#error "At least two buttons required in the BSP (see 'BUTTONS_NUMBER')"
#endif

#if defined(BUTTON_DFU) || defined(BUTTON_FRESET)
void button_init(uint32_t pin);
bool button_pressed(uint32_t pin);
#endif

bool is_ota(void);

Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,14 @@ static void check_dfu_mode(void)

/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/
// DFU button pressed
#if defined(BUTTON_DFU)
dfu_start = dfu_start || button_pressed(BUTTON_DFU);
#endif

// DFU + FRESET are pressed --> OTA
#if defined(BUTTON_DFU) && defined(BUTTON_FRESET)
_ota_dfu = _ota_dfu || ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ;
#endif

bool const valid_app = bootloader_app_is_valid();
bool const just_start_app = valid_app && !dfu_start && (*dbl_reset_mem) == DFU_DBL_RESET_APP;
Expand Down