diff --git a/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/manifest.py b/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/manifest.py index d19f4e95..f021d578 100644 --- a/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/manifest.py +++ b/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/manifest.py @@ -5,13 +5,12 @@ # The ili9341_esp32_audio_kit board package: what mip.install("ili9341_esp32_audio_kit") brings. metadata( description="Ai-Thinker ESP32-Audio-Kit V2.2 with a 2.8\" ILI9341 IPS touch module - MicroPython", - version="0.1", + version="0.2", ) require("omnipython") +require("esp32_audio_kit") require("ili9341") require("ft6x36") -require("es8388") module("board_config.py") -module("board_peripherals.py") diff --git a/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/package.json b/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/package.json index 3bdf2551..6e506889 100644 --- a/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/package.json +++ b/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/package.json @@ -6,7 +6,15 @@ ], [ "board_peripherals.py", - "github:PyDevices/omnipython/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/board_peripherals.py" + "github:PyDevices/omnipython/board_configs/nodisplay/esp32_audio_kit/board_peripherals.py" + ], + [ + "es8388.py", + "github:PyDevices/omnipython/drivers/codec/es8388.py" + ], + [ + "keypad_gpio.py", + "github:PyDevices/omnipython/drivers/input/keypad_gpio.py" ], [ "ili9341.py", @@ -15,10 +23,6 @@ [ "ft6x36.py", "github:PyDevices/omnipython/drivers/touch/ft6x36.py" - ], - [ - "es8388.py", - "github:PyDevices/omnipython/drivers/codec/es8388.py" ] ], "deps": [ @@ -27,7 +31,7 @@ "latest" ] ], - "version": "0.1", + "version": "0.2", "description": "Ai-Thinker ESP32-Audio-Kit V2.2 with a 2.8\" ILI9341 IPS touch module - MicroPython", "generated": "from manifest.py by tools/libbuild.py installers; edit manifest.py, not this" } diff --git a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_config.py b/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_config.py index df6788aa..4645c9be 100644 --- a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_config.py +++ b/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_config.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: MIT -"""Adafruit 3.5" TFT FeatherWing (HX8357D) + STMPE610 on an Unexpected Maker Feather ESP32 V2 +"""Adafruit 3.5" TFT FeatherWing (HX8357D) + STMPE610 on an Adafruit ESP32 Feather V2 The HX8357D takes the ILI9341 driver's init unchanged; only the size differs: 320x480 native, shown as 480x320 landscape. Pins are the Feather ESP32 V2's GPIO diff --git a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_peripherals.py b/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_peripherals.py deleted file mode 100644 index 34f87d62..00000000 --- a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_peripherals.py +++ /dev/null @@ -1,21 +0,0 @@ -# SPDX-FileCopyrightText: 2026 Brad Barnett -# -# SPDX-License-Identifier: MIT - -"""Lazy constructors for the 3.5" TFT FeatherWing on a Feather ESP32 V2. PERIPHERALS = lazy roles only.""" -import boarddev -import sys - -PERIPHERALS = frozenset({"i2c"}) - - -def load_peripherals(ns): - boarddev.bind_lazy(ns, sys.modules[__name__]) - - -def i2c(): - """The Feather ESP32 V2's STEMMA QT / I2C: SDA GPIO22, SCL GPIO20 (power on GPIO2).""" - from machine import I2C, Pin - - Pin(2, Pin.OUT, value=1) - return I2C(0, sda=Pin(22), scl=Pin(20), freq=400_000) diff --git a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/manifest.py b/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/manifest.py index 154a69e4..07179f08 100644 --- a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/manifest.py +++ b/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/manifest.py @@ -4,13 +4,13 @@ # The pitft_hx8357_featherwing_on_feather_esp32_v2 board package: what mip.install("pitft_hx8357_featherwing_on_feather_esp32_v2") brings. metadata( - description="Adafruit 3.5\" TFT FeatherWing (HX8357D) + STMPE610 on an Unexpected Maker Feather ESP32 V2", - version="0.1", + description="Adafruit 3.5\" TFT FeatherWing (HX8357D) + STMPE610 on an Adafruit ESP32 Feather V2", + version="0.2", ) require("omnipython") +require("adafruit_feather_esp32_v2") require("ili9341") require("stmpe610") module("board_config.py") -module("board_peripherals.py") diff --git a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/package.json b/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/package.json index 90a6aa12..8d9d7621 100644 --- a/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/package.json +++ b/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/package.json @@ -6,7 +6,15 @@ ], [ "board_peripherals.py", - "github:PyDevices/omnipython/board_configs/busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2/board_peripherals.py" + "github:PyDevices/omnipython/board_configs/nodisplay/adafruit_feather_esp32_v2/board_peripherals.py" + ], + [ + "battery_adc.py", + "github:PyDevices/omnipython/drivers/power/battery_adc.py" + ], + [ + "keypad_gpio.py", + "github:PyDevices/omnipython/drivers/input/keypad_gpio.py" ], [ "ili9341.py", @@ -23,7 +31,7 @@ "latest" ] ], - "version": "0.1", - "description": "Adafruit 3.5\" TFT FeatherWing (HX8357D) + STMPE610 on an Unexpected Maker Feather ESP32 V2", + "version": "0.2", + "description": "Adafruit 3.5\" TFT FeatherWing (HX8357D) + STMPE610 on an Adafruit ESP32 Feather V2", "generated": "from manifest.py by tools/libbuild.py installers; edit manifest.py, not this" } diff --git a/board_configs/nodisplay/adafruit_feather_esp32_v2/board_peripherals.py b/board_configs/nodisplay/adafruit_feather_esp32_v2/board_peripherals.py new file mode 100644 index 00000000..1615a718 --- /dev/null +++ b/board_configs/nodisplay/adafruit_feather_esp32_v2/board_peripherals.py @@ -0,0 +1,119 @@ +# SPDX-FileCopyrightText: 2026 Brad Barnett +# +# SPDX-License-Identifier: MIT + +"""Lazy roles for the Adafruit ESP32 Feather V2. PERIPHERALS = lazy roles only. + +The Feather V2 is a classic ESP32 (ESP32-PICO-MINI-02) with 8 MB of flash, +2 MB of PSRAM, a USB-C port through a CH9102, and a LiPo charger. Pins are +from Adafruit's pinout: + + NeoPixel GPIO0, powered through GPIO2 + STEMMA QT / I2C SDA GPIO22, SCL GPIO20, powered through GPIO2 + red LED GPIO13, high = on + button SW38 GPIO38, input only, pulled up on the board: low + when pressed + battery monitor GPIO35, through a divider of two 200K resistors + reset button the chip's enable line; no GPIO + +GPIO2 (``NEOPIXEL_I2C_POWER``) switches the regulator for both the +NeoPixel and the STEMMA QT connector's 3V3, so ``pixels`` and ``i2c`` each +drive it high. GPIO12 is a boot strap that must be low at reset. + +It has no display. Install the ``remote-display`` board config beside this +package for a screen in a web browser, or a display's own board config +when one is fitted: the 3.5" TFT FeatherWing has +``pitft_hx8357_featherwing_on_feather_esp32_v2``, which brings this +package too. + +It has no audio output of its own, so there is no ``audio_out`` or ``bt`` +receiver role: an I2S amplifier on its pins brings its own. + +Checked on a board: a ``RemoteDisplay`` at 480x320 as its board config. +Not checked yet: each role below on the board, the button and LED by hand, +and the battery reading against a meter. +""" + +import sys + +import boarddev + +PERIPHERALS = frozenset({"pixels", "led", "i2c", "battery", "wlan", "ble"}) + +_PIXEL = 0 +_POWER = 2 # NEOPIXEL_I2C_POWER +_LED = 13 +_BUTTON = 38 +_BATTERY = 35 +_SDA = 22 +_SCL = 20 + + +def load_peripherals(ns): + boarddev.bind_lazy(ns, sys.modules[__name__]) + + +def _power_on(): + from machine import Pin + + Pin(_POWER, Pin.OUT, value=1) + + +def pixels(): + """The NeoPixel, as a one-pixel ``neopixel.NeoPixel``.""" + from machine import Pin + from neopixel import NeoPixel + + _power_on() + return NeoPixel(Pin(_PIXEL, Pin.OUT), 1) + + +def led(): + """The red LED on GPIO13, a ``machine.Pin``: ``led(1)`` turns it on.""" + from machine import Pin + + return Pin(_LED, Pin.OUT, value=0) + + +def i2c(): + """The STEMMA QT connector's I2C, at 400 kHz, with its power switched on.""" + from machine import I2C, Pin + + _power_on() + return I2C(0, sda=Pin(_SDA), scl=Pin(_SCL), freq=400_000) + + +def battery(): + """The LiPo's voltage, through the divider on GPIO35 (``voltage`` in volts).""" + from battery_adc import BatteryADC + + return BatteryADC(_BATTERY, scale=2.0) + + +def keypad(): + """SW38 as the Enter key, for a board config to give the app as ``keypad``.""" + import keys + from keypad_gpio import GPIOButtons + from machine import Pin + + # GPIO38 has no internal pull-up; the board's own resistor holds it high. + return GPIOButtons({"sw38": (Pin(_BUTTON, Pin.IN), keys.K_RETURN)}) + + +def wlan(): + import network + + return network.WLAN(network.STA_IF) + + +def ble(): + # A bledev adapter (docs/guides/bluetooth-le.md). It also answers every + # bluetooth.BLE method, so code written for the raw radio keeps working. + # Firmware built with btclassic has no BLE: one Bluetooth host at a time. + try: + import bledev.mpble + except ImportError: + import bluetooth + + return bluetooth.BLE() + return bledev.mpble.get() diff --git a/board_configs/nodisplay/adafruit_feather_esp32_v2/manifest.py b/board_configs/nodisplay/adafruit_feather_esp32_v2/manifest.py new file mode 100644 index 00000000..728bd421 --- /dev/null +++ b/board_configs/nodisplay/adafruit_feather_esp32_v2/manifest.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2026 Brad Barnett +# +# SPDX-License-Identifier: MIT + +# The adafruit_feather_esp32_v2 board package: what mip.install("adafruit_feather_esp32_v2") brings. +metadata( + description="board_peripherals for the Adafruit ESP32 Feather V2, on MicroPython", + version="0.1.0", +) + +require("omnipython") +require("battery_adc") +require("keypad_gpio") + +module("board_peripherals.py") diff --git a/board_configs/nodisplay/adafruit_feather_esp32_v2/package.json b/board_configs/nodisplay/adafruit_feather_esp32_v2/package.json new file mode 100644 index 00000000..4027843c --- /dev/null +++ b/board_configs/nodisplay/adafruit_feather_esp32_v2/package.json @@ -0,0 +1,25 @@ +{ + "urls": [ + [ + "board_peripherals.py", + "github:PyDevices/omnipython/board_configs/nodisplay/adafruit_feather_esp32_v2/board_peripherals.py" + ], + [ + "battery_adc.py", + "github:PyDevices/omnipython/drivers/power/battery_adc.py" + ], + [ + "keypad_gpio.py", + "github:PyDevices/omnipython/drivers/input/keypad_gpio.py" + ] + ], + "deps": [ + [ + "omnipython", + "latest" + ] + ], + "version": "0.1.0", + "description": "board_peripherals for the Adafruit ESP32 Feather V2, on MicroPython", + "generated": "from manifest.py by tools/libbuild.py installers; edit manifest.py, not this" +} diff --git a/board_configs/nodisplay/esp32-p4-wifi6-dev-kit/board_peripherals.py b/board_configs/nodisplay/esp32-p4-wifi6-dev-kit/board_peripherals.py index 9039ade4..beb0e40a 100644 --- a/board_configs/nodisplay/esp32-p4-wifi6-dev-kit/board_peripherals.py +++ b/board_configs/nodisplay/esp32-p4-wifi6-dev-kit/board_peripherals.py @@ -4,9 +4,11 @@ """board_peripherals for the Waveshare ESP32-P4-WIFI6-DEV-KIT, on MicroPython. -Headless, so there is no board_config.py; an app imports board_peripherals -directly. A display on the DSI connector brings its own board_config (see -fbdisplay/esp32-p4-wifi6-dev-kit_kedei-5in-dsi), which loads this file. +Headless: an app imports board_peripherals directly, or the +``remote-display`` board config installed beside it gives the board a +screen in a web browser. A display on the DSI connector brings its own +board_config instead (see fbdisplay/esp32-p4-wifi6-dev-kit_kedei-5in-dsi), +which loads this file. PERIPHERALS = lazy roles only: nothing is constructed until it is asked for. What the board carries, from Waveshare's schematic (ESP32-P4-WIFI6-DEV-KIT diff --git a/board_configs/nodisplay/esp32-s31-zero/board_peripherals.py b/board_configs/nodisplay/esp32-s31-zero/board_peripherals.py index 9104e763..93680798 100644 --- a/board_configs/nodisplay/esp32-s31-zero/board_peripherals.py +++ b/board_configs/nodisplay/esp32-s31-zero/board_peripherals.py @@ -6,8 +6,9 @@ The Zero is an ESP32-S31 with 32 MB of flash and 16 MB of PSRAM, a USB-C port, two buttons, an RGB LED, 18 edge pads and a 40-pin FPC connector. -Pins are from Waveshare's schematic. It has no display of its own, so there -is no ``board_config.py``: import this module. +Pins are from Waveshare's schematic. It has no display of its own: import this +module, or install the ``remote-display`` board config beside it for a +screen in a web browser. RGB LED WS2812B on GPIO60, through a level shifter to 5 V BOOT button GPIO61, low while pressed (a boot strap at reset) diff --git a/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/board_peripherals.py b/board_configs/nodisplay/esp32_audio_kit/board_peripherals.py similarity index 85% rename from board_configs/busdisplay/spi/ili9341_esp32_audio_kit/board_peripherals.py rename to board_configs/nodisplay/esp32_audio_kit/board_peripherals.py index a093d633..856a9f62 100644 --- a/board_configs/busdisplay/spi/ili9341_esp32_audio_kit/board_peripherals.py +++ b/board_configs/nodisplay/esp32_audio_kit/board_peripherals.py @@ -14,6 +14,28 @@ Many of these kits ship with the microphones' two coupling capacitors on the wrong pads, and their microphones record only noise until those are moved. The line-in jack works either way. + +The kit's own buttons and LED, from its schematic and Espressif's board +definition: + + KEY1-KEY6 IO36, IO13, IO19, IO23, IO18, IO5, each low while + pressed; ``keypad()`` gives them as the keys 1 to 6 + green LED D4 IO22 + headphone detect IO39 + +KEY2 (IO13) is the microSD card's D3, so it works only while the card runs +1-bit and DIP switch 1 is on. KEY3 to KEY6 and the LED are on the 2x7 +header, so a display wired there takes them: the ILI9341 module's board +config uses IO5, IO18, IO19, IO22 and IO23. + +It has no display. Install the ``remote-display`` board config beside this +package for a screen in a web browser, or the 2.8" ILI9341 module's +``ili9341_esp32_audio_kit``, which brings this package too. + +Checked on a board, with the ILI9341 module fitted: ``audio_out`` and +``pcm_out`` on the headphone output, ``pcm_in`` from the line-in jack, and +``bt`` playing a phone's music. Not checked yet: ``keypad()``, ``led`` and +``sdcard``. """ import sys @@ -39,6 +61,7 @@ "pcm_out", "pcm_in", "audio_power", + "led", "sdcard", "wlan", "bt", @@ -57,6 +80,8 @@ _DOUT = 26 _DIN = 35 # the ES8388's ADC output _AMP = 21 # NS4150B enable, high = on +_LED = 22 # the green LED, D4 +_KEYS = (36, 13, 19, 23, 18, 5) # KEY1 to KEY6 # The codec's I2C: a port of its own, inside the A1S module. _CODEC_I2C_PORT = 1 @@ -317,7 +342,8 @@ def _audio_power(enable=True, *, volume=None): def sdcard(): """The kit's microSD slot in 1-bit mode (CLK IO14, CMD IO15, D0 IO2). - It has to stay 1-bit: IO12, the 4-bit D2, is the display's chip select. + It stays 1-bit: IO12, the 4-bit D2, is a boot strap, and the ILI9341 + module's chip select. CMD reaches IO15 through DIP switch 3, which must be on. """ from machine import SDCard @@ -325,6 +351,28 @@ def sdcard(): return SDCard(slot=1, width=1) +def led(): + """The green LED D4 on IO22, a ``machine.Pin``.""" + from machine import Pin + + return Pin(_LED, Pin.OUT, value=0) + + +def keypad(): + """KEY1 to KEY6 as the keys 1 to 6, for a board config to give the app as ``keypad``.""" + import keys + from keypad_gpio import GPIOButtons + from machine import Pin + + codes = (keys.K_1, keys.K_2, keys.K_3, keys.K_4, keys.K_5, keys.K_6) + mapping = {} + for n, (gpio, code) in enumerate(zip(_KEYS, codes)): + # IO36 is input only, with no internal pull-up: the kit's resistor holds it. + pull = None if gpio == 36 else Pin.PULL_UP + mapping["key%d" % (n + 1)] = (Pin(gpio, Pin.IN, pull), code) + return GPIOButtons(mapping) + + def wlan(): import network diff --git a/board_configs/nodisplay/esp32_audio_kit/manifest.py b/board_configs/nodisplay/esp32_audio_kit/manifest.py new file mode 100644 index 00000000..8ce24256 --- /dev/null +++ b/board_configs/nodisplay/esp32_audio_kit/manifest.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2026 Brad Barnett +# +# SPDX-License-Identifier: MIT + +# The esp32_audio_kit board package: what mip.install("esp32_audio_kit") brings. +metadata( + description="board_peripherals for the Ai-Thinker ESP32-Audio-Kit V2.2 (ESP32-A1S, ES8388), on MicroPython", + version="0.1.0", +) + +require("omnipython") +require("es8388") +require("keypad_gpio") + +module("board_peripherals.py") diff --git a/board_configs/nodisplay/esp32_audio_kit/package.json b/board_configs/nodisplay/esp32_audio_kit/package.json new file mode 100644 index 00000000..f7fe979d --- /dev/null +++ b/board_configs/nodisplay/esp32_audio_kit/package.json @@ -0,0 +1,25 @@ +{ + "urls": [ + [ + "board_peripherals.py", + "github:PyDevices/omnipython/board_configs/nodisplay/esp32_audio_kit/board_peripherals.py" + ], + [ + "es8388.py", + "github:PyDevices/omnipython/drivers/codec/es8388.py" + ], + [ + "keypad_gpio.py", + "github:PyDevices/omnipython/drivers/input/keypad_gpio.py" + ] + ], + "deps": [ + [ + "omnipython", + "latest" + ] + ], + "version": "0.1.0", + "description": "board_peripherals for the Ai-Thinker ESP32-Audio-Kit V2.2 (ESP32-A1S, ES8388), on MicroPython", + "generated": "from manifest.py by tools/libbuild.py installers; edit manifest.py, not this" +} diff --git a/board_configs/nodisplay/qtpy_esp32_pico_audio_bff/board_peripherals.py b/board_configs/nodisplay/qtpy_esp32_pico_audio_bff/board_peripherals.py index 53d3766d..6e87e006 100644 --- a/board_configs/nodisplay/qtpy_esp32_pico_audio_bff/board_peripherals.py +++ b/board_configs/nodisplay/qtpy_esp32_pico_audio_bff/board_peripherals.py @@ -28,7 +28,8 @@ every other board_configs/ category is named for a display technology, and a board that is only an audio peripheral fits none of them. There is no board_config.py here either -- nothing eager to construct. A non-graphics app -imports board_peripherals directly, which is the whole point of the idiom. +imports board_peripherals directly; for a screen in a web browser, install +the ``remote-display`` board config beside this package. The amplifier is a MAX98357A: no codec, no I2C, no register set, no MCLK. It takes its clock from BCLK, which is why rates are continuous here rather than diff --git a/board_configs/nodisplay/remote-display/board_config.py b/board_configs/nodisplay/remote-display/board_config.py new file mode 100644 index 00000000..fd5d0af1 --- /dev/null +++ b/board_configs/nodisplay/remote-display/board_config.py @@ -0,0 +1,71 @@ +# SPDX-FileCopyrightText: 2026 Brad Barnett +# +# SPDX-License-Identifier: MIT + +"""Give a board with no screen one in a web browser: the same config for every board. + +The display is a `RemoteDisplay `, +480x320, served at ``http:///``. Apps draw on it and +read the browser's clicks and keys as they would a panel and its touch. It +names no pins, so one copy suits any board with a network and the RAM for +the frame (``width * height * 2`` bytes, 300 KB at 480x320). + +Install it beside your board's own ``board_peripherals`` package, which +brings the audio, buttons, LEDs and radios. When you fit a real display +later, install that display's board config instead: it replaces this +``board_config.py``, and your apps stay as they are. + +The browser asks for your WebREPL password (``webrepl_cfg.PASS``) before +it shows or takes input. Set these environment variables before the first +``import board_config`` to change the defaults: + + OMNIPYTHON_WIDTH width in pixels, 480 + OMNIPYTHON_HEIGHT height in pixels, 320 + OMNIPYTHON_REMOTE_PORT the page's TCP port, 80 + OMNIPYTHON_REMOTE_PASSWORD a password other than WebREPL's + +There is no default without a password: with neither set, the import +raises, so the display is never left open to everyone on the network. + +A board's buttons become ``keypad`` when its ``board_peripherals`` has a +``keypad()`` function. The board's Wi-Fi has to be up before a browser can +reach the page; the display works without it. +""" + +import board_peripherals +from boarddev import env_get, env_int +from displaydev.remotedisplay import RemoteDisplay + + +def _password(): + password = env_get("OMNIPYTHON_REMOTE_PASSWORD") + if password: + return password + try: + import webrepl_cfg + except ImportError: + raise ImportError( + "board_config: no password for the browser display; run webrepl_setup or set OMNIPYTHON_REMOTE_PASSWORD" + ) from None + return webrepl_cfg.PASS + + +display_drv = RemoteDisplay( + env_int("OMNIPYTHON_WIDTH", 480), + env_int("OMNIPYTHON_HEIGHT", 320), + port=env_int("OMNIPYTHON_REMOTE_PORT", 80), + password=_password(), +) +host_read = display_drv.get_events + +# Buttons are UI, so they're built here, where a board with a panel builds +# its own; the board's package only says which pins they're on. +if hasattr(board_peripherals, "keypad"): + keypad = board_peripherals.keypad() + keypad_read = keypad.read + +display_drv.fill(0) + +from board_peripherals import PERIPHERALS, load_peripherals # noqa: E402, F401 (re-exported for apps) + +load_peripherals(globals()) diff --git a/board_configs/nodisplay/remote-display/manifest.py b/board_configs/nodisplay/remote-display/manifest.py new file mode 100644 index 00000000..8ca425fa --- /dev/null +++ b/board_configs/nodisplay/remote-display/manifest.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2026 Brad Barnett +# +# SPDX-License-Identifier: MIT + +# The remote-display board package: what mip.install("remote-display") brings. +# It has no board_peripherals: each board's own package brings that. +metadata( + description="board_config for any board with no display: a RemoteDisplay in a web browser, on MicroPython", + version="0.1.0", +) + +require("omnipython") + +module("board_config.py") diff --git a/board_configs/nodisplay/remote-display/package.json b/board_configs/nodisplay/remote-display/package.json new file mode 100644 index 00000000..579e4fb3 --- /dev/null +++ b/board_configs/nodisplay/remote-display/package.json @@ -0,0 +1,17 @@ +{ + "urls": [ + [ + "board_config.py", + "github:PyDevices/omnipython/board_configs/nodisplay/remote-display/board_config.py" + ] + ], + "deps": [ + [ + "omnipython", + "latest" + ] + ], + "version": "0.1.0", + "description": "board_config for any board with no display: a RemoteDisplay in a web browser, on MicroPython", + "generated": "from manifest.py by tools/libbuild.py installers; edit manifest.py, not this" +} diff --git a/docs/boards/board-configs.md b/docs/boards/board-configs.md index bbf9e372..fb385426 100644 --- a/docs/boards/board-configs.md +++ b/docs/boards/board-configs.md @@ -114,7 +114,7 @@ and `omnipython`; its `manifest.py` lists them. | ESP32-WROVER-E ST7789 + joystick | `busdisplay/spi/esp32_wrover_e_st7789_joystick` | | | `joystick` | `wlan` | | Adafruit FunHouse (no BLE on ESP32-S2) | `busdisplay/spi/funhouse` | yes | | `touch`, `keypad` | `temperature`, `humidity`, `pressure`, `light`, `motion`, `pixels`, `audio_out`, `wlan` | | Adafruit HalloWing M4 | `busdisplay/spi/hallowing_m4` | yes | | — | `pixels`, `accelerometer`, `audio_out`, `i2c` | -| Ai-Thinker ESP32-Audio-Kit V2.2 + 2.8" ILI9341 IPS touch module | `busdisplay/spi/ili9341_esp32_audio_kit` | | | | | +| Ai-Thinker ESP32-Audio-Kit V2.2 + 2.8" ILI9341 IPS touch module | `busdisplay/spi/ili9341_esp32_audio_kit` | | 240×320 ILI9341; touch FT6336G (`ft6x36`) | `touch` | from the `nodisplay/esp32_audio_kit` package | | Adafruit QT Py ESP32 Pico + EyeSPI ILI9341 | `busdisplay/spi/ili9341_eyespi_qtpy_esp32` | | | | | | Adafruit ESP32-S3 QT Py + EyeSPI ILI9341 | `busdisplay/spi/ili9341_eyespi_qtpy_esp32s3` | | | | | | QT Py RP2040 + EyeSPI ILI9341 | `busdisplay/spi/ili9341_eyespi_qtpy_rp2040` | | | | | @@ -126,7 +126,7 @@ and `omnipython`; its `manifest.py` lists them. | Pico LCD 1.8" | `busdisplay/spi/pico-lcd-1.8` | | | | | | Waveshare Pico-OLED-2.23 and Pico-Audio on a Pico | `busdisplay/spi/pico-oled-2.23-audio` | | 128×32, SSD1305 SPI | | `audio_out`, `pcm_out`, `audio_power` | | 3.5" TFT FeatherWing (HX8357D) (host-dependent STEMMA) | `busdisplay/spi/pitft_hx8357_featherwing` | yes | | `touch` | `i2c` | -| 3.5" TFT FeatherWing, HX8357D + STMPE610 on an Adafruit Feather ESP32 V2 | `busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2` | | | | | +| 3.5" TFT FeatherWing, HX8357D + STMPE610 on an Adafruit Feather ESP32 V2 | `busdisplay/spi/pitft_hx8357_featherwing_on_feather_esp32_v2` | | | | from the `nodisplay/adafruit_feather_esp32_v2` package | | PiTFT ILI9341 FeatherWing (host-dependent STEMMA) | `busdisplay/spi/pitft_ili9341_featherwing` | yes | | `touch` | `i2c` | | Adafruit PyBadge | `busdisplay/spi/pybadge` | yes | | `keypad` | `pixels`, `accelerometer`, `audio_out`, `i2c` | | Adafruit PyGamer | `busdisplay/spi/pygamer` | yes | | `joystick`, `keypad` | `pixels`, `accelerometer`, `sdcard`, `battery`, `audio_out`, `i2c` | @@ -205,12 +205,21 @@ and `omnipython`; its `manifest.py` lists them. ### Headless boards -A board with no display has no `board_config.py`, because there's nothing to -construct up front; an app imports `board_peripherals` directly, and an app -that also runs with a display treats `board_config` as optional. +A board with no display ships only its `board_peripherals` package. An app +that needs no screen imports `board_peripherals` directly. For a screen in a +web browser, install `nodisplay/remote-display` beside it: one +`board_config.py` for every headless board, a 480x320 +[`RemoteDisplay`](../guides/show-a-display-in-a-browser.md) that asks for the +WebREPL password and builds the board's buttons into `keypad` when its +package has a `keypad()`. A board that later gets a real display installs +that display's board config instead, and keeps its apps. | Directory | Board | |-----------|-------| +| `nodisplay/remote-display` | any board with a network: the board config, with no pins (MicroPython; `display_drv` in a browser, `host_read`, `keypad` from the board's package) | +| `nodisplay/adafruit_feather_esp32_v2` | Adafruit ESP32 Feather V2 (MicroPython; `pixels`, `led`, `i2c`, `battery`, `wlan`, `ble`; SW38 as `keypad()`) | +| `nodisplay/esp32_audio_kit` | Ai-Thinker ESP32-Audio-Kit V2.2, ES8388 (MicroPython; `audio_out`, `pcm_out`, `pcm_in`, `audio_power`, `led`, `sdcard`, `wlan`, `bt`, `ble`; KEY1-KEY6 as `keypad()`) | +| `nodisplay/esp32-p4-wifi6-dev-kit` | Waveshare ESP32-P4-WIFI6-DEV-KIT (MicroPython; `audio_out`, `pcm_out`, `pcm_in`, `audio_power`, `i2c`, `sdcard`, `camera`, `ethernet`, `radio`, `wlan`, `ble`, `boot_button`, `usb_device`) | | `nodisplay/qtpy_esp32_pico_audio_bff` | QT Py ESP32 Pico + Adafruit Audio BFF (MicroPython; `audio_out` on I2S, `boot_button`) | | `nodisplay/esp32-s31-zero` | Waveshare ESP32-S31-Zero (MicroPython; `pixels`, `boot_button`, `wlan`, `ble`) | | `cp/nodisplay/qtpy_esp32_pico_audio_bff` | the same, on CircuitPython (`audio_out` is `audiobusio.I2SOut`) | diff --git a/docs/boards/board-contract.md b/docs/boards/board-contract.md index 76958579..6e63a05c 100644 --- a/docs/boards/board-contract.md +++ b/docs/boards/board-contract.md @@ -195,10 +195,18 @@ for a role that is constructed, such as `sdcard`. ## Boards with no display [`board_configs/nodisplay/`](https://github.com/PyDevices/omnipython/tree/main/board_configs/nodisplay) holds boards that are only peripherals — an audio -DAC or amplifier on a QT Py, say. They ship a `board_peripherals.py` and **no -`board_config.py`**, because there is nothing eager to construct. Apps import -`board_peripherals` directly, which is the non-graphics idiom with nothing -else in the way. +DAC or amplifier on a QT Py, say. Each ships a `board_peripherals.py` and **no +`board_config.py`**, because there is nothing eager to construct. Apps that +need no screen import `board_peripherals` directly, which is the non-graphics +idiom with nothing else in the way. + +`nodisplay/remote-display` is the one `board_config.py` for all of them: a +`RemoteDisplay` in a web browser, with no pins. It ends like every other +config, binding the board's `board_peripherals`, and it builds `keypad` from +the board's buttons when that module has a `keypad()` function returning a +`keypad_gpio.GPIOButtons` or anything with `read()`. A board's package keeps +its buttons there, not in `PERIPHERALS`, because a display wired to the +same header may need the pins; a display's own config can call it too. Every other category is named for a display technology (`busdisplay`, `fbdisplay`, `pixeldisplay`, …), so `nodisplay` is where a board with no diff --git a/docs/guides/show-a-display-in-a-browser.md b/docs/guides/show-a-display-in-a-browser.md index e748716d..02aaa53d 100644 --- a/docs/guides/show-a-display-in-a-browser.md +++ b/docs/guides/show-a-display-in-a-browser.md @@ -14,7 +14,25 @@ With a password set, the page asks for it before it shows anything. ## A board with no screen -In the board's `board_config.py`: +Install the `remote-display` board config beside your board's own package. +It is the same for every board, a 480x320 `RemoteDisplay` that asks for your +WebREPL password, so a board with no screen of its own needs nothing else: + +```python +import mip + +mip.install("github:PyDevices/omnipython/board_configs/nodisplay/remote-display") +mip.install("github:PyDevices/omnipython/board_configs/nodisplay/esp32-s31-zero") +``` + +[Boards with no display](../boards/board-configs.md#headless-boards) lists the +boards' own packages. To change the size, the port or the password, set +`OMNIPYTHON_WIDTH`, `OMNIPYTHON_HEIGHT`, `OMNIPYTHON_REMOTE_PORT` or +`OMNIPYTHON_REMOTE_PASSWORD` before the first `import board_config`. When you +fit a real display, install its board config: it replaces this one, and your +apps stay. + +To write your own instead, in the board's `board_config.py`: ```python from displaydev.remotedisplay import RemoteDisplay diff --git a/tests/test_remote_display_config.py b/tests/test_remote_display_config.py new file mode 100644 index 00000000..a38b1e35 --- /dev/null +++ b/tests/test_remote_display_config.py @@ -0,0 +1,150 @@ +# SPDX-FileCopyrightText: 2026 Brad Barnett +# +# SPDX-License-Identifier: MIT + +"""The remote-display board config: a RemoteDisplay beside any board's peripherals.""" + +import importlib.util +import os +from pathlib import Path +import sys +import types +import unittest +from unittest import mock + +_TESTS = Path(__file__).resolve().parent +if str(_TESTS) not in sys.path: + sys.path.insert(0, str(_TESTS)) +import _env # noqa: E402, F401 (lib/ and drivers/ on the path) + +import boarddev # noqa: E402 + +ROOT = _env.ROOT +CONFIG = ROOT / "board_configs" / "nodisplay" / "remote-display" / "board_config.py" +NODISPLAY = ROOT / "board_configs" / "nodisplay" +if str(ROOT / "drivers" / "input") not in sys.path: + sys.path.insert(0, str(ROOT / "drivers" / "input")) # keypad_gpio + + +class _Pin: + def __init__(self, level=1): + self.level = level + + def value(self): + return self.level + + +def _peripherals(with_keypad): + mod = types.ModuleType("board_peripherals") + mod.PERIPHERALS = frozenset({"thing"}) + mod.thing = lambda: "made" + mod.pin = _Pin() + + def load_peripherals(ns): + boarddev.bind_lazy(ns, mod) + + mod.load_peripherals = load_peripherals + if with_keypad: + + def keypad(): + import keys + from keypad_gpio import GPIOButtons + + return GPIOButtons({"a": (mod.pin, keys.K_RETURN)}) + + mod.keypad = keypad + return mod + + +class RemoteDisplayConfigTests(unittest.TestCase): + def setUp(self): + self.made = [] + test = self + + class FakeRemoteDisplay: + def __init__(self, width, height, port=80, *, password=None): + self.width, self.height, self.port, self.password = width, height, port, password + test.made.append(self) + + def get_events(self): + return [] + + def fill(self, color): + pass + + remote = types.ModuleType("displaydev.remotedisplay") + remote.RemoteDisplay = FakeRemoteDisplay + self.modules = {"displaydev.remotedisplay": remote} + # env_set writes os.environ too: give each test its own copy. + names = ("OMNIPYTHON_REMOTE_PASSWORD", "OMNIPYTHON_WIDTH", "OMNIPYTHON_HEIGHT", "OMNIPYTHON_REMOTE_PORT") + environ = mock.patch.dict(os.environ) + environ.start() + self.addCleanup(environ.stop) + for name in names: + os.environ.pop(name, None) + boarddev._overrides.pop(name, None) + self.addCleanup(boarddev._overrides.pop, name, None) + + def _load(self, peripherals, webrepl_pass=None): + modules = dict(self.modules) + modules["board_peripherals"] = peripherals + if webrepl_pass is None: + modules["webrepl_cfg"] = None # an import of it raises ImportError + else: + modules["webrepl_cfg"] = types.SimpleNamespace(PASS=webrepl_pass) + with mock.patch.dict(sys.modules, modules): + spec = importlib.util.spec_from_file_location("board_config", CONFIG) + config = importlib.util.module_from_spec(spec) + spec.loader.exec_module(config) + return config + + def test_defaults_and_webrepl_password(self): + config = self._load(_peripherals(False), webrepl_pass="secret") + display = config.display_drv + self.assertEqual((display.width, display.height, display.port), (480, 320, 80)) + self.assertEqual(display.password, "secret") + self.assertEqual(config.host_read(), []) + self.assertFalse(hasattr(config, "keypad")) + + def test_board_peripherals_bind(self): + config = self._load(_peripherals(False), webrepl_pass="secret") + self.assertEqual(config.PERIPHERALS, frozenset({"thing"})) + self.assertEqual(config.thing, "made") + + def test_environment_overrides(self): + boarddev.env_set("OMNIPYTHON_REMOTE_PASSWORD", "other") + boarddev.env_set("OMNIPYTHON_WIDTH", 320) + boarddev.env_set("OMNIPYTHON_HEIGHT", 240) + boarddev.env_set("OMNIPYTHON_REMOTE_PORT", 8080) + display = self._load(_peripherals(False)).display_drv + self.assertEqual((display.width, display.height, display.port), (320, 240, 8080)) + self.assertEqual(display.password, "other") + + def test_no_password_refuses(self): + with self.assertRaises(ImportError) as caught: + self._load(_peripherals(False)) + self.assertIn("OMNIPYTHON_REMOTE_PASSWORD", str(caught.exception)) + self.assertEqual(self.made, []) + + def test_board_buttons_become_keypad(self): + import keys + + peripherals = _peripherals(True) + config = self._load(peripherals, webrepl_pass="secret") + self.assertEqual(config.keypad_read(), []) + peripherals.pin.level = 0 + self.assertEqual(config.keypad_read(), [keys.K_RETURN]) + + def test_every_headless_board_has_peripherals_only(self): + # A headless board's package must not bring a board_config.py: that + # would overwrite this one, or a display's, when both are installed. + for folder in sorted(NODISPLAY.iterdir()): + if folder.name == "remote-display" or not (folder / "manifest.py").is_file(): + continue + with self.subTest(board=folder.name): + self.assertTrue((folder / "board_peripherals.py").is_file()) + self.assertFalse((folder / "board_config.py").exists()) + + +if __name__ == "__main__": + unittest.main()