Skip to content

SAM: add iSerial USB field #4009

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 21, 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 hardware/arduino/sam/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 hardware/arduino/sam/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 hardware/arduino/sam/cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ const uint8_t STRING_MANUFACTURER[12] = 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_DeviceDescriptorA =
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);

const QualifierDescriptor USB_DeviceQualifier =
D_QUALIFIER(0x00,0x00,0x00,64,1);
Expand Down Expand Up @@ -429,6 +429,13 @@ static bool USBD_SendDescriptor(USBSetup& setup)
else if (setup.wValueL == IMANUFACTURER) {
return USB_SendStringDescriptor(STRING_MANUFACTURER, setup.wLength);
}
else if (setup.wValueL == ISERIAL) {
#ifdef PLUGGABLE_USB_ENABLED
char name[ISERIAL_MAX_LEN];
PluggableUSB().getShortName(name);
return USB_SendStringDescriptor((uint8_t*)name, setup.wLength);
#endif
}
else {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions hardware/arduino/sam/cores/arduino/USB/USBDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
#define CDC_TX CDC_ENDPOINT_IN
#endif

#define ISERIAL_MAX_LEN 20

#define IMANUFACTURER 1
#define IPRODUCT 2
#define ISERIAL 3

#endif /* __USBDESC_H__ */
10 changes: 10 additions & 0 deletions hardware/arduino/sam/libraries/HID/HID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 hardware/arduino/sam/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