Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

applications: nrf_desktop: generic max report size handling #19691

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 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)))

/* 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)

/* 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))
union _input_report_size_max {
#if CONFIG_DESKTOP_HID_REPORT_MOUSE_SUPPORT || CONFIG_DESKTOP_HID_REPORT_BOOT_INTERFACE_MOUSE
uint8_t _mouse_report[REPORT_SIZE_MOUSE];
#endif
#if CONFIG_DESKTOP_HID_REPORT_KEYBOARD_SUPPORT || CONFIG_DESKTOP_HID_REPORT_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_REPORT_BOOT_INTERFACE_MOUSE
uint8_t _mouse_report[REPORT_SIZE_MOUSE_BOOT];
#endif
#if CONFIG_DESKTOP_HID_REPORT_BOOT_INTERFACE_KEYBOARD
uint8_t _keyboard_report[REPORT_SIZE_KEYBOARD_BOOT];
#endif
};

union _output_report_size_max {
#if CONFIG_DESKTOP_HID_REPORT_KEYBOARD_SUPPORT
uint8_t _keyboard_report[REPORT_SIZE_KEYBOARD_LEDS];
#endif
};

/* Size of the biggest supported HID input report that is part of output 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
Loading