{"id":21833441,"url":"https://github.com/cbiffle/m4vga-rs","last_synced_at":"2025-04-14T07:41:37.612Z","repository":{"id":36318763,"uuid":"168068042","full_name":"cbiffle/m4vga-rs","owner":"cbiffle","description":"VGA-style video output for STM32F4 processors, in Rust","archived":false,"fork":false,"pushed_at":"2023-01-05T02:27:48.000Z","size":2020,"stargazers_count":158,"open_issues_count":21,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-11T06:42:19.293Z","etag":null,"topics":["cortex-m","graphics","microcontroller","no-std","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cbiffle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-29T01:34:51.000Z","updated_at":"2025-03-11T21:32:36.000Z","dependencies_parsed_at":"2023-01-17T01:17:10.811Z","dependency_job_id":null,"html_url":"https://github.com/cbiffle/m4vga-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbiffle%2Fm4vga-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbiffle%2Fm4vga-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbiffle%2Fm4vga-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbiffle%2Fm4vga-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbiffle","download_url":"https://codeload.github.com/cbiffle/m4vga-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248841857,"owners_count":21170255,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cortex-m","graphics","microcontroller","no-std","rust"],"created_at":"2024-11-27T19:31:13.483Z","updated_at":"2025-04-14T07:41:37.585Z","avatar_url":"https://github.com/cbiffle.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# m4vga-rs\n\n[![Build Status](https://travis-ci.org/cbiffle/m4vga-rs.svg?branch=master)](https://travis-ci.org/cbiffle/m4vga-rs)\n\nThis crate provides 800x600 60fps graphics on the STM32F407 microcontroller. The\nobservant reader will note that the STM32F407 has no video hardware, or enough\nRAM to hold an 800x600 color image. So how does `m4vga` get high-res color video\nout of it?\n\n*Magic.*\n\n![Recording of the tunnel demo on a small monitor](doc/tunnel.gif)\n\nThis is a rewrite of my C++ library [`m4vgalib`][11], plus ports of my\n[collection of `m4vgalib` demos][1]. It is still a work in progress. (If you're\ncurious, see [my notes on the port][rust-port].)\n\n(As of quite recently, several of the demos also compile for *another* platform\nwithout video hardware: WebAssembly.)\n\n## Why this is interesting\n\nMostly because it's really hard. I've got four CPU cycles *per pixel* to work\nwith, and any variation in timing will corrupt the display.\n\n## The Demos\n\nThe demo `main` files live in [m4demos/src/bin][3], though the core\nimplementations of several of the demos have migrated into the [fx][12]\ndirectory.\n\n- [`conway`][conway]: full-screen [Conway's Game of Life][4] at 60fps -- that's\n  28.8 million cell updates per second, for a budget of 5 cycles per update\n  (not counting video generation).\n\n- [`hires_text`][hires_text]: 80x37 text mode. Each character has adjustable\n  foreground and background colors. This is boring to watch but technically\n  interesting.\n\n- [`horiz_tp`][horiz_tp]: generates a display calibration pattern of vertical\n  stripes. This also demonstrates how to write a simple `m4vga`-based demo in\n  40 lines of code.\n\n- [`poly3`][poly3]: a tumbling dodecahedron made of solid polygons, with basic\n  lighting.\n\n- [`rook`][rook]: high-resolution 3D wireframe model with thousands of polygons,\n  plus scrolling text. (The model is from my [chess set][chess-set]).\n\n- [`rotozoom`][rotozoom]: old-school texture transform effect providing rotation\n  and scaling. This is chunky (400x300) to save RAM...which is still too much\n  data to double-buffer. This uses a trick to prevent tearing.\n\n- [`tunnel`][tunnel]: demoscene \"tunnel zoomer\" effect drawing shaded textured\n  graphics at 60fps. (This one is also 400x300, but it's hard to notice at\n  speed.)\n\n- [`xor_pattern`][xor_pattern]: fullscreen procedural texture with smooth\n  scrolling.  Demonstrates how to add a custom assembly language raster\n  function.\n\n## Building it\n\nAll of this is tested only on Linux, but it should work on Mac -- though you'll\nhave to translate the commands below to your package manager of choice.\n\n### Web target\n\nI recently made the core of `m4vga` portable, and I'm gradually porting demos to\nrun on WebAssembly. While this is less exciting than running on a real,\nresource-starved microcontroller, it gives you a way to test out the code\nwithout having to move a bunch of wires around.\n\nFirst, [follow the Rust WASM setup guide here][rust-wasm-setup]. In short, you\nwill need Rust, `wasm-pack`, and `npm`. (Debian/Ubuntu users: the ancient `npm`\nin `apt` will not work.)\n\nNow:\n\n```shell\n$ wasm-pack build -- -p m4vga-wasm-demos\n$ (cd www; npm run start)\n```\n\nPoint a browser at [http://localhost:8080/][localhost] and you should be able to\nview the demos!\n\n### Microcontroller target\n\nYou will need an STM32F407-based board to run this on; I use the\nSTM32F4-Discovery because it's *really cheap.* Hook it up to a VGA connector\naccording to [my instructions for C++][7].\n\nI recommend following the setup chapters from the [Rust Embedded][6] book. In\nparticular, you need to have [Rust][2] and you need to make Rust aware of the\ncross compilation target we're using here:\n\n```shell\n$ rustup target add thumbv7em-none-eabihf\n```\n\nYou will also need a GNU ARM toolchain to compile the assembly language\nroutines. On Arch:\n\n```shell\n$ sudo pacman -S arm-none-eabi-{gcc,newlib}\n```\n\nOn Ubuntu, the system ships an *ancient* version of GCC, but since we're only\nassembling this is okay:\n\n```shell\n$ sudo apt-get install gcc-arm-none-eabi\n```\n\nNow you should be able to compile everything by entering:\n\n```shell\n$ cargo build --release\n```\n\nThis will deposit several demo binaries in\n`target/thumbv7em-none-eabihf/release/`.\n\nAnd if you start `openocd` (tested with version 0.10) in this directory, it will\npick up the `openocd.cfg` file automagically, and (from a separate terminal) you\ncan flash one of the demos by typing:\n\n```shell\n$ cargo run --release --bin horiz_tp\n```\n\n[1]: https://github.com/cbiffle/m4vgalib-demos\n[2]: https://rust-lang.org\n[3]: m4demos/src/bin\n[4]: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life\n[6]: https://rust-embedded.github.io/book\n[7]: https://github.com/cbiffle/m4vgalib-demos/blob/master/README.mkdn#connections\n[11]: https://github.com/cbiffle/m4vgalib\n[12]: fx/\n\n[conway]: m4demos/src/bin/conway\n[hires_text]: m4demos/src/bin/hires_text.rs\n[horiz_tp]: m4demos/src/bin/horiz_tp.rs\n[poly3]: m4demos/src/bin/poly3/\n[rook]: m4demos/src/bin/rook/\n[rotozoom]: fx/rotozoom/src/lib.rs\n[tunnel]: fx/tunnel/src/lib.rs\n[xor_pattern]: m4demos/src/bin/xor_pattern\n\n[chess-set]: http://cliffle.com/project/chess-set-i/\n[rust-port]: doc/rust-port.md\n[rust-wasm-setup]: https://rustwasm.github.io/book/game-of-life/setup.html\n[localhost]: http://localhost:8080/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbiffle%2Fm4vga-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcbiffle%2Fm4vga-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbiffle%2Fm4vga-rs/lists"}