Ryan Malloy 068f38d7eb Add ESP32-S3 BLE-to-RS422 bridge firmware for Carryout G2
NimBLE-based Nordic UART Service (NUS) bridge on ESP32-S3-DevKitC-1.
Transparent passthrough: BLE client writes → UART1 TX → RS-422 → G2,
and G2 → RS-422 → UART1 RX → BLE notifications. USB serial serves as
debug monitor and fallback input.

Uses two MAX485 modules (one locked TX, one locked RX) with a SparkFun
BSS138 level converter for 3.3V/5V translation. Wiring schematic and
RJ-12 pinout documented in docs/ble-bridge-wiring.md.
2026-02-11 14:33:10 -07:00

40 lines
1.2 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 -> MAX490 RXD
#define PIN_RS422_RX 18 // MAX490 TXD -> level shifter -> ESP32 RX
// 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
// --- 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
// --- 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