Skip to content

Commit

Permalink
Bake a very simple library into the firmware.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Sep 23, 2024
1 parent aa7ee5c commit 40ba071
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
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.

0 comments on commit 40ba071

Please sign in to comment.