Sunday 7 November 2021

Terminal software for the Raspberry Pi Pico

 I am very proud to have been involved in this hardware / software project with Spencer, creator of the RC2014.

The Pi Pico is a powerful microcontroller, it runs at 133 Mhz by default but can be overclocked to 400Mhz. It has two cores and eight state machines. The state machines have their own assembly language and can independently manage i/o or dma tasks.

It is capable of buffering and generating a video signal, VGA or DVI. Using the TinyUSB library it's capable of receiving USB input.

With these features, it's the perfect candidate for this task. With a few supporting components and the software/firmware installed, it's acting as a serial terminal with USB keyboard input and VGA output. 

The RC2014 is a retro-style computer running a Z80 at up to 7.372Mhz. It does require you to use some kind of terminal for input and output. Usually this is a terminal program running on a modern computer and that's where this new module comes in. It allows the computer to be used standalone, as seen here with CP/M running on the RC2014. It communicates with the computer using UART serial via two of the Pico's GPIO pins and the Rx and Tx lines on the RC2014 bus. It receives keyboard input via the micro USB socket on the Pico (with an OTG adaptor. NB TinyUSB on the pico seems to work with some keyboards and not others.)
The project required custom software to be written for the Pico in C. 

The video output is taken care of by libraries, although the example code certainly did take a while to understand. That part of Textmode PicoTerm largely draws on the text mode example code. 

The USB handling uses TinyUSB. The Pico must act as a host (with the keyboard connected via an OTG adaptor). 

That leaves the terminal functionality. You need to maintain a buffer to store the characters (because the video functionality makes callbacks, requesting the data for each scanline as it's generated). Scrolling is an important  feature of a terminal, so I created a structure to store the character codes for each row of characters, and an array of pointers to those rows. So scrolling is a matter of shuffling 30 pointers rather than 2400 characters. 

One of the Pico's cores can handle the scanline generation for the video while the other listens for characters sent from the computer and from the keyboard, buffers and handles those. [update - with the textmode Picoterm, polling was fine and works without dropped characters. With the newer colourmode PicoTerm, because of the increased load of putting characters on the screen, it was necessary to implement interrupts on Rx to receive and buffer each incoming character].

As well as just feeding characters to the screen and scrolling when necessary, it's also important to parse and handle certain escape sequences.  These codes can position the cursor on the screen or change the attributes (eg reverse characters). The full list of sequences that we've implemented so far are here on the module's documentation page.

No comments:

Post a Comment