; Common settings for ESP targets, mixin with extends = esp32_common
[esp32_common]
extends = arduino_base
custom_esp32_kind =
custom_mtjson_part =
platform =
  # TODO renovate
  https://github.com/pioarduino/platform-espressif32/releases/download/55.03.39/platform-espressif32.zip
  ; https://github.com/pioarduino/platform-espressif32.git#develop
platform_packages =
  # renovate: datasource=custom.pio depName=platformio/tool-mklittlefs packageName=platformio/tool/tool-mklittlefs
  platformio/tool-mklittlefs@1.203.210628

extra_scripts =
  ${env.extra_scripts}
  pre:extra_scripts/esp32_pre.py
  extra_scripts/esp32_extra.py

build_src_filter = 
  ${arduino_base.build_src_filter} -<platform/nrf52/> -<platform/nrf54l15/> -<platform/stm32wl> -<platform/rp2xx0> -<mesh/eth/> -<mesh/raspihttp>

upload_speed = 921600
debug_init_break = tbreak setup
monitor_filters = esp32_exception_decoder

board_build.filesystem = littlefs

# Remove -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL for low level BLE logging.
# See library directory for BLE logging possible values: .pio/libdeps/tbeam/NimBLE-Arduino/src/log_common/log_common.h
# This overrides the BLE logging default of LOG_LEVEL_INFO (1) from: .pio/libdeps/tbeam/NimBLE-Arduino/src/esp_nimble_cfg.h
build_unflags =
  -fno-lto
  # Keep explicit std unflags on ESP32; base-level unflags are not sufficient
  # to prevent framework-injected C++11 fallback on this platform.
  -std=c++11
  -std=gnu++11
build_flags =
  ${arduino_base.build_flags}
  -Wall
  -Wextra
  -Isrc/platform/esp32
  -std=gnu++17
  -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG
  # DO NOT INCREASE THIS TO DEBUG. It appears to trigger a bug in ESP-IDF
  # Bluetooth stack with Pixel 8 Android devices:
  # https://github.com/espressif/esp-idf/issues/18126#issuecomment-4286197744
  # Once the bug is resolved, we can remove this warning.
  -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO
  -DMYNEWT_VAL_BLE_HS_LOG_LVL=LOG_LEVEL_CRITICAL
  -DAXP_DEBUG_PORT=Serial
  -DESP_OPENSSL_SUPPRESS_LEGACY_WARNING
  -DSERIAL_BUFFER_SIZE=4096
  -DSERIAL_HAS_ON_RECEIVE
  -DLIBPAX_ARDUINO
  -DLIBPAX_WIFI
  -DLIBPAX_BLE
  -DHAS_UDP_MULTICAST=1
  ;-DDEBUG_HEAP
  -DCAN_RECLOCK_I2C

lib_deps =
  ${arduino_base.lib_deps}
  ${networking_base.lib_deps}
  ${environmental_base.lib_deps}
  ${environmental_extra.lib_deps}
  ${radiolib_base.lib_deps}
  # renovate: datasource=git-refs depName=meshtastic-esp32_https_server packageName=https://github.com/meshtastic/esp32_https_server gitBranch=master
  https://github.com/meshtastic/esp32_https_server/archive/0c71f380390ad483ff134ad938e07f6cf1226c5b.zip
  # TODO renovate
  https://github.com/mverch67/libpax/archive/6f52ee989301cdabaeef00bcbf93bff55708ce2f.zip
  # renovate: datasource=custom.pio depName=XPowersLib packageName=lewisxhe/library/XPowersLib
  lewisxhe/XPowersLib@0.3.3
  # renovate: datasource=git-refs depName=meshtastic/Crypto packageName=https://github.com/meshtastic/Crypto gitBranch=master
  https://github.com/meshtastic/Crypto/archive/1aa30eb536bd52a576fde6dfa393bf7349cf102d.zip

lib_ignore = 
  segger_rtt
  ; ESP32 BLE Arduino
  ; BLE
  ; Ignore select Bluetooth libs
  NimBLE-Arduino
  BluetoothSerial
  SimpleBLE
  WiFiProv
  ArduinoOTA
  ; Ignore pioarduino esp32 libs we don't use
  ESP_I2S
  ESP_NOW
  ESP_SR
  Insights
  Matter
  OpenThread
  RainMaker
  ;SPIFFS
  USB
  ;NetworkClientSecure
  Zigbee
  Micro-RTSP
  ; testing below
  mqtt
  esp-mqtt

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

; Please don't delete these lines. JM uses them.
;upload_port = /dev/cu.SLAB_USBtoUART
;monitor_port = /dev/cu.SLAB_USBtoUART

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

custom_component_remove =
  espressif/esp_hosted
  espressif/esp_wifi_remote
  espressif/esp_modem
  espressif/esp-dsp
  espressif/esp32-camera
  espressif/libsodium
  espressif/esp-modbus
  espressif/qrcode
  espressif/esp_insights
  espressif/esp_diag_data_store
  espressif/esp_diagnostics
  espressif/esp_rainmaker
  espressif/rmaker_common
  espressif/network_provisioning
  chmorgan/esp-libhelix-mp3
  espressif/esp-tflite-micro
  espressif/esp-sr
  espressif/esp_matter
  espressif/esp-zboss-lib
  espressif/esp-zigbee-lib
  espressif/mqtt

custom_sdkconfig =
  ; CONFIG_LOG_DEFAULT_LEVEL=4
  ; CONFIG_LOG_MAXIMUM_LEVEL=4
  '# CONFIG_BT_NIMBLE_LOG_LEVEL_INFO is not set'
  CONFIG_BT_NIMBLE_LOG_LEVEL_ERROR=y
  CONFIG_LOG_COLORS=y
  CONFIG_ARDUHAL_LOG_COLORS=y
  CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
  CONFIG_IDF_EXPERIMENTAL_FEATURES=y
  ;
  ; Compiler options
  ;
  CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=n
  CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
  CONFIG_COMPILER_CXX_EXCEPTIONS=n
  CONFIG_COMPILER_STACK_CHECK_MODE_NORM=n
  CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y
  CONFIG_COMPILER_DISABLE_GCC12_WARNINGS=y
  CONFIG_COMPILER_DISABLE_GCC13_WARNINGS=y
  CONFIG_COMPILER_DISABLE_GCC14_WARNINGS=y
  CONFIG_COMPILER_ORPHAN_SECTIONS_WARNING=n
  CONFIG_COMPILER_ORPHAN_SECTIONS_PLACE=y
  CONFIG_ESP_GDBSTUB_ENABLED=n
  CONFIG_ESP_TASK_WDT_INIT=n
  CONFIG_NEWLIB_NANO_FORMAT=y
  ; LIBC_NEWLIB_NANO_FORMAT is enabled via 'esp32_extra.py' to allow float support
  CONFIG_ESP_COREDUMP_ENABLE=n
  CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=n
  CONFIG_ESP_COREDUMP_ENABLE_TO_NONE=y
  CONFIG_ESP32_ENABLE_COREDUMP=n
  CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=n
  CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=n
  CONFIG_FREERTOS_USE_TRACE_FACILITY=n
  CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
  CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y
  CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y
  CONFIG_ESP_SYSTEM_ESP32_SRAM1_REGION_AS_IRAM=y
  CONFIG_ESP_WIFI_IRAM_OPT=n
  CONFIG_ESP32_WIFI_RX_IRAM_OPT=n
  CONFIG_SPIRAM_CACHE_LIBCHAR_IN_IRAM=n
  CONFIG_SPIRAM_CACHE_LIBSTR_IN_IRAM=n
  CONFIG_SPIRAM_CACHE_LIBMISC_IN_IRAM=n
  CONFIG_SPIRAM_CACHE_LIBTIME_IN_IRAM=n
  CONFIG_UNITY_ENABLE_FLOAT=n
  CONFIG_UNITY_ENABLE_DOUBLE=n
  CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
  CONFIG_SUPPORT_TERMIOS=n
  CONFIG_VFS_SUPPORT_TERMIOS=n
  CONFIG_VFS_SUPPORT_SELECT=n
  CONFIG_VFS_SUPPRESS_SELECT_DEBUG_OUTPUT=n
  CONFIG_WS_TRANSPORT=n
  CONFIG_PPP_SUPPORT=n
  CONFIG_NETWORK_PROV_NETWORK_TYPE_WIFI=n
  ; CONFIG_LWIP_DHCPS=n
  CONFIG_LWIP_PPP_SUPPORT=n
  CONFIG_LWIP_IP_FORWARD=n
  CONFIG_LWIP_IPV4_NAPT=n
  ;
  ; MBEDTLS
  ;
  CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384 ; do not change, affects buffer allocation (PR10535)
  CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n
  CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y
  ; Switch to custom CA bundle (for Meshtastic MQTT/etc) in the future
  ; https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/kconfig-reference.html#certificate-bundle-configuration
  ; CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE=y
  ; CONFIG_MBEDTLS_CUSTOM_CERTIFICATE_BUNDLE_PATH=""
  CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_MAX_CERTS=1
  ; #shame
  CONFIG_MBEDTLS_ALLOW_WEAK_CERTIFICATE_VERIFICATION=y
  ; These six options must match the precompiled framework-arduinoespressif32-libs
  ; which was built with all six enabled. Disabling them changes mbedtls_ssl_context
  ; struct layout, causing an ABI mismatch and a crash in mbedtls_ssl_set_hostname.
  CONFIG_MBEDTLS_SSL_RENEGOTIATION=y
  CONFIG_MBEDTLS_SSL_PROTO_DTLS=y
  CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS=y
  CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS=y
  CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=y
  CONFIG_MBEDTLS_SSL_ALPN=y
  CONFIG_MBEDTLS_PKCS7_C=n
  CONFIG_MBEDTLS_CAMELLIA_C=n
  CONFIG_MBEDTLS_CCM_C=n
  CONFIG_MBEDTLS_CMAC_C=n
  CONFIG_MBEDTLS_SHA512_C=n
  CONFIG_MBEDTLS_X509_CRL_PARSE_C=n
  CONFIG_MBEDTLS_X509_CSR_PARSE_C=n
  CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_PSK=n
  CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=n
  CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=n
  CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=n
  CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED=n
  CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED=n
  CONFIG_MDNS_ENABLE_CONSOLE_CLI=n
  CONFIG_MDNS_PREDEF_NETIF_AP=n
  ; CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
  CONFIG_ESP_WIFI_ENTERPRISE_SUPPORT=n
  CONFIG_ESP_WIFI_ENABLE_WPA3_SAE=n
  CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_STA=n
  CONFIG_ESP_WIFI_ENABLE_SAE_H2E=n
  CONFIG_OPENTHREAD_ENABLED=n
  CONFIG_ZB_ENABLED=n
  CONFIG_IEEE802154_ENABLED=n
  CONFIG_ESP_INSIGHTS_ENABLED=n
  CONFIG_HTTPD_WS_SUPPORT=n
  CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS=n
  CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=n
  ; using esp-idf5-https_server library instead, for now?
  CONFIG_ESP_HTTPS_SERVER_ENABLE=n
  ;
  ; Builtin ESP-MQTT, we don't use this (yet?)
  ;
  CONFIG_MQTT_TRANSPORT_SSL=n
  CONFIG_MQTT_TRANSPORT_WEBSOCKET=n
  CONFIG_MQTT_TRANSPORT_WEBSOCKET_SECURE=n
  CONFIG_MQTT_PROTOCOL_311=n
  ;
  ; Ethernet
  ; Disabled in esp32_common, re-enable on variants that need it
  ;
  CONFIG_ETH_ENABLED=n
  CONFIG_ARDUINO_SELECTIVE_Ethernet=n
  ;
  ; Bluetooth
  ;
  CONFIG_BLE_MESH=n
  CONFIG_BT_ENABLED=y
  CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
  CONFIG_BT_BLUEDROID_ENABLED=n
  CONFIG_BT_NIMBLE_ENABLED=y
  CONFIG_BT_NIMBLE_NVS_PERSIST=y
  CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
  CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
  CONFIG_BT_CONTROLLER_ENABLED=y
  CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=8192
  CONFIG_BT_NIMBLE_MAX_CCCDS=20
  CONFIG_BT_NIMBLE_MAX_BONDS=6
  CONFIG_BT_NIMBLE_ENABLE_PERIODIC_SYNC=n
  CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV=n
  CONFIG_BT_NIMBLE_EXT_SCAN=n
  CONFIG_BT_NIMBLE_EXT_ADV=n
  CONFIG_BT_NIMBLE_PERIODIC_ADV_SYNC_TRANSFER=n
  CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_2M_PHY=n
  CONFIG_BT_NIMBLE_BLUFI_ENABLE=n
  CONFIG_BT_NIMBLE_PROX_SERVICE=n
  CONFIG_BT_NIMBLE_ANS_SERVICE=n
  CONFIG_BT_NIMBLE_CTS_SERVICE=n
  CONFIG_BT_NIMBLE_HTP_SERVICE=n
  CONFIG_BT_NIMBLE_IPSS_SERVICE=n
  CONFIG_BT_NIMBLE_TPS_SERVICE=n
  CONFIG_BT_NIMBLE_IAS_SERVICE=n
  CONFIG_BT_NIMBLE_LLS_SERVICE=n
  CONFIG_BT_NIMBLE_SPS_SERVICE=y
  CONFIG_BT_NIMBLE_HR_SERVICE=n
  CONFIG_BT_NIMBLE_HID_SERVICE=n
  CONFIG_BT_NIMBLE_BAS_SERVICE=n
  CONFIG_BT_NIMBLE_DIS_SERVICE=n
  ;
  ; Arduino selective compilation
  ; Disable unused Arduino libraries to save space
  ;
  CONFIG_ARDUINO_SELECTIVE_COMPILATION=y
  CONFIG_ARDUINO_SELECTIVE_SPI=y
  CONFIG_ARDUINO_SELECTIVE_Wire=y
  CONFIG_ARDUINO_SELECTIVE_ESP_SR=n
  CONFIG_ARDUINO_SELECTIVE_EEPROM=y
  CONFIG_ARDUINO_SELECTIVE_Preferences=y
  CONFIG_ARDUINO_SELECTIVE_Ticker=y
  CONFIG_ARDUINO_SELECTIVE_Update=y
  CONFIG_ARDUINO_SELECTIVE_Zigbee=n
  CONFIG_ARDUINO_SELECTIVE_FS=y
  CONFIG_ARDUINO_SELECTIVE_SD=y
  CONFIG_ARDUINO_SELECTIVE_SD_MMC=y
  CONFIG_ARDUINO_SELECTIVE_SPIFFS=y
  CONFIG_ARDUINO_SELECTIVE_FFat=n
  CONFIG_ARDUINO_SELECTIVE_LittleFS=y
  CONFIG_ARDUINO_SELECTIVE_Network=y
  ; CONFIG_ARDUINO_SELECTIVE_Ethernet=n
  CONFIG_ARDUINO_SELECTIVE_PPP=n
  CONFIG_ARDUINO_SELECTIVE_Hash=y
  CONFIG_ARDUINO_SELECTIVE_ArduinoOTA=n
  CONFIG_ARDUINO_SELECTIVE_AsyncUDP=y
  CONFIG_ARDUINO_SELECTIVE_DNSServer=n
  CONFIG_ARDUINO_SELECTIVE_ESPmDNS=y
  CONFIG_ARDUINO_SELECTIVE_HTTPClient=n
  CONFIG_ARDUINO_SELECTIVE_Matter=n
  CONFIG_ARDUINO_SELECTIVE_NetBIOS=n
  CONFIG_ARDUINO_SELECTIVE_WebServer=n
  CONFIG_ARDUINO_SELECTIVE_WiFi=y
  CONFIG_ARDUINO_SELECTIVE_NetworkClientSecure=y
  CONFIG_ARDUINO_SELECTIVE_WiFiProv=n
  CONFIG_ARDUINO_SELECTIVE_BLE=y
  CONFIG_ARDUINO_SELECTIVE_BluetoothSerial=n
  CONFIG_ARDUINO_SELECTIVE_SimpleBLE=n
  CONFIG_ARDUINO_SELECTIVE_RainMaker=n
  CONFIG_ARDUINO_SELECTIVE_OpenThread=n
  CONFIG_ARDUINO_SELECTIVE_Insights=n
