refactor for streamlining

This commit is contained in:
2026-03-11 13:59:56 +01:00
parent a48ba2963d
commit 3112d15eec
91 changed files with 207 additions and 845 deletions

View File

@@ -0,0 +1,12 @@
[target.thumbv7m-none-eabi]
runner = "probe-rs run --chip STM32F103C8"
rustflags = [
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
]
[build]
target = "thumbv7m-none-eabi"
[env]
DEFMT_LOG = "info"

View File

@@ -0,0 +1,22 @@
[package]
name = "button_input_task"
version = "0.1.0"
edition = "2021"
[dependencies]
cortex-m = "0.7.7"
cortex-m-rt = "0.7.5"
defmt = "0.3.10"
defmt-rtt = "0.4.2"
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
nb = "1.1.0"
[dependencies.stm32f1xx-hal]
version = "0.11.0"
features = ["rt", "stm32f103", "medium"]
[profile.release]
codegen-units = 1
debug = 2
lto = true
opt-level = "z"

View File

@@ -0,0 +1,3 @@
# 07 - Button Input
Button an PA0 (Pull-up) lesen und Press/Release als Log ausgeben.

View File

@@ -0,0 +1,5 @@
MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 64K
RAM : ORIGIN = 0x20000000, LENGTH = 20K
}

View File

@@ -0,0 +1,4 @@
[toolchain]
channel = "stable"
components = ["rustfmt"]
targets = ["thumbv7m-none-eabi"]

View File

@@ -0,0 +1,33 @@
#![no_std]
#![no_main]
use cortex_m_rt::entry;
use defmt::info;
use nb::block;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
use {defmt_rtt as _, panic_probe as _};
#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();
let mut rcc = dp.RCC.constrain();
let mut gpioa = dp.GPIOA.split(&mut rcc);
// TODO: Button wiring: PA0 -> button -> GND
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
timer.start(40.Hz()).unwrap();
let mut last_pressed = false;
loop {
// TODO: get the current button status
// TODO: print a message when the button is pressed and released
// Poll at 25ms to avoid too much log spam.
block!(timer.wait()).unwrap();
}
}

View File

@@ -0,0 +1,37 @@
#![no_std]
#![no_main]
use cortex_m_rt::entry;
use defmt::info;
use nb::block;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
use {defmt_rtt as _, panic_probe as _};
#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();
let mut rcc = dp.RCC.constrain();
let mut gpioa = dp.GPIOA.split(&mut rcc);
let button = gpioa.pa0.into_pull_up_input(&mut gpioa.crl);
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
timer.start(40.Hz()).unwrap();
let mut last_pressed = false;
loop {
let pressed = button.is_low();
if pressed != last_pressed {
if pressed {
info!("button: pressed");
} else {
info!("button: released");
}
last_pressed = pressed;
}
block!(timer.wait()).unwrap();
}
}