Skip to content
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

CDCACM::availabe() blocks #5

Closed
bjc opened this issue Dec 16, 2021 · 2 comments
Closed

CDCACM::availabe() blocks #5

bjc opened this issue Dec 16, 2021 · 2 comments

Comments

@bjc
Copy link
Owner

bjc commented Dec 16, 2021

Upstream issue: CommunityGD32Cores#56

@algernon
Copy link

algernon commented Dec 20, 2021

Hey!

A bit of an update on the issue, and why .available() is pretty much essential for Kaleidoscope: the protocol between the keyboard and the host implemented by Kaleidoscope is a bi-directional protocol, and the most often used method is a request-response one, initiated by the host.

To be able to handle that, we need to be able to tell whether there's data available via Serial. We can't just use a blocking read, because then the rest of the keyboard functionality would be lost until the host sends data. The issue is further complicated by the protocol being rather loose, and there are often scenarios where the firmware doesn't know how much data to read or expect, because data can end abruptly, and still be valid.

For example, to reprogram the keys on a keyboard, the command to send over serial is keymap.map <code> <code>..., where <code> is the keycode for a particular key. Any number of codes can be sent, and then the first N keys will be remapped. It's also common to just send the raw command, keymap.map, without arguments, to query the keymap. Both of these things require Kaleidoscope to know whether there's data available.

The implementation heavily relies on this. We could, in theory, come up with a protocol that doesn't, but that'd be a huge breaking change, and quite an undertaking.

We could also - temporarily - make the keyboard modal: either in keyboard mode, or in "chrysalis-mode", and in the second case, blocking wouldn't be an issue. But this would be a non-negligible amount of temporary code in Kaleidoscope.

Another idea I just had, perhaps a silly one, and I'm not even sure it is possible with Arduino: what if we did a blocking read every couple of seconds, but garded by an alarm of some kind, so it gets interrupted within a few milliseconds? If there's data, we'd get that into buffers, and .available() would return true. If not, then it'd simply return false. This would cause very tiny stalls from time to time, but wouldn't require changing the protocol, or introducing temporary code.

@bjc
Copy link
Owner Author

bjc commented Jan 20, 2022

Fixed here: be5d7bb

@bjc bjc closed this as completed Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants