pyb — functions related to the board¶
Warning
The pyb module is deprecated. Use the cross-port machine
module for new code – it provides the same functionality on every
OpenMV Cam regardless of MCU family, whereas pyb exists only on
the STM32-based boards. pyb is retained for backwards compatibility
with older scripts, no new features will be added, and it may be
removed in a future release.
The pyb module contains STM32-specific functions related to the board.
Miscellaneous functions¶
- pyb.have_cdc() bool¶
Return True if USB is connected as a serial device, False otherwise.
Note
This function is deprecated. Use pyb.USB_VCP().isconnected() instead.
- pyb.hid(data: Tuple[int, int, int, int]) None¶
Takes a 4-tuple (or list) and sends it to the USB host (the PC) to signal a HID mouse-motion event.
Note
This function is deprecated. Use
pyb.USB_HID.send()instead.
- pyb.main(filename: str) None¶
Set the filename of the main script to run after boot.py is finished. If this function is not called then the default file main.py will be executed.
It only makes sense to call this function from within boot.py.
- pyb.mount(device: Any, mountpoint: str, *, readonly: bool = False, mkfs: bool = False) None¶
Note
This function is deprecated. Use
vfs.mount()/vfs.umount()and avfs.AbstractBlockDev-derived block device instead.Mount a block device under
mountpoint.devicemust implement the legacy pyb block-device protocol (also deprecated – seevfs.AbstractBlockDevfor the modern interface):Method
Purpose
readblocks(self, blocknum, buf)Copy
bufworth of bytes from the device starting at blockblocknum.buflength is a multiple of 512.writeblocks(self, blocknum, buf)(optional)Write
bufto the device starting at blockblocknum. If omitted, the device is mounted read-only.count(self)Return the number of 512-byte blocks on the device.
sync(self)(optional)Flush any cached writes.
mountpointis the path in the root of the filesystem to mount the device at; it must begin with a forward slash.readonlyforces a read-only mount.mkfscreates a new filesystem if none is present.
- pyb.repl_uart(uart: UART | None = None) UART | None¶
Get or set the UART object where the REPL is repeated on.
- pyb.usb_mode(modestr: str | None = None, port: int = -1, vid: int = 0xf055, pid: int = -1, msc: Tuple = (), hid: Tuple = pyb.hid_mouse, high_speed: bool = False) str | None¶
If called with no arguments, return the current USB mode as a string.
If called with modestr provided, attempts to configure the USB mode. The following values of modestr are understood:
modestr
Configures
NoneDisables USB.
'VCP'VCP (Virtual COM Port) only.
'MSC'MSC (USB mass storage class) only.
'VCP+MSC'VCP and MSC.
'VCP+HID'VCP and HID (human interface device).
'VCP+MSC+HID'VCP, MSC and HID together. Not supported on every OpenMV Cam.
For backwards compatibility,
'CDC'is understood to mean'VCP'(and similarly for'CDC+MSC'and'CDC+HID').The port parameter should be an integer (0, 1, …) and selects which USB port to use if the board supports multiple ports. A value of -1 uses the default or automatically selected port.
The vid and pid parameters allow you to specify the VID (vendor id) and PID (product id). A pid value of -1 will select a PID based on the value of modestr.
If enabling MSC mode, the msc parameter can be used to specify a list of SCSI LUNs to expose on the mass storage interface. For example
msc=(pyb.Flash(), pyb.SDCard()).If enabling HID mode, you may also specify the HID details by passing the hid keyword parameter. It takes a tuple of (subclass, protocol, max packet length, polling interval, report descriptor). By default it will set appropriate values for a USB mouse. There is also a
pyb.hid_keyboardconstant, which is an appropriate tuple for a USB keyboard.The high_speed parameter, when set to
True, enables USB HS mode if it is supported by the hardware.
Constants¶
Both of the constants below are ready-made 5-tuples in the form
(subclass, protocol, max_packet_size, polling_interval_ms, report_descriptor)
suitable for passing as the hid argument of usb_mode() to make the
OpenMV Cam appear to the host as a USB HID device. subclass = 1 means
“boot interface” and protocol selects the boot device class
(1 = keyboard, 2 = mouse). The fifth element is a bytes object
holding the HID report descriptor used when the host enumerates the device.
- pyb.hid_mouse: tuple¶
Pre-built HID descriptor for a 3-button boot mouse with relative X/Y movement. The tuple is
(1, 2, 4, 8, <mouse report descriptor>): boot subclass, mouse protocol, 4-byte input reports (button mask + X + Y + wheel), polled every 8 ms. The built-in report descriptor is the one used bypyb.USB_HID().send((buttons, dx, dy, wheel)).
- pyb.hid_keyboard: tuple¶
Pre-built HID descriptor for a USB boot keyboard. The tuple is
(1, 1, 8, 8, <keyboard report descriptor>): boot subclass, keyboard protocol, 8-byte input reports (modifier byte, one reserved byte, six concurrent key codes), polled every 8 ms. The built-in report descriptor matches the standard 8-byte HID boot-keyboard layout, so the report sent viaUSB_HID.send()should be abytesof the form(modifiers, 0, key1, key2, key3, key4, key5, key6).
Classes¶
- class ADC – analog to digital conversion
- class ADCAll – access all ADC channels
- class CAN – controller area network communication bus
- class DAC – digital to analog conversion
- class ExtInt – configure I/O pins to interrupt on external events
- class Flash – access to built-in flash storage
- class I2C – a two-wire serial protocol
- class LED – on-board LED
- class Pin – control I/O pins
- class PinAF – pin alternate functions
- class RTC – real time clock
- class Servo – 3-wire hobby servo driver
- class SPI – a controller-driven serial protocol
- class Timer – control internal timers
- class TimerChannel – setup a channel for a timer
- class UART – duplex serial communication bus
- class USB_HID – USB Human Interface Device (HID)
- class USB_VCP – USB virtual comm port