roo_io
API Documentation for roo_io
Loading...
Searching...
No Matches
sdfs.h
Go to the documentation of this file.
1#pragma once
2
3// Filesystem based on the Arduino SD library. On ESP32, it bypasses most of
4// the Arduino layer and uses the underlying VFS filesystem directly.
5//
6// Supports dynamic mounting, and software read-only mounting.
7//
8// On ESP32, very similar functionality is provided by the
9// roo_io::ArduinoSdSpiFs class, which uses the lower-level sd_diskio interface
10// directly, instead of going through the Arduino SD object at all.
11
12#ifdef ARDUINO
13
14#include <Arduino.h>
15#include <SD.h>
16
17#if (defined ESP32 || defined ROO_TESTING)
18#include <SPI.h>
19
21#else
23#endif
24
25namespace roo_io {
26
27#if (defined ESP32 || defined ROO_TESTING)
28
30 public:
32 void setSPI(decltype(::SPI)& spi) { spi_ = &spi; }
33
34 MediaPresence checkMediaPresence() override;
35
36 protected:
38
39 ArduinoSdFs(uint8_t cs_pin = SS, decltype(::SD)& sd = ::SD,
40 decltype(::SPI)& spi = ::SPI, uint32_t freq = 20000000);
41
42 MountImpl::MountResult mountImpl(std::function<void()> unmount_fn) override;
43
44 void unmountImpl() override;
45
47
48 decltype(::SD)& sd_;
49 decltype(::SPI)* spi_;
50};
51
52#else
53
54class ArduinoSdFs : public Filesystem {
55 public:
56 MediaPresence checkMediaPresence() override;
57
59
60 bool readOnly() const { return read_only_; }
61 void setReadOnly(bool read_only) { read_only_ = read_only; }
62
63 protected:
65
67
68 MountImpl::MountResult mountImpl(std::function<void()> unmount_fn) override;
69
70 void unmountImpl() override;
71
73
74 decltype(::SD)& sd_;
75#if defined (ARDUINO_ARCH_RP2040)
76 decltype(::SDFS)& sdfs_;
77#endif
78 bool read_only_;
79};
80
81#endif // ESP32
82
83extern ArduinoSdFs SD;
84
85} // namespace roo_io
86
87#endif // ARDUINO
Definition byte.h:6
roo::basic_string_view< CharT, Traits > basic_string_view
Definition string_view.h:8