USB

See the USB Entity for generic information.

class brainstem.entity.USB(module, index)[source]

The USB class provides methods to interact with a USB hub and USB switches. Different USB hub products have varying support; check the datasheet to understand the capabilities of each product.

clearPortErrorStatus(channel)[source]

Clear the error status for the given port.

Parameters:

channel (unsigned char) – The port to clear error status for.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

getAltModeConfig(channel)[source]

Get USB Alt Mode Configuration.

Parameters:

channel (unsigned char) – The USB sub channel

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned int

The USB configuration for the given channel.

Return type:

brainstem.result.Result

getCC1Current(channel)[source]

Get the current through the CC1 for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel current in micro-amps (1 == 1e-6A).

Return type:

brainstem.result.Result

getCC1Enable(channel)[source]

Get Enable/Disable on the CC1 line.

Parameters:

channel (unsigned char) – USB channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valuebool
State to be filled
  • Disabled: 0

  • Enabled: 1

Return type:

brainstem.result.Result

getCC1Voltage(channel)[source]

Get the voltage of CC1 for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel voltage in micro-volts (1 == 1e-6V).

Return type:

brainstem.result.Result

getCC2Current(channel)[source]

Get the current through the CC2 for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel current in micro-amps (1 == 1e-6A).

Return type:

brainstem.result.Result

getCC2Enable(channel)[source]

Get Enable/Disable on the CC1 line.

Parameters:

channel (unsigned char) – USB channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valuebool
State to be filled
  • Disabled: 0

  • Enabled: 1

Return type:

brainstem.result.Result

getCC2Voltage(channel)[source]

Get the voltage of CC2 for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel voltage in micro-volts (1 == 1e-6V).

Return type:

brainstem.result.Result

getCableFlip(channel)[source]

Get Cable flip setting.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valuebool

The enable/disable status of cable flip.

Return type:

brainstem.result.Result

getConnectMode(channel)[source]

Gets the connect mode of the switch.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned char

The current connect mode

Return type:

brainstem.result.Result

getDownstreamBoostMode()[source]

Get the downstream boost mode. Possible modes are 0 - no boost, 1 - 4% boost, 2 - 8% boost, 3 - 12% boost.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned char

The current Downstream boost setting 0, 1, 2, or 3.

Return type:

brainstem.result.Result

getDownstreamDataSpeed(channel)[source]

Get the current data transfer speed for the downstream port. The data speed can be Hi-Speed (2.0) or SuperSpeed (3.0) depending on what the downstream device attached is using

Parameters:

channel (unsigned char) – USB downstream channel to check.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned char
Filled with the current port data speed
  • N/A: usbDownstreamDataSpeed_na = 0

  • Hi Speed: usbDownstreamDataSpeed_hs = 1

  • SuperSpeed: usbDownstreamDataSpeed_ss = 2

Return type:

brainstem.result.Result

getEnumerationDelay()[source]

Get the inter-port enumeration delay in milliseconds.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned int

Millisecond delay in 100mS increments (100, 200, 300 etc.)

Return type:

brainstem.result.Result

getHubMode()[source]

Get a bit mapped representation of the hubs mode; see the product datasheet for mode mapping and meaning.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned int

The USB hub mode.

Return type:

brainstem.result.Result

getPortCurrent(channel)[source]

Get the current through the power line for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel current in micro-amps (1 == 1e-6A).

Return type:

brainstem.result.Result

getPortCurrentLimit(channel)[source]

Get the current limit for the port.

Parameters:

channel (unsigned char) – USB downstream channel to limit.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned int

The current limit setting.

Return type:

brainstem.result.Result

getPortError(channel)[source]

Get the current error for the Port.

Parameters:

channel (unsigned char) – USB downstream channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned int

The port mode setting. Mode will be filled with the current setting. Mode bits that are not used will be marked as don’t care.

Return type:

brainstem.result.Result

getPortMode(channel)[source]

Get the current mode for the Port. The mode is a bitmapped representation of the capabilities of the usb port. These capabilities change for each of the BrainStem devices which implement the usb entity. See your device reference page for a complete list of capabilities. Some devices use a common bit mapping for port mode, as sub-definitions of usbPortMode.

Parameters:

channel (unsigned char) – USB downstream channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned int

The port mode setting. Mode will be filled with the current setting. Mode bits that are not used will be marked as don’t care.

Return type:

brainstem.result.Result

getPortState(channel)[source]

Get the current State for the Port.

Parameters:

channel (unsigned char) – USB downstream channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned int

The port mode setting. Mode will be filled with the current setting. Mode bits that are not used will be marked as don’t care.

Return type:

brainstem.result.Result

getPortVoltage(channel)[source]

Get the voltage on the power line for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel voltage in microvolts (1 == 1e-6V).

Return type:

brainstem.result.Result

getSBU1Voltage(channel)[source]

Get the voltage of SBU1 for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel voltage in micro-volts (1 == 1e-6V).

Return type:

brainstem.result.Result

getSBU2Voltage(channel)[source]

Get the voltage of SBU2 for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueint

The USB channel voltage in micro-volts (1 == 1e-6V).

Return type:

brainstem.result.Result

getSBUEnable(channel)[source]

Get the Enable/Disable status of the SBU

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valuebool

The enable/disable status of the SBU

Return type:

brainstem.result.Result

getUpstreamBoostMode()[source]

Get the upstream boost mode. Possible modes are 0 - no boost, 1 - 4% boost, 2 - 8% boost, 3 - 12% boost.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned char

The current Upstream boost setting 0, 1, 2, or 3.

Return type:

brainstem.result.Result

getUpstreamMode()[source]

Get the upstream switch mode for the USB upstream ports. Returns auto, port 0 or port 1.

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned char

The Upstream port mode.

Return type:

brainstem.result.Result

getUpstreamState()[source]

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

Returns:

Object containing error code and returned value on success.
errorunsigned byte

An error result from the list of defined error codes

valueunsigned char

The Upstream port state.

Return type:

brainstem.result.Result

setAltModeConfig(channel, configuration)[source]

Set USB Alt Mode Configuration.

Parameters:
  • channel (unsigned char) – The USB sub channel

  • configuration (unsigned int) – The USB configuration to be set for the given channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setCC1Enable(channel, enable)[source]

Set Enable/Disable on the CC1 line.

Parameters:
  • channel (unsigned char) – USB channel.

  • enable (bool) –

    State to be set
    • Disabled: 0

    • Enabled: 1

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setCC2Enable(channel, enable)[source]

Set Enable/Disable on the CC2 line.

Parameters:
  • channel (unsigned char) – USB channel.

  • enable (bool) –

    State to be filled
    • Disabled: 0

    • Enabled: 1

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setCableFlip(channel, enable)[source]

Set Cable flip. This will flip SBU, CC and SS data lines.

Parameters:
  • channel (unsigned char) – The USB sub channel.

  • enable (bool) –

    The state to be set The state to be set
    • Disabled: 0

    • Enabled: 1

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setConnectMode(channel, mode)[source]

Sets the connect mode of the switch.

Parameters:
  • channel (unsigned char) – The USB sub channel.

  • mode (unsigned char) –

    The connect mode
    • usbManualConnect = 0

    • usbAutoConnect = 1

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setDataDisable(channel)[source]

Disable only the data lines for a port without changing the state of the power line.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setDataEnable(channel)[source]

Enable the only the data lines for a port without changing the state of the power line.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setDownstreamBoostMode(setting)[source]

Set the downstream boost mode. Boost mode increases the drive strength of the USB data signals (power signals are not changed). Boosting the data signal strength may help to overcome connectivity issues when using long cables or connecting through “pogo” pins. Possible modes are 0 - no boost, 1 - 4% boost, 2 - 8% boost, 3 - 12% boost. This setting is not applied until a stem.system.save() call and power cycle of the hub. Setting is then persistent until changed or the hub is reset. After reset, default value of 0% boost is restored.

Parameters:

setting (unsigned char) – Downstream boost setting 0, 1, 2, or 3.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setEnumerationDelay(ms_delay)[source]

Set the inter-port enumeration delay in milliseconds.

Parameters:

ms_delay (unsigned int) – Millisecond delay in 100mS increments (100, 200, 300 etc.)

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setHiSpeedDataDisable(channel)[source]

Disable only the data lines for a port without changing the state of the power line, Hi- Speed (2.0) only.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setHiSpeedDataEnable(channel)[source]

Enable the only the data lines for a port without changing the state of the power line, Hi-Speed (2.0) only.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setHubMode(mode)[source]

Set a bit mapped hub state; see the product datasheet for state mapping and meaning.

Parameters:

mode (unsigned int) – The USB hub mode.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setPortCurrentLimit(channel, microamps)[source]

Set the current limit for the port. If the set limit is not achievable, devices will round down to the nearest available current limit setting. This setting can be saved with a stem.system.save() call.

Parameters:
  • channel (unsigned char) – USB downstream channel to limit.

  • microamps (unsigned int) – The current limit setting.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setPortDisable(channel)[source]

Disable both power and data lines for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setPortEnable(channel)[source]

Enable both power and data lines for a port.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setPortMode(channel, mode)[source]

Set the mode for the Port. The mode is a bitmapped representation of the capabilities of the usb port. These capabilities change for each of the BrainStem devices which implement the usb entity. See your device reference page for a complete list of capabilities. Some devices use a common bit mapping for port mode, as sub-definitions of usbPortMode.

Parameters:
  • channel (unsigned char) – USB downstream channel to set the mode on.

  • mode (unsigned int) – The port mode setting as packed bit field.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setPowerDisable(channel)[source]

Disable only the power line for a port without changing the state of the data lines.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setPowerEnable(channel)[source]

Enable only the power line for a port without changing the state of the data lines.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setSBUEnable(channel, enable)[source]

Enable/Disable only the SBU1/2 based on the configuration of the usbPortMode settings.

Parameters:
  • channel (unsigned char) – The USB sub channel.

  • enable (bool) – The state to be set - Disabled: 0 - Enabled: 1

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setSuperSpeedDataDisable(channel)[source]

Disable only the data lines for a port without changing the state of the power line, SuperSpeed (3.0) only.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setSuperSpeedDataEnable(channel)[source]

Enable the only the data lines for a port without changing the state of the power line, SuperSpeed (3.0) only.

Parameters:

channel (unsigned char) – The USB sub channel.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setUpstreamBoostMode(setting)[source]

Set the upstream boost mode. Boost mode increases the drive strength of the USB data signals (power signals are not changed). Boosting the data signal strength may help to overcome connectivity issues when using long cables or connecting through “pogo” pins. Possible modes are 0 - no boost, 1 - 4% boost, 2 - 8% boost, 3 - 12% boost. This setting is not applied until a stem.system.save() call and power cycle of the hub. Setting is then persistent until changed or the hub is reset. After reset, default value of 0% boost is restored.

Parameters:

setting (unsigned char) – Upstream boost setting 0, 1, 2, or 3.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte

setUpstreamMode(mode)[source]

Set the upstream switch mode for the USB upstream ports. Values are usbUpstreamModeAuto, usbUpstreamModePort0, usbUpstreamModePort1, and usbUpstreamModeNone.

Parameters:

mode (unsigned char) – The Upstream port mode.

Returns:

An error result from the list of defined error codes in brainstem.result.Result

Return type:

unsigned byte