USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.

Dependencies:   FATFileSystem mbed-rtos

Dependents:   BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more

Embed: (wiki syntax)

« Back to documentation index

USBHost Class Reference

USBHost class This class is a singleton. More...

#include <USBHost.h>

Inherits USBHALHost.

Data Structures

class  Lock
 Instantiate to protect USB thread from accessing shared objects (USBConnectedDevices and Interfaces) More...

Public Member Functions

USB_TYPE controlRead (USBDeviceConnected *dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t *buf, uint32_t len)
 Control read: setup stage, data stage and status stage.
USB_TYPE controlWrite (USBDeviceConnected *dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t *buf, uint32_t len)
 Control write: setup stage, data stage and status stage.
USB_TYPE bulkRead (USBDeviceConnected *dev, USBEndpoint *ep, uint8_t *buf, uint32_t len, bool blocking=true)
 Bulk read.
USB_TYPE bulkWrite (USBDeviceConnected *dev, USBEndpoint *ep, uint8_t *buf, uint32_t len, bool blocking=true)
 Bulk write.
USB_TYPE interruptRead (USBDeviceConnected *dev, USBEndpoint *ep, uint8_t *buf, uint32_t len, bool blocking=true)
 Interrupt read.
USB_TYPE interruptWrite (USBDeviceConnected *dev, USBEndpoint *ep, uint8_t *buf, uint32_t len, bool blocking=true)
 Interrupt write.
USB_TYPE enumerate (USBDeviceConnected *dev, IUSBEnumerator *pEnumerator)
 Enumerate a device.
USB_TYPE resetDevice (USBDeviceConnected *dev)
 reset a specific device
USBDeviceConnectedgetDevice (uint8_t index)
 Get a device.
template<typename T >
void registerDriver (USBDeviceConnected *dev, uint8_t intf, T *tptr, void(T::*mptr)(void))
 register a driver into the host associated with a callback function called when the device is disconnected
void registerDriver (USBDeviceConnected *dev, uint8_t intf, void(*fn)(void))
 register a driver into the host associated with a callback function called when the device is disconnected

Static Public Member Functions

static USBHostgetHostInst ()
 Static method to create or retrieve the single USBHost instance.

Protected Member Functions

virtual void transferCompleted (volatile uint32_t addr)
 Virtual method called when a transfer has been completed.
virtual void deviceConnected (int hub, int port, bool lowSpeed, USBHostHub *hub_parent=NULL)
 Virtual method called when a device has been connected.
virtual void deviceDisconnected (int hub, int port, USBHostHub *hub_parent, volatile uint32_t addr)
 Virtuel method called when a device has been disconnected.
void init ()
 Initialize host controller.
void resetRootHub ()
 reset the root hub
uint32_t controlHeadED ()
 return the value contained in the control HEAD ED register
uint32_t bulkHeadED ()
 return the value contained in the bulk HEAD ED register
uint32_t interruptHeadED ()
 return the value of the head interrupt ED contained in the HCCA
void updateControlHeadED (uint32_t addr)
 Update the head ED for control transfers.
void updateBulkHeadED (uint32_t addr)
 Update the head ED for bulk transfers.
void updateInterruptHeadED (uint32_t addr)
 Update the head ED for interrupt transfers.
void enableList (ENDPOINT_TYPE type)
 Enable List for the specified endpoint type.
bool disableList (ENDPOINT_TYPE type)
 Disable List for the specified endpoint type.
volatile uint8_t * getED ()
 Find a memory section for a new ED.
volatile uint8_t * getTD ()
 Find a memory section for a new TD.
void freeED (volatile uint8_t *ed)
 Release a previous memory section reserved for an ED.
void freeTD (volatile uint8_t *td)
 Release a previous memory section reserved for an TD.

Friends

class USBHostHub

Detailed Description

USBHost class This class is a singleton.

All drivers have a reference on the static USBHost instance

Definition at line 34 of file USBHost.h.


Member Function Documentation

uint32_t bulkHeadED (  ) [protected, inherited]

return the value contained in the bulk HEAD ED register

Returns:
address of the bulk head ED
USB_TYPE bulkRead ( USBDeviceConnected dev,
USBEndpoint ep,
uint8_t *  buf,
uint32_t  len,
bool  blocking = true 
)

Bulk read.

Parameters:
devthe bulk transfer will be done for this device
epUSBEndpoint which will be used to read a packet
bufpointer on a buffer where will be store the data received
lenlength of the transfer
blockingif true, the read is blocking (wait for completion)
Returns:
status of the bulk read

Definition at line 1053 of file USBHost.cpp.

USB_TYPE bulkWrite ( USBDeviceConnected dev,
USBEndpoint ep,
uint8_t *  buf,
uint32_t  len,
bool  blocking = true 
)

Bulk write.

Parameters:
devthe bulk transfer will be done for this device
epUSBEndpoint which will be used to write a packet
bufpointer on a buffer which will be written
lenlength of the transfer
blockingif true, the write is blocking (wait for completion)
Returns:
status of the bulk write

Definition at line 1048 of file USBHost.cpp.

uint32_t controlHeadED (  ) [protected, inherited]

return the value contained in the control HEAD ED register

Returns:
address of the control Head ED
USB_TYPE controlRead ( USBDeviceConnected dev,
uint8_t  requestType,
uint8_t  request,
uint32_t  value,
uint32_t  index,
uint8_t *  buf,
uint32_t  len 
)

Control read: setup stage, data stage and status stage.

Parameters:
devthe control read will be done for this device
requestTyperequest type
requestrequest
valuevalue
indexindex
bufpointer on a buffer where will be store the data received
lenlength of the transfer
Returns:
status of the control read

Definition at line 1147 of file USBHost.cpp.

USB_TYPE controlWrite ( USBDeviceConnected dev,
uint8_t  requestType,
uint8_t  request,
uint32_t  value,
uint32_t  index,
uint8_t *  buf,
uint32_t  len 
)

Control write: setup stage, data stage and status stage.

Parameters:
devthe control write will be done for this device
requestTyperequest type
requestrequest
valuevalue
indexindex
bufpointer on a buffer which will be written
lenlength of the transfer
Returns:
status of the control write

Definition at line 1152 of file USBHost.cpp.

void deviceConnected ( int  hub,
int  port,
bool  lowSpeed,
USBHostHub hub_parent = NULL 
) [protected, virtual]

Virtual method called when a device has been connected.

Parameters:
hubhub number of the device
portport number of the device
lowSpeed1 if low speed, 0 otherwise
hub_parentreference on the parent hub

Implements USBHALHost.

Definition at line 402 of file USBHost.cpp.

void deviceDisconnected ( int  hub,
int  port,
USBHostHub hub_parent,
volatile uint32_t  addr 
) [protected, virtual]

Virtuel method called when a device has been disconnected.

Parameters:
hubhub number of the device
portport number of the device
addrlist of the TDs which have been completed to dequeue freed TDs

Implements USBHALHost.

Definition at line 425 of file USBHost.cpp.

bool disableList ( ENDPOINT_TYPE  type ) [protected, inherited]

Disable List for the specified endpoint type.

Parameters:
typedisable the list of ENDPOINT_TYPE type
void enableList ( ENDPOINT_TYPE  type ) [protected, inherited]

Enable List for the specified endpoint type.

Parameters:
typeenable the list of ENDPOINT_TYPE type
USB_TYPE enumerate ( USBDeviceConnected dev,
IUSBEnumerator *  pEnumerator 
)

Enumerate a device.

Parameters:
devdevice which will be enumerated
Returns:
status of the enumeration

Definition at line 895 of file USBHost.cpp.

void freeED ( volatile uint8_t *  ed ) [protected, inherited]

Release a previous memory section reserved for an ED.

Parameters:
edaddress of the ED
void freeTD ( volatile uint8_t *  td ) [protected, inherited]

Release a previous memory section reserved for an TD.

Parameters:
tdaddress of the TD
USBDeviceConnected * getDevice ( uint8_t  index )

Get a device.

Parameters:
indexindex of the device which will be returned
Returns:
pointer on the "index" device

Definition at line 563 of file USBHost.cpp.

volatile uint8_t* getED (  ) [protected, inherited]

Find a memory section for a new ED.

Returns:
the address of the new ED
USBHost * getHostInst (  ) [static]

Static method to create or retrieve the single USBHost instance.

Definition at line 388 of file USBHost.cpp.

volatile uint8_t* getTD (  ) [protected, inherited]

Find a memory section for a new TD.

Returns:
the address of the new TD
void init (  ) [protected, inherited]

Initialize host controller.

Enable USB interrupts. This part is not in the constructor because, this function calls a virtual method if a device is already connected

uint32_t interruptHeadED (  ) [protected, inherited]

return the value of the head interrupt ED contained in the HCCA

Returns:
address of the head interrupt ED contained in the HCCA
USB_TYPE interruptRead ( USBDeviceConnected dev,
USBEndpoint ep,
uint8_t *  buf,
uint32_t  len,
bool  blocking = true 
)

Interrupt read.

Parameters:
devthe bulk transfer will be done for this device
epUSBEndpoint which will be used to write a packet
bufpointer on a buffer which will be written
lenlength of the transfer
blockingif true, the read is blocking (wait for completion)
Returns:
status of the interrupt read

Definition at line 1063 of file USBHost.cpp.

USB_TYPE interruptWrite ( USBDeviceConnected dev,
USBEndpoint ep,
uint8_t *  buf,
uint32_t  len,
bool  blocking = true 
)

Interrupt write.

Parameters:
devthe bulk transfer will be done for this device
epUSBEndpoint which will be used to write a packet
bufpointer on a buffer which will be written
lenlength of the transfer
blockingif true, the write is blocking (wait for completion)
Returns:
status of the interrupt write

Definition at line 1058 of file USBHost.cpp.

void registerDriver ( USBDeviceConnected dev,
uint8_t  intf,
void(*)(void)  fn 
)

register a driver into the host associated with a callback function called when the device is disconnected

Parameters:
devdevice
intfinterface number
fncallback called when the specified device has been disconnected

Definition at line 183 of file USBHost.h.

void registerDriver ( USBDeviceConnected dev,
uint8_t  intf,
T *  tptr,
void(T::*)(void)  mptr 
)

register a driver into the host associated with a callback function called when the device is disconnected

Parameters:
devdevice
intfinterface number
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 167 of file USBHost.h.

USB_TYPE resetDevice ( USBDeviceConnected dev )

reset a specific device

Parameters:
devdevice which will be resetted

Definition at line 594 of file USBHost.cpp.

void resetRootHub (  ) [protected, inherited]

reset the root hub

void transferCompleted ( volatile uint32_t  addr ) [protected, virtual]

Virtual method called when a transfer has been completed.

Parameters:
addrlist of the TDs which have been completed

Implements USBHALHost.

Definition at line 328 of file USBHost.cpp.

void updateBulkHeadED ( uint32_t  addr ) [protected, inherited]

Update the head ED for bulk transfers.

void updateControlHeadED ( uint32_t  addr ) [protected, inherited]

Update the head ED for control transfers.

void updateInterruptHeadED ( uint32_t  addr ) [protected, inherited]

Update the head ED for interrupt transfers.