USB Component  Version 6.4
MDK-Professional Middleware for USB Device and Host
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
Custom Class Functions

Implement application specific behavior of a Custom Class USB Device. More...

Content

 Configuration
 Configuration of the USB Device Custom Class in µVision.
 

Functions

void USBD_CustomClassn_Initialize (void)
 Called during USBD_Initialize to initialize the USB Custom class Device.
 
void USBD_CustomClassn_Uninitialize (void)
 Called during USBD_Uninitialize to de-initialize the USB Custom class Device.
 
void USBD_CustomClassn_EventReset (void)
 Custom Class Reset Event handling.
 
void USBD_CustomClassn_EventEndpointStart (uint8_t ep_addr)
 Custom Class Endpoint Start Event handling.
 
void USBD_CustomClassn_EventEndpointStop (uint8_t ep_addr)
 Custom Class Endpoint Stop Event handling.
 
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

Implement application specific behavior of a Custom Class USB Device.

The Custom Class in the USB Component may be used to implement any type of USB Device class.

Refer to:

The USB Component allows multiple instances of the Custom class. This feature may be used to create USB Composite Devices. Each Custom Class instance has separate files and interface functions:

This documentation uses n as a placeholder for the instance number 0 - 3. Most applications require only one instance of a Custom Class. For the first Custom Class instance the instance number is 0:

Software Structure

The handling of the Custom Class endpoint events is implemented in an USBD_CustomClassn_Endpointx_Event for every endpoint. Each endpoint (or pair of IN/OUT endpoints with the same endpoint number) uses an own thread in order to allow a parallel functionality of every interface.

Setup Packets on Endpoint 0

Setup packets sent to endpoint 0 are received by the USB Core. The USB Core will call the USBD_CustomClassn_Endpoint0_SetupPacketReceived function and pass the application the setup packet. Depending on the return code of USBD_CustomClassn_Endpoint0_SetupPacketReceived, the USB Core either continues to handle the setup packet or passes the complete processing to the user application.

If the USB Core continues to process the setup packet, it will call USBD_CustomClassn_Endpoint0_SetupPacketProcessed to inform the application about the processed setup packet.

If the application continues processing the setup packet, the USB Core uses the functions USBD_CustomClassn_Endpoint0_OutDataReceived and USBD_CustomClassn_Endpoint0_InDataSent to signal that the data has been received or sent (depending on the setup packet itself).

msc_inline_mscgraph_3

Implementation

To create an USB Device with a Custom Class:

User Code Templates

Two user code templates are available to implement the application specific behavior:

Both user code templates contain example code that can be used to demonstrate the features of the templates. Uncomment this code to see how it works on your target hardware.

USBD_User_CustomClass.c

/*------------------------------------------------------------------------------
* MDK Middleware - Component ::USB:Device
* Copyright (c) 2004-2015 ARM Germany GmbH. All rights reserved.
*------------------------------------------------------------------------------
* Name: USBD_User_CustomClass_n.c
* Purpose: USB Device Custom Class User module
* Rev.: V6.4.0
*----------------------------------------------------------------------------*/
/*
* USBD_User_CustomClass_n.c is a code template for the Custom Class n
* class request handling. It allows user to handle all Custom Class class
* requests.
*
* Uncomment "Example code" lines to see example that receives data on
* Endpoint 1 OUT and echoes it back on Endpoint 1 IN.
* To try the example you also have to enable Bulk Endpoint 1 IN/OUT in Custom
* Class configuration in USBD_Config_CustomClass_n.h file.
*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "rl_usb.h"
#include "Driver_USBD.h"
//uint8_t classn_bulk_buf[64] = { 0 };
// \brief Called during USBD_Initialize to initialize the USB Custom class Device
// Handle Custom Class Initialization
}
// \brief Called during USBD_Uninitialize to un-initialize the USB Custom class Device
// Handle Custom Class De-initialization
}
// \brief Custom Class Reset Event handling
// Handle USB Bus Reset Event
}
// \brief Custom Class Endpoint Start Event handling
// \param[in] ep_addr endpoint address.
void USBD_CustomClassn_EventEndpointStart (uint8_t ep_addr) {
// Start communication on Endpoint
// // Example code start reception on Endpoint 1 OUT:
// if (ep_addr == USB_ENDPOINT_OUT(1)) {
// USBD_EndpointRead(0, USB_ENDPOINT_OUT(1), classn_bulk_buf, 64);
// }
}
// \brief Custom Class Endpoint Stop Event handling
// \param[in] ep_addr endpoint address.
void USBD_CustomClassn_EventEndpointStop (uint8_t ep_addr) {
// Handle Endpoint communication stopped
}
// \brief Callback function called when Custom Class n received SETUP PACKET on Control Endpoint 0
// (this callback will be called only for Class Requests (USB_REQUEST_CLASS) if it was not processed
// previously by Device callback)
// \param[in] setup_packet pointer to received setup packet.
// \param[out] buf pointer to data buffer used for data stage requested by setup packet.
// \param[out] len pointer to number of data bytes in data stage requested by setup packet.
// \return usbdRequestStatus enumerator value indicating the function execution status
// \return usbdRequestNotProcessed:request was not processed; processing will be done by USB library
// \return usbdRequestOK: request was processed successfully (send Zero-Length Packet if no data stage)
// \return usbdRequestStall: request was processed but is not supported (stall Endpoint 0)
usbdRequestStatus USBD_CustomClassn_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, int32_t *len) {
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;
}
}
// \brief Callback function called when Custom Class n SETUP PACKET was processed by USB library
// (this callback will be called only for Class Requests (USB_REQUEST_CLASS) if it was not processed
// previously by Device callback)
// \param[in] setup_packet pointer to processed setup packet.
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;
}
}
// \brief Callback function called when Custom Class n received OUT DATA on Control Endpoint 0
// (this callback will be called only for Class Requests (USB_REQUEST_CLASS) if it was not processed
// previously by Device callback)
// \param[in] len number of received data bytes.
// \return usbdRequestStatus enumerator value indicating the function execution status
// \return usbdRequestNotProcessed:request was not processed; processing will be done by USB library
// \return usbdRequestOK: request was processed successfully (send Zero-Length Packet)
// \return usbdRequestStall: request was processed but is not supported (stall Endpoint 0)
// \return usbdRequestNAK: request was processed but the device is busy (return NAK)
usbdRequestStatus USBD_CustomClassn_Endpoint0_OutDataReceived (uint32_t len) {
}
// \brief Callback function called when Custom Class n sent IN DATA on Control Endpoint 0
// (this callback will be called only for Class Requests (USB_REQUEST_CLASS) if it was not processed
// previously by Device callback)
// \param[in] len number of sent data bytes.
// \return usbdRequestStatus enumerator value indicating the function execution status
// \return usbdRequestNotProcessed:request was not processed; processing will be done by USB library
// \return usbdRequestOK: request was processed successfully (return ACK)
// \return usbdRequestStall: request was processed but is not supported (stall Endpoint 0)
// \return usbdRequestNAK: request was processed but the device is busy (return NAK)
usbdRequestStatus USBD_CustomClassn_Endpoint0_InDataSent (uint32_t len) {
}
// \brief Callback function called when DATA was sent or received on Endpoint n
// \param[in] event event on Endpoint:
// - ARM_USBD_EVENT_OUT = data OUT received
// - ARM_USBD_EVENT_IN = data IN sent
void USBD_CustomClassn_Endpoint1_Event (uint32_t event) {
// Handle Endpoint 1 events
if (event & ARM_USBD_EVENT_OUT) { // OUT event
// // Example code upon reception on Endpoint 1 OUT echo received data on
// // Endpoint 1 IN:
// USBD_EndpointWrite(0, USB_ENDPOINT_IN(1) , classn_bulk_buf, USBD_EndpointReadGetResult(0, USB_ENDPOINT_OUT(1)));
}
if (event & ARM_USBD_EVENT_IN) { // IN event
// // Example code after data was sent on Endpoint 1 IN restart data
// // reception on Endpoint 1 OUT:
// USBD_EndpointRead (0, USB_ENDPOINT_OUT(1), classn_bulk_buf, 64);
}
};
void USBD_CustomClassn_Endpoint2_Event (uint32_t event) {
// Handle Endpoint 2 events
};
void USBD_CustomClassn_Endpoint3_Event (uint32_t event) {
// Handle Endpoint 3 events
};
void USBD_CustomClassn_Endpoint4_Event (uint32_t event) {
// Handle Endpoint 4 events
};
void USBD_CustomClassn_Endpoint5_Event (uint32_t event) {
// Handle Endpoint 5 events
};
void USBD_CustomClassn_Endpoint6_Event (uint32_t event) {
// Handle Endpoint 6 events
};
void USBD_CustomClassn_Endpoint7_Event (uint32_t event) {
// Handle Endpoint 7 events
};
void USBD_CustomClassn_Endpoint8_Event (uint32_t event) {
// Handle Endpoint 8 events
};
void USBD_CustomClassn_Endpoint9_Event (uint32_t event) {
// Handle Endpoint 9 events
};
void USBD_CustomClassn_Endpoint10_Event (uint32_t event) {
// Handle Endpoint 10 events
};
void USBD_CustomClassn_Endpoint11_Event (uint32_t event) {
// Handle Endpoint 11 events
};
void USBD_CustomClassn_Endpoint12_Event (uint32_t event) {
// Handle Endpoint 12 events
};
void USBD_CustomClassn_Endpoint13_Event (uint32_t event) {
// Handle Endpoint 13 events
};
void USBD_CustomClassn_Endpoint14_Event (uint32_t event) {
// Handle Endpoint 14 events
};
void USBD_CustomClassn_Endpoint15_Event (uint32_t event) {
// Handle Endpoint 15 events
};

USBD_User_Device.c

/*------------------------------------------------------------------------------
* MDK Middleware - Component ::USB:Device
* Copyright (c) 2004-2015 ARM Germany GmbH. All rights reserved.
*------------------------------------------------------------------------------
* Name: USBD_User_Device_n.c
* Purpose: USB Device User module
* Rev.: V6.4.0
*----------------------------------------------------------------------------*/
/*
* USBD_User_Device_n.c is a code template for the user specific
* USB Control Endpoint 0 request handling. It allows user to intercept
* all Control Endpoint 0 requests and handle them overriding the default
* USB Library handling.
*
* Uncomment "Example code" lines to override USB Device Descriptor.
*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "rl_usb.h"
//const uint8_t devicen_dev_desc[] = {
// 18, /* bLength = 18 bytes */
// USB_DEVICE_DESCRIPTOR_TYPE, /* bDescriptorType = Device Desc */
// 0x00, 0x02, /* bcdUSB = 2.00 */
// 0x00, /* bDeviceClass = Defined in IF */
// 0x00, /* bDeviceSubClass = Defined in IF */
// 0x00, /* bDeviceProtocol = Defined in IF */
// 64, /* bMaxPacketSize0 = 64 bytes !!! Must be same as USBDn_MAX_PACKET0 in USBD_Config_n.c */
// 0x51, 0xC2, /* idVendor = 0xC251 */
// 0x01, 0x00, /* idProduct = 1 */
// 0x00, 0x01, /* bcdDevice = 1.00 */
// 0x01, /* iManufacturer = String1 */
// 0x02, /* iProduct = String2 */
// 0x03, /* iSerialNumber = String3 */
// 0x01 /* bNumConfigurations = 1 config */
//};
// \brief Called during USBD_Initialize to initialize the USB Device
void USBD_Devicen_Initialize (void) {
// Handle Device Initialization
}
// \brief Called during USBD_Uninitialize to un-initialize the USB Device
void USBD_Devicen_Uninitialize (void) {
// Handle Device De-initialization
}
// \brief Device Reset Event handling
void USBD_Devicen_EventReset (void) {
// Handle USB Bus Reset Event
}
// \brief Callback function called when Device n received SETUP PACKET on Control Endpoint 0
// \param[in] setup_packet pointer to received setup packet.
// \param[out] buf pointer to data buffer used for data stage requested by setup packet.
// \param[out] len pointer to number of data bytes in data stage requested by setup packet.
// \return usbdRequestStatus enumerator value indicating the function execution status
// \return usbdRequestNotProcessed:request was not processed; processing will be done by USB library
// \return usbdRequestOK: request was processed successfully (send Zero-Length Packet if no data stage)
// \return usbdRequestStall: request was processed but is not supported (stall Endpoint 0)
usbdRequestStatus USBD_Devicen_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, int32_t *len) {
switch (setup_packet->bmRequestType.Type) {
case USB_REQUEST_STANDARD:
// // Example code handling Get Device Descriptor request:
// if ((setup_packet->bmRequestType.Dir == USB_REQUEST_DEVICE_TO_HOST) &&
// (setup_packet->bmRequestType.Recipient == USB_REQUEST_TO_DEVICE ) &&
// (setup_packet->bRequest == USB_REQUEST_GET_DESCRIPTOR) &&
// (setup_packet->wValueH == USB_DEVICE_DESCRIPTOR_TYPE) &&
// (setup_packet->wIndex == 0 )) {
// *buf = (uint8_t *)devicen_dev_desc;
// *len = sizeof (devicen_dev_desc);
// return usbdRequestOK;
// }
break;
case USB_REQUEST_CLASS:
break;
case USB_REQUEST_VENDOR:
break;
case USB_REQUEST_RESERVED:
break;
}
}
// \brief Callback function called when Device n SETUP PACKET was processed by USB library
// \param[in] setup_packet pointer to processed setup packet.
void USBD_Devicen_Endpoint0_SetupPacketProcessed (const USB_SETUP_PACKET *setup_packet) {
switch (setup_packet->bmRequestType.Type) {
case USB_REQUEST_STANDARD:
break;
case USB_REQUEST_CLASS:
break;
case USB_REQUEST_VENDOR:
break;
case USB_REQUEST_RESERVED:
break;
}
}
// \brief Callback function called when Device n received OUT DATA on Control Endpoint 0
// \param[in] len number of received data bytes.
// \return usbdRequestStatus enumerator value indicating the function execution status
// \return usbdRequestNotProcessed:request was not processed; processing will be done by USB library
// \return usbdRequestOK: request was processed successfully (send Zero-Length Packet)
// \return usbdRequestStall: request was processed but is not supported (stall Endpoint 0)
// \return usbdRequestNAK: request was processed but the device is busy (return NAK)
usbdRequestStatus USBD_Devicen_Endpoint0_OutDataReceived (uint32_t len) {
}
// \brief Callback function called when Device n sent IN DATA on Control Endpoint 0
// \param[in] len number of sent data bytes.
// \return usbdRequestStatus enumerator value indicating the function execution status
// \return usbdRequestNotProcessed:request was not processed; processing will be done by USB library
// \return usbdRequestOK: request was processed successfully (return ACK)
// \return usbdRequestStall: request was processed but is not supported (stall Endpoint 0)
// \return usbdRequestNAK: request was processed but the device is busy (return NAK)
usbdRequestStatus USBD_Devicen_Endpoint0_InDataSent (uint32_t len) {
}

Function Documentation

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
usbdRequestNotProcessed:request was not processed; processing will be done by USB library
usbdRequestOK: request was processed successfully (return ACK)
usbdRequestStall: request was processed but is not supported (stall endpoint 0)
usbdRequestNAK: request was processed but the device is busy (return NAK)

The callback function USBD_CustomClassn_Endpoint0_InDataSent will be called by the USB 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.

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
usbdRequestNotProcessed:request was not processed; processing will be done by USB library
usbdRequestOK: request was processed successfully (send Zero-Length Packet)
usbdRequestStall: request was processed but is not supported (stall endpoint 0)
usbdRequestNAK: request was processed but the device is busy (return NAK)

The callback function USBD_CustomClassn_Endpoint0_OutDataReceived will be called by the USB 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.

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.
Returns
none.

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

Code Example

void USBD_CustomClass0_Endpoint0_SetupPacketProcessed (const USB_SETUP_PACKET *setup_packet) {
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;
}
}
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.
[out]bufpointer to data buffer used for data stage requested by setup packet.
[out]lenpointer to number of data bytes in data stage requested by setup packet.
Returns
usbdRequestStatus enumerator value indicating the function execution status
usbdRequestNotProcessed:request was not processed; processing will be done by USB library
usbdRequestOK: request was processed successfully (send Zero-Length Packet if no data stage)
usbdRequestStall: request was processed but is not supported (STALL EP)

The callback function USBD_CustomClassn_Endpoint0_SetupPacketReceived function will be called by the USB Core when a setup packet has been received. Further handling by the USB 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;
}
}
void USBD_CustomClassn_Endpoint10_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint11_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint12_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint13_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint14_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint15_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

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 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) {
}
}
void USBD_CustomClassn_Endpoint2_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint3_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint4_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint5_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint6_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint7_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint8_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_Endpoint9_Event ( uint32_t  event)

Refer to USBD_CustomClassn_Endpoint1_Event for more information

void USBD_CustomClassn_EventEndpointStart ( uint8_t  ep_addr)

Custom Class Endpoint Start Event handling.

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

The function USBD_CustomClassn_EventEndpointStart 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;
}
}
}
void USBD_CustomClassn_EventEndpointStop ( uint8_t  ep_addr)

Custom Class Endpoint Stop Event handling.

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

The function USBD_CustomClassn_EventEndpointStop 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;
}
}
}
void USBD_CustomClassn_EventReset ( void  )

Custom Class Reset Event handling.

Returns
none.

The function USBD_CustomClassn_EventReset 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.

void USBD_CustomClassn_Initialize ( void  )

Called during USBD_Initialize to initialize the USB Custom class Device.

Returns
none.

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
..
}
void USBD_CustomClassn_Uninitialize ( void  )

Called during USBD_Uninitialize to de-initialize the USB Custom class Device.

Returns
none.

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
..
}
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.

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 data on an endpoint.

The argument device specifies the USB Device instance.

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

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

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

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.

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]stallfalse = Clear stall, 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.

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
[out]bufbuffer containing data bytes to write.
[in]lenmaximum number of bytes to write.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBD_EndpointWrite writes data to an endpoint.

The argument device specifies the USB Device instance.

The argument ep_addr specifies the 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.

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.