Skip to content

Commit 1c97b7f

Browse files
deshiputannewt
authored andcommitted
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 470a23d) Conflicts: atmel-samd/main.c
1 parent a1be272 commit 1c97b7f

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

atmel-samd/supervisor/port.c

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ void reset_port(void) {
193193
//
194194
// analogin_reset();
195195
//
196+
// #ifdef CIRCUITPY_GAMEPAD_TICKS
197+
// gamepad_reset();
198+
// #endif
196199
//
197200
// // Wait for the DAC to sync then reset.
198201
// while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {}

shared-module/gamepad/__init__.c

+4
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

+1
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)