#![no_std]
#![no_main]
use embedded_graphics::{
mono_font::{
ascii::{FONT_6X10, FONT_9X18_BOLD},
MonoTextStyleBuilder,
},
pixelcolor::BinaryColor,
prelude::*,
text::{Alignment, Text},
};
use esp32_hal::{
clock::ClockControl,
gpio::IO,
i2c::I2C,
peripherals::Peripherals,
prelude::*,
timer::TimerGroup,
};
use esp_backtrace as _;
use nb::block;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut timer0 = timer_group0.timer0;
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let i2c = I2C::new(
peripherals.I2C0,
io.pins.gpio32,
io.pins.gpio33,
100u32.kHz(),
&clocks,
);
timer0.start(5u64.secs());
let interface = I2CDisplayInterface::new(i2c);
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
.into_buffered_graphics_mode();
display.init().unwrap();
let text_style = MonoTextStyleBuilder::new()
.font(&FONT_6X10)
.text_color(BinaryColor::On)
.build();
let text_style_big = MonoTextStyleBuilder::new()
.font(&FONT_9X18_BOLD)
.text_color(BinaryColor::On)
.build();
loop {
Text::with_alignment(
"esp-hal",
display.bounding_box().center() + Point::new(0, 0),
text_style_big,
Alignment::Center,
)
.draw(&mut display)
.unwrap();
Text::with_alignment(
"Chip: ESP32",
display.bounding_box().center() + Point::new(0, 14),
text_style,
Alignment::Center,
)
.draw(&mut display)
.unwrap();
display.flush().unwrap();
display.clear(BinaryColor::Off).unwrap();
block!(timer0.wait()).unwrap();
Text::with_alignment(
"Hello World!",
display.bounding_box().center(),
text_style_big,
Alignment::Center,
)
.draw(&mut display)
.unwrap();
display.flush().unwrap();
display.clear(BinaryColor::Off).unwrap();
block!(timer0.wait()).unwrap();
}
}