Asynchronous Serial and Terminal Emulator Support

A project log for VGA Graphics Over SPI and Serial - VGATonic

640x480 (and 848x480!) Color VGA Video Card for Microcontrollers and Single Board Computers

PKPK 07/23/2015 at 02:130 Comments

Today, the ATTiny 2313a comes alive!

Serial support (or, as I discussed today in the Hacker Channel, other names you might know it as - "Asynchronous Serial", "RS-232 TTL", "TTL Serial", etc.) was always on the roadmap for VGATonic, but my Terminal Emulator Support comment was a joke.

Of course, once I put it out there in the universe, I had to try to make it reality - despite only having 128 bytes of RAM to work with on the 2313a!

The Serial Framebuffer

The serial framebuffer works mostly as I telegraphed a few articles back, but as I was running low on a different resource (flash memory), I modified it a bit so all framebuffer transmits are 255 bytes long. If you are doing one of these pixel transmissions and you are transmitting less than 255 bytes over UART, you'll have to transmit in a 255 byte block (or if it is at the end of the transmission, you can transmit random characters or all 0s or something).

This means you can use VGATonic over asynchronous serial almost exactly as you'd use it over SPI - that is, drawing pixel by pixel.

The Terminal Emulator

The main feature, though, is the terminal emulator. I decided to attempt to reproduce the vt52 character codes as best as I could, and got most of them. I got the 3x5 (4x6 with white space) font I discussed the other day to fit in EEPROM and Flash on the 2313, and I use it in 160x120 mode for an effective 40x15 character terminal. For background and foreground color changes, we go beyond spec (16 colors) of the vt52, and allow you to set any of 256 colors supported by RRRGGGBB in one byte, our selected 8 bit color mode.

I used the vt52 escape code listing I found here. The ones that involve memory of multiple lines or writing more than 40 characters I compromised, either going to a newline (line wrap) or zooming to the beginning of the line when I change line numbers. I will make another article listing the escape codes VGATonic supports.

How Did You Do It?

Since this is Hackaday, I figured I better explain how I got 600 bytes of screen... plus foreground colors, background colors, and line changes... into 128 bytes of memory.

The short answer? I used the hardware acceleration capabilities I built into VGATonic to avoid overwriting lines that had already been written. If I'm on line 7, for example, I don't need to send commands to update lines 1 through 6 - I just tell VGATonic to skip to line 7 (Internally, since it is in 160x120 mode it's more like "skip to line 56"). I then only maintain a buffer of the current line.

It's a nifty trick, and I will put it in my next video demo so you can see it in action without procuring a VGATonic (just yet!). It's a feature I couldn't have done terminal emulation without, but it's also a great demonstration of my hardware acceleration scheme working - that specification will be fully published with the final product so you can do something similar without delving into the source code, if you so choose!