More refactoring
This commit is contained in:
parent
7e89beeb31
commit
ae60968563
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -1741,10 +1741,6 @@ msgstr ""
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr ""
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr ""
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -1697,10 +1697,6 @@ msgstr ""
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr ""
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr ""
|
||||
|
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
|
||||
"Last-Translator: Pascal Deneaux\n"
|
||||
"Language-Team: Sebastian Plamauer, Pascal Deneaux\n"
|
||||
|
@ -1737,10 +1737,6 @@ msgstr "Exceptions müssen von BaseException abgeleitet sein"
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr "erwarte ':' nach format specifier"
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr "erwarte DigitalInOut"
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr "erwarte tuple/list"
|
||||
|
@ -2742,6 +2738,9 @@ msgstr ""
|
|||
#~ msgid "buffer too long"
|
||||
#~ msgstr "Buffer zu lang"
|
||||
|
||||
#~ msgid "expected a DigitalInOut"
|
||||
#~ msgstr "erwarte DigitalInOut"
|
||||
|
||||
#~ msgid "expecting a pin"
|
||||
#~ msgstr "Ein Pin wird erwartet"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
@ -1697,10 +1697,6 @@ msgstr ""
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr ""
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr ""
|
||||
|
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: @sommersoft, @MrCertainly\n"
|
||||
|
@ -1701,10 +1701,6 @@ msgstr ""
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr ""
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr ""
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
@ -1769,10 +1769,6 @@ msgstr "las excepciones deben derivar de BaseException"
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr "se espera ':' despues de un especificaro de tipo format"
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr "se espera un DigitalInOut"
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr "tupla/lista esperada"
|
||||
|
@ -2789,6 +2785,9 @@ msgstr "paso cero"
|
|||
#~ msgid "either pos or kw args are allowed"
|
||||
#~ msgstr "ya sea pos o kw args son permitidos"
|
||||
|
||||
#~ msgid "expected a DigitalInOut"
|
||||
#~ msgstr "se espera un DigitalInOut"
|
||||
|
||||
#~ msgid "expecting a pin"
|
||||
#~ msgstr "esperando un pin"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-12-20 22:15-0800\n"
|
||||
"Last-Translator: Timothy <me@timothygarcia.ca>\n"
|
||||
"Language-Team: fil\n"
|
||||
|
@ -1772,10 +1772,6 @@ msgstr "ang mga exceptions ay dapat makuha mula sa BaseException"
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr "umaasa ng ':' pagkatapos ng format specifier"
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr "umasa ng DigitalInOut"
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr "umaasa ng tuple/list"
|
||||
|
@ -2795,6 +2791,9 @@ msgstr "zero step"
|
|||
#~ msgid "either pos or kw args are allowed"
|
||||
#~ msgstr "pos o kw args ang pinahihintulutan"
|
||||
|
||||
#~ msgid "expected a DigitalInOut"
|
||||
#~ msgstr "umasa ng DigitalInOut"
|
||||
|
||||
#~ msgid "expecting a pin"
|
||||
#~ msgstr "umaasa ng isang pin"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: 0.1\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-12-23 20:05+0100\n"
|
||||
"Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n"
|
||||
"Language-Team: fr\n"
|
||||
|
@ -1789,10 +1789,6 @@ msgstr "les exceptions doivent dériver de BaseException"
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr "':' attendu après la spécification de format"
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr "objet DigitalInOut attendu"
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr "un tuple ou une liste est attendu"
|
||||
|
@ -2811,6 +2807,9 @@ msgstr "'step' nul"
|
|||
#~ msgid "either pos or kw args are allowed"
|
||||
#~ msgstr "soit 'pos', soit 'kw' est permis en argument"
|
||||
|
||||
#~ msgid "expected a DigitalInOut"
|
||||
#~ msgstr "objet DigitalInOut attendu"
|
||||
|
||||
#~ msgid "expecting a pin"
|
||||
#~ msgstr "une broche (Pin) est attendue"
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
|
||||
"Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n"
|
||||
"Language-Team: \n"
|
||||
|
@ -1764,10 +1764,6 @@ msgstr "le eccezioni devono derivare da BaseException"
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr "':' atteso dopo lo specificatore di formato"
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr "DigitalInOut atteso"
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr "lista/tupla prevista"
|
||||
|
@ -2787,6 +2783,9 @@ msgstr "zero step"
|
|||
#~ msgid "either pos or kw args are allowed"
|
||||
#~ msgstr "sono permesse solo gli argomenti pos o kw"
|
||||
|
||||
#~ msgid "expected a DigitalInOut"
|
||||
#~ msgstr "DigitalInOut atteso"
|
||||
|
||||
#~ msgid "expecting a pin"
|
||||
#~ msgstr "pin atteso"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2019-03-19 18:37-0700\n"
|
||||
"Last-Translator: Radomir Dopieralski <circuitpython@sheep.art.pl>\n"
|
||||
"Language-Team: pl\n"
|
||||
|
@ -1728,10 +1728,6 @@ msgstr "wyjątki muszą dziedziczyć po BaseException"
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr "oczekiwano ':' po specyfikacji formatu"
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr "oczekiwano DigitalInOut"
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr "oczekiwano krotki/listy"
|
||||
|
@ -2613,6 +2609,9 @@ msgstr "zerowy krok"
|
|||
#~ msgid "RTC set is not supported on this board"
|
||||
#~ msgstr "Ustawianie RTC nie jest obsługiwane na tej płytce"
|
||||
|
||||
#~ msgid "expected a DigitalInOut"
|
||||
#~ msgstr "oczekiwano DigitalInOut"
|
||||
|
||||
#~ msgid "row must be packed and word aligned"
|
||||
#~ msgstr "row musi być upakowana i wyrównana do słowa"
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2019-04-11 11:22+0200\n"
|
||||
"POT-Creation-Date: 2019-04-11 11:44+0200\n"
|
||||
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
@ -1730,10 +1730,6 @@ msgstr ""
|
|||
msgid "expected ':' after format specifier"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/gamepad/GamePad.c
|
||||
msgid "expected a DigitalInOut"
|
||||
msgstr ""
|
||||
|
||||
#: py/obj.c
|
||||
msgid "expected tuple/list"
|
||||
msgstr ""
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
STATIC digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) {
|
||||
if (!MP_OBJ_IS_TYPE(obj, &digitalio_digitalinout_type)) {
|
||||
mp_raise_TypeError(translate("expected a DigitalInOut"));
|
||||
mp_raise_TypeError(translate("argument num/types mismatch"));
|
||||
}
|
||||
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(obj);
|
||||
raise_error_if_deinited(
|
||||
|
@ -105,18 +105,37 @@ STATIC digitalio_digitalinout_obj_t *validate_pin(mp_obj_t obj) {
|
|||
//|
|
||||
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) {
|
||||
if (n_args > 8 || n_args == 0) {
|
||||
mp_raise_TypeError(translate("argument num/types mismatch"));
|
||||
}
|
||||
for (size_t i = 0; i < n_args; ++i) {
|
||||
validate_pin(args[i]);
|
||||
}
|
||||
if (!MP_STATE_VM(gamepad_singleton)) {
|
||||
gamepad_obj_t* gamepad_singleton = m_new_obj(gamepad_obj_t);
|
||||
gamepad_singleton->base.type = &gamepad_type;
|
||||
gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
if (!gamepad_singleton) {
|
||||
gamepad_singleton = m_new_obj(gamepad_obj_t);
|
||||
gamepad_singleton->base.type = &gamepadshift_type;
|
||||
MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton);
|
||||
}
|
||||
gamepad_init_pins(n_args, args);
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
gamepad_singleton->pins[i] = NULL;
|
||||
}
|
||||
gamepad_singleton->pulls = 0;
|
||||
for (size_t i = 0; i < n_args; ++i) {
|
||||
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(args[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_singleton->pulls |= 1 << i;
|
||||
}
|
||||
gamepad_singleton->pins[i] = pin;
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton));
|
||||
}
|
||||
|
||||
|
@ -149,12 +168,21 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
digitalio_digitalinout_obj_t *clock_pin = validate_pin(args[ARG_clock].u_obj);
|
||||
digitalio_digitalinout_obj_t *latch_pin = validate_pin(args[ARG_latch].u_obj);
|
||||
|
||||
if (!MP_STATE_VM(gamepad_singleton)) {
|
||||
gamepad_obj_t* gamepad_singleton = m_new_obj(gamepad_obj_t);
|
||||
gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
if (!gamepad_singleton) {
|
||||
gamepad_singleton = m_new_obj(gamepad_obj_t);
|
||||
gamepad_singleton->base.type = &gamepadshift_type;
|
||||
MP_STATE_VM(gamepad_singleton) = gc_make_long_lived(gamepad_singleton);
|
||||
}
|
||||
gamepad_init_shift(data_pin, clock_pin, latch_pin);
|
||||
gamepad_singleton->pins[0] = NULL;
|
||||
common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE);
|
||||
gamepad_singleton->pins[1] = data_pin;
|
||||
common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0,
|
||||
DRIVE_MODE_PUSH_PULL);
|
||||
gamepad_singleton->pins[2] = clock_pin;
|
||||
common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1,
|
||||
DRIVE_MODE_PUSH_PULL);
|
||||
gamepad_singleton->pins[3] = latch_pin;
|
||||
return MP_OBJ_FROM_PTR(MP_STATE_VM(gamepad_singleton));
|
||||
}
|
||||
|
||||
|
@ -171,9 +199,9 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
|
|||
//|
|
||||
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 gamepad = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed);
|
||||
mp_obj_t pressed = MP_OBJ_NEW_SMALL_INT(gamepad_singleton->pressed);
|
||||
gamepad_singleton->pressed = 0;
|
||||
return gamepad;
|
||||
return pressed;
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(gamepad_get_pressed_obj, gamepad_get_pressed);
|
||||
|
||||
|
|
|
@ -1,77 +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 "__init__.h"
|
||||
#include "GamePad.h"
|
||||
|
||||
#include "shared-bindings/digitalio/Pull.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "shared-bindings/util.h"
|
||||
|
||||
|
||||
void gamepad_init_pins(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;
|
||||
}
|
||||
gamepad_singleton->pulls = 0;
|
||||
for (size_t i = 0; i < n_pins; ++i) {
|
||||
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(pins[i]);
|
||||
digitalio_direction_t direction = common_hal_digitalio_digitalinout_get_direction(pin);
|
||||
if (direction != 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_singleton->pulls |= 1 << i;
|
||||
}
|
||||
gamepad_singleton->pins[i] = pin;
|
||||
}
|
||||
gamepad_singleton->kind = GAMEPAD_KIND_PINS;
|
||||
}
|
||||
|
||||
void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin,
|
||||
digitalio_digitalinout_obj_t *clock_pin,
|
||||
digitalio_digitalinout_obj_t *latch_pin) {
|
||||
gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
|
||||
common_hal_digitalio_digitalinout_switch_to_input(data_pin, PULL_NONE);
|
||||
gamepad_singleton->pins[0] = data_pin;
|
||||
|
||||
common_hal_digitalio_digitalinout_switch_to_output(clock_pin, 0, DRIVE_MODE_PUSH_PULL);
|
||||
gamepad_singleton->pins[1] = clock_pin;
|
||||
|
||||
common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1, DRIVE_MODE_PUSH_PULL);
|
||||
gamepad_singleton->pins[2] = latch_pin;
|
||||
|
||||
gamepad_singleton->kind = GAMEPAD_KIND_SHIFT;
|
||||
}
|
|
@ -36,15 +36,6 @@ typedef struct {
|
|||
digitalio_digitalinout_obj_t* pins[8];
|
||||
volatile uint8_t pressed;
|
||||
uint8_t pulls;
|
||||
uint8_t kind;
|
||||
} gamepad_obj_t;
|
||||
|
||||
#define GAMEPAD_KIND_PINS 0
|
||||
#define GAMEPAD_KIND_SHIFT 1
|
||||
|
||||
void gamepad_init_pins(size_t n_pins, const mp_obj_t* pins);
|
||||
void gamepad_init_shift(digitalio_digitalinout_obj_t *data_pin,
|
||||
digitalio_digitalinout_obj_t *clock_pin,
|
||||
digitalio_digitalinout_obj_t *latch_pin);
|
||||
|
||||
#endif // MICROPY_INCLUDED_GAMEPAD_GAMEPAD_H
|
||||
|
|
|
@ -37,12 +37,16 @@ void gamepad_tick(void) {
|
|||
static uint8_t last = 0;
|
||||
uint8_t current = 0;
|
||||
uint8_t bit = 1;
|
||||
digitalio_digitalinout_obj_t* data_pin;
|
||||
digitalio_digitalinout_obj_t* clock_pin;
|
||||
digitalio_digitalinout_obj_t* latch_pin;
|
||||
|
||||
gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
|
||||
if (!gamepad_singleton) {
|
||||
return;
|
||||
}
|
||||
switch (gamepad_singleton->kind) {
|
||||
case GAMEPAD_KIND_PINS:
|
||||
if (gamepad_singleton->pins[0]) {
|
||||
// buttons connected directly to pins
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
digitalio_digitalinout_obj_t* pin = gamepad_singleton->pins[i];
|
||||
if (!pin) {
|
||||
|
@ -54,12 +58,11 @@ void gamepad_tick(void) {
|
|||
bit <<= 1;
|
||||
}
|
||||
current ^= gamepad_singleton->pulls;
|
||||
break;
|
||||
case GAMEPAD_KIND_SHIFT:
|
||||
bit = 1; // we need a statement after a label
|
||||
digitalio_digitalinout_obj_t* data_pin = gamepad_singleton->pins[0];
|
||||
digitalio_digitalinout_obj_t* clock_pin = gamepad_singleton->pins[1];
|
||||
digitalio_digitalinout_obj_t* latch_pin = gamepad_singleton->pins[2];
|
||||
} else {
|
||||
// buttons connected to a shift register
|
||||
data_pin = gamepad_singleton->pins[1];
|
||||
clock_pin = gamepad_singleton->pins[2];
|
||||
latch_pin = gamepad_singleton->pins[3];
|
||||
|
||||
common_hal_digitalio_digitalinout_set_value(latch_pin, 1);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
|
@ -67,11 +70,10 @@ void gamepad_tick(void) {
|
|||
if (common_hal_digitalio_digitalinout_get_value(data_pin)) {
|
||||
current |= bit;
|
||||
}
|
||||
bit <<= 1;
|
||||
common_hal_digitalio_digitalinout_set_value(clock_pin, 1);
|
||||
bit <<= 1;
|
||||
}
|
||||
common_hal_digitalio_digitalinout_set_value(latch_pin, 0);
|
||||
break;
|
||||
}
|
||||
gamepad_singleton->pressed |= last & current;
|
||||
last = current;
|
||||
|
|
Loading…
Reference in New Issue