Skip to content

fix(rp): SDK 2.x pio_program init + type-limits + sign-compare hygiene (#2727) - #2740

Merged
zackees merged 1 commit into
masterfrom
fix/2727-rp-hygiene
Jun 4, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/2727-rp-hygiene

Conversation

@zackees

@zackees zackees commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Closes #2727.

Summary

Three RP2040/RP2350 warning families fire on every CI build for those boards. None are immediate bugs individually, but together they signal the RP common layer needs a hygiene pass before pico-sdk 2.x lands as the default for RP2350.

H1. pio_program missing initializer for pio_version / used_gpio_ranges

pico-sdk 2.x (RP2350) added pio_version and used_gpio_ranges to struct pio_program. FastLED's four pio_program literals omit them, triggering -Wmissing-field-initializers and (more dangerously) leaving the new fields zero-initialized by C++ aggregate rules. On RP2350 "no GPIO range claimed" could become a runtime failure the moment the SDK starts validating it.

Fix: explicitly initialize both new fields to 0 under #if defined(PICO_SDK_VERSION_MAJOR) && PICO_SDK_VERSION_MAJOR >= 2 guards in all 4 literals:

  • src/platforms/arm/rp/rpcommon/pio_gen.h:48
  • src/platforms/arm/rp/rpcommon/spi_hw_2_rp.cpp.hpp:88
  • src/platforms/arm/rp/rpcommon/spi_hw_4_rp.cpp.hpp:90
  • src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp:94

Preserves current behavior, silences the warning, and documents the field-init choice in one place to revisit when RP2350-SDK ergonomics solidify.

H2. -Wtype-limits always-true on mData[1-3]Pin >= 0

In spi_hw_4_rp.cpp.hpp the data-lane pin presence checks read:

if (mData1Pin >= 0 && mData2Pin >= 0 && mData3Pin >= 0)

But the fields are u8, so the comparisons are tautologies. The SpiHw4::Config source fields are i8 with -1 as the "unused lane" sentinel (see src/platforms/shared/spi_hw_4.h:44-46), so the intent was clearly "lane is configured". Currently broken: the storage truncates -1 to 0xFF and every lane is treated as active in the quad-mode check.

Fix: change mData1Pin / mData2Pin / mData3Pin from u8 to i8 so -1 round-trips. Update constructor initializers from 0 to -1 to match the Config defaults. mData0Pin and mClockPin stay u8 (always required, never sentinel-valued). Lane-presence checks now work as intended.

H3. -Wsign-compare in pin_rp.hpp (int pin vs unsigned NUM_BANK0_GPIOS)

Four loop-bound checks in pin_rp.hpp compare int pin against NUM_BANK0_GPIOS (unsigned from pico-sdk). Cast the bound to int inline — the cast is exact since NUM_BANK0_GPIOS fits in int on both RP2040 and RP2350.

Test plan

  • bash lint clean
  • CI green on rp2040 / rp2350
  • Verify H2 lane-count regression: a 1-lane SPIQuad config previously silently used 4 lanes; should now correctly skip the quad-mode consecutive-pin requirement.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed SPI quad mode pin configuration handling for multi-lane data support
    • Enhanced compatibility with Pico SDK version 2 and later releases
  • Refactor

    • Updated pin validation logic in PWM-related functions
    • Improved struct initialization patterns for better SDK compatibility

#2727)

Three RP2040/RP2350 warning families fire on every CI build for those
boards. None are immediate bugs individually, but together they signal
the RP common layer needs a hygiene pass before pico-sdk 2.x lands as
the default for RP2350.

## H1. pio_program missing initializer for pio_version / used_gpio_ranges

pico-sdk 2.x (RP2350) added `pio_version` and `used_gpio_ranges` to
`struct pio_program`. FastLED's four `pio_program` literals omit them,
triggering -Wmissing-field-initializers and (more dangerously) leaving
the new fields zero-initialized by C++ aggregate rules. On RP2350
"no GPIO range claimed" could become a runtime failure the moment the
SDK starts validating it.

Fix: explicitly initialize both new fields to 0 under
`#if defined(PICO_SDK_VERSION_MAJOR) && PICO_SDK_VERSION_MAJOR >= 2`
guards in all 4 literals (pio_gen.h, spi_hw_2_rp.cpp.hpp,
spi_hw_4_rp.cpp.hpp, spi_hw_8_rp.cpp.hpp). Preserves current behavior,
silences the warning, and documents the field-init choice in one place
to revisit when RP2350-SDK ergonomics solidify.

## H2. -Wtype-limits "always true" on `mData[1-3]Pin >= 0`

In `spi_hw_4_rp.cpp.hpp` the data-lane pin presence checks read
`if (mData1Pin >= 0 && mData2Pin >= 0 && mData3Pin >= 0)` — but the
fields are u8, so the comparison is always true. The `SpiHw4::Config`
source field is `i8` with `-1` as the "unused lane" sentinel, so the
intent was clearly "lane is configured" — currently broken: the
storage truncates `-1` to `0xFF` and every lane is treated as active.

Fix: change `mData1Pin / mData2Pin / mData3Pin` from `u8` to `i8` so
`-1` round-trips. Update constructor initializers from `0` to `-1` to
match the Config defaults. `mData0Pin` and `mClockPin` stay u8 (always
required, never sentinel-valued). Lane-presence checks now work as
intended.

## H3. -Wsign-compare in pin_rp.hpp (`int pin` vs unsigned NUM_BANK0_GPIOS)

Four loop-bound checks in pin_rp.hpp compare `int pin` against
`NUM_BANK0_GPIOS` (unsigned, from pico-sdk). Cast the bound to int
inline — the cast is exact since NUM_BANK0_GPIOS fits in int on both
RP2040 and RP2350.

Closes #2727.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR fixes three compiler warning families across RP2040/RP2350 platform code. PWM pin validation uses unsigned comparison casts, PIO program definitions are updated for Pico SDK v2+ struct fields, and optional SPI lane pins switch from unsigned to signed type with sentinel-value initialization for proper absence detection.

Changes

RP Platform Compiler Warnings and SDK v2+ Compatibility

Layer / File(s) Summary
PWM pin validation sign-compare fixes
src/platforms/arm/rp/pin_rp.hpp
Four PWM functions (analogWrite, setPwm16, setPwmFrequencyNative, getPwmFrequencyNative) cast NUM_BANK0_GPIOS to int in range checks, eliminating -Wsign-compare warnings while preserving the existing invalid-pin early-return behavior.
PIO program SDK v2+ field initialization
src/platforms/arm/rp/rpcommon/pio_gen.h, src/platforms/arm/rp/rpcommon/spi_hw_2_rp.cpp.hpp, src/platforms/arm/rp/rpcommon/spi_hw_4_rp.cpp.hpp, src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp
pio_program struct initializations across four files conditionally set .pio_version and .used_gpio_ranges to zero when building with PICO_SDK_VERSION_MAJOR >= 2, preventing uninitialized-field warnings and runtime issues on RP2350.
SPIQuadRP2040 optional lane pin type safety
src/platforms/arm/rp/rpcommon/spi_hw_4_rp.cpp.hpp
Optional data lane pin members (mData1Pin, mData2Pin, mData3Pin) change from u8 to i8 to support -1 as the "unused lane" sentinel, and constructor initialization changes from 0 to -1 to correctly express absent lanes in existing if (mDataXPin >= 0) presence checks, fixing -Wtype-limits warnings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • Issue #2727: The changes directly address all three warning families documented in the issue (pio_program missing field initializers for SDK 2.x, -Wsign-compare in pin_rp PWM functions, and -Wtype-limits in spi_hw_4_rp lane pin checks), along with the semantic fix for optional lane presence detection via signed type and sentinel initialization.

Poem

🐰 A hop through the warnings we go,
Sign-compare casts put warnings to rest,
SDK fields zero'd for SDK v2's zest,
Lane pins now signed, −1 marks unused flow,
Compiler smiles bright, as hygiene's in vogue! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the three main changes: SDK 2.x pio_program initialization, type-limits fixes, and sign-compare warnings.
Linked Issues check ✅ Passed All three objectives from issue #2727 are addressed: pio_program field initialization for SDK 2.x, spi_hw_4_rp lane-pin type changes with -1 sentinel, and pin_rp sign-compare casts.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #2727: pio_program SDK 2.x fields, spi_hw_4_rp lane-pin types and initialization, and pin_rp sign-compare fixes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2727-rp-hygiene

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 73eed71 into master Jun 4, 2026
6 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 4, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 4, 2026
@zackees
zackees deleted the fix/2727-rp-hygiene branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

RP common hygiene: pio_program missing pio_version/used_gpio_ranges (rp2350 SDK 2.x), -Wtype-limits in spi_hw_4_rp, -Wsign-compare in pin_rp

1 participant