From 40ba07108ac18f7bdadaa90cb3246a6a677a0b71 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 23 Sep 2024 15:30:11 +0100 Subject: [PATCH] Bake a very simple library into the firmware. --- modules/default.txt | 2 +- modules/py_frozen/boot.py | 6 +++++ modules/py_frozen/explorer.py | 42 ++++++++++++++++++++++++++++++++++ modules/py_littlefs/example.py | 2 -- 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 modules/py_frozen/explorer.py delete mode 100644 modules/py_littlefs/example.py diff --git a/modules/default.txt b/modules/default.txt index 8d75d26..079af51 100644 --- a/modules/default.txt +++ b/modules/default.txt @@ -1 +1 @@ -example.py \ No newline at end of file +multi-sensor-breakout/*.py \ No newline at end of file diff --git a/modules/py_frozen/boot.py b/modules/py_frozen/boot.py index 46e338c..0da3f85 100644 --- a/modules/py_frozen/boot.py +++ b/modules/py_frozen/boot.py @@ -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) diff --git a/modules/py_frozen/explorer.py b/modules/py_frozen/explorer.py new file mode 100644 index 0000000..1bb75f2 --- /dev/null +++ b/modules/py_frozen/explorer.py @@ -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 +} \ No newline at end of file diff --git a/modules/py_littlefs/example.py b/modules/py_littlefs/example.py deleted file mode 100644 index 51bd8e8..0000000 --- a/modules/py_littlefs/example.py +++ /dev/null @@ -1,2 +0,0 @@ -# This file should be added to the user-facing MicroPython filesystem -print("Hello World") \ No newline at end of file