USB Component  
MDK Middleware for USB Device and Host Communication
 
Loading...
Searching...
No Matches

User API reference of the Custom Device Class. More...

Functions

void USBD_CustomClassn_Initialize (void)
 Callback function called during USBD_Initialize to initialize the USB Custom class instance.
 
void USBD_CustomClassn_Uninitialize (void)
 Callback function called during USBD_Uninitialize to de-initialize the USB Custom class instance.
 
void USBD_CustomClassn_Reset (void)
 Callback function called upon USB Bus Reset signaling.
 
void USBD_CustomClassn_EndpointStart (uint8_t ep_addr)
 Callback function called when Endpoint Start was requested (by activating interface or configuration)
 
void USBD_CustomClassn_EndpointStop (uint8_t ep_addr)
 Callback function called when Endpoint Stop was requested (by de-activating interface or activating configuration 0)
 
usbdRequestStatus USBD_CustomClassn_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, uint32_t *len)
 Callback function called when a SETUP PACKET was received on Control Endpoint 0.
 
void USBD_CustomClassn_Endpoint0_SetupPacketProcessed (const USB_SETUP_PACKET *setup_packet)
 Callback function called when a SETUP PACKET was processed by USB library.
 
usbdRequestStatus USBD_CustomClassn_Endpoint0_OutDataReceived (uint32_t len)
 Callback function called when OUT DATA was received on Control Endpoint 0.
 
usbdRequestStatus USBD_CustomClassn_Endpoint0_InDataSent (uint32_t len)
 Callback function called when IN DATA was sent on Control Endpoint 0.
 
void USBD_CustomClassn_Endpoint1_Event (uint32_t event)
 Callback function called when DATA was sent or received on Endpoint n.
 
void USBD_CustomClassn_Endpoint2_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint3_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint4_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint5_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint6_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint7_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint8_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint9_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint10_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint11_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint12_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint13_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint14_Event (uint32_t event)
 
void USBD_CustomClassn_Endpoint15_Event (uint32_t event)
 
usbStatus USBD_EndpointRead (uint8_t device, uint8_t ep_addr, uint8_t *buf, uint32_t len)
 Start reception on Endpoint.
 
uint32_t USBD_EndpointReadGetResult (uint8_t device, uint8_t ep_addr)
 Get result of read operation on Endpoint.
 
usbStatus USBD_EndpointWrite (uint8_t device, uint8_t ep_addr, const uint8_t *buf, uint32_t len)
 Start write on Endpoint.
 
uint32_t USBD_EndpointWriteGetResult (uint8_t device, uint8_t ep_addr)
 Get result of write operation on Endpoint.
 
usbStatus USBD_EndpointStall (uint8_t device, uint8_t ep_addr, bool stall)
 Set/Clear stall on Endpoint.
 
usbStatus USBD_EndpointAbort (uint8_t device, uint8_t ep_addr)
 Abort read/write operation on Endpoint.
 

Description

User API reference of the Custom Device Class.

Function Documentation

◆ USBD_CustomClassn_Endpoint0_InDataSent()

usbdRequestStatus USBD_CustomClassn_Endpoint0_InDataSent ( uint32_t  len)

Callback function called when IN DATA was sent on Control Endpoint 0.

Parameters
[in]lennumber of sent data bytes.
Returns
usbdRequestStatus enumerator value indicating the function execution status :
  • value usbdRequestNotProcessed : request was not processed; processing will be done by USB library
  • value usbdRequestOK : request was processed successfully (return ACK)
  • value usbdRequestStall : request was processed but is not supported (stall endpoint 0)
  • value usbdRequestNAK : request was processed but the device is busy (return NAK)

The callback function USBD_CustomClassn_Endpoint0_InDataSent will be called by the USB Device Core when data is available for further processing by the application (the return code of a previous USBD_CustomClassn_Endpoint0_SetupPacketReceived was usbdRequestOK).

The argument len determines the length of the data that is sent.

◆ USBD_CustomClassn_Endpoint0_OutDataReceived()

usbdRequestStatus USBD_CustomClassn_Endpoint0_OutDataReceived ( uint32_t  len)

Callback function called when OUT DATA was received on Control Endpoint 0.

Parameters
[in]lennumber of received data bytes.
Returns
usbdRequestStatus enumerator value indicating the function execution status :
  • value usbdRequestNotProcessed : request was not processed; processing will be done by USB library
  • value usbdRequestOK : request was processed successfully (send Zero-Length Packet)
  • value usbdRequestStall : request was processed but is not supported (stall endpoint 0)
  • value usbdRequestNAK : request was processed but the device is busy (return NAK)

The callback function USBD_CustomClassn_Endpoint0_OutDataReceived will be called by the USB Device Core when data is available for further processing by the application (the return code of a previous USBD_CustomClassn_Endpoint0_SetupPacketReceived was usbdRequestOK).

The argument len determines the length of the data that is received.

◆ USBD_CustomClassn_Endpoint0_SetupPacketProcessed()

void USBD_CustomClassn_Endpoint0_SetupPacketProcessed ( const USB_SETUP_PACKET setup_packet)

Callback function called when a SETUP PACKET was processed by USB library.

Parameters
[in]setup_packetpointer to processed setup packet.

The callback function USBD_CustomClassn_Endpoint0_SetupPacketProcessed SetupPacketProcessed will be called by the USB Device Core when a setup packet was processed by the USB Device Core. This callback function acts as a notification only, so it has no return value.

Code Example

switch (setup_packet->bmRequestType.Type & 3) {
case USB_REQUEST_STANDARD:
break;
case USB_REQUEST_CLASS:
switch (setup_packet->bmRequestType.Recipient) {
case USB_REQUEST_TO_DEVICE:
break;
case USB_REQUEST_TO_INTERFACE:
break;
case USB_REQUEST_TO_ENDPOINT:
break;
default:
break;
}
break;
case USB_REQUEST_VENDOR:
break;
case USB_REQUEST_RESERVED:
break;
}
}

◆ USBD_CustomClassn_Endpoint0_SetupPacketReceived()

usbdRequestStatus USBD_CustomClassn_Endpoint0_SetupPacketReceived ( const USB_SETUP_PACKET setup_packet,
uint8_t **  buf,
uint32_t *  len 
)

Callback function called when a SETUP PACKET was received on Control Endpoint 0.

Parameters
[in]setup_packetpointer to received setup packet.
[in,out]bufpointer to data buffer used for data stage requested by setup packet.
[in,out]lenpointer to number of data bytes in data stage requested by setup packet.
Returns
usbdRequestStatus enumerator value indicating the function execution status :
  • value usbdRequestNotProcessed : request was not processed; processing will be done by USB library
  • value usbdRequestOK : request was processed successfully (send Zero-Length Packet if no data stage)
  • value usbdRequestStall : request was processed but is not supported (STALL EP)

The callback function USBD_CustomClassn_Endpoint0_SetupPacketReceived function will be called by the USB Device Core when a setup packet has been received. Further handling by the USB Device Core is determined by the return code of this callback function.

The argument setup_packet specifies the setup packet that has been received.

The argument buf specifies the buffer for the data stage (in case the application will continue to process the setup packet)

The argument len specifies the length of the data for the data stage.

Code Example

usbdRequestStatus USBD_CustomClass0_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, int32_t *len) {
switch (setup_packet->bmRequestType.Type & 3) {
case USB_REQUEST_STANDARD:
break;
case USB_REQUEST_CLASS:
switch (setup_packet->bmRequestType.Recipient) {
case USB_REQUEST_TO_DEVICE:
break;
case USB_REQUEST_TO_INTERFACE:
break;
case USB_REQUEST_TO_ENDPOINT:
break;
default:
break;
}
break;
case USB_REQUEST_VENDOR:
break;
case USB_REQUEST_RESERVED:
break;
}
}

◆ USBD_CustomClassn_Endpoint10_Event()

void USBD_CustomClassn_Endpoint10_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint11_Event()

void USBD_CustomClassn_Endpoint11_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint12_Event()

void USBD_CustomClassn_Endpoint12_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint13_Event()

void USBD_CustomClassn_Endpoint13_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint14_Event()

void USBD_CustomClassn_Endpoint14_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint15_Event()

void USBD_CustomClassn_Endpoint15_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint1_Event()

void USBD_CustomClassn_Endpoint1_Event ( uint32_t  event)

Callback function called when DATA was sent or received on Endpoint n.

Parameters
[in]eventevent on Endpoint :
  • ARM_USBD_EVENT_OUT = data OUT received
  • ARM_USBD_EVENT_IN = data IN sent

The callback function USBD_CustomClassn_Endpoint1_Event is called by the USB Device Core when an event happens on endpoint 1. This function can use the USBD_EndpointRead, USBD_EndpointWrite, USBD_EndpointStall and USBD_EndpointAbort functions.

The argument event specifies the event on the endpoint. Code Example

void USBD_CustomClass0_Endpoint1_Event (uint32_t event) {
uint32_t i;
if (event & ARM_USBD_EVENT_OUT) {
class0_bulk_len = USBD_EndpointReadGetResult (0, 0x01);
USBD_EndpointRead(0, 0x01, class0_bulk_out_buf, 64);
switch (class0_bulk_out_buf[0]) {
case 0:
for (i = 1; i < class0_bulk_len; i++) {
class0_bulk_in_buf[i] = (class0_bulk_out_buf[i] << 4);
}
USBD_EndpointWrite(0, 0x81, class0_bulk_in_buf, class0_bulk_len);
break;
}
}
if (event & ARM_USBD_EVENT_IN) {
}
}
Note
If USB driver uses DMA and USB buffer for incoming data (OUT transfers) is in cached (write-back policy) memory, please ensure that buffer is aligned correctly and that it's size is as required by cache handling. For example Cortex-M7 cache handling requires that this buffer is aligned on 32 byte and that it's size is multiple of 32 bytes (cache line size).

◆ USBD_CustomClassn_Endpoint2_Event()

void USBD_CustomClassn_Endpoint2_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint3_Event()

void USBD_CustomClassn_Endpoint3_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint4_Event()

void USBD_CustomClassn_Endpoint4_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint5_Event()

void USBD_CustomClassn_Endpoint5_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint6_Event()

void USBD_CustomClassn_Endpoint6_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint7_Event()

void USBD_CustomClassn_Endpoint7_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint8_Event()

void USBD_CustomClassn_Endpoint8_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_Endpoint9_Event()

void USBD_CustomClassn_Endpoint9_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

◆ USBD_CustomClassn_EndpointStart()

void USBD_CustomClassn_EndpointStart ( uint8_t  ep_addr)

Callback function called when Endpoint Start was requested (by activating interface or configuration)

Parameters
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction

The function USBD_CustomClassn_EndpointStart is called for each endpoint that is a part of an activated interface of a Custom Class. Start data reception (USBD_EndpointRead) here, if the enabled endpoint is of type OUT.

The argument ep_addr determines the endpoint that is to be started. Code Example

void USBD_CustomClass0_EventEndpointStart (uint8_t ep_addr) {
if (!(ep_addr & 0x80)) { // If Endpoint type is OUT
switch (ep_addr & 0x0F) {
case 1:
USBD_EndpointRead(0, ep_addr, class0_bulk_out_buf, 64);
break;
default:
break;
}
}
}

◆ USBD_CustomClassn_EndpointStop()

void USBD_CustomClassn_EndpointStop ( uint8_t  ep_addr)

Callback function called when Endpoint Stop was requested (by de-activating interface or activating configuration 0)

Parameters
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction

The function USBD_CustomClassn_EndpointStop is called for each endpoint that is a part of an deactivated interface of a Custom Class.

Code Example

void USBD_CustomClass0_EventEndpointStop (uint8_t ep_addr) {
if (!(ep_addr & 0x80)) { // If Endpoint type is OUT
switch (ep_addr & 0x0F) {
case 1:
USBD_EndpointAbort(0, ep_addr);
break;
default:
break;
}
}
}

◆ USBD_CustomClassn_Initialize()

void USBD_CustomClassn_Initialize ( void  )

Callback function called during USBD_Initialize to initialize the USB Custom class instance.

The function USBD_CustomClassn_Initialize is called when the USB Device containing the custom class is initialized. This function should be adapted to clear all variables and to setup all required interfaces.

Code Example

#include "rl_usb.h"
int main (void) {
..
USBD_Initialize (0); // USB Device 0 Initialization
...
USBD_Uninitialize (0); // USB Device 0 De-Initialization
..
}

◆ USBD_CustomClassn_Reset()

void USBD_CustomClassn_Reset ( void  )

Callback function called upon USB Bus Reset signaling.

The function USBD_CustomClassn_Reset is called when a reset condition happens on the USB bus. Initialization of the instance's local parameters and variables should be done in this function.

◆ USBD_CustomClassn_Uninitialize()

void USBD_CustomClassn_Uninitialize ( void  )

Callback function called during USBD_Uninitialize to de-initialize the USB Custom class instance.

The function USBD_CustomClassn_Uninitialize is called when the USB Device containing the custom class is uninitialized and needs no invocation in the user code. If USBD_CustomClassn_Initialize has been adapted to the application, USBD_CustomClassn_Uninitialize should release resources and should de-initialize interfaces and peripherals.

Code Example

#include "rl_usb.h"
int main (void) {
..
USBD_Initialize (0); // USB Device 0 Initialization
...
USBD_Uninitialize (0); // USB Device 0 De-Initialization
..
}

◆ USBD_EndpointAbort()

usbStatus USBD_EndpointAbort ( uint8_t  device,
uint8_t  ep_addr 
)

Abort read/write operation on Endpoint.

Parameters
[in]deviceindex of USB Device.
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBD_EndpointAbort aborts the transfer on an endpoint.

The argument device specifies the USB Device instance.

The argument ep_addr specifies the endpoint address.

◆ USBD_EndpointRead()

usbStatus USBD_EndpointRead ( uint8_t  device,
uint8_t  ep_addr,
uint8_t *  buf,
uint32_t  len 
)

Start reception on Endpoint.

Parameters
[in]deviceindex of USB Device.
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction
[out]bufbuffer that receives data.
[in]lenmaximum number of bytes to receive.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBD_EndpointRead starts the reception of a number of bytes specified by len on the OUT endpoint ep_addr to the buffer provided by buf. The reception is finished when either the requested number of bytes have been received or reception is terminated by reception of a short packet. When the reception is finished, the ARM_USBD_EVENT_OUT event is sent to the USBD_CustomClassn_Endpointx_Event thread (with x specifying the endpoint number that was used for the read (receive) operation).

USBD_EndpointReadGetResult() can be used to retrieve number of received bytes after receive operation has finished (event was sent).

The argument device specifies the USB Device instance.

The argument ep_addr specifies the OUT endpoint address for data reception.

The argument buf is pointing to the buffer for the data.

The argument len specifies the number of bytes to be read (must be multiple of endpoint maximum packet size).

◆ USBD_EndpointReadGetResult()

uint32_t USBD_EndpointReadGetResult ( uint8_t  device,
uint8_t  ep_addr 
)

Get result of read operation on Endpoint.

Parameters
[in]deviceindex of USB Device.
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction
Returns
number of bytes received.

The function USBD_EndpointReadGetResult gets number of received bytes on an endpoint.

The argument device specifies the USB Device instance.

The argument ep_addr specifies the endpoint address that carries the data.

◆ USBD_EndpointStall()

usbStatus USBD_EndpointStall ( uint8_t  device,
uint8_t  ep_addr,
bool  stall 
)

Set/Clear stall on Endpoint.

Parameters
[in]deviceindex of USB Device.
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction
[in]stalloperation :
  • value false : clear stall
  • value true : set stall
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBD_EndpointStall sets or clears stall on an endpoint.

The argument device specifies the USB Device instance.

The argument ep_addr specifies the endpoint address.

The argument stall specifies set or clear operation.

◆ USBD_EndpointWrite()

usbStatus USBD_EndpointWrite ( uint8_t  device,
uint8_t  ep_addr,
const uint8_t *  buf,
uint32_t  len 
)

Start write on Endpoint.

Parameters
[in]deviceindex of USB Device.
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction
[in]bufbuffer containing data bytes to write.
[in]lennumber of bytes to write.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBD_EndpointWrite starts the transmission of a number of bytes specified by len on the IN endpoint ep_addr from the buffer provided by buf. When the transmission is finished, the ARM_USBD_EVENT_IN event is sent to the USBD_CustomClassn_Endpointx_Event thread (with x specifying the endpoint number that was used for the write (transmit) operation).

The argument device specifies the USB Device instance.

The argument ep_addr specifies the IN endpoint address for sending the data.

The argument buf is pointing to the buffer containing the data.

The argument len specifies the number of bytes to be written.

◆ USBD_EndpointWriteGetResult()

uint32_t USBD_EndpointWriteGetResult ( uint8_t  device,
uint8_t  ep_addr 
)

Get result of write operation on Endpoint.

Parameters
[in]deviceindex of USB Device.
[in]ep_addrendpoint address :
  • ep_addr.0..3 : address
  • ep_addr.7 : direction
Returns
number of bytes written.

The function USBD_EndpointWriteGetResult gets number of sent bytes on an endpoint.

The argument device specifies the USB Device instance.

The argument ep_addr specifies the endpoint address for sending the data.