diff --git a/src/userland/hid/include/hid.h b/src/userland/hid/include/hid.h index acdd352..2488ff7 100644 --- a/src/userland/hid/include/hid.h +++ b/src/userland/hid/include/hid.h @@ -7,6 +7,7 @@ uint32_t serviceId; uint32_t deviceId; uint32_t normalFunction; + uint32_t interval; void *buffer; ListElement *inputGroups; } HIDDevice; diff --git a/src/userland/hid/include/hid.h b/src/userland/hid/include/hid.h index acdd352..2488ff7 100644 --- a/src/userland/hid/include/hid.h +++ b/src/userland/hid/include/hid.h @@ -7,6 +7,7 @@ uint32_t serviceId; uint32_t deviceId; uint32_t normalFunction; + uint32_t interval; void *buffer; ListElement *inputGroups; } HIDDevice; diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 1947580..dbed8fc 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -268,8 +268,7 @@ foreach (device->inputGroups, InputGroup *, group, { handleGroup(group, &report, &bit); }); - // TODO: sleep for at least endpoint->interval? - sleep(10); + sleep(device->interval); } } @@ -283,6 +282,8 @@ device->inputGroups = NULL; printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); + uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); + device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); return 0; } diff --git a/src/userland/hid/include/hid.h b/src/userland/hid/include/hid.h index acdd352..2488ff7 100644 --- a/src/userland/hid/include/hid.h +++ b/src/userland/hid/include/hid.h @@ -7,6 +7,7 @@ uint32_t serviceId; uint32_t deviceId; uint32_t normalFunction; + uint32_t interval; void *buffer; ListElement *inputGroups; } HIDDevice; diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 1947580..dbed8fc 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -268,8 +268,7 @@ foreach (device->inputGroups, InputGroup *, group, { handleGroup(group, &report, &bit); }); - // TODO: sleep for at least endpoint->interval? - sleep(10); + sleep(device->interval); } } @@ -283,6 +282,8 @@ device->inputGroups = NULL; printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); + uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); + device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); return 0; } diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 9277af1..efc3f14 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -70,7 +70,7 @@ void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *, uint32_t); void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); - void (*configureEndpoint)(void *, UsbEndpointDescriptor *); + uint32_t (*configureEndpoint)(void *, UsbEndpointDescriptor *); } UsbHostControllerInterface; typedef struct { @@ -82,7 +82,7 @@ void *data; UsbHostControllerInterface *interface; uint32_t portIndex; - uint32_t id; + uint32_t id, interval; } UsbSlot; extern uint32_t serviceId; diff --git a/src/userland/hid/include/hid.h b/src/userland/hid/include/hid.h index acdd352..2488ff7 100644 --- a/src/userland/hid/include/hid.h +++ b/src/userland/hid/include/hid.h @@ -7,6 +7,7 @@ uint32_t serviceId; uint32_t deviceId; uint32_t normalFunction; + uint32_t interval; void *buffer; ListElement *inputGroups; } HIDDevice; diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 1947580..dbed8fc 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -268,8 +268,7 @@ foreach (device->inputGroups, InputGroup *, group, { handleGroup(group, &report, &bit); }); - // TODO: sleep for at least endpoint->interval? - sleep(10); + sleep(device->interval); } } @@ -283,6 +282,8 @@ device->inputGroups = NULL; printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); + uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); + device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); return 0; } diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 9277af1..efc3f14 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -70,7 +70,7 @@ void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *, uint32_t); void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); - void (*configureEndpoint)(void *, UsbEndpointDescriptor *); + uint32_t (*configureEndpoint)(void *, UsbEndpointDescriptor *); } UsbHostControllerInterface; typedef struct { @@ -82,7 +82,7 @@ void *data; UsbHostControllerInterface *interface; uint32_t portIndex; - uint32_t id; + uint32_t id, interval; } UsbSlot; extern uint32_t serviceId; diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8093bad..d443b0f 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -62,7 +62,7 @@ for (uint32_t i = 0; i < interface->endpointCount;) { UsbEndpointDescriptor *endpoint = nextInterface; if (endpoint->descriptorType == 5) { - slot->interface->configureEndpoint(slot->data, endpoint); + slot->interval = slot->interface->configureEndpoint(slot->data, endpoint); i++; } nextInterface += endpoint->size; @@ -143,6 +143,11 @@ // data is returned to buffer } +uint32_t hidInterval(uint32_t slotId) { + UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); + return usbSlot->interval; +} + void initialize() { serviceId = getServiceId(); // xhciEvent will carry data corresponding to the data in the xhci event @@ -150,6 +155,7 @@ xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); createFunction("hid_normal", (void *)hidNormal); + createFunction("hid_interval", (void *)hidInterval); for (uint32_t i = 0;; i++) { uint32_t class = getDeviceClass(i, 0); if (!class) { diff --git a/src/userland/hid/include/hid.h b/src/userland/hid/include/hid.h index acdd352..2488ff7 100644 --- a/src/userland/hid/include/hid.h +++ b/src/userland/hid/include/hid.h @@ -7,6 +7,7 @@ uint32_t serviceId; uint32_t deviceId; uint32_t normalFunction; + uint32_t interval; void *buffer; ListElement *inputGroups; } HIDDevice; diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 1947580..dbed8fc 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -268,8 +268,7 @@ foreach (device->inputGroups, InputGroup *, group, { handleGroup(group, &report, &bit); }); - // TODO: sleep for at least endpoint->interval? - sleep(10); + sleep(device->interval); } } @@ -283,6 +282,8 @@ device->inputGroups = NULL; printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); + uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); + device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); return 0; } diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 9277af1..efc3f14 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -70,7 +70,7 @@ void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *, uint32_t); void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); - void (*configureEndpoint)(void *, UsbEndpointDescriptor *); + uint32_t (*configureEndpoint)(void *, UsbEndpointDescriptor *); } UsbHostControllerInterface; typedef struct { @@ -82,7 +82,7 @@ void *data; UsbHostControllerInterface *interface; uint32_t portIndex; - uint32_t id; + uint32_t id, interval; } UsbSlot; extern uint32_t serviceId; diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8093bad..d443b0f 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -62,7 +62,7 @@ for (uint32_t i = 0; i < interface->endpointCount;) { UsbEndpointDescriptor *endpoint = nextInterface; if (endpoint->descriptorType == 5) { - slot->interface->configureEndpoint(slot->data, endpoint); + slot->interval = slot->interface->configureEndpoint(slot->data, endpoint); i++; } nextInterface += endpoint->size; @@ -143,6 +143,11 @@ // data is returned to buffer } +uint32_t hidInterval(uint32_t slotId) { + UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); + return usbSlot->interval; +} + void initialize() { serviceId = getServiceId(); // xhciEvent will carry data corresponding to the data in the xhci event @@ -150,6 +155,7 @@ xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); createFunction("hid_normal", (void *)hidNormal); + createFunction("hid_interval", (void *)hidInterval); for (uint32_t i = 0;; i++) { uint32_t class = getDeviceClass(i, 0); if (!class) { diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index efb6123..6475e34 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -133,7 +133,7 @@ doXhciCommand(slot, 0x00, 9, configValue, 0); } -void xhciConfigureEndpoint(SlotXHCI *slot, UsbEndpointDescriptor *endpoint) { +uint32_t xhciConfigureEndpoint(SlotXHCI *slot, UsbEndpointDescriptor *endpoint) { uint8_t endpointNumber = endpoint->address & 0xF; // never 0 uint8_t direction = endpoint->address >> 7; uint8_t endpointIndex = (endpointNumber)*2 - 1 + direction; @@ -142,7 +142,6 @@ &inputContext->deviceContext.endpoints[endpointIndex]; endpointContext->maxPrimaryStreams = 0; endpointContext->interval = endpoint->interval; - printf("interval: %i\n", endpointContext->interval); endpointContext->errorCount = 3; endpointContext->endpointType = direction << 2 | endpoint->attributes & 3; @@ -156,6 +155,7 @@ inputContext->inputControl.addContextFlags |= 1 << (endpointIndex + 1); inputContext->deviceContext.slot.contextEntryCount = MAX( inputContext->deviceContext.slot.contextEntryCount, endpointIndex); + return (1 << endpointContext->interval) / 8; } UsbHostControllerInterface xhci = {