; PlatformIO Project Configuration File for EMS-ESP
; override any settings with your own local ones in pio_local.ini

[platformio]
default_envs = esp32_4M
; default_envs = lolin_s3
; default_envs = esp32_16M
; default_envs = standalone

extra_configs =
  factory_settings.ini
  pio_local.ini

[common]
core_build_flags =
  -D CORE_DEBUG_LEVEL=0
  -D NDEBUG
  -D ARDUINO_ARCH_ESP32=1
  -D ESP32=1
  ; -std=gnu++17

; core_unbuild_flags = -std=gnu++11
core_unbuild_flags =

; my_build_flags is set in pio_local.ini
my_build_flags =

build_flags =
  ${common.core_build_flags}
  ${factory_settings.build_flags}
  ${common.my_build_flags}
  -D ONEWIRE_CRC16=0
  -D NO_GLOBAL_ARDUINOOTA
  -D ARDUINOJSON_ENABLE_STD_STRING=1
  -D ARDUINOJSON_USE_DOUBLE=0
  ; -D CONFIG_UART_ISR_IN_IRAM

unbuild_flags =
  ${common.core_unbuild_flags}

[espressi32_base]
platform = espressif32@6.4.0
framework = arduino
board_build.filesystem = littlefs
build_flags = ${common.build_flags}
build_unflags = ${common.unbuild_flags}
extra_scripts =
  pre:scripts/build_interface.py
  scripts/rename_fw.py

[espressi32_base_tasmota]
; use Tasmota's libary which removes some libs (like mbedtsl) and increases available heap
; platform = https://github.com/tasmota/platform-espressif32.git ; latest development
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip ; latest stable
; platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.02/platform-espressif32.zip
framework = arduino
board_build.filesystem = littlefs
build_flags = ${common.build_flags}
build_unflags = ${common.unbuild_flags}
extra_scripts =
  pre:scripts/build_interface.py
  scripts/rename_fw.py

[env]
monitor_speed = 115200
monitor_raw = yes
upload_speed = 921600
build_type = release
lib_ldf_mode = chain+
; board_build.flash_mode = qio

check_tool = cppcheck, clangtidy
check_severity = high, medium
check_flags =
  cppcheck: --std=c++11 -v
  clangtidy: --checks=-*,clang-analyzer-*,performance-*

; build for GitHub Actions CI
; the Web interface is built seperately
[env:ci]
extends = espressi32_base_tasmota
extra_scripts = scripts/rename_fw.py
board = esp32dev
board_build.partitions = esp32_partition_4M.csv
board_build.extra_flags = -DBOARD_HAS_PSRAM
build_flags = ${common.build_flags}
build_unflags = ${common.unbuild_flags}

[env:ci_s3]
extends = espressi32_base
extra_scripts = scripts/rename_fw.py
board = lolin_s3
board_build.f_cpu = 240000000L
board_upload.flash_size = 16MB
board_build.partitions = esp32_partition_16M.csv
build_flags =
  ${common.build_flags}
  -O2
build_unflags = ${common.unbuild_flags}

[env:esp32_4M]
extends = espressi32_base_tasmota
board = esp32dev
board_upload.flash_size = 4MB
board_build.partitions = esp32_partition_4M.csv
build_flags =
  ${common.build_flags}
  -Os

[env:esp32_4Mplus]
extends = espressi32_base_tasmota
board = esp32dev
board_upload.flash_size = 4MB
board_build.partitions = esp32_asym_partition_4M.csv
build_flags = ${common.build_flags}

[env:esp32_16M]
extends = espressi32_base_tasmota
board = esp32dev
board_build.extra_flags = -DBOARD_HAS_PSRAM
board_upload.flash_size = 16MB
board_build.partitions = esp32_partition_16M.csv
build_flags = ${common.build_flags}

[env:lolin_c3_mini]
extends = espressi32_base_tasmota
board = lolin_c3_mini
board_upload.flash_size = 4MB
board_build.partitions = esp32_partition_4M.csv
build_flags =
  ${common.build_flags}
  -DEMSESP_DEFAULT_BOARD_PROFILE = "C3MINI"

; lolin C3 mini v1 needs special wifi init.
; https://www.wemos.cc/en/latest/c3/c3_mini_1_0_0.html#about-wifi
[env:lolin_c3_mini_v1]
extends = espressi32_base_tasmota
board = lolin_c3_mini
board_upload.flash_size = 4MB
board_build.partitions = esp32_partition_4M.csv
build_flags =
  ${common.build_flags}
  -DBOARD_C3_MINI_V1
  -DEMSESP_DEFAULT_BOARD_PROFILE = "C3MINI"

[env:lolin_s2_mini]
extends = espressi32_base_tasmota
board = lolin_s2_mini
board_upload.flash_size = 4MB
board_build.partitions = esp32_partition_4M.csv
build_flags =
  ${common.build_flags}
  -DEMSESP_DEFAULT_BOARD_PROFILE = "S2MINI"

[env:lolin_s3]
extends = espressi32_base
board = lolin_s3
board_build.f_cpu = 240000000L
board_upload.flash_size = 16MB
board_build.partitions = esp32_partition_16M.csv
board_upload.use_1200bps_touch = false
board_upload.wait_for_upload_port = false
build_flags =
  ${common.build_flags}
  -O2
  -DEMSESP_DEFAULT_BOARD_PROFILE = "S32S3"

; to build and run: pio run -e standalone -t exec
[env:standalone]
platform = native
build_flags =
  -DARDUINOJSON_ENABLE_STD_STRING=1 -DARDUINOJSON_ENABLE_PROGMEM=1 -DARDUINOJSON_ENABLE_ARDUINO_STRING -DARDUINOJSON_USE_DOUBLE=0
  -DEMSESP_DEBUG -DEMSESP_STANDALONE -DEMSESP_TEST -D__linux__
  -DEMSESP_DEFAULT_LOCALE=\"en\" -DEMSESP_DEFAULT_TX_MODE=8 -DEMSESP_DEFAULT_VERSION=\"3.6.0-dev\" -DEMSESP_DEFAULT_BOARD_PROFILE=\"S32\"
	-lpthread
  -std=gnu++11 -Og -ggdb
build_src_flags =
  -Wall -Wextra -Werror -Wswitch-enum -Wno-unused-parameter -Wno-inconsistent-missing-override -Wno-unused-lambda-capture -Wno-sign-compare
  -Wno-missing-braces
  -I./lib_standalone
  -I./lib/ArduinoJson/src
  -I./lib/uuid-common/src
  -I./lib/uuid-console/src
  -I./lib/uuid-log/src
  -I./lib/semver
  -I./lib/PButton
  -I./lib/espMqttClient/src
  -I./lib/espMqttClient/src/Transport
build_src_filter =
	+<*>
  -<.git/>
  +<../lib_standalone>
  +<../lib/uuid-common>
  +<../lib/uuid-console>
  +<../lib/uuid-log>
  +<../lib/semver>
  +<../lib/PButton>
  +<../lib/espMqttClient/src>
  +<../lib/espMqttClient/src/Transport>
lib_compat_mode = off
lib_ldf_mode = off