diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile index b6396d2ed0..5d3af6e39a 100644 --- a/atmel-samd/Makefile +++ b/atmel-samd/Makefile @@ -27,6 +27,15 @@ BOSSAC := tools/bossac_osx HAL_DIR=hal/$(MCU_SERIES) +# Frozen bytecode configuration. Any .py files placed in the modules subdirectory +# will be frozen into .mpy files and embedded in the firmware (like the ESP8266 +# port). +MPY_CROSS = ../mpy-cross/mpy-cross +MPY_TOOL = ../tools/mpy-tool.py +FROZEN_MPY_DIR = modules +FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py') +FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy)) + INC += -I. INC += -I.. INC += -I../lib/mp-readline @@ -187,7 +196,7 @@ SRC_BINDINGS_EXPANDED = $(addprefix shared-bindings/, $(SRC_BINDINGS)) \ $(addprefix common-hal/, $(SRC_BINDINGS)) SRC_AUTOGEN = \ - $(BUILD)/_frozen_mpy.c \ + $(BUILD)/frozen_mpy.c \ OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o)) @@ -199,9 +208,16 @@ SRC_QSTR += $(SRC_C) $(SRC_BINDINGS_EXPANDED) $(STM_SRC_C) all: $(BUILD)/firmware.bin -$(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h - $(ECHO) "MISC freezing bytecode" - $(Q)../tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@ +# to build .mpy files from .py files +$(BUILD)/$(FROZEN_MPY_DIR)/%.mpy: $(FROZEN_MPY_DIR)/%.py + @$(ECHO) "MPY $<" + $(Q)$(MKDIR) -p $(dir $@) + $(Q)$(MPY_CROSS) -o $@ -s $(^:$(FROZEN_MPY_DIR)/%=%) $^ + +# to build frozen_mpy.c from all .mpy files +$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h + @$(ECHO) "Creating $@" + $(Q)$(PYTHON) $(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $(FROZEN_MPY_MPY_FILES) > $@ $(BUILD)/firmware.elf: $(OBJ) $(ECHO) "LINK $@" diff --git a/atmel-samd/frozentest.mpy b/atmel-samd/frozentest.mpy deleted file mode 100644 index c8345b1910..0000000000 Binary files a/atmel-samd/frozentest.mpy and /dev/null differ diff --git a/atmel-samd/frozentest.py b/atmel-samd/modules/frozentest.py similarity index 100% rename from atmel-samd/frozentest.py rename to atmel-samd/modules/frozentest.py diff --git a/atmel-samd/modules/neopixel.py b/atmel-samd/modules/neopixel.py new file mode 100644 index 0000000000..dba1e4aea0 --- /dev/null +++ b/atmel-samd/modules/neopixel.py @@ -0,0 +1,31 @@ +# NeoPixel driver for MicroPython on ESP8266 +# MIT license; Copyright (c) 2016 Damien P. George + +from neopixel_write import neopixel_write + +class NeoPixel: + def __init__(self, pin, n): + self.pin = pin + self.n = n + self.buf = bytearray(n * 3) + self.pin.init(pin.OUT) + + def __setitem__(self, index, val): + r, g, b = val + self.buf[index * 3] = g + self.buf[index * 3 + 1] = r + self.buf[index * 3 + 2] = b + + def __getitem__(self, index): + i = index * 3 + return self.buf[i + 1], self.buf[i], self.buf[i + 2] + + def fill(self, color): + r, g, b = color + for i in range(len(self.buf) / 3): + self.buf[i * 3] = g + self.buf[i * 3 + 1] = r + self.buf[i * 3 + 2] = b + + def write(self): + neopixel_write(self.pin, self.buf, True)