Skip to content

Repository files navigation

ulisp-lispbox --- Firmware for LispBox and LispDeck 4.9a

Modified version of ulisp-arm (see below) for use with a self-contained uLisp computer based on the Teensy 4.1, a TFT screen with RA8875 controller and touchscreen support (if applicable) and an USB keyboard. The REPL works locally and via serial connection simultaneously and prints to the TFT as well.

ADDENDUM: Added "Lispy Little Helper", please see below screenshot

Contains several modifications to the ulisp-arm version 4.9a (many based on the uLisp firmware for the LilyGO T-Deck) as well as a set of suitable uLisp extensions including RFM69 support and a Lisp library providing an extended ULOS system, the most important parts of a uLisp port of ErsatzMoco (github.com/ersatzmoco/ersatzmoco) and a full-screen uLisp and text editor.

Note: The autocomplete feature of uLisp 4.9a in the REPL is now supported. Press TAB to cycle through uLisp keywords matching the first few characters you typed, including keywords from the extension file. To echo the previous line typed after the prompt, press F6 or F12.

The full-screen editor features complete SD card support, direct binding to uLisp symbols, full bracket matching and some keyboard shortcuts partially compatible with EMACS:

  • CTRL-q / CTRL-c --- quit editor and return to REPL

  • CTRL-x / CTRL-b / CTRL-n --- discard current text buffer (i.e. new file)

  • CTRL-k / CTRL-l / ALT-x --- delete line starting at cursor position (deleted part is copied before). If a selection exists, the selected line range will be copied and then be deleted.

  • ALT-c --- copy current line or selected line range

  • ALT-v --- insert copy buffer at cursor position

Note: ALT-v also serves as a rudimentary undo. If you accidentally delete part of a line or a selected line range using CTRL-k, CTRL-l or ALT-x you can insert that part again using ALT-v.

  • CTRL-a / HOME --- move cursor to start of line

  • CTRL-e / END --- move cursor to end of line

  • ^ --- move cursor to beginning of buffer

  • PG UP/PG DOWN --- move one page up or down

  • CTRL-r --- execute code of current line in editor immediately. If a selection exists, the selected line range will be enclosed in "(progn [...])" behind the scenes and then be executed immediately. See also "F5".

  • CTRL-s --- search downwards for provided string in buffer starting at cursor position. When found, the cursor jumps to the related text position.

  • CTRL-i --- set start line of selection for copy/paste/delete/execute

  • CTRL-o --- set end line of selection for copy/paste/delete/execute

  • CTRL-p --- unselect selected line range

  • F1 --- toggle bracket matching on/off

  • F2 --- check whether bracket under the cursor has a matching bracket in the buffer. If so, both are temporarily highlighted. (Use when continuous bracket matching is off.)

  • F3 --- invoke "Lispy Little Helper" if applicable, see below

  • F4 --- load the code of a symbol of your choice read-only into the editor. You may scroll through it and copy lines, but editing is blocked. To return to your text buffer press F4 again (or F6, F7 or F12).

  • F5 --- either bind contents of the text buffer to a symbol of your choice and quit editor or run code (content of text buffer) immediately. To achieve the latter just press ENTER when the input line requests "Symbol name:" (i.e. don't provide a name).

  • F6 --- NEW Send current line or selection to a serial port. If a selection exists, the selected line range will be enclosed in "(progn [...])" behind the scenes before sending. The default serial port is 1 (this is not Arduino Serial, but Arduino Serial1), the default baud rate is 9600. To change the port number and the baud rate set the global variables "se:port" and "se:baud" from within the editor to the new values, using the same parameters as in ´(with-serial)´. This function is intended for communication with another uLisp microcontroller using a serial connection. When your message is sent, the editor immediately listens to incoming data from the serial port and writes it to the read-only buffer. To terminate receiving, press a key. To exit the read-only buffer, press F6 again (or F4, F7 or F12).

  • F7 --- load text from SD card read-only into the editor. You may scroll through it and copy lines, but editing is blocked. To return to your text buffer press F7 again (or F4, F6 or F12).

  • F8 --- save current buffer to backup file "lisp/BACKUP.CL" (overwriting old backup file). This is intended as a quick save function to prevent the worst case scenario of running out of battery before having saved your current work. It is recommended to use F8 at regular intervals. Note: The subdirectory "lisp" needs to exist beforehand, create it on the SD card before inserting it into LispDeck or LispBox.

  • F9 --- delete a file on the SD card

  • F10 --- save text buffer to SD card

  • F11 --- load text from SD card into buffer, discarding the present one

  • F12 --- show directory of SD card in read-only buffer. To return to your text buffer press F12 again (or F4, F6 or F7).

Note: File names (excluding a suffix of 3 letters max.) may have a length of up to 17 characters including one or more directory names separated by a forward slash /. This is sufficient to access files with a filename length of 8 characters (suffix excluded) and a preceding directory name of 8 characters - or any combination of shorter file and directory names.

  • ALT-0 to ALT-9 --- insert one of up to ten predefined snippets at cursor position The snippets are defined in function se:init and reside in the global variable se:sniplist during runtime of the editor. You may change them according to your needs in file "LispboxLibrary.h" (re-flash your MCU with this firmware after change).

The editor is written in uLisp. To invoke it type

(se:sedit) or (se:sedit 'symbol) where "symbol" can be any symbol name already present in uLisp

Editor screenshot

ADDENDUM

The Lisp Library of the Lisp Box now contains "Lispy Little Helper". This is a gadget using a KY-040 rotary encoder and a small second TFT display with ST7735 driver chip (see photo below, encoder on the right placed behind and below the Teensy). The default settings use a resolution of 160x128 pixels.

The Lispy Little Helper collects built-in help information of uLisp symbols as a kind of virtual Rolodex lexicon, accessible from the REPL and the fullscreen editor as well.

If you do not intend to use this addendum, please set variable "se:help-active" to nil. This is done either by modifying the first active line of the Lisp Library (file LispboxLibrary.h) before uploading the firmware to your Teensy or by executing (setf se:help-active nil) in the REPL after startup.

When se:help-active is set to t, the rotary encoder also controls vertical movement of the cursor in the fullscreen editor, as an alternative to the up/down cursor keys.

The backlight of the secondary display is set to 0 by default to reduce the power draw and save some energy. If you want to use the TFT for own experiments, use (set-backlight level) to make it visible. level may be any integer number between 0 and 255.

If you want to add the Lispy Little Helper to your Lisp Box, connect the rotary encoder and the display to the following pins (you may change them within the function se:help):

Encoder: "+" to 3.3V, "GND" to GND, "CLK" to pin 16, "DT" to pin 14, "SW" to pin 20.

Display (using the default SPI port): "SCK" to SCK (pin 13), "SDA" to MOSI (pin 11), "CS" to pin 9, "A0" to pin 6, "RST" to pin 8 and LED to pin 5.

Usage of Lispy Little Helper:

The help screen works both within the fullscreen editor and with the REPL. In the editor, you can access the lexicon by pressing "F3". The TFT display is activated with the message: Press key or encoder! If you press an alphanumeric key on the USB keyboard, a scrollable list of all uLisp symbols that begin with the chosen character will appear. If there are none, No entry will be displayed. If instead of pressing a key, you directly turn or press the encoder, the list of all symbols currently included in uLisp will appear, i.e., functions and global variables.

Now turn the encoder until the entry you want to view is highlighted. Press the encoder, and the display will show the help text for it, if available. For example, if it is a global variable, which naturally does not have help text, the display will show No doc. Most help texts also provide a function prototype, which is an empty dummy of the correct function call. If you press the encoder again from the help text, this function prototype will be directly written into the fullscreen editor, and the lexicon will return to the list.

If you type a starting letter in the help text (or in the list) instead, the corresponding list will be shown. Pressing "F3" again will exit the helper.

To use it in the REPL, enter (se:help) [Enter] - the rest works as described. With one exception: when you press the encoder in the help text, the function prototype will not be output. To exit the helper, press "F3".

Lispy Little Helper LispDeck

Lisp Box firmware is based on ulisp-arm by David Johnson-Davies:

ulisp-arm

A version of the Lisp programming language for boards based on the ARM processor:

  • Arduino Zero and MKRZero.
  • Arduino Uno R4 Minima and WiFi.
  • Adafruit ItsyBitsy M0, Feather M0, and Gemma M0.
  • Adafruit Metro M4, ItsyBitsy M4, Feather M4, and Grand Central M4.
  • Adafruit PyBadge and PyGamer.
  • Adafruit CLUE and ItsyBitsy nRF52840.
  • Raspberry Pi Pico and Raspberry Pi Pico W.
  • BBC Micro Bit.
  • Maxim MAX32620FTHR.
  • Teensy 4.0/4.1.

For more information see: http://www.ulisp.com/

About

Self-contained uLisp computer using Teensy 4.1 and TFT with RA8875 controller

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages