Skip to content

Commit 6e5b389

Browse files
Fix BT/BLE Joystick reports (#2293)
Underlying HID_Joystick now always using 16-bit format axes, need to update BT and BLE descriptors sent to the BT master or it will misinterpret the reports and the reported joystick state will be read as garbage. Fixes bug introduced in #2276, oops!
1 parent f3b8c58 commit 6e5b389

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

libraries/HID_Bluetooth/src/HID_Bluetooth.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,54 @@
11
#include "HID_Bluetooth.h"
22

3+
#define TUD_HID_REPORT_DESC_GAMEPAD16(...) \
4+
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
5+
HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
6+
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
7+
/* Report ID if any */\
8+
__VA_ARGS__ \
9+
/* 16 bit X, Y, Z, Rz, Rx, Ry (min -32767, max 32767 ) */ \
10+
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
11+
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
12+
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
13+
HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\
14+
HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
15+
HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\
16+
HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\
17+
HID_LOGICAL_MIN_N ( -32767, 2 ) ,\
18+
HID_LOGICAL_MAX_N ( 32767, 2 ) ,\
19+
HID_REPORT_COUNT ( 6 ) ,\
20+
HID_REPORT_SIZE ( 16 ) ,\
21+
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
22+
/* 8 bit DPad/Hat Button Map */ \
23+
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
24+
HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\
25+
HID_LOGICAL_MIN ( 1 ) ,\
26+
HID_LOGICAL_MAX ( 8 ) ,\
27+
HID_PHYSICAL_MIN ( 0 ) ,\
28+
HID_PHYSICAL_MAX_N ( 315, 2 ) ,\
29+
HID_REPORT_COUNT ( 1 ) ,\
30+
HID_REPORT_SIZE ( 8 ) ,\
31+
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
32+
/* 32 bit Button Map */ \
33+
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
34+
HID_USAGE_MIN ( 1 ) ,\
35+
HID_USAGE_MAX ( 32 ) ,\
36+
HID_LOGICAL_MIN ( 0 ) ,\
37+
HID_LOGICAL_MAX ( 1 ) ,\
38+
HID_REPORT_COUNT ( 32 ) ,\
39+
HID_REPORT_SIZE ( 1 ) ,\
40+
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
41+
HID_COLLECTION_END \
42+
43+
44+
345
//setup the report map.
446
//more generic function to be used with BLE & BT Classis
547
void __SetupHIDreportmap(void (*WeakMouse)(), void (*WeakKeyboard)(), void (*WeakJoystick)(), bool absMouse, uint16_t *report_size, uint8_t **reportmap) {
648
//allocate memory for the HID report descriptors. We don't use them, but need the size here.
749
uint8_t desc_hid_report_mouse[] = { TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(1)) };
850
uint8_t desc_hid_report_absmouse[] = { TUD_HID_REPORT_DESC_ABSMOUSE(HID_REPORT_ID(1)) };
9-
uint8_t desc_hid_report_joystick[] = { TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(1)) };
51+
uint8_t desc_hid_report_joystick[] = { TUD_HID_REPORT_DESC_GAMEPAD16(HID_REPORT_ID(1)) };
1052
uint8_t desc_hid_report_keyboard[] = { TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(1)), TUD_HID_REPORT_DESC_CONSUMER(HID_REPORT_ID(2)) };
1153
int size = 0;
1254

@@ -111,7 +153,7 @@ void __SetupHIDreportmap(void (*WeakMouse)(), void (*WeakKeyboard)(), void (*Wea
111153
reportid++;
112154
offset += sizeof(desc_hid_report_absmouse);
113155
}
114-
uint8_t desc_local[] = { TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(reportid)) };
156+
uint8_t desc_local[] = { TUD_HID_REPORT_DESC_GAMEPAD16(HID_REPORT_ID(reportid)) };
115157
memcpy(*reportmap + offset, desc_local, sizeof(desc_local));
116158
}
117159

0 commit comments

Comments
 (0)