pokeys_lib/lib.rs
1//! # PoKeys Core Library - Pure Rust Implementation
2//!
3//! This is the **core library** of the PoKeys ecosystem, providing a pure Rust implementation
4//! of the PoKeysLib functionality for controlling PoKeys devices without external dependencies.
5//!
6//! ## Core Features
7//!
8//! ### Device Connectivity
9//! - USB and Network device enumeration and connection
10//! - Auto-detection of connection types
11//! - Multi-device concurrent management
12//!
13//! ### Digital & Analog I/O
14//! - Digital I/O operations with bulk configuration
15//! - Multi-channel analog input with configurable reference voltage
16//! - Pin function validation and safety checks
17//!
18//! ### Advanced Control Systems
19//! - PWM control with configurable frequency and duty cycle
20//! - Quadrature encoder support (4x/2x sampling modes)
21
22//! - Matrix keyboard scanning and LED matrix control
23//!
24//! ### Communication Protocols
25//! - **SPI**: Full master support with multiple chip select pins
26//! - **I2C**: Master operations with device scanning
27//! - **1-Wire**: Temperature sensor support
28//! - **CAN Bus**: Message transmission and reception
29//! - **UART**: Serial communication
30//!
31//! ### Display & Interface Support
32//! - LCD display control and management
33//! - Seven-segment character mapping utilities
34//!
35//! ### Sensor Integration
36//! - EasySensors support and data acquisition
37//! - Real-time clock operations and synchronization
38//! - Temperature sensor integration
39//!
40//! ### Safety & Reliability
41//! - Device model validation with pin capability checks
42//! - Comprehensive error handling with context
43//! - Thread-safe concurrent device access
44//! - Configurable failsafe behavior
45//! - SPI pin reservation and conflict prevention
46//!
47//! ## Performance Optimizations
48//!
49//! - **Bulk Operations**: 28x faster pin configuration (96.4% time reduction)
50//! - **Single Enumeration**: 3x faster multi-device sync (65% improvement)
51//! - **Encoder Fix**: Correct pin numbering conversion
52//!
53//! ## Usage
54//!
55//! ```rust,no_run
56//! use pokeys_lib::{enumerate_usb_devices, connect_to_device, PinFunction, Result};
57//!
58//! fn main() -> Result<()> {
59//! // Enumerate available devices
60//! let device_count = enumerate_usb_devices()?;
61//!
62//! // Connect to first device
63//! if device_count > 0 {
64//! let mut device = connect_to_device(0)?;
65//!
66//! // Read device information
67//! device.get_device_data()?;
68//!
69//! // Set pin as digital output
70//! device.set_pin_function(1, PinFunction::DigitalOutput)?;
71//!
72//! // Set pin high
73//! device.set_digital_output(1, true)?;
74//! }
75//!
76//! Ok(())
77//! }
78//! ```
79// Allow clippy warnings for cleanup PR - these will be addressed in a separate PR
80#![allow(clippy::derivable_impls)]
81#![allow(clippy::ptr_arg)]
82#![allow(clippy::needless_range_loop)]
83#![allow(clippy::vec_init_then_push)]
84#![allow(clippy::uninlined_format_args)]
85
86pub mod communication;
87pub mod device;
88pub mod encoders;
89pub mod error;
90pub mod io;
91pub mod keyboard_matrix;
92pub mod lcd;
93pub mod matrix;
94pub mod model_manager;
95pub mod models;
96pub mod network;
97pub mod oem_parameters;
98pub mod protocols;
99pub mod pulse_engine;
100pub mod pwm;
101pub mod sensors;
102pub mod types;
103
104pub use device::*;
105pub use error::*;
106pub use pulse_engine::PulseEngineConfig;
107pub use types::*;
108
109// Re-export main functionality
110pub use device::{connect_to_device, connect_to_device_with_serial, enumerate_usb_devices};
111pub use io::{PinCapability, PinFunction};
112pub use keyboard_matrix::MatrixKeyboard;
113pub use model_manager::ModelManager;
114pub use models::{DeviceModel, PinModel};
115
116// Re-export OEM parameter constants
117pub use oem_parameters::{LOCATION_PARAMETER_INDEX, OEM_PARAMETER_MAX_INDEX};
118
119// Re-export LED matrix functionality
120pub use matrix::{
121 LedMatrixConfig, MatrixAction, MatrixLedProtocolConfig, SEVEN_SEGMENT_DIGITS,
122 SEVEN_SEGMENT_LETTERS, SevenSegmentDisplay, get_seven_segment_pattern,
123};
124
125// Re-export network configuration helpers
126pub use network::NetworkDeviceConfig;
127
128// Re-export protocol convenience functions
129pub use protocols::{
130 can_send_standard, i2c_read_simple, i2c_write_simple, spi_configure_simple, spi_read_simple,
131 spi_write_simple,
132};
133
134// Re-export uSPIBridge functionality
135pub use protocols::{SegmentMapping, SegmentMappingType, USPIBridgeCommand, USPIBridgeConfig};
136
137// Re-export servo control functionality
138pub use pwm::{ServoConfig, ServoType};
139
140/// Library version information
141pub const VERSION_MAJOR: u8 = 0;
142pub const VERSION_MINOR: u8 = 3;
143pub const VERSION_PATCH: u8 = 0;
144
145/// Get library version as string
146pub fn version() -> String {
147 format!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}")
148}