File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 1
1
// to override the USB Manufacturer or Product names:
2
2
//
3
- // tinygo flash -target circuitplay-express -ldflags="-X main.usbManufacturer='TinyGopher Labs' -X main.usbProduct='GopherKeyboard'" examples/hid-keyboard
3
+ // tinygo flash -target circuitplay-express -ldflags="-X main.usbManufacturer='TinyGopher Labs' -X main.usbProduct='GopherKeyboard' -X main.usbSerial='XXXXX' " examples/hid-keyboard
4
4
//
5
5
// you can also override the VID/PID. however, only set this if you know what you are doing,
6
6
// since changing it can make it difficult to reflash some devices.
@@ -15,7 +15,7 @@ import (
15
15
)
16
16
17
17
var usbVID , usbPID string
18
- var usbManufacturer , usbProduct string
18
+ var usbManufacturer , usbProduct , usbSerial string
19
19
20
20
func main () {
21
21
button := machine .BUTTON
@@ -49,4 +49,8 @@ func init() {
49
49
if usbProduct != "" {
50
50
usb .Product = usbProduct
51
51
}
52
+
53
+ if usbSerial != "" {
54
+ usb .Serial = usbSerial
55
+ }
52
56
}
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ func usbProduct() string {
63
63
return usb_STRING_PRODUCT
64
64
}
65
65
66
+ func usbSerial () string {
67
+ if usb .Serial != "" {
68
+ return usb .Serial
69
+ }
70
+ return ""
71
+ }
72
+
66
73
// strToUTF16LEDescriptor converts a utf8 string into a string descriptor
67
74
// note: the following code only converts ascii characters to UTF16LE. In order
68
75
// to do a "proper" conversion, we would need to pull in the 'unicode/utf16'
@@ -160,8 +167,14 @@ func sendDescriptor(setup usb.Setup) {
160
167
sendUSBPacket (0 , b , setup .WLength )
161
168
162
169
case usb .ISERIAL :
163
- // TODO: allow returning a product serial number
164
- SendZlp ()
170
+ sz := len (usbSerial ())
171
+ if sz == 0 {
172
+ SendZlp ()
173
+ } else {
174
+ b := usb_trans_buffer [:(sz << 1 )+ 2 ]
175
+ strToUTF16LEDescriptor (usbSerial (), b )
176
+ sendUSBPacket (0 , b , setup .WLength )
177
+ }
165
178
}
166
179
return
167
180
case descriptor .TypeHIDReport :
Original file line number Diff line number Diff line change @@ -134,4 +134,8 @@ var (
134
134
135
135
// Product is the product name displayed for this USB device.
136
136
Product string
137
+
138
+ // Serial is the serial value displayed for this USB device. Assign a value to
139
+ // transmit the serial to the host when requested.
140
+ Serial string
137
141
)
You can’t perform that action at this time.
0 commit comments