代码use display_interface_spi::SPIInterfaceNoCS;
use embedded_graphics::mono_font::ascii::FONT_10X20;
use embedded_graphics::mono_font::MonoTextStyle;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::{Point, RgbColor, DrawTarget};
use embedded_graphics::text::Text;
use embedded_graphics::Drawable;
use mipidsi::Builder;
use rppal::gpio::Gpio;
use rppal::spi::Spi;
use std::process::ExitCode;
fn main() -> ExitCode {
let gpio = Gpio::new().unwrap();
let rst = gpio.get(27).unwrap().into_output();
let mut backlight = gpio.get(18).unwrap().into_output();
let dc = gpio.get(25).unwrap().into_output();
let spi = Spi::new(
rppal::spi::Bus::Spi0,
rppal::spi::SlaveSelect::Ss0,
60_000_000,
rppal::spi::Mode::Mode0,
)
.unwrap();
let di = SPIInterfaceNoCS::new(spi, dc);
let mut delay = rppal::hal::Delay::new();
let mut display = Builder::st7789(di)
.with_display_size(240, 280)
.with_orientation(mipidsi::Orientation::Landscape(true))
.with_invert_colors(mipidsi::ColorInversion::Inverted)
.init(&mut delay, Some(rst))
.unwrap();
let char_w = 10;
let text = "Hello World ^_^;";
let mut text_x = 120;
let text_y = 280 / 2;
let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
let colors = [Rgb565::RED, Rgb565::GREEN, Rgb565::BLUE];
display.clear(colors[0]).unwrap();
backlight.set_high();
let mut last = std::time::Instant::now();
let mut counter = 0;
loop {
let elapsed = last.elapsed().as_secs_f64();
if elapsed < 0.00125 {
continue;
}
last = std::time::Instant::now();
counter += 1;
display.clear(colors[(counter / 8) % colors.len()]).unwrap();
let right = Text::new(text, Point::new(text_x, text_y), text_style)
.draw(&mut display)
.unwrap();
text_x = if right.x <= 0 { 240 } else { text_x - char_w };
}
backlight.set_low();
display.clear(Rgb565::BLACK).unwrap();
ExitCode::SUCCESS
}

- 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