Skip to content

Commit 87a400a

Browse files
authored
Merge pull request #9189 from dhalbert/pixel-trinkey
Adafruit Pixel Trinkey M0
2 parents 1a1d756 + 2e49989 commit 87a400a

File tree

8 files changed

+152
-10
lines changed

8 files changed

+152
-10
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "supervisor/board.h"
28+
29+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#define MICROPY_HW_BOARD_NAME "Adafruit Pixel Trinkey M0"
2+
#define MICROPY_HW_MCU_NAME "samd21e18"
3+
4+
#define MICROPY_HW_NEOPIXEL (&pin_PA01)
5+
#define MICROPY_HW_NEOPIXEL_COUNT (1)
6+
7+
#define CIRCUITPY_BOARD_SPI (1)
8+
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_PA05, .mosi = &pin_PA04, .miso = &pin_PA06}}
9+
10+
#define IGNORE_PIN_PA00 1
11+
12+
#define IGNORE_PIN_PA03 1
13+
14+
#define IGNORE_PIN_PA07 1
15+
#define IGNORE_PIN_PA08 1
16+
#define IGNORE_PIN_PA09 1
17+
#define IGNORE_PIN_PA10 1
18+
#define IGNORE_PIN_PA11 1
19+
// no PA12
20+
// no PA13
21+
#define IGNORE_PIN_PA14 1
22+
#define IGNORE_PIN_PA15 1
23+
#define IGNORE_PIN_PA16 1
24+
#define IGNORE_PIN_PA17 1
25+
#define IGNORE_PIN_PA18 1
26+
#define IGNORE_PIN_PA19 1
27+
// no PA20
28+
// no PA21
29+
#define IGNORE_PIN_PA22 1
30+
#define IGNORE_PIN_PA23 1
31+
// USB is always used internally so skip the pin objects for it.
32+
#define IGNORE_PIN_PA24 1
33+
#define IGNORE_PIN_PA25 1
34+
// no PA26
35+
#define IGNORE_PIN_PA27 1
36+
#define IGNORE_PIN_PA28 1
37+
// no PA29
38+
#define IGNORE_PIN_PA30 1
39+
#define IGNORE_PIN_PA31 1
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
USB_VID = 0x239A
2+
USB_PID = 0x8156
3+
USB_PRODUCT = "Pixel Trinkey M0"
4+
USB_MANUFACTURER = "Adafruit Industries LLC"
5+
6+
CHIP_VARIANT = SAMD21E18A
7+
CHIP_FAMILY = samd21
8+
9+
INTERNAL_FLASH_FILESYSTEM = 1
10+
LONGINT_IMPL = NONE
11+
12+
CIRCUITPY_FULL_BUILD = 0
13+
14+
CIRCUITPY_AUDIOCORE = 0
15+
CIRCUITPY_BUSIO_I2C = 0
16+
CIRCUITPY_PULSEIO = 1
17+
CIRCUITPY_PULSEIO_PULSEOUT = 0
18+
CIRCUITPY_PWMIO = 1
19+
CIRCUITPY_ROTARYIO = 0
20+
CIRCUITPY_RTC = 0
21+
CIRCUITPY_TOUCHIO = 0
22+
23+
CIRCUITPY_PIXELBUF = 1
24+
25+
# Include these Python libraries in firmware.
26+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
27+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_DotStar
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
4+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
5+
6+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA01) },
7+
8+
// 10K-10K voltage divider
9+
{ MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_PA02) },
10+
11+
// GPIO on 3-pin JST SH
12+
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA06) },
13+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA06) },
14+
15+
{ MP_ROM_QSTR(MP_QSTR_DATA), MP_ROM_PTR(&pin_PA04) },
16+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA04) },
17+
18+
{ MP_ROM_QSTR(MP_QSTR_CLOCK), MP_ROM_PTR(&pin_PA05) },
19+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA05) },
20+
21+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
22+
};
23+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

py/circuitpy_mpconfig.mk

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,16 @@ CFLAGS += -DCIRCUITPY_BUILTINS_POW3=$(CIRCUITPY_BUILTINS_POW3)
173173
CIRCUITPY_BUSIO ?= 1
174174
CFLAGS += -DCIRCUITPY_BUSIO=$(CIRCUITPY_BUSIO)
175175

176-
# These two flags pretend to implement their class but raise a ValueError due to
177-
# unsupported pins. This should be used sparingly on boards that don't break out
178-
# generic IO but need parts of busio.
179-
CIRCUITPY_BUSIO_SPI ?= 1
176+
# Allow disabling of individual busio functionality.
177+
# This should be used sparingly on specialized boards that can only implement parts of busio
178+
# due to pin restrictions.
179+
CIRCUITPY_BUSIO_I2C ?= $(CIRCUITPY_BUSIO)
180+
CFLAGS += -DCIRCUITPY_BUSIO_I2C=$(CIRCUITPY_BUSIO_I2C)
181+
182+
CIRCUITPY_BUSIO_SPI ?= $(CIRCUITPY_BUSIO)
180183
CFLAGS += -DCIRCUITPY_BUSIO_SPI=$(CIRCUITPY_BUSIO_SPI)
181184

182-
CIRCUITPY_BUSIO_UART ?= 1
185+
CIRCUITPY_BUSIO_UART ?= $(CIRCUITPY_BUSIO)
183186
CFLAGS += -DCIRCUITPY_BUSIO_UART=$(CIRCUITPY_BUSIO_UART)
184187

185188
CIRCUITPY_CAMERA ?= 0
@@ -409,6 +412,12 @@ CFLAGS += -DCIRCUITPY_PS2IO=$(CIRCUITPY_PS2IO)
409412
CIRCUITPY_PULSEIO ?= $(CIRCUITPY_FULL_BUILD)
410413
CFLAGS += -DCIRCUITPY_PULSEIO=$(CIRCUITPY_PULSEIO)
411414

415+
# Allow disabling of pulseio.PulseOut
416+
# This should be used sparingly on specialized boards that need PulseIin but
417+
# don't have the space for PulseOut.
418+
CIRCUITPY_PULSEIO_PULSEOUT ?= $(CIRCUITPY_PULSEIO)
419+
CFLAGS += -DCIRCUITPY_PULSEIO_PULSEOUT=$(CIRCUITPY_PULSEIO_PULSEOUT)
420+
412421
CIRCUITPY_PWMIO ?= 1
413422
CFLAGS += -DCIRCUITPY_PWMIO=$(CIRCUITPY_PWMIO)
414423

shared-bindings/busio/I2C.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
//| """
6868
//| ...
6969
STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
70+
#if CIRCUITPY_BUSIO_I2C
7071
busio_i2c_obj_t *self = mp_obj_malloc(busio_i2c_obj_t, &busio_i2c_type);
7172
enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout };
7273
static const mp_arg_t allowed_args[] = {
@@ -83,8 +84,13 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, siz
8384

8485
common_hal_busio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int, args[ARG_timeout].u_int);
8586
return (mp_obj_t)self;
87+
#else
88+
mp_raise_NotImplementedError(NULL);
89+
#endif // CIRCUITPY_BUSIO_I2C
90+
8691
}
8792

93+
#if CIRCUITPY_BUSIO_I2C
8894
//| def deinit(self) -> None:
8995
//| """Releases control of the underlying hardware so other classes can use it."""
9096
//| ...
@@ -371,8 +377,10 @@ STATIC mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *p
371377
return mp_const_none;
372378
}
373379
MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_then_readfrom_obj, 1, busio_i2c_writeto_then_readfrom);
380+
#endif // CIRCUITPY_BUSIO_I2C
374381

375382
STATIC const mp_rom_map_elem_t busio_i2c_locals_dict_table[] = {
383+
#if CIRCUITPY_BUSIO_I2C
376384
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&busio_i2c_deinit_obj) },
377385
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
378386
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&busio_i2c___exit___obj) },
@@ -384,6 +392,7 @@ STATIC const mp_rom_map_elem_t busio_i2c_locals_dict_table[] = {
384392
{ MP_ROM_QSTR(MP_QSTR_readfrom_into), MP_ROM_PTR(&busio_i2c_readfrom_into_obj) },
385393
{ MP_ROM_QSTR(MP_QSTR_writeto), MP_ROM_PTR(&busio_i2c_writeto_obj) },
386394
{ MP_ROM_QSTR(MP_QSTR_writeto_then_readfrom), MP_ROM_PTR(&busio_i2c_writeto_then_readfrom_obj) },
395+
#endif // CIRCUITPY_BUSIO_I2C
387396
};
388397

389398
STATIC MP_DEFINE_CONST_DICT(busio_i2c_locals_dict, busio_i2c_locals_dict_table);

shared-bindings/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, siz
127127
common_hal_busio_spi_construct(self, clock, mosi, miso, args[ARG_half_duplex].u_bool);
128128
return MP_OBJ_FROM_PTR(self);
129129
#else
130-
raise_ValueError_invalid_pins();
130+
mp_raise_NotImplementedError(NULL);
131131
#endif // CIRCUITPY_BUSIO_SPI
132132
}
133133

shared-bindings/pulseio/PulseOut.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@
3232

3333
#include "shared-bindings/microcontroller/Pin.h"
3434
#include "shared-bindings/pulseio/PulseOut.h"
35-
#include "shared-bindings/pwmio/PWMOut.h"
3635
#include "shared-bindings/util.h"
3736

3837
//| class PulseOut:
39-
//| """Pulse PWM "carrier" output on and off. This is commonly used in infrared remotes. The
40-
//| pulsed signal consists of timed on and off periods. Unlike PWM, there is no set duration
38+
//| """Pulse PWM-modulated "carrier" output on and off. This is commonly used in infrared remotes. The
39+
//| pulsed signal consists of timed on and off periods. Unlike `pwmio.PWMOut`, there is no set duration
4140
//| for on and off pairs."""
4241
//|
4342
//| def __init__(
@@ -53,7 +52,6 @@
5352
//|
5453
//| import array
5554
//| import pulseio
56-
//| import pwmio
5755
//| import board
5856
//|
5957
//| # 50% duty cycle at 38kHz.
@@ -67,6 +65,7 @@
6765
//| pulse.send(pulses)"""
6866
//| ...
6967
STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
68+
#if CIRCUITPY_PULSEIO_PULSEOUT
7069
enum { ARG_pin, ARG_frequency, ARG_duty_cycle};
7170
static const mp_arg_t allowed_args[] = {
7271
{ MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
@@ -84,8 +83,12 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar
8483
self->base.type = &pulseio_pulseout_type;
8584
common_hal_pulseio_pulseout_construct(self, pin, frequency, duty_cycle);
8685
return MP_OBJ_FROM_PTR(self);
86+
#else
87+
mp_raise_NotImplementedError(NULL);
88+
#endif
8789
}
8890

91+
#if CIRCUITPY_PULSEIO_PULSEOUT
8992
//| def deinit(self) -> None:
9093
//| """Deinitialises the PulseOut and releases any hardware resources for reuse."""
9194
//| ...
@@ -138,14 +141,17 @@ STATIC mp_obj_t pulseio_pulseout_obj_send(mp_obj_t self_in, mp_obj_t pulses) {
138141
return mp_const_none;
139142
}
140143
MP_DEFINE_CONST_FUN_OBJ_2(pulseio_pulseout_send_obj, pulseio_pulseout_obj_send);
144+
#endif // CIRCUITPY_PULSEIO_PULSEOUT
141145

142146
STATIC const mp_rom_map_elem_t pulseio_pulseout_locals_dict_table[] = {
143147
// Methods
148+
#if CIRCUITPY_PULSEIO_PULSEOUT
144149
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pulseio_pulseout_deinit_obj) },
145150
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&pulseio_pulseout_deinit_obj) },
146151
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
147152
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&pulseio_pulseout___exit___obj) },
148153
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&pulseio_pulseout_send_obj) },
154+
#endif // CIRCUITPY_PULSEIO_PULSEOUT
149155
};
150156
STATIC MP_DEFINE_CONST_DICT(pulseio_pulseout_locals_dict, pulseio_pulseout_locals_dict_table);
151157

0 commit comments

Comments
 (0)