/* Allocate the next device address from the host  */
static uint8_t alloc_device_address(usbh_host *host)
/* Allocate the next device address from the host  */
static uint8_t alloc_device_address(usbh_host *host)
{
	unsigned i, j;
	for (i = 0; i < 127; i++) {
		uint8_t addr = host->next_device_address & 0x7F;
		addr = (!addr) ? 1 : addr;
		host->next_device_address = (addr == 0x7F) ? 1 : (addr + 1);
		for (j = 0; j < DEVICE_ARRAY_LENGTH; j++) {
			usbh_device *dev = &host->devices[j];
			if (IS_DEVICE_VALID(dev) && dev->address == addr) {
				addr = 0;
				break;
			}
		}
		if (addr) {
			LOGF_LN("address 0x%"PRIx8" is free for use", addr);
			return addr;
		}
	}
	LOG_LN("tried all possibilities, no valid address found");
	return 0;
}