Skip to content

File espos_sensor_math.h

File List > espos_sensors > include > espos_sensor_math.h

Go to the documentation of this file

/*
 * SPDX-FileCopyrightText: 2026 Dirk Wahrheit
 * SPDX-License-Identifier: Apache-2.0
 *
 * espos_sensor_math — the arithmetic of the sensor drivers, with no hardware
 * under it.
 *
 * These four functions are the only places in espos_sensors where a wrong
 * answer is silent: a counter that mis-handles its wrap reports a plausible
 * RPM, and an uncalibrated ADC conversion that is off by a factor reports a
 * plausible voltage. Everything else in the component either works or
 * returns an error.
 *
 * So they live here, pure and host-tested, rather than inline in the drivers
 * (see test/host/espos_sensors_test). The drivers call them.
 */
#pragma once

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

float espos_adc_counts_to_volts(int raw, float full_scale_v, int max_counts);

float espos_pulses_to_hz(uint32_t count, uint64_t interval_us);

uint32_t espos_counter_delta(int prev, int now, int limit);

float espos_hz_to_revolutions(float hz, int pulses_per_rev);

#ifdef __cplusplus
}
#endif