Skip to content

Commit 45fea86

Browse files
committed
Rebase on top of CircuitPython 4.x
1 parent 48f0a51 commit 45fea86

10 files changed

Lines changed: 46 additions & 18 deletions

File tree

ports/atmel-samd/boards/pewpew10/mpconfigboard.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
#define CIRCUITPY_INTERNAL_NVM_SIZE 0
99

10-
#include "internal_flash.h"
11-
1210
#define BOARD_FLASH_SIZE (0x00040000 - 0x2000 - 0x010000)
1311

1412

ports/atmel-samd/boards/pewpew10/mpconfigboard.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ CHIP_VARIANT = SAMD21E18A
1111
CHIP_FAMILY = samd21
1212

1313
FROZEN_MPY_DIRS += $(TOP)/frozen/pewpew10
14+
15+
CIRCUITPY_PEW = 1
16+
CIRCUITPY_ANALOGIO = 1
17+
CIRCUITPY_MATH = 0
18+
CIRCUITPY_NEOPIXEL_WRITE = 1
19+
CIRCUITPY_RTC = 0
20+
CIRCUITPY_SAMD = 0
21+
CIRCUITPY_USB_MIDI = 0
22+
CIRCUITPY_SMALL_BUILD = 1

ports/atmel-samd/boards/pewpew10/pins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "shared-bindings/board/__init__.h"
22

3-
#include "board_busses.h"
3+
#include "supervisor/shared/board_busses.h"
44

55
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
66
{ MP_ROM_QSTR(MP_QSTR_R1), MP_ROM_PTR(&pin_PA05) },

ports/atmel-samd/timer_handler.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "timer_handler.h"
3131

3232
#include "common-hal/pulseio/PulseOut.h"
33+
#include "shared-module/_pew/PewPew.h"
3334

3435
static uint8_t tc_handler[TC_INST_NUM];
3536

@@ -44,8 +45,15 @@ void shared_timer_handler(bool is_tc, uint8_t index) {
4445
// Make sure to add the handler #define to timer_handler.h
4546
if (is_tc) {
4647
uint8_t handler = tc_handler[index];
47-
if (handler == TC_HANDLER_PULSEOUT) {
48-
pulseout_interrupt_handler(index);
48+
switch(handler) {
49+
case TC_HANDLER_PULSEOUT:
50+
pulseout_interrupt_handler(index);
51+
break;
52+
case TC_HANDLER_PEW:
53+
pewpew_interrupt_handler(index);
54+
break;
55+
default:
56+
break;
4957
}
5058
}
5159
}

ports/atmel-samd/timer_handler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define TC_HANDLER_NO_INTERRUPT 0x0
3030
#define TC_HANDLER_PULSEOUT 0x1
31+
#define TC_HANDLER_PEW 0x2
3132

3233
void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler);
3334
void shared_timer_handler(bool is_tc, uint8_t index);

py/circuitpy_defns.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ $(filter $(SRC_PATTERNS), \
321321
terminalio/__init__.c \
322322
uheap/__init__.c \
323323
ustack/__init__.c \
324+
_pew/__init__.c \
325+
_pew/PewPew.c \
324326
)
325327

326328
ifeq ($(INTERNAL_LIBM),1)

py/circuitpy_mpconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ extern const struct _mp_obj_module_t pew_module;
543543
USB_HID_MODULE \
544544
USB_MIDI_MODULE \
545545
USTACK_MODULE \
546+
PEW_MODULE \
546547

547548
// If weak links are enabled, just include strong links in the main list of modules,
548549
// and also include the underscore alternate names.
@@ -569,6 +570,7 @@ extern const struct _mp_obj_module_t pew_module;
569570
vstr_t *repl_line; \
570571
mp_obj_t rtc_time_source; \
571572
mp_obj_t gamepad_singleton; \
573+
mp_obj_t pew_singleton; \
572574
mp_obj_t terminal_tilegrid_tiles; \
573575
FLASH_ROOT_POINTERS \
574576
NETWORK_ROOT_POINTERS \

py/circuitpy_mpconfig.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ CIRCUITPY_USB_MIDI = 1
213213
endif
214214
CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI)
215215

216+
ifndef CIRCUITPY_PEW
217+
CIRCUITPY_PEW = 0
218+
endif
219+
CFLAGS += -DCIRCUITPY_PEW=$(CIRCUITPY_PEW)
220+
216221
# For debugging.
217222
ifndef CIRCUITPY_USTACK
218223
CIRCUITPY_USTACK = 0

shared-bindings/_pew/PewPew.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "shared-bindings/util.h"
3333
#include "PewPew.h"
3434
#include "shared-module/_pew/PewPew.h"
35+
#include "supervisor/shared/translate.h"
3536

3637

3738
//| .. currentmodule:: _pew
@@ -49,10 +50,8 @@
4950
//|
5051
//|
5152
STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args,
52-
size_t n_kw, const mp_obj_t *pos_args) {
53-
mp_arg_check_num(n_args, n_kw, 4, 4, true);
54-
mp_map_t kw_args;
55-
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
53+
const mp_obj_t *pos_args, mp_map_t *kw_args) {
54+
mp_arg_check_num(n_args, kw_args, 4, 4, true);
5655
enum { ARG_buffer, ARG_rows, ARG_cols, ARG_buttons };
5756
static const mp_arg_t allowed_args[] = {
5857
{ 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,
6160
{ MP_QSTR_buttons, MP_ARG_OBJ | MP_ARG_REQUIRED },
6261
};
6362
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
64-
mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args),
63+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args),
6564
allowed_args, args);
6665

6766
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,
7675
mp_obj_get_array(args[ARG_cols].u_obj, &cols_size, &cols);
7776

7877
if (bufinfo.len != rows_size * cols_size) {
79-
mp_raise_TypeError("wrong buffer size");
78+
mp_raise_TypeError(translate(""));
8079
}
8180

8281
for (size_t i = 0; i < rows_size; ++i) {
8382
if (!MP_OBJ_IS_TYPE(rows[i], &digitalio_digitalinout_type)) {
84-
mp_raise_TypeError("expected a DigitalInOut");
83+
mp_raise_TypeError(translate(""));
8584
}
8685
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(rows[i]);
8786
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,
9089

9190
for (size_t i = 0; i < cols_size; ++i) {
9291
if (!MP_OBJ_IS_TYPE(cols[i], &digitalio_digitalinout_type)) {
93-
mp_raise_TypeError("expected a DigitalInOut");
92+
mp_raise_TypeError(translate(""));
9493
}
9594
digitalio_digitalinout_obj_t *pin = MP_OBJ_TO_PTR(cols[i]);
9695
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,
9998

10099
if (!MP_OBJ_IS_TYPE(args[ARG_buttons].u_obj,
101100
&digitalio_digitalinout_type)) {
102-
mp_raise_TypeError("expected a DigitalInOut");
101+
mp_raise_TypeError(translate(""));
103102
}
104103
digitalio_digitalinout_obj_t *buttons = MP_OBJ_TO_PTR(
105104
args[ARG_buttons].u_obj);

shared-module/_pew/PewPew.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "shared-bindings/digitalio/DigitalInOut.h"
3636
#include "shared-bindings/util.h"
3737
#include "samd/timers.h"
38+
#include "supervisor/shared/translate.h"
39+
#include "timer_handler.h"
3840

3941

4042
static uint8_t pewpew_tc_index = 0xff;
@@ -77,10 +79,11 @@ void pew_init() {
7779
}
7880
}
7981
if (tc == NULL) {
80-
mp_raise_RuntimeError("All timers in use");
82+
mp_raise_RuntimeError(translate(""));
8183
}
8284

8385
pewpew_tc_index = index;
86+
set_timer_handler(true, index, TC_HANDLER_PEW);
8487

8588
// We use GCLK0 for SAMD21 and GCLK1 for SAMD51 because they both run
8689
// at 48mhz making our math the same across the boards.
@@ -106,7 +109,6 @@ void pew_init() {
106109
#endif
107110

108111
tc_set_enable(tc, true);
109-
//tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_STOP;
110112
tc->COUNT16.CC[0].reg = 160;
111113

112114
// Clear our interrupt in case it was set earlier
@@ -117,7 +119,9 @@ void pew_init() {
117119
}
118120

119121
void pew_reset(void) {
120-
tc_insts[pewpew_tc_index]->COUNT16.CTRLA.bit.ENABLE = 0;
121-
pewpew_tc_index = 0xff;
122+
if (pewpew_tc_index != 0xff) {
123+
tc_reset(tc_insts[pewpew_tc_index]);
124+
pewpew_tc_index = 0xff;
125+
}
122126
MP_STATE_VM(pew_singleton) = NULL;
123127
}

0 commit comments

Comments
 (0)