From 6c2013756a88ee0728f7890e6608d23db021a055 Mon Sep 17 00:00:00 2001 From: RockyZeroFour Date: Mon, 23 Sep 2024 17:49:12 +0200 Subject: [PATCH] New function to get itfnum from HID instance - Function to get the interface number for a given HID instance --- src/class/hid/hid_device.c | 8 ++++++++ src/class/hid/hid_device.h | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index ca08907928..dfc0897999 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -74,6 +74,14 @@ static inline uint8_t get_index_by_itfnum(uint8_t itf_num) //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ +uint8_t tud_hid_get_itfnum_by_instance(uint8_t index) +{ + // Only return the interface number when the instance is valid + if ( _hidd_itf[index].ep_in || _hidd_itf[index].ep_out ) return _hidd_itf[index].itf_num; + + return 0xFF; +} + bool tud_hid_n_ready(uint8_t instance) { uint8_t const ep_in = _hidd_itf[instance].ep_in; diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 12023d6ea1..d679b98e34 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -52,6 +52,9 @@ // CFG_TUD_HID > 1 //--------------------------------------------------------------------+ +// Get the interface number for the HID instance index +uint8_t tud_hid_get_itfnum_by_instance(uint8_t index); + // Check if the interface is ready to use bool tud_hid_n_ready(uint8_t instance);