The Pedigree Project 0.1
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
UsbDevice Class Reference
+ Inheritance diagram for UsbDevice:
+ Collaboration diagram for UsbDevice:

Classes

struct  ConfigDescriptor
 
struct  DeviceDescriptor
 
struct  DeviceQualifier
 
struct  Endpoint
 
struct  Interface
 
struct  Setup
 
struct  UnknownDescriptor
 

Public Types

enum  UsbState {
  Connected = 0 , Addressed , HasDescriptors , Configured ,
  HasInterface , HasDriver
}
 Possible states for an USB device. More...
 

Public Member Functions

 UsbDevice (UsbHub *pHub, uint8_t nPort, UsbSpeed speed)
 Default constructor.
 
 UsbDevice (UsbDevice *pDev)
 Copy constructor.
 
virtual ~UsbDevice ()
 Destructor.
 
void initialise (uint8_t nAddress)
 Initialises the device at the given address.
 
virtual void initialiseDriver ()
 Implemented by the driver class, initialises driver-specific stuff.
 
virtual void getUsbDeviceName (String &str)
 
uint8_t getAddress ()
 Returns the current address of the device.
 
uint8_t getPort ()
 Returns the number of the port on which the device is connected.
 
UsbHub * getHub () const
 
UsbSpeed getSpeed ()
 Returns the speed at which the device operates.
 
UsbState getUsbState ()
 Returns the current state of the device.
 
DeviceDescriptor * getDescriptor ()
 Returns the device descriptor of the device.
 
ConfigDescriptor * getConfiguration ()
 Returns the configuration in use.
 
Interface * getInterface ()
 Returns the interface in use.
 
void useConfiguration (uint8_t nConfig)
 Switches to the given configuration.
 
void useInterface (uint8_t nInterface)
 Switches to the given interface.
 
UsbDeviceContainer * getContainer () const
 Gets our Device container, for replacing parents on hubs etc.
 
virtual bool hasSubtree () const
 Do we expose our own Device tree?
 
virtual Device * getDevice ()
 
virtual void prepareForDriverRetirement ()
 
virtual void quiesceForRetirement ()
 
virtual void prepareForDisconnection ()
 

Public Attributes

struct UsbDevice::Setup PACKED
 
struct UsbDevice::DeviceQualifier PACKED
 

Protected Member Functions

ssize_t doSync (Endpoint *pEndpoint, UsbPid pid, uintptr_t pBuffer, size_t nBytes, size_t timeout)
 
ssize_t syncIn (Endpoint *pEndpoint, uintptr_t pBuffer, size_t nBytes, size_t timeout=5000)
 
ssize_t syncOut (Endpoint *pEndpoint, uintptr_t pBuffer, size_t nBytes, size_t timeout=5000)
 
MUST_USE_RESULT bool addInterruptInHandler (Endpoint *pEndpoint, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), UsbInterruptInHandle &handle, uintptr_t pParam=0)
 
bool controlRequest (uint8_t nRequestType, uint8_t nRequest, uint16_t nValue, uint16_t nIndex, uint16_t nLength=0, uintptr_t pBuffer=0, uint32_t timeout=5000)
 Performs an USB control request.
 
ssize_t controlRequestResult (uint8_t nRequestType, uint8_t nRequest, uint16_t nValue, uint16_t nIndex, uint16_t nLength=0, uintptr_t pBuffer=0, uint32_t timeout=5000)
 Returns data bytes transferred, or a negative UsbError.
 
uint16_t getStatus ()
 Gets device's current status.
 
bool clearEndpointHalt (Endpoint *pEndpoint)
 Clears a halt on the given endpoint.
 
void * getDescriptor (uint8_t nDescriptorType, uint8_t nDescriptorIndex, uint16_t nBytes, uint8_t requestType=0)
 Gets a descriptor from the device.
 
uint8_t getDescriptorLength (uint8_t nDescriptorType, uint8_t nDescriptorIndex, uint8_t requestType=0)
 Gets a descriptor's length from the device.
 
String getString (uint8_t nString)
 Gets a string.
 

Protected Attributes

uint8_t m_nAddress
 The current address of the device.
 
uint16_t m_ControlPacketSize
 
uint8_t m_nPort
 The number of the port on which the device is connected.
 
uint8_t m_nRootPort
 Root-controller connection which owns this device generation.
 
size_t m_nRootPortGeneration
 
UsbSpeed m_Speed
 The speed at which the device operates.
 
UsbState m_UsbState
 The current state of the device.
 
DeviceDescriptor * m_pDescriptor
 Device descriptor for this device.
 
ConfigDescriptor * m_pConfiguration
 Configuration in use.
 
Interface * m_pInterface
 Interface in use.
 
UsbHub * m_pHub
 Parent USB hub.
 
UsbDeviceContainer * m_pContainer
 Our current container.
 

Private Member Functions

 UsbDevice (const UsbDevice &d)
 
const UsbDevice & operator= (const UsbDevice &d)
 

Friends

class UsbDeviceContainer
 
class UsbPnP
 

Detailed Description

Definition at line 44 of file UsbDevice.h.

Member Enumeration Documentation

◆ UsbState

Possible states for an USB device.

Definition at line 170 of file UsbDevice.h.

Constructor & Destructor Documentation

◆ UsbDevice() [1/2]

UsbDevice::UsbDevice ( UsbHub *  pHub,
uint8_t  nPort,
UsbSpeed  speed 
)

Default constructor.

Definition at line 39 of file UsbDevice.cc.

References m_nRootPort, and UsbHub::rootConnectionForChild().

◆ UsbDevice() [2/2]

UsbDevice::UsbDevice ( UsbDevice *  pDev)

Copy constructor.

Definition at line 61 of file UsbDevice.cc.

References m_pDescriptor.

◆ ~UsbDevice()

UsbDevice::~UsbDevice ( )
virtual

Destructor.

Definition at line 79 of file UsbDevice.cc.

References m_pDescriptor.

Member Function Documentation

◆ addInterruptInHandler()

bool UsbDevice::addInterruptInHandler ( Endpoint *  pEndpoint,
uintptr_t  pBuffer,
uint16_t  nBytes,
void(*)(uintptr_t, ssize_t)  pCallback,
UsbInterruptInHandle &  handle,
uintptr_t  pParam = 0 
)
protected

Definition at line 449 of file UsbDevice.cc.

◆ clearEndpointHalt()

bool UsbDevice::clearEndpointHalt ( Endpoint *  pEndpoint)
protected

Clears a halt on the given endpoint.

Definition at line 573 of file UsbDevice.cc.

References controlRequest(), m_nAddress, m_nPort, m_nRootPort, m_pHub, and m_Speed.

◆ controlRequest()

bool UsbDevice::controlRequest ( uint8_t  nRequestType,
uint8_t  nRequest,
uint16_t  nValue,
uint16_t  nIndex,
uint16_t  nLength = 0,
uintptr_t  pBuffer = 0,
uint32_t  timeout = 5000 
)
protected

◆ controlRequestResult()

ssize_t UsbDevice::controlRequestResult ( uint8_t  nRequestType,
uint8_t  nRequest,
uint16_t  nValue,
uint16_t  nIndex,
uint16_t  nLength = 0,
uintptr_t  pBuffer = 0,
uint32_t  timeout = 5000 
)
protected

Returns data bytes transferred, or a negative UsbError.

Definition at line 487 of file UsbDevice.cc.

References UsbHub::addTransferToTransaction(), UsbHub::createTransaction(), UsbHub::doSync(), m_nAddress, m_nPort, m_nRootPort, m_pHub, and m_Speed.

Referenced by controlRequest(), and UsbMassStorageDevice::initialiseDriver().

+ Here is the caller graph for this function:

◆ doSync()

ssize_t UsbDevice::doSync ( UsbDevice::Endpoint *  pEndpoint,
UsbPid  pid,
uintptr_t  pBuffer,
size_t  nBytes,
size_t  timeout 
)
protected

Definition at line 378 of file UsbDevice.cc.

◆ getAddress()

uint8_t UsbDevice::getAddress ( )
inline

Returns the current address of the device.

Definition at line 192 of file UsbDevice.h.

◆ getConfiguration()

ConfigDescriptor * UsbDevice::getConfiguration ( )
inline

Returns the configuration in use.

Definition at line 221 of file UsbDevice.h.

◆ getContainer()

UsbDeviceContainer * UsbDevice::getContainer ( ) const
inline

Gets our Device container, for replacing parents on hubs etc.

Definition at line 237 of file UsbDevice.h.

◆ getDescriptor() [1/2]

DeviceDescriptor * UsbDevice::getDescriptor ( )
inline

Returns the device descriptor of the device.

Definition at line 216 of file UsbDevice.h.

Referenced by getString(), initialise(), UsbHumanInterfaceDevice::initialiseDriver(), and UsbHubDevice::initialiseDriver().

+ Here is the caller graph for this function:

◆ getDescriptor() [2/2]

void * UsbDevice::getDescriptor ( uint8_t  nDescriptorType,
uint8_t  nDescriptorIndex,
uint16_t  nBytes,
uint8_t  requestType = 0 
)
protected

Gets a descriptor from the device.

Todo:
Proper language ID handling!

Definition at line 622 of file UsbDevice.cc.

References controlRequest(), and m_pInterface.

◆ getDescriptorLength()

uint8_t UsbDevice::getDescriptorLength ( uint8_t  nDescriptorType,
uint8_t  nDescriptorIndex,
uint8_t  requestType = 0 
)
protected

Gets a descriptor's length from the device.

Todo:
Proper language ID handling

Definition at line 643 of file UsbDevice.cc.

References controlRequest(), and m_pInterface.

Referenced by getString(), and UsbHubDevice::initialiseDriver().

+ Here is the caller graph for this function:

◆ getDevice()

virtual Device * UsbDevice::getDevice ( )
inlinevirtual

Get a usable Device for this particular UsbDevice, if it has a subtree.

Returns
NULL if this operation is not supported.

Reimplemented in UsbMassStorageDevice, and UsbHubDevice.

Definition at line 248 of file UsbDevice.h.

Referenced by UsbDeviceContainer::replaceUsbDevice().

+ Here is the caller graph for this function:

◆ getHub()

UsbHub * UsbDevice::getHub ( ) const
inline

Definition at line 201 of file UsbDevice.h.

◆ getInterface()

Interface * UsbDevice::getInterface ( )
inline

Returns the interface in use.

Definition at line 226 of file UsbDevice.h.

Referenced by UsbPnP::doProbe().

+ Here is the caller graph for this function:

◆ getPort()

uint8_t UsbDevice::getPort ( )
inline

Returns the number of the port on which the device is connected.

Definition at line 197 of file UsbDevice.h.

◆ getSpeed()

UsbSpeed UsbDevice::getSpeed ( )
inline

Returns the speed at which the device operates.

Definition at line 206 of file UsbDevice.h.

◆ getStatus()

uint16_t UsbDevice::getStatus ( )
protected

Gets device's current status.

Definition at line 565 of file UsbDevice.cc.

References controlRequest().

◆ getString()

String UsbDevice::getString ( uint8_t  nString)
protected

Gets a string.

Todo:
UTF-8 support of some kind

Definition at line 662 of file UsbDevice.cc.

References getDescriptor(), and getDescriptorLength().

Referenced by initialise().

+ Here is the caller graph for this function:

◆ getUsbDeviceName()

virtual void UsbDevice::getUsbDeviceName ( String &  str)
inlinevirtual

Definition at line 187 of file UsbDevice.h.

◆ getUsbState()

UsbState UsbDevice::getUsbState ( )
inline

Returns the current state of the device.

Definition at line 211 of file UsbDevice.h.

Referenced by UsbPnP::doProbe().

+ Here is the caller graph for this function:

◆ hasSubtree()

virtual bool UsbDevice::hasSubtree ( ) const
inlinevirtual

Do we expose our own Device tree?

Reimplemented in UsbMassStorageDevice, and UsbHubDevice.

Definition at line 242 of file UsbDevice.h.

Referenced by UsbDeviceContainer::replaceUsbDevice().

+ Here is the caller graph for this function:

◆ initialise()

void UsbDevice::initialise ( uint8_t  nAddress)

Initialises the device at the given address.

Todo:
support more configurations (how?)

Definition at line 239 of file UsbDevice.cc.

References controlRequest(), Dec, EMIT_IF, getDescriptor(), getString(), Hex, m_nAddress, m_nPort, m_nRootPort, m_pDescriptor, m_pHub, m_Speed, m_UsbState, and useConfiguration().

◆ initialiseDriver()

virtual void UsbDevice::initialiseDriver ( )
inlinevirtual

Implemented by the driver class, initialises driver-specific stuff.

Reimplemented in Dm9601, FtdiSerialDevice, UsbHumanInterfaceDevice, UsbHubDevice, and UsbMassStorageDevice.

Definition at line 185 of file UsbDevice.h.

Referenced by UsbPnP::doProbe().

+ Here is the caller graph for this function:

◆ prepareForDisconnection()

virtual void UsbDevice::prepareForDisconnection ( )
inlinevirtual

Prepares a driver after its physical device has disappeared.

Reimplemented in UsbHubDevice, and UsbMassStorageDevice.

Definition at line 259 of file UsbDevice.h.

◆ prepareForDriverRetirement()

virtual void UsbDevice::prepareForDriverRetirement ( )
inlinevirtual

Quiesces driver-specific ownership before replacing this binding.

Reimplemented in UsbHubDevice.

Definition at line 253 of file UsbDevice.h.

◆ quiesceForRetirement()

virtual void UsbDevice::quiesceForRetirement ( )
inlinevirtual

Stops producers which can add or replace devices in this subtree.

Reimplemented in UsbHubDevice.

Definition at line 256 of file UsbDevice.h.

◆ syncIn()

ssize_t UsbDevice::syncIn ( Endpoint *  pEndpoint,
uintptr_t  pBuffer,
size_t  nBytes,
size_t  timeout = 5000 
)
protected

Definition at line 441 of file UsbDevice.cc.

◆ syncOut()

ssize_t UsbDevice::syncOut ( Endpoint *  pEndpoint,
uintptr_t  pBuffer,
size_t  nBytes,
size_t  timeout = 5000 
)
protected

Definition at line 445 of file UsbDevice.cc.

◆ useConfiguration()

void UsbDevice::useConfiguration ( uint8_t  nConfig)

Switches to the given configuration.

Definition at line 590 of file UsbDevice.cc.

References controlRequest(), m_pConfiguration, m_pDescriptor, and m_UsbState.

Referenced by initialise().

+ Here is the caller graph for this function:

◆ useInterface()

void UsbDevice::useInterface ( uint8_t  nInterface)

Switches to the given interface.

Definition at line 599 of file UsbDevice.cc.

References controlRequest(), m_pConfiguration, m_pInterface, and m_UsbState.

Friends And Related Symbol Documentation

◆ UsbDeviceContainer

friend class UsbDeviceContainer
friend

Definition at line 45 of file UsbDevice.h.

◆ UsbPnP

friend class UsbPnP
friend

Definition at line 46 of file UsbDevice.h.

Member Data Documentation

◆ m_ControlPacketSize

uint16_t UsbDevice::m_ControlPacketSize
protected

Definition at line 298 of file UsbDevice.h.

◆ m_nAddress

uint8_t UsbDevice::m_nAddress
protected

◆ m_nPort

uint8_t UsbDevice::m_nPort
protected

The number of the port on which the device is connected.

Definition at line 301 of file UsbDevice.h.

Referenced by UsbHubDevice::addInterruptInHandler(), clearEndpointHalt(), controlRequestResult(), UsbHubDevice::createTransaction(), and initialise().

◆ m_nRootPort

uint8_t UsbDevice::m_nRootPort
protected

Root-controller connection which owns this device generation.

Definition at line 304 of file UsbDevice.h.

Referenced by clearEndpointHalt(), controlRequestResult(), initialise(), and UsbDevice().

◆ m_nRootPortGeneration

size_t UsbDevice::m_nRootPortGeneration
protected

Definition at line 305 of file UsbDevice.h.

◆ m_pConfiguration

ConfigDescriptor* UsbDevice::m_pConfiguration
protected

Configuration in use.

Definition at line 317 of file UsbDevice.h.

Referenced by useConfiguration(), and useInterface().

◆ m_pContainer

UsbDeviceContainer* UsbDevice::m_pContainer
protected

Our current container.

Definition at line 326 of file UsbDevice.h.

Referenced by UsbDeviceContainer::replaceUsbDevice().

◆ m_pDescriptor

DeviceDescriptor* UsbDevice::m_pDescriptor
protected

Device descriptor for this device.

Definition at line 314 of file UsbDevice.h.

Referenced by initialise(), UsbHumanInterfaceDevice::initialiseDriver(), UsbDevice(), useConfiguration(), and ~UsbDevice().

◆ m_pHub

UsbHub* UsbDevice::m_pHub
protected

◆ m_pInterface

Interface* UsbDevice::m_pInterface
protected

◆ m_Speed

UsbSpeed UsbDevice::m_Speed
protected

The speed at which the device operates.

Definition at line 308 of file UsbDevice.h.

Referenced by UsbHubDevice::addInterruptInHandler(), clearEndpointHalt(), controlRequestResult(), UsbHubDevice::createTransaction(), and initialise().

◆ m_UsbState

UsbState UsbDevice::m_UsbState
protected

The documentation for this class was generated from the following files: