- New baro module (include/baro.h, src/baro.c): reads BME280/BMP280
at 1 Hz on I2C1, computes pressure altitude (ISA formula), publishes
JLINK_TLM_BARO (0x8D) telemetry to Orin. Runs entirely on Mamba F722S
with no Orin dependency. baro_get_alt_cm() exposes altitude to balance
PID slope compensation.
- New JLink telemetry frame 0x8D (jlink_tlm_baro_t, 12 bytes packed):
pressure_pa (int32), temp_x10 (int16), alt_cm (int32),
humidity_pct_x10 (int16; -1 = BMP280/absent).
- Wire into main.c: baro_init() after bmp280_init(), baro_tick(now)
each ms (self-rate-limits to 1 Hz).
- Unit tests (test/test_baro.c): 31 tests, all pass. Build:
gcc -I include -I test/stubs -DTEST_HOST -lm -o /tmp/test_baro test/test_baro.c
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
67 lines
2.3 KiB
C
67 lines
2.3 KiB
C
#ifndef BARO_H
|
||
#define BARO_H
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
|
||
/*
|
||
* baro — BME280/BMP280 barometric pressure & ambient temperature module
|
||
* (Issue #672).
|
||
*
|
||
* Reads pressure and temperature from the BME280 at BARO_READ_HZ (1 Hz),
|
||
* computes pressure altitude using the ISA barometric formula, and publishes
|
||
* JLINK_TLM_BARO (0x8D) telemetry to the Orin at BARO_TLM_HZ (1 Hz).
|
||
*
|
||
* Runs entirely on the Mamba F722S — no Orin dependency.
|
||
* Altitude is exposed via baro_get_alt_cm() for use by slope compensation
|
||
* in the balance PID (Issue #672 requirement).
|
||
*
|
||
* Usage:
|
||
* 1. Call i2c1_init() then bmp280_init() and pass the chip_id result.
|
||
* 2. Call baro_tick(now_ms) every ms from the main loop.
|
||
* 3. Call baro_get_alt_cm() to read the latest altitude.
|
||
*/
|
||
|
||
/* ---- Configuration ---- */
|
||
#define BARO_READ_HZ 1u /* sensor poll rate (Hz) */
|
||
#define BARO_TLM_HZ 1u /* JLink telemetry rate (Hz) */
|
||
|
||
/* ---- Data ---- */
|
||
typedef struct {
|
||
int32_t pressure_pa; /* barometric pressure (Pa) */
|
||
int16_t temp_x10; /* ambient temperature (°C × 10; e.g. 235 = 23.5 °C) */
|
||
int32_t alt_cm; /* pressure altitude above ISA sea level (cm) */
|
||
int16_t humidity_pct_x10; /* %RH × 10 (BME280 only); -1 if BMP280/absent */
|
||
bool valid; /* true once at least one reading has been obtained */
|
||
} baro_data_t;
|
||
|
||
/* ---- API ---- */
|
||
|
||
/*
|
||
* baro_init(chip_id) — register chip type from bmp280_init() result.
|
||
* chip_id : 0x58 = BMP280, 0x60 = BME280, 0 = absent/not found.
|
||
* Call after i2c1_init() and bmp280_init(); no-op if chip_id == 0.
|
||
*/
|
||
void baro_init(int chip_id);
|
||
|
||
/*
|
||
* baro_tick(now_ms) — rate-limited sensor read + JLink telemetry publish.
|
||
* Call every ms from the main loop. No-op if chip absent.
|
||
* Reads at BARO_READ_HZ; sends JLINK_TLM_BARO at BARO_TLM_HZ.
|
||
*/
|
||
void baro_tick(uint32_t now_ms);
|
||
|
||
/*
|
||
* baro_get(out) — copy latest baro data into *out.
|
||
* Returns true on success; false if no valid reading yet.
|
||
*/
|
||
bool baro_get(baro_data_t *out);
|
||
|
||
/*
|
||
* baro_get_alt_cm() — latest pressure altitude (cm above ISA sea level).
|
||
* Returns 0 if no valid reading. Used by slope compensation in balance PID.
|
||
*/
|
||
int32_t baro_get_alt_cm(void);
|
||
|
||
#endif /* BARO_H */
|