Module sh1106::builder

source ·
Expand description

Interface factory

This is the easiest way to create a driver instance. You can set various parameters of the driver and give it an interface to use. The builder will return a mode::RawMode object which you should coerce to a richer display mode, like mode::Graphics for drawing primitives and text.

Examples

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

use sh1106::{mode::GraphicsMode, Builder};
let spi = /* SPI interface from your HAL of choice */
let dc = /* GPIO data/command select pin */

// This example does not use a Chip Select pin
let cs = sh1106::builder::NoOutputPin::new();

Builder::new().connect_spi(spi, dc, cs);

Connect over I2C, changing lots of options

use sh1106::{displayrotation::DisplayRotation, displaysize::DisplaySize, Builder};

let i2c = /* I2C interface from your HAL of choice */

Builder::new()
    .with_rotation(DisplayRotation::Rotate180)
    .with_i2c_addr(0x3D)
    .with_size(DisplaySize::Display128x32)
    .connect_i2c(i2c);

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

use sh1106::{mode::GraphicsMode, Builder};
let spi = /* SPI interface from your HAL of choice */
let dc = /* GPIO data/command select pin */

// This example does not use a Chip Select pin
let cs = sh1106::builder::NoOutputPin::new();

let display: GraphicsMode<_> = Builder::new().connect_spi(spi, dc, cs).into();

Structs

  • Builder struct. Driver options and interface are set using its methods.
  • Represents an unused output pin.