17 #if !defined(__ADDRESS_H__)
27 #define USB_NAK_MAX_POWER 16 //NAK binary order maximum value
28 #define USB_NAK_DEFAULT 14 //default 16K-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
74 #define bmUSB_DEV_ADDR_ADDRESS 0x07
75 #define bmUSB_DEV_ADDR_PARENT 0x38
76 #define bmUSB_DEV_ADDR_HUB 0x40
91 virtual uint8_t
AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0) = 0;
97 #define ADDR_ERROR_INVALID_INDEX 0xFF
98 #define ADDR_ERROR_INVALID_ADDRESS 0xFF
100 template <const u
int8_t MAX_DEVICES_ALLOWED>
111 void InitEntry(uint8_t index)
116 thePool[index].
epinfo = &dev0ep;
119 uint8_t FindAddressIndex(uint8_t address = 0)
121 for (uint8_t i=1; i<MAX_DEVICES_ALLOWED; i++)
123 if (thePool[i].address == address)
131 for (uint8_t i=(start<1 || start>=MAX_DEVICES_ALLOWED) ? 1 : start; i<MAX_DEVICES_ALLOWED; i++)
139 void FreeAddressByIndex(uint8_t index)
148 for (uint8_t i=1; i = FindChildIndex(*((
UsbDeviceAddress*)&thePool[index].address), i); )
149 FreeAddressByIndex(i);
158 void InitAllAddresses()
160 for (uint8_t i=1; i<MAX_DEVICES_ALLOWED; i++)
173 thePool[0].
epinfo = &dev0ep;
187 uint8_t index = FindAddressIndex(addr);
189 return (!index) ? NULL : thePool + index;
198 for (uint8_t i=1; i<MAX_DEVICES_ALLOWED; i++)
199 if (thePool[i].address)
203 virtual uint8_t
AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0)
208 if (parent > 127 || port > 7)
211 if (is_hub && hubCounter == 7)
215 uint8_t index = FindAddressIndex(0);
247 thePool[index].
address = *((uint8_t*)&addr);
267 uint8_t index = FindAddressIndex(addr);
268 FreeAddressByIndex(index);
288 #endif // __ADDRESS_H__