-
Notifications
You must be signed in to change notification settings - Fork 1k
USBHID (keyboard / mouse) support #2889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The commit message is probably correct as follows |
|
Now ready for review. A summary of the changes in each file is as follows
|
|
@sago35 this PR is really quite useful to me, because it helps me to actually study the HID API a little bit. I will provide feedback later on about how I think we should modify it, but consider how the API would need to handle the following 3 use cases:
I think the current implementation makes some assumptions about keyboard/mouse that might not be sufficient. What do you think? |
|
@deadprogram Thanks for the comment. src/machine/usb.goI have simplified USB Enumeration in this PR. To support MIDI and MSD, it should be necessary to add callbacks to BulkIn and BulkOut. src/machine/usb/hid/There may be something missing in the keyboard or mouse functionality, but I don't understand what it is. Gamepad and Joystick support should be implemented here. Based on my optimistic view, I believe that all implementations can be done with only the following Interface. tinygo/src/machine/usb/hid/hid.go Lines 34 to 46 in a1e6277
src/machine/usb/midiI have not been able to confirm much yet, but after the enumeration is done, BulkIn and BulkOut need to be implemented. src/machine/usb/msdI am not sure what I need for msd. |
|
@sago35 I was imagining something more like this: https://gist.github.com/deadprogram/4e55c3d0e663295839dd66f6517d8aa4 |
|
I would like to complete USB enumeration as soon as possible, so I think it is better not to have the hid.Enable(kb) part.
package main
import (
"machine"
"machine/usb/hid"
"time"
)
func main() {
button := machine.BUTTON
button.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
kb := hid.NewKeyboard()
mouse := hid.NewMouse()
for {
if !button.Get() {
kb.Write([]byte("tinygo"))
mouse.Move(0, 0)
time.Sleep(200 * time.Millisecond)
}
}
} |
|
I also thought we should put the different devices into their own package folders, e.g. |
|
Lastly, would be good to use an array of handlers. For example (not syntax checked or anything): type hidDevicer interface {
callback()
}
var devices [5]hidDevicer
var size int
func SetCallbackHandler(d hidDevicer) {
callbacks[size] = d
size++
}
func PerformCallbacks() {
for(i := 0; i < size; i++ {
if done := devices[i].callback(); done {
return
}
}
}Then |
|
@deadprogram |
|
Tested on my Circuit Playground Express, and I had to change the example to this for it to work: package main
import (
"machine"
"machine/usb/hid/keyboard"
"time"
)
func main() {
button := machine.BUTTON
button.Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
kb := keyboard.New()
for {
if button.Get() {
kb.Write([]byte("tinygo"))
time.Sleep(200 * time.Millisecond)
}
}
}Otherwise it was amazing! |
|
I think if we correct these small items, and squash commits, we can merge this @sago35 |
|
I made a squash commit. |
|
Thank you for all the work on this PR @sago35 very exciting! Now merging. |
This PR adds USBHID (keyboard / mouse) support.
The following microcontrollers are targeted
(WIP: nrf52840's USBCDC / USBHID is broken)(It works fine now)Unlike #1829, it extends the existing USB implementation.
Also, the keyboard implementation is made by copying the @ardnew implementation.
The USBHID Support being added in this PR is to buy time until #1829 is completed.
The remaining tasks are as follows