Ryan Malloy f218cd468b Add GPS, IMU, and barometer sensor suite to BLE bridge firmware
RYS352A GPS on UART2 (GPIO5/6) with PPS interrupt (GPIO7),
MPU-9250 IMU and BMP388 barometer on shared I2C bus (GPIO8/9).
Sensor data exposed via dedicated BLE service with binary
notify characteristics alongside the existing NUS serial bridge.
Sensors degrade gracefully if not wired.
2026-02-11 15:47:20 -07:00

68 lines
2.3 KiB
C

#pragma once
// --- GPIO Pin Assignments ---
// UART1 to RS-422 module via 3.3V<->5V level shifter
#define PIN_RS422_TX 17 // ESP32 TX -> level shifter -> MAX485₁ DI
#define PIN_RS422_RX 18 // MAX485₂ RO -> level shifter -> ESP32 RX
// GPS UART (UART2) — RYS352A
#define PIN_GPS_RX 5 // ESP32 RX <- GPS TX (NMEA out)
#define PIN_GPS_TX 6 // ESP32 TX -> GPS RX (config in, optional)
#define PIN_GPS_PPS 7 // 1Hz PPS rising edge (interrupt)
#define GPS_BAUD 9600
// I2C Sensor Bus
#define PIN_I2C_SDA 8
#define PIN_I2C_SCL 9
#define I2C_FREQ 400000 // 400kHz
// Sensor I2C addresses
#define MPU9250_ADDR 0x68
#define BMP388_ADDR 0x76
// Onboard RGB LED (WS2812, DevKitC-1 V1.1)
#define PIN_LED 38
// --- RS-422 UART (UART1) ---
#define RS422_BAUD 115200
#define RS422_CONFIG SERIAL_8N1
// --- BLE Configuration ---
#define BLE_DEVICE_NAME "Travler-G2"
#define BLE_MTU 517
// Max payload per NUS notification (must fit in ATT_MTU - 3)
#define BLE_NOTIFY_MAX 240
// Nordic UART Service UUIDs
#define NUS_SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define NUS_RX_UUID "6E400002-B5A3-F393-E0A9-E50E24DCCA9E" // Client writes here
#define NUS_TX_UUID "6E400003-B5A3-F393-E0A9-E50E24DCCA9E" // ESP32 notifies here
// Sensor Service UUIDs (custom, A0E7xxxx block)
#define SENSOR_SERVICE_UUID "A0E70001-B5A3-F393-E0A9-E50E24DCCA9E"
#define SENSOR_GPS_UUID "A0E70002-B5A3-F393-E0A9-E50E24DCCA9E"
#define SENSOR_ORIENT_UUID "A0E70003-B5A3-F393-E0A9-E50E24DCCA9E"
#define SENSOR_ENV_UUID "A0E70004-B5A3-F393-E0A9-E50E24DCCA9E"
#define SENSOR_PPS_UUID "A0E70005-B5A3-F393-E0A9-E50E24DCCA9E"
// --- Timing ---
// Inter-byte coalescing window: collect bytes arriving within this
// gap into one BLE notification instead of sending byte-by-byte
#define COALESCE_MS 3
// LED refresh interval
#define LED_UPDATE_MS 50
// Sensor read/report intervals
#define GPS_REPORT_MS 1000 // 1Hz GPS position reports
#define IMU_REPORT_MS 100 // 10Hz orientation updates
#define BARO_REPORT_MS 1000 // 1Hz pressure/temperature
#define STATUS_PRINT_MS 1000 // 1Hz USB serial status line
// --- LED ---
#define LED_BRIGHTNESS 30 // 0-255, keep low to avoid blinding in enclosure
#define LED_COUNT 1
// --- Buffers ---
#define UART_RX_BUF_SIZE 512