2.1.4 Creating Your Own USB Device
The initial step in creating a USB device involves determining whether the desired device function aligns with any standard USB device class functions. Utilizing standard USB classes can be advantageous, given that major operating systems offer Host driver support for such devices. However, the application may opt against standard USB device class protocols due to associated overhead. In such cases, a Vendor USB device implementation becomes viable. Vendor USB devices can be created using USB Device Layer Endpoint functions, though custom USB host drivers are necessary for operation.
Identifying the Device Class
Once the device class is identified, it's recommended to utilize available demonstration applications as a starting point for development.
Using Available Library Demonstration Applications
The USB Device Application release package (usb_apps_device) includes a range of demonstration applications representing common USB devices. These applications can be easily customized to incorporate application-specific initialization and logic, typically implemented as a non-blocking state machine.
Initialization and Logic Implementation:
-
Application-specific initialization should be integrated into the
APP_Initialize
function (located in theapp.c
file). TheAPP_Initialize
function is invoked from theSYS_Initialize
function upon the device exiting Power-on Reset (POR). -
Application logic, implemented as a state machine, resides in the
APP_Tasks
function (in theapp.c
file). This logic can interact with function drivers and the Device Layer through available API calls. -
Device events can be tracked by processing them in the application USB device event handler function (
APP_USBDeviceEventHandler
function inapp.c
).