From 0d04aef6fe8389b649fe1a8c17ea1cc022c7264c Mon Sep 17 00:00:00 2001 From: Michael Hope Date: Sat, 31 Mar 2018 17:27:22 +0200 Subject: [PATCH] usb: hid: add a INT IN transfer complete callback. int_in_ready is an optional callback that is called when the current interrupt IN transfer has completed. This can be used to wait for the endpoint to go idle or to trigger the next transfer. This is needed for protocols like FIDO U2F that use the interrupt endpoint for transfers. Signed-off-by: Michael Hope --- include/usb/class/usb_hid.h | 8 ++++++++ subsys/usb/class/hid/core.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/usb/class/usb_hid.h b/include/usb/class/usb_hid.h index b4fe3be5546..1a92d51aadf 100644 --- a/include/usb/class/usb_hid.h +++ b/include/usb/class/usb_hid.h @@ -49,6 +49,7 @@ struct usb_hid_descriptor { typedef int (*hid_cb_t)(struct usb_setup_packet *setup, s32_t *len, u8_t **data); +typedef void (*hid_int_ready_callback)(void); struct hid_ops { hid_cb_t get_report; @@ -57,6 +58,13 @@ struct hid_ops { hid_cb_t set_report; hid_cb_t set_idle; hid_cb_t set_protocol; + /* + * int_in_ready is an optional callback that is called when + * the current interrupt IN transfer has completed. This can + * be used to wait for the endpoint to go idle or to trigger + * the next transfer. + */ + hid_int_ready_callback int_in_ready; }; /* HID Report Definitions */ diff --git a/subsys/usb/class/hid/core.c b/subsys/usb/class/hid/core.c index 53fa460c959..80f8badb418 100644 --- a/subsys/usb/class/hid/core.c +++ b/subsys/usb/class/hid/core.c @@ -130,7 +130,11 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup, static void hid_int_in(u8_t ep, enum usb_dc_ep_cb_status_code ep_status) { - SYS_LOG_DBG("ep %x status %d", ep, ep_status); + if (ep_status != USB_DC_EP_DATA_IN || + hid_device.ops->int_in_ready == NULL) { + return; + } + hid_device.ops->int_in_ready(); } /* Describe Endpoints configuration */