hub
Board-provided hub module.
Exposes the on-device peripherals: LPF2 ports (hub.ports), hub LED, IMU (hub.imu), buttons, LCD (LVGL), status log and power-off. Objects here are singletons created by the C firmware — this module is a stub; the real implementation lives in the ESP32 port.
Attributes
Built-in accelerometer wrapped as a Devices.accelerometer. |
|
Raw-PCM audio player via NS4168 I2S amp (see |
|
Battery voltage + charging status (see |
|
Board-specific constants (see |
|
Button API (see |
|
Built-in gyroscope wrapped as a Devices.gyroscope. |
|
Shared internal I2C bus (Grove + on-board devices). See |
|
Fused IMU (see |
|
LCD + LVGL control (see |
|
Built-in hub RGB LED. |
|
Firmware log control. |
|
Hub ports (see |
|
On-board PCA9685 PWM driver (see |
|
MJPEG-in-AVI video player (see |
Functions
|
Exit the running user script cleanly. Raises SystemExit. |
|
Flush any buffered framed stdout data as a #FR:OUT frame. |
|
Register a callback for a firmware event. Currently only |
|
Turn the hub off immediately. Does not return. |
|
Write bytes to stdout bypassing the framing wrapper. Returns bytes written. |
|
Return the mounted |
|
Unmount the cached SD card handle and re-mount the SD card at |
|
Register a callback that mirrors framed and raw stdout bytes elsewhere. |
|
Enable/disable C-level stdout framing (#FR:OUT <len>n<bytes>). |
|
Enable or disable USB Mass Storage Class (SD card). |
|
Return |
Module Contents
- hub.exit() NoReturn[source]
Exit the running user script cleanly. Raises SystemExit.
The program runner catches SystemExit and shows the “Done” screen. Safe to call from anywhere — button callbacks, loops, top-level code.
- hub.on(name: _PollName) Callable[[_PollFn], _PollFn][source]
- hub.on(name: _PollName, fn: _PollFn) _PollFn
Register a callback for a firmware event. Currently only
"poll"is supported."poll"callbacks are scheduled on mp_task viamp_sched_scheduleevery ~20 ms by the C firmware loop. They run even while a user script is executing.
- hub.powerOff() NoReturn[source]
Turn the hub off immediately. Does not return.
If the hardware power latch does not hold (e.g. USB power is present), the firmware performs an orderly shutdown: disables LPF2 ports and motor PWM outputs, turns off the LCD backlight, deinitialises BLE and WiFi, signals the MicroPython task to exit (GC runs before the task deletes itself), throttles the CPU to 80 MHz, then enters a low-activity loop that keeps the battery status LED updated. Pressing the right button restarts the firmware.
- hub.raw_write(buf: bytes) int[source]
Write bytes to stdout bypassing the framing wrapper. Returns bytes written.
Flushes any pending framed output first so raw bytes never interleave inside a framed payload.
- hub.sd_card() machine.SDCard | None[source]
Return the mounted
machine.SDCardinstance, orNoneif no SD card is present.The card is initialised and mounted at
/sdbeforeboot.pyruns. ReturnsNoneon boards withoutHAS_SD_CARDor when mount failed.
- hub.sd_remount() None[source]
Unmount the cached SD card handle and re-mount the SD card at
/sd.Call after disabling USB MSC so the SDMMC host is freed and can be re-initialised via
machine.SDCard.
- hub.set_frame_sink(cb: Callable[[bytes], None] | None) None[source]
Register a callback that mirrors framed and raw stdout bytes elsewhere.
Called from
mp_hal_stdout_tx_strnunder the GIL after every framed flush and everyraw_write(). Used to forward the same byte stream to BLE NUS (sinceos.duptermonly exposes slot 0 = REPL on this port). PassNoneto detach. Exceptions inside the callback are swallowed.
- hub.set_framed_output(enabled: bool) None[source]
Enable/disable C-level stdout framing (#FR:OUT <len>n<bytes>).
When enabled, every
mp_hal_stdout_tx_strncall is wrapped so the host protocol parser can separate program output from binary frames. Used by the HubProtocol layer sincesys.stdoutis an immutable dummy in this build and can’t be replaced from Python.
- hub.set_usb_msc(enabled: bool) None[source]
Enable or disable USB Mass Storage Class (SD card).
When enabling, the SDMMC host is opened without a VFS mount so TinyUSB can own the SD card. When disabling, the SDMMC host is released so
sd_remount()can re-mount it via MicroPython.
- hub.accelerometer: lpf2.devices.accelerometer[source]
Built-in accelerometer wrapped as a Devices.accelerometer.
- hub.audio: _audio_module[source]
Raw-PCM audio player via NS4168 I2S amp (see
_audio_module). Only present when board has NS4168.
- hub.gyro: lpf2.devices.gyroscope[source]
Built-in gyroscope wrapped as a Devices.gyroscope.
- hub.led: lpf2.devices.hub_led[source]
Built-in hub RGB LED.