1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
//! SSD1331 OLED display driver
//!
//! This crate is an SPI-based driver for the popular SSD1331 colour OLED display. This display uses
//! an RGB565 colour space on a canvas of 96x64 pixels and runs over SPI. This driver should work
//! with any device implementing the [embedded-hal] [`blocking::spi::Write`] trait.
//!
//! [`embedded-graphics`] is also supported behind the `graphics` feature flag (on by default).
//!
//! Note that the driver requires at least 12288 bytes (96 x 64 pixels, 16 bits per pixel) of memory
//! to store the display's framebuffer.
//!
//! # Examples
//!
//! Full examples can be found in
//! [the examples/ folder](https://github.com/jamwaffles/ssd1331/blob/master/examples)
//!
//! ## Set individual pixels with `.set_pixel()`
//!
//! ```rust
//! # use ssd1331::test_helpers::{Spi, Pin};
//! use embedded_graphics::{
//!     pixelcolor::{
//!         raw::{RawData, RawU16},
//!         Rgb565,
//!     },
//!     prelude::*,
//! };
//! 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);
//! display.init();
//!
//! // Use raw hex values
//! display.set_pixel(10, 20, 0xf00);
//! // Or embedded-graphics' `Rgb565` if the `graphics` feature is enabled
//! display.set_pixel(10, 30, RawU16::from(Rgb565::new(255, 127, 0)).into_inner());
//!
//! display.flush();
//! ```
//!
//! ## Render a rainbow Rust logo
//!
//! ```rust
//! # use ssd1331::test_helpers::{Spi, Pin};
//! use embedded_graphics::{image::Image, pixelcolor::Rgb565, prelude::*};
//! use ssd1331::{DisplayRotation::Rotate0, Ssd1331};
//! use tinybmp::Bmp;
//!
//! // 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);
//! display.init();
//!
//! let bmp = Bmp::from_slice(include_bytes!("../examples/rust-pride.bmp")).unwrap();
//!
//! let im: Image<Bmp, Rgb565> = Image::new(&bmp, Point::zero());
//!
//! // Center the image on the display
//! let moved = im.translate(Point::new((96 - bmp.width() as i32) / 2, 0));
//!
//! moved.draw(&mut display);
//!
//! display.flush().unwrap();
//! ```
//!
//! # Features
//!
//! ## `graphics` (enabled by default)
//!
//! Enable the `graphics` feature in `Cargo.toml` to get access to features in the
//! [`embedded-graphics`] crate. This adds the `.draw()` method to the [`Ssd1331`] struct which
//! accepts any `embedded-graphics` compatible item.
//!
//! [embedded-hal]: https://docs.rs/embedded-hal
//! [`blocking::spi::Write`]: https://docs.rs/embedded-hal/0.2.3/embedded_hal/blocking/spi/trait.Write.html
//! [`Ssd1331`]: ./struct.Ssd1331.html
//! [`embedded-graphics`]: https://docs.rs/embedded-graphics

#![no_std]
// #![deny(missing_debug_implementations)]
#![deny(missing_docs)]
// #![deny(warnings)]
#![deny(missing_copy_implementations)]
#![deny(trivial_casts)]
#![deny(trivial_numeric_casts)]
#![deny(unsafe_code)]
#![deny(unstable_features)]
#![deny(unused_import_braces)]
#![deny(unused_qualifications)]

extern crate embedded_hal as hal;

const DISPLAY_WIDTH: u8 = 96;
const DISPLAY_HEIGHT: u8 = 64;

mod command;
mod display;
mod displayrotation;
mod error;
#[doc(hidden)]
pub mod test_helpers;

pub use crate::{display::Ssd1331, displayrotation::DisplayRotation, error::Error};