[−][src]Crate ssd1331
SSD1331 OLED display driver
This crate is an SPI-based driver for the popular SSD1331 colour OLED display. This display uses
an RGB565 colour space on a canvas of 96x64 pixels and runs over SPI. This driver should work
with any device implementing the embedded-hal blocking::spi::Write
trait.
embedded-graphics
is also supported behind the graphics
feature flag (on by default).
Note that the driver requires at least 12288 bytes (96 x 64 pixels, 16 bits per pixel) of memory to store the display's framebuffer.
Examples
Full examples can be found in the examples/ folder
Set individual pixels with .set_pixel()
use embedded_graphics::{ pixelcolor::{ raw::{RawData, RawU16}, Rgb565, }, prelude::*, }; use ssd1331::{DisplayRotation::Rotate0, Ssd1331}; // Set up SPI interface and digital pin. These are stub implementations used in examples. let spi = Spi; let dc = Pin; let mut display = Ssd1331::new(spi, dc, Rotate0); display.init(); // Use raw hex values display.set_pixel(10, 20, 0xf00); // Or embedded-graphics' `Rgb565` if the `graphics` feature is enabled display.set_pixel(10, 30, RawU16::from(Rgb565::new(255, 127, 0)).into_inner()); display.flush();
Render a rainbow Rust logo
use embedded_graphics::{image::Image, pixelcolor::Rgb565, prelude::*}; use ssd1331::{DisplayRotation::Rotate0, Ssd1331}; use tinybmp::Bmp; // Set up SPI interface and digital pin. These are stub implementations used in examples. let spi = Spi; let dc = Pin; let mut display = Ssd1331::new(spi, dc, Rotate0); display.init(); let bmp = Bmp::from_slice(include_bytes!("../examples/rust-pride.bmp")).unwrap(); let im: Image<Bmp, Rgb565> = Image::new(&bmp, Point::zero()); // Center the image on the display let moved = im.translate(Point::new((96 - bmp.width() as i32) / 2, 0)); moved.draw(&mut display); display.flush().unwrap();
Features
graphics
(enabled by default)
Enable the graphics
feature in Cargo.toml
to get access to features in the
embedded-graphics
crate. This adds the .draw()
method to the Ssd1331
struct which
accepts any embedded-graphics
compatible item.
Structs
Ssd1331 | SSD1331 display interface |
Enums
DisplayRotation | Display rotation |
Error | Enum of errors in this crate |