Skip to content

Commit

Permalink
Use the interrupt endpoint poll rate to control mouse report frequenc…
Browse files Browse the repository at this point in the history
…y rather than explicitly limiting from the main loop.
  • Loading branch information
Chris Andreae committed Apr 15, 2014
1 parent e24f2db commit 29e93b5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | MOUSE_IN_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = HID_EPSIZE,
.PollingIntervalMS = 0x01
.PollingIntervalMS = 0x18
}

};
Expand Down
15 changes: 1 addition & 14 deletions Keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,7 @@ void __attribute__((noreturn)) Keyboard_Main(void)
vm_step_all();
}

/* Limit frequency of mouse reports. Unlike keyboard reports,
identical reports won't be ignored by the class driver, so
report speed affects mouse movement speed. */
uint8_t mouse_slice = (uptimems() & 0x8);
uint8_t perform_mouse_update = 0;
if(!mouse_slice && update.mouse){
perform_mouse_update = 1;
update.mouse = 0;
}
else if(!update.mouse && mouse_slice){
update.mouse = 1;
}

USB_Perform_Update(1, perform_mouse_update);
USB_Perform_Update();
}
}

Expand Down
8 changes: 3 additions & 5 deletions lufa/lufa_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ void USB_KeepAlive(uint8_t poll){
}
}

void USB_Perform_Update(uint8_t update_kbd, uint8_t update_mouse){
if(update_mouse)
HID_Device_USBTask(&Mouse_HID_Interface);
void USB_Perform_Update(void){
HID_Device_USBTask(&Mouse_HID_Interface);

if(update_kbd)
HID_Device_USBTask(&Keyboard_HID_Interface);
HID_Device_USBTask(&Keyboard_HID_Interface);

USB_KeepAlive(true);
}
Expand Down
2 changes: 1 addition & 1 deletion usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ void USB_KeepAlive(uint8_t poll);
* Performs a USB update, scanning keyboard/mouse and responding
* to interrupt requests. Includes KeepAlive.
*/
void USB_Perform_Update(uint8_t update_kbd, uint8_t update_mouse);
void USB_Perform_Update(void);

#endif // __USB_H
6 changes: 3 additions & 3 deletions vusb/vusb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,14 @@ void USB_KeepAlive(uint8_t poll){
}
}

void USB_Perform_Update(uint8_t update_kbd, uint8_t update_mouse){
void USB_Perform_Update(void){
USB_KeepAlive(true);

static bool sending_keyboard = 0;
static bool sending_mouse = 0;

// Keyboard
if(!sending_keyboard && update_kbd){
if(!sending_keyboard){
// Update, set sending_keyboard if the report is different to last time
sending_keyboard = update_and_compare(&KeyboardReportData, &PrevKeyboardHIDReportBuffer, sizeof(KeyboardReport_Data_t), (void(*)(void*)) &Fill_KeyboardReport);
}
Expand All @@ -430,7 +430,7 @@ void USB_Perform_Update(uint8_t update_kbd, uint8_t update_mouse){
}

// Mouse
if(!sending_mouse && update_mouse){
if(!sending_mouse){
// Update, set sending_mouse if the report is different to last time
sending_mouse = update_and_compare(&MouseReportData, &PrevMouseHIDReportBuffer, sizeof(MouseReport_Data_t), (void(*)(void*)) &Fill_MouseReport);
// Mouse reports need to repeat for the cursor to continue to move, so always send if there is a movement component to the report
Expand Down

0 comments on commit 29e93b5

Please sign in to comment.