Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions software/firmware/europi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

from version import __version__

from configuration import ConfigSettings
from framebuf import FrameBuffer, MONO_HLSB

from europi_config import load_europi_config, MODEL_PICO_2W, MODEL_PICO_W
Expand All @@ -39,7 +38,6 @@
from europi_log import *

from experimental.experimental_config import load_experimental_config
from experimental.wifi import WifiConnection, WifiError


if sys.implementation.name == "micropython":
Expand Down Expand Up @@ -127,6 +125,8 @@ def bootsplash():
# Connect to wifi, if supported
if europi_config.PICO_MODEL == MODEL_PICO_W or europi_config.PICO_MODEL == MODEL_PICO_2W:
try:
from experimental.wifi import WifiConnection, WifiError

oled.centre_text(
f"""WiFi connecting
{experimental_config.WIFI_SSID}
Expand Down
5 changes: 3 additions & 2 deletions software/uf2_build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ FROM ubuntu:22.04
ENV TERM=xterm DEBIAN_FRONTEND=noninteractive

RUN apt update && apt install -y \
cmake git-core gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential wget python3
cmake git-core gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential wget python3 sed

WORKDIR /

RUN git clone -b v1.25.0 --depth=1 --recursive https://github.com/micropython/micropython.git
RUN git clone -b v1.28.0 --depth=1 --recursive https://github.com/micropython/micropython.git

WORKDIR micropython

Expand All @@ -25,6 +25,7 @@ BootloaderMenu(EUROPI_SCRIPTS).main()\n\
' > ports/rp2/modules/main.py

COPY software/uf2_build/copy_and_compile.sh /
COPY software/uf2_build/strip_python.py /

WORKDIR /

Expand Down
20 changes: 16 additions & 4 deletions software/uf2_build/copy_and_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ echo "Copying EuroPi firmware and scripts to container..."
mkdir /micropython/ports/rp2/modules/contrib
mkdir /micropython/ports/rp2/modules/experimental
mkdir /micropython/ports/rp2/modules/tools
cp -r europi/software/firmware/*.py /micropython/ports/rp2/modules
cp -r europi/software/firmware/experimental/*.py /micropython/ports/rp2/modules/experimental
cp -r europi/software/firmware/tools/*.py /micropython/ports/rp2/modules/tools
cp -r europi/software/contrib/*.py /micropython/ports/rp2/modules/contrib
for pyfile in $(ls europi/software/firmware/*.py); do
f=$(basename $pyfile)
python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/$f"
done
for pyfile in $(ls europi/software/firmware/experimental/*.py); do
f=$(basename $pyfile)
python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/experimental/$f"
done
for pyfile in $(ls europi/software/firmware/tools/*.py); do
f=$(basename $pyfile)
python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/tools/$f"
done
for pyfile in $(ls europi/software/contrib/*.py); do
f=$(basename $pyfile)
python3 /strip_python.py "$pyfile" "/micropython/ports/rp2/modules/contrib/$f"
done

echo "Compiling micropython and firmware modules..."
cd /micropython/ports/rp2
Expand Down
51 changes: 51 additions & 0 deletions software/uf2_build/strip_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
"""
Strip comments and docstrings from a file.

Copied from https://gist.github.com/BroHui/aca2b8e6e6bdf3cb4af4b246c9837fa3 with modifications.
"""

import sys, token, tokenize


def process_file(infile, outfile):
"""
Remove comments and docstrings from one file and write the result to another.

@param infile The path to the file to process
@param outfile The path to the file we're generating
"""
source = open(infile, "r")
mod = open(outfile, "w")

prev_toktype = token.INDENT
last_lineno = -1
last_col = 0

tokgen = tokenize.generate_tokens(source.readline)
for toktype, ttext, (slineno, scol), (elineno, ecol), ltext in tokgen:
if 0: # Change to if 1 to see the tokens fly by.
print("%10s %-14s %-20r %r" % (
tokenize.tok_name.get(toktype, toktype),
"%d.%d-%d.%d" % (slineno, scol, elineno, ecol),
ttext, ltext
))
if slineno > last_lineno:
last_col = 0
if scol > last_col:
mod.write(" " * (scol - last_col))
if toktype == token.STRING and prev_toktype == token.INDENT:
# Docstring
mod.write("#--")
elif toktype == tokenize.COMMENT:
# Comment
mod.write("##")
else:
mod.write(ttext)
prev_toktype = toktype
last_col = ecol
last_lineno = elineno


if __name__ == '__main__':
process_file(sys.argv[1], sys.argv[2])
Loading