![]() |
USB Component
Version 6.0
MDK-Professional Middleware for USB Device and Host
|
Implement application specific behaviour of a Custom Class Interface. More...
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 un-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, int32_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 (int32_t len) |
Callback function called when OUT DATA was received on Control Endpoint 0. | |
usbdRequestStatus | USBD_CustomClassn_Endpoint0_InDataSent (int32_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 (int8_t device, uint8_t ep_addr, uint8_t *buf, uint32_t len) |
Start reception on Endpoint. | |
uint32_t | USBD_EndpointReadGetResult (int8_t device, const uint8_t ep_addr) |
Get result of read on Endpoint. | |
usbStatus | USBD_EndpointWrite (int8_t device, uint8_t ep_addr, const uint8_t *buf, uint32_t len) |
Start write on Endpoint. | |
uint32_t | USBD_EndpointWriteGetResult (int8_t device, const uint8_t ep_addr) |
Get result of write on Endpoint. | |
usbStatus | USBD_EndpointStall (int8_t device, uint8_t ep_addr, bool stall) |
Set/Clear stall on Endpoint. | |
usbStatus | USBD_EndpointAbort (int8_t device, uint8_t ep_addr) |
Abort operation read/write on Endpoint. | |
Implement application specific behaviour of a Custom Class Interface.
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:
To create an USB Device with a Custom Class:
Configuration File USBD_Config_CustomClass_n.h
The configuration file USBD_Config_CustomClass_n.h defines:
These settings are used to create the Interface Descriptor and Endpoint Descriptor of the related USB Device Class. It is important that the settings match the application specific behaviour in the related C source file USBD_User_CustomClass_n.c.
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 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).
The following source code is part of the user code template file. The application specific behaviour may be implemented using this code template.
usbdRequestStatus USBD_CustomClassn_Endpoint0_InDataSent | ( | int32_t | len | ) |
Callback function called when IN DATA was sent on Control Endpoint 0.
[in] | len | number of sent data bytes. |
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 | ( | int32_t | len | ) |
Callback function called when OUT DATA was received on Control Endpoint 0.
[in] | len | number of received data bytes. |
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.
[in] | setup_packet | pointer to processed setup packet. |
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
usbdRequestStatus USBD_CustomClassn_Endpoint0_SetupPacketReceived | ( | const USB_SETUP_PACKET * | setup_packet, |
uint8_t ** | buf, | ||
int32_t * | len | ||
) |
Callback function called when a SETUP PACKET was received on Control Endpoint 0.
[in] | setup_packet | pointer to received setup packet. |
[out] | buf | pointer to data buffer used for data stage requested by setup packet. |
[out] | len | pointer to number of data bytes in data stage requested by setup packet. |
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
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.
[in] | event | event on Endpoint:
|
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_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.
[in] | ep_addr | endpoint address.
|
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_CustomClassn_EventEndpointStop | ( | uint8_t | ep_addr | ) |
Custom Class Endpoint Stop Event handling.
[in] | ep_addr | endpoint address.
|
The function USBD_CustomClassn_EventEndpointStop is called for each endpoint that is a part of an deactivated interface of a Custom Class.
void USBD_CustomClassn_EventReset | ( | void | ) |
Custom Class Reset Event handling.
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.
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
void USBD_CustomClassn_Uninitialize | ( | void | ) |
Called during USBD_Uninitialize to un-initialize the USB Custom class Device.
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
usbStatus USBD_EndpointAbort | ( | int8_t | device, |
uint8_t | ep_addr | ||
) |
Abort operation read/write on Endpoint.
[in] | device | index of USB Device. |
[in] | ep_addr | endpoint address
|
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 | ( | int8_t | device, |
uint8_t | ep_addr, | ||
uint8_t * | buf, | ||
uint32_t | len | ||
) |
Start reception on Endpoint.
[in] | device | index of USB Device. |
[in] | ep_addr | endpoint address
|
[out] | buf | buffer that receives data. |
[in] | len | maximum number of bytes to receive. |
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 specifies the number of bytes to be read.
uint32_t USBD_EndpointReadGetResult | ( | int8_t | device, |
const uint8_t | ep_addr | ||
) |
Get result of read on Endpoint.
[in] | device | index of USB Device. |
[in] | ep_addr | endpoint address
|
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 | ( | int8_t | device, |
uint8_t | ep_addr, | ||
bool | stall | ||
) |
Set/Clear stall on Endpoint.
[in] | device | index of USB Device. |
[in] | ep_addr | endpoint address.
|
[in] | stall | false = Clear stall, true = Set stall. |
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 | ( | int8_t | device, |
uint8_t | ep_addr, | ||
const uint8_t * | buf, | ||
uint32_t | len | ||
) |
Start write on Endpoint.
[in] | device | index of USB Device. |
[in] | ep_addr | endpoint address
|
[out] | buf | buffer containing data bytes to write. |
[in] | len | maximum number of bytes to write. |
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 specifies the number of bytes to be written.
uint32_t USBD_EndpointWriteGetResult | ( | int8_t | device, |
const uint8_t | ep_addr | ||
) |
Get result of write on Endpoint.
[in] | device | index of USB Device. |
[in] | ep_addr | endpoint address
|
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.