machine/usb: add ability to override default VID, PID, manufacturer name, and product name
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
f180339d6b
коммит
e8f6df928c
2 изменённых файлов: 55 добавлений и 5 удалений
|
@ -33,6 +33,38 @@ var usbDescriptor = usb.DescriptorCDC
|
||||||
|
|
||||||
var usbDescriptorConfig uint8 = usb.DescriptorConfigCDC
|
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
|
// strToUTF16LEDescriptor converts a utf8 string into a string descriptor
|
||||||
// note: the following code only converts ascii characters to UTF16LE. In order
|
// 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'
|
// 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 = usb.DescriptorCDC
|
||||||
}
|
}
|
||||||
|
|
||||||
usbDescriptor.Configure(usb_VID, usb_PID)
|
usbDescriptor.Configure(usbVendorID(), usbProductID())
|
||||||
sendUSBPacket(0, usbDescriptor.Device, setup.WLength)
|
sendUSBPacket(0, usbDescriptor.Device, setup.WLength)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -132,13 +164,13 @@ func sendDescriptor(setup usb.Setup) {
|
||||||
sendUSBPacket(0, usb_trans_buffer[:4], setup.WLength)
|
sendUSBPacket(0, usb_trans_buffer[:4], setup.WLength)
|
||||||
|
|
||||||
case usb.IPRODUCT:
|
case usb.IPRODUCT:
|
||||||
b := usb_trans_buffer[:(len(usb_STRING_PRODUCT)<<1)+2]
|
b := usb_trans_buffer[:(len(usbProduct())<<1)+2]
|
||||||
strToUTF16LEDescriptor(usb_STRING_PRODUCT, b)
|
strToUTF16LEDescriptor(usbProduct(), b)
|
||||||
sendUSBPacket(0, b, setup.WLength)
|
sendUSBPacket(0, b, setup.WLength)
|
||||||
|
|
||||||
case usb.IMANUFACTURER:
|
case usb.IMANUFACTURER:
|
||||||
b := usb_trans_buffer[:(len(usb_STRING_MANUFACTURER)<<1)+2]
|
b := usb_trans_buffer[:(len(usbManufacturer())<<1)+2]
|
||||||
strToUTF16LEDescriptor(usb_STRING_MANUFACTURER, b)
|
strToUTF16LEDescriptor(usbManufacturer(), b)
|
||||||
sendUSBPacket(0, b, setup.WLength)
|
sendUSBPacket(0, b, setup.WLength)
|
||||||
|
|
||||||
case usb.ISERIAL:
|
case usb.ISERIAL:
|
||||||
|
|
|
@ -126,3 +126,21 @@ func NewSetup(data []byte) Setup {
|
||||||
u.WLength = uint16(data[6]) | (uint16(data[7]) << 8)
|
u.WLength = uint16(data[6]) | (uint16(data[7]) << 8)
|
||||||
return u
|
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
|
||||||
|
)
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче