-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[PluggableHID] 3rd round of API improvement (WIP) #3931
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 iterations in the for loop also use unsigned and the setup struct etc as well. There was no change in HID required since we just init the inherited variables via constructor and the type is never mentioned.
Alternatively we can only pass the wIndex to getDescriptor but I suggest to just pass the pointer aka reference of the whole setup. In guess (havent tested this) that this results in more or less the code size but its a) idential with the other functions and b) we late have more flexibility here. The Code got a quick SerialKeyboard.ino test
This commit just shows other that this option is available and not implemented. You may use this to determine the Led Lights state of a keyboard or transmit data via RAWHID from the PC. Quick usage guide: int length = ((setup.wValueH << 8) | setup.wLength); USB_RecvControl((uint8_t* data, USB_EP_SIZE); // Needs to be splitted into USB_EP_SIZE packets, not shown here. See HID Project.
Everything looks fine thanks! The only thing that I'll add is a more strict check for interface as explained in my comment NicoHood@0f9f63f#commitcomment-13661401 |
Hi @NicoHood , first of all thanks for all these useful patches. Test it if you wish, I used this sample sketch
With |
I will try this out now! Thinking about this I'd say that the pluggable HID in general should use multiple endpoint/interfaces. This gives us some very important features:
Since Arduino by default only supports Keyboard + Mouse with a 32u4 we have enough endpoints to do this. Even 1 more endpoint is free. Boot support is also a very desired feature around the web. The pros above should make it clear enough. This way we are most flexible in any way. We (or better me) could then create another layer of pluggable Multireport which can be used for u2 devices with less endpoints. Let me see what @facchinm s example already gives us ;) |
Thinking about this twice results in: Otherwise we end in using tons of linked lists with a lot of overhead. This way its also easier to implement HID Out reports (leds, rawHID data to MCU). Adding single interface HIDDevices via linked list makes no sense to me, also because they differ too much which gives a lot of overhead. For this purpose we have the awesome pluggable USB API. The APIs however should be kept that you can inherit them and dont need to dupe the code (if you want a keyboard as multiHID or normal). Not sure if thats possible without overhead/limitations. This also means the current API is fine how it is. Maybe it should be renamed and a proper Keyboard/Mouse API should be added (with boot support and all that). Or you leave it like that and I just add those features to my HID Project. |
https://gist.github.com/NicoHood/c5e77a3f9d73b998a49f Leds currently dont work, 2 additional headers needs to be copied from the HID Project. Just to get the idea. I tested this code and it works. Havent tested the Boot function but it should (and if not there is a fix for sure because it works in the current HID project with old PUSB). I am now wondering if your PUSB core is full avr/sam independent. If yes you could just use the same API. If not, its not solved this easy. After applying a few changes I think the best solution is to keep it like that. If someone really want to add a special HID device real quick, he now can. I also do really like the pluggable HID and I will use it (how it is right now). However a real working HID device with more than just simple functions requires a real interface anyways. And for those features I will just provide a special 2nd API/Singleton. So people can use the (pretty good) pluggable HID with a single endpoint or extended singe EP HID Devices. Depending on your opinion I will start working on my HID Project and say those changes are final now. The sam implementation requires some time to patch anyways. However I dont have one to test, so I am out of that. So any opinions? Edit: Oh and we have to make the Serial pluggable. I am really looking forward to see this. ISerial may then be implemented as well @facchinm |
And another thing I want to mention: It should be possible to create just two instances of this class and you have just two keyboards. This is especially useful with gamepads of course. Or with multiple RAW HID channels, but then a different descriptor is needed (another story). This might also be useful to create a dual Serial interface. Lufa has an example for this, not sure if its so easy to do, or If you need to add more tweaks. But two debug channels, how cool is that? (however then no more HID device is supported since it uses all 6 endpoints) And we should also make the endpoint size flexible. This way we can increase/decrease the buffer size of the serial or of the HID devices. Especially for the u2 Series we are currently limited to 16bytes single bank which slows down the serial a bit. However if this change requires too much work or overhead I'd just leave it like that. |
Hi @NicoHood, I've just read all your emails, at some point I felt a bit lost, so let me recap your conclusions:
So, if I've interpreted your emails correclty, before declaring closed the refactoring, I would like to rename the following classes:
the word "List" in this case is really an implementation detail and the new names have a much better meaning IMHO. |
Yes you are right. I think for the simple stuff the API is good how it is right now. And the rest can be achieved via PUSB.
I was thinking of making the Keyboard API etc even more abstract, so one can use that as single device or as multidevice. However I also think that this is not 100% needed for the core IDE and I can better do this myself (with HID Project) anyways. It s now implemented in HID Project 2.4 dev branch. |
Current dev states can be found here: |
Another thing that you really should do is to move the static inline functions of USBCore.cpp inside a header file. I wanted to use the Send8() function from my HID implementation but I cannot do this, because no header has this function. Its okay to make it inline, but please put it inside a header. Also The USB Core (Not the pluggable USB) looks very incomplete to me. We should maybe rework this as well and keep similar names as the LUFA project does. This way the code is easier to read, understand and features can be added easier. |
cc @cmaglie @facchinm @matthijskooijman
Also see (and below)
#3896 (comment)