25 #define USB_METHODS_INLINE
37 #if defined(ARDUINO) && ARDUINO >=100
50 #if defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
51 #define BOARD_TEENSY_PLUS_PLUS
54 #ifdef BOARD_BLACK_WIDDOW
56 #elif defined(BOARD_TEENSY_PLUS_PLUS)
58 #elif defined(BOARD_MEGA_ADK)
65 #define USBTRACE(s) (Serial.print((s)))
66 #define USBTRACE2(s,r) (Serial.print((s)), Serial.println((r),HEX))
71 #define bmREQ_GET_DESCR USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE //get descriptor request type
72 #define bmREQ_SET USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_DEVICE //set request type for all but 'set feature' and 'set interface'
73 #define bmREQ_CL_GET_INTF USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE //get interface request type
80 #define USB_CLASS_USE_CLASS_INFO 0x00 // Use Class Info in the Interface Descriptors
81 #define USB_CLASS_AUDIO 0x01 // Audio
82 #define USB_CLASS_COM_AND_CDC_CTRL 0x02 // Communications and CDC Control
83 #define USB_CLASS_HID 0x03 // HID
84 #define USB_CLASS_PHYSICAL 0x05 // Physical
85 #define USB_CLASS_IMAGE 0x06 // Image
86 #define USB_CLASS_PRINTER 0x07 // Printer
87 #define USB_CLASS_MASS_STORAGE 0x08 // Mass Storage
88 #define USB_CLASS_HUB 0x09 // Hub
89 #define USB_CLASS_CDC_DATA 0x0a // CDC-Data
90 #define USB_CLASS_SMART_CARD 0x0b // Smart-Card
91 #define USB_CLASS_CONTENT_SECURITY 0x0d // Content Security
92 #define USB_CLASS_VIDEO 0x0e // Video
93 #define USB_CLASS_PERSONAL_HEALTH 0x0f // Personal Healthcare
94 #define USB_CLASS_DIAGNOSTIC_DEVICE 0xdc // Diagnostic Device
95 #define USB_CLASS_WIRELESS_CTRL 0xe0 // Wireless Controller
96 #define USB_CLASS_MISC 0xef // Miscellaneous
97 #define USB_CLASS_APP_SPECIFIC 0xfe // Application Specific
98 #define USB_CLASS_VENDOR_SPECIFIC 0xff // Vendor Specific
101 #define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED 0xD1
102 #define USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE 0xD2
103 #define USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS 0xD3
104 #define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL 0xD4
105 #define USB_ERROR_HUB_ADDRESS_OVERFLOW 0xD5
106 #define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL 0xD6
107 #define USB_ERROR_EPINFO_IS_NULL 0xD7
108 #define USB_ERROR_INVALID_ARGUMENT 0xD8
109 #define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE 0xD9
110 #define USB_ERROR_INVALID_MAX_PKT_SIZE 0xDA
111 #define USB_ERROR_EP_NOT_FOUND_IN_TBL 0xDB
112 #define USB_ERROR_TRANSFER_TIMEOUT 0xFF
117 virtual uint8_t
Init(uint8_t parent, uint8_t port,
bool lowspeed) = 0;
119 virtual uint8_t
Poll() = 0;
123 #define USB_XFER_TIMEOUT 5000 //USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec
125 #define USB_RETRY_LIMIT 3 //retry limit for a transfer
126 #define USB_SETTLE_DELAY 200 //settle delay in milliseconds
128 #define USB_NUMDEVICES 16 //number of USB devices
130 #define HUB_PORT_RESET_DELAY 20 // hub port reset delay 10 ms recomended, can be up to 20 ms
133 #define USB_STATE_MASK 0xf0
135 #define USB_STATE_DETACHED 0x10
136 #define USB_DETACHED_SUBSTATE_INITIALIZE 0x11
137 #define USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE 0x12
138 #define USB_DETACHED_SUBSTATE_ILLEGAL 0x13
139 #define USB_ATTACHED_SUBSTATE_SETTLE 0x20
140 #define USB_ATTACHED_SUBSTATE_RESET_DEVICE 0x30
141 #define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE 0x40
142 #define USB_ATTACHED_SUBSTATE_WAIT_SOF 0x50
143 #define USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x60
144 #define USB_STATE_ADDRESSING 0x70
145 #define USB_STATE_CONFIGURING 0x80
146 #define USB_STATE_RUNNING 0x90
147 #define USB_STATE_ERROR 0xa0
154 uint8_t recipient: 5;
156 uint8_t direction: 1;
177 virtual void Parse(
const uint16_t len,
const uint8_t *pbuf,
const uint16_t &offset) = 0;
185 uint8_t devConfigIndex;
223 uint8_t
getDevDescr( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr );
224 uint8_t
getConfDescr( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr );
228 uint8_t
getStrDescr( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t index, uint16_t langid, uint8_t* dataptr );
229 uint8_t
setAddr( uint8_t oldaddr, uint8_t ep, uint8_t newaddr );
230 uint8_t
setConf( uint8_t addr, uint8_t ep, uint8_t conf_value );
232 uint8_t
ctrlData( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr,
boolean direction );
233 uint8_t
ctrlStatus( uint8_t ep,
boolean direction, uint16_t nak_limit );
234 uint8_t
inTransfer( uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data );
235 uint8_t
outTransfer( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data );
236 uint8_t
dispatchPkt( uint8_t token, uint8_t ep, uint16_t nak_limit );
241 uint8_t
Configuring(uint8_t parent, uint8_t port,
bool lowspeed);
244 uint8_t
ctrlReq( uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi,
245 uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t* dataptr,
USBReadParser *p);
249 uint8_t SetAddress(uint8_t addr, uint8_t ep,
EpInfo **ppep, uint16_t &nak_limit);
250 uint8_t OutTransfer(
EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data);
251 uint8_t InTransfer (
EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data);
254 #if 0 //defined(USB_METHODS_INLINE)
256 inline uint8_t
USB::getDevDescr( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr )
261 inline uint8_t
USB::getConfDescr( uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr )
266 inline uint8_t
USB::getStrDescr( uint8_t addr, uint8_t ep, uint16_t nuint8_ts, uint8_t index, uint16_t langid, uint8_t* dataptr )
271 inline uint8_t
USB::setAddr( uint8_t oldaddr, uint8_t ep, uint8_t newaddr )
276 inline uint8_t
USB::setConf( uint8_t addr, uint8_t ep, uint8_t conf_value )
281 #endif // defined(USB_METHODS_INLINE)