X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8711dc7ced0ed02a33a96222d86bd27f65c239ed..24f730fce3f2022762011d795c3feada5ef874b3:/Demos/Host/ClassDriver/MouseHost/MouseHost.c diff --git a/Demos/Host/ClassDriver/MouseHost/MouseHost.c b/Demos/Host/ClassDriver/MouseHost/MouseHost.c index 65fb4893a..c46bfe9d7 100644 --- a/Demos/Host/ClassDriver/MouseHost/MouseHost.c +++ b/Demos/Host/ClassDriver/MouseHost/MouseHost.c @@ -45,16 +45,18 @@ USB_ClassInfo_HID_Host_t Mouse_HID_Interface = .Config = { .DataINPipeNumber = 1, + .DataINPipeDoubleBank = false, + .DataOUTPipeNumber = 2, + .DataOUTPipeDoubleBank = false, - .MatchInterfaceProtocol = true, - .HIDInterfaceProtocol = 0x02, + .HIDInterfaceProtocol = HID_BOOT_MOUSE_PROTOCOL, }, }; /** Main program entry point. This routine configures the hardware required by the application, then - * starts the scheduler to run the application tasks. + * enters a loop to run the application tasks in sequence. */ int main(void) { @@ -74,9 +76,8 @@ int main(void) uint16_t ConfigDescriptorSize; uint8_t ConfigDescriptorData[512]; - if ((USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, NULL) != HOST_SENDCONTROL_Successful) || - (ConfigDescriptorSize > sizeof(ConfigDescriptorData)) || - (USB_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData))) + if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData, + sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful) { printf("Error Retrieving Configuration Descriptor.\r\n"); LEDs_SetAllLEDs(LEDMASK_USB_ERROR); @@ -100,16 +101,45 @@ int main(void) USB_HostState = HOST_STATE_WaitForDeviceRemoval; break; } + + if (HID_Host_SetBootProtocol(&Mouse_HID_Interface) != 0) + { + printf("Could not Set Boot Protocol Mode.\r\n"); + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + USB_HostState = HOST_STATE_WaitForDeviceRemoval; + break; + } printf("Mouse Enumerated.\r\n"); USB_HostState = HOST_STATE_Configured; break; case HOST_STATE_Configured: - if (HID_Host_ReportReceived(&Mouse_HID_Interface)) + if (HID_Host_IsReportReceived(&Mouse_HID_Interface)) { + uint8_t LEDMask = LEDS_NO_LEDS; + + USB_MouseReport_Data_t MouseReport; + HID_Host_ReceiveReport(&Mouse_HID_Interface, &MouseReport); + printf_P(PSTR("dX:%2d dY:%2d Button:%d\r\n"), MouseReport.X, + MouseReport.Y, + MouseReport.Button); + if (MouseReport.X > 0) + LEDMask |= LEDS_LED1; + else if (MouseReport.X < 0) + LEDMask |= LEDS_LED2; + + if (MouseReport.Y > 0) + LEDMask |= LEDS_LED3; + else if (MouseReport.Y < 0) + LEDMask |= LEDS_LED4; + + if (MouseReport.Button) + LEDMask = LEDS_ALL_LEDS; + + LEDs_SetAllLEDs(LEDMask); } - + break; }