17 #if !defined(__ADDRESS_H__)
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));
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));
86 virtual uint8_t
AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0) = 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;
114 uint8_t FindAddressIndex(uint8_t address = 0) {
115 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++) {
116 if(thePool[i].address == address)
124 for(uint8_t i = (start < 1 || start >= MAX_DEVICES_ALLOWED) ? 1 : start; i < MAX_DEVICES_ALLOWED; i++) {
132 void FreeAddressByIndex(uint8_t index) {
139 for(uint8_t i = 1; (i = FindChildIndex(*((
UsbDeviceAddress*) & thePool[index].address), i));)
140 FreeAddressByIndex(i);
150 void InitAllAddresses() {
151 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
164 thePool[0].
epinfo = &dev0ep;
178 uint8_t index = FindAddressIndex(addr);
180 return(!index) ? NULL : thePool + index;
189 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
190 if(thePool[i].address)
195 virtual uint8_t
AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0) {
199 if(parent > 127 || port > 7)
202 if(is_hub && hubCounter == 7)
206 uint8_t index = FindAddressIndex(0);
232 thePool[index].
address = *((uint8_t*) & addr);
251 uint8_t index = FindAddressIndex(addr);
252 FreeAddressByIndex(index);
272 #endif // __ADDRESS_H__