class UsbPeripheral
Defined at line 101 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
This is the main class for the USB peripheral role driver.
It binds against the USB DCI driver device and manages a list of UsbFunction devices,
one for each USB function in the peripheral role configuration.
Public Members
static basic_string_view kDriverName
static basic_string_view kChildNodeName
static const uint8_t kMaxInterfaces
static const uint8_t kMaxStrings
static const uint8_t kMaxStringLength
static const uint8_t kOutEpStart
static const uint8_t kOutEpEnd
static const uint8_t kInEpStart
static const uint8_t kInEpEnd
Public Methods
zx::result<> Start (fdf::DriverContext context)
fdf::DriverBase2 implementation.
Defined at line 79 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
const fidl::WireSyncClient<fuchsia_hardware_usb_dci::UsbDci> & dci ()
Defined at line 247 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void Stop (fdf::StopCompleter completer)
Defined at line 1426 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t UsbDciCancelAll (uint8_t ep_address)
Defined at line 47 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void UsbPeripheral ()
Defined at line 164 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
DeviceState SnapshotState ()
Defined at line 200 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetState (DeviceState state)
Defined at line 206 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
usb_mode_t SnapshotUsbMode ()
Defined at line 211 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetUsbMode (usb_mode_t mode)
Defined at line 216 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
const usb_device_descriptor_t & device_desc ()
Defined at line 252 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
void SetConfiguration (SetConfigurationRequestView request, SetConfigurationCompleter::Sync & completer)
fuchsia_hardware_usb_peripheral::Device protocol implementation.
Defined at line 1313 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ClearFunctions (ClearFunctionsCompleter::Sync & completer)
Defined at line 1408 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetStateChangeListener (SetStateChangeListenerRequestView request, SetStateChangeListenerCompleter::Sync & completer)
Defined at line 1418 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t SetDeviceDescriptor (DeviceDescriptor desc)
Defined at line 1370 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx::result<uint8_t> ValidateFunction (size_tfunction_index,void *descriptors,size_tlength)
Validates a function and returns the number of interfaces it uses on
success.
Defined at line 291 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t FunctionRegistered ()
Defined at line 399 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t CheckAndStartController ()
Defined at line 415 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t StartController ()
Defined at line 523 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t StopController ()
Defined at line 557 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t FunctionUnregistered ()
Defined at line 495 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void FunctionCleared (size_t function_index)
Defined at line 1043 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void SetStateLocked (DeviceState state)
Defined at line 590 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx::result<ResourceAllocations> AllocResources (size_tfunction_index,uint8_tinterface_count,std::span<fuchsia_hardware_usb_function::EndpointResource>endpoints,std::span<std::string>strings)
Defined at line 642 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
bool ValidateEndpoint (size_t function_index, uint8_t ep_address)
Defined at line 719 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ReleaseResources (size_t function_index)
Defined at line 1531 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void ReleaseResourcesLocked (size_t function_index)
Defined at line 1536 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
ResourceAllocations GetResourceAllocations (size_t function_index)
Returns currently allocated resources for the given function.
For testing purposes only.
Defined at line 1570 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
zx_status_t ConnectToEndpoint (uint8_t ep_address, fidl::ServerEnd<fuchsia_hardware_usb_endpoint::Endpoint> ep)
Defined at line 65 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
void OnHostConnectionChanged (bool connected)
Defined at line 1258 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.cc
Enumerations
enum class DeviceState : uint8_t
| Name | Value |
|---|---|
| kNoConfiguration | 0 |
| kWaitForFunctionBind | 1 |
| kStarting | 2 |
| kPeripheralReady | 3 |
| kHostConnected | 4 |
| kStopping | 5 |
The driver uses a formal state machine to manage the lifecycle of configurations
and host connections. This ensures that resources (child nodes, DCI mode) are
handled safely during asynchronous events like host (dis)connects or driver
teardown.
State Machine:
kNoConfiguration:
Initial state. No active configuration. Functions can be added to the staging area.
Transitions:
-> kWaitForFunctionBind: Occurs when a configuration is committed (SetConfiguration()
or SetDefaultConfig()). Child nodes are published.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kWaitForFunctionBind:
Configuration committed. Child nodes are published. Waiting for function drivers to bind.
Transitions:
-> kStarting: Occurs when all functions have registered.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
-> kWaitForFunctionBind: Occurs when a function is unregistered (node unbound).
kStarting:
All functions have registered. Starting the DCI controller.
Transitions:
-> kPeripheralReady: Occurs when StartController() succeeds.
-> kWaitForFunctionBind: Occurs if StartController() fails.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kPeripheralReady:
All functions have registered. DCI is active. Ready for a USB host to connect.
Transitions:
-> kHostConnected: Occurs when a USB host connects.
-> kWaitForFunctionBind: Occurs if a function is unregistered.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kHostConnected:
USB host has performed enumeration and selected a configuration. Data paths are active.
Transitions:
-> kPeripheralReady: Occurs when the host disconnects.
-> kWaitForFunctionBind: Occurs if a function is unregistered.
-> kStopping: Occurs on ClearFunctions() or PrepareStop().
kStopping:
Teardown in progress (either a configuration clear or a full driver shutdown).
Transitions:
-> Terminates: When all functions are cleared and the driver is stopping.
-> kNoConfiguration: When all functions are cleared and we are just clearing functions
(not stopping the driver).
Defined at line 152 of file ../../src/devices/usb/drivers/usb-peripheral/usb-peripheral.h
Records
Friends
class UsbDciInterfaceServer