summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorRadomir Dopieralski <deshipu@users.noreply.github.com>2017-10-22 04:39:20 +0200
committerDan Halbert <halbert@halwitz.org>2017-10-21 22:39:20 -0400
commit9bcc1057ca3796e8ba8aa9805cf9d140ee7f51d3 (patch)
tree8f715415852bcb8a7941bee4f7c4905d4e01e36c /shared-module
parenta1409d1432ea4280293749b3a2bb5c2278fda609 (diff)
Gracefully reset the gamepad module (#356)
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.
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/gamepad/__init__.c4
-rw-r--r--shared-module/gamepad/__init__.h1
2 files changed, 5 insertions, 0 deletions
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