Skip to main content

feagi_hal/
lib.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4#![no_std]
5#![warn(missing_docs)]
6
7//! # FEAGI HAL
8//!
9//! Hardware Abstraction Layer (HAL) for FEAGI embedded neural networks.
10//! Platform abstraction and implementations for embedded systems.
11//!
12//! This crate provides:
13//! - **HAL traits** (`hal` module) - Platform-agnostic hardware abstractions
14//! - **Platform implementations** (`platforms` module) - Concrete implementations for ESP32, Arduino, STM32, etc.
15//!
16//! ## Usage
17//!
18//! ### Advanced Users (Direct HAL Usage)
19//! ```no_run
20//! use feagi_hal::prelude::*;
21//! use feagi_npu_runtime::embedded::{NeuronArray, SynapseArray};
22//! use feagi_npu_neural::types::INT8Value;
23//!
24//! fn main() -> ! {
25//!     let platform = Esp32Platform::init().expect("Failed to init");
26//!     let mut neurons = NeuronArray::<INT8Value, 1000>::new();
27//!     let mut synapses = SynapseArray::<5000>::new();
28//!
29//!     // Custom network topology
30//!     // Custom burst loop
31//!     loop {
32//!         neurons.process_burst(&synapses);
33//!     }
34//! }
35//! ```
36//!
37//! ### SDK Users
38//! See `feagi-nano` crate for high-level SDK with NetworkBuilder, templates, etc.
39//!
40//! ## Feature Flags
41//!
42//! Platforms are selected via feature flags:
43//! - `esp32` - ESP32, ESP32-S3, ESP32-C3 support
44//! - `arduino-due` - Arduino Due support (future)
45//! - `stm32f4` - STM32F4 series support (future)
46//! - `hailo` - Hailo-8 neural accelerator support (future)
47
48/// Hardware abstraction traits shared by all platforms.
49pub mod hal;
50
51/// Concrete platform implementations (ESP32, STM32, etc.).
52pub mod platforms;
53
54/// Bluetooth Low Energy protocol and abstractions
55pub mod bluetooth;
56
57/// Transport layer (protocol that works with BLE, USB CDC, UART, etc.)
58pub mod transports;
59
60// Re-export commonly used types
61pub use hal::{
62    AcceleratorCapabilities, BluetoothProvider, ConnectionStatus, GpioProvider, LogLevel, Logger,
63    NeuralAccelerator, Platform, SerialIO, TimeProvider, UsbCdcProvider, UsbConnectionStatus,
64};
65
66#[cfg(feature = "async")]
67pub use hal::{AsyncBluetoothProvider, AsyncUsbCdcProvider};
68
69// Re-export transport protocol
70pub use transports::{Command, PacketCommand, Protocol};
71
72// Re-export platform implementations
73#[cfg(feature = "esp32")]
74pub use platforms::Esp32Platform;
75
76#[cfg(feature = "arduino-due")]
77pub use platforms::ArduinoDuePlatform;
78
79#[cfg(feature = "stm32f4")]
80pub use platforms::Stm32F4Platform;
81
82#[cfg(feature = "rpi-pico")]
83pub use platforms::RpiPicoPlatform;
84
85#[cfg(feature = "hailo")]
86pub use platforms::{Hailo8Accelerator, HailoError, HybridCpuHailo};
87
88// Re-export core FEAGI types for convenience
89pub use feagi_npu_neural::types::{INT8Value, NeuralValue};
90pub use feagi_npu_runtime::embedded::{NeuronArray, SynapseArray};
91
92/// Prelude module for convenient imports
93///
94/// ```no_run
95/// use feagi_hal::prelude::*;
96/// ```
97pub mod prelude {
98    pub use crate::hal::*;
99    pub use crate::platforms::*;
100    pub use feagi_npu_neural::types::{INT8Value, NeuralValue};
101    pub use feagi_npu_runtime::embedded::{NeuronArray, SynapseArray};
102
103    #[cfg(feature = "esp32")]
104    pub use crate::platforms::Esp32Platform;
105
106    #[cfg(feature = "arduino-due")]
107    pub use crate::platforms::ArduinoDuePlatform;
108
109    #[cfg(feature = "stm32f4")]
110    pub use crate::platforms::Stm32F4Platform;
111
112    #[cfg(feature = "rpi-pico")]
113    pub use crate::platforms::RpiPicoPlatform;
114
115    #[cfg(feature = "hailo")]
116    pub use crate::platforms::{Hailo8Accelerator, HailoError, HybridCpuHailo};
117}
118
119/// Version information
120pub const VERSION: &str = env!("CARGO_PKG_VERSION");
121
122/// Get library version
123pub fn version() -> &'static str {
124    VERSION
125}