Skip to content

Commit 2082737

Browse files
authored
feat(AudioSourceSD): pass an spi instance (#1717)
* fix typo * pass your own spi instance * dont make use of `pinSS()` due to compatibility issues
1 parent 1d487ba commit 2082737

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/AudioLibs/AudioSourceSD.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,31 @@ class AudioSourceSD : public AudioSource {
3636
/// Default constructor
3737
AudioSourceSD(const char *startFilePath = "/", const char *ext = ".mp3", int chipSelect = PIN_CS, bool setupIndex=true) {
3838
start_path = startFilePath;
39-
exension = ext;
39+
extension = ext;
4040
setup_index = setupIndex;
41+
spi = &SPI;
42+
cs = chipSelect;
43+
}
44+
45+
// Pass your own spi instance, in case you need a dedicated one
46+
AudioSourceSD(const char *startFilePath = "/", const char *ext = ".mp3", int chipSelect = PIN_CS, SPIClass &spiInstance = SPI, bool setupIndex=true) {
47+
start_path = startFilePath;
48+
extension = ext;
49+
setup_index = setupIndex;
50+
spi = &spiInstance;
4151
cs = chipSelect;
4252
}
4353

4454
virtual void begin() override {
4555
TRACED();
4656
if (!is_sd_setup) {
47-
while (!SD.begin(cs)) {
48-
LOGE("SD.begin cs=%d failed",cs);
57+
while (!SD.begin(cs, *spi)) {
58+
LOGE("SD.begin cs=%d failed", cs);
4959
delay(1000);
5060
}
5161
is_sd_setup = true;
5262
}
53-
idx.begin(start_path, exension, file_name_pattern);
63+
idx.begin(start_path, extension, file_name_pattern);
5464
idx_pos = 0;
5565
}
5666

@@ -102,22 +112,21 @@ class AudioSourceSD : public AudioSource {
102112
long size() { return idx.size();}
103113

104114
protected:
105-
#if defined(USE_SD_NO_NS)
115+
#if defined(USE_SD_NO_NS)
106116
SDDirect<SDClass, File> idx{SD};
107117
#else
108118
SDDirect<fs::SDFS,fs::File> idx{SD};
109119
#endif
110120
File file;
111121
size_t idx_pos = 0;
112122
const char *file_name;
113-
const char *exension = nullptr;
123+
const char *extension = nullptr;
114124
const char *start_path = nullptr;
115125
const char *file_name_pattern = "*";
116126
bool setup_index = true;
117127
bool is_sd_setup = false;
118128
int cs;
119-
120-
129+
SPIClass *spi = nullptr;
121130
};
122131

123-
} // namespace audio_tools
132+
} // namespace audio_tools

0 commit comments

Comments
 (0)