Merge pull request #5068 from dhalbert/remove-gamepad
remove gamepad; deprecate gamepadshift
This commit is contained in:
commit
fc59a7ac02
@ -80,7 +80,7 @@ as a natural "TODO" list. An example minimal build list is shown below:
|
||||
# Requires DigitalIO:
|
||||
CIRCUITPY_BITBANGIO = 0
|
||||
# Requires DigitalIO
|
||||
CIRCUITPY_GAMEPAD = 0
|
||||
CIRCUITPY_GAMEPADSHIFT = 0
|
||||
# Requires neopixel_write or SPI (dotstar)
|
||||
CIRCUITPY_PIXELBUF = 0
|
||||
# Requires OS
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 68b7e580fe7d162d686f92301ab3937907dcaafe
|
||||
Subproject commit e0fecb6c73f11c31cfc2a9c0e9ce9805b8fb1cf1
|
@ -1 +1 @@
|
||||
Subproject commit c55425e17842cce3ec0b34489133436c3e1a3898
|
||||
Subproject commit 03f54421a050bbfda71e1c98986ddecc3862431a
|
@ -12,8 +12,8 @@ EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ"
|
||||
LONGINT_IMPL = NONE
|
||||
CIRCUITPY_FULL_BUILD = 0
|
||||
|
||||
CIRCUITPY_GAMEPAD = 1
|
||||
CIRCUITPY_BUSDEVICE = 1
|
||||
CIRCUITPY_KEYPAD = 1
|
||||
|
||||
# Include these Python libraries in firmware.
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID
|
||||
|
@ -12,6 +12,7 @@ LONGINT_IMPL = NONE
|
||||
|
||||
# To keep the build small
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
CIRCUITPY_KEYPAD = 0
|
||||
|
||||
# Include these Python libraries in firmware.
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH
|
||||
|
@ -10,37 +10,36 @@ INTERNAL_FLASH_FILESYSTEM = 1
|
||||
LONGINT_IMPL = NONE
|
||||
|
||||
CIRCUITPY_FULL_BUILD = 0
|
||||
|
||||
CIRCUIPTY_USB_CDC = 0
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
CIRCUITPY_AUDIOPWMIO = 0
|
||||
CIRCUITPY_AUDIOMP3 = 0
|
||||
CIRCUITPY_AUDIOPWMIO = 0
|
||||
CIRCUITPY_BITBANGIO = 0
|
||||
CIRCUITPY_BITBANG_APA102 = 0
|
||||
CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_GAMEPADSHIFT = 0
|
||||
CIRCUITPY_I2CPERIPHERAL = 0
|
||||
CIRCUITPY_NEOPIXEL_WRITE = 0
|
||||
CIRCUITPY_PIXELBUF = 0
|
||||
CIRCUITPY_PS2IO = 0
|
||||
CIRCUITPY_PULSEIO = 0
|
||||
CIRCUITPY_PWMIO = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
CIRCUITPY_RTC = 0
|
||||
CIRCUITPY_SAMD = 0
|
||||
CIRCUITPY_TOUCHIO = 0
|
||||
CIRCUIPTY_USB_CDC = 0
|
||||
CIRCUITPY_USB_HID = 0
|
||||
CIRCUITPY_USB_MIDI = 0
|
||||
CIRCUITPY_VECTORIO = 0
|
||||
CIRCUITPY_GAMEPAD = 0
|
||||
CIRCUITPY_PWMIO = 0
|
||||
|
||||
CIRCUITPY_ANALOGIO = 1
|
||||
CIRCUITPY_AUDIOMIXER = 1
|
||||
CIRCUITPY_AUDIOIO = 1
|
||||
CIRCUITPY_SYNTHIO = 1
|
||||
CIRCUITPY_AUDIOMIXER = 1
|
||||
CIRCUITPY_DISPLAYIO = 1
|
||||
CIRCUITPY_KEYPAD = 1
|
||||
CIRCUITPY_MATH = 1
|
||||
CIRCUITPY_STAGE = 1
|
||||
CIRCUITPY_KEYPAD = 1
|
||||
CIRCUITPY_SYNTHIO = 1
|
||||
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pewpew_m4
|
||||
CIRCUITPY_DISPLAY_FONT = $(TOP)/ports/atmel-samd/boards/ugame10/brutalist-6.bdf
|
||||
|
@ -10,7 +10,6 @@ QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICES = GD25Q16C
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CIRCUITPY_GAMEPAD = 1
|
||||
CIRCUITPY_GAMEPADSHIFT = 1
|
||||
CIRCUITPY_STAGE = 1
|
||||
|
||||
|
@ -16,8 +16,8 @@ CIRCUITPY_DRIVE_LABEL = "PYCUBED"
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
CIRCUITPY_BITMAPTOOLS = 0
|
||||
CIRCUITPY_DISPLAYIO = 0
|
||||
CIRCUITPY_KEYPAD = 0
|
||||
CIRCUITPY_FRAMEBUFFERIO = 0
|
||||
CIRCUITPY_KEYPAD = 0
|
||||
CIRCUITPY_RGBMATRIX = 0
|
||||
CIRCUITPY_PS2IO = 0
|
||||
|
||||
|
@ -10,7 +10,6 @@ QSPI_FLASH_FILESYSTEM = 1
|
||||
EXTERNAL_FLASH_DEVICES = GD25Q64C
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CIRCUITPY_GAMEPAD = 1
|
||||
CIRCUITPY_GAMEPADSHIFT = 1
|
||||
CIRCUITPY_STAGE = 1
|
||||
|
||||
|
@ -14,8 +14,8 @@ CIRCUITPY_STAGE = 1
|
||||
CIRCUITPY_MATH = 1
|
||||
CIRCUITPY_AUDIOIO = 1
|
||||
CIRCUITPY_ANALOGIO = 1
|
||||
CIRCUITPY_GAMEPAD = 1
|
||||
CIRCUITPY_DISPLAYIO = 1
|
||||
CIRCUITPY_KEYPPAD = 1
|
||||
|
||||
CIRCUITPY_PULSEIO = 0
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
|
@ -22,6 +22,7 @@ CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_AUDIOBUSIO = 0
|
||||
CIRCUITPY_BLEIO = 0
|
||||
CIRCUITPY_DISPLAYIO = 0
|
||||
CIRCUITPY_KEYPAD = 0
|
||||
CIRCUITPY_I2CPERIPHERAL = 0
|
||||
CIRCUITPY_TOUCHIO = 0
|
||||
CIRCUITPY_RGBMATRIX = 0
|
||||
|
@ -21,6 +21,7 @@ CIRCUITPY_BITMAPTOOLS = 0
|
||||
CIRCUITPY_BLEIO_HCI = 0
|
||||
CIRCUITPY_DISPLAYIO = 0
|
||||
CIRCUITPY_FRAMEBUFFERIO = 0
|
||||
CIRCUITPY_KEYPAD = 0
|
||||
CIRCUITPY_I2CPERIPHERAL = 0
|
||||
CIRCUITPY_TOUCHIO = 0
|
||||
CIRCUITPY_RGBMATRIX = 0
|
||||
|
@ -85,9 +85,6 @@
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
#include "shared-module/gamepad/__init__.h"
|
||||
#endif
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
#include "shared-module/gamepadshift/__init__.h"
|
||||
#endif
|
||||
@ -358,9 +355,6 @@ void reset_port(void) {
|
||||
|
||||
reset_gclks();
|
||||
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
gamepad_reset();
|
||||
#endif
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
gamepadshift_reset();
|
||||
#endif
|
||||
|
@ -17,9 +17,9 @@ CIRCUITPY_CAMERA = 1
|
||||
CIRCUITPY_COUNTIO = 0
|
||||
CIRCUITPY_DISPLAYIO = 0
|
||||
CIRCUITPY_FREQUENCYIO = 0
|
||||
CIRCUITPY_GAMEPAD = 0
|
||||
CIRCUITPY_GNSS = 1
|
||||
CIRCUITPY_I2CPERIPHERAL = 0
|
||||
CIRCUITPY_KEYPAD = 0
|
||||
CIRCUITPY_NEOPIXEL_WRITE = 0
|
||||
CIRCUITPY_NVM = 0
|
||||
CIRCUITPY_ROTARYIO = 0
|
||||
|
@ -47,9 +47,6 @@
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
#include "shared-module/gamepad/__init__.h"
|
||||
#endif
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
#include "shared-module/gamepadshift/__init__.h"
|
||||
#endif
|
||||
@ -300,9 +297,6 @@ void reset_port(void) {
|
||||
rtc_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
gamepad_reset();
|
||||
#endif
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
gamepadshift_reset();
|
||||
#endif
|
||||
|
@ -8,5 +8,4 @@ MCU_CHIP = nrf52840
|
||||
INTERNAL_FLASH_FILESYSTEM = 1
|
||||
CIRCUITPY_AUDIOIO = 0
|
||||
CIRCUITPY_DISPLAYIO = 1
|
||||
CIRCUITPY_GAMEPAD = 1
|
||||
CIRCUITPY_STAGE = 1
|
||||
|
@ -1,26 +0,0 @@
|
||||
import board
|
||||
import digitalio
|
||||
import gamepad
|
||||
import time
|
||||
|
||||
pad = gamepad.GamePad(
|
||||
digitalio.DigitalInOut(board.P0_11),
|
||||
digitalio.DigitalInOut(board.P0_12),
|
||||
digitalio.DigitalInOut(board.P0_24),
|
||||
digitalio.DigitalInOut(board.P0_25),
|
||||
)
|
||||
|
||||
prev_buttons = 0
|
||||
|
||||
while True:
|
||||
buttons = pad.get_pressed()
|
||||
|
||||
if buttons != prev_buttons:
|
||||
for i in range(0, 4):
|
||||
bit = 1 << i
|
||||
if (buttons & bit) != (prev_buttons & bit):
|
||||
print("Button %d %s" % (i + 1, "pressed" if buttons & bit else "released"))
|
||||
|
||||
prev_buttons = buttons
|
||||
|
||||
time.sleep(0.1)
|
@ -39,7 +39,6 @@
|
||||
#include "nrf/power.h"
|
||||
#include "nrf/timers.h"
|
||||
|
||||
#include "shared-module/gamepad/__init__.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "common-hal/_bleio/__init__.h"
|
||||
#include "common-hal/analogio/AnalogIn.h"
|
||||
@ -207,10 +206,6 @@ safe_mode_t port_init(void) {
|
||||
}
|
||||
|
||||
void reset_port(void) {
|
||||
#ifdef CIRCUITPY_GAMEPAD_TICKS
|
||||
gamepad_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_BUSIO
|
||||
i2c_reset();
|
||||
spi_reset();
|
||||
|
@ -184,9 +184,7 @@ endif
|
||||
ifeq ($(CIRCUITPY_FREQUENCYIO),1)
|
||||
SRC_PATTERNS += frequencyio/%
|
||||
endif
|
||||
ifeq ($(CIRCUITPY_GAMEPAD),1)
|
||||
SRC_PATTERNS += gamepad/%
|
||||
endif
|
||||
|
||||
ifeq ($(CIRCUITPY_GAMEPADSHIFT),1)
|
||||
SRC_PATTERNS += gamepadshift/%
|
||||
endif
|
||||
@ -523,8 +521,6 @@ SRC_SHARED_MODULE_ALL = \
|
||||
keypad/Keys.c \
|
||||
sdcardio/SDCard.c \
|
||||
sdcardio/__init__.c \
|
||||
gamepad/GamePad.c \
|
||||
gamepad/__init__.c \
|
||||
gamepadshift/GamePadShift.c \
|
||||
gamepadshift/__init__.c \
|
||||
memorymonitor/__init__.c \
|
||||
|
@ -468,13 +468,6 @@ extern const struct _mp_obj_module_t frequencyio_module;
|
||||
#define FREQUENCYIO_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
extern const struct _mp_obj_module_t gamepad_module;
|
||||
#define GAMEPAD_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module },
|
||||
#else
|
||||
#define GAMEPAD_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
extern const struct _mp_obj_module_t gamepadshift_module;
|
||||
#define GAMEPADSHIFT_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_gamepadshift),(mp_obj_t)&gamepadshift_module },
|
||||
@ -482,7 +475,7 @@ extern const struct _mp_obj_module_t gamepadshift_module;
|
||||
#define GAMEPADSHIFT_MODULE
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPAD || CIRCUITPY_GAMEPADSHIFT
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
// Scan gamepad every 32ms
|
||||
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
|
||||
#define GAMEPAD_ROOT_POINTERS mp_obj_t gamepad_singleton;
|
||||
@ -539,8 +532,8 @@ extern const struct _mp_obj_module_t keypad_module;
|
||||
#define KEYPAD_ROOT_POINTERS
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPAD || CIRCUITPY_GAMEPADSHIFT
|
||||
// Scan gamepad every 32ms
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
// Scan gamepadshift every 32ms
|
||||
#define CIRCUITPY_GAMEPAD_TICKS 0x1f
|
||||
#define GAMEPAD_ROOT_POINTERS mp_obj_t gamepad_singleton;
|
||||
#else
|
||||
@ -888,7 +881,6 @@ extern const struct _mp_obj_module_t msgpack_module;
|
||||
_EVE_MODULE \
|
||||
FRAMEBUFFERIO_MODULE \
|
||||
FREQUENCYIO_MODULE \
|
||||
GAMEPAD_MODULE \
|
||||
GAMEPADSHIFT_MODULE \
|
||||
GNSS_MODULE \
|
||||
I2CPERIPHERAL_MODULE \
|
||||
|
@ -181,9 +181,6 @@ CFLAGS += -DCIRCUITPY__EVE=$(CIRCUITPY__EVE)
|
||||
CIRCUITPY_FREQUENCYIO ?= $(CIRCUITPY_FULL_BUILD)
|
||||
CFLAGS += -DCIRCUITPY_FREQUENCYIO=$(CIRCUITPY_FREQUENCYIO)
|
||||
|
||||
CIRCUITPY_GAMEPAD ?= 0
|
||||
CFLAGS += -DCIRCUITPY_GAMEPAD=$(CIRCUITPY_GAMEPAD)
|
||||
|
||||
CIRCUITPY_GAMEPADSHIFT ?= 0
|
||||
CFLAGS += -DCIRCUITPY_GAMEPADSHIFT=$(CIRCUITPY_GAMEPADSHIFT)
|
||||
|
||||
|
@ -1,166 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include "shared-bindings/gamepad/GamePad.h"
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "py/gc.h"
|
||||
#include "py/mpstate.h"
|
||||
#include "shared-bindings/gamepad/__init__.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
//| class GamePad:
|
||||
//| """Scan buttons for presses
|
||||
//|
|
||||
//| Usage::
|
||||
//|
|
||||
//| import board
|
||||
//| import digitalio
|
||||
//| import gamepad
|
||||
//| import time
|
||||
//|
|
||||
//| B_UP = 1 << 0
|
||||
//| B_DOWN = 1 << 1
|
||||
//|
|
||||
//|
|
||||
//| pad = gamepad.GamePad(
|
||||
//| digitalio.DigitalInOut(board.D10),
|
||||
//| digitalio.DigitalInOut(board.D11),
|
||||
//| )
|
||||
//|
|
||||
//| y = 0
|
||||
//| while True:
|
||||
//| buttons = pad.get_pressed()
|
||||
//| if buttons & B_UP:
|
||||
//| y -= 1
|
||||
//| print(y)
|
||||
//| elif buttons & B_DOWN:
|
||||
//| y += 1
|
||||
//| print(y)
|
||||
//| time.sleep(0.1)
|
||||
//| while buttons:
|
||||
//| # Wait for all buttons to be released.
|
||||
//| buttons = pad.get_pressed()
|
||||
//| time.sleep(0.1)"""
|
||||
//|
|
||||
//| def __init__(
|
||||
//| self,
|
||||
//| b1: digitalio.DigitalInOut,
|
||||
//| b2: digitalio.DigitalInOut,
|
||||
//| b3: digitalio.DigitalInOut,
|
||||
//| b4: digitalio.DigitalInOut,
|
||||
//| b5: digitalio.DigitalInOut,
|
||||
//| b6: digitalio.DigitalInOut,
|
||||
//| b7: digitalio.DigitalInOut,
|
||||
//| b8: digitalio.DigitalInOut,
|
||||
//| ) -> None:
|
||||
//| """Initializes button scanning routines.
|
||||
//|
|
||||
//| The ``b1``-``b8`` parameters are ``DigitalInOut`` objects, which
|
||||
//| immediately get switched to input with a pull-up, (unless they already
|
||||
//| were set to pull-down, in which case they remain so), and then scanned
|
||||
//| regularly for button presses. The order is the same as the order of
|
||||
//| bits returned by the ``get_pressed`` function. You can re-initialize
|
||||
//| it with different keys, then the new object will replace the previous
|
||||
//| one.
|
||||
//|
|
||||
//| The basic feature required here is the ability to poll the keys at
|
||||
//| regular intervals (so that de-bouncing is consistent) and fast enough
|
||||
//| (so that we don't miss short button presses) while at the same time
|
||||
//| letting the user code run normally, call blocking functions and wait
|
||||
//| on delays.
|
||||
//|
|
||||
//| They button presses are accumulated, until the ``get_pressed`` method
|
||||
//| is called, at which point the button state is cleared, and the new
|
||||
//| button presses start to be recorded."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
const mp_obj_t *args, mp_map_t *kw_args) {
|
||||
if (n_args > 8 || n_args == 0) {
|
||||
mp_raise_TypeError(translate("argument num/types mismatch"));
|
||||
}
|
||||
for (size_t i = 0; i < n_args; ++i) {
|
||||
assert_digitalinout(args[i]);
|
||||
}
|
||||
gamepad_obj_t *gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
if (!gamepad_singleton ||
|
||||
!mp_obj_is_type(MP_OBJ_FROM_PTR(gamepad_singleton), &gamepad_type)) {
|
||||
gamepad_singleton = m_new_ll_obj(gamepad_obj_t);
|
||||
gamepad_singleton->base.type = &gamepad_type;
|
||||
if (!MP_STATE_VM(gamepad_singleton)) {
|
||||
supervisor_enable_tick();
|
||||
}
|
||||
MP_STATE_VM(gamepad_singleton) = gamepad_singleton;
|
||||
}
|
||||
common_hal_gamepad_gamepad_init(gamepad_singleton, args, n_args);
|
||||
return MP_OBJ_FROM_PTR(gamepad_singleton);
|
||||
}
|
||||
|
||||
//| def get_pressed(self) -> int:
|
||||
//| """Get the status of buttons pressed since the last call and clear it.
|
||||
//|
|
||||
//| Returns an 8-bit number, with bits that correspond to buttons,
|
||||
//| which have been pressed (or held down) since the last call to this
|
||||
//| function set to 1, and the remaining bits set to 0. Then it clears
|
||||
//| the button state, so that new button presses (or buttons that are
|
||||
//| held down) can be recorded for the next call."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepad_get_pressed(mp_obj_t self_in) {
|
||||
gamepad_obj_t *gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed);
|
||||
gamepad_singleton->pressed = gamepad_singleton->last;
|
||||
return pressed;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gamepad_get_pressed_obj, gamepad_get_pressed);
|
||||
|
||||
|
||||
//| def deinit(self) -> None:
|
||||
//| """Disable button scanning."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepad_deinit(mp_obj_t self_in) {
|
||||
common_hal_gamepad_gamepad_deinit(self_in);
|
||||
return mp_const_none;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gamepad_deinit_obj, gamepad_deinit);
|
||||
|
||||
|
||||
STATIC const mp_rom_map_elem_t gamepad_locals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&gamepad_get_pressed_obj)},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gamepad_deinit_obj)},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(gamepad_locals_dict, gamepad_locals_dict_table);
|
||||
const mp_obj_type_t gamepad_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_GamePad,
|
||||
.make_new = gamepad_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&gamepad_locals_dict,
|
||||
};
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H
|
||||
|
||||
#include "shared-module/gamepad/GamePad.h"
|
||||
|
||||
extern const mp_obj_type_t gamepad_type;
|
||||
|
||||
void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad, const mp_obj_t pins[], size_t n_pins);
|
||||
void common_hal_gamepad_gamepad_deinit(gamepad_obj_t *gamepad);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD_GAMEPAD_H
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "shared-bindings/gamepad/GamePad.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| """Button handling in the background"""
|
||||
//|
|
||||
STATIC const mp_rom_map_elem_t gamepad_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepad) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_GamePad), MP_ROM_PTR(&gamepad_type)},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(gamepad_module_globals,
|
||||
gamepad_module_globals_table);
|
||||
|
||||
const mp_obj_module_t gamepad_module = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t *)&gamepad_module_globals,
|
||||
};
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H
|
||||
#define MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GAMEPAD___INIT___H
|
@ -46,8 +46,7 @@
|
||||
//| is called, at which point the button state is cleared, and the new
|
||||
//| button presses start to be recorded.
|
||||
//|
|
||||
//| Only one gamepad (`gamepad.GamePad` or `gamepadshift.GamePadShift`)
|
||||
//| may be used at a time."""
|
||||
//| Only one `gamepadshift.GamePadShift` may be used at a time."""
|
||||
//| ...
|
||||
//|
|
||||
STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
|
@ -30,7 +30,11 @@
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
//| """Tracks button presses read through a shift register"""
|
||||
//| """Tracks button presses read through a shift register.
|
||||
//|
|
||||
//| .. note:: `gamepadshift` is deprecated in CircuitPython 7.0.0 and will be removed in 8.0.0.
|
||||
//| Use `keypad` instead.
|
||||
//| """
|
||||
//|
|
||||
STATIC const mp_rom_map_elem_t gamepadshift_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gamepadshift) },
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/mpstate.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/gamepad/GamePad.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad,
|
||||
const mp_obj_t pins[], size_t n_pins) {
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
gamepad->pins[i] = NULL;
|
||||
}
|
||||
gamepad->pulls = 0;
|
||||
for (size_t i = 0; i < n_pins; ++i) {
|
||||
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(pins[i]);
|
||||
if (common_hal_digitalio_digitalinout_get_direction(pin) !=
|
||||
DIRECTION_INPUT) {
|
||||
common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP);
|
||||
}
|
||||
digitalio_pull_t pull = common_hal_digitalio_digitalinout_get_pull(pin);
|
||||
if (pull == PULL_NONE) {
|
||||
common_hal_digitalio_digitalinout_set_pull(pin, PULL_UP);
|
||||
}
|
||||
if (pull != PULL_DOWN) {
|
||||
gamepad->pulls |= 1 << i;
|
||||
}
|
||||
gamepad->pins[i] = pin;
|
||||
}
|
||||
gamepad->last = 0;
|
||||
}
|
||||
|
||||
void common_hal_gamepad_gamepad_deinit(gamepad_obj_t *self) {
|
||||
MP_STATE_VM(gamepad_singleton) = NULL;
|
||||
supervisor_disable_tick();
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H
|
||||
#define MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
digitalio_digitalinout_obj_t *pins[8];
|
||||
volatile uint8_t last;
|
||||
volatile uint8_t pressed;
|
||||
uint8_t pulls;
|
||||
} gamepad_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Radomir Dopieralski for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "py/mpstate.h"
|
||||
#include "shared-bindings/gamepad/__init__.h"
|
||||
#include "shared-bindings/gamepad/GamePad.h"
|
||||
#include "supervisor/shared/tick.h"
|
||||
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
|
||||
|
||||
void gamepad_tick(void) {
|
||||
uint8_t current = 0;
|
||||
uint8_t bit = 1;
|
||||
|
||||
void *singleton = MP_STATE_VM(gamepad_singleton);
|
||||
if (singleton == NULL || !mp_obj_is_type(MP_OBJ_FROM_PTR(singleton), &gamepad_type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
gamepad_obj_t *self = MP_OBJ_TO_PTR(singleton);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
digitalio_digitalinout_obj_t *pin = self->pins[i];
|
||||
if (!pin) {
|
||||
break;
|
||||
}
|
||||
if (common_hal_digitalio_digitalinout_get_value(pin)) {
|
||||
current |= bit;
|
||||
}
|
||||
bit <<= 1;
|
||||
}
|
||||
current ^= self->pulls;
|
||||
self->pressed |= self->last & current;
|
||||
self->last = current;
|
||||
}
|
||||
|
||||
void gamepad_reset(void) {
|
||||
if (MP_STATE_VM(gamepad_singleton)) {
|
||||
supervisor_disable_tick();
|
||||
}
|
||||
MP_STATE_VM(gamepad_singleton) = NULL;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2016 Scott Shawcroft for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_GAMEPAD_H
|
||||
#define MICROPY_INCLUDED_GAMEPAD_H
|
||||
|
||||
void gamepad_tick(void);
|
||||
void gamepad_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_GAMEPAD_H
|
@ -40,10 +40,6 @@
|
||||
#include "shared-module/displayio/__init__.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
#include "shared-module/gamepad/__init__.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
#include "shared-module/gamepadshift/__init__.h"
|
||||
#endif
|
||||
@ -102,9 +98,6 @@ void supervisor_tick(void) {
|
||||
|
||||
#ifdef CIRCUITPY_GAMEPAD_TICKS
|
||||
if (!(port_get_raw_ticks(NULL) & CIRCUITPY_GAMEPAD_TICKS)) {
|
||||
#if CIRCUITPY_GAMEPAD
|
||||
gamepad_tick();
|
||||
#endif
|
||||
#if CIRCUITPY_GAMEPADSHIFT
|
||||
gamepadshift_tick();
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user