Fix board name redefinition in BoardTypes.h (thanks to Daniel Czigany).
[pub/USBasp.git] / Demos / Device / LowLevel / Joystick / Joystick.c
index 6ced1ce..5aadb59 100644 (file)
@@ -93,16 +93,14 @@ void EVENT_USB_Device_Disconnect(void)
  */ 
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
-       /* Indicate USB connected and ready */
-       LEDs_SetAllLEDs(LEDMASK_USB_READY);
+       bool ConfigSuccess = true;
 
-       /* Setup Joystick Report Endpoint */
-       if (!(Endpoint_ConfigureEndpoint(JOYSTICK_EPNUM, EP_TYPE_INTERRUPT,
-                                            ENDPOINT_DIR_IN, JOYSTICK_EPSIZE,
-                                        ENDPOINT_BANK_SINGLE)))
-       {
-               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-       }
+       /* Setup HID Report Endpoint */
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(JOYSTICK_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
+                                                   JOYSTICK_EPSIZE, ENDPOINT_BANK_SINGLE);
+
+       /* Indicate endpoint configuration success or failure */
+       LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
 /** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
@@ -119,15 +117,13 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        {
                                USB_JoystickReport_Data_t JoystickReportData;
                                
-                               Endpoint_ClearSETUP();
-
                                /* Create the next HID report to send to the host */                            
                                GetNextReport(&JoystickReportData);
-                                       
+
+                               Endpoint_ClearSETUP();
+
                                /* Write the report data to the control endpoint */
                                Endpoint_Write_Control_Stream_LE(&JoystickReportData, sizeof(JoystickReportData));
-                               
-                               /* Finalize the stream transfer to send the last packet or clear the host abort */
                                Endpoint_ClearOUT();
                        }
                
@@ -141,7 +137,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
  *
  *  \return Boolean true if the new report differs from the last report, false otherwise
  */
-bool GetNextReport(USB_JoystickReport_Data_t* ReportData)
+bool GetNextReport(USB_JoystickReport_Data_t* const ReportData)
 {
        static uint8_t PrevJoyStatus    = 0;
        static uint8_t PrevButtonStatus = 0;