Skip to main content

feagi_hal/platforms/
mod.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4/// Platform implementations for embedded systems
5///
6/// Each platform module implements the HAL traits defined in `crate::hal`.
7///
8/// Available platforms:
9/// - ESP32 family (ESP32, ESP32-S3, ESP32-C3)
10/// - Arduino family (Due, Mega, Uno) - future
11/// - STM32 family (F4, H7) - future
12/// - ARM Cortex-M (Raspberry Pi Pico, nRF52) - future
13/// - Neural accelerators (Hailo-8, Google Coral TPU) - future
14
15#[cfg(feature = "esp32")]
16pub mod esp32;
17
18#[cfg(feature = "arduino-due")]
19pub mod arduino;
20
21#[cfg(feature = "stm32f4")]
22pub mod stm32;
23
24#[cfg(feature = "rpi-pico")]
25pub mod rpi_pico;
26
27#[cfg(feature = "hailo")]
28pub mod hailo;
29
30// Re-export platform types
31#[cfg(feature = "esp32")]
32pub use esp32::Esp32Platform;
33
34#[cfg(feature = "arduino-due")]
35pub use arduino::ArduinoDuePlatform;
36
37#[cfg(feature = "stm32f4")]
38pub use stm32::Stm32F4Platform;
39
40#[cfg(feature = "rpi-pico")]
41pub use rpi_pico::RpiPicoPlatform;
42
43#[cfg(feature = "hailo")]
44pub use hailo::{Hailo8Accelerator, HailoError, HybridCpuHailo};
45
46/// Platform registry for runtime selection.
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum PlatformType {
49    /// Espressif ESP32 family (Xtensa dual-core).
50    #[cfg(feature = "esp32")]
51    Esp32,
52    /// Espressif ESP32-S3 family with vector extensions.
53    #[cfg(feature = "esp32-s3")]
54    Esp32S3,
55    /// Espressif ESP32-C3 family based on RISC-V.
56    #[cfg(feature = "esp32-c3")]
57    Esp32C3,
58    /// Arduino Due board (Atmel SAM3X8E).
59    #[cfg(feature = "arduino-due")]
60    ArduinoDue,
61    /// STM32F4 series microcontrollers.
62    #[cfg(feature = "stm32f4")]
63    Stm32F4,
64    /// Raspberry Pi Pico (RP2040) board.
65    #[cfg(feature = "rpi-pico")]
66    RaspberryPiPico,
67    /// Hailo-8 neural accelerator module.
68    #[cfg(feature = "hailo")]
69    Hailo8,
70    // Future platforms
71    // #[cfg(feature = "nrf52")]
72    // Nrf52,
73}
74
75impl PlatformType {
76    /// Get platform type name
77    pub fn name(&self) -> &'static str {
78        match self {
79            #[cfg(feature = "esp32")]
80            PlatformType::Esp32 => "ESP32",
81            #[cfg(feature = "esp32-s3")]
82            PlatformType::Esp32S3 => "ESP32-S3",
83            #[cfg(feature = "esp32-c3")]
84            PlatformType::Esp32C3 => "ESP32-C3 (RISC-V)",
85            #[cfg(feature = "arduino-due")]
86            PlatformType::ArduinoDue => "Arduino Due",
87            #[cfg(feature = "stm32f4")]
88            PlatformType::Stm32F4 => "STM32F4",
89            #[cfg(feature = "rpi-pico")]
90            PlatformType::RaspberryPiPico => "Raspberry Pi Pico",
91            #[cfg(feature = "hailo")]
92            PlatformType::Hailo8 => "Hailo-8 Neural Accelerator",
93            #[allow(unreachable_patterns)]
94            _ => "Unknown",
95        }
96    }
97
98    /// Detect platform at runtime
99    pub fn detect() -> Option<Self> {
100        #[cfg(feature = "esp32")]
101        {
102            // Generic ESP32 platform (covers ESP32, ESP32-S3, ESP32-C3)
103            return Some(PlatformType::Esp32);
104        }
105
106        #[cfg(feature = "arduino-due")]
107        return Some(PlatformType::ArduinoDue);
108
109        #[cfg(feature = "stm32f4")]
110        return Some(PlatformType::Stm32F4);
111
112        #[cfg(feature = "rpi-pico")]
113        return Some(PlatformType::RaspberryPiPico);
114
115        #[cfg(feature = "hailo")]
116        return Some(PlatformType::Hailo8);
117
118        #[allow(unreachable_code)]
119        None
120    }
121}