Rebase on top of CircuitPython 4.x

This commit is contained in:
Radomir Dopieralski 2019-03-01 14:59:21 +01:00
parent 48f0a5163e
commit 45fea86554
10 changed files with 46 additions and 18 deletions

View File

@ -7,8 +7,6 @@
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
#include "internal_flash.h"
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)

View File

@ -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

View File

@ -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) },

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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)

View File

@ -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 \

View File

@ -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

View File

@ -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);

View File

@ -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;
}