-
Notifications
You must be signed in to change notification settings - Fork 852
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
machine/usb: descriptor refactor #3636
Conversation
cc @neildavis |
Note also this PR includes #3626 |
273a5ce
to
acad29d
Compare
This PR now has the mostly complete refactoring of the USB descriptors. The only parts that are still incomplete are to finish creating types for HID keyboard and mouse descriptors. EDIT: I added comments to the HID reports, that is probably enough for now. |
f270f00
to
b1cf4b2
Compare
Had to do one last thing on this PR, which was to cleanup |
I have started reviewing the code. I think it is good work. On the other hand, I may have to think a little more when adding new devices such as msd. However, I still think it is a very good improvement. |
const endpointMIDITypeLen = 9 | ||
|
||
var endpointEP6IN = [endpointMIDITypeLen]byte{ | ||
endpointMIDITypeLen, | ||
TypeEndpoint, | ||
0x86, // EndpointAddress | ||
0x02, // Attributes | ||
0x40, // MaxPacketSizeL | ||
0x00, // MaxPacketSizeH | ||
0x00, // Interval | ||
0x00, // refresh | ||
0x00, // sync address | ||
} | ||
|
||
var EndpointEP6IN = EndpointType{ | ||
data: endpointEP6IN[:], | ||
} | ||
|
||
var endpointEP7OUT = [endpointMIDITypeLen]byte{ | ||
endpointMIDITypeLen, | ||
TypeEndpoint, | ||
0x07, // EndpointAddress | ||
0x02, // Attributes | ||
0x40, // MaxPacketSizeL | ||
0x00, // MaxPacketSizeH | ||
0x00, // Interval | ||
0x00, // refresh | ||
0x00, // sync address | ||
} | ||
|
||
var EndpointEP7OUT = EndpointType{ | ||
data: endpointEP7OUT[:], | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be implemented in endpoint.go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about that, however since these endpoints have values specific to the MIDI protocol (note the length difference).
Perhaps they should have MIDI
in the endpoint name to make that more explicit?
midi and joystick may not be working. |
I will check that out later today, thanks for letting me know. |
@sago35 I tested this branch, and was not able to get keyboard or MIDI to work using circuitplayground express board. Then I tested the same thing on the Finally I tested the last release, and it also did not work Are you having this same problem with your devices? Which processor are you using? |
OK, checked out code using Clue (nrf52840) In this branch using Clue the Keyboard works, however MIDI does not. Have not tried Joystick yet. |
@sago35 did some more testing last night, appears the The release branch still working as expected when I plugged both devices into my Macbook. However |
Did a |
DId a session with
I get the same error in both the |
@deadprogram @aykevl Of course it is better to fix the heap allocation, but it takes time for the user to realize why it is not working. |
@deadprogram I think Ayke suggested setting this bp to try to catch it in the original PR: #1460
@sago35 I think we can make interrupt allocation checks either opt-in or opt-out fairly easily using build tags. The longer we leave it
|
My main concern is that the code that was working with tinygo0.27 will no longer work. |
I had forgotten to add the Here is debug info from commit f41b6a3
|
Played around a bit more. By commenting out this line https://github.com/tinygo-org/tinygo/blob/dev/src/examples/usb-midi/main.go#L23 the example works on So I think this branch with the refactor has an error, but there is separately something in |
b1cf4b2
to
63fa0ac
Compare
Had to make a few more changes in descriptors, but now I will submit a separate PR to remove Now ready for "final" review. |
Added #3660 to correct example as mentioned. |
2ad9752
to
8355ebc
Compare
I believe the code is fine. |
@sago35 can you please share the repo with the code in which you are using |
@deadprogram |
Just wondering why you need this code exactly? https://github.com/sago35/pico-ffb-steering-wheel/blob/7a1098872fdc3fb6f3747a69daca0c02974097f9/pid/pid_handler.go#L173-L195 I don't know a lot about HID joysticks, perhaps you can briefly explain what that code is doing? |
|
It appears that -1 is returned here and runtime.slicePanic is called. I will look into it more tomorrow. tinygo/src/machine/usb/descriptor/hid.go Line 80 in 8355ebc
|
I think that happened because the Joystick had already been enabled by the default. I just added some code to handle that case, please give it a try. |
src/machine/usb/descriptor/hid.go
Outdated
|
||
// search only for ClassHIDType without the ClassLength, | ||
// in case it has already been set. | ||
idx := bytes.Index(data[:ClassHIDTypeLen-2], section) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClassHIDTypeLen is 9, so this will not work.
idx := bytes.Index(data[:ClassHIDTypeLen-2], section) | |
idx := bytes.Index(data, section) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I had it reversed. Renamed the parameter names and corrected, seems to be working now.
}) | ||
binary.LittleEndian.PutUint16(usb.DescriptorCDCJoystick.Configuration[idx+7:idx+9], uint16(len(hidDesc))) | ||
usb.DescriptorCDCJoystick.HID[2] = hidDesc | ||
class, err := descriptor.FindClassHIDType(descriptor.CDCJoystick.Configuration, descriptor.ClassHIDJoystick.Bytes()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnableJoystick has been called twice, and the second call seems to fail to find it because ClassLength has already been set.
Why it is being called twice requires a little more checking.
@deadprogram |
79ca15a
to
faee2e4
Compare
Done. |
faee2e4
to
991d6b2
Compare
@sago35 I think this PR is now ready, please take another look. |
991d6b2
to
7b94867
Compare
@sago35 rebased just now again against the latest |
Signed-off-by: deadprogram <ron@hybridgroup.com>
…t HID descriptor Signed-off-by: deadprogram <ron@hybridgroup.com>
7b94867
to
1a8e731
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The following example and the FFB JoyStick also worked.
$ tinygo flash --target feather-rp2040 --size short --monitor ./src/examples/echo
$ tinygo flash --target feather-rp2040 --size short --monitor ./src/examples/hid-keyboard
$ tinygo flash --target feather-rp2040 --size short --monitor ./src/examples/hid-mouse
$ tinygo flash --target feather-rp2040 --size short --monitor ./src/examples/usb-midi
$ tinygo flash --target feather-rp2040 --size short --monitor ./src/examples/hid-joystick
FFB JoyStick
https://github.com/sago35/pico-ffb-steering-wheel/tree/work
Hey! The hid-joystick example worked for you on a rp2040 board? I can get it to compile but it does not work. Windows 10 won't even enumerate it after flashing. It consistently gets either a error code 43 or 10 in the device manager. You actually got it to build, flash, enumerate, and then generate input in joy.cpl or something similar? This is on 0.28.1 btw |
This PR is to refactor the USB descriptors to make them modular. This is in part to address what is being discussed in #3474
There is still further work needed to complete this feature, this PR in intended to continue the conversation in the form of code.