; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = tbeam
;default_envs = tbeam0.7
;default_envs = heltec
;default_envs = tlora-v1
;default_envs = tlora-v2
;default_envs = lora-relay-v1 # nrf board
;default_envs = eink
;default_envs = linux # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here

[common]
; common is not currently used

; REQUIRED environment variables - if not set the specified default will be sued
; The following environment variables must be set in the shell if you'd like to override them.
; They are used in this ini file as systenv.VARNAME, so in your shell do export "VARNAME=fish"
; COUNTRY (default US), i.e. "export COUNTRY=EU865"
; HW_VERSION (default emptystring)

[env]

; note: APP_VERSION now comes from bin/version.json
extra_scripts = bin/platformio-custom.py 

; note: we add src to our include search path so that lmic_project_config can override
; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc
build_flags = -Wno-missing-field-initializers
  -Wno-format 
  -Isrc -Isrc/mesh -Isrc/gps -Ilib/nanopb/include -Wl,-Map,.pio/build/output.map 
  -DHW_VERSION_${sysenv.COUNTRY}
  -DHW_VERSION=${sysenv.HW_VERSION}
  -DUSE_THREAD_NAMES
  -DTINYGPSPLUS_OPTION_NO_CUSTOM_FIELDS

; leave this commented out to avoid breaking Windows
;upload_port = /dev/ttyUSB0
;monitor_port = /dev/ttyUSB0

;upload_port = /dev/cu.SLAB_USBtoUART
;monitor_port = /dev/cu.SLAB_USBtoUART

; the default is esptool
; upload_protocol = esp-prog

; monitor_speed = 115200
monitor_speed = 921600

# debug_tool = esp-prog
# debug_port = /dev/ttyACM0

debug_tool = jlink
;upload_protocol = jlink

; debug_tool = olimex-arm-usb-ocd-h
; upload_protocol = olimex-arm-usb-ocd-h

;debug_init_cmds =
;  monitor adapter_khz 10000

lib_deps =
  https://github.com/meshtastic/esp8266-oled-ssd1306.git#35d796226b853b0c0ff818b2f1aa3d35e7296a96 ; ESP8266_SSD1306 
  https://github.com/geeksville/OneButton.git ; OneButton library for non-blocking button debounce
  1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
  https://github.com/meshtastic/arduino-fsm.git#2f106146071fc7bc620e1e8d4b88dc4e0266ce39
  https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git#31015a55e630a2df77d9d714669c621a5bf355ad
  https://github.com/meshtastic/RadioLib.git#07de964e929238949035fb0d5887026a3058df1a
  https://github.com/meshtastic/TinyGPSPlus.git#9c1d584d2469523381e077b0b9c1bf868d6c0206
  https://github.com/meshtastic/AXP202X_Library.git#8404abb6d4b486748636bc6ad72d2a47baaf5460
  Wire ; explicitly needed here because the AXP202 library forgets to add it
  SPI
  https://github.com/geeksville/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3
  
; Common settings for conventional (non Portduino) Ardino targets
[arduino_base]

framework = arduino

lib_deps =
  ${env.lib_deps}

build_flags = ${env.build_flags} -Os

src_filter = ${env.src_filter} -<portduino/>

; Common settings for ESP targes, mixin with extends = esp32_base
[esp32_base]
extends = arduino_base
platform = espressif32
src_filter = 
  ${arduino_base.src_filter} -<nrf52/>
upload_speed = 921600
debug_init_break = tbreak setup
build_flags =
  ${arduino_base.build_flags} -Wall -Wextra -Isrc/esp32 -Isrc/esp32-mfix-esp32-psram-cache-issue -lnimble -std=c++11 
  -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
  -DAXP_DEBUG_PORT=Serial
lib_deps =
  ${arduino_base.lib_deps}
  https://github.com/meshtastic/esp32_https_server.git
  adafruit/DHT sensor library@^1.4.1
  adafruit/Adafruit Unified Sensor@^1.1.4
# Hmm - this doesn't work yet
# board_build.ldscript = linker/esp32.extram.bss.ld
lib_ignore = segger_rtt
platform_packages =
    framework-arduinoespressif32@https://github.com/meshtastic/arduino-esp32.git#352c8ea7cb73f10433ed139f34251979c470ad56

; customize the partition table
; http://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
board_build.partitions = partition-table.csv

; not needed included in ttgo-t-beam board file
; also to use PSRAM https://docs.platformio.org/en/latest/platforms/espressif32.html#external-ram-psram
;  -DBOARD_HAS_PSRAM
;  -mfix-esp32-psram-cache-issue

; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG

; The 1.0 release of the TBEAM board 
[env:tbeam]
extends = esp32_base
board = ttgo-t-beam
lib_deps =
  ${esp32_base.lib_deps}
build_flags = 
  ${esp32_base.build_flags} -D TBEAM_V10

; The original TBEAM board without the AXP power chip and a few other changes
; Note: I've heard reports this didn't work.  Disabled until someone with a 0.7 can test and debug.
[env:tbeam0.7]
extends = esp32_base
board = ttgo-t-beam
build_flags = 
  ${esp32_base.build_flags} -D TBEAM_V07

[env:heltec]
;build_type = debug ; to make it possible to step through our jtag debugger 
extends = esp32_base
board = heltec_wifi_lora_32_V2

[env:tlora-v1]
extends = esp32_base
board = ttgo-lora32-v1
build_flags = 
  ${esp32_base.build_flags} -D TLORA_V1

; note: the platformio definition for lora32-v2 seems stale, it is missing a pins_arduino.h file, therefore I don't think it works
[env:tlora-v2]
extends = esp32_base
board = ttgo-lora32-v1
build_flags = 
  ${esp32_base.build_flags} -D TLORA_V2

[env:tlora-v2-1-1.6]
extends = esp32_base
board = ttgo-lora32-v1
build_flags = 
  ${esp32_base.build_flags} -D TLORA_V2_1_16

; The Heltec Cubecell plus 
; IMPORTANT NOTE: This target doesn't yet work and probably won't ever work.  I'm keeping it around for now.
; For more details see my post in the forum.
[env:cubecellplus]
platform = https://github.com/HelTecAutomation/platform-asrmicro650x.git ; we use top-of-tree because stable version has too many bugs - asrmicro650x
board = cubecell_board_plus
; FIXME, bug in cubecell arduino - they are supposed to set ARDUINO
build_flags = ${arduino_base.build_flags} -DARDUINO=100 -Isrc/cubecell
src_filter = 
  ${arduino_base.src_filter} -<esp32/> -<nrf52/>
  
; Common settings for NRF52 based targets
[nrf52_base]
; Instead of the standard nordicnrf52 platform, we use our fork which has our added variant files
; platform = nordicnrf52
platform = https://github.com/meshtastic/platform-nordicnrf52.git#1a2639a6b0f79b5df66bea3e3089f0d5285fdc63
extends = arduino_base
debug_tool = jlink
build_type = debug ; I'm debugging with ICE a lot now
; note: liboberon provides the AES256 implementation for NRF52 (though not using the hardware acceleration of the NRF52840 - FIXME)
build_flags = 
  ${arduino_base.build_flags} -Wno-unused-variable 
  -Isrc/nrf52 
  -Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.7 
;-DCFG_DEBUG=3
src_filter = 
  ${arduino_base.src_filter} -<esp32/> -<nimble/> -<mesh/wifi/> -<mesh/http/> -<plugins/esp32>
lib_ignore =
  BluetoothOTA
monitor_port = /dev/ttyACM1

debug_extra_cmds =
  source gdbinit

; after programming the flash, reset the initial PC
; debug_load_cmds = load

; Set initial breakpoint (defaults to main)
debug_init_break =
;debug_init_break = tbreak loop
;debug_init_break = tbreak Reset_Handler

; The NRF52840-dk development board
; Note: By default no lora device is created for this build - it uses a simulated interface
[env:nrf52840dk]
extends = nrf52_base
board = nrf52840_dk

; The NRF52840-dk development board, but @geeksville's board - which has a busted oscilliator 
[env:nrf52840dk-geeksville]
extends = nrf52_base
board = nrf52840_dk_modified
# add our variants files to the include and src paths
build_flags = ${nrf52_base.build_flags} -Ivariants/pca10056-rc-clock
src_filter = ${nrf52_base.src_filter} +<../variants/pca10056-rc-clock>

; Note: By default no lora device is created for this build - it uses a simulated interface
[env:feather_nrf52832]
extends = nrf52_base
board = adafruit_feather_nrf52832

[env:rak815]
extends = nrf52_base
board = rak815
debug_tool = jlink
upload_protocol = jlink
monitor_port = /dev/ttyUSB0
; this board's serial chip can only run at 115200, not faster
monitor_speed = 115200 

# For experimenting with RAM sizes
# board_build.ldscript = linker/nrf52840_s140_sim832.ld

; The PPR board
[env:ppr]
extends = nrf52_base
board = ppr
lib_deps = 
  ${arduino_base.lib_deps}
  UC1701

; The PPR board
[env:ppr1]
extends = nrf52_base
board = ppr1
build_flags = ${nrf52_base.build_flags} -Ivariants/ppr1
src_filter = ${nrf52_base.src_filter} +<../variants/ppr1>
lib_deps = 
  ${arduino_base.lib_deps}

; First prototype eink/nrf52840/sx1262 device
[env:eink]
extends = nrf52_base
board = eink
# add our variants files to the include and src paths
# define build flags for the TFT_eSPI library
build_flags = ${nrf52_base.build_flags} -Ivariants/eink
  -DBUSY_PIN=3 -DRST_PIN=2 -DDC_PIN=28 -DCS_PIN=30
src_filter = ${nrf52_base.src_filter} +<../variants/eink>
lib_deps = 
  ${arduino_base.lib_deps}
  https://github.com/geeksville/EPD_Libraries.git
  TFT_eSPI

; First prototype eink/nrf52840/sx1262 device
[env:eink0.1]
extends = nrf52_base
board = eink0.1
# add our variants files to the include and src paths
# define build flags for the TFT_eSPI library
build_flags = ${nrf52_base.build_flags} -Ivariants/eink0.1
  -DBUSY_PIN=3 -DRST_PIN=2 -DDC_PIN=28 -DCS_PIN=30
src_filter = ${nrf52_base.src_filter} +<../variants/eink0.1>
lib_deps = 
  ${arduino_base.lib_deps}
  https://github.com/geeksville/EPD_Libraries.git
  TFT_eSPI

; The https://github.com/BigCorvus/SX1262-LoRa-BLE-Relay board by @BigCorvus
[env:lora-relay-v1]
extends = nrf52_base
board = lora-relay-v1
# add our variants files to the include and src paths
# define build flags for the TFT_eSPI library
build_flags = ${nrf52_base.build_flags} -Ivariants/lora_relay_v1
  -DUSER_SETUP_LOADED
  -DTFT_WIDTH=80
  -DTFT_HEIGHT=160
  -DST7735_GREENTAB160x80
  -DST7735_DRIVER
  -DTFT_CS=ST7735_CS
  -DTFT_DC=ST7735_RS
  -DTFT_RST=ST7735_RESET
  -DSPI_FREQUENCY=27000000
src_filter = ${nrf52_base.src_filter} +<../variants/lora_relay_v1>
lib_deps = 
  ${arduino_base.lib_deps}
  SparkFun BQ27441 LiPo Fuel Gauge Arduino Library
  TFT_eSPI

; The https://github.com/BigCorvus/LoRa-BLE-Relay-v2 board by @BigCorvus
[env:lora-relay-v2]
extends = nrf52_base
board = lora-relay-v2
# add our variants files to the include and src paths
# define build flags for the TFT_eSPI library
build_flags = ${nrf52_base.build_flags} -Ivariants/lora_relay_v2
  -DUSER_SETUP_LOADED
  -DTFT_WIDTH=80
  -DTFT_HEIGHT=160
  -DST7735_GREENTAB160x80
  -DST7735_DRIVER
  -DTFT_CS=ST7735_CS
  -DTFT_DC=ST7735_RS
  -DTFT_RST=ST7735_RESET
  -DSPI_FREQUENCY=27000000
  -DTFT_WR=ST7735_SDA
  -DTFT_SCLK=ST7735_SCK
src_filter = ${nrf52_base.src_filter} +<../variants/lora_relay_v2>
lib_deps = 
  ${arduino_base.lib_deps}
  SparkFun BQ27441 LiPo Fuel Gauge Arduino Library
  TFT_eSPI

; The Portduino based sim environment on top of linux
[env:linux]
platform = https://github.com/geeksville/platform-portduino.git
src_filter = ${env.src_filter} -<esp32/> -<nimble/> -<nrf52/> -<mesh/http/> -<plugins/esp32>
build_flags = ${arduino_base.build_flags} -O0
framework = arduino
board = linux_x86_64
lib_deps =
  ${arduino_base.lib_deps}
  rweather/Crypto

; The GenieBlocks LORA prototype board
[env:genieblocks_lora]
extends = esp32_base
board = genieblocks_lora
build_flags = 
  ${esp32_base.build_flags} -D GENIEBLOCKS