FastLED 3.10.8
Loading...
Searching...
No Matches
file_system_sd.cpp.hpp
Go to the documentation of this file.
1
21
22#include "fl/fs/fs.h"
23#include "fl/stl/has_include.h"
24#include "fl/log/log.h"
25#include "platforms/is_platform.h"
26
27#ifdef FASTLED_TESTING
28// Stub filesystem maps to the host's real disk (for unit tests).
29// `make_sdcard_filesystem` strong impl lives in
30// `platforms/stub/fs_stub.cpp.hpp` (part of `platforms+.cpp.o`).
31// IWYU pragma: begin_keep
32#include "platforms/stub/fs_stub.hpp" // ok platform headers
33// IWYU pragma: end_keep
34#define FASTLED_HAS_SDCARD_IMPL 1
35
36#elif defined(FL_IS_WASM)
37// WASM filesystem backs onto the browser. `make_sdcard_filesystem`
38// strong impl lives in `platforms/wasm/fs_wasm.cpp.hpp`.
39// IWYU pragma: begin_keep
40#include "platforms/wasm/fs_wasm.h" // ok platform headers
41// IWYU pragma: end_keep
42#define FASTLED_HAS_SDCARD_IMPL 1
43
44#elif defined(FL_IS_TEENSY)
45// Teensy's Arduino SD wrapper declares a process-wide `SD` object. Keep
46// FastLED's optional filesystem on the SdFat path instead, whose state is
47// privately owned and lazy behind an implementation-only fl::Singleton.
48// IWYU pragma: begin_keep
49#include "platforms/arm/teensy/sdfat/fs_sdfat_teensy.h" // ok platform headers
50// IWYU pragma: end_keep
51#include "fl/stl/singleton.h"
52
53namespace fl { namespace platforms { namespace teensy {
54
55SdFatState &sdfat_state() FL_NO_EXCEPT {
57}
58
59} } } // namespace fl::platforms::teensy
60
61#define FASTLED_HAS_SDCARD_IMPL 1
62
63#elif FL_HAS_INCLUDE(<SD.h>) && FL_HAS_INCLUDE(<fs.h>)
64// Arduino SD library is on the include path. `fs_sdcard_arduino.cpp.hpp`
65// provides an `inline` `make_sdcard_filesystem` definition that uses
66// the real Arduino `SD`/`FS` libraries. Pulling those into
67// `fl.system.sd+.cpp.o` is fine — the linker only links this TU when
68// the user calls beginSd, so non-SD sketches see none of it.
69#define FASTLED_HAS_SDCARD_IMPL 1
70
71#else
72#define FASTLED_HAS_SDCARD_IMPL 0
73#endif
74
75namespace fl {
76
77#if !FASTLED_HAS_SDCARD_IMPL
78// Weak fallback when no platform-specific SD implementation is
79// available in the build environment. Returns nullptr so
80// `FileSystem::beginSd()` cleanly returns `false`.
82 FASTLED_UNUSED(cs_pin);
83 return FsImplPtr();
84}
85#endif
86
89 if (!mFs) {
90 return false;
91 }
92 mFs->begin();
93 return true;
94}
95
97 FileSystem fs;
98 fs.beginSd(cs_pin);
99 return fs;
100}
101
102} // namespace fl
static FileSystem sd(int cs_pin) FL_NO_EXCEPT
bool beginSd(int cs_pin) FL_NO_EXCEPT
FsImplPtr mFs
Definition fs.h:106
FileSystem() FL_NO_EXCEPT
Definition fs.cpp.hpp:109
static T & instance() FL_NO_EXCEPT
Definition singleton.h:41
Centralized logging categories for FastLED hardware interfaces and subsystems.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
FsImplPtr make_sdcard_filesystem(int cs_pin) FL_NO_EXCEPT
Base definition for an LED controller.
#define FASTLED_UNUSED(x)
#define FL_NO_EXCEPT
#define FL_LINK_WEAK