Coder Social home page Coder Social logo

CDCACM::availabe() blocks about arduinocore-gd32 HOT 2 CLOSED

bjc avatar bjc commented on June 9, 2024
CDCACM::availabe() blocks

from arduinocore-gd32.

Comments (2)

algernon avatar algernon commented on June 9, 2024

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.

from arduinocore-gd32.

bjc avatar bjc commented on June 9, 2024

Fixed here: be5d7bb

from arduinocore-gd32.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.