25 #if !defined(_usb_h_) || defined(__ADDRESS_H__)
26 #error "Never include address.h directly; include Usb.h instead"
34 #define USB_NAK_MAX_POWER 15
35 #define USB_NAK_DEFAULT 14
36 #define USB_NAK_NOWAIT 1
37 #define USB_NAK_NONAK 0
50 } __attribute__((packed));
52 } __attribute__((packed));
73 } __attribute__((packed));
76 } __attribute__((packed));
78 #define bmUSB_DEV_ADDR_ADDRESS 0x07
79 #define bmUSB_DEV_ADDR_PARENT 0x38
80 #define bmUSB_DEV_ADDR_HUB 0x40
88 } __attribute__((packed));
93 virtual uint8_t
AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0) = 0;
99 #define ADDR_ERROR_INVALID_INDEX 0xFF
100 #define ADDR_ERROR_INVALID_ADDRESS 0xFF
102 template <const u
int8_t MAX_DEVICES_ALLOWED>
113 void InitEntry(uint8_t index) {
117 thePool[index].
epinfo = &dev0ep;
122 uint8_t FindAddressIndex(uint8_t address = 0) {
123 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++) {
124 if(thePool[i].address.devAddress == address)
133 for(uint8_t i = (start < 1 || start >= MAX_DEVICES_ALLOWED) ? 1 : start; i < MAX_DEVICES_ALLOWED; i++) {
134 if(thePool[i].address.bmParent == addr.
bmAddress)
142 void FreeAddressByIndex(uint8_t index) {
150 for(uint8_t i = 1; (i = FindChildIndex(uda, i));)
151 FreeAddressByIndex(i);
162 void InitAllAddresses() {
163 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
176 thePool[0].
epinfo = &dev0ep;
192 uint8_t index = FindAddressIndex(addr);
194 return (!index) ? NULL : thePool + index;
203 for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
204 if(thePool[i].address.devAddress)
210 virtual uint8_t
AllocAddress(uint8_t parent,
bool is_hub =
false, uint8_t port = 0) {
219 if(is_hub && hubCounter == 7)
223 uint8_t index = FindAddressIndex(0);
268 uint8_t index = FindAddressIndex(addr);
269 FreeAddressByIndex(index);
#define USB_NAK_MAX_POWER
void(* UsbDeviceHandleFunc)(UsbDevice *pdev)
virtual void FreeAddress(uint8_t addr)=0
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc)
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)
virtual void FreeAddress(uint8_t addr)
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)