44#include "btl_interface.h"
55#include "em_cmu.h"
66#include "em_gpio.h"
7+ #include "em_rmu.h"
78#include "sl_main_init.h"
89
910#include <joybus/backend/gecko.h>
@@ -288,17 +289,29 @@ static bool qualify_packet(const uint8_t *packet)
288289 return (buttons & settings .pair_btns ) == settings .pair_btns ;
289290}
290291
291- // Initialize the various GPIOs
292- static void gpio_init (void )
292+ int main (void )
293293{
294+ // Initialize the device
295+ sl_main_init ();
296+
297+ // Enable millisecond systick interrupts
298+ SysTick_Config (CMU_ClockFreqGet (cmuClock_CORE ) / 1000 );
299+
294300 // Enable GPIO clocks
295301 CMU_ClockEnable (cmuClock_GPIO , true);
296302
297- // Make SWDIO available as a GPIO, if necessary
298- if (JOYBUS_PORT == GPIO_SWDIO_PORT && JOYBUS_PIN == GPIO_SWDIO_PIN ) {
299- printf ("[WARNING] Joybus is using SWDIO as GPIO, disabling SWD\n" );
300- GPIO_DbgSWDIOEnable (false);
303+ // Check the reset cause and clear it
304+ uint32_t resetCause = RMU_ResetCauseGet ();
305+ RMU_ResetCauseClear ();
306+
307+ // Make SWDIO/SWCLK available as a GPIOs
308+ // If the debugger caused the reset, delay first to let the probe disconnect
309+ if (resetCause & EMU_RSTCAUSE_SYSREQ ) {
310+ while (millis < 100 )
311+ ;
301312 }
313+ GPIO_DbgSWDIOEnable (false);
314+ GPIO_DbgSWDClkEnable (false);
302315
303316 // Initialize status LED, if present
304317#if HAS_STATUS_LED
@@ -325,18 +338,6 @@ static void gpio_init(void)
325338 CHANNEL_WHEEL_PIN_3 );
326339 channel_wheel_set_change_callback (channel_wheel , handle_channel_wheel_change );
327340#endif
328- }
329-
330- int main (void )
331- {
332- // Initialize the device
333- sl_main_init ();
334-
335- // Initialize the GPIOs
336- gpio_init ();
337-
338- // Enable millisecond systick interrupts
339- SysTick_Config (CMU_ClockFreqGet (cmuClock_CORE ) / 1000 );
340341
341342 // Initialize persistent settings
342343 settings_init (& settings , sizeof (wp_settings_t ), SETTINGS_SIGNATURE , & DEFAULT_SETTINGS );
0 commit comments