-
Notifications
You must be signed in to change notification settings - Fork 71
/
pixelsquare.rs
86 lines (74 loc) · 2.33 KB
/
pixelsquare.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
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
82
83
84
85
86
//! This example draws a small square one pixel at a time in the top left corner of the display
//!
//! You will probably want to use the [`embedded_graphics`](https://crates.io/crates/embedded-graphics) crate to do more complex drawing.
//!
//! This example is for the STM32F103 "Blue Pill" board using a 4 wire interface to the display on
//! SPI1.
//!
//! Wiring connections are as follows
//!
//! ```
//! GND -> GND
//! 3V3 -> VCC
//! PA5 -> SCL (D0)
//! PA7 -> SDA (D1)
//! PB0 -> RST
//! PB1 -> D/C
//! PB10 -> CS
//! ```
//!
//! Run on a Blue Pill with `cargo run --example pixelsquare`.
#![no_std]
#![no_main]
use cortex_m::asm::nop;
use cortex_m_rt::entry;
use defmt_rtt as _;
use embassy_stm32::{
gpio,
spi::{self, Spi},
time::Hertz,
};
use panic_probe as _;
use ssd1306::{prelude::*, Ssd1306};
#[entry]
fn main() -> ! {
let p = embassy_stm32::init(Default::default());
let mut config = spi::Config::default();
config.frequency = Hertz::mhz(8);
let spi = Spi::new_blocking_txonly(p.SPI1, p.PA5, p.PA7, config);
let mut rst = gpio::Output::new(p.PB0, gpio::Level::Low, gpio::Speed::Low);
let dc = gpio::Output::new(p.PB1, gpio::Level::Low, gpio::Speed::Low);
let cs = gpio::Output::new(p.PB10, gpio::Level::Low, gpio::Speed::Low);
let spi = embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, cs).unwrap();
let interface = display_interface_spi::SPIInterface::new(spi, dc);
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
.into_buffered_graphics_mode();
display
.reset(&mut rst, &mut embassy_time::Delay {})
.unwrap();
display.init().unwrap();
// Top side
display.set_pixel(0, 0, true);
display.set_pixel(1, 0, true);
display.set_pixel(2, 0, true);
display.set_pixel(3, 0, true);
// Right side
display.set_pixel(3, 0, true);
display.set_pixel(3, 1, true);
display.set_pixel(3, 2, true);
display.set_pixel(3, 3, true);
// Bottom side
display.set_pixel(0, 3, true);
display.set_pixel(1, 3, true);
display.set_pixel(2, 3, true);
display.set_pixel(3, 3, true);
// Left side
display.set_pixel(0, 0, true);
display.set_pixel(0, 1, true);
display.set_pixel(0, 2, true);
display.set_pixel(0, 3, true);
display.flush().unwrap();
loop {
nop()
}
}