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.
- Curves —
Curve/MonotonicCurvetraits and the LUT-backedCurveLut/MonotonicCurveLuttypes. - Tickless scheduling —
Ticklessextension trait,TicklessSchedule, and theTicklessIteriterator. - Math helpers —
UnitValuetrait,lerp_u8,lerp_u16,map_u8_to_u16,quantize, andnext_target_value.
Structs§
- Curve
Lut - A curve backed by an
N-entry forward and optionalM-entry inverse LUT. - Monotonic
Curve Lut - A monotonic curve backed by an
N-entry forward andM-entry inverse LUT. - Tickless
Deadline - A single output produced by the tickless scheduler.
- Tickless
Iter - Iterator over successive
TicklessDeadlinevalues produced by aTicklessSchedule. - Tickless
Schedule - A tickless schedule bound to a monotonic curve and segment parameters.
Enums§
- Repeat
Mode - Repeat behaviour for a tickless schedule.
- Rounding
- Rounding policy used by
quantizeand the tickless scheduler.
Traits§
- Curve
- Curve evaluation trait.
- Monotonic
Curve - Trait for monotonic curves that can be inverted.
- Tickless
- Extension trait that adds tickless scheduling to any
MonotonicCurve<T, T>whereT: UnitValue. - Unit
Value - A normalized value type usable as a curve domain / range.
Functions§
- lerp_u8
- Linearly interpolate between
aandbwith au8blend weight. - lerp_
u16 - Linearly interpolate between two
u16values with au8blend weight. - map_
u8_ to_ u16 - Scale a normalized
u8value (0..=255) into au16range0..=max. - next_
target_ value - Return the next quantized target value one
stepcloser toend. - quantize
- Snap
valueto the nearest multiple ofstepaccording torounding.
Type Aliases§
- Curve
Lut256 - A 256-entry curve lookup table (u8 domain and range).
- Curve
Lut65536 - A 65536-entry curve lookup table (u16 domain and range).
- Monotonic
Curve Lut256 - A 256-entry monotonic curve lookup table (u8 domain and range).
- Monotonic
Curve Lut65536 - A 65536-entry monotonic curve lookup table (u16 domain and range).