From f5882b875e067685fc46e3f1a001f54bb16ee36d Mon Sep 17 00:00:00 2001
From: Dean Camera <dean@fourwalledcubicle.com>
Date: Thu, 23 May 2013 19:54:42 +0200
Subject: Fix HID descriptor mouse and joystick macros for integer multiples of
 8 buttons.

---
 LUFA/DoxygenPages/ChangeLog.txt                | 2 ++
 LUFA/Drivers/USB/Class/Common/HIDClassCommon.h | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

(limited to 'LUFA')

diff --git a/LUFA/DoxygenPages/ChangeLog.txt b/LUFA/DoxygenPages/ChangeLog.txt
index aec199cb0..8813bcdda 100644
--- a/LUFA/DoxygenPages/ChangeLog.txt
+++ b/LUFA/DoxygenPages/ChangeLog.txt
@@ -35,6 +35,8 @@
   *     unknown SCSI command
   *   - Fixed incorrect HID report descriptor generated for 16-bit axis ranges by the HID_DESCRIPTOR_MOUSE() and HID_DESCRIPTOR_JOYSTICK()
   *     macros (thanks to Armory)
+  *   - Fixed incorrect HID report descriptor generated for button multiples of 8 by the HID_DESCRIPTOR_MOUSE() and HID_DESCRIPTOR_JOYSTICK()
+  *     macros
   *   - Fixed race condition in the DFU class bootloader causing failed device reprogramming in some circumstances (thanks to Luis Mendes)
   *
   *  \section Sec_ChangeLog130303 Version 130303
diff --git a/LUFA/Drivers/USB/Class/Common/HIDClassCommon.h b/LUFA/Drivers/USB/Class/Common/HIDClassCommon.h
index 3c30daa9e..f40afd3f9 100644
--- a/LUFA/Drivers/USB/Class/Common/HIDClassCommon.h
+++ b/LUFA/Drivers/USB/Class/Common/HIDClassCommon.h
@@ -382,7 +382,7 @@
 				HID_RI_REPORT_SIZE(8, 0x01),                \
 				HID_RI_REPORT_COUNT(8, Buttons),            \
 				HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), \
-				HID_RI_REPORT_SIZE(8, (8 - (Buttons % 8))), \
+				HID_RI_REPORT_SIZE(8, (Buttons % 8) ? (8 - (Buttons % 8)) : 0), \
 				HID_RI_REPORT_COUNT(8, 0x01),               \
 				HID_RI_INPUT(8, HID_IOF_CONSTANT),          \
 			HID_RI_END_COLLECTION(0)
@@ -476,7 +476,7 @@
 					HID_RI_REPORT_SIZE(8, 0x01),            \
 					HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), \
 					HID_RI_REPORT_COUNT(8, 0x01),           \
-					HID_RI_REPORT_SIZE(8, (8 - (Buttons % 8))), \
+					HID_RI_REPORT_SIZE(8, (Buttons % 8) ? (8 - (Buttons % 8)) : 0), \
 					HID_RI_INPUT(8, HID_IOF_CONSTANT),      \
 					HID_RI_USAGE_PAGE(8, 0x01),             \
 					HID_RI_USAGE(8, 0x30),                  \
-- 
cgit v1.2.3