flatUSB/usb_driver_common.h
Epagris 685fa77bda - function separation done
- a load of CMake modification
2024-11-16 18:15:13 +01:00

58 lines
2.1 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);
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
} USB_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;
typedef enum { UST_SETUP,
UST_DATA } USBDRV_ControlTfStage;
#endif /* FLATUSB_USB_DRIVER_INTERFACE */