Peripherals Module (peripherals)
Overview
Section titled “Overview”The peripherals crate implements the Core’s PeripheralsInterface and is unique among domain crates: it spans both sides of the Hexagonal Architecture. Buttons and touch surfaces drive the system (left side); LEDs and haptics are driven by the Core (right side).
Ports & Adapters (Feature Flags)
Section titled “Ports & Adapters (Feature Flags)”| Adapter | Implements Port(s) | Capability Feature | Technology / Purpose |
|---|---|---|---|
DeviceInputAdapter | UserInteractionPort | periph_gpio | gpiocdev → Physical GPIO buttons |
periph_evdev | evdev → Linux touch/keyboard events | ||
periph_i2c | linux-embedded-hal → I2C sensors (IMU, gesture) | ||
DesktopHotkeyAdapter | periph_desktop | rdev → Desktop OS keyboard shortcuts | |
LedAdapter | UserFeedbackPort | periph_gpio | gpiocdev / sysfs-pwm → Physical status LEDs |
HapticFeedbackAdapter | periph_pwm | sysfs-pwm → PWM haptic motor control | |
DesktopNotifyAdapter | periph_desktop | notify-rust → OS desktop notifications | |
UsbKeyboardAdapter | KeyboardEmulatorPort | periph_usb_hid | std::fs → Linux USB Gadget HID emulation |
DesktopTypingAdapter | periph_desktop_hid | enigo → Desktop typing simulation |
Architecture Context / Relationships
Section titled “Architecture Context / Relationships”The peripherals crate is unique as it bridges both sides of the Hexagonal Architecture. It pushes events (like physical button presses) to core as a driving adapter, but it also receives commands (like LEDs or haptic feedback) from core as a driven adapter.
Crate Structure
Section titled “Crate Structure”crates/peripherals/├── src/│ ├── domain/ # PeripheralsManager, Semantic Events│ │ └── ports.rs # Traits: `UserInteractionPort`, `UserFeedbackPort`, `KeyboardEmulatorPort`│ ├── adapters/ # Hardware & OS implementations│ │ ├── gpio.rs # Raw buttons and LEDs (`gpiocdev`)│ │ ├── evdev.rs # Linux touch/keyboard events│ │ ├── desktop.rs # Desktop hotkeys/notifications fallback│ │ └── usb_hid.rs # Hardware USB Gadget keyboard emulation│ └── lib.rs # Implements Core's `PeripheralsInterface`└── Cargo.tomlThe Dual Nature in the Hexagon
Section titled “The Dual Nature in the Hexagon”Unlike Audio and Vision (strictly Driven right-side adapters), the Peripherals domain bridges both sides:
- Driving (Left side): Physical buttons generate interrupts that trigger Core state changes (wake, start listening, confirm HITL prompt)
- Driven (Right side): LEDs and haptic motors provide status feedback (Listening, Processing, Error) and implement HITL confirmation
This dual role makes Peripherals the physical bridge between the user and the system.
Internal Domain Components
Section titled “Internal Domain Components”| Component | Responsibility |
|---|---|
PeripheralsManager | Central facade implementing PeripheralsInterface. Translates raw hardware signals to semantic domain events (input) and Core state to physical feedback (output). Ensures consistency across the entire paiOS architecture (matching VisionManager, AudioManager, etc.). |
Input Ports & Adapters (The Driving Side)
Section titled “Input Ports & Adapters (The Driving Side)”UserInteractionPort
Section titled “UserInteractionPort”Translates raw physical inputs into semantic domain events (e.g., WakeButton_Pressed, VolumeUp, LongPress).
DeviceInputAdapter
Section titled “DeviceInputAdapter”The primary hardware adapter for this port. It is feature-gated to select the concrete technology at compile time.
- Gated by
periph_gpio,periph_evdev,periph_i2c gpiocdev: raw buttons and switches (GPIO lines)evdev: touch, mouse, keyboard events from Linux input subsystemlinux-embedded-hal: IMU and I2C sensor data (gesture triggers)
DesktopHotkeyAdapter
Section titled “DesktopHotkeyAdapter”Development-focused adapter that maps OS-level keyboard shortcuts to the same semantic events as real hardware. Enables full development on a desktop without the target AI device attached.
- Gated by
periph_desktop - Uses
rdevcrate for global OS keyboard shortcuts (e.g., Ctrl+Shift+W for “wake”) - Same semantic events emitted; Core and flows behave identically on host/desktop
Output Ports & Adapters (The Driven Side)
Section titled “Output Ports & Adapters (The Driven Side)”The Driven side is split into two distinct ports to maintain strict separation of concerns:
UserFeedbackPort
Section titled “UserFeedbackPort”Translates Core state into non-verbal physical feedback. Hyper-critical for screen-less form factors (e.g. wearables) where the Permission System (HITL) must ask for confirmation using LED and haptic patterns only: no display. HITL is required on all devices regardless of screen presence; non-verbal feedback enables it on screen-less devices.
LedAdapter
Section titled “LedAdapter”Hardware adapter for visual feedback.
- Gated by
periph_gpio - Uses
gpiocdev/sysfs-pwmfor physical status LEDs (Listening, Processing, Error, HITL prompt)
HapticFeedbackAdapter
Section titled “HapticFeedbackAdapter”Hardware adapter for vibration feedback.
- Gated by
periph_gpio/periph_i2c/periph_pwm - Drives vibration motor (short buzz = “got it”, double buzz = “please confirm”)
DesktopNotifyAdapter
Section titled “DesktopNotifyAdapter”Development-focused adapter that mirrors LED/haptic patterns into desktop notifications so developers can see what the device would do.
- Gated by
periph_desktop - Uses
notify-rustfor OS-level desktop notifications - Developers see what the device’s LED/haptic would do (e.g., popup “HITL: Confirm tool execution?”)
KeyboardEmulatorPort
Section titled “KeyboardEmulatorPort”Acts as a Machine-to-Machine (M2M) interface for active data payload output. Takes text generated by the LLM and pushes it to a host system as simulated keystrokes. This enables the “paiType” accelerator use case: the user speaks into the device, the local LLM transcribes and corrects the text, and the PeripheralsManager streams the text directly into the user’s active desktop application (e.g., Word, Obsidian) via USB without requiring any driver installations on the host.
UsbKeyboardAdapter
Section titled “UsbKeyboardAdapter”Target hardware adapter for USB HID keyboard emulation.
- Gated by
periph_usb_hid - Technology: Rust
std::fs(File I/O for HID Reports) - Infrastructure: Linux USB Gadget Subsystem (
/dev/hidg0) connecting to a Host PC via USB-C - Enables the “USB AI Accelerator” milestone
DesktopTypingAdapter
Section titled “DesktopTypingAdapter”Desktop-focused adapter that simulates keystrokes directly into the active window on the host OS.
- Gated by
periph_desktop_hid - Technology: The
enigoRust crate - Infrastructure: The Host OS (Mac/Windows). Simulates physical keystrokes directly into the active window
- Allows full development and testing on host/desktop without USB hardware
Related Documentation
Section titled “Related Documentation”- ADR-004: Engine Architecture: Dual Driving/Driven role of Peripherals
- Core Module: PeripheralsInterface and SessionManager
- Workspace and Build: Feature flags (periph_gpio, periph_desktop, etc.)
- Security Architecture: HITL confirmation via LEDs and haptics