Repository navigation
fix(arm): correct apply_scale shift in m0clockless_c.h (#3504) - #3737
Conversation
Without a repo-root pin, soldr resolves rustc from PATH. On hosts where a non-rustup Rust shadows rustup (e.g. chocolatey's x86_64-pc-windows-gnu build), soldr still canonicalizes the build target to x86_64-pc-windows-msvc and every crate fails with E0463 (can't find crate for `std`). Pinning the toolchain routes resolution through rustup, which always carries the host target's std. Co-Authored-By: Claude <[email protected]>
apply_scale() returned `(pixel * scale) >> 16`, but the scale factors in M0ClocklessData.s[] are plain 8-bit values (0..255, or 1..256 under FASTLED_SCALE8_FIXED). The product therefore never reached 65536, so the function returned 0 for every pixel and the C++ M0 driver output all black. The assembly it was translated from is scale4 + swapbbn1 taken together: scale4 leaves the raw product in bn, then swapbbn1's `lsl b, bn, #16` puts product bit 15 in b bit 31 -- the first bit qlo4 shifts into the carry. The byte the assembly clocks out is product bits 15:8, i.e. scale8 semantics. Shift by 8 instead, and document the scale4/swapbbn1 pairing so the two implementations no longer look like they disagree. Fixes #3504 Co-Authored-By: Claude <[email protected]>
📝 WalkthroughWalkthroughThe PR pins Rust toolchain resolution to stable and changes ARM M0 clockless scaling to interpret stored factors as 8-bit values, extracting scaled output with ChangesRust toolchain pin
ARM scaling correction
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
rust-toolchain.toml (1)
12-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPin an exact Rust release if reproducibility is required.
channel = "stable"selects the moving stable channel rather than a specific compiler version, so lint results can change as Rust releases advance. Rustup supports exact version channels; consider pinning the version used by CI and updating it deliberately. (rust-lang.github.io)🤖 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 `@rust-toolchain.toml` at line 12, Update the rust-toolchain.toml channel setting from the moving “stable” channel to the exact Rust release used by CI, and maintain that pinned version through deliberate updates.
🤖 Prompt for all review comments with 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.
Inline comments:
In `@src/platforms/arm/common/m0clockless_c.h`:
- Around line 337-340: Move the apply_scale function definition out of
m0clockless_c.h into its corresponding .cpp.hpp or .impl.hpp implementation
file, preserving its FL_FORCE_INLINE qualifier and current scale8 behavior. Keep
only the necessary declaration or usage-facing interface in the header.
---
Nitpick comments:
In `@rust-toolchain.toml`:
- Line 12: Update the rust-toolchain.toml channel setting from the moving
“stable” channel to the exact Rust release used by CI, and maintain that pinned
version through deliberate updates.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 51f4d3d0-5116-4167-9fdc-0dcc12716ff4
📒 Files selected for processing (2)
rust-toolchain.tomlsrc/platforms/arm/common/m0clockless_c.h
| FL_FORCE_INLINE fl::u8 apply_scale(fl::u8 pixel, fl::u32 scale_factor) FL_NO_EXCEPT { | ||
| fl::u32 result = (fl::u32)pixel * scale_factor; | ||
| // Extract high byte (bits 23:16) as the scaled result | ||
| return (fl::u8)(result >> 16); | ||
| // Extract bits 15:8 as the scaled result (scale8 semantics) | ||
| return (fl::u8)(result >> 8); |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Move this function definition out of the .h file.
apply_scale is defined directly in src/platforms/arm/common/m0clockless_c.h. Move the implementation to the corresponding .cpp.hpp or .impl.hpp file while preserving FL_FORCE_INLINE; the updated shift itself matches the intended scale8 behavior.
As per path instructions, headers under src/**/*.h must not contain function definitions; implementations belong in .cpp.hpp or .impl.hpp.
🤖 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 `@src/platforms/arm/common/m0clockless_c.h` around lines 337 - 340, Move the
apply_scale function definition out of m0clockless_c.h into its corresponding
.cpp.hpp or .impl.hpp implementation file, preserving its FL_FORCE_INLINE
qualifier and current scale8 behavior. Keep only the necessary declaration or
usage-facing interface in the header.
Source: Path instructions
Summary
Fixes #3504 —
apply_scale()insrc/platforms/arm/common/m0clockless_c.halways returned 0, blanking every pixel on the C++ M0 clockless path.Root cause. The function computed
(pixel * scale_factor) >> 16. ButM0ClocklessData.s[]holds plain 8-bit color-correction values (pixels.mColorAdjustment.premixed[i], 0..255 — or 1..256 after theFASTLED_SCALE8_FIXEDpre-increment). The product tops out at255 * 256 == 65280 < 65536, so the shift discarded everything.Why the translation went wrong. The C++ file was derived from
m0clockless_asm.h, where the scaling is split across two macros.scale4leaves the raw product inbn;swapbbn1then doeslsl b, bn, #16, which places product bit 15 intobbit 31 — exactly the bitqlo4shifts into the carry first. So the byte the assembly clocks out is product bits 15:8, i.e. plainscale8semantics. The C++ port foldedswapbbn1into a no-op (prepare_byte_for_output) but kept a>> 16that only made sense for a 16.16 fixed-point scale that this driver never used.Fix: shift by 8, and document the
scale4/swapbbn1pairing so the two implementations no longer read as if they disagree.Testing
bash lint— greenbash compile lpc845 --examples Blink— succeeds (LPC845 is the platform that selectsm0clockless_c.hvialed_sysdefs_arm_lpc.h); flash 17.68KB, RAM 5.10KBbash test --cpp— greenNo host unit test: the header is ARM-only (inline
MRS/cpsidasm, CMSISSysTick) and cannot be included from the host test build. The fix is verified against the assembly it mirrors, as traced above.Note
The issue also asks whether this generated-from-asm C++ variant should exist at all, given the hand-written drivers under
arm/k66etc. That is a larger design question and is deliberately out of scope here — this PR only fixes the reported blanking bug.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores