Skip to content

Commit 862e861

Browse files
committed
Allow a second USBSerial port
The new contructor also allows specifying a name (extended attribute on interface)
1 parent 1c02465 commit 862e861

File tree

8 files changed

+33
-28
lines changed

8 files changed

+33
-28
lines changed

cores/arduino/USB/PluggableUSBDevice.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,6 @@ const uint8_t *arduino::PluggableUSBDevice::device_desc()
209209
return device_descriptor;
210210
}
211211

212-
const uint8_t *arduino::PluggableUSBDevice::string_iinterface_desc()
213-
{
214-
static const uint8_t stringIinterfaceDescriptor[] = {
215-
0x08,
216-
STRING_DESCRIPTOR,
217-
'U', 0, 'S', 0, 'B', 0,
218-
};
219-
return stringIinterfaceDescriptor;
220-
}
221-
222212
static uint8_t TO_UNICODE(const char* string, uint8_t* where) {
223213
for (size_t i = 0; i < strlen(string); i++) {
224214
where[i*2] = string[i];
@@ -227,6 +217,22 @@ static uint8_t TO_UNICODE(const char* string, uint8_t* where) {
227217
return strlen(string) * 2;
228218
}
229219

220+
const uint8_t *arduino::PluggableUSBDevice::string_iinterface_desc()
221+
{
222+
arduino::internal::PluggableUSBModule* node;
223+
const char* iinterface_descriptor = NULL;
224+
for (node = rootNode; node; node = node->next) {
225+
iinterface_descriptor = (const char*)node->string_iinterface_desc();
226+
if (iinterface_descriptor != NULL) {
227+
break;
228+
}
229+
}
230+
_config_iinterfacedescriptor[0] = 2;
231+
_config_iinterfacedescriptor[1] = STRING_DESCRIPTOR;
232+
_config_iinterfacedescriptor[0] += TO_UNICODE(iinterface_descriptor, &_config_iinterfacedescriptor[2]);
233+
return _config_iinterfacedescriptor;
234+
}
235+
230236
#ifdef BOARD_NAME
231237
const uint8_t *arduino::PluggableUSBDevice::string_iproduct_desc()
232238
{

cores/arduino/USB/PluggableUSBDevice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class PluggableUSBModule {
5555
virtual bool callback_set_configuration(uint8_t configuration);
5656
virtual void callback_set_interface(uint16_t interface, uint8_t alternate);
5757
virtual void init(EndpointResolver& resolver);
58+
virtual const uint8_t *string_iinterface_desc();
5859

5960
uint8_t pluggedInterface;
6061

@@ -197,6 +198,7 @@ class PluggableUSBDevice: public USBDevice {
197198
uint8_t _config_descriptor[400];
198199
uint8_t _config_iserial[64];
199200
uint8_t _config_iproductdescriptor[64];
201+
uint8_t _config_iinterfacedescriptor[64];
200202

201203
uint8_t lastIf;
202204
internal::PluggableUSBModule* rootNode;

cores/arduino/USB/PluggableUSBSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class USBSerial: public USBCDC, public ::mbed::Stream, public HardwareSerial {
6666
* @param product_release Your product_release (default: 0x0001)
6767
*
6868
*/
69-
USBSerial(bool connect_blocking = true, uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001);
69+
USBSerial(bool connect_blocking = true, const char* name = NULL, uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001);
7070

7171
/**
7272
* Fully featured constructor

cores/arduino/USB/USBCDC.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ class USBCDC::AsyncWait: public AsyncOp {
155155
USBCDC *serial;
156156
};
157157

158-
USBCDC::USBCDC(bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
159-
: internal::PluggableUSBModule(2)
158+
USBCDC::USBCDC(bool connect_blocking, const char* name, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
159+
: internal::PluggableUSBModule(2), extraDescriptor(name)
160160
{
161161
PluggableUSBD().plug(this);
162162
}
163163

164-
USBCDC::USBCDC(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
165-
: internal::PluggableUSBModule(2)
164+
USBCDC::USBCDC(USBPhy *phy, const char* name, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
165+
: internal::PluggableUSBModule(2), extraDescriptor(name)
166166
{
167167
PluggableUSBD().plug(this);
168168
}
@@ -492,12 +492,7 @@ void USBCDC::_receive_isr()
492492

493493
const uint8_t *USBCDC::string_iinterface_desc()
494494
{
495-
static const uint8_t stringIinterfaceDescriptor[] = {
496-
0x08,
497-
STRING_DESCRIPTOR,
498-
'C', 0, 'D', 0, 'C', 0,
499-
};
500-
return stringIinterfaceDescriptor;
495+
return (const uint8_t *)extraDescriptor;
501496
}
502497

503498
const uint8_t *USBCDC::string_iproduct_desc()
@@ -546,7 +541,7 @@ const uint8_t *USBCDC::configuration_desc(uint8_t index)
546541
0x02, // bInterfaceClass
547542
0x02, // bInterfaceSubClass
548543
0x01, // bInterfaceProtocol
549-
0, // iInterface
544+
(extraDescriptor != NULL) ? 0x5 : 0x0, // iInterface
550545

551546
// CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26
552547
5, // bFunctionLength

cores/arduino/USB/USBCDC.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class USBCDC: public internal::PluggableUSBModule{
4343
* @param product_id Your product_id
4444
* @param product_release Your product_release
4545
*/
46-
USBCDC(bool connect_blocking = true, uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001);
46+
USBCDC(bool connect_blocking = true, const char* name = NULL, uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001);
4747

4848
/**
4949
* Fully featured constructor
@@ -61,7 +61,7 @@ class USBCDC: public internal::PluggableUSBModule{
6161
* @param product_id Your product_id
6262
* @param product_release Your product_release
6363
*/
64-
USBCDC(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
64+
USBCDC(USBPhy *phy, const char* name, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
6565

6666
/**
6767
* Destroy this object
@@ -216,6 +216,8 @@ class USBCDC: public internal::PluggableUSBModule{
216216
uint8_t _rx_buffer[512];
217217
uint8_t *_rx_buf;
218218
uint32_t _rx_size;
219+
220+
const char* extraDescriptor;
219221
};
220222
}
221223

cores/arduino/USB/USBSerial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void usbPortChanged(int baud, int bits, int parity, int stop) {
4545
}
4646
}
4747

48-
USBSerial::USBSerial(bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release):
49-
USBCDC(get_usb_phy(), vendor_id, product_id, product_release)
48+
USBSerial::USBSerial(bool connect_blocking, const char* name, uint16_t vendor_id, uint16_t product_id, uint16_t product_release):
49+
USBCDC(get_usb_phy(), name, vendor_id, product_id, product_release)
5050
{
5151
_settings_changed_callback = 0;
5252

@@ -56,7 +56,7 @@ USBSerial::USBSerial(bool connect_blocking, uint16_t vendor_id, uint16_t product
5656
}
5757

5858
USBSerial::USBSerial(USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release):
59-
USBCDC(phy, vendor_id, product_id, product_release)
59+
USBCDC(phy, NULL, vendor_id, product_id, product_release)
6060
{
6161
_settings_changed_callback = 0;
6262
}

variants/PORTENTA_H7_M7/defines.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
-DFEATURE_LWIP=1
4444
-D__FPU_PRESENT=1
4545
-D__MBED__=1
46-
-DMBED_BUILD_TIMESTAMP=1597306180.6950672
46+
-DMBED_BUILD_TIMESTAMP=1598515239.1038344
4747
-D__MBED_CMSIS_RTOS_CM
4848
-DMBED_HEAP_STATS_ENABLED=1
4949
-DMBED_MEM_TRACING_ENABLED=1
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)