facedancer.backends.greathost module
Host support for GreatFET-base devices.
- class facedancer.backends.greathost.GreatDancerHostApp(verbose=0, quirks=[], autoconnect=True, device=None)[source]
Bases:
FacedancerUSBHostClass that represents a GreatFET-based USB host.
- DEVICE_SPEED_FULL = 1
- DEVICE_SPEED_HIGH = 2
- DEVICE_SPEED_LOW = 0
- DEVICE_SPEED_NAMES = {0: 'Low speed', 1: 'Full speed', 2: 'High speed', 3: 'Disconnected'}
- DEVICE_SPEED_NONE = 3
- DIRECTION_IN = 0
- DIRECTION_OUT = 128
- ENDPOINT_TYPE_CONTROL = 0
- LINE_STATE_J = 1
- LINE_STATE_K = 2
- LINE_STATE_NAMES = {0: 'SE0', 1: 'J', 2: 'K', 3: 'No device / SE1'}
- LINE_STATE_SE0 = 0
- LINE_STATE_SE1 = 3
- PID_IN = 1
- PID_OUT = 0
- PID_SETUP = 2
- PORT_STATUS_REG = 0
- PORT_STATUS_REGISTER_CONNECTED_MASK = 1
- PORT_STATUS_REGISTER_ENABLED_MASK = 4
- PORT_STATUS_REGISTER_LINE_STATE_MASK = 3
- PORT_STATUS_REGISTER_LINE_STATE_SHIFT = 10
- PORT_STATUS_REGISTER_POWERED_MASK = 4096
- PORT_STATUS_REGISTER_SPEED_MASK = 3
- PORT_STATUS_REGISTER_SPEED_SHIFT = 26
- READ_STATUS_REG = 1
- SPEED_REQUESTS = {0: 1, 1: 0, 2: 2, 3: 3}
- STATUS_REG_SPEED_VALUES = {0: 1, 1: 0, 2: 2, 3: 3}
- WRITE_STATUS_REG = 2
- __init__(verbose=0, quirks=[], autoconnect=True, device=None)[source]
Sets up a GreatFET-based host connection.
- app_name = 'GreatDancer Host'
- classmethod appropriate_for_environment(backend_name)[source]
Determines if the current environment seems appropriate for using the GreatDancer backend.
- bus_reset(delay=0.5)[source]
Issues a “bus reset”, requesting that the downstream device reset itself.
- Parameters:
delay – The amount of time, in seconds, to wait before or after the reset request. To be compliant, this should be omitted, or set to 0.1s.
- connect(device_speed=None)[source]
Sets up our host to talk to the device, including turning on VBUS.
- current_device_speed(as_string=False)[source]
Returns the speed of the connected device
- Parameters:
as_string – If true, returns the speed as a string for printing; otherwise returns a DEVICE_SPEED_* constant.
- current_line_state(as_string=False)[source]
Returns the current state of the USB differential pair
- Parameters:
as_string – If true, returns the speed as a string for printing; otherwise returns a LINE_STATE_* constant.
- initialize_control_endpoint(device_address=None, device_speed=None, max_packet_size=None)[source]
Set up the device’s control endpoint, so we can use it for e.g. enumeration.
- read_from_endpoint(endpoint_number, expected_read_size=64, data_packet_pid=0)[source]
Sends a block of data on the provided endpoints.
- Parameters:
endpoint_number – The endpoint number on which to send.
expected_read_size – The expected amount of data to be read.
data_packet_pid – The data packet PID to use (1 or 0). Ignored if the endpoint is set to automatically alternate data PIDs.
Raises an IOError on a communications error or stall.
- send_on_endpoint(endpoint_number, data, is_setup=False, blocking=True, data_packet_pid=0)[source]
Sends a block of data on the provided endpoints.
- Parameters:
endpoint_number – The endpoint number on which to send.
data – The data to be transmitted.
is_setup – True iff this transfer should begin with a SETUP token.
blocking – True iff this transaction should wait for the transaction to complete.
data_packet_pid – The data packet PID to use (1 or 0). Ignored if the endpoint is set to automatically alternate data PIDs.
Raises an IOError on a communications error or stall.
- set_up_endpoint(endpoint_address_or_object, endpoint_type=None, max_packet_size=None, device_address=None, endpoint_speed=None, handle_data_toggle=None, is_control_endpoint=None)[source]
Sets up an endpoint for use. Can be used to initialize an endpoint or to update its parameters. Two forms exist:
- Parameters:
endpoint_object – a USBEndpoint object with the parameters to be populated
or
- Parameters:
endpoint_address – the address of the endpoint to be setup; including the direction bit
endpoint_type – one of the ENDPOINT_TYPE constants that specifies the transfer mode on the endpoint_address
max_packet_size – the maximum packet size to be communicated on the given endpoint
device_address – the address of the device to be communicated with; if not provided, the last address will be used.
endpoint_speed – the speed of the packets to be communicated on the endpoint; should be a DEVICE_SPEED_* constant; if not provided, the last device’s speed will be used.
handle_data_toggle – true iff the hardware should automatically handle selection of data packet PIDs
is_control_endpoint – true iff the given packet is a for a control endpoint