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

Enable the USB Host to support Custom Class Devices. More...

Functions

int8_t USBH_CustomClass_Configure (USBH_DEV *ptr_dev, USB_CONFIGURATION_DESCRIPTOR *ptr_cfg_desc)
 Callback function called when custom class device is connected and needs to configure resources used by custom class device instance.
 
usbStatus USBH_CustomClass_Unconfigure (int8_t instance)
 Callback function called when custom class device is disconnected and needs to unconfigure resources used by custom class device instance.
 
usbStatus USBH_CustomClass_Initialize (int8_t instance)
 Callback function called when custom class device is connected and needs to initialize custom class device instance.
 
usbStatus USBH_CustomClass_Uninitialize (int8_t instance)
 Callback function called when custom class device is disconnected and needs to uninitialize custom class device instance.
 

Description

Enable the USB Host to support Custom Class Devices.

The Custom Class in the USB Host Component is used for attaching USB Devices with a specific USB Class to your system. This can either be one of the standard classes that are not directly supported by the Middleware or a vendor specific custom class. Using these functions, you can add support for any USB Device class to the system.

Refer to:

To create an USB Host with support for the Custom class:

Configuration File USBH_Config_CustomClass.h
The USB Host Component has one configuration file for the Custom Device class: USBH_Config_CustomClass.h. This configuration file defines the maximum number of concurrent Custom Class Devices that may be attached to the system.

Code Example

#include <stdint.h>
#include "rl_usbh.h"
// These commented variable declarations are a part of example code
// uint8_t ctrl;
// ARM_USBH_EP_HANDLE ep_hndl;
int8_t USBH_CustomClass_Configure (USBH_DEV *ptr_dev, USB_CONFIGURATION_DESCRIPTOR *ptr_cfg_desc) {
// Add code for configuring device
//
// for example add endpoint to system:
//
// USB_ENDPOINT_DESCRIPTOR *ptr_ep_desc;
// ctrl = ptr_dev->ctrl;
// ptr_ep_desc = (USB_ENDPOINT_DESCRIPTOR *)((uint32_t)ptr_if_desc + ptr_if_desc->bLength);
// ep_hndl = USBH_DriverEndpointCreate (ptr_dev->ctrl, ptr_dev->dev_addr, ptr_dev->dev_speed, 0, 0, ptr_ep_desc->bEndpointAddress, ptr_ep_desc->bmAttributes & USB_ENDPOINT_TYPE_MASK, ptr_ep_desc->wMaxPacketSize & 0x7FF, ptr_ep_desc->bInterval);
return 0;
}
usbStatus USBH_CustomClass_Unconfigure (int8_t instance) {
// Add code for unconfiguring device
//
// for example delete endpoint from system:
//
// USBH_DriverEndpointDelete (ctrl, ep_hndl)
return usbOK;
}
usbStatus USBH_CustomClass_Initialize (int8_t instance) {
// Add code for initializing device
return usbOK;
}
usbStatus USBH_CustomClass_Uninitialize (int8_t instance) {
// Add code for de-initializing device
return usbOK;
}

Function Documentation

int8_t USBH_CustomClass_Configure ( USBH_DEV ptr_dev,
USB_CONFIGURATION_DESCRIPTOR *  ptr_cfg_desc 
)

Callback function called when custom class device is connected and needs to configure resources used by custom class device instance.

Parameters
[in]ptr_devpointer to device structure.
[in]ptr_cfg_descpointer to configuration descriptor.
Returns
value >= 0 index of configured custom class device instance.
value < 0 configuration failed.

The function USBH_Class_Configure should create all necessary endpoints for the custom class. It needs to be adapted to the specific needs of the Custom Class that is to be supported. For more information on the USB_CONFIGURATION_DESCRIPTOR, please refer to Configuration Descriptor.

The argument ptr_dev specifies the pointer to the connected device.

The argument ptr_cfg_desc specifies the pointer to the configuration descriptor of the Custom Class.

usbStatus USBH_CustomClass_Initialize ( int8_t  instance)

Callback function called when custom class device is connected and needs to initialize custom class device instance.

Parameters
[in]instanceindex of custom class device instance.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_Class_Initialize initializes the Custom Class device when connected to the system. It needs to be adapted to the specific needs of the Custom Class that is to be supported.

The argument instance specifies device instance of the Custom Class USB Device.

usbStatus USBH_CustomClass_Unconfigure ( int8_t  instance)

Callback function called when custom class device is disconnected and needs to unconfigure resources used by custom class device instance.

Parameters
[in]instanceindex of custom class device instance.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_Class_Unconfigure should release all resources that were used by the Custom Class device after it has been uninitialized using USBH_CustomClass_Uninitialize. All endpoints relating to the Custom Class should be removed. It needs to be adapted to the specific needs of the Custom Class that is to be supported.

The argument instance specifies device instance of the Custom Class USB Device.

usbStatus USBH_CustomClass_Uninitialize ( int8_t  instance)

Callback function called when custom class device is disconnected and needs to uninitialize custom class device instance.

Parameters
[in]instanceindex of custom class device instance.
Returns
status code that indicates the execution status of the function as defined with usbStatus.

The function USBH_Class_Uninitialize uninitializes the Custom Class device after it has been disconnected from the system. It needs to be adapted to the specific needs of the Custom Class that is to be supported.

The argument instance specifies device instance of the Custom Class USB Device.