Skip to content

Commit

Permalink
Support for reset chip on canary
Browse files Browse the repository at this point in the history
  • Loading branch information
lolsborn committed Jul 17, 2023
1 parent a3408a9 commit d098f8e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/boards/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
#define BOARD_RGB_BRIGHTNESS 0x101010
#endif

// Rest chip support for devices with a battery and no dedicated reset button
#ifndef RESET_CHIP
#define RESET_CHIP 0
#endif

// Power configuration - should we enable DC/DC converters? (requires inductors on board)
#ifndef ENABLE_DCDC_0
#define ENABLE_DCDC_0 0
Expand Down
1 change: 1 addition & 0 deletions src/boards/canary/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define BUTTON_1 _PINNUM(0, 16)
#define BUTTON_2 _PINNUM(0, 15)
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
#define RESET_CHIP 1

//--------------------------------------------------------------------+
// BLE OTA
Expand Down
19 changes: 19 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,30 @@ static void check_dfu_mode(void)
if (dfu_skip) return;

/*------------- Determine DFU mode (Serial, OTA, FRESET or normal) -------------*/

#ifdef RESET_CHIP
// If both buttons are pressed --> skip dfu
// This is for boards that have no reset button
// but pressing both buttons will reset the chip
// after 10 seconds

// Wait 3 seconds before reading button state to allow user to release the buttons
NRFX_DELAY_MS(3000);

bool const reset_only = ( button_pressed(BUTTON_DFU) && button_pressed(BUTTON_FRESET) ) ;
if (reset_only) return;

// DFU button pressed
dfu_start = dfu_start || button_pressed(BUTTON_DFU);
_ota_dfu = _ota_dfu || button_pressed(BUTTON_FRESET);
if (_ota_dfu) dfu_start = true;
#else
// DFU button pressed
dfu_start = dfu_start || button_pressed(BUTTON_DFU);

// DFU + FRESET are pressed --> OTA
_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

0 comments on commit d098f8e

Please sign in to comment.