3.10 Vendor - How to use
This section guides the user to set up and use the vendor class on the Microchip® USB Device Stack. It includes example usage of functions to implement the vendor class on a USB device.
The stack includes functions to help set up and use the vendor class following the provided guidelines. Using these is highly recommended, to avoid unexpected behavior when using Microchip® devices. The vendor class supports control, interrupt, isochronous and bulk transfer, allowing for versatility.
Before starting on a USB vendor project, consider if any of the other classes meet the requirement for the application. In most cases, it is better to use a specific USB class rather than a default vendor class. If none of the other standards meet the requirements, the vendor class implementation might be considered the best option.
The fastest way to implement the vendor class on any device is to use MCC Melody to set up the USB vendor class for any project. This can be done in a few steps:
- Create a new project in MPLAB® X IDE
- Import the USB Device Stack from the UI
- From the USB Device Tab, Select the USB vendor class
- Configure the vendor class settings according to project requirements if necessary
- Click “Generate”
It is also possible to enable the vendor class manually by creating your own project and adding the necessary code. This however requires more work than the MCC Melody code generation.
When writing the project code manually, it is important to note that the USB descriptor
is an important part of USB communication, and needs to be set up correctly for the USB
Device Stack to operate properly. For the vendor class, it is necessary to set the USB
descriptors ID to 0xFF
to signal a vendor class being used, which is
done by setting the structureUSB_DEVICE_DESCRIPTOR_t
’s
bDeviceClass
value. This notifies the host system about the
device’s vendor-specific class, prompting it to refer to the corresponding
vendor-specific drivers for device communication.
The next step is to communicate to the stack that the Vendor class is used. The USB
stack includes a USB_VendorClassInit()
helper function to easily
initialize the class for the user, with the three input arguments, each one a callback
to functions for enabling the interface, vendor control function and for disabling the
interface. Each of these three callback functions might be necessary to set up,
depending on which callbacks will be necessary in the code.
Upon successful initialization, the generic function driver interface activates and
configures all attached endpoints. These are primed and set ready for data transfers
upon receipt of the USB_DEVICE_EVENT_CONFIGURED
event.
Note that unlike standard USB class drivers, the device layer does not automatically manage endpoints for vendor interface. This means that the application must maintain all active endpoints belonging to that interface in the correct configuration (e.g., bulk, interrupt). This involves enabling the endpoints for the desired transfer type according to pending transfers, and disabling them when a USB reset is received or when the configuration is changed.