Jump to main content

##

# 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:

1. Application-specific initialization should be integrated into the `APP_Initialize` function (located in the `app.c` file). The `APP_Initialize` function is invoked from the `SYS_Initialize` function upon the device exiting Power-on Reset (POR).

2. Application logic, implemented as a state machine, resides in the `APP_Tasks` function (in the `app.c` file). This logic can interact with function drivers and the Device Layer through available API calls.

3. Device events can be tracked by processing them in the application USB device event handler function (`APP_USBDeviceEventHandler` function in `app.c`).