Skip to content

Commit 470a23d

Browse files
committed
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.
1 parent a1409d1 commit 470a23d

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

atmel-samd/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "common-hal/pulseio/PWMOut.h"
6262
#include "common-hal/touchio/TouchIn.h"
6363
#include "common-hal/usb_hid/__init__.h"
64+
#include "shared-module/gamepad/__init__.h"
6465

6566
#include "autoreload.h"
6667
#include "flash_api.h"
@@ -202,6 +203,9 @@ void reset_samd21(void) {
202203
pwmout_reset();
203204
analogin_reset();
204205

206+
#ifdef CIRCUITPY_GAMEPAD_TICKS
207+
gamepad_reset();
208+
#endif
205209

206210
// TODO: move this to analogout_reset()
207211
// Wait for the DAC to sync then reset.

shared-module/gamepad/__init__.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@ void gamepad_tick(void) {
4949
gamepad_singleton->pressed |= gamepad_singleton->last & gamepad_current;
5050
gamepad_singleton->last = gamepad_current;
5151
}
52+
53+
void gamepad_reset(void) {
54+
gamepad_singleton = NULL;
55+
}

shared-module/gamepad/__init__.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
#define MICROPY_INCLUDED_GAMEPAD_H
2929

3030
void gamepad_tick(void);
31+
void gamepad_reset(void);
3132

3233
#endif // MICROPY_INCLUDED_GAMEPAD_H

0 commit comments

Comments
 (0)