diff options
author | deadprogram <[email protected]> | 2023-03-21 00:10:44 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-03-22 08:35:42 +0100 |
commit | a4a1001dd39755eb174522be2ca83857ac3c101c (patch) | |
tree | 848cf40772dc0957a73d54aec90731c74af40fd7 | |
parent | e8f6df928c5917641ad8b5b8d11f69b9d24627c2 (diff) | |
download | tinygo-a4a1001dd39755eb174522be2ca83857ac3c101c.tar.gz tinygo-a4a1001dd39755eb174522be2ca83857ac3c101c.zip |
examples: use hid-keyboard example to show how to to override default USB VID, PID, manufacturer name, and product name
Signed-off-by: deadprogram <[email protected]>
-rw-r--r-- | src/examples/hid-keyboard/main.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/examples/hid-keyboard/main.go b/src/examples/hid-keyboard/main.go index 4024c1e56..a5aed9365 100644 --- a/src/examples/hid-keyboard/main.go +++ b/src/examples/hid-keyboard/main.go @@ -1,11 +1,22 @@ +// to override the USB Manufacturer or Product names: +// +// tinygo flash -target circuitplay-express -ldflags="-X main.usbManufacturer='TinyGopher Labs' -X main.usbProduct='GopherKeyboard'" examples/hid-keyboard +// +// you can also override the VID/PID. however, only set this if you know what you are doing, +// since changing it can make it difficult to reflash some devices. package main import ( "machine" + "machine/usb" "machine/usb/hid/keyboard" + "strconv" "time" ) +var usbVID, usbPID string +var usbManufacturer, usbProduct string + func main() { button := machine.BUTTON button.Configure(machine.PinConfig{Mode: machine.PinInputPullup}) @@ -19,3 +30,23 @@ func main() { } } } + +func init() { + if usbVID != "" { + vid, _ := strconv.ParseUint(usbVID, 0, 16) + usb.VendorID = uint16(vid) + } + + if usbPID != "" { + pid, _ := strconv.ParseUint(usbPID, 0, 16) + usb.ProductID = uint16(pid) + } + + if usbManufacturer != "" { + usb.Manufacturer = usbManufacturer + } + + if usbProduct != "" { + usb.Product = usbProduct + } +} |