Skip to content

Commit bdde0f7

Browse files
committed
usb: hid: Define sensor page usages IDs
This commit adds the following: * A subset of usage IDs defined in the Sensors' page of the HID standard. * A HID usage macro that works with IDs of 2 bytes. * A macro to define the exponent in a report descriptor. The values and naming came from the following document: https://www.usb.org/sites/default/files/hutrr39b_0.pdf Signed-off-by: Zak Essadaoui [email protected]
1 parent 2a8118c commit bdde0f7

File tree

1 file changed

+35
-1
lines changed
  • include/zephyr/usb/class

1 file changed

+35
-1
lines changed

include/zephyr/usb/class/hid.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ extern "C" {
141141
#define HID_USAGE_GEN_LEDS 0x08
142142
/** HID Button Usage page */
143143
#define HID_USAGE_GEN_BUTTON 0x09
144+
/** HID Sensors Usage page */
145+
#define HID_USAGE_SENSORS 0x20
144146

145147
/** HID Generic Desktop Undefined Usage ID */
146148
#define HID_USAGE_GEN_DESKTOP_UNDEFINED 0x00
@@ -163,6 +165,19 @@ extern "C" {
163165
/** HID Generic Desktop Wheel Usage ID */
164166
#define HID_USAGE_GEN_DESKTOP_WHEEL 0x38
165167

168+
/** HID Sensors Collection Usage ID */
169+
#define HID_USAGE_SENSOR_TYPE_COLLECTION 0x001
170+
/** HID Sensors Environmental Temperature Type Usage ID */
171+
#define HID_USAGE_SENSORS_TYPE_ENVIRONMENTAL_TEMPERATURE 0x033
172+
/** HID Sensors Event Sensor State Usage ID */
173+
#define HID_USAGE_SENSORS_EVENT_SENSOR_STATE 0x201
174+
/** HID Sensors Friendly Name Property Usage ID */
175+
#define HID_USAGE_SENSORS_PROPERTY_FRIENDLY_NAME 0x301
176+
/** HID Sensors Enviromental Temperature Data Usage ID */
177+
#define HID_USAGE_SENSORS_DATA_ENVIRONMENTAL_TEMPERATURE 0x434
178+
/** HID Sensors Timestamp Property Usage ID */
179+
#define HID_USAGE_SENSORS_PROPERTY_TIMESTAMP 0x529
180+
166181
/**
167182
* @}
168183
*/
@@ -357,12 +372,21 @@ extern "C" {
357372
* For usage examples, see @ref HID_MOUSE_REPORT_DESC(),
358373
* @ref HID_KEYBOARD_REPORT_DESC()
359374
*
360-
* @param idx Number of data fields included in the report
375+
* @param idx HID Usage ID per the HID Usage Table
361376
* @return HID Usage Index item
362377
*/
363378
#define HID_USAGE(idx) \
364379
HID_ITEM(HID_ITEM_TAG_USAGE, HID_ITEM_TYPE_LOCAL, 1), idx
365380

381+
/**
382+
* @brief Define HID Usage Index item with the data length of two bytes.
383+
*
384+
* @param idx HID Usage ID per the HID Usage Table
385+
* @return HID Usage Index item
386+
*/
387+
#define HID_USAGE16(idx) \
388+
HID_ITEM(HID_ITEM_TAG_USAGE, HID_ITEM_TYPE_LOCAL, 2), ((0xFF) & idx), ((0xFF) & (idx >> 8))
389+
366390
/**
367391
* @brief Define HID Usage Minimum item with the data length of one byte.
368392
*
@@ -413,6 +437,16 @@ extern "C" {
413437
#define HID_USAGE_MAX16(a, b) \
414438
HID_ITEM(HID_ITEM_TAG_USAGE_MAX, HID_ITEM_TYPE_LOCAL, 2), a, b
415439

440+
/**
441+
* @brief Define HID Unit Exponent item.
442+
*
443+
* @param exp Unit exponent, refer to the HID Unit Exponent table
444+
* in the specification for usage
445+
* @return HID Unit Exponent item
446+
*/
447+
#define HID_UNIT_EXPONENT(exp) \
448+
HID_ITEM(HID_ITEM_TAG_UNIT_EXPONENT, HID_ITEM_TYPE_GLOBAL, 1), exp
449+
416450
/**
417451
* @}
418452
*/

0 commit comments

Comments
 (0)