Skip to content

fix(channels): guard Bus enum against CMSIS UART/SPI/I2S register macros - #2575

Merged
zackees merged 1 commit into
masterfrom
fix/sam3x8e-bus-enum-macro-collision
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/sam3x8e-bus-enum-macro-collision

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Every sam3x8e_due and sam3x8e_due (digix merged) workflow on master fails before any code is compiled: Atmel CMSIS defines UART / SPI / I2S as bare-name peripheral pointer macros, and enum class Bus { ..., SPI, I2S, UART, ... } in fl/channels/bus.h is preprocessor-expanded to garbage.
  • Fix: wrap the enum definition and the bus_priorities.h constexpr lookup with #pragma push_macro / #undef / #pragma pop_macro for the three colliding names. pop_macro at the end restores CMSIS's original register macros for downstream TUs.
  • No public API change — fl::Bus::SPI / fl::Bus::I2S / fl::Bus::UART still mean exactly what they did.
  • ESP32 unaffected (register types there are typedefs, not bare-name macros).

Fixes #2574

Test plan

  • bash lint clean (cpp_linting / meson_linting / etc.).
  • Host channels test still passes: bash test fl_channels_bus_traits --cpp.
  • CI: sam3x8e_due and sam3x8e_due (digix merged) workflows should now reach actual compilation.

Generated with Claude Code (https://claude.com/claude-code)

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Resolved a critical compatibility issue that affected certain microcontroller platforms (e.g., Sam3X8E), where system-level register macros conflicted with the Bus enumeration's internal names, causing build failures. The library now properly isolates and manages these platform-specific definitions to ensure reliable compilation across all supported hardware architectures.

Review Change Stack

On SAM3X8E (Arduino Due), the CMSIS header `sam3x8e.h` defines
peripheral pointer macros:

    #define UART ((Uart *)0x400E0800U)
    #define SPI  ((Spi  *)0x40008000U)
    // ...

These get pulled in transitively through `platforms/is_platform.h`
before `fl/channels/bus.h` declares:

    enum class Bus : fl::u8 {
        ..., SPI, I2S, UART, ...
    };

The preprocessor doesn't understand `enum class` scoping — bare
`UART`/`SPI`/`I2S` macro-expand inside the enum body, producing:

    sam3x8e.h:489:20: error: expected identifier before '(' token
    bus.h:54:5: note: in expansion of macro 'UART'

cascading to "'Bus' was not declared in this scope" for every TU that
includes bus.h. Every `sam3x8e_due` example build on master fails this
way before any code is compiled.

Fix: wrap both `bus.h` (enum definition + DefaultBus specializations +
busName() switch) and `bus_priorities.h` (constexpr lookup over
`Bus::SPI` / `Bus::I2S` / `Bus::UART`) with
`#pragma push_macro` / `#undef` / `#pragma pop_macro` for the three
colliding names. `pop_macro` at the end restores CMSIS's original
register macros for any downstream TU that needs them as register
pointers.

GCC, Clang, MSVC, IAR, and ARM Compiler all support the
push_macro/pop_macro pragmas. No public API change — `fl::Bus::SPI`,
`fl::Bus::I2S`, `fl::Bus::UART` still mean exactly what they did.

ESP32 is unaffected (its register types are typedefs, not bare-name
macros). All other non-platform-specific code paths that mention these
enumerators are inside `bus.h` / `bus_priorities.h` or under
`platforms/esp/32/` (ESP32-only — no CMSIS-SAM collision).

Fixes #2574
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e1b335fc-0777-4cb0-aed8-21010210689e

📥 Commits

Reviewing files that changed from the base of the PR and between b2254c1 and ba8a732.

📒 Files selected for processing (2)
  • src/fl/channels/bus.h
  • src/fl/channels/bus_priorities.h

📝 Walkthrough

Walkthrough

This PR adds preprocessor macro guards to src/fl/channels/bus.h and src/fl/channels/bus_priorities.h to prevent platform-specific register macros (UART, SPI, I2S) from expanding inside fl::Bus enum token names, which would corrupt the enum definition on platforms like Sam3X8E that define these as CMSIS register macros.

Changes

Macro guards for Bus enum definitions

Layer / File(s) Summary
Bus enum token macro guards
src/fl/channels/bus.h, src/fl/channels/bus_priorities.h
Pushes and undefines UART, SPI, and I2S macros before Bus enum declarations, then restores the original macro definitions after the definitions complete, preventing platform register macro expansion from corrupting enum member tokens (Bus::UART, Bus::SPI, Bus::I2S).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2429: Main PR introduces the fl::Bus enum whose token names are now protected by macro guards in this PR.
  • FastLED/FastLED#2451: Modifies src/fl/channels/bus.h to add templated dispatch logic (busName) that depends on these exact enum tokens being preserved from macro expansion.
  • FastLED/FastLED#2472: Refactors driver selection to heavily use typed fl::Bus::SPI/etc. enum values, which now require these macro guards to compile correctly on all platforms.

Poem

🐰 Ah, pesky macros scheme and plot,
To twist our UART, SPI lot!
With push and pop and strategic undef,
Our Bus enum tokens now are blessed! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding preprocessor guards to prevent CMSIS register macros (UART/SPI/I2S) from corrupting the Bus enum definition on SAM3X8E platforms.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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/sam3x8e-bus-enum-macro-collision

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 93d9c98 into master May 30, 2026
6 of 8 checks passed
@zackees
zackees deleted the fix/sam3x8e-bus-enum-macro-collision branch May 30, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sam3x8e_due: every example fails — Bus enum collides with CMSIS UART/SPI/I2S register macros

1 participant