From 45fea86554d42d07360ec16574908bc96c5e37ec Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 14:59:21 +0100 Subject: Rebase on top of CircuitPython 4.x --- ports/atmel-samd/boards/pewpew10/mpconfigboard.h | 2 -- ports/atmel-samd/boards/pewpew10/mpconfigboard.mk | 9 +++++++++ ports/atmel-samd/boards/pewpew10/pins.c | 2 +- ports/atmel-samd/timer_handler.c | 12 ++++++++++-- ports/atmel-samd/timer_handler.h | 1 + py/circuitpy_defns.mk | 2 ++ py/circuitpy_mpconfig.h | 2 ++ py/circuitpy_mpconfig.mk | 5 +++++ shared-bindings/_pew/PewPew.c | 17 ++++++++--------- shared-module/_pew/PewPew.c | 12 ++++++++---- 10 files changed, 46 insertions(+), 18 deletions(-) diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h index 3fd1cbce1..09618431b 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.h +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.h @@ -7,8 +7,6 @@ #define CIRCUITPY_INTERNAL_NVM_SIZE 0 -#include "internal_flash.h" - #define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000) diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk index cf3004a4d..eeb5632ef 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk @@ -11,3 +11,12 @@ CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 FROZEN_MPY_DIRS += $(TOP)/frozen/pewpew10 + +CIRCUITPY_PEW = 1 +CIRCUITPY_ANALOGIO = 1 +CIRCUITPY_MATH = 0 +CIRCUITPY_NEOPIXEL_WRITE = 1 +CIRCUITPY_RTC = 0 +CIRCUITPY_SAMD = 0 +CIRCUITPY_USB_MIDI = 0 +CIRCUITPY_SMALL_BUILD = 1 diff --git a/ports/atmel-samd/boards/pewpew10/pins.c b/ports/atmel-samd/boards/pewpew10/pins.c index 499e6270b..082394d17 100644 --- a/ports/atmel-samd/boards/pewpew10/pins.c +++ b/ports/atmel-samd/boards/pewpew10/pins.c @@ -1,6 +1,6 @@ #include "shared-bindings/board/__init__.h" -#include "board_busses.h" +#include "supervisor/shared/board_busses.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_R1), MP_ROM_PTR(&pin_PA05) }, diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index 26f984d96..ac162329e 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -30,6 +30,7 @@ #include "timer_handler.h" #include "common-hal/pulseio/PulseOut.h" +#include "shared-module/_pew/PewPew.h" static uint8_t tc_handler[TC_INST_NUM]; @@ -44,8 +45,15 @@ void shared_timer_handler(bool is_tc, uint8_t index) { // Make sure to add the handler #define to timer_handler.h if (is_tc) { uint8_t handler = tc_handler[index]; - if (handler == TC_HANDLER_PULSEOUT) { - pulseout_interrupt_handler(index); + switch(handler) { + case TC_HANDLER_PULSEOUT: + pulseout_interrupt_handler(index); + break; + case TC_HANDLER_PEW: + pewpew_interrupt_handler(index); + break; + default: + break; } } } diff --git a/ports/atmel-samd/timer_handler.h b/ports/atmel-samd/timer_handler.h index f7a6e6e0e..e249fca36 100644 --- a/ports/atmel-samd/timer_handler.h +++ b/ports/atmel-samd/timer_handler.h @@ -28,6 +28,7 @@ #define TC_HANDLER_NO_INTERRUPT 0x0 #define TC_HANDLER_PULSEOUT 0x1 +#define TC_HANDLER_PEW 0x2 void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler); void shared_timer_handler(bool is_tc, uint8_t index); diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 080263487..c10edfe4e 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -321,6 +321,8 @@ $(filter $(SRC_PATTERNS), \ terminalio/__init__.c \ uheap/__init__.c \ ustack/__init__.c \ + _pew/__init__.c \ + _pew/PewPew.c \ ) ifeq ($(INTERNAL_LIBM),1) diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index c20c0fb66..25aabc292 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -543,6 +543,7 @@ extern const struct _mp_obj_module_t pew_module; USB_HID_MODULE \ USB_MIDI_MODULE \ USTACK_MODULE \ + PEW_MODULE \ // If weak links are enabled, just include strong links in the main list of modules, // and also include the underscore alternate names. @@ -569,6 +570,7 @@ extern const struct _mp_obj_module_t pew_module; vstr_t *repl_line; \ mp_obj_t rtc_time_source; \ mp_obj_t gamepad_singleton; \ + mp_obj_t pew_singleton; \ mp_obj_t terminal_tilegrid_tiles; \ FLASH_ROOT_POINTERS \ NETWORK_ROOT_POINTERS \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index a4a59170f..54a38dfee 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -213,6 +213,11 @@ CIRCUITPY_USB_MIDI = 1 endif CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI) +ifndef CIRCUITPY_PEW +CIRCUITPY_PEW = 0 +endif +CFLAGS += -DCIRCUITPY_PEW=$(CIRCUITPY_PEW) + # For debugging. ifndef CIRCUITPY_USTACK CIRCUITPY_USTACK = 0 diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 69c9ff4fc..19eb00736 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -32,6 +32,7 @@ #include "shared-bindings/util.h" #include "PewPew.h" #include "shared-module/_pew/PewPew.h" +#include "supervisor/shared/translate.h" //| .. currentmodule:: _pew @@ -49,10 +50,8 @@ //| //| STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, - size_t n_kw, const mp_obj_t *pos_args) { - mp_arg_check_num(n_args, n_kw, 4, 4, true); - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); + const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 4, 4, true); enum { ARG_buffer, ARG_rows, ARG_cols, ARG_buttons }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -61,7 +60,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_buttons, MP_ARG_OBJ | MP_ARG_REQUIRED }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; @@ -76,12 +75,12 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, mp_obj_get_array(args[ARG_cols].u_obj, &cols_size, &cols); if (bufinfo.len != rows_size * cols_size) { - mp_raise_TypeError("wrong buffer size"); + mp_raise_TypeError(translate("")); } for (size_t i = 0; i < rows_size; ++i) { if (!MP_OBJ_IS_TYPE(rows[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError("expected a DigitalInOut"); + mp_raise_TypeError(translate("")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(rows[i]); raise_error_if_deinited( @@ -90,7 +89,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, for (size_t i = 0; i < cols_size; ++i) { if (!MP_OBJ_IS_TYPE(cols[i], &digitalio_digitalinout_type)) { - mp_raise_TypeError("expected a DigitalInOut"); + mp_raise_TypeError(translate("")); } digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(cols[i]); raise_error_if_deinited( @@ -99,7 +98,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, if (!MP_OBJ_IS_TYPE(args[ARG_buttons].u_obj, &digitalio_digitalinout_type)) { - mp_raise_TypeError("expected a DigitalInOut"); + mp_raise_TypeError(translate("")); } digitalio_digitalinout_obj_t *buttons = MP_OBJ_TO_PTR( args[ARG_buttons].u_obj); diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index cbe7164bc..2900f2ac7 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -35,6 +35,8 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/util.h" #include "samd/timers.h" +#include "supervisor/shared/translate.h" +#include "timer_handler.h" static uint8_t pewpew_tc_index = 0xff; @@ -77,10 +79,11 @@ void pew_init() { } } if (tc == NULL) { - mp_raise_RuntimeError("All timers in use"); + mp_raise_RuntimeError(translate("")); } pewpew_tc_index = index; + set_timer_handler(true, index, TC_HANDLER_PEW); // We use GCLK0 for SAMD21 and GCLK1 for SAMD51 because they both run // at 48mhz making our math the same across the boards. @@ -106,7 +109,6 @@ void pew_init() { #endif tc_set_enable(tc, true); - //tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_STOP; tc->COUNT16.CC[0].reg = 160; // Clear our interrupt in case it was set earlier @@ -117,7 +119,9 @@ void pew_init() { } void pew_reset(void) { - tc_insts[pewpew_tc_index]->COUNT16.CTRLA.bit.ENABLE = 0; - pewpew_tc_index = 0xff; + if (pewpew_tc_index != 0xff) { + tc_reset(tc_insts[pewpew_tc_index]); + pewpew_tc_index = 0xff; + } MP_STATE_VM(pew_singleton) = NULL; } -- cgit v1.2.3