.docs/io_refactoring_summary.md
Date: 2026-02-05 Status: ✅ Complete
Refactored the platform-specific I/O code in src/fl/stl/cstdio.cpp.hpp into a clean trampoline architecture, reducing code complexity and improving maintainability.
cstdio.cpp.hpp had ~400 lines with 8 functions × 7-8 platforms = 200+ lines of repetitive #ifdef blockscstdio.cpp.hpp now has ~200 lines, with platform dispatch delegated to trampoline filesCreated 9 new trampoline files in src/platforms/io/:
serial_begin.cpp.hpp - Serial initializationprint.cpp.hpp - String outputprintln.cpp.hpp - String output with newlineavailable.cpp.hpp - Input availability checkpeek.cpp.hpp - Peek at inputread.cpp.hpp - Read input byteflush.cpp.hpp - Flush output bufferwrite_bytes.cpp.hpp - Write raw bytesserial_ready.cpp.hpp - Serial ready statusEach trampoline:
#ifdef chainsMoved platform I/O headers to proper directories:
Before:
src/platforms/io_arduino.h
src/platforms/io_teensy.h
src/platforms/io_teensy_lc.h
src/platforms/io_native.h
src/platforms/io_null.h
After:
src/platforms/arduino/io_arduino.h
src/platforms/teensy/io_teensy.h
src/platforms/teensy/io_teensy_lc.h
src/platforms/native/io_native.h
src/platforms/shared/io_null.h (shared utility)
Created top-level dispatcher:
src/platforms/io.h - Central dispatch header that includes correct platform headerio_teensy.h to reference platforms/shared/io_null.hcstdio.cpp.hpp to include trampoline headers instead of inline #ifdef blockscstdio.cpp.hpp (log levels, test injection)#ifdef blockssrc/
├── fl/stl/
│ ├── cstdio.h # Public API declarations
│ └── cstdio.cpp.hpp # Top-level orchestration (200 lines, was 400)
└── platforms/
├── io.h # Top-level platform dispatcher (NEW)
├── io/ # Trampoline layer (NEW)
│ ├── README.md # Architecture documentation
│ ├── serial_begin.cpp.hpp
│ ├── print.cpp.hpp
│ ├── println.cpp.hpp
│ ├── available.cpp.hpp
│ ├── peek.cpp.hpp
│ ├── read.cpp.hpp
│ ├── flush.cpp.hpp
│ ├── write_bytes.cpp.hpp
│ └── serial_ready.cpp.hpp
├── wasm/
│ └── io_wasm.h # Existing
├── native/
│ └── io_native.h # Moved from platforms/
├── esp/
│ └── io_esp.h # Existing
├── avr/
│ └── io_avr.h # Existing
├── teensy/
│ ├── io_teensy.h # Moved from platforms/
│ └── io_teensy_lc.h # Moved from platforms/
├── arduino/
│ └── io_arduino.h # Moved from platforms/
└── shared/
└── io_null.h # Moved from platforms/ (shared utility)
The trampoline architecture supports 7 platforms in priority order:
__EMSCRIPTEN__)FASTLED_TESTING || __linux__ || __APPLE__ || _WIN32)ESP32 || ESP8266)__AVR__ && !ARDUINO_ARCH_MEGAAVR)__MKL26Z64__)__IMXRT1062__ || __MK66FX1M0__ || ...)Created comprehensive documentation:
src/platforms/io/README.md - Detailed architecture documentation
This trampoline pattern can be applied to other areas:
The I/O trampoline architecture refactoring successfully:
This pattern establishes a template for future platform abstraction work in FastLED.