@si14/si-usbd
usbd::UsbDevice Class Referenceabstract

USB device base class. More...

Collaboration diagram for usbd::UsbDevice:

Public Member Functions

virtual void init ()
 
virtual UsbEndpointgetControlEndpoint ()=0
 
virtual UsbInterfacegetInterface (int index)=0
 
virtual void setup (SetupData *setupData)
 
virtual void checkDescriptor (DeviceDescriptor *deviceDesriptor)
 
virtual const char * getManufacturer ()
 
virtual const char * getProduct ()
 
virtual const char * getSerial ()
 
virtual void setAddress (int address)=0
 
virtual void startTx (int epIndex, int length)=0
 
virtual void stall (int epIndex)=0
 

Public Attributes

UsbEndpointendpoints [MAX_ENDPOINTS]
 
int endpointCount
 

Detailed Description

USB device base class.

This class is not subclassed directly by the application. There must always be chip specific implementation as midclass. This means there is a hierarchy like: UsbDevice <- ChipAbcUsbDevice <- ApplicationXyzUsbDevice.

Typical application subclass of a chip midclass (ATSAMD in this case) looks like:

class TestDevice : public atsamd::usbd::AtSamdUsbDevice {
public:
TestInterface testInterface;
UsbControlEndpoint controlEndpoint;
UsbInterface *getInterface(int index) { return index == 0 ? &testInterface : NULL; };
UsbEndpoint *getControlEndpoint() { return &controlEndpoint; };
void checkDescriptor(DeviceDescriptor *deviceDesriptor) {
deviceDesriptor->idVendor = 0xFEE0;
deviceDesriptor->idProduct = 0x0001;
};
};

Chip midclass must overload following methods:

Member Function Documentation

◆ checkDescriptor()

virtual void usbd::UsbDevice::checkDescriptor ( DeviceDescriptor *  deviceDesriptor)
inlinevirtual

Called when generating device descriptor.

Called internally from the library.

May be overloaded by application subclass to modify the default descriptor.

Parameters
deviceDesriptor

◆ getControlEndpoint()

virtual UsbEndpoint* usbd::UsbDevice::getControlEndpoint ( )
pure virtual

Gets control endpoint.

Called internally from the library.

Must be overloaded by the application subclass.

Returns
UsbEndpoint*

◆ getInterface()

virtual UsbInterface* usbd::UsbDevice::getInterface ( int  index)
pure virtual

Gets interface by index.

Called internally from the library.

Must be overloaded by the application subclass.

Parameters
indexzero based in scope of device
Returns
UsbInterface*

◆ getManufacturer()

virtual const char* usbd::UsbDevice::getManufacturer ( )
inlinevirtual

Get string identifier of the manufacturer.

Called internally from the library.

May be overloaded by application subclass.

Returns
const char*

◆ getProduct()

virtual const char* usbd::UsbDevice::getProduct ( )
inlinevirtual

Get string identifier of the product.

Called internally from the library.

May be overloaded by application subclass.

Returns
const char*

◆ getSerial()

virtual const char* usbd::UsbDevice::getSerial ( )
inlinevirtual

Get string serial number of the device.

Called internally from the library.

May be overloaded by application subclass or chip midclass.

Returns
const char*

◆ init()

virtual void usbd::UsbDevice::init ( )
inlinevirtual

Device initialization.

Called from chip midclass init() method.

UsbEndpoint::init() is responsible for collecting of endpoints from interfaces.

◆ setAddress()

virtual void usbd::UsbDevice::setAddress ( int  address)
pure virtual

Sets device USB address.

Called internally from the library.

Must be overloaded by chip midclass.

Parameters
address

◆ setup()

virtual void usbd::UsbDevice::setup ( SetupData *  setupData)
inlinevirtual

Handler of device control request.

Called internally from the library.

May be overloaded by application subclass to implement vendor request.

Parameters
setupData

◆ stall()

virtual void usbd::UsbDevice::stall ( int  epIndex)
pure virtual

Sends stall handshake on the given endpoint.

Called internally from the library.

Must be overloaded by chip midclass.

Parameters
epIndex

◆ startTx()

virtual void usbd::UsbDevice::startTx ( int  epIndex,
int  length 
)
pure virtual

Starts transmission of the data on the given endpoint.

Called internally from the library.

Must be overloaded by chip midclass.

Parameters
epIndex
length

Member Data Documentation

◆ endpointCount

int usbd::UsbDevice::endpointCount

Number of endpoints as collected by the init() method.

◆ endpoints

UsbEndpoint* usbd::UsbDevice::endpoints[MAX_ENDPOINTS]

Array of endpoints as collected by the init() method.


The documentation for this class was generated from the following file:
usbd::UsbDevice::checkDescriptor
virtual void checkDescriptor(DeviceDescriptor *deviceDesriptor)
Definition: usb-device.cpp:123
usbd::UsbDevice::getControlEndpoint
virtual UsbEndpoint * getControlEndpoint()=0
usbd::UsbDevice::getInterface
virtual UsbInterface * getInterface(int index)=0