// SPDX-FileCopyrightText: 2025 Tomasz Kramkowski // SPDX-License-Identifier: GPL-3.0-or-later #![no_main] #![no_std] mod dual_hx711; mod pulse; use embassy_stm32::{bind_interrupts, peripherals, timer}; use {defmt_rtt as _, panic_probe as _}; use rtic_monotonics::systick::prelude::*; systick_monotonic!(Mono); bind_interrupts!(struct Irqs { TIM3 => timer::UpdateInterruptHandler; }); #[rtic::app(device = embassy_stm32, peripherals = true, dispatchers = [SDIO, USART6])] mod app { use crate::pulse::CountingMode; use super::*; use embassy_stm32::{ exti::ExtiInput, gpio::{Level, OutputOpenDrain, OutputType, Pull, Speed}, time::*, timer::simple_pwm::PwmPin, Config, }; use pulse::Pulse; #[shared] struct Shared {} #[local] struct Local {} #[init] fn init(cx: init::Context) -> (Shared, Local) { defmt::trace!("init"); embassy_stm32::pac::FLASH.acr().modify(|w| { w.set_prften(true); w.set_icen(true); w.set_dcen(true) }); let mut config = Config::default(); { use embassy_stm32::rcc::*; config.rcc.hsi = false; config.rcc.hse = Some(Hse { freq: mhz(25), mode: HseMode::Oscillator, }); config.rcc.pll_src = PllSource::HSE; config.rcc.pll = Some(Pll { prediv: PllPreDiv::DIV13, mul: PllMul::MUL104, divp: Some(PllPDiv::DIV2), divq: None, divr: None, }); config.rcc.ahb_pre = AHBPrescaler::DIV1; config.rcc.apb1_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV1; config.rcc.sys = Sysclk::PLL1_P; } let p = embassy_stm32::init(config); defmt::trace!("embassy_stm32::init done"); Mono::start(cx.core.SYST, 100_000_000); let led = OutputOpenDrain::new(p.PC13, Level::High, Speed::Medium); blink::spawn(led).ok(); // Create the clock pin let tim3_ch3_pin = PwmPin::new(p.PB0, OutputType::OpenDrain); let tim3_pulse = Pulse::new( p.TIM3, None, None, Some(tim3_ch3_pin), None, khz(500), CountingMode::EdgeAlignedUp, Irqs, ); // Data pins let left_lc = ExtiInput::new(p.PB8, p.EXTI8, Pull::None); let right_lc = ExtiInput::new(p.PB9, p.EXTI9, Pull::None); // Spawn test task test::spawn(tim3_pulse, left_lc, right_lc).ok(); (Shared {}, Local {}) } #[task()] async fn test( _cx: test::Context, clk: Pulse<'static, peripherals::TIM3>, a: ExtiInput<'static>, b: ExtiInput<'static>, ) { // Create driver from peripherals let mut scales = dual_hx711::DualHx711::new(clk, a, b); // Keep reading forever loop { let (a, b) = scales.read().await.unwrap(); defmt::info!("scales read: {}, {}", a, b); } } #[task()] async fn blink(_cx: blink::Context, mut led: OutputOpenDrain<'static>) { loop { led.toggle(); Mono::delay(1.secs()).await; } } }