This repository has been archived on 2026-08-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
donglora/vendor/ssd1306/examples/graphics_i2c_72x40.rs
T
swaitsandClaude Opus 4.6 3102fc747a feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support:
- Splash screen on boot (1.5s) with project name, version, board
- Dashboard showing radio state, config, counters, RSSI/SNR
- RSSI history sparkline (64-sample ring buffer, 2px-wide bars)
- DisplayOn/DisplayOff host commands routed via dedicated channel
- Pure render functions against generic DrawTarget (no hardware coupling)
- Display on/off control bypasses radio task entirely

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:42:54 -06:00

123 lines
3.0 KiB
Rust

//! 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;
#[cfg(feature = "async")]
use embassy_stm32::{bind_interrupts, i2c, peripherals};
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());
#[cfg(feature = "async")]
bind_interrupts!(struct Irqs {
I2C1_EV => i2c::EventInterruptHandler<peripherals::I2C1>;
I2C1_ER => i2c::ErrorInterruptHandler<peripherals::I2C1>;
});
#[cfg(feature = "async")]
let i2c = embassy_stm32::i2c::I2c::new(
p.I2C1,
p.PB6,
p.PB7,
Irqs,
p.DMA1_CH6,
p.DMA1_CH7,
Hertz::khz(400),
Default::default(),
);
#[cfg(not(feature = "async"))]
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, DisplaySize72x40, DisplayRotation::Rotate0)
.into_buffered_graphics_mode();
display.init().unwrap();
let size = 10;
let offset = Point::new(10, (42 / 2) - (size / 2) - 1);
let spacing = size + 10;
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::with_corners(Point::new(0, 0), Point::new(71, 39))
.into_styled(style)
.draw(&mut display)
.unwrap();
// Triangle
Triangle::new(
Point::new(0, size),
Point::new(size / 2, 0),
Point::new(size, size),
)
.translate(offset)
.into_styled(style)
.draw(&mut display)
.unwrap();
// Move over to next position
let offset = offset + Point::new(spacing, 0);
// Draw a square
Rectangle::new(Point::new(0, 0), Size::new_equal(size as u32))
.translate(offset)
.into_styled(style)
.draw(&mut display)
.unwrap();
// Move over a bit more
let offset = offset + Point::new(spacing, 0);
// Circle
Circle::new(Point::zero(), size as u32)
.translate(offset)
.into_styled(style)
.draw(&mut display)
.unwrap();
display.flush().unwrap();
loop {
nop()
}
}