use core::fmt::Write; use embassy_stm32::i2c; use embassy_stm32::peripherals; use embassy_stm32::time::Hertz; use embassy_time::{Duration, Timer}; use embedded_graphics::{ mono_font::{ MonoTextStyle, {ascii::FONT_5X7, ascii::FONT_7X13}, }, pixelcolor::BinaryColor, prelude::*, primitives::{PrimitiveStyleBuilder, Rectangle}, text::Text, }; use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; #[embassy_executor::task] pub async fn display_task(i2c1: peripherals::I2C1, sda: peripherals::PB6, scl: peripherals::PB7) { let i2c = i2c::I2c::new(i2c1, sda, scl, Hertz::hz(100_000), i2c::Config::default()); let interface = I2CDisplayInterface::new(i2c); let mut display = Ssd1306::new(interface, DisplaySize128x32, DisplayRotation::Rotate0) .into_buffered_graphics_mode(); display.init().unwrap(); let text_large = MonoTextStyle::new(&FONT_7X13, BinaryColor::On); let text_large_inv = MonoTextStyle::new(&FONT_7X13, BinaryColor::Off); let text_small = MonoTextStyle::new(&FONT_5X7, BinaryColor::On); let style_filled = PrimitiveStyleBuilder::new() .fill_color(BinaryColor::On) .build(); loop { display.clear(); Text::new("AFG rotor ctrl v0.1.0", Point::new(0, 6), text_small) .draw(&mut display) .unwrap(); Text::new("AZ: 23", Point::new(1, 17), text_large) .draw(&mut display) .unwrap(); Text::new("EL: 42", Point::new(64, 17), text_large) .draw(&mut display) .unwrap(); Rectangle::new(Point::new(0, 19), Size::new(128, 23)) .into_styled(style_filled) .draw(&mut display) .unwrap(); Text::new("AZ: 23", Point::new(1, 30), text_large_inv) .draw(&mut display) .unwrap(); Text::new("EL: 42", Point::new(64, 30), text_large_inv) .draw(&mut display) .unwrap(); /* let now = Instant::now().as_millis(); let mut buf = ArrayString::<20>::new(); write!(&mut buf, "{}", now).expect("Can't write"); Text::new(&buf, Point::new(0, 20), text_large) .draw(&mut display) .unwrap(); */ display.flush().unwrap(); Timer::after(Duration::from_millis(500)).await; } }