espforge_lib/nibblers/
esp32.rs

1use crate::{
2    config::EspforgeConfiguration,
3    nibblers::{ConfigNibbler, NibblerResult, NibblerStatus},
4    register_nibbler,
5};
6use espforge_macros::auto_register_nibbler;
7
8#[derive(Default)]
9#[auto_register_nibbler]
10pub struct HardwareNibbler;
11
12impl ConfigNibbler for HardwareNibbler {
13    fn name(&self) -> &str {
14        "HardwareNibbler"
15    }
16
17    fn priority(&self) -> u8 {
18        10
19    }
20
21    fn process(&self, config: &EspforgeConfiguration) -> Result<NibblerResult, String> {
22        let mut findings = Vec::new();
23        let mut status = NibblerStatus::Ok;
24
25        if let Some(esp32) = &config.esp32 {
26            // Check GPIOs
27            for (name, pin_config) in &esp32.gpio {
28                if pin_config.pin > 48 {
29                    findings.push(format!(
30                        "Error: GPIO '{}' uses pin {}, which is out of range.",
31                        name, pin_config.pin
32                    ));
33                    status = NibblerStatus::Error;
34                } else {
35                    findings.push(format!("GPIO '{}' mapped to pin {}.", name, pin_config.pin));
36                }
37            }
38
39            // Check SPIs
40            for (name, spi_config) in &esp32.spi {
41                let miso = match spi_config.miso {
42                    Some(pin) => pin.to_string(),
43                    None => "None".to_string(),
44                };
45                findings.push(format!(
46                    "SPI '{}' configured (SCK:{}, MOSI:{}, MISO:{})",
47                    name, spi_config.sck, spi_config.mosi, miso
48                ));
49            }
50        }
51
52        Ok(NibblerResult {
53            nibbler_name: self.name().to_string(),
54            findings,
55            status,
56        })
57    }
58}