From 1c97b7f4df63e5fcac655b2749e861eeba4ef79f Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sun, 22 Oct 2017 00:50:58 +0200 Subject: Gracefully reset the gamepad module If a soft reset happens while the gamepad module is scanning for button presses, there is a moment when the pins get de-initialized, but the gamepad module is still trying to read them, which ends in a crash. We can avoid it by disabling scanning on reset. (cherry picked from commit 470a23d4c9345785bbaa830fdc036b4e982496c6) Conflicts: atmel-samd/main.c --- atmel-samd/supervisor/port.c | 3 +++ shared-module/gamepad/__init__.c | 4 ++++ shared-module/gamepad/__init__.h | 1 + 3 files changed, 8 insertions(+) diff --git a/atmel-samd/supervisor/port.c b/atmel-samd/supervisor/port.c index 74c79ce3f..b91171992 100644 --- a/atmel-samd/supervisor/port.c +++ b/atmel-samd/supervisor/port.c @@ -193,6 +193,9 @@ void reset_port(void) { // // analogin_reset(); // +// #ifdef CIRCUITPY_GAMEPAD_TICKS +// gamepad_reset(); +// #endif // // // Wait for the DAC to sync then reset. // while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {} diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index 1aebf611d..b6c8be215 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -49,3 +49,7 @@ void gamepad_tick(void) { gamepad_singleton->pressed |= gamepad_singleton->last & gamepad_current; gamepad_singleton->last = gamepad_current; } + +void gamepad_reset(void) { + gamepad_singleton = NULL; +} diff --git a/shared-module/gamepad/__init__.h b/shared-module/gamepad/__init__.h index eacd72366..1fae570f9 100644 --- a/shared-module/gamepad/__init__.h +++ b/shared-module/gamepad/__init__.h @@ -28,5 +28,6 @@ #define MICROPY_INCLUDED_GAMEPAD_H void gamepad_tick(void); +void gamepad_reset(void); #endif // MICROPY_INCLUDED_GAMEPAD_H -- cgit v1.2.3