Raspberry Pi graphics card / ANSI terminal emulator
PiGFX is a bare metal kernel for the Raspberry Pi that implements a basic ANSI terminal emulator with the additional support of some primitive graphics functions. It can be driven by pushing characters to the raspi UART. Additional functions like changing text color, moving the cursor or clear the screen can be invoked via ANSI escape codes. The result is that you can easily add an HDMI display output to your embedded project without the hassle of directly generate the video signal.
This work is inspired by Spencer's project that aims to create a cheap graphics card and keyboard interface to its homebrew Z80 computer. PiGFX has the advantage of removing the fuss of having a full-featured Linux system running on your raspi. This dramatically decreases the boot time, lets the system be more customizable and, of course, adds a lot of fun :)
UPDATE: Thanks to the uspi bare-metal USB driver PiGFX now support an external USB keyboard as input device. Anything typed will be automatically sent to raspi UART Tx0 (pin 8, GPIO 14).
UPDATE: (2018 Nov. by F. Pierot) Added display modes, fonts, tabulation set... See 2018 Nov. modifications.
By now this is a work in progress with a minimum set of features implemented so expect that more functionalities will be added from time to time.
Here is a preliminary TODO list of what I plan to add in the future:
- ✔ Add support for USB or Ps2 keyboard
- ✔ Add some graphics primitives like lines
- Add some more graphics primitives (circles, rectangles etc.)
- Let the resolution being configurable without recompiling
- Implement double buffering
- Load bitmap fonts directly from the SD card
How to run
Format an SD-card with FAT32 filesystem.
bin/kernel.imgin the root of the SD card along with the files
bootcode.binthat are commonly distributed with the Raspberry Pi Alternatively, you can find those files in the
Add a new text file with a single line called config.txt containing:
- Insert the card and reboot the Pi.
As soon as your raspi is turned on, the message "PIGFX Ready!" should be As soon as your raspi is turned on, some debug messages should be displayed as a 640x480 @ 60hz video stream from the HDMI interface. Any data received from the UART is immediately displayed in a terminal-like fashion (ie. it automatically scrolls once you reach the bottom of the screen, etc.).
Test inside QEMU
$ make run
in the PiGFX root folder.
UART Physical connection
|8||UART Tx0 (GPIO 14). Keyboard output|
|10||UART Rx0 (GPIO 15). Connect this pin to your device transmit pin.|
Note: Please be aware that all Raspberry Pi models accept levels between 0 and 3v3. Be sure to provide an appropriate level shifter to match your output
UART communication expects a baud rate of 115200 baud, 8 bit data, 1 bit stop and no parity.
Terminal ANSI Codes
The following escape sequences can be used to further control the terminal behaviour
|\ESC[H||Move to 0-0|
|\ESC[s||Save the cursor position|
|\ESC[u||Move cursor to previously saved position|
|\ESC[-Row-;-Col-H||Move to -Row-,-Col-|
|\ESC[0K||Clear from cursor to the end of the line|
|\ESC[1K||Clear from the beginning of the current line to the cursor|
|\ESC[2K||Clear the whole line|
|\ESC[2J||Clear the screen and move the cursor to 0-0|
|\ESC[-n-A||Move the cursor up -n- lines|
|\ESC[-n-B||Move the cursor down -n- lines|
|\ESC[-n-C||Move the cursor forward -n- characters|
|\ESC[-n-D||Move the cursor backward -n- characters|
|\ESC[0m||Reset color attributes (white on black)|
|\ESC[38;5;-n-m||Set foreground color to -n- (0-255)|
|\ESC[48;5;-n-m||Set background color to -n- (0-255)|
\ESC is the binary character
-Col- is any sequence of numeric characters like
Additionally, PiGFX implements the following custom codes:
|\ESC[?#-x0-;-y0-;-x1-;-y1-l||Draw a line from -x0-;-y0- to -x1-;-y1-|
|\ESC[?#-x0-;-y0-;-x1-;-y1-r||Fill a rectangle with top-left corner at -x0-;-y0- and bottom-right at -x1-;-y1-|
See Here for a reference of the provided xterm color palette.
To compile you will need to install a GNU ARM cross compiler toolchain and
arm-none-eabi-objcopy are in your PATH.
At this point, just run:
$ make $ make kernel
in the PiGFX root directory.
The MIT License (MIT)
Copyright (c) 2016 Filippo Bergamasco.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.