examples: use hid-keyboard example to show how to to override default USB VID, PID, manufacturer name, and product name
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
e8f6df928c
коммит
a4a1001dd3
1 изменённых файлов: 31 добавлений и 0 удалений
|
@ -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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
"machine"
|
||||||
|
"machine/usb"
|
||||||
"machine/usb/hid/keyboard"
|
"machine/usb/hid/keyboard"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var usbVID, usbPID string
|
||||||
|
var usbManufacturer, usbProduct string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
button := machine.BUTTON
|
button := machine.BUTTON
|
||||||
button.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче