|
PER Firmware
|
Header-only helpers for embedded C. All macros are type-safe (_Generic dispatched) and force-inlined when applicable. Include them directly:
max.h / min.hInline functions to compute the maximum or minimum of 2, 3, or 4 ints or floats.
abs.hABS(x) returns the absolute value of an int or float.
clamp.hCLAMP(input, lower, upper) saturates a value into [lower, upper]. Works on int, unsigned int, long, unsigned long, and float.
rescale.hRESCALE(input, in_min, in_max, out_min, out_max) linearly maps a value from one range to another. Returns out_min if the input range is zero (no div-by-zero).
countof.hcountof(array) returns the number of elements in a stack/global array. Passing a pointer is rejected at compile time.
units.hTiny typed wrappers around physical units. Each unit is a struct holding a single float, so they cost nothing at runtime but stop you from accidentally mixing, e.g., feet with meters.
Available unit families: temperature (C/F), distance (m/cm/mm/in/ft/mi), time (ms/s/min/hr/day), angle (rad/deg), mass (g/kg/lb), pressure (Pa/psi/bar), velocity (mps/kph/mph).
linear_algebra.hFloat-only vector3_t / matrix3x3_t / euler_angles_t plus the basic operations needed for IMU/orientation work: magnitude, normalize, matrix-vector and matrix-matrix multiply, and a Tait-Bryan ZYX Euler-to-rotation-matrix helper.