18 #if !defined(_usb_h_) || defined(__ADDRESS_H__) 19 #error "Never include address.h directly; include Usb.h instead" 27 #define USB_NAK_MAX_POWER 15 //NAK binary order maximum value 28 #define USB_NAK_DEFAULT 14 //default 32K-1 NAKs before giving up 29 #define USB_NAK_NOWAIT 1 //Single NAK stops transfer 30 #define USB_NAK_NONAK 0 //Do not count NAKs, stop retrying after USB Timeout 43 } __attribute__((packed));
45 } __attribute__((packed));
62 uint8_t bmAddress : 3;
65 uint8_t bmReserved : 1;
66 } __attribute__((packed));
69 } __attribute__((packed));
71 #define bmUSB_DEV_ADDR_ADDRESS 0x07 72 #define bmUSB_DEV_ADDR_PARENT 0x38 73 #define bmUSB_DEV_ADDR_HUB 0x40 81 } __attribute__((packed));
85 virtual UsbDevice* GetUsbDevicePtr(uint8_t addr) = 0;
86 virtual uint8_t AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0) = 0;
87 virtual void FreeAddress(uint8_t addr) = 0;
92 #define ADDR_ERROR_INVALID_INDEX 0xFF 93 #define ADDR_ERROR_INVALID_ADDRESS 0xFF 95 template <const u
int8_t MAX_DEVICES_ALLOWED>
106 void InitEntry(uint8_t index) {
110 thePool[index].
epinfo = &dev0ep;
115 uint8_t FindAddressIndex(uint8_t address = 0) {
116 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++) {
117 if(thePool[i].address.devAddress == address)
126 for(uint8_t i = (start < 1 || start >= MAX_DEVICES_ALLOWED) ? 1 : start; i < MAX_DEVICES_ALLOWED; i++) {
127 if(thePool[i].address.bmParent == addr.
bmAddress)
135 void FreeAddressByIndex(uint8_t index) {
143 for(uint8_t i = 1; (i = FindChildIndex(uda, i));)
144 FreeAddressByIndex(i);
155 void InitAllAddresses() {
156 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
169 thePool[0].
epinfo = &dev0ep;
185 uint8_t index = FindAddressIndex(addr);
187 return (!index) ? NULL : thePool + index;
196 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
197 if(thePool[i].address.devAddress)
203 virtual uint8_t
AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0) {
212 if(is_hub && hubCounter == 7)
216 uint8_t index = FindAddressIndex(0);
261 uint8_t index = FindAddressIndex(addr);
262 FreeAddressByIndex(index);
283 #endif // __ADDRESS_H__
#define USB_NAK_MAX_POWER
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
virtual void FreeAddress(uint8_t addr)
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)
void(* UsbDeviceHandleFunc)(UsbDevice *pdev)