Crates.io | sh1122 |
lib.rs | sh1122 |
version | 0.1.0 |
source | src |
created_at | 2021-12-02 16:51:32.211507 |
updated_at | 2021-12-02 16:51:32.211507 |
description | A user mode driver for SH1122 |
homepage | https://github.com/cnwzhjs/sh1122 |
repository | https://github.com/cnwzhjs/sh1122 |
max_upload_size | |
id | 491320 |
size | 9,723 |
A user mode driver for SH1122 written in Rust.
SH1122 is a 256x64 16 grayscale OLED/PLED driver with controller.
It is very common to be used in a OLED display module with I2C, SPI, or 8-bit 6800-series or 8080-series interface.
sh1122
is an abstract device driver for SH1122;sh1122-rppal
uses rppal to drive a SH1122 display with Raspberry PI (note: I2C is the only supported interface yet);sh1122-clock
is a sample binary using above two crates to display a clock on a SH1122 OLED display.The code is only tested on a Raspberry PI 4B board, but it should work on other models as well.
The only exception would be the first generation of Raspberry PI, which uses I2C0 instead of I2C1.
For modern Raspberry PI firmwares, you should change the /boot/firmware/usercfg.txt
by adding dtparam
to enable I2C and make sure it works at fast mode:
dtparam=i2c_arm=on,i2c_arm_baudrate=400000
Reboot to make this effective.
Connect the display to Raspberry PI
Make sure the Raspberry PI's power is disconnected while connecting the board and the display.
The SH1122 display is powered by 3.3v. Just connect the display's VCC to PI's 3v3, and connect SDL, SCL, GND of the display to those pins with same name on PI.
The demo app uses freetype-rs
and Roboto font to render text. Some packages should be installed before building this example:
sudo apt install -y cmake fonts-roboto gcc
git clone https://github.com/cnwzhjs/sh1122-rs.git
cd sh1122-rs
cargo run
To use sh1122
in your own apps, just add these crates as your dependency:
[dependencies]
sh1122 = "0.1"
sh1122-rppal = "0.1"
rppal = "0.13"
Use the driver in your code:
use rppal::i2c::I2c;
use sh1122::*;
use sh1122_rppal::*;
// create I2C bus device
let mut i2c = I2c::with_bus(1).unwrap();
// create SH1122 communication interface
let sh1122if = Sh1122I2cInterface::new(
&mut i2c,
0x3cu8 // the device address (check the manual of your display module)
).unwrap();
// create SH1122 device
let mut sh1122 = Sh1122Device::with_interface(
sh1122if,
256, // width
64 // height
);
// initialize display
sh1122.init_display().unwrap();
// fill pixels
for y in 0..sh1122.get_height() {
for x in 0..sh1122.get_width() {
sh1122.set_pixel(x, y, x as u8);
}
}
// transfer framebuffer to display
sh1122.flush().unwrap();
:balloon: Thanks for your help improving the project! We are so happy to have you!
Licensed under MIT license.