; =============================================================================
; LilyGo T-Echo Lite — Meck variant configuration
;
; nRF52840 + SX1262 + GxEPD2 1.22" e-ink (176×192, GDEM0122T61/SSD1681)
; + CardKB via QWIIC (0x5F) + optional L76K GPS
;
; Display: GxEPD2_122_T61 — full refresh only (~2s), no fast/partial refresh.
;          UI must minimise unnecessary redraws.
;          Scale factors: 1.5×/2.0× give ~117×96 virtual coordinate space.
;
; Platform: nRF52 (Adafruit nRF52 Arduino)
; Board JSON: boards/t-echo.json (nRF52840 PCA10056 compatible)
; =============================================================================

; --- Base configuration for all T-Echo Lite Meck builds (with display) ---
[lilygo_techo_lite_meck]
extends = nrf52_base
board = t-echo
board_build.ldscript = boards/nrf52840_s140_v6.ld
extra_scripts = pre:patch_nrf52_bsp.py
build_flags = ${nrf52_base.build_flags}
  -I variants/lilygo_techo_lite
  -I src/helpers/nrf52
  -I lib/nrf52/s140_nrf52_6.1.1_API/include
  -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
  -D LILYGO_TECHO
  -D LILYGO_TECHO_LITE
  -D RADIO_CLASS=CustomSX1262
  -D WRAPPER_CLASS=CustomSX1262Wrapper
  -D LORA_TX_POWER=22
  -D SX126X_POWER_EN=30
  -D SX126X_CURRENT_LIMIT=140
  -D SX126X_RX_BOOSTED_GAIN=1
  ; nRF52 compatibility — no PSRAM, no SD card, fallback GPS baud for CLI code paths
  -D ps_calloc=calloc
  -D ps_malloc=malloc
  -D GPS_BAUDRATE=9600
  -D SDCARD_CS=-1
  -D ROW_AUTO_LOCK=255
  ; Display — GxEPD2 1.22" e-ink (176×192, SSD1681)
  -D DISPLAY_CLASS=GxEPDDisplay
  -D EINK_DISPLAY_MODEL=GxEPD2_122_T61
  -D EINK_SCALE_X=1.5f
  -D EINK_SCALE_Y=2.0f
  -D EINK_X_OFFSET=6
  -D EINK_Y_OFFSET=1
  -D DISPLAY_ROTATION=4
  -D EINK_FULL_REFRESH_ONLY=1
  -D EINK_VIRTUAL_W=117
  -D EINK_VIRTUAL_H=88
  -D AUTO_OFF_MILLIS=0
build_src_filter = ${nrf52_base.build_src_filter}
  +<helpers/*.cpp>
  +<TechoBoard.cpp>
  +<helpers/sensors/EnvironmentSensorManager.cpp>
  +<helpers/ui/GxEPDDisplay.cpp>
  +<helpers/ui/MomentaryButton.cpp>
  +<../variants/lilygo_techo_lite>
lib_deps =
  ${nrf52_base.lib_deps}
  stevemarple/MicroNMEA @ ^2.0.6
  adafruit/Adafruit BME280 Library @ ^2.3.0
  https://github.com/SoulOfNoob/GxEPD2.git
  bakercp/CRC32 @ ^2.0.0
debug_tool = jlink
upload_protocol = nrfutil

; =============================================================================
; Build Environments
; =============================================================================

; --- BLE Companion Radio (no GPS) ---
; Pairs with MeshCore companion app over Bluetooth.
; CardKB provides on-device text input for standalone messaging.
; No GPS — time synced via BLE companion or serial CLI.
[env:meck_techo_lite_ble]
extends = lilygo_techo_lite_meck
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${lilygo_techo_lite_meck.build_flags}
  -I src/helpers/ui
  -I examples/companion_radio/ui-new
  -D MAX_CONTACTS=250
  -D MAX_GROUP_CHANNELS=8
  -D CHANNEL_MSG_HISTORY_SIZE=20
  -D BLE_PIN_CODE=123456
  ; -D BLE_DEBUG_LOGGING=1
  -D OFFLINE_QUEUE_SIZE=64
  -D MECK_CARDKB
  -D UI_SENSORS_PAGE=1
  ; -D MESH_PACKET_LOGGING=1
  ; -D MESH_DEBUG=1
  -D AUTO_SHUTDOWN_MILLIVOLTS=2800
build_src_filter = ${lilygo_techo_lite_meck.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
  ${lilygo_techo_lite_meck.lib_deps}
  densaugeo/base64 @ ~1.4.0

; --- Standalone Radio (no BLE, CardKB + display only) ---
; No companion app — device IS the terminal.
; USB serial for CLI configuration.
; Frees ~20-30KB BLE RAM → room for 500 contacts + larger message history.
[env:meck_techo_lite_standalone]
extends = lilygo_techo_lite_meck
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${lilygo_techo_lite_meck.build_flags}
  -I src/helpers/ui
  -I examples/companion_radio/ui-new
  -D MAX_CONTACTS=500
  -D MAX_GROUP_CHANNELS=8
  -D CHANNEL_MSG_HISTORY_SIZE=150
  -D OFFLINE_QUEUE_SIZE=1
  -D MECK_CARDKB
  -D UI_SENSORS_PAGE=1
  -D AUTO_SHUTDOWN_MILLIVOLTS=2800
build_src_filter = ${lilygo_techo_lite_meck.build_src_filter}
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
  ${lilygo_techo_lite_meck.lib_deps}
  densaugeo/base64 @ ~1.4.0

; --- BLE Companion Radio (with GPS) ---
; Same as above + L76K GPS for location and time sync.
; Requires external GPS module connected to UART1 (TX=P0.29, RX=P1.10).
[env:meck_techo_lite_gps_ble]
extends = lilygo_techo_lite_meck
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${lilygo_techo_lite_meck.build_flags}
  -I src/helpers/ui
  -I examples/companion_radio/ui-new
  -D ENV_INCLUDE_GPS=1
  -D GPS_BAUD_RATE=9600
  -D PIN_GPS_EN=GPS_EN
  -D MAX_CONTACTS=250
  -D MAX_GROUP_CHANNELS=8
  -D CHANNEL_MSG_HISTORY_SIZE=20
  -D BLE_PIN_CODE=123456
  -D OFFLINE_QUEUE_SIZE=64
  -D MECK_CARDKB
  -D UI_RECENT_LIST_SIZE=9
  -D UI_SENSORS_PAGE=1
  -D AUTO_SHUTDOWN_MILLIVOLTS=2800
build_src_filter = ${lilygo_techo_lite_meck.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
  ${lilygo_techo_lite_meck.lib_deps}
  stevemarple/MicroNMEA @ ^2.0.6
  densaugeo/base64 @ ~1.4.0

; --- Repeater ---
; Standalone LoRa repeater node. E-ink shows status.
; CardKB not useful here but included by base for consistency.
[env:meck_techo_lite_repeater]
extends = lilygo_techo_lite_meck
build_src_filter = ${lilygo_techo_lite_meck.build_src_filter}
  +<../examples/simple_repeater>
build_flags =
  ${lilygo_techo_lite_meck.build_flags}
  -D ADVERT_NAME='"Meck T-Echo Lite Repeater"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1

; --- Room Server ---
; BBS-style message board node.
[env:meck_techo_lite_room_server]
extends = lilygo_techo_lite_meck
build_src_filter = ${lilygo_techo_lite_meck.build_src_filter}
  +<../examples/simple_room_server>
build_flags =
  ${lilygo_techo_lite_meck.build_flags}
  -D ADVERT_NAME='"Meck T-Echo Lite Room"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1

; =============================================================================
; Headless (no display) variants
; =============================================================================

; --- Headless base (no display, no GxEPD2) ---
[lilygo_techo_lite_meck_core]
extends = nrf52_base
board = t-echo
board_build.ldscript = boards/nrf52840_s140_v6.ld
build_flags = ${nrf52_base.build_flags}
  -I variants/lilygo_techo_lite
  -I src/helpers/nrf52
  -I lib/nrf52/s140_nrf52_6.1.1_API/include
  -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
  -D LILYGO_TECHO
  -D LILYGO_TECHO_LITE
  -D RADIO_CLASS=CustomSX1262
  -D WRAPPER_CLASS=CustomSX1262Wrapper
  -D LORA_TX_POWER=22
  -D SX126X_POWER_EN=30
  -D SX126X_CURRENT_LIMIT=140
  -D SX126X_RX_BOOSTED_GAIN=1
  ; nRF52 compatibility
  -D ps_calloc=calloc
  -D ps_malloc=malloc
  -D GPS_BAUDRATE=9600
  -D SDCARD_CS=-1
  -D ROW_AUTO_LOCK=255
  -D DISABLE_DIAGNOSTIC_OUTPUT
  -D AUTO_OFF_MILLIS=0
build_src_filter = ${nrf52_base.build_src_filter}
  +<helpers/*.cpp>
  +<TechoBoard.cpp>
  +<helpers/sensors/EnvironmentSensorManager.cpp>
  +<helpers/ui/MomentaryButton.cpp>
  +<../variants/lilygo_techo_lite>
lib_deps =
  ${nrf52_base.lib_deps}
  stevemarple/MicroNMEA @ ^2.0.6
  adafruit/Adafruit BME280 Library @ ^2.3.0
  bakercp/CRC32 @ ^2.0.0
debug_tool = jlink
upload_protocol = nrfutil

; --- Headless Repeater (no display — lowest power, outdoor deployment) ---
[env:meck_techo_lite_core_repeater]
extends = lilygo_techo_lite_meck_core
build_src_filter = ${lilygo_techo_lite_meck_core.build_src_filter}
  +<../examples/simple_repeater>
build_flags =
  ${lilygo_techo_lite_meck_core.build_flags}
  -D ADVERT_NAME='"Meck T-Echo Lite Core Repeater"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50

; --- Headless BLE Companion (no display — phone-only UI) ---
[env:meck_techo_lite_core_ble]
extends = lilygo_techo_lite_meck_core
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${lilygo_techo_lite_meck_core.build_flags}
  -D MAX_CONTACTS=250
  -D MAX_GROUP_CHANNELS=8
  -D CHANNEL_MSG_HISTORY_SIZE=20
  -D BLE_PIN_CODE=234567
  -D OFFLINE_QUEUE_SIZE=64
  -D AUTO_SHUTDOWN_MILLIVOLTS=2800
build_src_filter = ${lilygo_techo_lite_meck_core.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
lib_deps =
  ${lilygo_techo_lite_meck_core.lib_deps}
  densaugeo/base64 @ ~1.4.0