Cornell University ECE4760
ProtoThreads
with 640x480 VGA 16-color
Pi Pico RP2040

Protothreads v1.1.1 and VGA on RP2040
Protothreads is a very light-weight, stackless, threading library written entirely as C macros by Adam Dunkels. See the protothreads page for details.
Here we are adding Hunter Adam's VGA driver, specifically this example, but slightly modified for 4-bit rather than 3-bit color. The extra bit is used to make four green levels. Of course, the extra bit means that a 2-bit DAC is required for the green channel. The rgb.pio assembler program had to be slightly modified, and the drawPixel routine had to be recoded. All of the changes are included in the ZIP file below.
The example code consists of four threads, with two threads on each core.
One core 0 thread just blinks the on-board LED, while the other generates the graphics demo shown below.
The names associated with each color can be used whenever a color is required.
The core 1 threads toggle an i/o pin and produce a serial interface and command line.
The serial interface just asks for two numbers, adds them, and prints the sum.

Hunter's VGA implementation uses:
- PIO state machines 0, 1, and 2 on PIO 0
- DMA channels 0, 1, 2, and 3
- 153.6 kBytes of RAM (for 640x480 pixel, 4-bit, color data)

The blue and red VGA lines are driven directly through 330 ohm resistors, as in Hunter's implementation:
- GPIO 16 ---> VGA Hsync
- GPIO 17 ---> VGA Vsync
- GPIO 18 ---> VGA Green lo-bit -- see below
- GPIO 19 ---> VGA Green hi_bit -- see below
- GPIO 20 ---> 330 ohm resistor ---> VGA-Blue
- GPIO 21 ---> 330 ohm resistor ---> VGA-Red
- RP2040 GND ---> VGA-GND
The VGA-green connection is as shown.

Performance is good. The drawPixel routine takes about 0.43 uSec. So you can draw about 2.3 million pixels/sec, or around 38,000 pixels/frame. It takes about 130 mSec to clear the screen.

Project ZIP file.
C demo code
The Cmake file includes double-click bootsel and compiler optimization options


 


Copyright Cornell University April 19, 2022