4个版本
0.2.0 | 2023年11月9日 |
---|---|
0.1.2 | 2022年11月7日 |
0.1.1 | 2022年11月6日 |
0.1.0 | 2022年11月6日 |
#1642 in 嵌入式开发
25KB
327 行
GDEH0154D67
描述
为GDEH0154D67电子纸显示屏的简单SPI驱动程序。这个crate是一个no_std
库,提供与embedded-hal-1.0.0-rc.1兼容的接口。它还设计用于与embedded-graphics一起使用。通过在编译时使用零成本抽象强制设计约束,确保每次都正确初始化并保持一致的状态。
该crate有一个std
功能,用于在完全std
环境中使用,它的唯一效果是使error::Error
实现std:error::Error
。还有一个名为heap_buffer
的功能,它将在堆上分配内部图形缓冲区,以防止在更有限的平台上发生栈溢出。当然,这个功能需要分配器。
用法
从embedded-graphics主文档页面改编的简单示例
use gdeh0154d67::GDEH0154D67;
use embedded_graphics::{
pixelcolor::BinaryColor,
prelude::*,
mono_font::{ascii::FONT_10X20, MonoTextStyle},
primitives::{
Circle, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle, StrokeAlignment, Triangle,
},
text::{Alignment, Text},
};
fn main() {
let peripherals = Peripherals::take().unwrap();
let spi = peripherals.spi2;
let sclk = peripherals.pins.gpio18.into_output().unwrap();
let serial_out = peripherals.pins.gpio23.into_output().unwrap();
let cs = peripherals.pins.gpio5.into_output().unwrap();
let reset = peripherals.pins.gpio9.into_output().unwrap();
let busy = peripherals.pins.gpio19.into_input().unwrap();
let dc = peripherals.pins.gpio10.into_output().unwrap();
let config = <spi::config::Config as Default>::default().baudrate(20.MHz().into());
let spi = spi::Master::<spi::SPI2, _, _, _, _>::new(
spi,
spi::Pins {
sclk,
sdo: serial_out,
sdi: Option::<GpioPin<InputOutput>>::None,
cs: Option::<Gpio5<Output>>::Some(cs),
},
config,
).unwrap();
let delay = delay::Ets;
let mut display = GDEH0154D67::new(spi, dc, reset, busy, delay).unwrap().init().unwrap();
display.full_update().unwrap();
// Create styles used by the drawing operations.
let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1);
let thick_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 3);
let border_stroke = PrimitiveStyleBuilder::new()
.stroke_color(BinaryColor::On).stroke_width(3)
.stroke_alignment(StrokeAlignment::Inside).build();
let fill = PrimitiveStyle::with_fill(BinaryColor::On);
let character_style = MonoTextStyle::new(&FONT_10X20, BinaryColor::On);
let yoffset = 20;
// Draw a 3px wide outline around the display.
display.bounding_box().into_styled(border_stroke).draw(&mut display).unwrap();
// Draw a triangle.
Triangle::new(
Point::new(32, 32 + yoffset),
Point::new(32 + 32, 32 + yoffset),
Point::new(32 + 16, yoffset),
).into_styled(thin_stroke).draw(&mut display).unwrap();
display.partial_update().unwrap();
// Draw a filled square
Rectangle::new(Point::new(84, yoffset), Size::new(32, 32))
.into_styled(fill).draw(&mut display).unwrap();
display.partial_update().unwrap();
let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::Off, 1);
// Erase the triangle.
Triangle::new(
Point::new(32, 32 + yoffset),
Point::new(32 + 32, 32 + yoffset),
Point::new(32 + 16, yoffset),
).into_styled(thin_stroke).draw(&mut display).unwrap();
// Draw a circle with a 3px wide stroke.
Circle::new(Point::new(32, yoffset), 34)
.into_styled(thick_stroke).draw(&mut display).unwrap();
display.partial_update().unwrap();
// Draw centered text.
let text = "23:35";
Text::with_alignment(
text,
display.bounding_box().center() + Point::new(0, 0),
character_style,
Alignment::Center,
).draw(&mut display).unwrap();
display.partial_update().unwrap();
(spi, dc, reset, busy) = display.release().unwrap();
Ok(())
}
支持
如果在项目中发现任何错误或要讨论新功能,请打开一个问题。
致谢
我想感谢嵌入式-rust社区,特别是这篇博客文章的作者,因为多亏了它,我才能迈出正确的第一步。
许可证
本项目采用MIT许可证,您可以在同一个存储库中找到它。
项目状态
这是我为了娱乐和学习Rust而在业余时间做的一个项目。我愿意包括新功能,但我只有一块ESP板来测试驱动程序,所有的连接都已经连接好了,这阻止了我包括I2C通信等。因此,除非有人愿意贡献这些功能,否则驱动程序可能不会包含GDEH0154D67显示屏的所有功能。话虽如此,这个驱动程序足以通过SPI协议高效地控制显示屏。
依赖关系
~6MB
~95K SLoC