add rgb check and example

This commit is contained in:
2026-05-25 19:27:51 +02:00
parent be5dd9632c
commit 9c66429030
17 changed files with 347 additions and 12 deletions

View File

@@ -0,0 +1,16 @@
[package]
name = "embassy-rgb-check"
version = "0.1.0"
edition = "2024"
publish = false
build = "build.rs"
[dependencies]
cortex-m.workspace = true
cortex-m-rt.workspace = true
defmt.workspace = true
defmt-rtt.workspace = true
embassy-executor = { workspace = true, features = ["defmt", "executor-thread", "platform-cortex-m"] }
embassy-stm32 = { workspace = true, features = ["defmt", "stm32f103c8", "time-driver-tim3"] }
embassy-time.workspace = true
panic-probe.workspace = true

View File

@@ -0,0 +1,12 @@
// main: tell Cargo to rerun when memory.x changes and add the shared link path.
// Input: none.
// Output: build script side effects only.
fn main() {
println!("cargo:rerun-if-changed=../../memory.x");
println!(
"cargo:rustc-link-search={}",
std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap())
.join("../..")
.display()
);
}

View File

@@ -0,0 +1,70 @@
#![deny(unsafe_code)]
#![no_std]
#![no_main]
use cortex_m as _;
use defmt::info;
use defmt_rtt as _;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_time::Timer;
use panic_probe as _;
const HOLD_MS: u64 = 1000;
// main: cycle each RGB pin high and low in order so the LED wiring can be checked.
// Input: the Embassy spawner, which this example does not use.
// Output: never returns.
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
let _gnd = Output::new(p.PA0, Level::Low, Speed::Low);
let mut red = Output::new(p.PA1, Level::Low, Speed::Low);
let mut green = Output::new(p.PA2, Level::Low, Speed::Low);
let mut blue = Output::new(p.PA3, Level::Low, Speed::Low);
let mut led = Output::new(p.PC13, Level::High, Speed::Low);
loop {
info!("expected: red high, green low, blue low");
red.set_high();
green.set_low();
blue.set_low();
led.set_low();
Timer::after_millis(HOLD_MS).await;
info!("expected: red low, green low, blue low");
red.set_low();
green.set_low();
blue.set_low();
led.set_high();
Timer::after_millis(HOLD_MS).await;
info!("expected: red low, green high, blue low");
red.set_low();
green.set_high();
blue.set_low();
led.set_low();
Timer::after_millis(HOLD_MS).await;
info!("expected: red low, green low, blue low");
red.set_low();
green.set_low();
blue.set_low();
led.set_high();
Timer::after_millis(HOLD_MS).await;
info!("expected: red low, green low, blue high");
red.set_low();
green.set_low();
blue.set_high();
led.set_low();
Timer::after_millis(HOLD_MS).await;
info!("expected: red low, green low, blue low");
red.set_low();
green.set_low();
blue.set_low();
led.set_high();
Timer::after_millis(HOLD_MS).await;
}
}