Skip to content

Commit e737154

Browse files
tomfoowilltoth
tomfoo
authored andcommittedMar 20, 2022
Add logical minimum and maximum to HID descriptor for analog axes.
Reporting a logical minimum (0) and maximum (2**12 - 1 = 4095) that matches the range of the 12-bit A2D allows the host to scale the analog inputs automatically, allowing use of the analog axes without calibration. This change required adding the LogicalMaximum16b macro, which encodes a 2-byte logical maximum for use in the descriptor. (The existing LogicalMaximum macro encodes a 1-byte value.)
1 parent c3f7ab2 commit e737154

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed
 

‎USB_config/descriptors.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
uint16_t const report_desc_size[HID_NUM_INTERFACES] =
4646
{
47-
80
47+
85
4848
};
4949
uint8_t const report_len_input[HID_NUM_INTERFACES] =
5050
{
@@ -191,7 +191,7 @@ Collection(USB_HID_APPLICATION),
191191
Collection (USB_HID_PHYSICAL),
192192

193193
//
194-
// The X, Y and Z values which are specified as 8-bit absolute
194+
// The X, Y and Z values which are specified as 12-bit absolute
195195
// position values.
196196
//
197197
Usage (USB_HID_X),
@@ -203,8 +203,11 @@ Collection(USB_HID_APPLICATION),
203203
Usage (USB_HID_SLIDER),
204204
Usage (USB_HID_DIAL),
205205
//
206-
// 8 16-bit absolute values.
206+
// 8 16-bit absolute values (but only 12 bit range due to 12-bit
207+
// ADCs).
207208
//
209+
LogicalMinimum(0),
210+
LogicalMaximum16b(4095),
208211
ReportSize(16),
209212
ReportCount(8),
210213
Input(USB_HID_INPUT_DATA | USB_HID_INPUT_VARIABLE |

‎USB_config/descriptors.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extern "C"
136136
//***********************************************************************************************
137137
#define SIZEOF_DEVICE_DESCRIPTOR 0x12
138138
#define MAX_STRING_DESCRIPTOR_INDEX 5
139-
#define report_desc_size_HID0 80
139+
#define report_desc_size_HID0 85
140140
//#define SIZEOF_REPORT_DESCRIPTOR 36
141141
//#define USBHID_REPORT_LENGTH 64 // length of whole HID report (including Report ID)
142142
#define CONFIG_STRING_INDEX 4

‎USB_config/hidUsage.h

+19
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,25 @@ extern "C"
283283
//*****************************************************************************
284284
#define LogicalMaximum(i8Value) 0x25, ((i8Value) & 0xff)
285285

286+
//*****************************************************************************
287+
//
288+
//! This is a macro to assist adding Logical Maximum entries in HID report
289+
//! descriptors, when the representation of the logical maximum value requires
290+
//! 16 bits to represent.
291+
//!
292+
//! \param i16Value is the Logical Maximum value.
293+
//!
294+
//! This macro takes a value and prepares it to be placed as a Logical Maximum
295+
//! entry into a HID report structure. This is the actual maximum value for
296+
//! the range of values associated with a field.
297+
//!
298+
//! \return Not a function.
299+
//
300+
//*****************************************************************************
301+
#define LogicalMaximum16b(i16Value) \
302+
0x26, ((i16Value) & 0xFF), \
303+
(((i16Value) >> 8) & 0xFF)
304+
286305
//*****************************************************************************
287306
//
288307
//! This is a macro to assist adding Physical Minimum entries in HID report

0 commit comments

Comments
 (0)