• Stars
    star
    305
  • Rank 136,879 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SSD1306 OLED driver

SSD1306 driver

Build Status Crates.io Docs.rs

CRIUS display showing the Rust logo

I2C and SPI (4 wire) driver for the SSD1306 OLED display.

Please consider becoming a sponsor so I may continue to maintain this crate in my spare time!

Documentation

Changelog

Examples

This crate uses probe-run to run the examples. Once set up, it should be as simple as cargo run --example <example name> --release.

From examples/image_i2c.rs:

#![no_std]
#![no_main]

use cortex_m_rt::{entry, exception, ExceptionFrame};
use embedded_graphics::{
    image::{Image, ImageRaw},
    pixelcolor::BinaryColor,
    prelude::*,
};
use panic_halt as _;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
use stm32f1xx_hal::{
    i2c::{BlockingI2c, DutyCycle, Mode},
    prelude::*,
    stm32,
};

#[entry]
fn main() -> ! {
    let dp = stm32::Peripherals::take().unwrap();

    let mut flash = dp.FLASH.constrain();
    let mut rcc = dp.RCC.constrain();

    let clocks = rcc.cfgr.freeze(&mut flash.acr);

    let mut afio = dp.AFIO.constrain(&mut rcc.apb2);

    let mut gpiob = dp.GPIOB.split(&mut rcc.apb2);

    let scl = gpiob.pb8.into_alternate_open_drain(&mut gpiob.crh);
    let sda = gpiob.pb9.into_alternate_open_drain(&mut gpiob.crh);

    let i2c = BlockingI2c::i2c1(
        dp.I2C1,
        (scl, sda),
        &mut afio.mapr,
        Mode::Fast {
            frequency: 400_000.hz(),
            duty_cycle: DutyCycle::Ratio2to1,
        },
        clocks,
        &mut rcc.apb1,
        1000,
        10,
        1000,
        1000,
    );

    let interface = I2CDisplayInterface::new(i2c);
    let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
        .into_buffered_graphics_mode();
    display.init().unwrap();

    let raw: ImageRaw<BinaryColor> = ImageRaw::new(include_bytes!("./rust.raw"), 64);

    let im = Image::new(&raw, Point::new(32, 0));

    im.draw(&mut display).unwrap();

    display.flush().unwrap();

    loop {}
}

#[exception]
fn HardFault(ef: &ExceptionFrame) -> ! {
    panic!("{:#?}", ef);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

usb-device

Experimental device-side USB framework for microcontrollers in Rust.
Rust
425
star
2

embedded-sdmmc-rs

A SD/MMC library with FAT16/FAT32 support, suitable for Embedded Rust systems
Rust
302
star
3

embedded-nal

An Embedded Network Abstraction Layer
Rust
177
star
4

serde-json-core

`serde-json` for `no_std` programs
Rust
159
star
5

async-on-embedded

Rust
123
star
6

usbd-serial

Work-in progress minimal CDC-ACM (USB serial port) class for usb-device
Rust
114
star
7

pc-keyboard

PS/2 Keyboard Decoder in Rust
Rust
93
star
8

embedded-storage

An Embedded Storage Abstraction Layer
Rust
64
star
9

menu

Command-line menu system for embedded Rust platforms.
Rust
44
star
10

usbd-midi

Rust
44
star
11

tinyrlibc

Tiny C library written in Rust
Rust
41
star
12

tm4c-hal

An Embedded HAL and general chip support for the TM4C123/LM4F120. Replaces the old lm4f120 crate.
Rust
40
star
13

sh1106

SH1106 driver for use with embedded_hal and (optionally) embedded_graphics
Rust
32
star
14

aligned

A newtype with alignment of at least `A` bytes
Rust
30
star
15

sensehat-rs

Rust support for the Raspberry Pi Sense Hat
Rust
27
star
16

multi-map

Like a Rust std::collection::HashMap, but allows you to use either of two different keys to retrieve items.
Rust
26
star
17

ssd1331

SSD1331 colour OLED display driver for embedded Rust applications using embedded-hal
Rust
17
star
18

hash32

32-bit hashing machinery
Rust
10
star
19

meta

Details about the rust-embedded-community project
10
star
20

tb6612fng-rs

A pure rust `no_std` driver for the TB6612FNG motor driver.
Rust
4
star
21

adafruit-bluefruit-protocol-rs

A `no_std` parser for the Adafruit Bluefruit LE Connect controller protocol.
Rust
2
star