Expand description
lib8tion — fast 8-/16-bit fixed-point math for no_std embedded targets.
This is a Rust port of the math primitives from
FastLED’s lib8tion:
saturating/wrapping byte arithmetic, scaling & dimming, fast trigonometric
approximations, a small fast PRNG, integer range mapping and simple
fixed-point types. All functions are pure integer math with defined
overflow behavior (saturating, wrapping or truncating, matching the
semantics of the original C implementation) — nothing here panics or
allocates.
Re-exports§
pub use fixed_point::Q44;pub use fixed_point::Q62;pub use fixed_point::Q88;pub use fixed_point::Q124;pub use fixed_point::Qfx;pub use intmap::IntScale;pub use intmap::int_scale;pub use random::RangeSample;pub use random::Rng16;pub use beat::*;pub use ease::*;pub use lerp::*;pub use math8::*;pub use scale8::*;pub use trig8::*;
Modules§
- beat
- Beat generators — phase/value oscillators driven by a millisecond clock, the building block FastLED animations use to “pulse” or “wave” values at a given tempo (BPM).
- ease
- Easing curves and waveform generators — turning a linearly increasing counter into a value that accelerates and decelerates smoothly, the way a physical object would when starting and stopping.
- fixed_
point Qfx<F>— a small fixed-point “scale factor” type for multiplying integers by a non-integer ratio without floating point.- intmap
- Generic integer range mapping: rescale a value from one integer width to another while preserving its relative position in the range (e.g. “50% of an 8-bit range” maps to “50% of a 16-bit range”).
- lerp
- Fast linear interpolation (“lerp”) between two integer values, the
building block for things like Perlin noise, color blending, and smooth
parameter sweeps.
crate::math8::blend8is essentiallylerp8by8for color channels; these are the general-purpose primitives it (and you) can build on. - math8
- Fast 8-/16-bit integer arithmetic: saturating & wrapping add/sub, averages, multiplication, blending, modulo and integer square roots.
- random
- A small, fast, not cryptographically secure pseudo-random number generator, suitable for visually-random LED animation — significantly cheaper than a “real” PRNG.
- scale8
- Fast 8-/16-/32-bit scaling, video-safe scaling, and gamma-ish dimming / brightening curves.
- trig8
- Fast 8-/16-bit approximations of
sin/cos, using small lookup tables plus linear interpolation rather than a full trig implementation.
Structs§
- Accum88
- 8.8 fixed-point accumulator: high byte is the integer part, low byte
is the fractional part — e.g. a BPM of
120.5isAccum88((120 << 8) | 128). The formatbeat88/beatsin88expect their tempo in. - Fract8
- 8-bit fixed-point fraction in the range
0/256 ..= 255/256, stored as a numerator over 256. The scale-factor type forscale8(),lerp8by8and friends — build one withFract8(n)/Fract8::new, orn.into(). - Fract16
- 16-bit fixed-point fraction in the range
0/65536 ..= 65535/65536, stored as a numerator over 65536. The scale-factor type forscale16,lerp16by16and friends. - SFract8
- Signed 8-bit fixed-point fraction in the range
-1.0 ..= 1.0, stored as a numerator over 128.