Skip to content

Commit

Permalink
applications: nrf_desktop: generic max report size handling
Browse files Browse the repository at this point in the history
Handle max input and output report size in scalable way.

Signed-off-by: Pawel Dunaj <[email protected]>
  • Loading branch information
pdunaj committed Jan 8, 2025
1 parent 3665a25 commit d99fda6
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions applications/nrf_desktop/configuration/common/hid_report_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,38 @@ static const uint8_t output_reports[] = {
REPORT_ID_KEYBOARD_LEDS,
};

/* Internal definitions used to calculate size of the biggest supported HID input report. */
#define _REPORT_BUFFER_SIZE_MOUSE \
(IS_ENABLED(CONFIG_DESKTOP_HID_REPORT_MOUSE_SUPPORT) ? (REPORT_SIZE_MOUSE) : (0))
#define _REPORT_BUFFER_SIZE_KEYBOARD_KEYS \
(IS_ENABLED(CONFIG_DESKTOP_HID_REPORT_KEYBOARD_SUPPORT) ? (REPORT_SIZE_KEYBOARD_KEYS) : (0))
#define _REPORT_BUFFER_SIZE_SYSTEM_CTRL \
(IS_ENABLED(CONFIG_DESKTOP_HID_REPORT_SYSTEM_CTRL_SUPPORT) ? \
(REPORT_SIZE_SYSTEM_CTRL) : (0))
#define _REPORT_BUFFER_SIZE_CONSUMER_CTRL \
(IS_ENABLED(CONFIG_DESKTOP_HID_REPORT_CONSUMER_CTRL_SUPPORT) ? \
(REPORT_SIZE_CONSUMER_CTRL) : (0))
#define _REPORT_BUFFER_SIZE_BOOT_MOUSE \
(IS_ENABLED(CONFIG_DESKTOP_HID_BOOT_INTERFACE_MOUSE) ? (REPORT_SIZE_MOUSE_BOOT) : (0))
#define _REPORT_BUFFER_SIZE_BOOT_KEYBOARD \
(IS_ENABLED(CONFIG_DESKTOP_HID_BOOT_INTERFACE_KEYBOARD) ? (REPORT_SIZE_KEYBOARD_BOOT) : (0))
#define _MAX6(a, b, c, d, e, f) MAX(MAX(a, b), MAX(MAX(c, d), MAX(e, f)))
union _input_report_size_max {
#if CONFIG_DESKTOP_HID_REPORT_MOUSE_SUPPORT || CONFIG_DESKTOP_HID_BOOT_INTERFACE_MOUSE
uint8_t _mouse_report[REPORT_SIZE_MOUSE];
#endif
#if CONFIG_DESKTOP_HID_REPORT_KEYBOARD_SUPPORT || CONFIG_DESKTOP_HID_BOOT_INTERFACE_KEYBOARD
uint8_t _keyboard_report[REPORT_SIZE_KEYBOARD_KEYS];
#endif
#if CONFIG_DESKTOP_HID_REPORT_SYSTEM_CTRL_SUPPORT
uint8_t _sysctrl_report[REPORT_SIZE_SYSTEM_CTRL];
#endif
#if CONFIG_DESKTOP_HID_REPORT_CONSUMER_CTRL_SUPPORT
uint8_t _consumerctrl_report[REPORT_SIZE_CONSUMER_CTRL];
#endif
#if CONFIG_DESKTOP_HID_BOOT_INTERFACE_MOUSE
uint8_t _boot_mouse_report[REPORT_SIZE_MOUSE_BOOT];
#endif
#if CONFIG_DESKTOP_HID_BOOT_INTERFACE_KEYBOARD
uint8_t _boot_keyboard_report[REPORT_SIZE_KEYBOARD_BOOT];
#endif
};

/* Size of the biggest supported HID input report that is part of input reports map. */
#define REPORT_BUFFER_SIZE_INPUT_REPORT \
_MAX6(_REPORT_BUFFER_SIZE_MOUSE, _REPORT_BUFFER_SIZE_KEYBOARD_KEYS, \
_REPORT_BUFFER_SIZE_SYSTEM_CTRL, _REPORT_BUFFER_SIZE_CONSUMER_CTRL, \
_REPORT_BUFFER_SIZE_BOOT_MOUSE, _REPORT_BUFFER_SIZE_BOOT_KEYBOARD)
union _output_report_size_max {
#if CONFIG_DESKTOP_HID_REPORT_KEYBOARD_SUPPORT
uint8_t _keyboard_report[REPORT_SIZE_KEYBOARD_LEDS];
#endif
};

/* Internal definitions used to calculate size of the biggest supported HID output report. */
#define _REPORT_BUFFER_SIZE_KEYBOARD_LEDS \
(IS_ENABLED(CONFIG_DESKTOP_HID_REPORT_KEYBOARD_SUPPORT) ? (REPORT_SIZE_KEYBOARD_LEDS) : (0))
/* Size of the biggest supported HID input report that is part of input reports map. */
#define REPORT_BUFFER_SIZE_INPUT_REPORT sizeof(union _input_report_size_max)

/* Size of the biggest supported HID output report that is part of output reports map. */
#define REPORT_BUFFER_SIZE_OUTPUT_REPORT _REPORT_BUFFER_SIZE_KEYBOARD_LEDS
#define REPORT_BUFFER_SIZE_OUTPUT_REPORT sizeof(union _output_report_size_max)

extern const uint8_t hid_report_desc[];
extern const size_t hid_report_desc_size;
Expand Down

0 comments on commit d99fda6

Please sign in to comment.