diff options
author | deadprogram <[email protected]> | 2023-03-21 00:09:50 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-03-22 08:35:42 +0100 |
commit | e8f6df928c5917641ad8b5b8d11f69b9d24627c2 (patch) | |
tree | cf3909f7633210190e22ff7d588859bb6f470eda | |
parent | f180339d6b2bf63e02b2d05312870a8fb52bbf39 (diff) | |
download | tinygo-e8f6df928c5917641ad8b5b8d11f69b9d24627c2.tar.gz tinygo-e8f6df928c5917641ad8b5b8d11f69b9d24627c2.zip |
machine/usb: add ability to override default VID, PID, manufacturer name, and product name
Signed-off-by: deadprogram <[email protected]>
-rw-r--r-- | src/machine/usb.go | 42 | ||||
-rw-r--r-- | src/machine/usb/usb.go | 18 |
2 files changed, 55 insertions, 5 deletions
diff --git a/src/machine/usb.go b/src/machine/usb.go index 1449a87bc..05aa7a6c4 100644 --- a/src/machine/usb.go +++ b/src/machine/usb.go @@ -33,6 +33,38 @@ var usbDescriptor = usb.DescriptorCDC var usbDescriptorConfig uint8 = usb.DescriptorConfigCDC +func usbVendorID() uint16 { + if usb.VendorID != 0 { + return usb.VendorID + } + + return usb_VID +} + +func usbProductID() uint16 { + if usb.ProductID != 0 { + return usb.ProductID + } + + return usb_PID +} + +func usbManufacturer() string { + if usb.Manufacturer != "" { + return usb.Manufacturer + } + + return usb_STRING_MANUFACTURER +} + +func usbProduct() string { + if usb.Product != "" { + return usb.Product + } + + return usb_STRING_PRODUCT +} + // strToUTF16LEDescriptor converts a utf8 string into a string descriptor // note: the following code only converts ascii characters to UTF16LE. In order // to do a "proper" conversion, we would need to pull in the 'unicode/utf16' @@ -118,7 +150,7 @@ func sendDescriptor(setup usb.Setup) { usbDescriptor = usb.DescriptorCDC } - usbDescriptor.Configure(usb_VID, usb_PID) + usbDescriptor.Configure(usbVendorID(), usbProductID()) sendUSBPacket(0, usbDescriptor.Device, setup.WLength) return @@ -132,13 +164,13 @@ func sendDescriptor(setup usb.Setup) { sendUSBPacket(0, usb_trans_buffer[:4], setup.WLength) case usb.IPRODUCT: - b := usb_trans_buffer[:(len(usb_STRING_PRODUCT)<<1)+2] - strToUTF16LEDescriptor(usb_STRING_PRODUCT, b) + b := usb_trans_buffer[:(len(usbProduct())<<1)+2] + strToUTF16LEDescriptor(usbProduct(), b) sendUSBPacket(0, b, setup.WLength) case usb.IMANUFACTURER: - b := usb_trans_buffer[:(len(usb_STRING_MANUFACTURER)<<1)+2] - strToUTF16LEDescriptor(usb_STRING_MANUFACTURER, b) + b := usb_trans_buffer[:(len(usbManufacturer())<<1)+2] + strToUTF16LEDescriptor(usbManufacturer(), b) sendUSBPacket(0, b, setup.WLength) case usb.ISERIAL: diff --git a/src/machine/usb/usb.go b/src/machine/usb/usb.go index 8363fc361..97efbbfa4 100644 --- a/src/machine/usb/usb.go +++ b/src/machine/usb/usb.go @@ -126,3 +126,21 @@ func NewSetup(data []byte) Setup { u.WLength = uint16(data[6]) | (uint16(data[7]) << 8) return u } + +var ( + // VendorID aka VID is the officially assigned vendor number + // for this USB device. Only set this if you know what you are doing, + // since changing it can make it difficult to reflash some devices. + VendorID uint16 + + // ProductID aka PID is the product number associated with the officially assigned + // vendor number for this USB device. Only set this if you know what you are doing, + // since changing it can make it difficult to reflash some devices. + ProductID uint16 + + // Manufacturer is the manufacturer name displayed for this USB device. + Manufacturer string + + // Product is the product name displayed for this USB device. + Product string +) |