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.
 

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. More...
 
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.
 
UsbSpeed getSpeed ()
 Returns the speed at which the device operates.
 
UsbState getUsbState ()
 Returns the current state of the device.
 
DeviceDescriptorgetDescriptor ()
 Returns the device descriptor of the device.
 
ConfigDescriptorgetConfiguration ()
 Returns the configuration in use.
 
InterfacegetInterface ()
 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.
 
UsbDeviceContainergetContainer () const
 Gets our Device container, for replacing parents on hubs etc.
 
virtual bool hasSubtree () const
 Do we expose our own Device tree?
 
virtual DevicegetDevice ()
 

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)
 
void addInterruptInHandler (Endpoint *pEndpoint, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), 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)
 Performs an USB control request.
 
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. More...
 
uint8_t getDescriptorLength (uint8_t nDescriptorType, uint8_t nDescriptorIndex, uint8_t requestType=0)
 Gets a descriptor's length from the device. More...
 
String getString (uint8_t nString)
 Gets a string. More...
 

Protected Attributes

uint8_t m_nAddress
 The current address of the device.
 
uint8_t m_nPort
 The number of the port on which the device is connected.
 
UsbSpeed m_Speed
 The speed at which the device operates.
 
UsbState m_UsbState
 The current state of the device.
 
DeviceDescriptorm_pDescriptor
 Device descriptor for this device.
 
ConfigDescriptorm_pConfiguration
 Configuration in use.
 
Interfacem_pInterface
 Interface in use.
 
UsbHubm_pHub
 Parent USB hub.
 
UsbDeviceContainerm_pContainer
 Our current container.
 

Private Member Functions

 UsbDevice (const UsbDevice &d)
 
const UsbDeviceoperator= (const UsbDevice &d)
 

Friends

class UsbDeviceContainer
 

Detailed Description

Definition at line 37 of file UsbDevice.h.

Member Function Documentation

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 556 of file UsbDevice.cc.

References controlRequest(), and m_pInterface.

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 580 of file UsbDevice.cc.

References controlRequest(), and m_pInterface.

Referenced by getString(), and initialise().

+ Here is the caller graph for this function:

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.

Definition at line 255 of file UsbDevice.h.

Referenced by getString().

+ Here is the caller graph for this function:

String UsbDevice::getString ( uint8_t  nString)
protected

Gets a string.

Todo:
UTF-8 support of some kind

Definition at line 600 of file UsbDevice.cc.

References getDescriptor(), getDescriptorLength(), getDevice(), hasSubtree(), m_pContainer, and Device::setParent().

Referenced by initialise().

+ Here is the caller graph for this function:

void UsbDevice::initialise ( uint8_t  nAddress)

Initialises the device at the given address.

Todo:
This doesn't work - HS devices at FS stall all over the place. Find out why.
Todo:
support more configurations (how?)

Definition at line 155 of file UsbDevice.cc.

References UsbHub::addInterruptInHandler(), UsbHub::addTransferToTransaction(), assert, controlRequest(), UsbHub::createTransaction(), DEBUG_LOG, Dec, UsbHub::doSync(), ERROR, getDescriptor(), getDescriptorLength(), getString(), Hex, m_nAddress, m_nPort, m_pDescriptor, m_pHub, m_Speed, m_UsbState, useConfiguration(), and WARNING.

Referenced by UsbHub::deviceConnected().

+ Here is the caller graph for this function:


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