Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ build_flags = ${common.build_flags} ${esp32s2.build_flags} -D WLED_RELEASE_NAME=
[env:usermods]
extends = env:esp32dev
build_flags = ${common.build_flags} ${esp32_idf_V4.build_flags} -D WLED_RELEASE_NAME=\"ESP32_USERMODS\"
-DTOUCH_CS=9 -DWLED_USE_SD_SPI ;; help a few usermods that require special flags to compile
-DTOUCH_CS=9

@coderabbitai coderabbitai Bot Jul 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== platformio.ini line count =="
wc -l platformio.ini

echo
echo "== around referenced line 717 =="
nl -ba platformio.ini | sed -n '690,740p'

echo
echo "== all TOUCH_CS occurrences =="
rg -n "TOUCH_CS|custom_usermods|\\[env:usermods\\]|\\[env:" platformio.ini

echo
echo "== env headers around usermods =="
python3 - <<'PY'
from pathlib import Path
text = Path('platformio.ini').read_text().splitlines()
for i, line in enumerate(text, 1):
    if line.strip().startswith('[env:') or 'TOUCH_CS' in line or 'custom_usermods' in line:
        start = max(1, i-3)
        end = min(len(text), i+3)
        print(f"\n--- lines {start}-{end} ---")
        for j in range(start, end+1):
            print(f"{j:4d}: {text[j-1]}")
PY

Repository: wled/WLED

Length of output: 272


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== platformio.ini context around TOUCH_CS =="
nl -ba platformio.ini | sed -n '700,730p'

echo
echo "== all env headers and custom_usermods references =="
rg -n "^\[env:|custom_usermods|TOUCH_CS" platformio.ini

echo
echo "== nearby override envs if present =="
python3 - <<'PY'
from pathlib import Path
lines = Path('platformio.ini').read_text().splitlines()
for i, line in enumerate(lines, 1):
    if line.strip().startswith('[env:') and ('usermods' in line.lower() or 'override' in line.lower() or 'touch' in line.lower()):
        start = max(1, i-2)
        end = min(len(lines), i+18)
        print(f"\n--- {i}: {line} ---")
        for j in range(start, end+1):
            print(f"{j:4d}: {lines[j-1]}")
PY

Repository: wled/WLED

Length of output: 232


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== lines 700-730 with line numbers =="
awk 'NR>=700 && NR<=730 { printf "%4d: %s\n", NR, $0 }' platformio.ini

echo
echo "== all occurrences of TOUCH_CS, custom_usermods, and relevant env headers =="
python3 - <<'PY'
from pathlib import Path
lines = Path('platformio.ini').read_text().splitlines()
for i, line in enumerate(lines, 1):
    if 'TOUCH_CS' in line or 'custom_usermods' in line or line.strip().startswith('[env:'):
        print(f"{i:4d}: {line}")
PY

echo
echo "== locate [env:usermods] block =="
python3 - <<'PY'
from pathlib import Path
lines = Path('platformio.ini').read_text().splitlines()
start = None
for i, line in enumerate(lines, 1):
    if line.strip() == '[env:usermods]':
        start = i
        break
if start is None:
    print("missing [env:usermods]")
    raise SystemExit(0)
end = len(lines)
for j in range(start + 1, len(lines) + 1):
    if lines[j-1].startswith('[env:') and j != start:
        end = j - 1
        break
for j in range(start, min(end, start + 40) + 1):
    print(f"{j:4d}: {lines[j-1]}")
PY

Repository: wled/WLED

Length of output: 5366


Keep [env:usermods] generic.
TOUCH_CS=9 in [env:usermods] forces every custom_usermods = * build to inherit the same touch pin. Move it to the specific env that needs it so usermods with different wiring don't pick up the wrong default.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@platformio.ini` at line 717, The generic [env:usermods] configuration is
leaking a touch pin default into every custom_usermods build. Remove TOUCH_CS
from the shared usermods env and move it into the specific environment that
actually needs that wiring, using the relevant env block in platformio.ini so
other usermods can define their own pin settings.

Source: Path instructions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@willmmiles -DTOUCH_CS=9 is actually an older "workaround" for making TFT_eSPI based usermods compile in the CI workflow. Not sure if we should keep this flag?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
rg -n "TOUCH_CS" --type=cpp --type=ini -g '*.ini' -g '*.h' -g '*.cpp' . || true
rg -n "TOUCH_CS" .

Length of output: 331


@softhack007, I searched the repo and TOUCH_CS appears only in platformio.ini (Line 717) — it's not referenced anywhere in the WLED core .cpp/.h sources. That confirms it's purely a compile-time define consumed by an external library's config (likely TFT_eSPI's User_Setup.h/pin-select macros), not something WLED itself depends on.

Given that, and consistent with this PR's stated goal of keeping the shared [env:usermods] environment free of usermod-specific flags:

  • If there's currently no usermod in-tree that still needs TOUCH_CS=9 to compile in CI, it's probably safe to drop it entirely from [env:usermods].
  • If some TFT_eSPI-based usermod does still need it, it should move into that usermod's own platformio_override.ini.sample (the same pattern being introduced for WLED_USE_SD_SPI/SD_Card and PWM_fan in this PR), rather than leaking a pin default into every custom_usermods = * build.

I'll leave the final call to you/willmmiles since you have more context on which usermods currently rely on this workaround in CI.


🧠 Learnings used
Learnt from: netmindz
Repo: wled/WLED PR: 5311
File: platformio.ini:395-395
Timestamp: 2026-01-31T18:19:28.320Z
Learning: In platformio.ini for WLED, understand that usermods can be pulled as out-of-tree dependencies via lib_deps (external repositories). The custom_usermods setting controls only in-tree usermods; setting custom_usermods =  (empty) disables in-tree usermods but does not disable out-of-tree usermods included through library dependencies.

Learnt from: softhack007
Repo: wled/WLED PR: 5048
File: platformio.ini:486-491
Timestamp: 2026-02-10T13:52:36.924Z
Learning: In PlatformIO projects, prefer using build_unflags in the PlatformIO configuration to remove inherited -D defines rather than using GCC's -U option. The -U approach is order-dependent and may be unreliable if the build command order is not guaranteed by PlatformIO. Use build_unflags in platformio.ini to explicitly remove inherited build flags for more robust and maintainable builds.

Learnt from: softhack007
Repo: wled/WLED PR: 5456
File: platformio.ini:788-850
Timestamp: 2026-03-31T13:31:01.488Z
Learning: For PlatformIO projects using `platform = pioarduino/platform-espressif32` with dual frameworks (`framework = arduino, espidf`), do not require an explicit `board_build.sdkconfig = sdkconfig.<env_name>` setting. `sdkconfig.<env_name>` (e.g., `sdkconfig.esp32s3_matter_wifi`) is a per-environment build artifact generated by pioarduino from merged board defaults plus the project-root `sdkconfig.defaults`. The project-root `sdkconfig.defaults` is automatically loaded by ESP-IDF’s CMake build, so the absence of `board_build.sdkconfig` should not be flagged as a missing configuration.

Learnt from: softhack007
Repo: wled/WLED PR: 5456
File: platformio.ini:788-850
Timestamp: 2026-03-31T13:31:01.488Z
Learning: For PlatformIO projects using `pioarduino/platform-espressif32` with dual framework (`framework = arduino, espidf`), treat `sdkconfig.<env_name>` (e.g., `sdkconfig.esp32s3_matter_wifi`) as a per-environment build artifact generated in the project root. PlatformIO will create it from `sdkconfig.defaults` on first build if it doesn’t exist, and will reuse the existing file on subsequent builds. In code review, do not recommend setting `board_build.sdkconfig = sdkconfig.<env_name>` because that file is an output, not required input. Only use `board_build.cmake_extra_args = -DSDKCONFIG_DEFAULTS=...` to select different defaults files when different environments truly need different SDK config defaults. As a sanity check, if `sdkconfig.<env_name>` is deleted and a rebuild regenerates it with the same content, that indicates `sdkconfig.defaults` is the correct source of truth.

Learnt from: netmindz
Repo: wled/WLED PR: 5543
File: platformio.ini:133-136
Timestamp: 2026-04-26T09:03:12.551Z
Learning: For WLED platformio.ini files: do not mark the audioreactive usermod as “unsupported” for ESP8266 build environments. While ESP8266 can’t process audio locally, it may still receive audioreactive sync data over the network (e.g., from an ESP32 or other source), so the outdated readme note about “ESP8266 is not supported” should be interpreted as only local audio processing. Reviewers should allow audioreactive to be included in ESP8266 environments in platformio.ini when network sync-receive is being used.

Learnt from: softhack007
Repo: wled/WLED PR: 5692
File: platformio.ini:798-799
Timestamp: 2026-06-20T15:08:04.789Z
Learning: For PlatformIO INI files, validate variable interpolation syntax as `${section_name.variable}` where `section_name` is the exact literal section header text (including any `env:` prefix for build environments like `[env:some_name]`). This refers to INI section data, not OS/system environment variables. Therefore, `${env:some_name.variable}` is correct for values in `[env:some_name]` (e.g., `${env:esp32S3_wroom2_32MB.build_unflags}` references `build_unflags` from that `[env:esp32S3_wroom2_32MB]` section); do not flag it as incorrect interpolation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's actually necessary. TFT_eSPI generates warnings to indicate that the touch subsystem is disabled without it, but that's normal and expected if you don't actually have a touch screen!

I'm almost done the PR for the TFT_eSPI shim anyways. It's been another one where CodeRabbit has been pretty good at finding issues before I push. ;)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

custom_usermods = * ; Expands to all usermods in usermods folder
board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat

Expand Down
13 changes: 4 additions & 9 deletions usermods/platformio_override.usermods.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,31 @@ default_envs = usermods_esp32, usermods_esp32c3, usermods_esp32s2, usermods_esp3

[env:usermods_esp32]
extends = env:esp32dev
build_flags = ${env:esp32dev.build_flags}
-DTOUCH_CS=9 -D WLED_USE_SD_SPI ;; help a few usermods that require special flags to compile
custom_usermods = ${usermods.custom_usermods}
board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat
build_flags = ${env:esp32dev.build_flags} -D WLED_DEBUG


[env:usermods_esp32c3]
extends = env:esp32c3dev
build_flags = ${env:esp32c3dev.build_flags}
-DTOUCH_CS=9 -D WLED_USE_SD_SPI ;; help a few usermods that require special flags to compile
board = esp32-c3-devkitm-1
custom_usermods = ${usermods.custom_usermods}
board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat
build_flags = ${env:esp32c3dev.build_flags} -D WLED_DEBUG


[env:usermods_esp32s2]
extends = env:lolin_s2_mini
build_flags = ${env:lolin_s2_mini.build_flags}
-DTOUCH_CS=9 -D WLED_USE_SD_SPI ;; help a few usermods that require special flags to compile
custom_usermods = ${usermods.custom_usermods}
board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat
build_flags = ${env:lolin_s2_mini.build_flags} -D WLED_DEBUG


[env:usermods_esp32s3]
extends = env:esp32s3dev_16MB_opi
build_flags = ${env:esp32s3dev_16MB_opi.build_flags}
-DTOUCH_CS=9 -D WLED_USE_SD_SPI ;; help a few usermods that require special flags to compile
-D WLED_DEBUG ;; try to catch broken DEBUG_PRINT statements
custom_usermods = ${usermods.custom_usermods}
board_build.partitions = ${esp32.extreme_partitions} ; We're gonna need a bigger boat
build_flags = ${env:esp32s3dev_16MB_opi.build_flags} -D WLED_DEBUG



Expand Down
Loading