From 48c3cb47018a0a60786d6b8fe891a26bfc3af650 Mon Sep 17 00:00:00 2001
From: fly <merspieler@alwaysdata.net>
Date: Mon, 2 Dec 2024 13:06:57 +0100
Subject: [PATCH] Fix for flightgear enumeration issue

Signed-off-by: fly <merspieler@alwaysdata.net>
---
 Pedestal/MCDU/firmware/descriptor.wara |  6 +-----
 Pedestal/MCDU/firmware/src/device.rs   | 12 +++++-------
 Pedestal/MCDU/firmware/src/main.rs     |  1 +
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/Pedestal/MCDU/firmware/descriptor.wara b/Pedestal/MCDU/firmware/descriptor.wara
index 5058a87..01b51b2 100644
--- a/Pedestal/MCDU/firmware/descriptor.wara
+++ b/Pedestal/MCDU/firmware/descriptor.wara
@@ -4,11 +4,7 @@ usage = ['Generic Desktop', 'Joystick']
 [[applicationCollection.inputReport]]
 
 [[applicationCollection.inputReport.variableItem]]
-usageRange = ['Button', 'Button 1', 'Button 64']
-logicalValueRange = [0, 1]
-
-[[applicationCollection.inputReport.variableItem]]
-usageRange = ['Button', 'Button 1', 'Button 32']
+usageRange = ['Button', 'Button 1', 'Button 128']
 logicalValueRange = [0, 1]
 
 [[applicationCollection.outputReport]]
diff --git a/Pedestal/MCDU/firmware/src/device.rs b/Pedestal/MCDU/firmware/src/device.rs
index bfa3ed6..4c93446 100644
--- a/Pedestal/MCDU/firmware/src/device.rs
+++ b/Pedestal/MCDU/firmware/src/device.rs
@@ -22,16 +22,12 @@ pub const CUSTOM_DESCRIPTOR: &[u8] = &[
     0x85, 0x01,          //     ReportId(1)
     0x05, 0x09,          //     UsagePage(Button[0x0009])
     0x19, 0x01,          //     UsageIdMin(Button 1[0x0001])
-    0x29, 0x40,          //     UsageIdMax(Button 64[0x0040])
+    0x29, 0x80,          //     UsageIdMax(Button 128[0x0080])
     0x15, 0x00,          //     LogicalMinimum(0)
     0x25, 0x01,          //     LogicalMaximum(1)
-    0x95, 0x40,          //     ReportCount(64)
+    0x95, 0x80,          //     ReportCount(128)
     0x75, 0x01,          //     ReportSize(1)
     0x81, 0x02,          //     Input(Data, Variable, Absolute, NoWrap, Linear, PreferredState, NoNullPosition, BitField)
-    0x19, 0x01,          //     UsageIdMin(Button 1[0x0001])
-    0x29, 0x20,          //     UsageIdMax(Button 32[0x0020])
-    0x95, 0x20,          //     ReportCount(32)
-    0x81, 0x02,          //     Input(Data, Variable, Absolute, NoWrap, Linear, PreferredState, NoNullPosition, BitField)
     0x05, 0x0E,          //     UsagePage(Haptics[0x000E])
     0x09, 0x21,          //     UsageId(Manual Trigger[0x0021])
     0x26, 0xFF, 0x00,    //     LogicalMaximum(255)
@@ -42,7 +38,7 @@ pub const CUSTOM_DESCRIPTOR: &[u8] = &[
 ];
 
 #[derive(Clone, Copy, Debug, Eq, PartialEq, Default, PackedStruct)]
-#[packed_struct(endian = "lsb", size_bytes = "13")] // MUST be <= 64 else we get problem cause InBytes64 or OutBytes64
+#[packed_struct(endian = "lsb", size_bytes = "17")] // MUST be <= 64 else we get problem cause InBytes64 or OutBytes64
 pub struct CustomInputReport {
     #[packed_field]
     pub report_id: u8,
@@ -50,6 +46,8 @@ pub struct CustomInputReport {
     pub buttons1: u64,
     #[packed_field]
     pub buttons2: u32,
+    #[packed_field]
+    pub dummy: u32,
 }
 
 #[derive(Clone, Copy, Debug, Eq, PartialEq, Default, PackedStruct)]
diff --git a/Pedestal/MCDU/firmware/src/main.rs b/Pedestal/MCDU/firmware/src/main.rs
index 390b23e..a97aa5b 100644
--- a/Pedestal/MCDU/firmware/src/main.rs
+++ b/Pedestal/MCDU/firmware/src/main.rs
@@ -235,6 +235,7 @@ fn main() -> ! {
 			report_id: 1,
 			buttons1,
 			buttons2,
+			dummy: 0,
 		};
 		// Pull the next LSK column high for next time coming through in the main loop ~1ms
 		if lsk_col_select <= 0 {