Skip to content

Peripherals Module (peripherals)

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).

AdapterImplements Port(s)Capability FeatureTechnology / Purpose
DeviceInputAdapterUserInteractionPortperiph_gpiogpiocdev → Physical GPIO buttons
periph_evdevevdev → Linux touch/keyboard events
periph_i2clinux-embedded-hal → I2C sensors (IMU, gesture)
DesktopHotkeyAdapterperiph_desktoprdev → Desktop OS keyboard shortcuts
LedAdapterUserFeedbackPortperiph_gpiogpiocdev / sysfs-pwm → Physical status LEDs
HapticFeedbackAdapterperiph_pwmsysfs-pwm → PWM haptic motor control
DesktopNotifyAdapterperiph_desktopnotify-rust → OS desktop notifications
UsbKeyboardAdapterKeyboardEmulatorPortperiph_usb_hidstd::fs → Linux USB Gadget HID emulation
DesktopTypingAdapterperiph_desktop_hidenigo → Desktop typing simulation

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.

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.toml

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.

ComponentResponsibility
PeripheralsManagerCentral 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.).

Translates raw physical inputs into semantic domain events (e.g., WakeButton_Pressed, VolumeUp, LongPress).

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 subsystem
  • linux-embedded-hal: IMU and I2C sensor data (gesture triggers)

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 rdev crate for global OS keyboard shortcuts (e.g., Ctrl+Shift+W for “wake”)
  • Same semantic events emitted; Core and flows behave identically on host/desktop

The Driven side is split into two distinct ports to maintain strict separation of concerns:

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.

Hardware adapter for visual feedback.

  • Gated by periph_gpio
  • Uses gpiocdev/sysfs-pwm for physical status LEDs (Listening, Processing, Error, HITL prompt)

Hardware adapter for vibration feedback.

  • Gated by periph_gpio/periph_i2c/periph_pwm
  • Drives vibration motor (short buzz = “got it”, double buzz = “please confirm”)

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-rust for OS-level desktop notifications
  • Developers see what the device’s LED/haptic would do (e.g., popup “HITL: Confirm tool execution?”)

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.

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

Desktop-focused adapter that simulates keystrokes directly into the active window on the host OS.

  • Gated by periph_desktop_hid
  • Technology: The enigo Rust 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