[Xiao_nrf52]
extends = rak4631_hw
board = seeed-xiao-afruitnrf52-nrf52840
board_build.ldscript = boards/nrf52840_s140_v7.ld
build_flags = ${rak4631_hw.build_flags}
  ${sensor_base.build_flags}
  -I lib/nrf52/s140_nrf52_7.3.0_API/include
  -I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52
  -I variants/xiao_nrf52
  -UENV_INCLUDE_GPS
  -D NRF52_PLATFORM
;  -D NRF52_POWER_MANAGEMENT
  -D XIAO_NRF52
  -D USE_SX1262
  -D RADIO_CLASS=CustomSX1262
  -D WRAPPER_CLASS=CustomSX1262Wrapper
  -D LORA_TX_POWER=22
  -D P_LORA_TX_LED=11
  -D P_LORA_DIO_1=D1
  -D P_LORA_RESET=D2
  -D P_LORA_BUSY=D3
  -D P_LORA_NSS=D4
  -D SX126X_RXEN=D5
  -D SX126X_TXEN=RADIOLIB_NC
  -D SX126X_DIO2_AS_RF_SWITCH=1
  -D SX126X_DIO3_TCXO_VOLTAGE=1.8
  -D SX126X_CURRENT_LIMIT=140
  -D SX126X_RX_BOOSTED_GAIN=1
  ; D6/D7 are also Serial1 TX/RX.  Auto-probing I2C there can hold the UART
  ; peripheral in a bad state and prevent boot/BLE startup.  Use the dedicated
  ; NFC pads for I2C on every XIAO nRF52 build.
  -D PIN_WIRE_SCL=PIN_NFC1
  -D PIN_WIRE_SDA=PIN_NFC2
  -D PIN_USER_BTN=PIN_BUTTON1
  -D DISPLAY_CLASS=NullDisplayDriver
build_src_filter = ${rak4631_hw.build_src_filter}
  +<helpers/*.cpp>
  +<helpers/sensors>
  +<../variants/xiao_nrf52>
  +<helpers/ui/MomentaryButton.cpp>
  +<helpers/ui/NullDisplayDriver.cpp>
debug_tool = jlink
upload_protocol = nrfutil
lib_deps = ${rak4631_hw.lib_deps}
  ${sensor_base.lib_deps}

[env:Xiao_nrf52_companion_radio_ble]
extends = Xiao_nrf52
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags =
  ${Xiao_nrf52.build_flags}
  -I examples/companion_radio/ui-orig
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
  -D BLE_PIN_CODE=123456
  -D OFFLINE_QUEUE_SIZE=256
;  -D BLE_DEBUG_LOGGING=1
;  -D MESH_PACKET_LOGGING=1
  -D MESH_DEBUG=1
  -D QSPIFLASH=1
build_src_filter = ${Xiao_nrf52.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-orig/*.cpp>
lib_deps =
  ${Xiao_nrf52.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:Xiao_nrf52_companion_radio_usb]
extends = Xiao_nrf52
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags =
  ${Xiao_nrf52.build_flags}
  -I examples/companion_radio/ui-orig
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
  -D OFFLINE_QUEUE_SIZE=256
  -D QSPIFLASH=1
;  -D MESH_PACKET_LOGGING=1
;  -D MESH_DEBUG=1
build_src_filter = ${Xiao_nrf52.build_src_filter}
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-orig/*.cpp>
lib_deps =
  ${Xiao_nrf52.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:Xiao_nrf52_repeater]
extends = Xiao_nrf52
build_flags =
  ${Xiao_nrf52.build_flags}
  -D ADVERT_NAME='"Xiao_nrf52 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
build_src_filter = ${Xiao_nrf52.build_src_filter}
  +<../examples/simple_repeater/*.cpp>

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

[env:Xiao_nrf52_kiss_modem]
extends = Xiao_nrf52
build_flags =
  ${Xiao_nrf52.build_flags}
build_src_filter = ${Xiao_nrf52.build_src_filter}
  +<../examples/kiss_modem/*.cpp>
lib_deps =
  ${Xiao_nrf52.lib_deps}

; =============================================================================
; SolarXiao (wehooper4) boards
; Same Xiao nRF52840 module.  I2C is already on the NFC pads in the base target;
; these solar builds additionally skip the RTC probe.
; 30S = standard SX1262 (22 dBm), 33S = 2W PA variant (9 dBm limit)
; =============================================================================

[solarxiao]
extends = Xiao_nrf52
build_flags = ${Xiao_nrf52.build_flags}
  -D DISABLE_I2C_RTC_SCAN

[env:solarxiao_30S_companion_radio_ble]
extends = solarxiao
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags =
  ${solarxiao.build_flags}
  -I examples/companion_radio/ui-orig
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
  -D BLE_PIN_CODE=123456
  -D OFFLINE_QUEUE_SIZE=256
  -D QSPIFLASH=1
build_src_filter = ${solarxiao.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-orig/*.cpp>
lib_deps =
  ${solarxiao.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:solarxiao_33S_companion_radio_ble]
extends = env:solarxiao_30S_companion_radio_ble
build_unflags =
  -D LORA_TX_POWER=22
build_flags =
  ${env:solarxiao_30S_companion_radio_ble.build_flags}
  -D LORA_TX_POWER=9

[env:solarxiao_30S_companion_radio_usb]
extends = solarxiao
board_build.ldscript = boards/nrf52840_s140_v7_extrafs.ld
board_upload.maximum_size = 708608
build_flags =
  ${solarxiao.build_flags}
  -I examples/companion_radio/ui-orig
  -D MAX_CONTACTS=350
  -D MAX_GROUP_CHANNELS=40
  -D QSPIFLASH=1
build_src_filter = ${solarxiao.build_src_filter}
  +<helpers/nrf52/SerialBLEInterface.cpp>
  +<../examples/companion_radio/*.cpp>
  +<../examples/companion_radio/ui-orig/*.cpp>
lib_deps =
  ${solarxiao.lib_deps}
  densaugeo/base64 @ ~1.4.0

[env:solarxiao_33S_companion_radio_usb]
extends = env:solarxiao_30S_companion_radio_usb
build_unflags =
  -D LORA_TX_POWER=22
build_flags =
  ${env:solarxiao_30S_companion_radio_usb.build_flags}
  -D LORA_TX_POWER=9

[env:solarxiao_30S_repeater]
extends = solarxiao
build_flags =
  ${solarxiao.build_flags}
  -D ADVERT_NAME='"SolarXiao 30S Repeater"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
  -D MAX_NEIGHBOURS=50
build_src_filter = ${solarxiao.build_src_filter}
  +<../examples/simple_repeater/*.cpp>

[env:solarxiao_33S_repeater]
extends = env:solarxiao_30S_repeater
build_unflags =
  -D LORA_TX_POWER=22
  -D ADVERT_NAME='"SolarXiao 30S Repeater"'
build_flags =
  ${env:solarxiao_30S_repeater.build_flags}
  -D LORA_TX_POWER=9
  -D ADVERT_NAME='"SolarXiao 33S Repeater"'

[env:solarxiao_30S_repeater_bridge_rs232]
extends = env:solarxiao_30S_repeater
build_unflags =
  -D ADVERT_NAME='"SolarXiao 30S Repeater"'
build_flags =
  ${env:solarxiao_30S_repeater.build_flags}
  -D ADVERT_NAME='"SolarXiao 30S RS232"'
  -D WITH_RS232_BRIDGE=Serial1
  -D WITH_RS232_BRIDGE_RX=PIN_SERIAL1_RX
  -D WITH_RS232_BRIDGE_TX=PIN_SERIAL1_TX
  -D BRIDGE_MAX_BAUD=500000
build_src_filter = ${env:solarxiao_30S_repeater.build_src_filter}
  +<helpers/bridges/RS232Bridge.cpp>

[env:solarxiao_33S_repeater_bridge_rs232]
extends = env:solarxiao_30S_repeater_bridge_rs232
build_unflags =
  -D LORA_TX_POWER=22
  -D ADVERT_NAME='"SolarXiao 30S Repeater"'
  -D ADVERT_NAME='"SolarXiao 30S RS232"'
build_flags =
  ${env:solarxiao_30S_repeater_bridge_rs232.build_flags}
  -D LORA_TX_POWER=9
  -D ADVERT_NAME='"SolarXiao 33S RS232"'

[env:solarxiao_30S_room_server]
extends = solarxiao
build_flags =
  ${solarxiao.build_flags}
  -D ADVERT_NAME='"SolarXiao 30S Room"'
  -D ADVERT_LAT=0.0
  -D ADVERT_LON=0.0
  -D ADMIN_PASSWORD='"password"'
build_src_filter = ${solarxiao.build_src_filter}
  +<../examples/simple_room_server/*.cpp>

[env:solarxiao_33S_room_server]
extends = env:solarxiao_30S_room_server
build_unflags =
  -D LORA_TX_POWER=22
  -D ADVERT_NAME='"SolarXiao 30S Room"'
build_flags =
  ${env:solarxiao_30S_room_server.build_flags}
  -D LORA_TX_POWER=9
  -D ADVERT_NAME='"SolarXiao 33S Room"'

[env:solarxiao_30S_kiss_modem]
extends = solarxiao
build_flags =
  ${solarxiao.build_flags}
build_src_filter = ${solarxiao.build_src_filter}
  +<../examples/kiss_modem/*.cpp>
lib_deps =
  ${solarxiao.lib_deps}

[env:solarxiao_33S_kiss_modem]
extends = env:solarxiao_30S_kiss_modem
build_unflags =
  -D LORA_TX_POWER=22
build_flags =
  ${env:solarxiao_30S_kiss_modem.build_flags}
  -D LORA_TX_POWER=9
