Emacs: Zeptoforth Interface (publ. 2024-04-04)

I have been wanting to do more microcontroller programming using Zeptoforth, a full-featured, actively-developed Forth which runs on my Rpi Pico:

zeptoforth

However, one obstacle has been that Zeptoforth uses a non-standard flow control system based on ACK and NAK bytes. It is a good system, but it is not supported by any of the usual serial communication programs like picocom and minicom. In brief, Zeptoforth receives and processes one line, and then it send an ACK indicating it is ready for more input. If an error occurs while processing the line, like a compile error or a stack underflow, Zeptoforth will send a NAK as well, before sending the ACK. If you try to send multiple lines without respecting the flow control system, it is possible that some of your input will be malformed, or that your code will be broken because some line didn't compile.

The Zeptoforth project includes an IDE called Zeptocomjs which handles this flow control, as well as providing some other nice features like processing INCLUDE directives. However, this JavaScript IDE must be run in a Web browser, which in and of itself is not appealing to me, and also the IDE has no Emacs integration while it is running. To have enjoyable and productive Zeptoforth programming, I felt I needed an Emacs interface.

Consequently, I spent the last few lunch breaks coding a simple system to interact with a Zeptoforth serial connection from Emacs, using proper flow control. I wondered if perhaps the built-in terminal emulator program could be hacked to include this flow control, but I had no idea how to approach that, and I thought a different approach might in the end be more flexible anyway. So, instead I learned how to use the Serial process interface described in the Elisp manual, and then I came up with a filter function to process the Zeptoforth output — setting flags when the ACK or NAK bytes are detected. And I coded some interactive functions to send input — either one line or a region of lines, and some code for keeping track of the buffer and process. There is still more work to be done, but I have enough now to send regions of code and to display raw output. Here is the fledgling repository:

emacs-zeptoforth

This work © 2024 by Christopher Howard is licensed under Attribution-ShareAlike 4.0 International.

CC BY-SA 4.0 Deed

Proxied content from gemini://gem.librehacker.com/gemlog/starlog/20240404-0.gmi

Gemini request details:

Original URL
gemini://gem.librehacker.com/gemlog/starlog/20240404-0.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.