Header-only helpers for embedded C. All macros are type-safe (_Generic dispatched) and force-inlined when applicable. Include them directly:
Utility header to clamp a value to a bounded range.
Maximum value functions utility header.
max.h / min.h
Inline functions to compute the maximum or minimum of 2, 3, or 4 ints or floats.
int a = 5, b = 3, c = 10, d = 7;
float x = 1.5f, y = 2.3f, z = 0.8f;
#define MAXOF(...)
Definition max.h:42
#define MINOF(...)
Definition min.h:42
abs.h
ABS(x) returns the absolute value of an int or float.
#define ABS(x)
Definition abs.h:24
clamp.h
CLAMP(input, lower, upper) saturates a value into [lower, upper]. Works on int, unsigned int, long, unsigned long, and float.
int duty =
CLAMP(raw_duty, 0, 100);
float throttle =
CLAMP(pedal_pos, 0.0f, 1.0f);
#define CLAMP(input, lower_bound, upper_bound)
Definition clamp.h:28
rescale.h
RESCALE(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).
float v =
RESCALE((
float)adc_counts, 0.0f, 4095.0f, 0.0f, 3.3f);
int deg =
RESCALE(counts, 0, 1023, -180, 180);
#define RESCALE(input, input_min, input_max, output_min, output_max)
Definition rescale.h:71
countof.h
countof(array) returns the number of elements in a stack/global array. Passing a pointer is rejected at compile time.
int rails[] = { RAIL_24V, RAIL_5V, RAIL_3V3 };
for (
size_t i = 0; i <
countof(rails); ++i) {
enable_rail(rails[i]);
}
#define countof(array)
Definition countof.h:19
units.h
Tiny 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).
UNIT_FUNC_MODIFIERS fahrenheit_t fahrenheit_from(celsius_t c)
Definition units.h:28
UNIT_FUNC_MODIFIERS radians_t radians_from(degrees_t deg)
Definition units.h:133
#define meters_from(x)
Definition units.h:77
#define seconds_from(x)
Definition units.h:118
linear_algebra.h
Float-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.
static vector3_t matrix_multiply_vector3(const matrix3x3_t *mat, const vector3_t *in)
Multiply a 3x3 matrix with a 3D vector.
Definition linear_algebra.h:61
static vector3_t vector3_normalize(const vector3_t vec)
Normalize a 3D vector.
Definition linear_algebra.h:41
static float vector3_magnitude(const vector3_t vec)
Calculate the magnitude of a 3D vector.
Definition linear_algebra.h:31
Definition orientation.h:9
Definition linear_algebra.h:21
Definition linear_algebra.h:15