Skip to content

Commit de9a9b7

Browse files
committed
refactor: deduplicate code for disabling SD
1 parent b8544f5 commit de9a9b7

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/main.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ static void mbr_init_sd(void) {
157157
sd_mbr_command(&com);
158158
}
159159

160-
// Helper function to check if SoftDevice is already enabled.
160+
// Helper function to disable the SoftDevice with upfront check if it is enabled.
161161
// Especially SoftDevice S340 locks up when calling sd_softdevice_disable() and it's not enabled.
162-
static bool is_sd_enabled(void) {
162+
static void sd_disable(void) {
163163
uint8_t sd_enabled = 0;
164164
sd_softdevice_is_enabled(&sd_enabled);
165-
return (sd_enabled == 1);
165+
if (sd_enabled == 1) {
166+
sd_softdevice_disable();
167+
}
166168
}
167169

168170
//--------------------------------------------------------------------+
@@ -214,9 +216,7 @@ int main(void) {
214216
if (!_sd_inited) mbr_init_sd();
215217

216218
// Make sure SD is disabled
217-
if (is_sd_enabled()) {
218-
sd_softdevice_disable();
219-
}
219+
sd_disable();
220220
}
221221

222222
// clear in case we kept DFU_DBL_RESET_APP there
@@ -317,9 +317,7 @@ static void check_dfu_mode(void) {
317317
}
318318

319319
if (_ota_dfu) {
320-
if (is_sd_enabled()) {
321-
sd_softdevice_disable();
322-
}
320+
sd_disable();
323321
} else {
324322
usb_teardown();
325323
}

0 commit comments

Comments
 (0)