Skip to content

Commit 3117c35

Browse files
committed
VS1053BaseStream change startup sequence
1 parent 52a7244 commit 3117c35

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/AudioLibs/VS1053Stream.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,33 @@ namespace audio_tools {
1717
*/
1818
class VS1053BaseStream : public AudioStreamX {
1919
public:
20-
VS1053BaseStream(uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin,int16_t _reset_pin=-1){
20+
VS1053BaseStream(uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin,int16_t _reset_pin=-1, bool startSPI=true){
2121
LOGD(LOG_METHOD);
2222
this->_cs_pin = _cs_pin;
2323
this->_dcs_pin = _dcs_pin;
2424
this->_dreq_pin = _dreq_pin;
2525
this->_reset_pin = _reset_pin;
26+
this->_start_SPI = startSPI;
2627
}
2728

2829
bool begin() {
2930
LOGD(LOG_METHOD);
31+
p_vs1053 = new VS1053(_cs_pin,_dcs_pin,_dreq_pin);
32+
33+
// initialize SPI
34+
if (_start_SPI) {
35+
LOGI("SPI.begin()")
36+
SPI.begin();
37+
} else {
38+
LOGI("SPI not started");
39+
}
40+
3041
if (_reset_pin!=-1){
3142
LOGI("Setting reset pin to high: %d", _reset_pin);
3243
pinMode(_reset_pin, OUTPUT);
3344
digitalWrite(_reset_pin, HIGH);
3445
delay(200);
3546
}
36-
p_vs1053 = new VS1053(_cs_pin,_dcs_pin,_dreq_pin);
37-
// initialize SPI
38-
SPI.begin();
3947

4048
p_vs1053->begin();
4149
p_vs1053->startSong();
@@ -163,6 +171,7 @@ class VS1053BaseStream : public AudioStreamX {
163171
VS1053 *p_vs1053 = nullptr;
164172
uint8_t _cs_pin, _dcs_pin, _dreq_pin;
165173
int16_t _reset_pin=-1;
174+
bool _start_SPI;
166175
};
167176

168177
enum VS1053Mode {ENCODED_MODE, PCM_MODE, MIDI_MODE };
@@ -188,6 +197,7 @@ class VS1053Config : public AudioBaseInfo {
188197
RxTxMode mode;
189198
bool is_encoded_data = false;
190199
bool is_midi_mode = false;
200+
bool is_start_spi = true;
191201
};
192202

193203
/**
@@ -231,7 +241,7 @@ class VS1053Stream : public AudioStreamX {
231241
LOGI("cs_sd_pin: %d", cfg.cs_sd_pin);
232242

233243
if (p_driver==nullptr){
234-
p_driver = new VS1053BaseStream(cfg.cs_pin,cfg.dcs_pin,cfg.dreq_pin, cfg.reset_pin);
244+
p_driver = new VS1053BaseStream(cfg.cs_pin,cfg.dcs_pin,cfg.dreq_pin, cfg.reset_pin, cfg.is_start_spi);
235245
}
236246
if (p_out==nullptr){
237247
AudioEncoder *p_enc = cfg.is_encoded_data ? p_encoder :©

0 commit comments

Comments
 (0)