Skip to content

PluggableUSB: add iSerial USB field #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cores/arduino/USB/PluggableUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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;
Expand Down
2 changes: 2 additions & 0 deletions cores/arduino/USB/PluggableUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class PluggableUSBModule {
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;
Expand All @@ -55,6 +56,7 @@ class PluggableUSB_ {
int getInterface(uint8_t* interfaceCount);
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);
void getShortName(char *iSerialNum);

private:
uint8_t lastIf;
Expand Down
11 changes: 9 additions & 2 deletions cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const uint8_t STRING_MANUFACTURER[] = USB_MANUFACTURER;


// DEVICE DESCRIPTOR
const DeviceDescriptor USB_DeviceDescriptorB = D_DEVICE(0xEF, 0x02, 0x01, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
const DeviceDescriptor USB_DeviceDescriptor = D_DEVICE(0x00, 0x00, 0x00, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, 0, 1);
const DeviceDescriptor USB_DeviceDescriptorB = D_DEVICE(0xEF, 0x02, 0x01, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, ISERIAL, 1);
const DeviceDescriptor USB_DeviceDescriptor = D_DEVICE(0x00, 0x00, 0x00, 64, USB_VID, USB_PID, 0x100, IMANUFACTURER, IPRODUCT, ISERIAL, 1);

//==================================================================

Expand Down Expand Up @@ -208,6 +208,13 @@ bool USBDeviceClass::sendDescriptor(USBSetup &setup)
else if (setup.wValueL == IMANUFACTURER) {
return sendStringDescriptor(STRING_MANUFACTURER, setup.wLength);
}
else if (setup.wValueL == ISERIAL) {
#ifdef PLUGGABLE_USB_ENABLED
char name[ISERIAL_MAX_LEN];
PluggableUSB().getShortName(name);
return sendStringDescriptor((uint8_t*)name, setup.wLength);
#endif
}
else {
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion cores/arduino/USB/USBDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
#define CDC_TX CDC_ENDPOINT_IN
#endif

#define ISERIAL_MAX_LEN 20

// Defined string description
#define IMANUFACTURER 1
#define IPRODUCT 2
#define IPRODUCT 2
#define ISERIAL 3

#endif /* __USBDESC_H__ */
10 changes: 10 additions & 0 deletions libraries/HID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ int HID_::getDescriptor(USBSetup& setup)
return total;
}

uint8_t HID_::getShortName(char *name)
{
name[0] = 'H';
name[1] = 'I';
name[2] = 'D';
name[3] = 'A' + (descriptorSize & 0x0F);
name[4] = 'A' + ((descriptorSize >> 4) & 0x0F);
return 5;
}

void HID_::AppendDescriptor(HIDSubDescriptor *node)
{
if (!rootNode) {
Expand Down
1 change: 1 addition & 0 deletions libraries/HID/HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class HID_ : public PluggableUSBModule
int getInterface(uint8_t* interfaceCount);
int getDescriptor(USBSetup& setup);
bool setup(USBSetup& setup);
uint8_t getShortName(char* name);

private:
uint32_t epType[1];
Expand Down