#![no_std]
#![no_main]
use embedded_graphics::{
mono_font::MonoTextStyleBuilder,
pixelcolor::BinaryColor::On as Black,
pixelcolor::BinaryColor::{self, Off as White},
prelude::*,
primitives::{Circle, Line, PrimitiveStyle},
text::{Baseline, Text, TextStyleBuilder},
};
use epd_waveshare::{epd2in9_v2::*, graphics::DisplayRotation, prelude::*};
use esp_backtrace as _;
use esp_println::println;
use hal::{
clock::ClockControl,
peripherals::Peripherals,
prelude::*,
spi::{master::Spi, SpiMode},
timer::TimerGroup,
Delay, Rtc, IO,
};
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let clocks = ClockControl::max(system.clock_control).freeze();
let mut delay = Delay::new(&clocks);
// Disable the RTC and TIMG watchdog timers
// let mut rtc = Rtc::new(peripherals.RTC_CNTL);
// let timer_group0 = TimerGroup::new(
// peripherals.TIMG0,
// &clocks,
// &mut system.peripheral_clock_control,
// );
// let mut wdt0 = timer_group0.wdt;
// let timer_group1 = TimerGroup::new(
// peripherals.TIMG1,
// &clocks,
// &mut system.peripheral_clock_control,
// );
// let mut wdt1 = timer_group1.wdt;
// rtc.rwdt.disable();
// wdt0.disable();
// wdt1.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let mosi = io.pins.gpio5; // DIN
let miso = io.pins.gpio6;
let clk = io.pins.gpio18;
let cs_esp = io.pins.gpio15.into_push_pull_output();
let mut spi = Spi::new(
peripherals.SPI2,
clk,
mosi,
miso,
cs_esp,
25u32.kHz(),
SpiMode::Mode0,
&clocks,
);
let cs = io.pins.gpio19.into_push_pull_output();
let busy = io.pins.gpio22.into_pull_up_input();
let rst = io.pins.gpio23.into_push_pull_output();
let dc = io.pins.gpio21.into_push_pull_output();
let mut epd = Epd2in9::new(&mut spi, cs, busy, dc, rst, &mut delay).unwrap();
// Use display graphics from embedded-graphics
let mut display = Display2in9::default();
println!("Drawing rotated text...");
display.set_rotation(DisplayRotation::Rotate0);
draw_text(&mut display, "Hallo Claudi!", 5, 50);
display.set_rotation(DisplayRotation::Rotate90);
draw_text(&mut display, "Hallo Claudi", 5, 50);
display.set_rotation(DisplayRotation::Rotate180);
draw_text(&mut display, "Hallo Claudi!", 5, 50);
display.set_rotation(DisplayRotation::Rotate270);
draw_text(&mut display, "Hallo Claudi!", 5, 50);
epd.update_frame(&mut spi, display.buffer(), &mut delay)
.unwrap();
epd.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
// Set the EPD to sleep
epd.sleep(&mut spi, &mut delay).unwrap();
loop {}
}
fn draw_text(display: &mut Display2in9, text: &str, x: i32, y: i32) {
let style = MonoTextStyleBuilder::new()
.font(&embedded_graphics::mono_font::ascii::FONT_6X10)
.text_color(Black)
// .background_color(Pink)
.build();
let text_style = TextStyleBuilder::new().baseline(Baseline::Top).build();
let _ = Text::with_text_style(text, Point::new(x, y), style, text_style).draw(display);
}
Loading
epaper-2in9
epaper-2in9