mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 11:37:46 +00:00
machine/usb: add support for ISERIAL descriptor
This commit is contained in:
+15
-2
@@ -63,6 +63,13 @@ func usbProduct() string {
|
||||
return usb_STRING_PRODUCT
|
||||
}
|
||||
|
||||
func usbSerial() string {
|
||||
if usb.Serial != "" {
|
||||
return usb.Serial
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// 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'
|
||||
@@ -160,8 +167,14 @@ func sendDescriptor(setup usb.Setup) {
|
||||
sendUSBPacket(0, b, setup.WLength)
|
||||
|
||||
case usb.ISERIAL:
|
||||
// TODO: allow returning a product serial number
|
||||
SendZlp()
|
||||
sz := len(usbSerial())
|
||||
if sz == 0 {
|
||||
SendZlp()
|
||||
} else {
|
||||
b := usb_trans_buffer[:(sz<<1)+2]
|
||||
strToUTF16LEDescriptor(usbSerial(), b)
|
||||
sendUSBPacket(0, b, setup.WLength)
|
||||
}
|
||||
}
|
||||
return
|
||||
case descriptor.TypeHIDReport:
|
||||
|
||||
@@ -134,4 +134,8 @@ var (
|
||||
|
||||
// Product is the product name displayed for this USB device.
|
||||
Product string
|
||||
|
||||
// Serial is the serial value displayed for this USB device. Assign a value to
|
||||
// transmit the serial to the host when requested.
|
||||
Serial string
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user