Files
qtalker---/firmware/esp32p4-sensor-node/main/bmp280.h
Indiana 6e627bae15 firmware: verify against actual target hardware, fix real conflicts
Researched the exact modules the user is building with and fixed three
concrete issues the earlier speculative firmware got wrong:

1. WiFi: confirmed the target board (Waveshare ESP32-P4-Module-DEV-KIT,
   chip ESP32-P4NRW32) bridges WiFi through an onboard ESP32-C6
   co-processor over a fixed 7-pin SDIO link (CLK18/CMD19/D0-14/D1-15/
   D2-16/D3-17/RESET54, cross-confirmed against Espressif's own
   esp-hosted-mcu docs). wifi_manager.c's esp_wifi_init()/esp_wifi_start()
   calls don't need to change — esp_wifi_remote/esp_hosted provide a
   drop-in-compatible API — but the component manifest (new
   main/idf_component.yml) and sdkconfig.defaults were missing entirely.

2. Real pin conflict: the presence sensor's original UART pins (17/18)
   directly collided with the SDIO CLK/D3 pins above — wiring it there
   would have broken WiFi, the sensor, or both. Moved to GPIO4/5.

3. Swapped placeholder parts for the user's actual hardware:
   - BME280 -> BMP280 (GY-BMP280 module): temp+pressure only, no humidity.
     Rewrote the driver rather than just renaming it — the old code would
     have read nonexistent humidity registers and reported garbage
     forever. 3.3V-only wiring note added (the BME280 assumption of
     5V-tolerant logic doesn't hold for this specific breakout).
   - LD2410 -> RD-03E (Ai-Thinker, not Hi-Link — a different manufacturer
     with a different, incompatible UART protocol). Rewrote the frame
     parser against the RD-03E's actual (if less-documented) 5-byte
     simple-report format. Reports numeric distance instead of a boolean,
     which better fits both the hardware's actual output and the backend's
     statistical anomaly detector.

README, CMakeLists.txt, and all cross-references updated to match.
2026-07-24 21:30:37 +00:00

64 lines
2.2 KiB
C

// Bosch BMP280 driver (temperature / pressure only) over I2C.
//
// Implements the sensor_driver_t interface (see sensor_driver.h) so the
// registry can init/read it generically. Register map and compensation
// formulas are transcribed from Bosch's public BMP280 datasheet (Rev 1.23,
// section 3.11.3 "Compensation formulas", double-precision reference
// implementation) — publicly documented, well-trodden territory, not
// guesswork. What IS unverified: this has never talked to a real BMP280 —
// see README.md's honesty-policy section.
//
// Confirmed against the actual part in use: a GY-BMP280 breakout module
// (Bosch BMP280 — temperature + pressure ONLY, no humidity; do not confuse
// with the BME280, which adds a humidity sensor on an otherwise near-
// identical register map). 3.3V logic only — the GY-BMP280 module is not
// 5V tolerant, unlike the LD2410-family modules elsewhere in this project.
//
// Default wiring (override via `idf.py menuconfig` or by editing the pin
// macros below before building) — see README.md's wiring section for the
// full pinout table:
// BMP280 SDA -> GPIO8 (BMP280_I2C_SDA_GPIO)
// BMP280 SCL -> GPIO9 (BMP280_I2C_SCL_GPIO)
// BMP280 VCC -> 3V3, GND -> GND (3.3V ONLY — see above)
// BMP280 CSB -> VCC (selects I2C mode, not SPI)
// BMP280 SDO -> GND selects address 0x76 (default assumed here); tie SDO
// to VCC instead for address 0x77 and change
// BMP280_I2C_ADDR accordingly.
#pragma once
#include "esp_err.h"
#include "sensor_driver.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef BMP280_I2C_PORT
#define BMP280_I2C_PORT 0
#endif
#ifndef BMP280_I2C_SDA_GPIO
#define BMP280_I2C_SDA_GPIO 8
#endif
#ifndef BMP280_I2C_SCL_GPIO
#define BMP280_I2C_SCL_GPIO 9
#endif
#ifndef BMP280_I2C_ADDR
#define BMP280_I2C_ADDR 0x76 // 0x77 if SDO is tied to VCC instead of GND
#endif
#ifndef BMP280_I2C_CLK_HZ
#define BMP280_I2C_CLK_HZ 100000 // 100kHz standard mode; BMP280 supports up to 3.4MHz
#endif
// sensor_driver_t-compatible entry points.
esp_err_t bmp280_init(void);
esp_err_t bmp280_read(sensor_reading_t *out, size_t max_out, size_t *out_count);
#ifdef __cplusplus
}
#endif