Skip to main content

Crate ph_curves

Crate ph_curves 

Source
Expand description

no_std, zero-allocation curve lookup tables and tickless scheduling for embedded Rust.

ph-curves stores pre-computed forward (and optionally inverse) lookup tables as static arrays so that curve evaluation reduces to a single array index. Combined with the tickless scheduler, interrupt-driven firmware can sleep between value transitions instead of polling at a fixed tick rate.

§Quick start

Use the companion CLI (ph-curves-gen) to generate static LUTs from a TOML definition file, then include! the output in your crate:

use ph_curves::{Curve, MonotonicCurve, Tickless, Rounding};

include!("curves.rs");

// Forward evaluation — a single table lookup.
let brightness: u8 = GAMMA_22.eval(input);

// Inverse lookup (monotonic curves only).
let input: u8 = GAMMA_22.inv(brightness);

// Tickless scheduling — sleep until the next quantized value change.
let schedule = EASE_IN_QUAD.tickless_schedule(
    0,     // t0_ms
    1000,  // duration_ms
    0,     // start_val
    255,   // end_val
    10,    // step (quantization)
    Rounding::Nearest,
    0,     // min_dt_ms
);

for deadline in schedule.iter(0) {
    set_timer(deadline.deadline_ms);
    set_output(deadline.current_val);
}

§Key types

Everything is re-exported at the crate root.

Structs§

CurveLut
A curve backed by an N-entry forward and optional M-entry inverse LUT.
MonotonicCurveLut
A monotonic curve backed by an N-entry forward and M-entry inverse LUT.
TicklessDeadline
A single output produced by the tickless scheduler.
TicklessIter
Iterator over successive TicklessDeadline values produced by a TicklessSchedule.
TicklessSchedule
A tickless schedule bound to a monotonic curve and segment parameters.

Enums§

RepeatMode
Repeat behaviour for a tickless schedule.
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.

Functions§

lerp_u8
Linearly interpolate between a and b with a u8 blend weight.
lerp_u16
Linearly interpolate between two u16 values with a u8 blend weight.
map_u8_to_u16
Scale a normalized u8 value (0..=255) into a u16 range 0..=max.
next_target_value
Return the next quantized target value one step closer to end.
quantize
Snap value to the nearest multiple of step according to rounding.

Type Aliases§

CurveLut256
A 256-entry curve lookup table (u8 domain and range).
CurveLut65536
A 65536-entry curve lookup table (u16 domain and range).
MonotonicCurveLut256
A 256-entry monotonic curve lookup table (u8 domain and range).
MonotonicCurveLut65536
A 65536-entry monotonic curve lookup table (u16 domain and range).