Squishy Device

Todo

Flesh this out

class squishy.device.SquishyDevice(dev: USBDevice, serial: str, timeout: int = 2500)

Squishy Hardware Device

This class represents a Squishy hardware device that is attached to the host, it exposes a common and stable API for interacting with Squishy devices.

Parameters:
  • dev (usb1.USBDevice) – The USB Device handle for the attached Squishy hardware.

  • serial (str) – The serial number of the device.

  • timeout (int) – USB Transaction timeout in ms. (default: 2500)

Variables:
  • rev (tuple[int, int]) – The revision of the attached Squishy device in the form of (major, minor).

  • serial (str) – The serial number of this Squishy device

classmethod get_device(*, serial: str | None = None, first: bool = True) Self | None

Returns an instance of the first SquishyDevice attached to the system, or if serial is specified the device with that serial number, if possible.

If there are no Squishy devices attached to the host system, or one with serial is not found None is returned instead.

Parameters:
  • serial (str | None) – The serial number of the target device wanted.

  • first (bool) – If there is more than one Squishy attached, and no serial number is specified, return the first that occurs in the list.

Returns:

The requested Squishy device if found, otherwise None

Return type:

SquishyDevice | None

classmethod enumerate() list[tuple[str, tuple[int, int], USBDevice]]

Collect all of the attached Squishy devices.

Returns:

A collection of Squishy hardware devices attached to the system.

Return type:

list[DeviceContainer]

static generate_serial() str

Generate a new serial number string for a Squishy device.

The current implementation uses the current datetime in an ISO 8601-like format.

Returns:

The new serial number.

Return type:

str

can_dfu() bool

Determine whether or not this device is DFU capable.

Returns:

True if the given USB device is DFU capable, otherwise False

Return type:

bool

get_altmodes() dict[int, str]

Collect and return all of the DFU alt-modes and their name from the device.

Returns:

A mapping of the alt-mode endpoint and it’s name.

Return type:

dict[int, str]

Raises:
  • RuntimeError – If the DFU interface is unknown, or the DFU control request times out.

  • AssertionError – If we lose the DFU configuration or interface somehow.

reset() bool

Invoke a DFU detach.

Returns:

True if the detach was successful, otherwise False

Return type:

bool

Raises:

RuntimeError – If the DFU interface is unknown, or the DFU control request times out.

upload(data: bytes, altmode: int, progress: Progress | None = None) bool

Push firmware/gateware to device.

Parameters:
  • data (bytes) – The data to upload to the device.

  • altmode (int) – The alt-mode endpoint to upload to.

  • progress (rich.progress.Progress | None) – Optional Rich progressbar instance.

Returns:

Upload was successful, otherwise False

Return type:

bool

Raises:

RuntimeError – If the DFU interface is unknown, the DFU control request times out, or we can’t determine the transaction size

get_platform() type[SquishyPlatform | Platform] | None

Get the type Torii platform definition for the currently attached device.

Returns:

The type Torii platform definition for this device if found, otherwise None

Return type:

type[SquishyPlatformType] | None