FastLED 3.9.15
Loading...
Searching...
No Matches
file_system_sd.cpp.hpp
Go to the documentation of this file.
1
21
23#include "fl/stl/has_include.h"
24#include "fl/log/log.h"
25
26#ifdef FASTLED_TESTING
27// Stub filesystem maps to the host's real disk (for unit tests).
28// `make_sdcard_filesystem` strong impl lives in
29// `platforms/stub/fs_stub.cpp.hpp` (part of `platforms+.cpp.o`).
30// IWYU pragma: begin_keep
31#include "platforms/stub/fs_stub.hpp" // ok platform headers
32// IWYU pragma: end_keep
33#define FASTLED_HAS_SDCARD_IMPL 1
34
35#elif defined(FL_IS_WASM)
36// WASM filesystem backs onto the browser. `make_sdcard_filesystem`
37// strong impl lives in `platforms/wasm/fs_wasm.cpp.hpp`.
38// IWYU pragma: begin_keep
39#include "platforms/wasm/fs_wasm.h" // ok platform headers
40// IWYU pragma: end_keep
41#define FASTLED_HAS_SDCARD_IMPL 1
42
43#elif FL_HAS_INCLUDE(<SD.h>) && FL_HAS_INCLUDE(<fs.h>)
44// Arduino SD library is on the include path. `fs_sdcard_arduino.hpp`
45// provides an `inline` `make_sdcard_filesystem` definition that uses
46// the real Arduino `SD`/`FS` libraries. Pulling those into
47// `fl.system.sd+.cpp.o` is fine — the linker only links this TU when
48// the user calls beginSd, so non-SD sketches see none of it.
49#include "platforms/fs_sdcard_arduino.hpp"
50#define FASTLED_HAS_SDCARD_IMPL 1
51
52#else
53#define FASTLED_HAS_SDCARD_IMPL 0
54#endif
55
56namespace fl {
57
58#if !FASTLED_HAS_SDCARD_IMPL
59// Weak fallback when no platform-specific SD implementation is
60// available in the build environment. Returns nullptr so
61// `FileSystem::beginSd()` cleanly returns `false`.
62FL_LINK_WEAK FsImplPtr make_sdcard_filesystem(int cs_pin) {
63 FASTLED_UNUSED(cs_pin);
64 return FsImplPtr();
65}
66#endif
67
68bool FileSystem::beginSd(int cs_pin) {
70 if (!mFs) {
71 return false;
72 }
73 mFs->begin();
74 return true;
75}
76
77} // namespace fl
bool beginSd(int cs_pin)
FsImplPtr mFs
Definition file_system.h:82
Centralized logging categories for FastLED hardware interfaces and subsystems.
FsImplPtr make_sdcard_filesystem(int cs_pin)
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_UNUSED(x)
#define FL_LINK_WEAK