The user can interact with Raw Gadget by opening /dev/raw-gadget and issuing ioctl calls; see the comments in include/uapi/linux/usb/raw_gadget.h for details. Multiple Raw Gadget instances (bound to different UDCs) can be used at the same time.
A typical usage scenario of Raw Gadget:
/dev/raw-gadget.USB_RAW_IOCTL_INIT.USB_RAW_IOCTL_RUN.USB_RAW_IOCTL_EVENT_FETCH to receive events from Raw Gadget and react to those depending on what kind of USB gadget must be implemented.Note that some UDC drivers have fixed addresses assigned to endpoints, and therefore arbitrary endpoint addresses cannot be used in the descriptors. Nevertheless, Raw Gadget provides a UDC-agnostic way to write USB gadgets. Once USB_RAW_EVENT_CONNECT is received via USB_RAW_IOCTL_EVENT_FETCH, USB_RAW_IOCTL_EPS_INFO can be used to find out information about the endpoints that the UDC driver has. Based on that, userspace must choose UDC endpoints for the gadget and assign addresses in the endpoint descriptors correspondingly.
Raw Gadget usage examples and a test suite:
https://github.com/xairy/raw-gadget