Skip to content
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

Omit serial number if not defined #11104

Merged
merged 2 commits into from
Dec 5, 2020
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
12 changes: 8 additions & 4 deletions tmk_core/protocol/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
.ReleaseNumber = DEVICE_VER,
.ManufacturerStrIndex = 0x01,
.ProductStrIndex = 0x02,
#if defined(SERIAL_NUMBER)
.SerialNumStrIndex = 0x03,
#else
.SerialNumStrIndex = 0x00,
#endif
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};

Expand Down Expand Up @@ -950,17 +954,15 @@ const USB_Descriptor_String_t PROGMEM ProductString = {
.UnicodeString = LSTR(PRODUCT)
};

#ifndef SERIAL_NUMBER
# define SERIAL_NUMBER 0
#endif

#if defined(SERIAL_NUMBER)
const USB_Descriptor_String_t PROGMEM SerialNumberString = {
.Header = {
.Size = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1), // Subtract 1 for null terminator
.Type = DTYPE_String
},
.UnicodeString = LSTR(SERIAL_NUMBER)
};
#endif

// clang-format on

Expand Down Expand Up @@ -1005,11 +1007,13 @@ uint16_t get_usb_descriptor(const uint16_t wValue, const uint16_t wIndex, const
Size = pgm_read_byte(&ProductString.Header.Size);

break;
#if defined(SERIAL_NUMBER)
case 0x03:
Address = &SerialNumberString;
Size = pgm_read_byte(&SerialNumberString.Header.Size);

break;
#endif
}

break;
Expand Down
12 changes: 8 additions & 4 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,6 @@ const PROGMEM uchar console_hid_report[] = {
};
#endif

#ifndef SERIAL_NUMBER
# define SERIAL_NUMBER 0
#endif

#ifndef USB_MAX_POWER_CONSUMPTION
# define USB_MAX_POWER_CONSUMPTION 500
#endif
Expand Down Expand Up @@ -569,13 +565,15 @@ const PROGMEM usbStringDescriptor_t usbStringDescriptorProduct = {
.bString = LSTR(PRODUCT)
};

#if defined(SERIAL_NUMBER)
const PROGMEM usbStringDescriptor_t usbStringDescriptorSerial = {
.header = {
.bLength = USB_STRING_LEN(sizeof(STR(SERIAL_NUMBER)) - 1),
.bDescriptorType = USBDESCR_STRING
},
.bString = LSTR(SERIAL_NUMBER)
};
#endif

/*
* Device descriptor
Expand All @@ -595,7 +593,11 @@ const PROGMEM usbDeviceDescriptor_t usbDeviceDescriptor = {
.bcdDevice = DEVICE_VER,
.iManufacturer = 0x01,
.iProduct = 0x02,
#if defined(SERIAL_NUMBER)
.iSerialNumber = 0x03,
#else
.iSerialNumber = 0x00,
#endif
.bNumConfigurations = 1
};

Expand Down Expand Up @@ -821,10 +823,12 @@ USB_PUBLIC usbMsgLen_t usbFunctionDescriptor(struct usbRequest *rq) {
usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorProduct;
len = usbStringDescriptorProduct.header.bLength;
break;
#if defined(SERIAL_NUMBER)
case 3: // iSerialNumber
usbMsgPtr = (usbMsgPtr_t)&usbStringDescriptorSerial;
len = usbStringDescriptorSerial.header.bLength;
break;
#endif
}
break;
case USBDESCR_HID:
Expand Down