From 301d69d045d9f3e636ec4f8a1f8d5b02b2cb0e3f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 24 Dec 2020 11:38:51 +0100 Subject: [PATCH] PluggableUSB: modules modify bcdDevice value This should solve driver mismatch in Windows when a different USBDevice functionality is added/removed. Based on this suggestion: https://github.com/arduino-libraries/Keyboard/issues/41#issuecomment-730700142 Fixes https://github.com/arduino/ArduinoCore-mbed/issues/107#issuecomment-750378348 --- cores/arduino/USB/PluggableUSBDevice.cpp | 1 + cores/arduino/USB/PluggableUSBDevice.h | 1 + cores/arduino/USB/USBCDC.cpp | 5 +++++ cores/arduino/USB/USBCDC.h | 7 +++++++ libraries/USBAudio/PluggableUSBAudio.h | 7 +++++++ libraries/USBAudio/USBAudio.cpp | 5 +++++ libraries/USBHID/PluggableUSBHID.h | 7 +++++++ libraries/USBHID/USBHID.cpp | 4 ++++ libraries/USBMSD/PluggableUSBMSD.h | 7 +++++++ libraries/USBMSD/USBMSD.cpp | 4 ++++ 10 files changed, 48 insertions(+) diff --git a/cores/arduino/USB/PluggableUSBDevice.cpp b/cores/arduino/USB/PluggableUSBDevice.cpp index 8b02ca825..9b871614c 100644 --- a/cores/arduino/USB/PluggableUSBDevice.cpp +++ b/cores/arduino/USB/PluggableUSBDevice.cpp @@ -95,6 +95,7 @@ bool arduino::PluggableUSBDevice::plug(internal::PluggableUSBModule*node) node->pluggedInterface = lastIf; lastIf += node->numInterfaces; + product_release += node->getProductVersion(); return true; } diff --git a/cores/arduino/USB/PluggableUSBDevice.h b/cores/arduino/USB/PluggableUSBDevice.h index 87f9779e5..561ed74c0 100644 --- a/cores/arduino/USB/PluggableUSBDevice.h +++ b/cores/arduino/USB/PluggableUSBDevice.h @@ -58,6 +58,7 @@ class PluggableUSBModule { virtual void callback_set_interface(uint16_t interface, uint8_t alternate); virtual void init(EndpointResolver& resolver); virtual const uint8_t *string_iinterface_desc(); + virtual uint8_t getProductVersion(); uint8_t pluggedInterface; diff --git a/cores/arduino/USB/USBCDC.cpp b/cores/arduino/USB/USBCDC.cpp index fcddbaea8..ef1e5674f 100644 --- a/cores/arduino/USB/USBCDC.cpp +++ b/cores/arduino/USB/USBCDC.cpp @@ -489,6 +489,11 @@ const uint8_t *USBCDC::string_iinterface_desc() return (const uint8_t *)extraDescriptor; } +uint8_t USBCDC::getProductVersion() +{ + return 1; +} + const uint8_t *USBCDC::string_iproduct_desc() { static const uint8_t stringIproductDescriptor[] = { diff --git a/cores/arduino/USB/USBCDC.h b/cores/arduino/USB/USBCDC.h index 5ae13da83..0bee97470 100644 --- a/cores/arduino/USB/USBCDC.h +++ b/cores/arduino/USB/USBCDC.h @@ -144,6 +144,13 @@ class USBCDC: public internal::PluggableUSBModule{ */ virtual const uint8_t *string_iproduct_desc(); + /* + * Get string product version + * + * Every module must declare a different number + */ + virtual uint8_t getProductVersion(); + /* * Get string interface descriptor * diff --git a/libraries/USBAudio/PluggableUSBAudio.h b/libraries/USBAudio/PluggableUSBAudio.h index 94688733f..d9b260157 100644 --- a/libraries/USBAudio/PluggableUSBAudio.h +++ b/libraries/USBAudio/PluggableUSBAudio.h @@ -274,6 +274,13 @@ class USBAudio: protected internal::PluggableUSBModule { virtual const uint8_t *string_iinterface_desc(); virtual const uint8_t *configuration_desc(uint8_t index); + /* + * Get string product version + * + * Every module must declare a different number + */ + virtual uint8_t getProductVersion(); + private: class AsyncWrite; diff --git a/libraries/USBAudio/USBAudio.cpp b/libraries/USBAudio/USBAudio.cpp index 892239850..7615fe154 100644 --- a/libraries/USBAudio/USBAudio.cpp +++ b/libraries/USBAudio/USBAudio.cpp @@ -588,6 +588,11 @@ const uint8_t *USBAudio::configuration_desc(uint8_t index) return _config_descriptor; } +uint8_t USBAudio::getProductVersion() +{ + return 2; +} + const uint8_t *USBAudio::string_iinterface_desc() { static const uint8_t stringIinterfaceDescriptor[] = { diff --git a/libraries/USBHID/PluggableUSBHID.h b/libraries/USBHID/PluggableUSBHID.h index 2626c5231..bb7324376 100644 --- a/libraries/USBHID/PluggableUSBHID.h +++ b/libraries/USBHID/PluggableUSBHID.h @@ -163,6 +163,13 @@ class USBHID: public internal::PluggableUSBModule { */ virtual uint16_t report_desc_length(); + /* + * Get string product version + * + * Every module must declare a different number + */ + virtual uint8_t getProductVersion(); + /* * Get string product descriptor * diff --git a/libraries/USBHID/USBHID.cpp b/libraries/USBHID/USBHID.cpp index 8d4b44c52..fe7f7e6c4 100644 --- a/libraries/USBHID/USBHID.cpp +++ b/libraries/USBHID/USBHID.cpp @@ -388,6 +388,10 @@ void USBHID::callback_set_interface(uint16_t interface, uint8_t alternate) assert_locked(); } +uint8_t USBHID::getProductVersion() +{ + return 4; +} const uint8_t *USBHID::string_iinterface_desc() { diff --git a/libraries/USBMSD/PluggableUSBMSD.h b/libraries/USBMSD/PluggableUSBMSD.h index 017158209..1b55dad9b 100644 --- a/libraries/USBMSD/PluggableUSBMSD.h +++ b/libraries/USBMSD/PluggableUSBMSD.h @@ -282,6 +282,13 @@ class USBMSD: public internal::PluggableUSBModule { // space for config descriptor uint8_t _configuration_descriptor[32]; + /* + * Get string product version + * + * Every module must declare a different number + */ + virtual uint8_t getProductVersion(); + virtual const uint8_t *string_iproduct_desc(); virtual const uint8_t *string_iinterface_desc(); virtual const uint8_t *configuration_desc(uint8_t index); diff --git a/libraries/USBMSD/USBMSD.cpp b/libraries/USBMSD/USBMSD.cpp index 19b4fd7e2..3802e0b60 100644 --- a/libraries/USBMSD/USBMSD.cpp +++ b/libraries/USBMSD/USBMSD.cpp @@ -311,6 +311,10 @@ void USBMSD::callback_set_interface(uint16_t interface, uint8_t alternate) //complete_set_interface(success); } +uint8_t USBMSD::getProductVersion() +{ + return 8; +} const uint8_t *USBMSD::string_iinterface_desc() {