USB¶
- class brainstem.entity.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
- getAltModeConfig(channel)[source]¶
- Gets alt mode configuration for defined USB channel.
See the product datasheet for device specific details.
- Parameters:
channel (int) – The USB channel
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.
- Parameters:
channel (int) – Upstream port to be applied.
- Returns:
value (int): The connect mode error: Non-zero BrainStem error code on failure.
- Return type:
Result (object)
- 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
- getPortMode(channel)[source]¶
- Get 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 at
ef usbPortMode
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
- getSBU1Voltage(channel)[source]¶
Get the voltage on the SBU1 line for a port.
- Parameters:
channel (int) – The USB port number
Returns: Result object
- getSBU2Voltage(channel)[source]¶
Get the voltage on the SBU2 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.
- setAltModeConfig(channel, configuration)[source]¶
- Sets alt mode configuration for defined USB channel.
See the product datasheet for device specific details
- Parameters:
channel (int) – The USB channel
configuration (uint) – The configuration to set
- Returns (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- setConnectMode(channel, mode)[source]¶
Set The connection mode for the Switch.
- Parameters:
channel (int) – Upstream port to be applied.
mode (int) – 0 = Manual mode, 1 = Auto mode.
- Returns (int):
Non-zero BrainStem error code on failure.
- setDataDisable(channel)[source]¶
Disable just the data lines for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- setDataEnable(channel)[source]¶
Enable just the data lines for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- setHiSpeedDataDisable(channel)[source]¶
Disable Hi-Speed (USB2.0) data transfer for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- setHiSpeedDataEnable(channel)[source]¶
Enable Hi-Speed (USB2.0) data transfer for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- setPortDisable(channel)[source]¶
Disable both power and data lines for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- setPortEnable(channel)[source]¶
Enable both power and data lines for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- 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 at
ef usbPortMode
- Args:
channel (int): Port Index. mode (int): The port mode setting as packed bit field.
- Returns (int):
Non-zero BrainStem error code on failure.
- setPowerDisable(channel)[source]¶
Disable just the power line for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- setPowerEnable(channel)[source]¶
Enable just the power line for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.
- setSuperSpeedDataDisable(channel)[source]¶
Disable SuperSpeed (USB3.0) data transfer for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- setSuperSpeedDataEnable(channel)[source]¶
Enable SuperSpeed (USB3.0) data transfer for a USB port.
- Parameters:
channel (int) – The USB port number
- Returns (int):
Non-zero BrainStem error code on failure.
- 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 (int):
Non-zero BrainStem error code on failure.