create N functions and inlines for multi hid interfaces
This commit is contained in:
parent
9a0a78c52e
commit
849681724a
|
@ -70,17 +70,17 @@ static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// APPLICATION API
|
// APPLICATION API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
bool tud_hid_ready(void)
|
bool tud_hid_n_ready(uint8_t itf)
|
||||||
{
|
{
|
||||||
uint8_t const itf = 0;
|
//uint8_t const itf = 0;
|
||||||
uint8_t const ep_in = _hidd_itf[itf].ep_in;
|
uint8_t const ep_in = _hidd_itf[itf].ep_in;
|
||||||
return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
|
return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len)
|
||||||
{
|
{
|
||||||
uint8_t const rhport = 0;
|
uint8_t const rhport = 0;
|
||||||
uint8_t const itf = 0;
|
//uint8_t const itf = 0;
|
||||||
hidd_interface_t * p_hid = &_hidd_itf[itf];
|
hidd_interface_t * p_hid = &_hidd_itf[itf];
|
||||||
|
|
||||||
// claim endpoint
|
// claim endpoint
|
||||||
|
@ -104,16 +104,16 @@ bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||||
return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
|
return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tud_hid_boot_mode(void)
|
bool tud_hid_n_boot_mode(uint8_t itf)
|
||||||
{
|
{
|
||||||
uint8_t itf = 0;
|
//uint8_t itf = 0;
|
||||||
return _hidd_itf[itf].boot_mode;
|
return _hidd_itf[itf].boot_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// KEYBOARD API
|
// KEYBOARD API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
|
bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
|
||||||
{
|
{
|
||||||
hid_keyboard_report_t report;
|
hid_keyboard_report_t report;
|
||||||
|
|
||||||
|
@ -127,13 +127,13 @@ bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycod
|
||||||
tu_memclr(report.keycode, 6);
|
tu_memclr(report.keycode, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
return tud_hid_report(report_id, &report, sizeof(report));
|
return tud_hid_n_report(itf, report_id, &report, sizeof(report));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MOUSE APPLICATION API
|
// MOUSE APPLICATION API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
|
bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
|
||||||
{
|
{
|
||||||
hid_mouse_report_t report =
|
hid_mouse_report_t report =
|
||||||
{
|
{
|
||||||
|
@ -144,7 +144,7 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y
|
||||||
.pan = horizontal
|
.pan = horizontal
|
||||||
};
|
};
|
||||||
|
|
||||||
return tud_hid_report(report_id, &report, sizeof(report));
|
return tud_hid_n_report(itf, report_id, &report, sizeof(report));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
|
@ -50,25 +50,35 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Application API
|
// Application API (Multiple Ports)
|
||||||
|
// CFG_TUD_HID > 1
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
// Check if the interface is ready to use
|
// Check if the interface is ready to use
|
||||||
bool tud_hid_ready(void);
|
bool tud_hid_n_ready(uint8_t itf);
|
||||||
|
|
||||||
// Check if current mode is Boot (true) or Report (false)
|
// Check if current mode is Boot (true) or Report (false)
|
||||||
bool tud_hid_boot_mode(void);
|
bool tud_hid_n_boot_mode(uint8_t itf);
|
||||||
|
|
||||||
// Send report to host
|
// Send report to host
|
||||||
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
|
bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len);
|
||||||
|
|
||||||
// KEYBOARD: convenient helper to send keyboard report if application
|
// KEYBOARD: convenient helper to send keyboard report if application
|
||||||
// use template layout report as defined by hid_keyboard_report_t
|
// use template layout report as defined by hid_keyboard_report_t
|
||||||
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||||
|
|
||||||
// MOUSE: convenient helper to send mouse report if application
|
// MOUSE: convenient helper to send mouse report if application
|
||||||
// use template layout report as defined by hid_mouse_report_t
|
// use template layout report as defined by hid_mouse_report_t
|
||||||
bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Application API (Single Port)
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
static inline bool tud_hid_ready(void);
|
||||||
|
static inline bool tud_hid_boot_mode(void);
|
||||||
|
static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
|
||||||
|
static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
|
||||||
|
static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Callbacks (Weak is optional)
|
// Callbacks (Weak is optional)
|
||||||
|
@ -95,6 +105,34 @@ TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
|
||||||
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
|
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
|
||||||
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
|
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Inline Functions
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
static inline bool tud_hid_ready(void)
|
||||||
|
{
|
||||||
|
return tud_hid_n_ready(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool tud_hid_boot_mode(void)
|
||||||
|
{
|
||||||
|
return tud_hid_n_boot_mode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
|
||||||
|
{
|
||||||
|
return tud_hid_n_report(0, report_id, report, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
|
||||||
|
{
|
||||||
|
return tud_hid_n_keyboard_report(0, report_id, modifier, keycode);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
|
||||||
|
{
|
||||||
|
return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal);
|
||||||
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------+
|
/* --------------------------------------------------------------------+
|
||||||
* HID Report Descriptor Template
|
* HID Report Descriptor Template
|
||||||
*
|
*
|
||||||
|
@ -318,4 +356,3 @@ bool hidd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t e
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _TUSB_HID_DEVICE_H_ */
|
#endif /* _TUSB_HID_DEVICE_H_ */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue