Files
swaitsandClaude Opus 4.7 784658e5c6 Initial release: mcufont 0.1.0
Faithful Rust port of Maurycy's mcufont.h — a 5x5 monospace pixel
font (~350 bytes of bitmap data) covering A-Z, a-z, 0-9, and the
punctuation set - + . , ? ! : = '.

- no_std, forbid(unsafe_code), zero deps with default features.
- Public glyph tables (UPPER / LOWER / DIGITS / SYMBOLS), SYM_*
  index constants, and a glyph(c: char) lookup.
- Each glyph row is packed in bits 7..=3 MSB-first so the bytes
  are byte-for-byte compatible with embedded_graphics::ImageRaw.
- Optional `embedded-graphics` feature exposes MCU_FONT
  (MonoFont<'static>), FONT_DATA, and McuGlyphMapping for drop-in
  use with MonoTextStyle / Text on any DrawTarget (SSD1306 over
  I²C, ST7735, etc.).
- Per-category feature flags (upper / lower / numbers / symbols,
  all on by default) so users can drop unused glyphs from flash.

Licensed CC BY-NC-SA 4.0, inherited from the upstream font data.
An email is out to the upstream author asking for a permissive
software license (MIT / Apache-2.0); if granted, the crate will
be relicensed and a new version published.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 13:36:29 -06:00

97 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# mcufont
Tiny 5×5 monospace pixel font for microcontrollers. `no_std`, zero dependencies (with default features), ~350 bytes of font data.
Faithful Rust port of [Maurycy's `mcufont`](https://maurycyz.com/projects/mcufont/) C header. Covers `A–Z`, `a–z`, `0–9`, and the punctuation set `- + . , ? ! : = '`.
## Usage — raw
```rust
use mcufont::{glyph, GLYPH_WIDTH, GLYPH_HEIGHT};
if let Some(g) = glyph('A') {
for row in g {
// bit 7 = leftmost pixel, bit 3 = rightmost; bits 2..=0 are zero.
for x in 0..GLYPH_WIDTH {
let on = (row >> (7 - x)) & 1 == 1;
// ... blit to your framebuffer
}
}
}
```
The static tables `UPPER`, `LOWER`, `DIGITS`, `SYMBOLS` are also public — index them directly if you don't need the lookup function.
## Usage — `embedded-graphics`
Enable the `embedded-graphics` feature in `Cargo.toml`:
```toml
mcufont = { version = "0.1", features = ["embedded-graphics"] }
```
Then drop `MCU_FONT` into a `MonoTextStyle`:
```rust
use embedded_graphics::{
mono_font::MonoTextStyle, pixelcolor::BinaryColor,
prelude::*, text::Text,
};
use mcufont::eg::MCU_FONT;
let style = MonoTextStyle::new(&MCU_FONT, BinaryColor::On);
Text::new("Hello", Point::new(0, 5), style).draw(&mut display)?;
```
Works with any `embedded-graphics` `DrawTarget` — SSD1306 over I²C, SH1106, ST7735, fbink, etc.
## Features
| Feature | Default | What it adds |
| ------------------- | ------- | ---------------------------------------------------------------- |
| `upper` | yes | `A–Z` (130 bytes) |
| `lower` | yes | `a–z` (130 bytes) |
| `numbers` | yes | `0–9` (50 bytes) |
| `symbols` | yes | `- + . , ? ! : = '` (45 bytes) |
| `embedded-graphics` | no | `MonoFont` integration + concatenated strip (~2× the flash cost) |
Disable any category you don't need to save flash. With all four enabled the raw tables sum to ~355 bytes.
## Glyph format
Each glyph is `[u8; 5]` — one byte per row. Pixels are packed in **bits 7..=3 MSB-first** (bit 7 = leftmost pixel); bits 2..=0 are always zero. This layout matches `embedded_graphics::image::ImageRaw` byte ordering for a 5-pixel-wide row, so the same bytes drive both the raw API and the `embedded-graphics` integration with no transformation.
```text
byte = 0b A B C D E _ _ _ → row pixels = A B C D E
```
## Embedded targets
Plain `static` arrays land in `.rodata`, which is mapped to flash on the common embedded Rust targets — Cortex-M, RISC-V, ESP32, etc. The crate is `no_std` and uses no allocator. AVR's Harvard architecture (`PROGMEM`) is **not** addressed; AVR Rust support is nightly-only and out of scope for this crate.
## License — read this
This crate is currently licensed **CC BY-NC-SA 4.0** — the only license offered for the upstream font data on the source page. That means:
- **Non-commercial use only.** You cannot ship this crate (or work derived from its font data) in a product you sell.
- **ShareAlike.** Any derivative work that incorporates the font data must also be licensed under CC BY-NC-SA 4.0.
- This is **not** an OSI-approved open-source license. It is incompatible with most permissive and copyleft software licenses.
If those terms don't fit your project, this crate is not for you.
Full license text: [`LICENSE`](./LICENSE) — see also <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
### Pending relicense
We've reached out to the upstream author asking for a permissive software license (MIT or Apache-2.0) on the original C source. If granted, this crate will be relicensed accordingly and a new version published. Until then the inherited CC BY-NC-SA 4.0 license stands.
Watch the [CHANGELOG](./CHANGELOG.md) for the relicense, if and when it lands.
## Attribution
- 5×5 font data and original C implementation: <https://maurycyz.com/projects/mcufont/>
- Original 5×6 `font-inline.h` it was based on: lcamtuf, <https://lcamtuf.coredump.cx/soft/embedded/font-inline.h>
- Lineage further traces to the ZX Spectrum 8×8 system font.
This Rust crate (scaffolding, `embedded-graphics` integration, tests) is itself a derivative work and is therefore also CC BY-NC-SA 4.0.