USB

API Documentation: [cpp] [python] [.NET] [LabVIEW]

The USB Entity provides the software control interface for USB related features. This entity is supported by BrainStem products which have programmatically controlled USB features.


The usb entity manages the software-controllable downstream USB 2.0 channels of the MTM-IO-Serial (there are also two non-software-controllable USB channels on the module, one through the edge connector and the other through the onboard type-A connector, which are always on), as well as the upstream USB connection mode. All downstream USB ports are configured as SDP (Standard Data Port).

Downstream

Each of the four software-controllable USB channels (ports 0-3) can be individually manipulated using the usb entity. The API individually controls port power, data, or both together

Power

stem.usb.setPowerEnable(port) [cpp] [python] [NET] [LabVIEW]

stem.usb.setPowerDisable(port) [cpp] [python] [NET] [LabVIEW]

Data

stem.usb.setDataEnable(port) [cpp] [python] [NET] [LabVIEW]

stem.usb.setDataDisable(port) [cpp] [python] [NET] [LabVIEW]

Port

stem.usb.setPortEnable(port) [cpp] [python] [NET] [LabVIEW]

stem.usb.setPortDisable(port) [cpp] [python] [NET] [LabVIEW]

Upstream Mode

The MTM-IO-Serial has two (2) upstream USB connection options: through the edge connector or via the mini-B connector on the board itself. The upstream mode can be set or read using the usb entity

stem.usb.setUpstreamMode(mode) [cpp] [python] [NET] [LabVIEW]

stem.usb.getUpstreamMode(mode) [cpp] [python] [NET] [LabVIEW]

The mode parameter is an integer that correlates to the following:

Mode

Result

0

Edge Connector

1

Mini-B Connector

2

Auto

Auto configuration chooses the upstream connection based on the presence or absence of VBUS power at the mini-B connector; if VBUS is present, the mini-B connector is used, otherwise the edge connector is used.

Upstream State

Gets the upstream switch state for the USB upstream ports. Returns none if no ports are plugged in, port 0 if the mode is set correctly and a cable is plugged into port 0, and port 1 if the mode is set correctly and a cable is plugged into port 1

stem.usb.getUpstreamState() [cpp] [python] [NET] [LabVIEW]

Hub Mode

In addition to targeting individual downstream USB ports, a bit-mapped hub state interface is also available. This interface allows the reading or setting of all USB downstream ports in one functional call

stem.usb.setHubMode(mode) [cpp] [python] [NET] [LabVIEW]

stem.usb.getHubMode(mode) [cpp] [python] [NET] [LabVIEW]

Bit

Hub Operational Mode Result Bitwise Description

0

USB Channel 0 USB Hi Speed Data Enabled

1

USB Channel 0 USB VBUS Enabled

2

USB Channel 1 USB Hi Speed Data Enabled

3

USB Channel 1 USB VBUS Enabled

4

USB Channel 2 USB Hi Speed Data Enabled

5

USB Channel 2 USB VBUS Enabled

6

USB Channel 3 USB Hi Speed Data Enabled

7

USB Channel 3 USB VBUS Enabled

8:31

Reserved

Port State

Each downstream port reports information regarding its operating state represented in bit-packed results from

stem.usb.getPortState(mode) [cpp] [python] [NET] [LabVIEW]

where channel can be [0-3], and the value status is 32-bit word, defined as the following:

Bit

Port State Result Bitwise Description

0

USB VBUS Enabled

1

USB2 Data Enabled

2:18

Reserved

19

USB Error Flag

20

USB2 Boost Enabled

21:31

Reserved

Hi-Speed Data

Enables or Disables Hi Speed data only for given downstream channel. This call enables or disables the usb data (+) and data (-) lines for the given channel.

stem.usb.setHiSpeedDataEnable(port) [cpp] [python] [NET] [LabVIEW]

stem.usb.setHiSpeedDataDisable(port) [cpp] [python] [NET] [LabVIEW]

Hub and Port Error Status

Errors can be cleared on each individual channel (0, 1, 2 or 3) by calling the following method:

stem.usb.getPortError(channel) [cpp] [python] [NET] [LabVIEW]

Details about the hub error status 32-bit word are as follows:

Bit

Port State Result Bitwise Description

0

USB VBUS Enabled

1

USB2 Data Enabled

2:18

Reserved

19

USB Error Flag

20

USB2 Boost Enabled

21:31

Reserved

To clear a Port error status

stem.usb.clearPortErrorStatus(channel) [cpp] [python] [NET] [LabVIEW]