Upgrade Doxygen configuration files to the latest version.
[pub/USBasp.git] / Demos / Device / LowLevel / Mouse / Mouse.c
index 03d5bbb..144cf4e 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
+     Copyright (C) Dean Camera, 2013.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2013  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -18,7 +18,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
 /** Indicates what report mode the host has requested, true for normal HID reporting mode, false for special boot
  *  protocol reporting mode.
  */
-bool UsingReportProtocol = true;
+static bool UsingReportProtocol = true;
 
 /** Current Idle period. This is set by the host via a Set Idle HID class request to silence the device's reports
  *  for either the entire idle duration, or until the report status changes (e.g. the user moves the mouse).
  */
-uint16_t IdleCount = 0;
+static uint16_t IdleCount = 0;
 
 /** Current Idle period remaining. When the IdleCount value is set, this tracks the remaining number of idle
  *  milliseconds. This is separate to the IdleCount timer and is incremented and compared as the host may request
  *  the current idle period via a Get Idle HID class request, thus its value must be preserved.
  */
-uint16_t IdleMSRemaining = 0;
+static uint16_t IdleMSRemaining = 0;
 
 
 /** Main program entry point. This routine configures the hardware required by the application, then
@@ -61,7 +61,7 @@ int main(void)
        SetupHardware();
 
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
-       sei();
+       GlobalInterruptEnable();
 
        for (;;)
        {
@@ -116,21 +116,20 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        bool ConfigSuccess = true;
 
        /* Setup HID Report Endpoint */
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                                   MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_EPADDR, EP_TYPE_INTERRUPT, MOUSE_EPSIZE, 1);
 
-       /* Turn on Start-of-Frame events for tracking HID report period exiry */
+       /* Turn on Start-of-Frame events for tracking HID report period expiry */
        USB_Device_EnableSOFEvents();
 
        /* 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
- *  control requests that are not handled internally by the USB library (including the HID commands, which are
- *  all issued via the control endpoint), so that they can be handled appropriately for the application.
+/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
+ *  the device from the USB host before passing along unhandled control requests to the library for processing
+ *  internally.
  */
-void EVENT_USB_Device_UnhandledControlRequest(void)
+void EVENT_USB_Device_ControlRequest(void)
 {
        /* Handle HID Class specific requests */
        switch (USB_ControlRequest.bRequest)
@@ -160,7 +159,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                                Endpoint_ClearSETUP();
 
                                /* Write the current protocol flag to the host */
-                               Endpoint_Write_Byte(UsingReportProtocol);
+                               Endpoint_Write_8(UsingReportProtocol);
 
                                Endpoint_ClearIN();
                                Endpoint_ClearStatusStage();
@@ -195,7 +194,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                                Endpoint_ClearSETUP();
 
                                /* Write the current idle duration to the host, must be divided by 4 before sent to host */
-                               Endpoint_Write_Byte(IdleCount >> 2);
+                               Endpoint_Write_8(IdleCount >> 2);
 
                                Endpoint_ClearIN();
                                Endpoint_ClearStatusStage();
@@ -233,10 +232,10 @@ void CreateMouseReport(USB_MouseReport_Data_t* const ReportData)
        if (JoyStatus_LCL & JOY_LEFT)
          ReportData->X = -1;
        else if (JoyStatus_LCL & JOY_RIGHT)
-         ReportData->X = 1;
+         ReportData->X =  1;
 
        if (JoyStatus_LCL & JOY_PRESS)
-         ReportData->Button  = (1 << 0);
+         ReportData->Button |= (1 << 0);
 
        if (ButtonStatus_LCL & BUTTONS_BUTTON1)
          ReportData->Button |= (1 << 1);
@@ -271,7 +270,7 @@ void SendNextReport(void)
        }
 
        /* Select the Mouse Report Endpoint */
-       Endpoint_SelectEndpoint(MOUSE_EPNUM);
+       Endpoint_SelectEndpoint(MOUSE_EPADDR);
 
        /* Check if Mouse Endpoint Ready for Read/Write and if we should send a new report */
        if (Endpoint_IsReadWriteAllowed() && SendReport)
@@ -280,7 +279,7 @@ void SendNextReport(void)
                PrevMouseReportData = MouseReportData;
 
                /* Write Mouse Report Data */
-               Endpoint_Write_Stream_LE(&MouseReportData, sizeof(MouseReportData));
+               Endpoint_Write_Stream_LE(&MouseReportData, sizeof(MouseReportData), NULL);
 
                /* Finalize the stream transfer to send the last packet */
                Endpoint_ClearIN();