[env]
; Global settings for all environments
; Symlink in the FastLED library so that changes to the library are reflected in the project
; build immediately.
lib_deps =
  FastLED=symlink://./
; NOTE: build_cache_enable and build_cache_dir are not standard PlatformIO options
; Board-specific cache directories are now configured per-board in ci/ci/boards.py
;build_cache_enable = true
;build_cache_dir = ${platformio.build_cache_dir}
[env:generic-esp]
# Developement branch of the open source espressif32 platform
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.35/platform-espressif32.zip
framework = arduino
upload_protocol = esptool
monitor_filters =
	default
	esp32_exception_decoder  ; Decode exceptions so that they are human readable.
; CRASH TRACE INVESTIGATION (2026-04-06):
; ESP32 Arduino framework includes built-in panic handler (Guru Meditation) that prints
; backtrace + register dump on crashes. The esp32_exception_decoder monitor filter above
; decodes addresses to file:line. For silent crashes (watchdog, brownout) with no output,
; the panic handler may not fire — CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT is the default.
; No additional crash handler implementation needed for stack traces.
build_type = debug

build_flags =
    -DDEBUG
    -DPIN_CLOCK=7
    -DFASTLED_RMT5=1
    -DESP32_ARDUINO_NO_RGB_BUILTIN=1
    ; -DFASTLED_LOG_RMT_ENABLED
    ; -DFASTLED_LOG_PARLIO_ENABLED
    -DFASTLED_DEBUG=1
    -g
    -Og
    -DCORE_DEBUG_LEVEL=5
    -DLOG_LOCAL_LEVEL=ESP_LOG_VERBOSE
    -DFASTLED_ESP32_SPI_BULK_TRANSFER=1
    -D IDF_CCACHE_ENABLE=1
check_tool = clangtidy

[env:uno]
platform = atmelavr
board = uno
framework = arduino

[env:giga_r1_m7]
platform = ststm32
board = giga_r1_m7
framework = arduino

[env:esp32s3]
extends = env:generic-esp
board = seeed_xiao_esp32s3
; Flash mode: Use board default (QIO) for hardware, ci/boards.py sets DIO for QEMU builds
; Set flash size to 4MB to match QEMU configuration (seeed_xiao_esp32s3 default is 8MB)
; Use board_build.flash_size to set the binary header, not board_upload.flash_size
board_build.flash_size = 4MB
; Note: This partition table is for normal builds. QEMU builds use settings from ci/boards.py
; Use huge_app partition table to allow larger debug builds
board_build.partitions = huge_app.csv
build_flags =
    ${env:generic-esp.build_flags}
    -D ARDUINO_USB_MODE=1
    -D ARDUINO_USB_CDC_ON_BOOT=1
    -D ARDUINO_LOOP_STACK_SIZE=16384

[env:esp32c6]
extends = env:generic-esp
board = esp32-c6-devkitc-1
build_flags =
  ${env:generic-esp.build_flags}
  -D ARDUINO_USB_MODE=1
  -D ARDUINO_USB_CDC_ON_BOOT=1
  -D CONFIG_PARLIO_TX_ISR_HANDLER_IN_IRAM=1
  -D CONFIG_PARLIO_TX_ISR_CACHE_SAFE=1
  -D ARDUINO_LOOP_STACK_SIZE=16384
  -D PIN_DATA=21
  -D PARLIO_FORCE_LSB_MODE=0
  ; Optional: fix early prints
; Flash mode: Use board default (QIO) for hardware, ci/boards.py sets DIO for QEMU builds
board_build.flash_size = 4MB
board_upload.flash_size = 4MB
board_build.partitions = huge_app.csv

[env:esp32p4]
extends = env:generic-esp
board = esp32-p4-evboard
build_flags =
  ${env:generic-esp.build_flags}

  -D ARDUINO_USB_MODE=1
board_build.partitions = huge_app.csv

[env:esp32c3]
extends = env:generic-esp
board = esp32-c3-devkitm-1
; Flash mode: Use board default (QIO) for hardware, ci/boards.py sets DIO for QEMU builds
build_flags = ${env:generic-esp.build_flags}

[env:esp32-wroom-32]
extends = env:generic-esp
board = esp32dev
build_flags = ${env:generic-esp.build_flags}

[env:esp32c2]
extends = env:generic-esp
platform = https://github.com/pioarduino/platform-espressif32.git#develop
board = esp32-c2-devkitm-1
custom_sdkconfig = CONFIG_IDF_TARGET="esp32c2"
board_build.partitions = huge_app.csv
build_flags =
  ${env:generic-esp.build_flags}


[env:esp32dev]
extends = env:generic-esp
platform = platformio/espressif32
board = esp32dev
; Use DIO flash mode instead of QIO for QEMU compatibility
; QEMU's ESP32 emulation doesn't support setting the QIE (Quad I/O Enable) bit,
; causing "Failed to set QIE bit" error and boot assertion failure in startup_funcs.c:95
; DIO (Dual I/O) mode works reliably in both hardware and QEMU emulation
board_build.flash_mode = dio
build_flags =
  ${env:generic-esp.build_flags}


[env:teensy40]
platform = teensy
board = teensy40
framework = arduino
build_flags = -D USB_MIDI_SERIAL


[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
build_flags = -D USB_MIDI_SERIAL


[env:sparkfun_xrp_controller]
platform = https://github.com/maxgerhardt/platform-raspberrypi
board = sparkfun_xrp_controller
framework = arduino
build_flags = -fopt-info-all=optimization_report.txt
extra_scripts = pre:ci/ci-flags.py


[env:lpc845brk]
; NXP LPC845-BRK bring-up target — built via the fbuild nxplpc orchestrator
; which consumes zackees/ArduinoCore-LPC8xx. PlatformIO does not have a
; native nxplpc platform; this env is here only so the AutoResearch wrapper
; (`bash autoresearch lpc845brk`) can resolve a known environment name and
; dispatch to the consolidated bring-up sketch at examples/AutoResearch/
; (low-memory mode auto-engages on LPC8xx; see FastLED #3030 / #3041).
;
; Build flags:
;   -DRELEASE                     -- disables FASTLED_FORCE_DBG so the FL_DBG
;                                    call sites stay no-op (~4 KB saved).
;   ; -DFASTLED_LPC_PWM_DMA=1       -- activates the hardware-accelerated SCT +
;                                    DMA-to-GPIO clockless driver (FastLED
;                                    #2842 / #2850) in place of the bit-bang
;                                    default. Claims the SCT + 3 DMA channels
;                                    for the FastLED controller lifetime.
;   -DFASTLED_LPC_RX_SCT_WS2812=1 -- binds the `ws2812SctTest` AutoResearch
;                                    loopback RPC (FastLED #3021 Phase 2).
;                                    Pulls in `<FastLED.h>` alongside fl::Remote;
;                                    fits the 64 KB budget after #3038's
;                                    soft-FP-codec replacement.
platform = nxplpc
board = lpc845brk
framework = arduino
build_flags =
    -DRELEASE
    -DFASTLED_LPC_PWM_DMA=1
    -DFASTLED_AUTORESEARCH_LOW_MEMORY=1
    -DFASTLED_LPC_RX_SCT_WS2812=1
    ; -DFASTLED_LPC_RX_SCT_WS2812=1   ; pulls <FastLED.h>, +20 KB, exceeds 64 KB
    ;                                  ; flash budget on LPC845-BRK. Re-enable
    ;                                  ; once additional flash-budget reduction
    ;                                  ; lands (gamma LUT / EngineEvents / etc.).

; --------------------------------------------------------------------------
; LPC8xx canary envs (FastLED #2990 — fbuild Stage 6 canary).
;
; Minimal definitions so the per-board CI workflows below can resolve
; each variant name against the fbuild nxplpc orchestrator. These envs
; do NOT carry the AutoResearch-specific build_flags that `lpc845brk`
; does — they exist for the Blink canary path only.
;
; All four use the same nxplpc + ArduinoCore-LPC8xx stack (see lpc845brk
; comment above for the dispatch rationale). Each maps 1:1 to one of the
; `variants/<name>/` entries in zackees/ArduinoCore-LPC8xx, matching the
; five upstream `fbuild build . -e <variant>` jobs that already pass on
; that repo (see #2990 body).
; --------------------------------------------------------------------------

[env:lpc845]
platform = nxplpc
board = lpc845
framework = arduino

[env:lpc804]
platform = nxplpc
board = lpc804
framework = arduino

[env:lpcxpresso845max]
platform = nxplpc
board = lpcxpresso845max
framework = arduino

[env:lpcxpresso804]
platform = nxplpc
board = lpcxpresso804
framework = arduino


[platformio]
src_dir = examples/Sailboat ; default: examples/AutoResearch/AutoResearch.ino (override with PLATFORMIO_SRC_DIR env var)
default_envs = esp32s3
; ARDUINO_USB_CDC_ON_BOOT lives in per-board build_flags now (ci/boards.py).
; Safe to enable thanks to Serial.setTxTimeoutMs(0); see issue #2668.
; Enable shared build cache to avoid recompiling FastLED library when switching sketches
; This dramatically speeds up `bash debug <example>` workflow by reusing compiled objects
build_cache_dir = .pio/build_cache
