Skip to main content

Crate ph_haptics

Crate ph_haptics 

Source
Expand description

ph-haptics is a no_std/no_alloc scheduling and motor-modeling runtime for compiled haptic catalogs.

It is not a hardware layer: the runtime models ERM and LRA motor behavior (profiles, kicks, ramps, level clamping) and emits abstract DriveCommand values with tickless wake deadlines. Consuming firmware maps those commands onto its own PWM, GPIO, bus, or motor-driver hardware.

Text/script compilation is handled by the ph-haptics-gen binary. Generated assets use this crate’s DSL/runtime types (Program, Instruction, CompiledHapticDef, Runner) for execution. Curve shaping and tickless transition timing come from ph-curves.

§Features

The default feature set is the embedded runtime and remains no_std and no_alloc. The optional gen feature enables the host-only generator and its std-based dependencies; never enable it in a firmware dependency.

§Example

Generated catalogs expose the same constants assembled explicitly below. Firmware normally includes the generator output and starts a runner from its COMPILED_CATALOG constant.

use ph_haptics::{
    CompiledCatalog, CompiledHapticDef, DriveCommand, ErmConfig, Instruction,
    MonotonicCurveLut256, MotorConfig, MotorKind, Program,
};

let instructions = [Instruction::<MonotonicCurveLut256>::hold(10, u16::MAX)];
let program = Program::new(MotorKind::Erm, &instructions);
let definition = CompiledHapticDef::new("click", program, None);
let definitions = [definition];
let catalog = CompiledCatalog::new(&definitions);
let mut runner = catalog
    .runner_started("click", MotorConfig::Erm(ErmConfig::new(255)), 0)
    .unwrap();

let frame = runner.poll(0);
assert_eq!(frame.command, DriveCommand::Erm { duty: 255 });
assert_eq!(frame.next_transition_ms, Some(10));

Re-exports§

pub use compiled::CompiledCatalog;
pub use compiled::CompiledCatalogError;
pub use compiled::CompiledHapticDef;
pub use error::Error;
pub use motor::DEFAULT_ERM_PROFILE;
pub use motor::DEFAULT_LRA_PROFILE;
pub use motor::DriveCommand;
pub use motor::ErmConfig;
pub use motor::LraConfig;
pub use motor::MotorConfig;
pub use motor::MotorKind;
pub use motor::MotorProfile;
pub use runtime::Frame;
pub use runtime::Runner;
pub use ph_curves;

Modules§

compiled
Compiled haptic definition and catalog types.
error
Runtime/lookup error types.
motor
Motor models, profiles, and driver command types.
runtime
Haptics runner and frame evaluation.

Structs§

MonotonicCurveLut
A monotonic curve backed by an N-entry forward and M-entry inverse LUT.
Program
A haptics program: motor target + instruction stream + repeat mode.
Ramp
A curve-shaped transition from from to to.
TicklessDeadline
A single output produced by the tickless scheduler.
TicklessSchedule
A tickless schedule bound to a monotonic curve and segment parameters.

Enums§

Instruction
A single DSL instruction.
LoopMode
How a program repeats.
Rounding
Rounding policy used by quantize and the tickless scheduler.

Traits§

Curve
Curve evaluation trait.
MonotonicCurve
Trait for monotonic curves that can be inverted.
Tickless
Extension trait that adds tickless scheduling to any MonotonicCurve<T, T> where T: UnitValue.
UnitValue
A normalized value type usable as a curve domain / range.

Type Aliases§

MonotonicCurveLut256
A 256-entry monotonic curve lookup table (u8 domain and range).