mini-oled
This is a fast and simple driver for the SH1106 OLED display. It is designed for bare-metal systems. The main goal is high speed. It uses embedded-hal for hardware communication and embedded-graphics-core(it's optional but recommended) for drawing. It works well for both simple text and complex animations.
Installation
Add this to your Cargo.toml:
[]
= "0.1.3"
Features
Available Features
- no-std Support: Designed for bare-metal environments.
- I2C Support: Fully implemented using
embedded-hal. - embedded-graphics: Seamless integration for drawing shapes, text, and images.
- Highly Optimized: Algorithmically optimized with branchless programming and fast bitwise math for high performance.
- Buffered Display: Uses ~1KB RAM to create a local frame buffer. Trade-off: Higher RAM usage but significantly reduced bus traffic (only changed pixels are sent).
- Partial Updates: Smart "dirty area" tracking ensures efficient refresh rates.
- Display Rotation: Hardware-assisted rotation (0, 90, 180, 270 degrees).
- Power Save Mode: Supports turning the display logic on/off.
- Contrast Control: Programmable display contrast.
Planned Features
- SPI Support: Currently not implemented.
- Async Support: Planned for future releases.
Usage
With embedded-graphics
Here is a complete example. It shows how to setup the display, draw shapes, write text, and make a simple animation.
use ;
use *;
use Write;
// ... setup your hardware I2C driver here ...
// let i2c = ...;
// Create the I2C interface (address 0x3C is common for SH1106)
let i2c_interface = new;
// Initialize the display driver
let mut screen = new;
// Initialize the display
screen.init.unwrap;
// Set rotation
screen.set_rotation.unwrap;
// Draw a filled rectangle
let fill = with_fill;
new
.into_styled
.draw
.unwrap;
// Prepare text style
let character_style = new
.font
.text_color
.background_color
.build;
let mut i = 0;
let mut old_i = 0;
// Animation loop
loop
Without embedded-graphics
You can also use the library without embedded-graphics. You can change pixels directly using set_pixel or by accessing the buffer.
Disable default features in Cargo.toml:
[]
= { = "0.1.1", = false }
Usage:
use *;
// ... setup your hardware I2C driver here ...
// let i2c = ...;
let i2c_interface = new;
let mut screen = new;
screen.init.unwrap;
// Manually set a pixel at (10, 10)
// This method automatically updates the "dirty area", so flush() is efficient.
screen.get_mut_canvas.set_pixel;
screen.flush.unwrap;
// Or access the raw buffer directly
let buffer = screen.get_mut_canvas.get_mut_buffer;
// buffer[0] = 0xFF; // Set first 8 pixels on
// IMPORTANT: Changing the buffer directly does NOT update the "dirty area".
// The driver does not know which pixels changed.
// You must use `flush_all()` to send the entire buffer to the display.
screen.flush_all.unwrap;
Credits
This project was heavily inspired by this projects:
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in mini-oled by you shall be dual licensed as above, without any additional terms or conditions.