Struct ssd1331::Ssd1331[][src]

pub struct Ssd1331<SPI, DC> { /* fields omitted */ }
Expand description

SSD1331 display interface

Examples

Draw shapes and text with embedded-graphics

This requires the graphics feature to be enabled (on by default).

use embedded_graphics::{
    geometry::Point,
    image::{Image, ImageRawLE},
    mono_font::{
        ascii::{FONT_6X10, FONT_9X18},
        MonoTextStyleBuilder,
    },
    pixelcolor::Rgb565,
    prelude::*,
    primitives::{Circle, Line, PrimitiveStyle, Rectangle, Triangle},
    text::{Baseline, Text},
};
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);
let raw = ImageRawLE::new(include_bytes!("../examples/ferris.raw"), 86);

let image: Image<ImageRawLE<Rgb565>> = Image::new(&raw, Point::zero());

// Initialise and clear the display
display.init().unwrap();
display.flush().unwrap();

Triangle::new(
    Point::new(8, 16 + 16),
    Point::new(8 + 16, 16 + 16),
    Point::new(8 + 8, 16),
)
.into_styled(PrimitiveStyle::with_stroke(Rgb565::RED, 1))
.draw(&mut display)
.unwrap();

Rectangle::with_corners(Point::new(36, 16), Point::new(36 + 16, 16 + 16))
    .into_styled(PrimitiveStyle::with_stroke(Rgb565::GREEN, 1))
    .draw(&mut display)
    .unwrap();

Circle::new(Point::new(64, 16), 16)
    .into_styled(PrimitiveStyle::with_stroke(Rgb565::BLUE, 1))
    .draw(&mut display)
    .unwrap();

image.draw(&mut display);

// Red with a small amount of green creates a deep orange colour
let rust_style = MonoTextStyleBuilder::new()
    .font(&FONT_9X18)
    .text_color(Rgb565::RED)
    .build();

Text::with_baseline("Hello Rust!", Point::new(0, 0), rust_style, Baseline::Top)
    .draw(&mut display)
    .unwrap();

// Render graphics objects to the screen
display.flush().unwrap();

Implementations

Create new display instance

Ensure display.init() is called before sending data otherwise nothing will be shown.

The driver allocates a buffer of 96px * 64px * 16bits = 12,288 bytes. This may be too large for some target hardware.

Examples

Create a display instance with no rotation

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);

// Initialise and clear the display
display.init().unwrap();
display.flush().unwrap();

Release SPI and DC resources for reuse in other code

Clear the display buffer

display.flush() must be called to update the display

Reset the display

This method brings the RST pin low for 1ms to reset the module, waits for another 1ms then brings RST high

Send the full framebuffer to the display

This resets the draw area the full size of the display

Set the top left and bottom right corners of a bounding box to draw to

Set the value for an individual pixel.

Initialise display, setting sensible defaults and rotation

Get display dimensions, taking into account the current rotation of the display

Examples

No rotation

use ssd1331::{DisplayRotation, Ssd1331};

// Set up SPI interface and digital pin. These are stub implementations used in examples.
let spi = Spi;
let dc = Pin;

let display = Ssd1331::new(spi, dc, DisplayRotation::Rotate0);

assert_eq!(display.dimensions(), (96, 64));

90 degree rotation rotation

use ssd1331::{DisplayRotation, Ssd1331};

// Set up SPI interface and digital pin. These are stub implementations used in examples.
let spi = Spi;
let dc = Pin;

let display = Ssd1331::new(spi, dc, DisplayRotation::Rotate90);

assert_eq!(display.dimensions(), (64, 96));

Set the display rotation

Get the current rotation of the display

Turn the display on (eg exiting sleep mode)

Turn the display off (enter sleep mode)

Trait Implementations

The pixel color type the targetted display supports.

Error type to return when a drawing operation fails. Read more

Draw individual pixels to the display without a defined order. Read more

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more

Fill a given area with a solid color. Read more

Fill the entire display with a solid color. Read more

Returns the size of the bounding box.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Returns the bounding box.

Performs the conversion.

Performs the conversion.

Casts the value.

Casts the value.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.