rustne-kretser / noline

IO-agnostic line editor for embedded systems
Mozilla Public License 2.0
96 stars 9 forks source link

noline under IRQ, not polling #15

Closed m5p3nc3r closed 1 year ago

m5p3nc3r commented 1 year ago

Hi Guys

I have the polling USB Serial version of noline working fine, but I need to have it working under IRQ as I am building a multi-function device with USB-HID and Serial (acting as a debug/status port).

Do you have an example of using noline with no_std under IRQ? Or are there known issues with this mode of usage?

m5p3nc3r commented 1 year ago

FYI: I have a working solution for this now. If you would like, I would be happy to create an example to upload to this repository?

eivindbergem commented 1 year ago

I had some issues with using usbd_serial and noline for an interrupt-driven design, but I can't remember the details.

Please, create a pull request if you have a working example.

m5p3nc3r commented 1 year ago

Sorry I have not posted a PR for this yet - I did hit a problem with synchronous editor being blocking as the interrupt handler never returns as noline is blocking on a complete line being available to return.

Is there any chance that the signature of the synchronous editor readline be changed to return something like

enum { Some(&str), // Line complete and ready to be consumed None(), // Line not yet complete Error(...), // Error detected }

This way we can simply put the readline in a polling loop (or interrupt handler) if needed along with other main loop activities

I understand this would be a breaking change on the API, but I do think it would be highly valuable.

eivindbergem commented 1 year ago

Do you have some example code? I'm not sure I fully understand the problem.

m5p3nc3r commented 1 year ago

Sorry - I don't have an example yet, but what I would like to do is this (in pseudo code! Don't expect this to comple)

In a single threaded application, do something like this:

loop {
  // Do something...

  // Do something else...

  if let Some(line) = noline_reader.readline(...) {
    // Do something with the input
  }

  // Do even more things
}

So basically I would like the noline sync reader to return if there is no line available to enable the main application loop to continue processing.

One other question (should probably be in a different ticket, happy to raise a new one for conversation) - I would also like to explore using noline with the embassay (https://embassy.dev/) async task executor, do you have any experience of this? My assumption is that it would need an alternative to the tokyo async IO implementation.

eivindbergem commented 1 year ago

What would make the most sense here is to add a new function – readline_non_blocking() (we can bikeshed the name later) – that can return a partial line. I guess it could also be readline_timeout() for a more generic version, and you could just give it a timeout of zero for a non-blocking version.

m5p3nc3r commented 1 year ago

Hey @eivindbergem - This issue is solved for me by #17 as I can use embassy async IO rather than having to use IRQ's explicitly. I think this is a nicer solution, so will close this issue.