hathach 7 سال پیش
والد
کامیت
bb544a0951
2فایلهای تغییر یافته به همراه15 افزوده شده و 5 حذف شده
  1. 13 4
      examples/device/cdc_msc_hid/src/main.c
  2. 2 1
      src/class/cdc/cdc_device.c

+ 13 - 4
examples/device/cdc_msc_hid/src/main.c

@@ -94,10 +94,19 @@ void virtual_com_task(void)
       // read and echo back
       uint32_t count = tud_cdc_read(buf, sizeof(buf));
 
-      tud_cdc_write(buf, count);
-    }
+      for(uint32_t i=0; i<count; i++)
+      {
+        tud_cdc_write_char(buf[i]);
 
-    tud_cdc_write_flush();
+        if ( buf[i] == '\r' )
+        {
+          tud_cdc_write_char('\n');
+          tud_cdc_write_str("tinyusb cdc: ");
+        }
+      }
+
+      tud_cdc_write_flush();
+    }
   }
 }
 
@@ -109,7 +118,7 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
   if ( dtr && rts )
   {
     // print greeting
-    tud_cdc_write_str("tinyusb usb cdc\n");
+    tud_cdc_write_str("tinyusb cdc: ");
   }
 }
 #endif

+ 2 - 1
src/class/cdc/cdc_device.c

@@ -346,9 +346,10 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request
       //        This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send)
       p_cdc->line_state = (uint8_t) request->wValue;
 
+      usbd_control_status(rhport, request);
+
       // Invoke callback
       if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, BIT_TEST_(request->wValue, 0), BIT_TEST_(request->wValue, 1));
-      usbd_control_status(rhport, request);
     break;
 
     default: return false; // stall unsupported request