Refactor to unified firmware architecture with modular configuration system

BREAKING CHANGE: Replace separate anchor/tag firmware with single configurable codebase

## Major Changes
- **Unified Firmware**: Single main.cpp replaces main_anchor.cpp and main_tag.cpp
- **Modular Config**: Organized configuration system in src/config/ directory
- **Dynamic Behavior**: Device behavior determined by build flags at compile time
- **Simplified Builds**: Reduced from 8+ environments to 3 core environments

## New Architecture
- src/main.cpp - Single firmware with config-driven behavior
- src/config/device_config.h - Device role detection and unified behavior
- src/config/anchor_config.h - Anchor-specific settings (positioning, communication)
- src/config/tag_config.h - Tag-specific settings (USB streaming, coordinate collection)
- src/config/positioning_config.h - Distributed positioning algorithm framework

## Build System Improvements
- Simplified platformio.ini (anchor/tag/debug environments)
- Support for custom device ID and network via PLATFORMIO_BUILD_FLAGS
- Same firmware for all devices, behavior configured at compile time
- Easy device configuration: set PLATFORMIO_BUILD_FLAGS=-DUWB_INDEX=5 -DNETWORK_ID=2000

## Technical Benefits
- Reduced code duplication from ~350 lines to unified ~200 lines
- Consistent behavior across device types
- Easier maintenance with single codebase
- Framework ready for distributed positioning algorithm implementation
- Modular configuration system for future algorithm expansion

## Positioning Framework Ready
- Anchor discovery protocol framework established
- Inter-anchor communication configuration ready
- Position calculation algorithm structure in place
- Coordinate storage and validation system configured
- Tag coordinate collection and USB streaming framework prepared

## Testing
-  Anchor build successful (325KB flash usage)
-  Tag build successful (325KB flash usage)
-  Custom device ID/network configuration working
-  UWB initialization sequence fixed for active networks
This commit is contained in:
martin 2025-08-21 21:24:38 +02:00
commit a2e404ec0f
11 changed files with 589 additions and 387 deletions

56
src/config/config.h Normal file
View file

@ -0,0 +1,56 @@
#ifndef CONFIG_H
#define CONFIG_H
// Hardware Pin Definitions for ESP32-S3
#define RESET_PIN 16
#define IO_RXD2 18
#define IO_TXD2 17
#define I2C_SDA 39
#define I2C_SCL 38
// UWB Configuration
#ifndef UWB_INDEX
#define UWB_INDEX 0
#endif
#ifndef NETWORK_ID
#define NETWORK_ID 1234
#endif
// System Configuration
#define MAX_DEVICES 10
#define MAX_ANCHORS 8
#define UWB_TAG_COUNT 64
// Timing Configuration
#define DISPLAY_UPDATE_INTERVAL 500
#define DEVICE_TIMEOUT 5000
#define SLEEP_DURATION 5000
// Display Configuration
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
// Serial Configuration
#define SERIAL_BAUD 115200
// Debug Configuration
#ifdef DEBUG_ENABLED
#define DEBUG_PRINT(x) Serial.print(x)
#define DEBUG_PRINTLN(x) Serial.println(x)
#define DEBUG_PRINTF(x, ...) Serial.printf(x, __VA_ARGS__)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)
#define DEBUG_PRINTF(x, ...)
#endif
// WiFi Configuration (optional)
#ifdef OTA_ENABLED
#define WIFI_SSID "YOUR_WIFI_SSID"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
#endif
#endif // CONFIG_H