Embedded graphics
Embedded-graphics is a 2D graphics library that is focused on memory constrained embedded devices. It contains built in items that make it easy to draw 2D graphics primitives:
- Primitive shapes with stroke and/or fill
- Lines
- Rectangles
- Circles
- Triangles
- Images
- Built in support for images from raw data
- Other image formats, like BMP and TGA images, are supported using an external crate
- Text
- Built in fonts
- Additional fonts can be added by external crates
A core goal of embedded-graphics is to draw graphics without using any buffers; the crate is
no_std
compatible and works without a dynamic memory allocator, and without pre-allocating large
chunks of memory. To achieve this, it takes an Iterator
based approach, where pixel values and
positions are calculated on the fly, with the minimum of saved state. This allows the consuming
application to use far less RAM at little to no performance penalty.
To support many different kinds of display embedded-graphics doesn't include any drivers directly but provides an API that can be implemented by external crates. The display drivers section contains a list of display drivers with embedded-graphics support. In addition to the drivers for real displays the simulator can be used to test code during development.
Other functions of embedded-graphics are also designed to be extended by the application or other
crates. Examples of this are adding support for different image formats or implementing custom
Drawable
items. The external crates section
contains a list of crates that provide reusable extensions to embedded-graphics.
Documentation
More information and up to date docs can be found on docs.rs.
Getting help/reporting an issue
If you think you've found a bug, or would like to suggest a new feature to add to embedded-graphics, please open an issue.
If you need more deeper/more personalized help, please check out the embedded-graphics Matrix channel.
Additional functions provided by external crates
- BMP images -
tinybmp
- TGA images -
tinytga
- ProFont monospace font -
profont
- Picofont Pico8 font -
picofont
Note that some of these crates may not support the latest version of embedded-graphics.
If you know of a crate that is not in this list, please open an issue.
Display drivers
- embedded-graphics-simulator: Simulated display
- hub75: A rust driver for hub75 rgb matrix displays
- ili9341: A platform agnostic driver to interface with the ILI9341 (and ILI9340C) TFT LCD display
- ls010b7dh01: A platform agnostic driver for the LS010B7DH01 memory LCD display
- sh1106: I2C driver for the SH1106 OLED display
- ssd1306: I2C and SPI (4 wire) driver for the SSD1306 OLED display
- ssd1322: Pure Rust driver for the SSD1322 OLED display chip
- ssd1331: SPI (4 wire) driver for the SSD1331 OLED display
- ssd1351: SSD1351 driver
- ssd1675: Rust driver for the Solomon Systech SSD1675 e-Paper display (EPD) controller
- st7735-lcd: Rust library for displays using the ST7735 driver
- st7920: ST7920 LCD driver in Rust
Note that some drivers may not support the latest version of embedded-graphics.
There may be other drivers out there we don't know about yet. If you know of a driver to add to this list, please open an issue!
Example
The following example uses the simulator to demonstrate some of the built in drawing functions:
use ;
use ;
This example is also included in the simulator crate and
can be run using cargo run --example hello-world
.
Additional examples can be found in the simulator crate.
Using macros
Embedded graphics defines macros to easily build drawables and styles for primitives and texts:
use Font6x8;
use Rgb565;
use *;
use ;
// Only used for examples - this would be replaced by the driver for your chosen display
use MockDisplay as Display;
Cargo Features
nalgebra_support
- use the Nalgebra crate withno_std
support to enable conversions fromnalgebra::Vector2
toCoord
andUnsignedCoord
.
Migrating from 0.5 to 0.6
Please read the migration guide.
Development setup
Minimum supported Rust version
The minimum supported Rust version for embedded-graphics is 1.40.0
or greater.
Ensure you have the latest stable version of Rust installed, preferably through https://rustup.rs.
Ubuntu/Linux Mint
# Update to latest stable version of Rust
# Ensure rustfmt is installed
# Install SDL2 for simulator and PIP to install linkchecker
Attribution
All source font PNGs are taken from the excellent Uzebox Wiki page.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.