stm32_rust_template/apps/
empty.rs

1use crate::apps::App;
2
3pub struct EmptyApp {
4    initialized: bool,
5}
6
7impl EmptyApp {
8    pub fn new() -> Self {
9        Self { initialized: false }
10    }
11
12    /// Initialize the app. Nothing to do for the empty app, but keep the same
13    /// Result signature so callers can treat it like other apps.
14    pub fn init(&mut self) -> Result<(), i32> {
15        if self.initialized {
16            return Ok(());
17        }
18
19        // No hardware to initialize for empty app.
20        self.initialized = true;
21        Ok(())
22    }
23
24    /// Non-blocking tick that does nothing useful (just idles).
25    pub fn tick(&mut self) {
26        // If not initialized yet, try to init.
27        if !self.initialized {
28            let _ = self.init();
29        }
30
31        // Do nothing
32    }
33}
34
35impl App for EmptyApp {
36    fn init(&mut self) -> Result<(), i32> {
37        self.init()
38    }
39    fn loop_step(&mut self) {
40        self.tick()
41    }
42}
43
44pub fn create_empty_app() -> EmptyApp {
45    EmptyApp::new()
46}