#embedded-graphics #led-matrix #arm #cortex-m #graphics

no-std smart-leds-matrix

DrawTarget implementation for smart led based matrixes. It allows the usage of the embedded-graphics Drawables.

3 releases (breaking)

0.2.0 Jan 17, 2024
0.1.0 Oct 17, 2022
0.0.1 Feb 6, 2022

#360 in Embedded development

Download history 7/week @ 2024-01-14 9/week @ 2024-02-18 26/week @ 2024-02-25 1/week @ 2024-03-03 106/week @ 2024-03-10 3/week @ 2024-03-17 29/week @ 2024-03-31

138 downloads per month

Apache-2.0

16KB
286 lines

Smart LEDs matrix

A DrawTarget implementation to use (one, or more) smart LED matrixes as a graphics display driven by embedded-graphics Drawable objects. The integrated driver is from smart-leds crate.

Known issues (with my setup: stm32f401 + 8x8 ws2812 matrix):

  • circles with the same parameters are not exactly drawn always to the same position, not sure if this is the same with bigger resolution displays or not
  • write operation usually gets back with an overrun error, while the display is still updated for ~every second time (workaround: flush always twice)

Plan

  • Add more display types (like 2x2 or 1x4 grids of 8x8 matrixes), though user can add those anytime by implementing another layout.

Usage

You may start by creating a driver for your LED and controller. Some examples can be found here.

Once you have it, you can plug it into the DrawTarget implemented by this crate.

Example:

use ws2812_spi as ws2812;

use smart_leds_matrix::{SmartLedMatrix, layout::Rectangular};

use embedded_graphics::{
    pixelcolor::*,
    prelude::*,
    primitives::{
        PrimitiveStyleBuilder, Rectangle,
    },
};

fn main() -> ! {
[...]
    let ws = ws2812::Ws2812::new(spi);
    let mut matrix = SmartLedMatrix::<_, _, {8 * 8}>::new(ws, Rectangular::new_inverted_y(8, 8));
    matrix.set_brightness(15);
    matrix.clear(Rgb888::new(0, 0, 0));

    // Drawable objects are calling draw_iter() function of the matrix.
    // That is, only the internal frame buffer is updated, no real 
    // communication happens yet. That is useful when a frame is composed
    // of multiple objects, text, etc.
    Rectangle::new(Point::new(1, 1), Size::new(6, 6))
    .into_styled(
        PrimitiveStyleBuilder::new()
        .fill_color(Rgb888::RED)
        .build(),
    ).draw(&mut matrix)?;
    // Trigger the actual frame update on the matrix with gamma correction.
    matrix.flush_with_gamma();
    loop{}
}

Dependencies

~660KB
~12K SLoC