; -- Platform specific build flags
[esp32]
extend = env
board_build.filesystem = littlefs
board_build.f_cpu = 240000000L
board_build.mcu = esp32

; ----- crash reporter
monitor_filters = esp32_exception_decoder

; ----- debugger
check_tool = cppcheck
check_flags = --enable=all
debug_tool = esp-prog
debug_init_break = tbreak setup

board_build.embed_files =
    ${esp32.files}

files =
    data/static/edit.htm.gz
    data/openhasp.ttf
    ; data/openhasplite.ttf
    data/static/style.css.gz
    data/static/script.js.gz
    data/cert/x509_crt_bundle.bin
    ; -- new dynamic website files -------------------
    data/static/logo.svg.gz
    ; data/static/ace.1.9.6.min.js.gz
    data/static/petite-vue.hasp.js.gz
    data/static/main.js.gz
    data/static/en.json.gz
    ; data/static/hasp.htm.gz
    data/pages/pages.jsonl
    
build_flags =
    ${env.build_flags}
    -D HASP_TARGET_ARDUINO=1
    -D HTTP_UPLOAD_BUFLEN=1024      ; lower http upload buffer
    -D MQTT_MAX_PACKET_SIZE=2048    ; longer PubSubClient messages
    -D HASP_CONSOLE_BUFFER=256      ; maximum length of a console/telnet command
    -D NO_GLOBAL_HTTPUPDATE         ; dont instantiate httpUpdate
    ;-D CONFIG_NEWLIB_NANO_FORMAT
; -- lvgl build options -----------------------------
    -D LV_ATTRIBUTE_FAST_MEM=IRAM_ATTR
    -D LV_ATTRIBUTE_TASK_HANDLER=IRAM_ATTR
    -D LV_USE_FS_IF=1
    ;-D LV_FS_PC_PATH="//littlefs"   ; this needs to match the vfs mount pount
; -- ArduinoJson build options ----------------------------
    -D ARDUINOJSON_ENABLE_PROGMEM=1 ; for PROGMEM arguments
; -- tft_espi build options ------------------------
    ;-D USE_DMA_TO_TFT
; -- openHASP build options ------------------------
    -D HASP_ATTRIBUTE_FAST_MEM=IRAM_ATTR
    -D HASP_USE_TELNET=1
    ;-D HASP_USE_SPIFFS=1
    -D HASP_USE_LITTLEFS=1
    -D HASP_USE_LVGL_TASK=0         ; Run LVGL in separate task
    ;-D HASP_USE_EEPROM=1
    -D HASP_USE_CONFIG=1            ; Native application, not library
    -D LV_LOG_TRACE_TIMER=1
    -D HASP_USE_PNGDECODE=1
    -D HASP_USE_BMPDECODE=1
    -D HASP_USE_JPGDECODE=0
    -D HASP_USE_GIFDECODE=0
; -- LittleFS build options ------------------------
	;-D CONFIG_LITTLEFS_FOR_IDF_3_2  ; obsolete in IDF 3.3
; -- FreeType build options ------------------------
    -D LV_FREETYPE_SBIT_CACHE=1             ; use small bitmap cache
    -D LV_FREETYPE_CACHE_SIZE=1             ; cache freetype font sizes
    -D LV_USE_FT_CACHE_MANAGER=1            ; crashes without cache
    -D LVGL_FREETYPE_MAX_FACES=16           ; max number of FreeType faces in cache
    -D LVGL_FREETYPE_MAX_SIZES=16           ; max number of sizes in cache
    -D LVGL_FREETYPE_MAX_BYTES=2048         ; max bytes in bitcache per font
    -D LVGL_FREETYPE_MAX_BYTES_PSRAM=65536  ; max bytes in bitcache per font when using PSRAM
; -- SimpleFTpServer build options -----------------
    -D HASP_USE_FTP=1
    -D FTP_SERVER_DEBUG
    -D FTP_SERVER_NETWORK_TYPE=NETWORK_ESP32 ;// NETWORK_ESP32
    -D STORAGE_TYPE=STORAGE_LITTLEFS ;//  STORAGE_LITTLEFS
    -D STORAGE_SD_FORCE_DISABLE
    -D STORAGE_SPIFFS_FORCE_DISABLE
    
lib_ignore =
    ${env.lib_ignore}
    GxTFT
    XPT2046_Touchscreen
    Adafruit GFX Library
    ESP32 BLE Arduino
    lv_drv_fsmc_ili9341
    lv_drivers
    AXP192

lib_deps =
    ${env.lib_deps}
    git+https://github.com/fvanroie/ConsoleInput.git#dev
    ; lorol/LittleFS_esp32@^1.0.6    ; for Arduino v1 only
    bxparks/AceButton@^1.10.1        ; GPIO button library
    bblanchon/StreamUtils@^1.8.0     ; for EEPromStream and BufferedTelnetClient
    ; knolleary/PubSubClient@^2.8.0    ; MQTT client

extra_scripts =
    pre:tools/auto_firmware_version.py
    tools/littlefsbuilder.py
    tools/esp_merge_bin.py
    tools/analyze_elf.py
;    ${env.extra_scripts}
;    tools/copy_partitions.py

ps_ram =
    -DBOARD_HAS_PSRAM
    -mfix-esp32-psram-cache-issue  ; uses 24kB
    -D HASP_USE_FREETYPE=1
    -D LV_USE_FREETYPE=1
no_ps_ram =
    -D HASP_USE_FREETYPE=1
    -D LV_USE_FREETYPE=1

; -- The ESP32 has 2 SPI Hardware Busses available to use:
vspi =
    -D TFT_MISO=19
    -D TFT_MOSI=23
    -D TFT_SCLK=18
hspi =
    -D TFT_MISO=12
    -D TFT_MOSI=13
    -D TFT_SCLK=14

; -- The Arduino ESP32 v1.0.6 with 3 available flash sizes:
[arduino_esp32_v1]
extends = esp32
framework = arduino
platform = espressif32@^3.5.0
lib_deps =
    ${esp32.lib_deps}
    lorol/LittleFS_esp32@^1.0.6   ; Needed for Arduino v1 only


; -- The Arduino ESP32 v2.0.2 with 3 available flash sizes:
[arduino_esp32_v2]
extends = esp32
framework = arduino
; platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.05.01/platform-espressif32.zip
; platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.08.01/platform-espressif32.zip
;platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32.zip
;;;platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.11.01/platform-espressif32.zip
platform = https://github.com/Jason2866/platform-espressif32/releases/download/2023.10.02/platform-espressif32-2023.10.02.zip
lib_ignore =
    ${esp32.lib_ignore}
    LittleFS_esp32    ; Not needed for Arduino v2


[flash_4mb]
board_upload.flash_size=4MB
board_upload.maximum_size = 4194304
board_build.partitions = user_setups/esp32/partitions_4MB.csv

[flash_8mb]
board_upload.flash_size=8MB
board_upload.maximum_size = 8388608
board_build.partitions = user_setups/esp32/partitions_8MB.csv

[flash_16mb]
board_upload.flash_size = 16MB
board_upload.maximum_size = 16777216
board_build.partitions = user_setups/esp32/partitions_16MB.csv
