Repository navigation
refactor(spi): wrap FlexIO/ObjectFLED internals in private namespaces - #3434
Conversation
… (no prefix) Per user directive 2026-06-27 "when in doubt use private namespaces" -- follow-up cleanup for the prefix-rename workaround that landed with #3431 / #3432. Both `flexio_spi_mode.cpp.hpp` and `objectfled_spi_mode.cpp.hpp` now wrap their file-static state + private helpers in matching named namespaces: - fl::detail::flexio_spi_internal - fl::detail::objectfled_spi_internal Each public API function (those in the .h header) opens with `using namespace detail::xxx_spi_internal;` so the bodies reference the private state without the namespace prefix. The two drivers' identically- named symbols (sSpiCurrentPins, sSpiDmaChannel, ...) now live in different namespaces, so they don't collide in the unity build (fl/build/platforms+.cpp). The ObjectFLED side drops the `sOfSpi*` / `kOfSpi*` / `of_spi_*` prefix that was the previous workaround for the unity-build collision -- the private namespace handles it cleanly now. Hardware-verified on Teensy 4.1 (COM20) after the refactor: - flexioSpiSelfTest: 3/3 pass (wait_ms=0) - objectfledSpiSelfTest: 3/3 pass (wait_ms=5 = drain only) Build / lint clean (bash test --cpp / bash lint / bash compile teensy41). Refs #3428, #3431, #3432. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughBoth Teensy 4.x SPI driver translation units ( ChangesFlexIO SPI: Private Namespace Isolation
ObjectFLED SPI: Namespace Isolation, Renaming, and Behavioral Hardening
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ 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 |
Summary
Follow-up to #3431 / #3432. Per user directive 2026-06-27 "when in doubt use private namespaces", replace the
sOfSpi*/kOfSpi*/of_spi_*prefix-rename workaround for the unity-build collision with the more idiomatic private named namespace approach.What changes
static ... sSpiCurrentPins; sSpiDmaChannel; ...atfl::scope (worked because it was first to land)namespace fl::detail::flexio_spi_internal { ... }static ... sOfSpiCurrentPins; sOfSpiDmaChannel; ...atfl::scope (prefixed to avoid collision with FlexIO in the same unity TU)namespace fl::detail::objectfled_spi_internal { ... }, prefix droppedEach public API function (the ones in the
.hheaders) opens its body withusing namespace detail::xxx_spi_internal;so call-sites read naturally. The two drivers' identically-named statics now live in different named namespaces — no collision in the unity build (fl/build/platforms+.cpp).Why not a single anonymous namespace per file
Per [C++ namespace.unnamed], multiple
namespace { ... }declarations within the same TU merge into one anonymous namespace. In a unity TU that pulls in both files, anonymous-namespace contents would still collide. Named-and-distinct is the only collision-free option short of file isolation (which the project's unity-build strategy doesn't grant).Hardware verification (Teensy 4.1, COM20)
flexioSpiSelfTest— 3/3 pass (wait_ms=0)objectfledSpiSelfTest— 3/3 pass (wait_ms=5 = drain wait only)Behavior is byte-equivalent before/after; this is a pure cleanup refactor.
Test plan
bash test --cpp— passesbash lint --cppcleanbash compile teensy41 --examples AutoResearchsucceedsRefs #3428, #3431, #3432.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Refactor