@si14/si-usbd
usbd::UsbEndpoint Class Reference

USB endpoint base class. More...

Inheritance diagram for usbd::UsbEndpoint:
Collaboration diagram for usbd::UsbEndpoint:

Public Member Functions

virtual void init ()
 
virtual void setup (SetupData *setupData)
 
virtual void checkDescriptor (EndpointDescriptor *deviceDesriptor)
 
virtual void rxComplete (int length)
 
virtual void txComplete ()
 
void startTx (int length)
 
void stall ()
 

Public Attributes

unsigned char * rxBufferPtr
 
unsigned int rxBufferSize
 
unsigned int rxPacketSize
 
unsigned char * txBufferPtr
 
unsigned int txBufferSize
 
unsigned int txPacketSize
 
EndpointTransferType transferType = INTERRUPT
 
unsigned int index
 
UsbInterfaceinterface
 
UsbDevicedevice
 

Detailed Description

USB endpoint base class.

Endpoint has RX and TX buffer. The library (or the chip) handles multipacket transfers.

Buffers may be larger (but must be multiple) of related packet size.

A subclass should set buffers in overloaded init() method. For OUT endpoints, rxBufferPtr, rxBufferSize should be set. For IN endpoints, txBufferPtr, txBufferSize should be set. For bidirectional endpoints, both RX and TX buffers should be set.

Packet sizes may be set by rxPacketSize and txPacketSize properties, and may be 8, 16, 32 or 64 bytes for control, interrupt and bulk transfers, or 8, 16, 32, 64, 128, 256, 512 or 1023 for isochronous transfers.

If not set, packet sizes are derived from buffer sizes: for buffers smaller than 64 bytes, packet size equals to buffer size. For bigger buffers, packet size is 64 bytes.

Typical subclass of UsbEndpoint class looks like:

class TestEndpoint : public usbd::UsbEndpoint {
public:
unsigned char rxBuffer[1024];
unsigned char txBuffer[8];
void init() {
rxBufferPtr = rxBuffer;
rxBufferSize = sizeof(rxBuffer);
txBufferPtr = txBuffer;
txBufferSize = sizeof(txBuffer);
}
void rxComplete(int length) {
// process rxBuffer data of the length
// fill txBuffer and send some bytes
startTx(4);
}
};

Member Function Documentation

◆ checkDescriptor()

virtual void usbd::UsbEndpoint::checkDescriptor ( EndpointDescriptor *  deviceDesriptor)
inlinevirtual

Called when generating endpoint descriptor.

May be overloaded to modify the default descriptor.

Parameters
deviceDesriptor

◆ init()

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

Endpoint initialization.

Called internally from the library.

UsbEndpoint::init() sets packet sizes based on buffer sizes, so the subclass should call super method after setting of rxPacketSize and txPacketSize properties.

Reimplemented in usbd::UsbControlEndpoint.

◆ rxComplete()

virtual void usbd::UsbEndpoint::rxComplete ( int  length)
inlinevirtual

Called when data received.

May be overloaded to process received data.

Parameters
length

◆ setup()

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

Handler of endpoint control request.

May be overloaded to implement vendor request.

Parameters
setupData

Reimplemented in usbd::UsbControlEndpoint.

◆ stall()

void usbd::UsbEndpoint::stall ( )

Sends stall handshake.

◆ startTx()

void usbd::UsbEndpoint::startTx ( int  length)

Starts transmission of the data.

Parameters
length

◆ txComplete()

virtual void usbd::UsbEndpoint::txComplete ( )
inlinevirtual

Called when data transmitted.

May be overloaded to recognize completed data transmission.

Reimplemented in usbd::UsbControlEndpoint.

Member Data Documentation

◆ device

UsbDevice* usbd::UsbEndpoint::device

Owner device. This property is set internally by the library.

◆ index

unsigned int usbd::UsbEndpoint::index

Index of the endpoint in scope of the device. This property is set internally by the library.

◆ interface

UsbInterface* usbd::UsbEndpoint::interface

Owner interface. This property is set internally by the library.

◆ rxBufferPtr

unsigned char* usbd::UsbEndpoint::rxBufferPtr

Pointer do RX data buffer. Should be set from overloaded init() method.

◆ rxBufferSize

unsigned int usbd::UsbEndpoint::rxBufferSize

Size of RX data buffer. Must be multiple of rxPacketSize. Should be set from overloaded init() method.

◆ rxPacketSize

unsigned int usbd::UsbEndpoint::rxPacketSize

Size of RX packet. May be set from overloaded init() method.

◆ transferType

EndpointTransferType usbd::UsbEndpoint::transferType = INTERRUPT

Transfer type of the endpoint. May be set from overloaded init() method. Defaults to INTERRUPT.

◆ txBufferPtr

unsigned char* usbd::UsbEndpoint::txBufferPtr

Pointer do TX data buffer. Should be set from overloaded init() method.

◆ txBufferSize

unsigned int usbd::UsbEndpoint::txBufferSize

Size of TX data buffer. Must be multiple of txPacketSize. Should be set from overloaded init() method.

◆ txPacketSize

unsigned int usbd::UsbEndpoint::txPacketSize

Size of TX data buffer. Must be multiple of txPacketSize. May be set from overloaded init() method.


The documentation for this class was generated from the following files:
usbd::UsbEndpoint
USB endpoint base class.
Definition: usb-endpoint.cpp:49
usbd::UsbEndpoint::rxComplete
virtual void rxComplete(int length)
Definition: usb-endpoint.cpp:154
usbd::UsbEndpoint::startTx
void startTx(int length)
Definition: usb-device.cpp:193
usbd::UsbEndpoint::txBufferPtr
unsigned char * txBufferPtr
Definition: usb-endpoint.cpp:74
usbd::UsbEndpoint::txBufferSize
unsigned int txBufferSize
Definition: usb-endpoint.cpp:81
usbd::UsbEndpoint::rxBufferPtr
unsigned char * rxBufferPtr
Definition: usb-endpoint.cpp:55
usbd::UsbEndpoint::rxBufferSize
unsigned int rxBufferSize
Definition: usb-endpoint.cpp:62
usbd::UsbEndpoint::init
virtual void init()
Definition: usb-endpoint.cpp:124