Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bake a very simple library into the firmware. #6

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion modules/default.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
example.py
multi-sensor-breakout/*.py
6 changes: 6 additions & 0 deletions modules/py_frozen/boot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import builtins
import cppmem
import explorer

for k, v in explorer._exports.items():
setattr(builtins, k, v)

# Switch C++ memory allocations to use MicroPython's heap
cppmem.set_mode(cppmem.MICROPYTHON)
42 changes: 42 additions & 0 deletions modules/py_frozen/explorer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from picographics import PicoGraphics, DISPLAY_EXPLORER, PEN_RGB565
from machine import Pin
from micropython import const

# We're only using a few colours so we can use a 4 bit/16 colour palette and save RAM!
display = PicoGraphics(display=DISPLAY_EXPLORER, pen_type=PEN_RGB565)

BUTTON_A_PIN = const(16)
BUTTON_B_PIN = const(15)
BUTTON_C_PIN = const(14)
BUTTON_X_PIN = const(17)
BUTTON_Y_PIN = const(18)
BUTTON_Z_PIN = const(19)

BLACK = display.create_pen(0, 0, 0)
WHITE = display.create_pen(255, 255, 255)
CYAN = display.create_pen(0, 255, 255)
MAGENTA = display.create_pen(255, 0, 255)
YELLOW = display.create_pen(255, 255, 0)
RED = display.create_pen(255, 0, 0)
GREEN = display.create_pen(0, 255, 0)
BLUE = display.create_pen(0, 0, 255)

_button_a = Pin(BUTTON_A_PIN, Pin.IN, Pin.PULL_UP)
_button_b = Pin(BUTTON_B_PIN, Pin.IN, Pin.PULL_UP)
_button_c = Pin(BUTTON_C_PIN, Pin.IN, Pin.PULL_UP)
_button_x = Pin(BUTTON_X_PIN, Pin.IN, Pin.PULL_UP)
_button_y = Pin(BUTTON_Y_PIN, Pin.IN, Pin.PULL_UP)
_button_z = Pin(BUTTON_Z_PIN, Pin.IN, Pin.PULL_UP)

_exports = {
"BLACK": BLACK,
"WHITE": WHITE,
"CYAN": CYAN,
"MAGENTA": MAGENTA,
"YELLOW": YELLOW,
"RED": RED,
"GREEN": GREEN,
"BLUE": BLUE,
"text": display.text,
"pen": display.set_pen
}
2 changes: 0 additions & 2 deletions modules/py_littlefs/example.py

This file was deleted.