Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Recall that callback is executed before and after the endpoint specified by type, endpoint, and direction transfers data. Below is its function prototype:
typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
Here,
struct usb_xfer * contains the transfer state:
struct usb_xfer {
...
uint8_t usb_state;
/* Set when callback is executed before a data transfer. */
#define USB_ST_SETUP 0
/* Set when callback is executed after a data transfer. */
#define USB_ST_TRANSFERRED 1
/* Set when a transfer error occurs. */
#define USB_ST_ERROR 2
...
};
Generally, you’d use struct usb_xfer * in a switch statement to provide a code block for each transfer state. Some example code should help clarify what I mean.