Repository navigation
fix(rp): SDK 2.x pio_program init + type-limits + sign-compare hygiene (#2727) - #2740
Conversation
#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]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis 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. ChangesRP Platform Compiler Warnings and SDK v2+ Compatibility
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
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_programmissing initializer forpio_version/used_gpio_rangespico-sdk 2.x(RP2350) addedpio_versionandused_gpio_rangestostruct pio_program. FastLED's fourpio_programliterals omit them, triggering-Wmissing-field-initializersand (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 >= 2guards in all 4 literals:src/platforms/arm/rp/rpcommon/pio_gen.h:48src/platforms/arm/rp/rpcommon/spi_hw_2_rp.cpp.hpp:88src/platforms/arm/rp/rpcommon/spi_hw_4_rp.cpp.hpp:90src/platforms/arm/rp/rpcommon/spi_hw_8_rp.cpp.hpp:94Preserves current behavior, silences the warning, and documents the field-init choice in one place to revisit when RP2350-SDK ergonomics solidify.
H2.
-Wtype-limitsalways-true onmData[1-3]Pin >= 0In
spi_hw_4_rp.cpp.hppthe data-lane pin presence checks read:But the fields are
u8, so the comparisons are tautologies. TheSpiHw4::Configsource fields arei8with-1as the "unused lane" sentinel (seesrc/platforms/shared/spi_hw_4.h:44-46), so the intent was clearly "lane is configured". Currently broken: the storage truncates-1to0xFFand every lane is treated as active in the quad-mode check.Fix: change
mData1Pin / mData2Pin / mData3Pinfromu8toi8so-1round-trips. Update constructor initializers from0to-1to match the Config defaults.mData0PinandmClockPinstayu8(always required, never sentinel-valued). Lane-presence checks now work as intended.H3.
-Wsign-compareinpin_rp.hpp(int pinvs unsignedNUM_BANK0_GPIOS)Four loop-bound checks in
pin_rp.hppcompareint pinagainstNUM_BANK0_GPIOS(unsigned from pico-sdk). Cast the bound tointinline — the cast is exact sinceNUM_BANK0_GPIOSfits ininton both RP2040 and RP2350.Test plan
bash lintclean🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Refactor