@@ -36,21 +36,31 @@ class AudioSourceSD : public AudioSource {
36
36
// / Default constructor
37
37
AudioSourceSD (const char *startFilePath = " /" , const char *ext = " .mp3" , int chipSelect = PIN_CS, bool setupIndex=true ) {
38
38
start_path = startFilePath;
39
- exension = ext;
39
+ extension = ext;
40
40
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;
41
51
cs = chipSelect;
42
52
}
43
53
44
54
virtual void begin () override {
45
55
TRACED ();
46
56
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);
49
59
delay (1000 );
50
60
}
51
61
is_sd_setup = true ;
52
62
}
53
- idx.begin (start_path, exension , file_name_pattern);
63
+ idx.begin (start_path, extension , file_name_pattern);
54
64
idx_pos = 0 ;
55
65
}
56
66
@@ -102,22 +112,21 @@ class AudioSourceSD : public AudioSource {
102
112
long size () { return idx.size ();}
103
113
104
114
protected:
105
- #if defined(USE_SD_NO_NS)
115
+ #if defined(USE_SD_NO_NS)
106
116
SDDirect<SDClass, File> idx{SD};
107
117
#else
108
118
SDDirect<fs::SDFS,fs::File> idx{SD};
109
119
#endif
110
120
File file;
111
121
size_t idx_pos = 0 ;
112
122
const char *file_name;
113
- const char *exension = nullptr ;
123
+ const char *extension = nullptr ;
114
124
const char *start_path = nullptr ;
115
125
const char *file_name_pattern = " *" ;
116
126
bool setup_index = true ;
117
127
bool is_sd_setup = false ;
118
128
int cs;
119
-
120
-
129
+ SPIClass *spi = nullptr ;
121
130
};
122
131
123
- } // namespace audio_tools
132
+ } // namespace audio_tools
0 commit comments