[Heltec_t096]
; nRF52840 (same SoftDevice S140 v6 + flash geometry as the RAK4631), so it reuses the shared
; rak4631_hw OTA recipe (ENABLE_OTA + OtaFlashLayout_nrf52.h). With the OTAFIX bootloader (oltaco
; PR #42 adds the T096 board) it can apply in place; without it the node still discovers/relays/serves
; OTA and just fetch-refuses apply (graceful) — a T096 is a valuable OTA relay/seeder either way.
extends = rak4631_hw
board = heltec_t096
board_build.ldscript = boards/nrf52840_s140_v6.ld
build_flags = ${rak4631_hw.build_flags}
  ${sensor_base.build_flags}
  -D MOTA_HW_ID='"Heltec_t096"'   ; OTA hardware tag (apply refuses a .mota built for other hardware)
  -I lib/nrf52/s140_nrf52_6.1.1_API/include
  -I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
  -I variants/heltec_t096
  -I src/helpers/ui
  -D HELTEC_T096
;  -D NRF52_POWER_MANAGEMENT
  -D P_LORA_DIO_1=21
  -D P_LORA_NSS=5
  -D P_LORA_RESET=16
  -D P_LORA_BUSY=19
  -D P_LORA_SCLK=40
  -D P_LORA_MISO=14
  -D P_LORA_MOSI=11
  -D P_LORA_TX_LED=28
  -D P_LORA_PA_POWER=30  ;VFEM_Ctrl -LDO power enable
  -D P_LORA_KCT8103L_PA_CSD=12
  -D P_LORA_KCT8103L_PA_CTX=41
  -D LORA_TX_POWER=9      ; 9dBm + ~13dB KCT8103L gain = ~22dBm output
  -D MAX_LORA_TX_POWER=22 ; Max SX1262 output -> ~28dBm at antenna
  -D RADIO_CLASS=CustomSX1262
  -D WRAPPER_CLASS=CustomSX1262Wrapper
  -D SX126X_DIO2_AS_RF_SWITCH=true
  -D SX126X_DIO3_TCXO_VOLTAGE=1.8
  -D SX126X_CURRENT_LIMIT=140
  -D SX126X_RX_BOOSTED_GAIN=1
  -D PIN_VEXT_EN=26   ; Vext is connected to VDD which is also connected to TFT & GPS
  -D PIN_VEXT_EN_ACTIVE=HIGH
  -D PIN_GPS_RX=25
  -D PIN_GPS_TX=23
  -D PIN_GPS_EN=GPS_EN
  -D PIN_GPS_EN_ACTIVE=LOW
  -D PIN_GPS_RESET=GPS_RESET
  -D PIN_GPS_RESET_ACTIVE=LOW
  -D GPS_BAUD_RATE=115200
  -D PIN_VBAT_READ=BATTERY_PIN
  -D PIN_BAT_CTL=47
  -D DISPLAY_CLASS=ST7735Display
  -D DISPLAY_ROTATION=1
build_src_filter = ${rak4631_hw.build_src_filter}
  +<helpers/*.cpp>
  +<helpers/sensors>
  +<../variants/heltec_t096>
  +<helpers/ui/ST7735Display.cpp>
  +<helpers/ui/MomentaryButton.cpp>
lib_deps =
  ${rak4631_hw.lib_deps}
  ${sensor_base.lib_deps}
  bodmer/TFT_eSPI @ ^2.4.31
debug_tool = jlink
upload_protocol = nrfutil

[env:Heltec_t096_repeater]
extends = Heltec_t096
build_src_filter = ${Heltec_t096.build_src_filter}
  +<../examples/simple_repeater>

build_flags =
  ${Heltec_t096.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Full external-sensor build exceeds the in-place OTA ceiling
  -D ADVERT_NAME='"Heltec_t096 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

; Explicit lean alternative to the full-sensor, non-OTA repeater above.
[env:Heltec_t096_repeater_lora_ota_no_external_sensors]
extends = Heltec_t096
build_src_filter = ${Heltec_t096.build_src_filter}
  +<../examples/simple_repeater>
build_flags =
  ${Heltec_t096.build_flags}
  ${nrf52_no_external_sensors.build_flags}
  -D ADVERT_NAME='"Heltec_t096 Repeater"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
lib_deps =
  ${nrf52_lora_ota.lib_deps}
  bodmer/TFT_eSPI @ ^2.4.31

[env:Heltec_t096_repeater_bridge_rs232]
extends = Heltec_t096
build_flags =
  ${Heltec_t096.build_flags}
  -UENABLE_OTA
  -D DISABLE_LORA_OTA=1                  ; Full external-sensor build exceeds the in-place OTA ceiling
  -D ADVERT_NAME='"RS232 Bridge"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
  -D WITH_RS232_BRIDGE=Serial2
  -D WITH_RS232_BRIDGE_RX=9
  -D WITH_RS232_BRIDGE_TX=10
;  -D BRIDGE_DEBUG=1
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${Heltec_t096.build_src_filter}
  +<helpers/bridges/RS232Bridge.cpp>
  +<../examples/simple_repeater>

; Explicit lean alternative to the full-sensor, non-OTA RS232 bridge above.
[env:Heltec_t096_repeater_bridge_rs232_lora_ota_no_external_sensors]
extends = Heltec_t096
build_flags =
  ${Heltec_t096.build_flags}
  ${nrf52_no_external_sensors.build_flags}
  -D ADVERT_NAME='"RS232 Bridge"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
  -D WITH_RS232_BRIDGE=Serial2
  -D WITH_RS232_BRIDGE_RX=9
  -D WITH_RS232_BRIDGE_TX=10
build_src_filter = ${Heltec_t096.build_src_filter}
  +<helpers/bridges/RS232Bridge.cpp>
  +<../examples/simple_repeater>
lib_deps =
  ${nrf52_lora_ota.lib_deps}
  bodmer/TFT_eSPI @ ^2.4.31

[env:Heltec_t096_room_server]
extends = Heltec_t096
build_src_filter = ${Heltec_t096.build_src_filter}
  +<../examples/simple_room_server>
build_flags =
  ${Heltec_t096.build_flags}
  -D ADVERT_NAME='"Heltec_t096 Room"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D ROOM_PASSWORD='"hello"'
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1

[env:Heltec_t096_sensor]
extends = Heltec_t096
build_flags =
  ${Heltec_t096.build_flags}
  -D ADVERT_NAME='"Heltec_t096 Sensor"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D ENV_PIN_SDA=PIN_WIRE1_SDA
  -D ENV_PIN_SCL=PIN_WIRE1_SCL
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${Heltec_t096.build_src_filter}
  +<../examples/simple_sensor>
lib_deps =
  ${Heltec_t096.lib_deps}

[env:Heltec_t096_companion_radio_ble_femon]
extends = Heltec_t096
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${Heltec_t096.build_flags}
  -I examples/companion_radio/ui-new
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
  -D BLE_PIN_CODE=123456
  -D ENV_INCLUDE_GPS=1   ; enable the GPS page in UI
;  -D BLE_DEBUG_LOGGING=1
  -D OFFLINE_QUEUE_SIZE=256
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${Heltec_t096.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
  ${Heltec_t096.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:Heltec_t096_companion_radio_ble_femoff]
extends = env:Heltec_t096_companion_radio_ble_femon
build_flags =
  ${env:Heltec_t096_companion_radio_ble_femon.build_flags}
  -D RADIO_FEM_RXGAIN=0 ; undefined (default on), 1=on, 0=off

[env:Heltec_t096_companion_radio_usb_femon]
extends = Heltec_t096
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
  ${Heltec_t096.build_flags}
  -I examples/companion_radio/ui-new
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
;  -D BLE_PIN_CODE=123456
;  -D BLE_DEBUG_LOGGING=1
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${Heltec_t096.build_src_filter}
  +<helpers/nrf52/*.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-new/*.cpp>
lib_deps =
  ${Heltec_t096.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:Heltec_t096_companion_radio_usb_femoff]
extends = env:Heltec_t096_companion_radio_usb_femon
build_flags =
  ${env:Heltec_t096_companion_radio_usb_femon.build_flags}
  -D RADIO_FEM_RXGAIN=0 ; undefined (default on), 1=on, 0=off

[env:Heltec_t096_kiss_modem]
extends = Heltec_t096
build_src_filter = ${Heltec_t096.build_src_filter}
  +<../examples/kiss_modem/>
