1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Binary crate targeting stm32f4 family microcontrollers.
#![deny(unsafe_code)]
#![no_main]
#![no_std]
#![feature(type_alias_impl_trait)]
#![feature(result_option_inspect)]

mod error;
mod sd_logger;
mod startup;
mod tasks;

use heapless::Vec;
pub use sd_logger::SdLogger;
pub use startup::{
    Bme280, Bme280Error, Buzzer, Delay, Gps, I2c1Devices, Led, Lora, LoraError, SdmmcController,
    SdmmcError,
};

#[cfg(debug_assertions)]
use panic_probe as _;
#[cfg(all(not(debug_assertions), feature = "panic-reset"))]
use panic_reset as _;
#[cfg(all(not(debug_assertions), not(feature = "panic-reset")))]
compile_error!("Run `--release` builds with `--no-default-features --features=panic-reset` flags");

use defmt_rtt as _;
use tasks::*;

#[rtic::app(device = stm32f4xx_hal::pac, peripherals = true, dispatchers = [EXTI0, EXTI1])]
mod app {
    use super::*;

    #[shared]
    pub struct Shared {
        pub is_fixed: bool,
        pub gps: Gps,
        pub csv_record: Vec<u8, 512>,
    }

    #[local]
    pub struct Local {
        pub delay: Delay,
        pub led: Led,
        pub buzzer: Buzzer,
        pub sd_logger: Option<SdLogger>,
        pub tracker: accelerometer::Tracker,
        pub i2c1_devices: I2c1Devices,
        pub lora: Option<Lora>,
    }

    #[init(local = [statik: startup::Statik = startup::Statik::new()])]
    fn init(ctx: init::Context) -> (Shared, Local) {
        startup::init(ctx)
    }

    extern "Rust" {
        #[task(local = [delay, sd_logger, tracker, i2c1_devices], shared = [gps, csv_record, is_fixed], priority = 0)]
        async fn measure(ctx: measure::Context);

        #[task(local = [lora], shared = [csv_record], priority = 1)]
        async fn send_meas(ctx: send_meas::Context);

        #[task(binds = USART1, shared = [gps], priority = 2)]
        fn gps_irq(ctx: gps_irq::Context);

        #[task(local = [led], priority = 1)]
        async fn blink(ctx: blink::Context);
        #[task(local = [buzzer], shared = [is_fixed], priority = 1)]
        async fn buzz(ctx: buzz::Context);
    }
}