summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorRadomir Dopieralski <openstack@sheep.art.pl>2017-10-22 00:50:58 +0200
committerScott Shawcroft <scott@tannewt.org>2017-10-22 20:54:10 -0700
commit1c97b7f4df63e5fcac655b2749e861eeba4ef79f (patch)
tree8db7386d64c43d0ee5c4fe5349c3f225a8247f95 /shared-module
parenta1be272b1e30d90fedb2d13051374d774e84d248 (diff)
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
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