USB

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

USBClass 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.

Useful Constants:
  • UPSTREAM_MODE_AUTO (2)
  • UPSTREAM_MODE_PORT_0 (0)
  • UPSTREAM_MODE_PORT_1 (1)
  • UPSTREAM_MODE_NONE (255)
  • DEFAULT_UPSTREAM_MODE (UPSTREAM_MODE_AUTO)
  • UPSTREAM_STATE_PORT_0 (0)
  • UPSTREAM_STATE_PORT_1 (1)
  • BOOST_0_PERCENT (0)
  • BOOST_4_PERCENT (1)
  • BOOST_8_PERCENT (2)
  • BOOST_12_PERCENT (3)
  • PORT_MODE_SDP (0)
  • PORT_MODE_CDP (1)
  • PORT_MODE_CHARGING (2)
  • PORT_MODE_PASSIVE (3)
  • PORT_MODE_USB2_A_ENABLE (4)
  • PORT_MODE_USB2_B_ENABLE (5)
  • PORT_MODE_VBUS_ENABLE (6)
  • PORT_MODE_SUPER_SPEED_1_ENABLE (7)
  • PORT_MODE_SUPER_SPEED_2_ENABLE (8)
  • PORT_MODE_USB2_BOOST_ENABLE (9)
  • PORT_MODE_USB3_BOOST_ENABLE (10)
  • PORT_MODE_AUTO_CONNECTION_ENABLE (11)
  • PORT_MODE_CC1_ENABLE (12)
  • PORT_MODE_CC2_ENABLE (13)
  • PORT_MODE_SBU_ENABLE (14)
  • PORT_MODE_CC_FLIP_ENABLE (15)
  • PORT_MODE_SS_FLIP_ENABLE (16)
  • PORT_MODE_SBU_FLIP_ENABLE (17)
  • PORT_MODE_USB2_FLIP_ENABLE (18)
  • PORT_MODE_CC1_INJECT_ENABLE (19)
  • PORT_MODE_CC2_INJECT_ENABLE (20)
  • PORT_SPEED_NA (0)
  • PORT_SPEED_HISPEED (1)
  • PORT_SPEED_SUPERSPEED (2)
clearPortErrorStatus(channel)[source]

Clear the error status for the given channel.

Parameters:channel (int) – The USB port number

Returns: Result object

getCC1Current(channel)[source]

Get the current through the CC1 line for a port.

Parameters:channel (int) – The USB port number

Returns: Result object

getCC1Voltage(channel)[source]

Get the voltage on the CC1 line for a port.

Parameters:channel (int) – The USB port number

Returns: Result object

getCC2Current(channel)[source]

Get the current through the CC2 line for a port.

Parameters:channel (int) – The USB port number

Returns: Result object

getCC2Voltage(channel)[source]

Get the voltage on the CC2 line for a port.

Parameters:channel (int) – The USB port number

Returns: Result object

getCableFlip(channel)[source]

Get the status of cable orientation flip within the S85 switch.

Parameters:channel (int) – The USB port number

Returns: Result object

getConnectMode(channel)[source]

Get The connection mode for the Switch. :param channel: USB sub channel. :return: NO_ERROR on success and error code on failure.

getDownstreamBoostMode()[source]

Get the downstream boost mode.

Returns: Result object
Result value 0 - no boost, 1 - 4%% boost, 2 - 8%% boost, 3 - 12%% boost.
getDownstreamDataSpeed(channel)[source]

Get the downstream port data speed.

Returns: Result object
Result value:
  • N/A: PORT_SPEED_NA = 0
  • Hi Speed: PORT_SPEED_HISPEED = 1
  • SuperSpeed: PORT_SPEED_SUPERSPEED = 2
getEnumerationDelay()[source]

Get the interport enumeration delay in milliseconds.

Returns: Result object

getHubMode()[source]
Get a bit mapped representation of the hub mode.
Usually represents the port data and power lines enable/disable state in one bit packed result. See the product datasheet for state mapping.

Returns: Result object

getPortCurrent(channel)[source]

Get the current through the power line for a port.

Parameters:channel (int) – The USB port number

Returns: Result object

getPortCurrentLimit(channel)[source]

Get the current limit for the port.

Returns: Result object

getPortError(channel)[source]

Get the error for the Port.

Returns: Result object

getPortMode(channel)[source]

Get the mode for the Port. The mode setting defaults to SDP or Standard Downstream port, and can be set to CDP (charging downstream port) for devices that require high port charge current above 500 milliamps.

Returns: Result object

getPortState(channel)[source]

Get the state for the Port.

Returns: Result object

getPortVoltage(channel)[source]

Get the voltage on the power line for a port.

Parameters:channel (int) – The USB port number

Returns: Result object

getUpstreamBoostMode()[source]

Get the upstream boost mode.

Returns: Result object
Result value 0 - no boost, 1 - 4%% boost, 2 - 8%% boost, 3 - 12%% boost.
getUpstreamMode()[source]

Get the upstream switch mode for the USB upstream ports.

Returns: Result object

getUpstreamState()[source]

Get the upstream switch state for the USB upstream ports.

Returns: Result object
Result value 2 if no ports plugged in; 0 if port0 is active, 1 if port1 is active.
setCC1Enable(channel, enable)[source]

Enable CC1 lines for a Type C USB port

Parameters:
  • channel (int) – The USB port number
  • enable (int) – enable (0 = disable, 1 = enable)

Returns: Result object

setCC2Enable(channel, enable)[source]

Enable CC2 lines for a Type C USB port

Parameters:
  • channel (int) – The USB port number
  • enable (int) – enable [0 = disable, 1 = enable]

Returns: Result object

setCableFlip(channel, enable)[source]

Enables a cable orientation flip within the S85 switch.

Parameters:
  • channel (int) – The USB port number
  • enable (int) – enables cable flip. [0 = disable, 1 = enable]

Returns: Error

setConnectMode(channel, mode)[source]

Set The connection mode for the Switch. :param channel: USB sub channel. :param mode: 0 = Manual mode, 1 = Auto mode. :return: NO_ERROR on success and error code on failure.

setDataDisable(channel)[source]

Disable just the data lines for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setDataEnable(channel)[source]

Enable just the data lines for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

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 (int) – Downstream boost setting 0, 1, 2, or 3.

Returns: Result object

setEnumerationDelay(ms_delay)[source]
Set the interport enumeration delay in milliseconds.
This setting must be saved with a stem.system.save() call for it to be active. This setting is persistent across hub power down. Resetting the hub will return this setting to the default value of 0ms.
Parameters:ms_delay (int) – Interport delay in milliseconds

Returns: Result object

setHiSpeedDataDisable(channel)[source]

Disable Hi-Speed (USB2.0) data transfer for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setHiSpeedDataEnable(channel)[source]

Enable Hi-Speed (USB2.0) data transfer for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setHubMode(mode)[source]
Set a bit mapped representation of the hub mode.
Usually represents the port data and power lines enable/disable. See the product datasheet for state mapping.
Parameters:mode (int) – The hub state

Returns: Result object

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 to make it persistent.
Parameters:
  • channel (int) – Port index.
  • microAmps (int) – The current limit setting in microAmps (1A=10e6)

Returns: Result object

setPortDisable(channel)[source]

Disable both power and data lines for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setPortEnable(channel)[source]

Enable both power and data lines for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setPortMode(channel, mode)[source]
Set the mode for the Port.
The mode setting defaults to SDP or Standard Downstream port, and can be set to CDP (charging downstream port) for devices that require high port charge current above 500 milliamps.
Parameters:
  • channel (int) – Port Index.
  • mode (int) – Mode The port mode setting (0 - SDP, 1 - CDP).

Returns: Result.error value.

setPowerDisable(channel)[source]

Disable just the power line for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setPowerEnable(channel)[source]

Enable just the power line for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setSBUEnable(channel, enable)[source]

Enable SBU1/SBU2 lines for a Type C USB port based on usbPortMode settings.

Parameters:
  • channel (int) – The USB port number
  • enable (int) – enables SBU1/SBU2 [0 = disable, 1 = enable]

Returns: Result object

setSuperSpeedDataDisable(channel)[source]

Disable SuperSpeed (USB3.0) data transfer for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

setSuperSpeedDataEnable(channel)[source]

Enable SuperSpeed (USB3.0) data transfer for a USB port.

Parameters:channel (int) – The USB port number

Returns: Result object

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 (int) – Upstream boost setting 0, 1, 2, or 3.

Returns: Result object

setUpstreamMode(mode)[source]

Set the upstream switch mode for the USB upstream ports

Parameters:mode (int) –
  • Auto: UPSTREAM_MODE_AUTO = 2
  • Port 0: UPSTREAM_STATE_PORT_0 = 0
  • Port 1: UPSTREAM_STATE_PORT_1 = 1

Returns: Result object