mirror of
https://github.com/gdsports/USBHost_t36
synced 2025-01-09 04:38:15 -05:00
Assign unique, auto-incrementing addresses to USB devices
This commit is contained in:
parent
08ed25eb49
commit
7f44715014
@ -151,6 +151,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static void isr();
|
static void isr();
|
||||||
static void claim_drivers(Device_t *dev);
|
static void claim_drivers(Device_t *dev);
|
||||||
|
static uint32_t assign_address(void);
|
||||||
static bool queue_Transfer(Pipe_t *pipe, Transfer_t *transfer);
|
static bool queue_Transfer(Pipe_t *pipe, Transfer_t *transfer);
|
||||||
static void init_Device_Pipe_Transfer_memory(void);
|
static void init_Device_Pipe_Transfer_memory(void);
|
||||||
static Device_t * allocate_Device(void);
|
static Device_t * allocate_Device(void);
|
||||||
|
@ -32,7 +32,6 @@ static uint16_t enumlen;
|
|||||||
static Device_t *devlist=NULL;
|
static Device_t *devlist=NULL;
|
||||||
|
|
||||||
|
|
||||||
static uint32_t assign_addr(void);
|
|
||||||
static void pipe_set_maxlen(Pipe_t *pipe, uint32_t maxlen);
|
static void pipe_set_maxlen(Pipe_t *pipe, uint32_t maxlen);
|
||||||
static void pipe_set_addr(Pipe_t *pipe, uint32_t addr);
|
static void pipe_set_addr(Pipe_t *pipe, uint32_t addr);
|
||||||
|
|
||||||
@ -124,7 +123,7 @@ void USBHost::enumeration(const Transfer_t *transfer)
|
|||||||
switch (dev->enum_state) {
|
switch (dev->enum_state) {
|
||||||
case 0: // read 8 bytes of device desc, set max packet, and send set address
|
case 0: // read 8 bytes of device desc, set max packet, and send set address
|
||||||
pipe_set_maxlen(dev->control_pipe, enumbuf[7]);
|
pipe_set_maxlen(dev->control_pipe, enumbuf[7]);
|
||||||
mk_setup(enumsetup, 0, 5, assign_addr(), 0, 0); // 5=SET_ADDRESS
|
mk_setup(enumsetup, 0, 5, assign_address(), 0, 0); // 5=SET_ADDRESS
|
||||||
queue_Control_Transfer(dev, &enumsetup, NULL, NULL);
|
queue_Control_Transfer(dev, &enumsetup, NULL, NULL);
|
||||||
dev->enum_state = 1;
|
dev->enum_state = 1;
|
||||||
return;
|
return;
|
||||||
@ -310,9 +309,25 @@ void USBHost::claim_drivers(Device_t *dev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t assign_addr(void)
|
static bool address_in_use(uint32_t addr)
|
||||||
{
|
{
|
||||||
return 29; // TODO: when multiple devices, assign a unique address
|
for (Device_t *p = devlist; p; p = p->next) {
|
||||||
|
if (p->address == addr) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t USBHost::assign_address(void)
|
||||||
|
{
|
||||||
|
static uint8_t last_assigned_address=0;
|
||||||
|
uint32_t addr = last_assigned_address;
|
||||||
|
while (1) {
|
||||||
|
if (++addr > 127) addr = 1;
|
||||||
|
if (!address_in_use(addr)) {
|
||||||
|
last_assigned_address = addr;
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pipe_set_maxlen(Pipe_t *pipe, uint32_t maxlen)
|
static void pipe_set_maxlen(Pipe_t *pipe, uint32_t maxlen)
|
||||||
|
Loading…
Reference in New Issue
Block a user