brainwires_hardware/lib.rs
1//! # brainwires-hardware
2//!
3//! Hardware I/O for the Brainwires Agent Framework.
4//!
5//! Provides a unified hardware abstraction layer covering:
6//!
7//! | Module | Feature flag | Description |
8//! |--------|-------------|-------------|
9//! | [`audio`] | `audio` | Audio capture/playback, STT, TTS (16 cloud providers + local Whisper) |
10//! | [`gpio`] | `gpio` | GPIO pin management with safety allow-lists and PWM (Linux) |
11//! | [`bluetooth`] | `bluetooth` | BLE advertisement scanning and adapter enumeration |
12//! | [`network`] | `network` | NIC enumeration, IP config, ARP discovery, port scanning |
13//! | [`camera`] | `camera` | Webcam/camera frame capture (V4L2/AVFoundation/MSMF) |
14//! | [`usb`] | `usb` | Raw USB device enumeration and bulk/control/interrupt transfers |
15//! | [`homeauto`] | `homeauto` | Home automation: Zigbee (EZSP+ZNP), Z-Wave, Thread (OTBR), Matter |
16//!
17//! ## Feature flags
18//!
19//! ```toml
20//! [dependencies]
21//! brainwires-hardware = { version = "0.10", features = ["audio", "gpio", "bluetooth", "network"] }
22//! # or enable everything:
23//! brainwires-hardware = { version = "0.10", features = ["full"] }
24//! ```
25//!
26//! ### Audio
27//! The `audio` feature enables hardware audio capture/playback via CPAL and
28//! 16 cloud STT/TTS provider integrations. Add `local-stt` for offline Whisper
29//! inference and `flac` for FLAC codec support.
30//!
31//! ### GPIO (Linux)
32//! The `gpio` feature exposes safe GPIO pin access using the Linux character
33//! device API (`gpio-cdev`) with an explicit allow-list safety policy.
34//!
35//! ### Bluetooth
36//! The `bluetooth` feature uses [`btleplug`](https://crates.io/crates/btleplug)
37//! for cross-platform BLE scanning (Linux/BlueZ, macOS CoreBluetooth, Windows WinRT).
38//!
39//! ### Network
40//! The `network` feature provides interface enumeration, IP configuration
41//! parsing, ARP-based host discovery, and async TCP port scanning.
42//!
43//! ### Camera
44//! The `camera` feature enables video frame capture using [`nokhwa`](https://crates.io/crates/nokhwa):
45//! V4L2 on Linux, AVFoundation on macOS, Media Foundation on Windows.
46//!
47//! ### USB
48//! The `usb` feature provides raw USB device enumeration and transfers via
49//! [`nusb`](https://crates.io/crates/nusb) — a pure-Rust async USB library
50//! with no `libusb` system dependency.
51
52/// Audio capture, playback, STT, and TTS.
53#[cfg(feature = "audio")]
54pub mod audio;
55
56/// GPIO hardware access (Linux).
57#[cfg(feature = "gpio")]
58pub mod gpio;
59
60/// Bluetooth discovery and scanning.
61#[cfg(feature = "bluetooth")]
62pub mod bluetooth;
63
64/// Network interface enumeration, discovery, and port scanning.
65#[cfg(feature = "network")]
66pub mod network;
67
68/// Camera and webcam frame capture.
69#[cfg(feature = "camera")]
70pub mod camera;
71
72/// Raw USB device access and transfers.
73#[cfg(feature = "usb")]
74pub mod usb;
75
76/// Home automation protocols: Zigbee (EZSP + ZNP), Z-Wave (Serial API), Thread (OTBR), Matter.
77#[cfg(any(
78 feature = "homeauto",
79 feature = "zigbee",
80 feature = "zwave",
81 feature = "thread",
82 feature = "matter",
83 feature = "matter-ble",
84))]
85pub mod homeauto;
86
87// ── Convenience re-exports: mirrors the old brainwires-audio public API ──────
88
89#[cfg(feature = "audio")]
90pub use audio::{
91 AudioBuffer, AudioCapture, AudioConfig, AudioDevice, AudioError, AudioPlayback, AudioResult,
92 AudioRingBuffer, DeviceDirection, OutputFormat, SampleFormat, SpeechToText, SttOptions,
93 TextToSpeech, Transcript, TranscriptSegment, TtsOptions, Voice,
94};
95
96#[cfg(feature = "audio")]
97pub use audio::{decode_wav, encode_wav};
98
99#[cfg(feature = "audio")]
100pub use audio::{
101 AzureStt, AzureTts, CartesiaTts, DeepgramStt, DeepgramTts, ElevenLabsStt, ElevenLabsTts,
102 FishStt, FishTts, GoogleTts, MurfTts, OpenAiResponsesStt, OpenAiResponsesTts, OpenAiStt,
103 OpenAiTts,
104};
105
106#[cfg(feature = "audio")]
107pub use audio::{CpalCapture, CpalPlayback};
108
109#[cfg(all(feature = "audio", feature = "flac"))]
110pub use audio::{decode_flac, encode_flac};
111
112#[cfg(all(feature = "audio", feature = "local-stt"))]
113pub use audio::WhisperStt;
114
115// ── GPIO re-exports ───────────────────────────────────────────────────────────
116
117#[cfg(feature = "gpio")]
118pub use gpio::{GpioChipInfo, GpioLineInfo, GpioPin, GpioPinManager, GpioSafetyPolicy};
119
120// ── Camera re-exports ─────────────────────────────────────────────────────────
121
122#[cfg(feature = "camera")]
123pub use camera::{
124 CameraCapture, CameraDevice, CameraError, CameraFormat, CameraFrame, FrameRate, NokhwaCapture,
125 PixelFormat, Resolution,
126};
127
128// ── USB re-exports ────────────────────────────────────────────────────────────
129
130#[cfg(feature = "usb")]
131pub use usb::{UsbClass, UsbDevice, UsbError, UsbHandle, UsbSpeed};
132
133// ── Home automation re-exports ────────────────────────────────────────────────
134
135#[cfg(any(
136 feature = "homeauto",
137 feature = "zigbee",
138 feature = "zwave",
139 feature = "thread",
140 feature = "matter",
141 feature = "matter-ble",
142))]
143pub use homeauto::{HomeAutoError, HomeAutoEvent, HomeAutoResult, HomeDevice, Protocol};
144
145#[cfg(feature = "zigbee")]
146pub use homeauto::{EzspCoordinator, ZigbeeAddr, ZigbeeCoordinator, ZigbeeDevice, ZnpCoordinator};
147
148#[cfg(feature = "zwave")]
149pub use homeauto::{CommandClass, NodeId, ZWaveController, ZWaveNode, ZWaveSerialController};
150
151#[cfg(feature = "thread")]
152pub use homeauto::{ThreadBorderRouter, ThreadNeighbor, ThreadNodeInfo};
153
154#[cfg(feature = "matter")]
155pub use homeauto::{MatterController, MatterDevice, MatterDeviceConfig, MatterDeviceServer};
156
157// ── VAD re-exports ────────────────────────────────────────────────────────────
158
159#[cfg(feature = "audio")]
160pub use audio::{EnergyVad, SpeechSegment, VoiceActivityDetector};
161#[cfg(feature = "vad")]
162pub use audio::{VadMode, WebRtcVad};
163
164// ── Wake word re-exports ──────────────────────────────────────────────────────
165
166#[cfg(feature = "wake-word-porcupine")]
167pub use audio::PorcupineDetector;
168#[cfg(feature = "wake-word-rustpotter")]
169pub use audio::RustpotterDetector;
170#[cfg(any(
171 feature = "wake-word",
172 feature = "wake-word-rustpotter",
173 feature = "wake-word-porcupine"
174))]
175pub use audio::{EnergyTriggerDetector, WakeWordDetection, WakeWordDetector};
176
177// ── Voice assistant re-exports ────────────────────────────────────────────────
178
179#[cfg(feature = "voice-assistant")]
180pub use audio::{
181 AssistantState, VoiceAssistant, VoiceAssistantBuilder, VoiceAssistantConfig,
182 VoiceAssistantHandler,
183};