- doxygen styling added - CDC -> ACM refactor - type refactoring - examples categorized - flatUSB_config.h examples added
69 lines
2.3 KiB
C
69 lines
2.3 KiB
C
#ifndef FLATUSB_USB_DRIVER_INTERFACE
|
|
#define FLATUSB_USB_DRIVER_INTERFACE
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
typedef enum {
|
|
USB_SPD_UKWN = 0,
|
|
USB_SPD_LOW = 1,
|
|
USB_SPD_FULL = 2,
|
|
USB_SPD_HIGH = 3
|
|
} UsbDrv_LineSpeed;
|
|
|
|
typedef void (*UsbDrv_IN_cb)(uint8_t ep);
|
|
|
|
/**
|
|
* USB Driver interface.
|
|
*/
|
|
typedef struct {
|
|
// USB CORE -> USB DRIVER
|
|
void (*init)(); ///< Initialize USB driver
|
|
void (*reset)(); ///< Reset USB driver
|
|
void (*stall)(uint8_t ep, uint8_t dir, bool stall); ///< Stall the endpoint
|
|
uint32_t (*arm_IN)(uint8_t ep, const uint8_t *data, uint16_t len); ///< Arm IN endpoint
|
|
uint32_t (*arm_OUT)(uint8_t ep, uint16_t len); ///< Arm OUT endpoint
|
|
void (*set_address)(uint8_t addr); ///< Set device address
|
|
void (*set_config)(uint8_t ci); ///< Make the chosen setting operational
|
|
void (*autoarm)(uint8_t ep); ///< Enable OUT autoarm
|
|
void (*en_ep_irq)(uint8_t ep, uint8_t dir, bool en); ///< Enable endpoint interrupt
|
|
void (*reg_IN_cb)(uint8_t ep, UsbDrv_IN_cb cb); ///< Register a callback for IN transaction complete
|
|
|
|
// USB DRIVER -> USB CORE
|
|
void (*rst_notify)(); ///< Notify USB core of a bus issued reset
|
|
void (*enum_notify)(uint8_t spd); ///< Notify the USB core that speed negotiation has concluded
|
|
} UsbDrv_DrvIntf;
|
|
|
|
#ifndef USBDBGMSG
|
|
#define USBMSG(...)
|
|
#endif
|
|
|
|
/**
|
|
* Callback codes.
|
|
*/
|
|
typedef enum {
|
|
USB_CBC_OUT, ///< OUT done!
|
|
USB_CBC_IN_DONE, ///< IN done!
|
|
USB_CBC_IN_FIFOEMPTY, ///< Could not serve IN request, since Tx FIFO was empty
|
|
} UsbDrv_CallbackCode;
|
|
|
|
/**
|
|
* Callback compound.
|
|
*/
|
|
typedef struct {
|
|
uint8_t ep : 4; ///< Endpoint number
|
|
uint8_t dir : 1; ///< Direction
|
|
uint8_t code : 3; ///< Event code
|
|
uint16_t size; ///< Data size
|
|
const uint8_t *data; ///< Data
|
|
} UsbDrv_CallbackCompound;
|
|
|
|
/**
|
|
* Control transfer stages.
|
|
*/
|
|
typedef enum { UST_SETUP, ///< Setup stage
|
|
UST_DATA ///< Data stage
|
|
} UsbDrv_ControlTfStage;
|
|
|
|
#endif /* FLATUSB_USB_DRIVER_INTERFACE */
|