diff options
| author | Radomir Dopieralski <deshipu@users.noreply.github.com> | 2017-10-03 22:35:57 +0200 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2017-10-03 13:35:57 -0700 |
| commit | f4981677b0b73d286f3af098a4111f8ba6d286bc (patch) | |
| tree | 05463c1df056798b08accba1d9effff5ea397e05 /atmel-samd | |
| parent | c478c10923b9085b2abe135470e968029aaf2fdb (diff) | |
Add a `gamepad` module for handling buttons in the background. (#295)
The `GamePad` singleton monitors buttons in the background to make sure a button press is never missed and debouncing happens consistently.
Diffstat (limited to 'atmel-samd')
| -rw-r--r-- | atmel-samd/Makefile | 2 | ||||
| -rw-r--r-- | atmel-samd/mpconfigport.h | 4 | ||||
| -rw-r--r-- | atmel-samd/tick.c | 6 |
3 files changed, 12 insertions, 0 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile index daf21568a..3bbe91ea9 100644 --- a/atmel-samd/Makefile +++ b/atmel-samd/Makefile @@ -289,6 +289,8 @@ SRC_SHARED_MODULE = \ bitbangio/OneWire.c \ bitbangio/SPI.c \ busio/OneWire.c \ + gamepad/__init__.c \ + gamepad/GamePad.c \ os/__init__.c \ random/__init__.c \ storage/__init__.c \ diff --git a/atmel-samd/mpconfigport.h b/atmel-samd/mpconfigport.h index e99d190be..fc061d1cb 100644 --- a/atmel-samd/mpconfigport.h +++ b/atmel-samd/mpconfigport.h @@ -152,6 +152,7 @@ extern const struct _mp_obj_module_t neopixel_write_module; extern const struct _mp_obj_module_t uheap_module; extern const struct _mp_obj_module_t ustack_module; extern const struct _mp_obj_module_t samd_module; +extern const struct _mp_obj_module_t gamepad_module; extern const struct _mp_obj_module_t touchio_module; extern const struct _mp_obj_module_t usb_hid_module; @@ -171,10 +172,13 @@ extern const struct _mp_obj_module_t usb_hid_module; #define MICROPY_PY_ARRAY_SLICE_ASSIGN (1) #define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_CPYTHON_COMPAT (1) + // Scan gamepad every 32ms + #define CIRCUITPY_GAMEPAD_TICKS 0x1f #define EXTRA_BUILTIN_MODULES \ { MP_OBJ_NEW_QSTR(MP_QSTR_audioio), (mp_obj_t)&audioio_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_audiobusio), (mp_obj_t)&audiobusio_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_nvm), (mp_obj_t)&cpy_nvm_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_bitbangio), (mp_obj_t)&bitbangio_module } diff --git a/atmel-samd/tick.c b/atmel-samd/tick.c index cbe72abc6..e97da0730 100644 --- a/atmel-samd/tick.c +++ b/atmel-samd/tick.c @@ -1,4 +1,5 @@ #include "autoreload.h" +#include "shared-module/gamepad/__init__.h" #include "tick.h" @@ -17,6 +18,11 @@ static void ms_tick(struct tc_module *const module_inst) { #ifdef CIRCUITPY_AUTORELOAD_DELAY_MS autoreload_tick(); #endif + #ifdef CIRCUITPY_GAMEPAD_TICKS + if (!(ticks_ms & CIRCUITPY_GAMEPAD_TICKS)) { + gamepad_tick(); + } + #endif } void tick_init() { |
