How a class driver works

A class driver typically performs the following operations:

  1. Connect to the USB stack (usbd_connect()) and provide two callbacks: one for insertion and one for removal.
  2. In the insertion callback:
    1. Connect to the USB device (usbd_attach()).
    2. Get descriptors (usbd_descriptor()).
    3. Select the configuration (usbd_select_config()) and interface (usbd_select_interface()).
    4. Set up communications pipes to the appropriate endpoint (usbd_open_pipe()).
  3. In the removal callback, detach from the USB device (usbd_detach()).
  4. Set up all data communications (e.g. reading and writing data, sending and receiving control information, etc.) via the usbd_setup_*() functions (usbd_setup_bulk(), usbd_setup_interrupt(), etc.).
  5. Initiate data transfer using the usbd_io() function (with completion callbacks if required).
Note: In this context, the term "pipe" is a USB-specific term that has nothing to do with standard POSIX "pipes" (as used, for example, in the command line ls | more). In USB terminology, a "pipe" is simply a handle; something that identifies a connection to an endpoint.