summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2018-05-30 17:19:12 -0700
committerGitHub <noreply@github.com>2018-05-30 17:19:12 -0700
commit6479cb08060d7fb29b9189430a1ee8d105d37b26 (patch)
tree20dc818be4afe97898b44ac0be338373d2c24f48 /shared-module
parent09504159b836b961f5be0f3ad88a083c0a3d84e2 (diff)
parentd02899f822c57979047c6a3fdea4e20b5f60e016 (diff)
Merge pull request #868 from pewpew-game/gamepad-longlive
Make the gamepad singleton long-living and add it to root pointers
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/gamepad/GamePad.c2
-rw-r--r--shared-module/gamepad/GamePad.h2
-rw-r--r--shared-module/gamepad/__init__.c4
3 files changed, 5 insertions, 3 deletions
diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c
index 88ab23fc1..2c14fa02a 100644
--- a/shared-module/gamepad/GamePad.c
+++ b/shared-module/gamepad/GamePad.c
@@ -26,6 +26,7 @@
#include <stdbool.h>
+#include "py/mpstate.h"
#include "__init__.h"
#include "GamePad.h"
@@ -35,6 +36,7 @@
void gamepad_init(size_t n_pins, const mp_obj_t* pins) {
+ gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
for (size_t i = 0; i < 8; ++i) {
gamepad_singleton->pins[i] = NULL;
}
diff --git a/shared-module/gamepad/GamePad.h b/shared-module/gamepad/GamePad.h
index 7ce55cf98..9fd5c9626 100644
--- a/shared-module/gamepad/GamePad.h
+++ b/shared-module/gamepad/GamePad.h
@@ -39,8 +39,6 @@ typedef struct {
uint8_t pulls;
} gamepad_obj_t;
-extern gamepad_obj_t* gamepad_singleton;
-
void gamepad_init(size_t n_pins, const mp_obj_t* pins);
#endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H
diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c
index b1cdac2a7..8414ddfbe 100644
--- a/shared-module/gamepad/__init__.c
+++ b/shared-module/gamepad/__init__.c
@@ -26,6 +26,7 @@
#include <stdbool.h>
+#include "py/mpstate.h"
#include "__init__.h"
#include "GamePad.h"
@@ -33,6 +34,7 @@
void gamepad_tick(void) {
+ gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
if (!gamepad_singleton) {
return;
}
@@ -54,5 +56,5 @@ void gamepad_tick(void) {
}
void gamepad_reset(void) {
- gamepad_singleton = NULL;
+ MP_STATE_VM(gamepad_singleton) = NULL;
}