Skip to main content

feagi_hal/hal/
mod.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4/// Neural accelerator control traits.
5pub mod accelerator;
6/// Bluetooth Low Energy communication traits.
7pub mod bluetooth;
8/// General-purpose I/O abstractions for pins.
9pub mod gpio;
10/// Logging interfaces for embedded targets.
11pub mod logger;
12/// Serial input/output traits for UART-style communication.
13pub mod serial;
14/// Hardware Abstraction Layer (HAL) trait definitions for embedded platforms
15///
16/// This module defines platform-agnostic traits that must be implemented
17/// by each platform to provide:
18/// - Time management (TimeProvider)
19/// - Serial I/O (SerialIO)
20/// - GPIO control (GpioProvider)
21/// - Logging (Logger)
22/// - Neural acceleration (NeuralAccelerator)
23/// - Timekeeping abstractions (monotonic timers, delays).
24pub mod time;
25/// USB CDC Serial communication traits.
26pub mod usb_cdc;
27
28// Re-export trait types
29pub use accelerator::{AcceleratorCapabilities, NeuralAccelerator};
30pub use bluetooth::{BluetoothProvider, ConnectionStatus};
31pub use gpio::GpioProvider;
32pub use logger::{LogLevel, Logger};
33pub use serial::SerialIO;
34pub use time::TimeProvider;
35pub use usb_cdc::{UsbCdcProvider, UsbConnectionStatus};
36
37#[cfg(feature = "async")]
38pub use bluetooth::AsyncBluetoothProvider;
39
40#[cfg(feature = "async")]
41pub use usb_cdc::AsyncUsbCdcProvider;
42
43/// Convenience trait combining common platform capabilities
44///
45/// Most embedded platforms will implement this trait by combining
46/// TimeProvider, SerialIO, GpioProvider, and Logger.
47pub trait Platform: TimeProvider + Logger {
48    /// Get platform name (e.g., "ESP32", "Arduino Due", "STM32F4")
49    fn name(&self) -> &'static str;
50
51    /// Get CPU frequency in Hz
52    fn cpu_frequency_hz(&self) -> u32;
53
54    /// Get available memory in bytes
55    fn available_memory_bytes(&self) -> usize;
56
57    /// Get platform uptime in milliseconds
58    fn uptime_ms(&self) -> u64 {
59        self.get_time_us() / 1000
60    }
61}