aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino/USBCore.cpp
diff options
context:
space:
mode:
authorDaniel Gibson <metalcaedes@gmail.com>2021-01-05 13:48:43 +0100
committerDaniel Gibson <metalcaedes@gmail.com>2021-01-06 17:27:52 +0100
commit8e823d276f939d79b2d323fad675fb8442a718c2 (patch)
tree54af191c3614736bafc4ad66e9c3e4512403140e /cores/arduino/USBCore.cpp
parent60f0d0b125e06dbf57b800192c80e5f60d681438 (diff)
Allow disabling CDC with -DCDC_DISABLED
Sometimes Arduino-based USB devices don't work because some hardware (like KVM switches) gets confused by the CDC sub-devices. This change makes it relatively easy to disable CDC at compiletime. Disabling it of course means that the serial console won't work anymore, so you need to use the reset button when flashing. CDC_DISABLED is also used in ArduinoCore-samd for the same purpose. based on https://github.com/gdsports/usb-metamorph/tree/master/USBSerPassThruLine See also https://github.com/NicoHood/HID/issues/225 and https://github.com/arduino/Arduino/issues/6387 and https://forum.arduino.cc/index.php?topic=545288.msg3717028#msg3717028
Diffstat (limited to 'cores/arduino/USBCore.cpp')
-rw-r--r--cores/arduino/USBCore.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp
index dc6bc38..9335238 100644
--- a/cores/arduino/USBCore.cpp
+++ b/cores/arduino/USBCore.cpp
@@ -69,8 +69,18 @@ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
#define DEVICE_CLASS 0x02
// DEVICE DESCRIPTOR
+
+#ifdef CDC_ENABLED
const DeviceDescriptor USB_DeviceDescriptorIAD =
D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
+#else // CDC_DISABLED
+// The default descriptor uses USB class OxEF, subclass 0x02 with protocol 1
+// which means "Interface Association Descriptor" - that's needed for the CDC,
+// but doesn't make much sense as a default for custom devices when CDC is disabled.
+// (0x00 means "Use class information in the Interface Descriptors" which should be generally ok)
+const DeviceDescriptor USB_DeviceDescriptorIAD =
+ D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
+#endif
//==================================================================
//==================================================================
@@ -328,10 +338,12 @@ int USB_Send(u8 ep, const void* d, int len)
u8 _initEndpoints[USB_ENDPOINTS] =
{
0, // Control Endpoint
-
+
+#ifdef CDC_ENABLED
EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM
EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
+#endif
// Following endpoints are automatically initialized to 0
};
@@ -373,10 +385,12 @@ void InitEndpoints()
static
bool ClassInterfaceRequest(USBSetup& setup)
{
+#ifdef CDC_ENABLED
u8 i = setup.wIndex;
if (CDC_ACM_INTERFACE == i)
return CDC_Setup(setup);
+#endif
#ifdef PLUGGABLE_USB_ENABLED
return PluggableUSB().setup(setup);
@@ -466,7 +480,9 @@ static u8 SendInterfaces()
{
u8 interfaces = 0;
+#ifdef CDC_ENABLED
CDC_GetInterface(&interfaces);
+#endif
#ifdef PLUGGABLE_USB_ENABLED
PluggableUSB().getInterface(&interfaces);