summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2022-02-13 14:33:54 +0800
committersakumisu <[email protected]>2022-02-13 14:33:59 +0800
commit0ec3c5e4ef8ad9a8fc0dcf95b7cccca5f9b9b5d4 (patch)
tree135fcd8575e8f6807f8a86774e524a6231d6cb5c
parent97f5b0e9af67819ce1f0c81baffaa70fdb49334c (diff)
complete async callback process for print received data
-rw-r--r--class/cdc/usbh_cdc_acm.c23
-rw-r--r--class/hid/usbh_hid.c13
2 files changed, 26 insertions, 10 deletions
diff --git a/class/cdc/usbh_cdc_acm.c b/class/cdc/usbh_cdc_acm.c
index 0b927381..f751ca9b 100644
--- a/class/cdc/usbh_cdc_acm.c
+++ b/class/cdc/usbh_cdc_acm.c
@@ -27,8 +27,6 @@
static uint32_t g_devinuse = 0;
-void usbh_cdc_acm_callback(void *arg, int nbytes);
-
/****************************************************************************
* Name: usbh_cdc_acm_devno_alloc
*
@@ -169,8 +167,22 @@ int usbh_cdc_acm_set_line_state(struct usbh_hubport *hport, uint8_t intf, bool d
return 0;
}
+
USB_NOCACHE_RAM_SECTION uint8_t cdc_buffer[4096];
+void usbh_cdc_acm_callback(void *arg, int nbytes)
+{
+ struct usbh_hub *cdc_acm_class = (struct usbh_hub *)arg;
+
+ if (nbytes > 0) {
+ for (size_t i = 0; i < nbytes; i++) {
+ printf("0x%02x ", cdc_buffer[i]);
+ }
+ }
+
+ printf("nbytes:%d\r\n", nbytes);
+}
+
int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
{
struct usbh_endpoint_cfg ep_cfg = { 0 };
@@ -268,7 +280,7 @@ int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
printf("send over:%d\r\n", ret);
#if 0
- usbh_ep_bulk_async_transfer(cdc_acm_class->bulkin, cdc_buffer, 512, usbh_cdc_acm_callback, NULL);
+ usbh_ep_bulk_async_transfer(cdc_acm_class->bulkin, cdc_buffer, 512, usbh_cdc_acm_callback, cdc_acm_class);
#else
ret = usbh_ep_bulk_transfer(cdc_acm_class->bulkin, cdc_buffer, 512);
if (ret < 0) {
@@ -324,11 +336,6 @@ int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret;
}
-void usbh_cdc_acm_callback(void *arg, int result)
-{
- printf("result:%d\r\n", result);
-}
-
const struct usbh_class_driver cdc_acm_class_driver = {
.driver_name = "cdc_acm",
.connect = usbh_cdc_acm_connect,
diff --git a/class/hid/usbh_hid.c b/class/hid/usbh_hid.c
index 5c6e4fc9..f047267a 100644
--- a/class/hid/usbh_hid.c
+++ b/class/hid/usbh_hid.c
@@ -163,6 +163,14 @@ USB_NOCACHE_RAM_SECTION uint8_t report_buffer[128];
void usbh_hid_callback(void *arg, int nbytes)
{
+ struct usbh_hub *hid_class = (struct usbh_hub *)arg;
+
+ if (nbytes > 0) {
+ for (size_t i = 0; i < nbytes; i++) {
+ printf("0x%02x ", report_buffer[i]);
+ }
+ }
+
printf("nbytes:%d\r\n", nbytes);
}
@@ -218,11 +226,12 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_INFO("Register HID Class:%s\r\n", devname);
- ret = usbh_ep_intr_async_transfer(hid_class->intin, report_buffer, 128, usbh_hid_callback, NULL);
+#if 1
+ ret = usbh_ep_intr_async_transfer(hid_class->intin, report_buffer, 128, usbh_hid_callback, hid_class);
if (ret < 0) {
return ret;
}
-#if 0
+#else
ret = usbh_ep_intr_transfer(hid_class->intin, report_buffer, 128);
if (ret < 0) {
return ret;