From 32a2ebb7c7f9b1040a5af9c4b49035317a7aada4 Mon Sep 17 00:00:00 2001 From: Pawel Dunaj Date: Mon, 9 Dec 2024 16:44:00 +0100 Subject: [PATCH] applications: nrf_desktop: generic max report size handling Handle max input and output report size in scalable way. Signed-off-by: Pawel Dunaj --- .../configuration/common/hid_report_desc.h | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/applications/nrf_desktop/configuration/common/hid_report_desc.h b/applications/nrf_desktop/configuration/common/hid_report_desc.h index 455f3fab811b..c891f8759103 100644 --- a/applications/nrf_desktop/configuration/common/hid_report_desc.h +++ b/applications/nrf_desktop/configuration/common/hid_report_desc.h @@ -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;