Microsoft Paint, built from logic gates.

My partner Kevin Wiszowaty and I built this paint program for our ECE 385 class project. Starting with basic setup code from the course, we designed the drawing hardware in SystemVerilog and wrote the bare-metal C firmware. Our firmware reads the USB mouse on a MicroBlaze processor. The drawing hardware renders each brush stroke on the Spartan-7 FPGA and sends the picture to a monitor over HDMI.

  • XC7S50 FPGA
  • MicroBlaze + custom AXI4-Lite IP
  • 450 × 450 canvas · 64 colours
  • 640 × 480 HDMI @ 60 Hz
  • USB mouse via MAX3421E

Live demo

The simulation uses a JavaScript model of our hardware and firmware to run the drawing tools in your browser. It models brush.sv, artist.sv, colorMapper.sv and the mouse handler updateLocation().

HDMI out
Left-drag round brush Right-drag square brush Click the toolbar on the right edge of the screen, or the list beside it

AXI registers · what the MicroBlaze writes

TOOL
0x00000000
MOUSEX
0
MOUSEY
0
FRAME_COUNT
0

Brush FSM · last stamp

Position
—
Shape
—
Pixels visited
—
Pixels written
—
Time @ 100 MHz
—
Total stamps
0

UART console · xil_printf


        
Hardware behaviour the demo reproduces
  • X then Y. The firmware writes MOUSEX and MOUSEY as two separate AXI writes, and the brush starts as soon as MOUSEX changes — so every diagonal move stamps once at (new X, old Y) and again at (new X, new Y).
  • Each pixel is touched once per stroke. A 450×450 occupancy RAM blocks repeats, so the highlighter and invert do not stack while you hold the button. Releasing clears it.
  • The highlighter wraps. It adds the tool colour to each 2-bit channel, so 3 + 1 = 0.
  • Clear fills with the current tool. It drags a radius-63 square brush over the screen from a nested software loop — with the pen it floods the canvas with the pen colour, with the eraser it blanks it.
  • A click without moving does nothing unless the mouse moved since the last stroke ended.

Architecture

Click any block with a file icon to open its file below.

System block design: MicroBlaze, AXI interconnect, USB host, UART and the custom paint IP driving HDMI Spartan-7 XC7S50 FPGA On the board Clock + resetclk_wiz_1 · 100 MHz Local memoryLMB BRAM · code + data MicroBlazesoft CPU · runs the firmware AXI INTCinterrupt controller MDMJTAG debug LMB IRQ AXI4-Lite interconnect · microblaze_0_axi_periph · 11 slaves M_AXI_DP axi_gpio ×4keycode / hexunused here spi_usbAXI Quad SPI gpio_usbint + rst lines timer_usbAXI timer uartlitedebug console finalhdmicontroller_0custom paint IPopen internals → MAX3421EUSB host controller chip USB mouseHID boot reports PC terminalxil_printf output HDMI monitor640 × 480 @ 60 Hz SPI INT / RST USB UART HDMI TMDS

From mouse to pixel

  1. The MAX3421E USB host chip hands the MicroBlaze a boot-protocol mouse report over SPI: Δx, Δy and buttons.
  2. updateLocation() integrates the deltas, clamps to the 470 × 450 screen and writes the button bits into TOOL. Clicks on the toolbar strip (x ≥ 450) are decoded in 18-pixel bands into TOOL fields.
  3. It writes MOUSEX and MOUSEY over AXI4-Lite into the paint IP's register file.
  4. brush.sv sees the position change, walks a (2r + 1)² box around it and requests each pixel inside the circle or square that has not been painted yet this stroke.
  5. artist.sv performs the tool's read-modify-write on port A of the frame buffer.
  6. In parallel, the VGA timing generator scans port B at 25 MHz; colorMapper.sv overlays the toolbar and cursor, and hdmi_tx_0 serializes it to TMDS.

TOOL register (offset 0x0)

BitsFieldMeaning
31:30BLUEtool colour, 2 bits
29:28GREENtool colour, 2 bits
27:26REDtool colour, 2 bits
25:20SIZEbrush radius r (toolbar sets 0–7; clear uses 63)
19:16TOOLF pen · E highlighter · D eraser · C invert
15:12BUTTON1 left (circle) · 2 right (square) · 0 up
11:0—unused

Pixels in the frame buffer use the same 6-bit layout as TOOL[31:26]: {B[1:0], G[1:0], R[1:0]}.

Source code

Every file in the build is listed so you can see how the project fits together. Code is shown for the parts we wrote ourselves: the brush, artist and colour-mapper hardware, the toolbar image, and the firmware’s mouse handler. Course-provided, Vivado-generated and third-party files are listed by name only.

Download

About

Built for ECE 385 (Digital Systems Laboratory) at the University of Illinois. The hardware is written in SystemVerilog in Vivado and packaged as a custom AXI4-Lite IP; the firmware runs on a MicroBlaze built in Vitis. Target: Spartan-7 xc7s50csga324-1.