25 #if !defined(_usb_h_) || defined(USBCORE_H)
26 #error "Never include UsbCore.h directly; include Usb.h instead"
35 #ifdef BOARD_BLACK_WIDDOW
37 #elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__))
43 #elif defined(BOARD_MEGA_ADK)
45 #elif defined(ARDUINO_AVR_BALANDUINO)
47 #elif defined(__ARDUINO_X86__) && PLATFORM_ID == 0x06
49 #elif defined(ESP8266)
51 #elif defined(ARDUINO_XIAO_ESP32S3)
55 #elif defined(ARDUINO_Seeed_XIAO_nRF52840_Sense)
57 #elif defined(MIGHTYCORE)
59 #elif (defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__))
61 #elif defined(ARDUINO_NRF52840_FEATHER_SENSE)
68 #define bmREQ_GET_DESCR USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE
69 #define bmREQ_SET USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE
70 #define bmREQ_CL_GET_INTF USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
77 #define USB_CLASS_USE_CLASS_INFO 0x00
78 #define USB_CLASS_AUDIO 0x01
79 #define USB_CLASS_COM_AND_CDC_CTRL 0x02
80 #define USB_CLASS_HID 0x03
81 #define USB_CLASS_PHYSICAL 0x05
82 #define USB_CLASS_IMAGE 0x06
83 #define USB_CLASS_PRINTER 0x07
84 #define USB_CLASS_MASS_STORAGE 0x08
85 #define USB_CLASS_HUB 0x09
86 #define USB_CLASS_CDC_DATA 0x0a
87 #define USB_CLASS_SMART_CARD 0x0b
88 #define USB_CLASS_CONTENT_SECURITY 0x0d
89 #define USB_CLASS_VIDEO 0x0e
90 #define USB_CLASS_PERSONAL_HEALTH 0x0f
91 #define USB_CLASS_DIAGNOSTIC_DEVICE 0xdc
92 #define USB_CLASS_WIRELESS_CTRL 0xe0
93 #define USB_CLASS_MISC 0xef
94 #define USB_CLASS_APP_SPECIFIC 0xfe
95 #define USB_CLASS_VENDOR_SPECIFIC 0xff
98 #define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED 0xD1
99 #define USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE 0xD2
100 #define USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS 0xD3
101 #define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL 0xD4
102 #define USB_ERROR_HUB_ADDRESS_OVERFLOW 0xD5
103 #define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL 0xD6
104 #define USB_ERROR_EPINFO_IS_NULL 0xD7
105 #define USB_ERROR_INVALID_ARGUMENT 0xD8
106 #define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE 0xD9
107 #define USB_ERROR_INVALID_MAX_PKT_SIZE 0xDA
108 #define USB_ERROR_EP_NOT_FOUND_IN_TBL 0xDB
109 #define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET 0xE0
110 #define USB_ERROR_FailGetDevDescr 0xE1
111 #define USB_ERROR_FailSetDevTblEntry 0xE2
112 #define USB_ERROR_FailGetConfDescr 0xE3
113 #define USB_ERROR_TRANSFER_TIMEOUT 0xFF
115 #define USB_XFER_TIMEOUT 5000
117 #define USB_RETRY_LIMIT 3
118 #define USB_SETTLE_DELAY 200
120 #define USB_NUMDEVICES 16
122 #define HUB_PORT_RESET_DELAY 20
125 #define USB_STATE_MASK 0xf0
127 #define USB_STATE_DETACHED 0x10
128 #define USB_DETACHED_SUBSTATE_INITIALIZE 0x11
129 #define USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE 0x12
130 #define USB_DETACHED_SUBSTATE_ILLEGAL 0x13
131 #define USB_ATTACHED_SUBSTATE_SETTLE 0x20
132 #define USB_ATTACHED_SUBSTATE_RESET_DEVICE 0x30
133 #define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE 0x40
134 #define USB_ATTACHED_SUBSTATE_WAIT_SOF 0x50
135 #define USB_ATTACHED_SUBSTATE_WAIT_RESET 0x51
136 #define USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x60
137 #define USB_STATE_ADDRESSING 0x70
138 #define USB_STATE_CONFIGURING 0x80
139 #define USB_STATE_RUNNING 0x90
140 #define USB_STATE_ERROR 0xa0
145 virtual uint8_t
Init(uint8_t parent __attribute__((unused)), uint8_t port __attribute__((unused)),
bool lowspeed __attribute__((unused))) {
149 virtual uint8_t
ConfigureDevice(uint8_t parent __attribute__((unused)), uint8_t port __attribute__((unused)),
bool lowspeed __attribute__((unused))) {
169 virtual bool VIDPIDOK(uint16_t vid __attribute__((unused)), uint16_t pid __attribute__((unused))) {
173 virtual bool DEVCLASSOK(uint8_t klass __attribute__((unused))) {
193 } __attribute__((packed));
203 } __attribute__((packed));
215 virtual void Parse(
const uint16_t len,
const uint8_t *pbuf,
const uint16_t &offset) = 0;
258 uint8_t
getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr);
259 uint8_t
getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr);
263 uint8_t
getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t* dataptr);
264 uint8_t
setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr);
265 uint8_t
setConf(uint8_t addr, uint8_t ep, uint8_t conf_value);
267 uint8_t
ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr,
bool direction);
268 uint8_t
ctrlStatus(uint8_t ep,
bool direction, uint16_t nak_limit);
269 uint8_t
inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval = 0);
270 uint8_t
outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data);
271 uint8_t
dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit);
276 uint8_t
Configuring(uint8_t parent, uint8_t port,
bool lowspeed);
279 uint8_t
ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
280 uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr,
USBReadParser *p);
284 uint8_t SetAddress(uint8_t addr, uint8_t ep,
EpInfo **ppep, uint16_t *nak_limit);
285 uint8_t OutTransfer(
EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data);
286 uint8_t InTransfer(
EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval = 0);
287 uint8_t AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port,
bool lowspeed);
293 inline uint8_t
USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) {
298 inline uint8_t
USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) {
303 inline uint8_t
USB::getStrDescr(uint8_t addr, uint8_t ep, uint16_t nuint8_ts, uint8_t index, uint16_t langid, uint8_t* dataptr) {
308 inline uint8_t
USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) {
313 inline uint8_t
USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) {
#define USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS
MAX3421e< P10, P9 > MAX3421E
struct SETUP_PKT * PSETUP_PKT
void(* UsbDeviceHandleFunc)(UsbDevice *pdev)
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
virtual void ResetHubPort(uint8_t port)
virtual bool DEVCLASSOK(uint8_t klass)
virtual uint8_t GetAddress()
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
virtual uint8_t Release()
virtual bool DEVSUBCLASSOK(uint8_t subklass)
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
uint8_t ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr, bool direction)
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
uint8_t getUsbTaskState(void)
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit)
uint8_t getStrDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t *dataptr)
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
EpInfo * getEpInfoEntry(uint8_t addr, uint8_t ep)
uint8_t DefaultAddressing(uint8_t parent, uint8_t port, bool lowspeed)
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
AddressPool & GetAddressPool()
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
void setUsbTaskState(uint8_t state)
uint8_t ReleaseDevice(uint8_t addr)
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
uint8_t ctrlStatus(uint8_t ep, bool direction, uint16_t nak_limit)
uint8_t Configuring(uint8_t parent, uint8_t port, bool lowspeed)
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
virtual void Parse(const uint16_t len, const uint8_t *pbuf, const uint16_t &offset)=0
#define USB_REQUEST_GET_DESCRIPTOR
#define USB_DESCRIPTOR_CONFIGURATION
#define USB_REQUEST_SET_CONFIGURATION
#define USB_DESCRIPTOR_STRING
#define USB_DESCRIPTOR_DEVICE
#define USB_REQUEST_SET_ADDRESS