Starting USB stack in host and device modes

Your configuration file must contain commands for launching the USB stack in each of the host and device modes if you want to support USB On-The-Go (OTG). Switching stack modes dynamically allows for creating devices capable of acting as either a USB host or a USB device, without requiring separate USB controllers and ports.

The rules.lua configuration file shipped with the platform contains sample rules for launching the USB stack in both the host and device modes:

Host_Stack = {
    cmd  = 'io-usb -c -d ehci-mx28 ioport=0x02184100,irq=75,\z
    path = '/dev/otg/io-usb';

dofile '/etc/usblauncher/iap2.lua'
dofile '/etc/usblauncher/iap2ncm.lua'
dofile '/etc/usblauncher/umass.lua'

Device_Stack = {
    cmd  = 'io-usb-dcd -d iap2-mx6sabrelite-ci \z
    path = '/dev/otg/io-usb-dcd';
    descriptors = { iap2, iap2ncm, umass };

These rules contain the following fields:

Stores the command line for starting the stack in a particular mode. The command line consists of the process name followed by hardware-specific options for configuring the stack. This excerpt shows the options for the i.MX6Q SABRE Lite platform; your system might use different options depending on the board you're running on. You can find information on all options supported by the host and device stacks in the io-usb and io-usb-dcd references.
Provides the full path of the USB stack service. In this release, there are separate services for the host and device modes.
The usblauncher service appends the stack path to the string in cmd by using the -n option; it's not necessary to provide this option in cmd when using a nondefault path.
Optional and used only with device mode.
Lists USB descriptors that your system can expose to a USB host. Each descriptor specifies a set of hardware and connection properties based on a particular device function (e.g., mass storage, serial data transfer). These descriptors override the default descriptors compiled into the USB device stack.
Note: The dofile statements that include the configuration files containing the descriptors must be placed above the Device_Stack rule to make them visible in the descriptors list.
Based on the device function you want your system to support, you can select a descriptor by sending the start_stack::device,n command to the device control object. Here, n is a one-based index in the descriptors list (i.e., 1 refers to the first list entry). If you don't define the descriptors list or you provide an out-of-bounds index or no index in the start_stack command, the compiled-in descriptors (but no overridden descriptors) are used.
You can use the RoleSwap_AppleDevice and RoleSwap_DigitaliPodOut flags to enable client-mode iAP2 and the CarPlay application. Both these flags cause usblauncher to restart the stack in device mode and expose a different set of descriptors. For RoleSwap_AppleDevice, usblauncher uses the first item in the list; for RoleSwap_DigitaliPodOut, it uses the second item. For more information on these flags, see "Supported third-party applications and protocols".