Struct ssd1331::Ssd1331[][src]

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

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::{
    fonts::{Font6x8, Text},
    geometry::Point,
    image::{Image, ImageRawLE},
    pixelcolor::Rgb565,
    prelude::*,
    primitives::{Circle, Line, Rectangle},
    style::{PrimitiveStyleBuilder, TextStyleBuilder},
};
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, 64);

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

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

Line::new(Point::new(0, 0), Point::new(16, 16))
    .into_styled(
        PrimitiveStyleBuilder::new()
            .stroke_color(Rgb565::RED)
            .stroke_width(1)
            .build(),
    )
    .draw(&mut display);

Rectangle::new(Point::new(24, 0), Point::new(40, 16))
    .into_styled(
        PrimitiveStyleBuilder::new()
            .stroke_color(Rgb565::new(255, 127, 0))
            .stroke_width(1)
            .build(),
    )
    .draw(&mut display);

Circle::new(Point::new(64, 8), 8)
    .into_styled(
        PrimitiveStyleBuilder::new()
            .stroke_color(Rgb565::GREEN)
            .stroke_width(1)
            .build(),
    )
    .draw(&mut display);

image.draw(&mut display);

Text::new("Hello Rust!", Point::new(24, 24))
    .into_styled(
        TextStyleBuilder::new(Font6x8)
            .text_color(Rgb565::RED)
            .build(),
    )
    .draw(&mut display);

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

Implementations

impl<SPI, DC, CommE, PinE> Ssd1331<SPI, DC> where
    SPI: Write<u8, Error = CommE>,
    DC: OutputPin<Error = PinE>, 
[src]

pub fn new(spi: SPI, dc: DC, display_rotation: DisplayRotation) -> Self[src]

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

pub fn release(self) -> (SPI, DC)[src]

Release SPI and DC resources for reuse in other code

pub fn clear(&mut self)[src]

Clear the display buffer

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

pub fn reset<RST, DELAY>(
    &mut self,
    rst: &mut RST,
    delay: &mut DELAY
) -> Result<(), Error<CommE, PinE>> where
    RST: OutputPin<Error = PinE>,
    DELAY: DelayMs<u8>, 
[src]

Reset the display

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

pub fn flush(&mut self) -> Result<(), Error<CommE, PinE>>[src]

Send the full framebuffer to the display

This resets the draw area the full size of the display

pub fn set_draw_area(
    &mut self,
    start: (u8, u8),
    end: (u8, u8)
) -> Result<(), Error<CommE, PinE>>
[src]

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

pub fn set_pixel(&mut self, x: u32, y: u32, value: u16)[src]

Turn a pixel on or off. A non-zero value is treated as on, 0 as off. If the X and Y coordinates are out of the bounds of the display, this method call is a noop.

pub fn init(&mut self) -> Result<(), Error<CommE, PinE>>[src]

Initialise display, setting sensible defaults and rotation

pub fn dimensions(&self) -> (u8, u8)[src]

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

pub fn set_rotation(
    &mut self,
    rot: DisplayRotation
) -> Result<(), Error<CommE, PinE>>
[src]

Set the display rotation

pub fn rotation(&self) -> DisplayRotation[src]

Get the current rotation of the display

pub fn turn_on(&mut self) -> Result<(), Error<CommE, PinE>>[src]

Turn the display on (eg exiting sleep mode)

pub fn turn_off(&mut self) -> Result<(), Error<CommE, PinE>>[src]

Turn the display off (enter sleep mode)

Trait Implementations

impl<SPI, DC> DrawTarget<Rgb565> for Ssd1331<SPI, DC> where
    SPI: Write<u8>,
    DC: OutputPin
[src]

type Error = Infallible

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

Auto Trait Implementations

impl<SPI, DC> Send for Ssd1331<SPI, DC> where
    DC: Send,
    SPI: Send

impl<SPI, DC> Sync for Ssd1331<SPI, DC> where
    DC: Sync,
    SPI: Sync

impl<SPI, DC> Unpin for Ssd1331<SPI, DC> where
    DC: Unpin,
    SPI: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.