Skip to content

Commit fffc6d1

Browse files
committed
atmel-samd: Add modules directory with frozen bytecode support (like ESP8266 port), and NeoPixel python wrapper module.
1 parent 674038c commit fffc6d1

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

atmel-samd/Makefile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ BOSSAC := tools/bossac_osx
2727

2828
HAL_DIR=hal/$(MCU_SERIES)
2929

30+
# Frozen bytecode configuration. Any .py files placed in the modules subdirectory
31+
# will be frozen into .mpy files and embedded in the firmware (like the ESP8266
32+
# port).
33+
MPY_CROSS = ../mpy-cross/mpy-cross
34+
MPY_TOOL = ../tools/mpy-tool.py
35+
FROZEN_MPY_DIR = modules
36+
FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py')
37+
FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy))
38+
3039
INC += -I.
3140
INC += -I..
3241
INC += -I../lib/mp-readline
@@ -187,7 +196,7 @@ SRC_BINDINGS_EXPANDED = $(addprefix shared-bindings/, $(SRC_BINDINGS)) \
187196
$(addprefix common-hal/, $(SRC_BINDINGS))
188197

189198
SRC_AUTOGEN = \
190-
$(BUILD)/_frozen_mpy.c \
199+
$(BUILD)/frozen_mpy.c \
191200

192201
OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
193202
OBJ += $(addprefix $(BUILD)/, $(SRC_ASF:.c=.o))
@@ -199,9 +208,16 @@ SRC_QSTR += $(SRC_C) $(SRC_BINDINGS_EXPANDED) $(STM_SRC_C)
199208

200209
all: $(BUILD)/firmware.bin
201210

202-
$(BUILD)/_frozen_mpy.c: frozentest.mpy $(BUILD)/genhdr/qstrdefs.generated.h
203-
$(ECHO) "MISC freezing bytecode"
204-
$(Q)../tools/mpy-tool.py -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $< > $@
211+
# to build .mpy files from .py files
212+
$(BUILD)/$(FROZEN_MPY_DIR)/%.mpy: $(FROZEN_MPY_DIR)/%.py
213+
@$(ECHO) "MPY $<"
214+
$(Q)$(MKDIR) -p $(dir $@)
215+
$(Q)$(MPY_CROSS) -o $@ -s $(^:$(FROZEN_MPY_DIR)/%=%) $^
216+
217+
# to build frozen_mpy.c from all .mpy files
218+
$(BUILD)/frozen_mpy.c: $(FROZEN_MPY_MPY_FILES) $(BUILD)/genhdr/qstrdefs.generated.h
219+
@$(ECHO) "Creating $@"
220+
$(Q)$(PYTHON) $(MPY_TOOL) -f -q $(BUILD)/genhdr/qstrdefs.preprocessed.h -mlongint-impl=none $(FROZEN_MPY_MPY_FILES) > $@
205221

206222
$(BUILD)/firmware.elf: $(OBJ)
207223
$(ECHO) "LINK $@"

atmel-samd/frozentest.mpy

-255 Bytes
Binary file not shown.
File renamed without changes.

atmel-samd/modules/neopixel.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# NeoPixel driver for MicroPython on ESP8266
2+
# MIT license; Copyright (c) 2016 Damien P. George
3+
4+
from neopixel_write import neopixel_write
5+
6+
class NeoPixel:
7+
def __init__(self, pin, n):
8+
self.pin = pin
9+
self.n = n
10+
self.buf = bytearray(n * 3)
11+
self.pin.init(pin.OUT)
12+
13+
def __setitem__(self, index, val):
14+
r, g, b = val
15+
self.buf[index * 3] = g
16+
self.buf[index * 3 + 1] = r
17+
self.buf[index * 3 + 2] = b
18+
19+
def __getitem__(self, index):
20+
i = index * 3
21+
return self.buf[i + 1], self.buf[i], self.buf[i + 2]
22+
23+
def fill(self, color):
24+
r, g, b = color
25+
for i in range(len(self.buf) / 3):
26+
self.buf[i * 3] = g
27+
self.buf[i * 3 + 1] = r
28+
self.buf[i * 3 + 2] = b
29+
30+
def write(self):
31+
neopixel_write(self.pin, self.buf, True)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy