#display #raspberry-pi #driver #sh1122

sh1122-rppal

SH1122 (Raspberry PI接口)的用户模式驱动程序

1个不稳定版本

0.1.0 2021年12月2日

#1028 in 嵌入式开发

MIT许可证

13KB
251

SH1122驱动程序

使用Rust编写的SH1122的用户模式驱动程序。

demo

SH1122

SH1122是一款256x64 16级灰度OLED/PLED控制器。

它通常用于具有I2C、SPI或8位6800系列或8080系列接口的OLED显示模块。

此仓库包含的内容

  1. sh1122是SH1122的抽象设备驱动程序;
  2. sh1122-rppal使用rppal在Raspberry PI上驱动SH1122显示屏(注意:目前只支持I2C接口);
  3. sh1122-clock是一个示例二进制文件,使用上述两个crate在SH1122 OLED显示屏上显示时钟。

准备您的Raspberry PI

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.
  1. 启用I2C并将波特率设置为400k

对于现代Raspberry PI固件,您应该通过添加dtparam/boot/firmware/usercfg.txt来启用I2C,并确保它以快速模式工作

dtparam=i2c_arm=on,i2c_arm_baudrate=400000

重新启动以生效。

  1. 将显示屏连接到Raspberry PI

    在连接板和显示屏时,请确保Raspberry PI的电源已断开。

SH1122显示屏由3.3v供电。只需将显示屏的VCC连接到PI的3v3,并将显示屏的SDL、SCL、GND连接到PI上具有相同名称的引脚。

  1. 安装演示所需的软件包

该演示应用程序使用freetype-rs和Roboto字体来渲染文本。在构建此示例之前应安装一些软件包

sudo apt install -y cmake fonts-roboto gcc

运行示例二进制文件

git clone https://github.com/cnwzhjs/sh1122-rs.git
cd sh1122-rs
cargo run

开始使用

要在您的应用程序中使用sh1122,只需将这些crate作为依赖项添加

[dependencies]
sh1122 = "0.1"
sh1122-rppal = "0.1"
rppal = "0.13"

在代码中使用驱动程序

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();

贡献

🎈 感谢您帮助改进项目!我们非常高兴有您!

许可证

根据MIT许可证授权。

依赖项

~515KB