-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathterminal_i2c.rs
53 lines (48 loc) · 1.35 KB
/
terminal_i2c.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
//! Endlessly fill the screen with characters from the alphabet
//!
//! This example is for the STM32F103 "Blue Pill" board using I2C1.
//!
//! Wiring connections are as follows for a CRIUS-branded display:
//!
//! ```
//! Display -> Blue Pill
//! (black) GND -> GND
//! (red) +5V -> VCC
//! (yellow) SDA -> PB7
//! (green) SCL -> PB6
//! ```
//!
//! Run on a Blue Pill with `cargo run --example terminal_i2c`.
#![no_std]
#![no_main]
use core::fmt::Write;
use cortex_m_rt::entry;
use defmt_rtt as _;
use embassy_stm32::time::Hertz;
use panic_probe as _;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
#[entry]
fn main() -> ! {
let p = embassy_stm32::init(Default::default());
let i2c = embassy_stm32::i2c::I2c::new_blocking(
p.I2C1,
p.PB6,
p.PB7,
Hertz::khz(400),
Default::default(),
);
let interface = I2CDisplayInterface::new(i2c);
let mut display =
Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0).into_terminal_mode();
display.init().unwrap();
let _ = display.clear();
/* Endless loop */
loop {
for c in 97..123 {
let _ = display.write_str(unsafe { core::str::from_utf8_unchecked(&[c]) });
}
for c in 65..91 {
let _ = display.write_str(unsafe { core::str::from_utf8_unchecked(&[c]) });
}
}
}