[][src]Module ssd1306::builder

Interface factory

This is the easiest way to create a driver instance, with the ability to set various parameters of the driver.

To finish the builder and produce a connected display interface, call .connect(interface) where interface is an instantiated DisplayInterface implementation. For I2C interfaces there's also an I2CDIBuilder to simplify the construction of an I2C DisplayInterface. The builder will be consumed into a DisplayProperties object which can be coerced into a richer display mode like GraphicsMode or TerminalMode.

Examples

Connect over SPI with default rotation (0 deg) and size (128x64):

use ssd1306::Builder;

let interface = display_interface_spi::SPIInterfaceNoCS::new(spi, dc);
Builder::new().connect(interface);

Connect over I2C, changing lots of options

use ssd1306::{prelude::*, Builder, I2CDIBuilder};

let interface = I2CDIBuilder::new().init(i2c);
let di: DisplayProperties<_, _> = Builder::new()
    .with_rotation(DisplayRotation::Rotate180)
    .connect(interface);

The builder defaults to a display size of 128 x 64px. To use a display with a different size, call the size method. Supported sizes can be found in the displaysize module or in the prelude.

use ssd1306::{prelude::*, Builder, I2CDIBuilder};

let interface = I2CDIBuilder::new().init(i2c);
let di: DisplayProperties<_, _> = Builder::new()
    .with_rotation(DisplayRotation::Rotate180)
    .size(DisplaySize128x32)
    .connect(interface);

The above examples will produce a DisplayProperties instance by default. You need to coerce them into a mode by specifying a type on assignment. For example, to use TerminalMode mode:

use ssd1306::{prelude::*, Builder};

let interface = display_interface_spi::SPIInterfaceNoCS::new(spi, dc);
let display: TerminalMode<_, _> = Builder::new().connect(interface).into();

Structs

Builder

Builder struct. Driver options and interface are set using its methods.

I2CDIBuilder

Builder struct for an I2C interface. Driver options and interface are set using its methods.