-
Notifications
You must be signed in to change notification settings - Fork 156
Description
Is your feature request related to a problem? Please describe.
I'm currently trying to extend/customize HID behavior in the Adafruit TinyUSB stack in a way that mimics the flexibility provided in the upstream TinyUSB project. However, several key callbacks are not marked as weak (__attribute__((weak))
/ TU_ATTR_WEAK
), which makes them difficult to override without modifying the core library files. This limitation makes it harder to implement custom HID behavior (such as composite devices or custom report descriptors) cleanly in user code.
Describe the solution you'd like
Please mark the following callbacks as weak (TU_ATTR_WEAK
) in Adafruit_USBD_HID.h
, Adafruit_USBD_Device.h
and related files so that they can be overridden by user sketches or libraries:
TU_ATTR_WEAK uint8_t const * tud_hid_descriptor_report_cb(void);
TU_ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id,
hid_report_type_t report_type,
uint8_t* buffer, uint16_t reqlen);
TU_ATTR_WEAK void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id,
hid_report_type_t report_type,
uint8_t const* buffer, uint16_t bufsize);
TU_ATTR_WEAK uint8_t const * tud_descriptor_device_cb(void);
TU_ATTR_WEAK uint8_t const * tud_descriptor_configuration_cb(uint8_t index);
TU_ATTR_WEAK uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid);
This would enable developers to fully override descriptor and report behavior in their applications without needing to fork or patch the core library.
Describe alternatives you've considered
- Forking or patching the core Adafruit_TinyUSB_Arduino library, which is not ideal for maintenance or sharing code with others.
- Rewriting parts of the HID implementation outside the library, but this is inconsistent and error-prone.
Additional context
Marking these functions as TU_ATTR_WEAK
is the style already encouraged in the main TinyUSB stack, and would improve compatibility and flexibility for developers building advanced USB devices (like composite HID, dynamic descriptors, etc.). This change would not affect existing users, but would open the door to more powerful use cases.