//! Draw a square, circle and triangle on the screen using the `embedded_graphics` crate. //! //! 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 graphics_i2c`. #![no_std] #![no_main] use cortex_m::asm::nop; use cortex_m_rt::entry; use defmt_rtt as _; use embassy_stm32::time::Hertz; use embedded_graphics::{ pixelcolor::BinaryColor, prelude::*, primitives::{Circle, PrimitiveStyleBuilder, Rectangle, Triangle}, }; 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_buffered_graphics_mode(); display.init().unwrap(); let yoffset = 20; let style = PrimitiveStyleBuilder::new() .stroke_width(1) .stroke_color(BinaryColor::On) .build(); // screen outline // default display size is 128x64 if you don't pass a _DisplaySize_ // enum to the _Builder_ struct Rectangle::new(Point::new(0, 0), Size::new(127, 63)) .into_styled(style) .draw(&mut display) .unwrap(); // triangle Triangle::new( Point::new(16, 16 + yoffset), Point::new(16 + 16, 16 + yoffset), Point::new(16 + 8, yoffset), ) .into_styled(style) .draw(&mut display) .unwrap(); // square Rectangle::new(Point::new(52, yoffset), Size::new_equal(16)) .into_styled(style) .draw(&mut display) .unwrap(); // circle Circle::new(Point::new(88, yoffset), 16) .into_styled(style) .draw(&mut display) .unwrap(); display.flush().unwrap(); loop { nop() } }