From a2c4a48dd627828f5899e5ab70412594b60f37c6 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 22 May 2021 22:03:21 +0700 Subject: [PATCH] add tuh_hid_report_sent_cb() --- examples/host/cdc_msc_hid/src/hid_app.c | 2 +- src/class/hid/hid_host.c | 5 +++-- src/class/hid/hid_host.h | 10 +++++++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/host/cdc_msc_hid/src/hid_app.c b/examples/host/cdc_msc_hid/src/hid_app.c index 67be8d50f..23ab12404 100644 --- a/examples/host/cdc_msc_hid/src/hid_app.c +++ b/examples/host/cdc_msc_hid/src/hid_app.c @@ -75,7 +75,7 @@ void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance); } -// Invoked when received Report from device via either regular endpoint +// Invoked when received report from device via interrupt endpoint void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) { (void) dev_addr; diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 63983ca5f..778a897be 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -171,7 +171,6 @@ static bool set_report_complete(uint8_t dev_addr, tusb_control_request_t const * return true; } - bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, void* report, uint16_t len) { hidh_interface_t* hid_itf = get_instance(dev_addr, instance); @@ -203,6 +202,8 @@ bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, u // return !hcd_edpt_busy(dev_addr, hid_itf->ep_in); //} +//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len); + //--------------------------------------------------------------------+ // USBH API //--------------------------------------------------------------------+ @@ -229,7 +230,7 @@ bool hidh_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint3 hidh_get_report(dev_addr, hid_itf); }else { -// if (tuh_hid_set_report_complete_cb) tuh_hid_set_report_complete_cb(dev_addr, instance, xferred_bytes); + if (tuh_hid_report_sent_cb) tuh_hid_report_sent_cb(dev_addr, instance, hid_itf->epout_buf, xferred_bytes); } return true; diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h index 3f9979f52..ea693df69 100644 --- a/src/class/hid/hid_host.h +++ b/src/class/hid/hid_host.h @@ -90,6 +90,10 @@ uint8_t tuh_hid_parse_report_descriptor(tuh_hid_report_info_t* reports_info_arr, // Check if the interface is ready to use //bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance); +// Send report using interrupt endpoint +// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent. +//void tuh_hid_send_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t const* report, uint16_t len); + //--------------------------------------------------------------------+ // Callbacks (Weak is optional) //--------------------------------------------------------------------+ @@ -102,9 +106,13 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report_ // Invoked when device with hid interface is un-mounted TU_ATTR_WEAK void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance); -// Invoked when received Report from device via either regular endpoint +// Invoked when received report from device via interrupt endpoint +// Note: if there is report ID (composite), it is 1st byte of report void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len); +// Invoked when sent report to device successfully via interrupt endpoint +TU_ATTR_WEAK void tuh_hid_report_sent_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len); + // Invoked when Sent Report to device via either control endpoint // len = 0 indicate there is error in the transfer e.g stalled response TU_ATTR_WEAK void tuh_hid_set_report_complete_cb(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, uint16_t len);