Generate an implementation contract for a FastLED change. The contract must be reviewed before any code is written.
$ARGUMENTS
Why Use a Contract
FastLED runs on 100+ microcontroller platforms. A change that seems simple can break:
- Platform-specific driver behavior (ESP32, Teensy, AVR, STM32, RP2040, nRF52...)
- Public API compatibility (users pin to specific versions)
- Timing-sensitive LED protocols (a single wrong bit ruins the strip)
- Build-system portability (meson, fbuild, Arduino IDE all involved)
The contract documents what changes, what risks exist, and how to prove it works — before a line of code is written.
Steps
1. Understand the Request
Determine:
- What is the requested change? (feature / bug fix / refactor / platform port / driver addition)
- Which LED chipsets or platforms are affected?
- What is the expected behavior after the change?
- Are there hardware constraints? (specific ESP32 variant, specific LED protocol, pin count)
- Is this a public API change or internal implementation?
2. Define Scope
Document:
- Summary: One-paragraph description of the change
- Non-goals: What this change explicitly does NOT do
- Affected files: Every file to be created, modified, or deleted
- APIs touched: Public functions, types, or macros that will change
3. Assess Platform Impact
For each affected area, evaluate impact:
| Platform Area |
Impact |
Notes |
| AVR (Arduino Uno/Mega/Nano) |
[None/Low/Med/High] |
RAM-constrained, no FPU |
| ESP32 (all variants) |
[None/Low/Med/High] |
RMT/I2S/SPI/PARLIO drivers |
| Teensy (3.x, 4.x) |
[None/Low/Med/High] |
ARM Cortex-M, bitbang & DMA |
| RP2040 (Raspberry Pi Pico) |
[None/Low/Med/High] |
PIO-based drivers |
| STM32 |
[None/Low/Med/High] |
HAL dependencies |
| WASM (web browser target) |
[None/Low/Med/High] |
Emulation only |
| nRF52 |
[None/Low/Med/High] |
BLE coexistence |
4. Assess Risks
Evaluate each risk category:
Timing Risks (critical for LED protocols):
- Does the change affect bit-timing (T0H, T1H, reset pulse)?
- Could added latency cause LED flicker or color errors?
- Is the change tested on hardware, not just WASM/emulation?
API Compatibility Risks:
- Does this change any public header or function signature?
- Will existing user sketches compile without modification?
- Is a deprecation path needed?
Memory Risks:
- Does this add to SRAM usage (critical for AVR with 2KB)?
- Does this add to flash usage?
- Are heap allocations properly checked for NULL?
Concurrency Risks (ESP32 / RTOS platforms):
- Shared state accessed from multiple tasks or ISR?
- DMA buffer lifetime during transfer?
- Interrupt-safe API used where required?
Build System Risks:
- Does this require changes to meson.build, library.properties, or component.mk?
- Is the new code compiled only on relevant platforms (guards correct)?
5. Define Test Plan
Specify the test layers that apply:
| Layer |
Applies |
Tests |
Host unit tests (bash test) |
Always |
Logic, math, data structures |
WASM compile check (bash compile wasm) |
Always |
Catches most compile errors |
Platform compile (bash compile <platform>) |
If driver code |
Catches platform-specific errors |
Hardware validation (bash autoresearch) |
If driver or timing change |
Only definitive proof for LED output |
List specific test cases:
- Positive: Expected behavior with valid inputs
- Negative: Error handling, boundary values
- Regression: Existing tests that must still pass
6. Define Rollback Strategy
Document:
- How to revert the change (git revert, feature flag, etc.)
- Whether any NVS/EEPROM data migration is needed
- Whether users need to update their code if the API changes
7. Generate Contract Document
# Implementation Contract: [Title]
## Change Summary
[One-paragraph description of what changes and why]
## Non-Goals
- [What this explicitly does NOT include]
## Affected Files
| File | Action | Description |
|------|--------|-------------|
| src/platforms/esp/32/foo.h | MODIFY | [What changes] |
| src/fl/bar.h | CREATE | [Purpose] |
## APIs Touched
- `FastLED.addLeds<...>()` — [How it changes, if at all]
- `CRGB` — [Impact]
## Platform Impact
| Platform | Impact | Rationale |
|---------|--------|-----------|
| AVR | None | No new code on AVR path |
| ESP32 | High | New RMT encoder implementation |
| ... | ... | ... |
## Risk Assessment
### Timing: [LOW / MED / HIGH]
[Details — will LED protocols still work?]
### API Compatibility: [LOW / MED / HIGH]
[Details — will existing user code still compile and run?]
### Memory: [LOW / MED / HIGH]
[Details — RAM/flash impact, especially for AVR]
### Concurrency: [LOW / MED / HIGH]
[Details — ISR safety, DMA lifetime, task interaction]
### Build System: [LOW / MED / HIGH]
[Details — meson.build, guards, new dependencies]
## Test Plan
- [ ] Host unit test: [test name / description]
- [ ] WASM compile: `bash compile wasm --examples Blink`
- [ ] Platform compile: `bash compile <platform>`
- [ ] Hardware validation: [specific test on which board]
- [ ] Regression: `bash test --cpp` — all existing tests pass
## Rollback Strategy
[Steps to safely revert this change]
## Acceptance Criteria
- [ ] [Specific, measurable criterion]
- [ ] All platform compiles pass
- [ ] No regressions in host test suite
- [ ] [Hardware test evidence if applicable]
Rules
- Never skip the contract for non-trivial changes. A "small" change to a shared header can break 100 platform builds.
- Define platform impact explicitly. Unknown = HIGH risk. Investigate before marking LOW.
- Hardware validation is required for any driver or timing change. WASM compilation is not sufficient proof.
- Public API changes need a compatibility note. FastLED users should not be surprised by breaking changes.
- Update the contract if scope changes. Scope creep must be re-reviewed.
What Makes a Good Acceptance Criterion
Good: "WS2812 output on ESP32 shows correct colors at 1000 LEDs without flicker, confirmed by hardware observation"
Bad: "It works"
Good: "All existing host tests pass with bash test --cpp"
Bad: "Tests pass"
Good: "Sketch compiles on Arduino IDE 2.x with no warnings"
Bad: "Compiles somewhere"
1---2name: feature-contract3description: Generate a structured implementation contract before making any code changes to FastLED. Defines scope, affected files, API changes, platform impact, risk assessment, and test plan. Use before implementing any feature, bug fix, driver addition, or refactoring.4---56Generate an implementation contract for a FastLED change. The contract must be reviewed before any code is written.78$ARGUMENTS910## Why Use a Contract1112FastLED runs on 100+ microcontroller platforms. A change that seems simple can break:13- Platform-specific driver behavior (ESP32, Teensy, AVR, STM32, RP2040, nRF52...)14- Public API compatibility (users pin to specific versions)15- Timing-sensitive LED protocols (a single wrong bit ruins the strip)16- Build-system portability (meson, fbuild, Arduino IDE all involved)1718The contract documents what changes, what risks exist, and how to prove it works — before a line of code is written.1920## Steps2122### 1. Understand the Request2324Determine:25- What is the requested change? (feature / bug fix / refactor / platform port / driver addition)26- Which LED chipsets or platforms are affected?27- What is the expected behavior after the change?28- Are there hardware constraints? (specific ESP32 variant, specific LED protocol, pin count)29- Is this a public API change or internal implementation?3031### 2. Define Scope3233Document:34- **Summary**: One-paragraph description of the change35- **Non-goals**: What this change explicitly does NOT do36- **Affected files**: Every file to be created, modified, or deleted37- **APIs touched**: Public functions, types, or macros that will change3839### 3. Assess Platform Impact4041For each affected area, evaluate impact:4243| Platform Area | Impact | Notes |44|--------------|--------|-------|45| AVR (Arduino Uno/Mega/Nano) | [None/Low/Med/High] | RAM-constrained, no FPU |46| ESP32 (all variants) | [None/Low/Med/High] | RMT/I2S/SPI/PARLIO drivers |47| Teensy (3.x, 4.x) | [None/Low/Med/High] | ARM Cortex-M, bitbang & DMA |48| RP2040 (Raspberry Pi Pico) | [None/Low/Med/High] | PIO-based drivers |49| STM32 | [None/Low/Med/High] | HAL dependencies |50| WASM (web browser target) | [None/Low/Med/High] | Emulation only |51| nRF52 | [None/Low/Med/High] | BLE coexistence |5253### 4. Assess Risks5455Evaluate each risk category:5657**Timing Risks** (critical for LED protocols):58- Does the change affect bit-timing (T0H, T1H, reset pulse)?59- Could added latency cause LED flicker or color errors?60- Is the change tested on hardware, not just WASM/emulation?6162**API Compatibility Risks**:63- Does this change any public header or function signature?64- Will existing user sketches compile without modification?65- Is a deprecation path needed?6667**Memory Risks**:68- Does this add to SRAM usage (critical for AVR with 2KB)?69- Does this add to flash usage?70- Are heap allocations properly checked for NULL?7172**Concurrency Risks** (ESP32 / RTOS platforms):73- Shared state accessed from multiple tasks or ISR?74- DMA buffer lifetime during transfer?75- Interrupt-safe API used where required?7677**Build System Risks**:78- Does this require changes to meson.build, library.properties, or component.mk?79- Is the new code compiled only on relevant platforms (guards correct)?8081### 5. Define Test Plan8283Specify the test layers that apply:8485| Layer | Applies | Tests |86|-------|---------|-------|87| Host unit tests (`bash test`) | Always | Logic, math, data structures |88| WASM compile check (`bash compile wasm`) | Always | Catches most compile errors |89| Platform compile (`bash compile <platform>`) | If driver code | Catches platform-specific errors |90| Hardware validation (`bash autoresearch`) | If driver or timing change | Only definitive proof for LED output |9192List specific test cases:93- **Positive**: Expected behavior with valid inputs94- **Negative**: Error handling, boundary values95- **Regression**: Existing tests that must still pass9697### 6. Define Rollback Strategy9899Document:100- How to revert the change (git revert, feature flag, etc.)101- Whether any NVS/EEPROM data migration is needed102- Whether users need to update their code if the API changes103104### 7. Generate Contract Document105106```markdown107# Implementation Contract: [Title]108109## Change Summary110[One-paragraph description of what changes and why]111112## Non-Goals113- [What this explicitly does NOT include]114115## Affected Files116| File | Action | Description |117|------|--------|-------------|118| src/platforms/esp/32/foo.h | MODIFY | [What changes] |119| src/fl/bar.h | CREATE | [Purpose] |120121## APIs Touched122- `FastLED.addLeds<...>()` — [How it changes, if at all]123- `CRGB` — [Impact]124125## Platform Impact126| Platform | Impact | Rationale |127|---------|--------|-----------|128| AVR | None | No new code on AVR path |129| ESP32 | High | New RMT encoder implementation |130| ... | ... | ... |131132## Risk Assessment133134### Timing: [LOW / MED / HIGH]135[Details — will LED protocols still work?]136137### API Compatibility: [LOW / MED / HIGH]138[Details — will existing user code still compile and run?]139140### Memory: [LOW / MED / HIGH]141[Details — RAM/flash impact, especially for AVR]142143### Concurrency: [LOW / MED / HIGH]144[Details — ISR safety, DMA lifetime, task interaction]145146### Build System: [LOW / MED / HIGH]147[Details — meson.build, guards, new dependencies]148149## Test Plan150- [ ] Host unit test: [test name / description]151- [ ] WASM compile: `bash compile wasm --examples Blink`152- [ ] Platform compile: `bash compile <platform>`153- [ ] Hardware validation: [specific test on which board]154- [ ] Regression: `bash test --cpp` — all existing tests pass155156## Rollback Strategy157[Steps to safely revert this change]158159## Acceptance Criteria160- [ ] [Specific, measurable criterion]161- [ ] All platform compiles pass162- [ ] No regressions in host test suite163- [ ] [Hardware test evidence if applicable]164```165166## Rules1671681. **Never skip the contract for non-trivial changes.** A "small" change to a shared header can break 100 platform builds.1692. **Define platform impact explicitly.** Unknown = HIGH risk. Investigate before marking LOW.1703. **Hardware validation is required for any driver or timing change.** WASM compilation is not sufficient proof.1714. **Public API changes need a compatibility note.** FastLED users should not be surprised by breaking changes.1725. **Update the contract if scope changes.** Scope creep must be re-reviewed.173174## What Makes a Good Acceptance Criterion175176Good: "WS2812 output on ESP32 shows correct colors at 1000 LEDs without flicker, confirmed by hardware observation"177Bad: "It works"178179Good: "All existing host tests pass with `bash test --cpp`"180Bad: "Tests pass"181182Good: "Sketch compiles on Arduino IDE 2.x with no warnings"183Bad: "Compiles somewhere"