aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
authorMartino Facchin <m.facchin@arduino.cc>2015-10-13 15:13:31 +0200
committerMartino Facchin <m.facchin@arduino.cc>2015-10-21 15:23:56 +0200
commitced062988bf0df175e54b77b658132685100b350 (patch)
tree5c95d5a374af46ed508e9b05870e6a658f38c3f4 /cores/arduino
parentf42b26c257859f1b76094972727c4ebc2b412a62 (diff)
[USB] use plugged modules name to create iSerial field
Diffstat (limited to 'cores/arduino')
-rw-r--r--cores/arduino/PluggableUSB.cpp9
-rw-r--r--cores/arduino/PluggableUSB.h2
-rw-r--r--cores/arduino/USBCore.cpp21
-rw-r--r--cores/arduino/USBDesc.h8
4 files changed, 31 insertions, 9 deletions
diff --git a/cores/arduino/PluggableUSB.cpp b/cores/arduino/PluggableUSB.cpp
index 7a6351d..c489d9f 100644
--- a/cores/arduino/PluggableUSB.cpp
+++ b/cores/arduino/PluggableUSB.cpp
@@ -50,6 +50,15 @@ int PluggableUSB_::getDescriptor(USBSetup& setup)
return 0;
}
+void PluggableUSB_::getShortName(char *iSerialNum)
+{
+ PluggableUSBModule* node;
+ for (node = rootNode; node; node = node->next) {
+ iSerialNum += node->getShortName(iSerialNum);
+ }
+ *iSerialNum = 0;
+}
+
bool PluggableUSB_::setup(USBSetup& setup)
{
PluggableUSBModule* node;
diff --git a/cores/arduino/PluggableUSB.h b/cores/arduino/PluggableUSB.h
index 3df9bff..507f0df 100644
--- a/cores/arduino/PluggableUSB.h
+++ b/cores/arduino/PluggableUSB.h
@@ -35,6 +35,7 @@ protected:
virtual bool setup(USBSetup& setup) = 0;
virtual int getInterface(uint8_t* interfaceCount) = 0;
virtual int getDescriptor(USBSetup& setup) = 0;
+ virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; }
uint8_t pluggedInterface;
uint8_t pluggedEndpoint;
@@ -55,6 +56,7 @@ public:
int getInterface(uint8_t* interfaceCount);
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);
+ void getShortName(char *iSerialNum);
private:
uint8_t lastIf;
diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp
index f67bfea..3c6610c 100644
--- a/cores/arduino/USBCore.cpp
+++ b/cores/arduino/USBCore.cpp
@@ -18,6 +18,7 @@
#include "USBAPI.h"
#include "PluggableUSB.h"
+#include <stdlib.h>
#if defined(USBCON)
@@ -69,10 +70,10 @@ const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
// DEVICE DESCRIPTOR
const DeviceDescriptor USB_DeviceDescriptor =
- D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
+ D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
const DeviceDescriptor USB_DeviceDescriptorB =
- D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
+ D_DEVICE(0xEF,0x02,0x01,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,ISERIAL,1);
//==================================================================
//==================================================================
@@ -409,11 +410,12 @@ int USB_SendControl(u8 flags, const void* d, int len)
// Send a USB descriptor string. The string is stored in PROGMEM as a
// plain ASCII string but is sent out as UTF-16 with the correct 2-byte
// prefix
-static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) {
+static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len, uint8_t flags) {
SendControl(2 + string_len * 2);
SendControl(3);
+ bool pgm = flags & TRANSFER_PGM;
for(u8 i = 0; i < string_len; i++) {
- bool r = SendControl(pgm_read_byte(&string_P[i]));
+ bool r = SendControl(pgm ? pgm_read_byte(&string_P[i]) : string_P[i]);
r &= SendControl(0); // high byte
if(!r) {
return false;
@@ -495,10 +497,17 @@ bool SendDescriptor(USBSetup& setup)
desc_addr = (const u8*)&STRING_LANGUAGE;
}
else if (setup.wValueL == IPRODUCT) {
- return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT));
+ return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT), TRANSFER_PGM);
}
else if (setup.wValueL == IMANUFACTURER) {
- return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER));
+ return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER), TRANSFER_PGM);
+ }
+ else if (setup.wValueL == ISERIAL) {
+#ifdef PLUGGABLE_USB_ENABLED
+ char name[ISERIAL_MAX_LEN];
+ PluggableUSB().getShortName(name);
+ return USB_SendStringDescriptor((uint8_t*)name, strlen(name), 0);
+#endif
}
else
return false;
diff --git a/cores/arduino/USBDesc.h b/cores/arduino/USBDesc.h
index 4b9cf66..c0dce07 100644
--- a/cores/arduino/USBDesc.h
+++ b/cores/arduino/USBDesc.h
@@ -24,6 +24,8 @@
#define USB_ENDPOINTS 5 // AtMegaxxU2
#endif
+#define ISERIAL_MAX_LEN 20
+
#define CDC_INTERFACE_COUNT 2
#define CDC_ENPOINT_COUNT 3
@@ -39,6 +41,6 @@
#define CDC_RX CDC_ENDPOINT_OUT
#define CDC_TX CDC_ENDPOINT_IN
-#define IMANUFACTURER 1
-#define IPRODUCT 2
-
+#define IMANUFACTURER 1
+#define IPRODUCT 2
+#define ISERIAL 3 \ No newline at end of file