-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathferris.rs
50 lines (40 loc) · 1.41 KB
/
ferris.rs
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
#![no_std]
#![no_main]
use panic_halt as _;
use embedded_graphics::image::{Image, ImageRaw};
use embedded_graphics::pixelcolor::raw::LittleEndian;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::*;
use embedded_graphics::primitives::{Rectangle, PrimitiveStyle};
use longan_nano::hal::{pac, prelude::*};
use longan_nano::{lcd, lcd_pins};
use riscv_rt::entry;
const FERRIS: &[u8] = include_bytes!("ferris.raw");
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
// Configure clocks
let mut rcu = dp
.RCU
.configure()
.ext_hf_clock(8.mhz())
.sysclk(108.mhz())
.freeze();
let mut afio = dp.AFIO.constrain(&mut rcu);
let gpioa = dp.GPIOA.split(&mut rcu);
let gpiob = dp.GPIOB.split(&mut rcu);
let lcd_pins = lcd_pins!(gpioa, gpiob);
let mut lcd = lcd::configure(dp.SPI0, lcd_pins, &mut afio, &mut rcu);
let (width, height) = (lcd.size().width as i32, lcd.size().height as i32);
// Clear screen
Rectangle::new(Point::new(0, 0), Size::new(width as u32, height as u32))
.into_styled(PrimitiveStyle::with_fill(Rgb565::BLACK))
.draw(&mut lcd)
.unwrap();
// Load Image Data
let raw_image: ImageRaw<Rgb565, LittleEndian> = ImageRaw::new(&FERRIS, 86);
Image::new(&raw_image, Point::new(width / 2 - 43, height / 2 - 32))
.draw(&mut lcd)
.unwrap();
loop {}
}