Skip to content

Commit 1a707b4

Browse files
authored
Remove ArduinoLog dependency (#13)
To get rid of ArduinoLog 3rd party dependency. To make use of ESP Arduino framework built in logger. Depending on the platform it's the one which comes from Arduino core for ESP32 or Arduino core for ESP8266. Documentation updated accordingly. The original plan to provide ESP-IDF framework compatibility is not yet done, as the library implementation uses much more Arduino core for ESP dependent stuff.
1 parent 0444cf9 commit 1a707b4

File tree

5 files changed

+105
-58
lines changed

5 files changed

+105
-58
lines changed

README.md

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,46 @@ Please note that `player.switchToMp3Mode()` is an optional switch. Some of VS105
6262
You can modify the board, but there is a more elegant way without soldering. For more details please read a discussion here: [http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773](http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773).
6363
<br />No side effects for boards which do not need this switch, so you can call it just in case.
6464

65-
#### Third-party dependencies
65+
#### Logging / debugging
6666

67-
The library use also a third-party logging framework [ArduinoLog](http://platformio.org/lib/show/1532/ArduinoLog/) for debugging purposes.<br />
68-
This dependency will be resolved automatically.
67+
The library uses ESP Arduino framework built in logger (Arduino core for [ESP32](https://github.com/espressif/arduino-esp32/issues/893#issuecomment-348069135) and [ESP8266](https://github.com/esp8266/Arduino/blob/master/doc/Troubleshooting/debugging.rst#debug-level)).<br />
6968

70-
Then you are able to include and use this library from your code (it offers several log levels):
69+
To see debug messages please add build flags to your `platformio.ini` as below (depending on platform):
7170

71+
- for ESP8266:
72+
73+
`build_flags = -D DEBUG_ESP_PORT=Serial`
74+
75+
- for ESP32:
76+
77+
`build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG`
78+
79+
The Serial Interface needs to be initialized in the `setup()`.
80+
81+
```
82+
void setup() {
83+
Serial.begin(115200);
84+
}
7285
```
73-
#include <ArduinoLog.h>
86+
Now if something is wrong, you'll see the output like below (from ESP32):
87+
7488
```
75-
...
89+
[I][main.cpp:117] setup(): Hello # VS1053!
90+
[D][VS1053.cpp:156] begin():
91+
[D][VS1053.cpp:157] begin(): Reset VS1053...
92+
[D][VS1053.cpp:161] begin(): End reset VS1053...
93+
[D][VS1053.cpp:119] testComm(): VS1053 not properly installed!
7694
```
77-
Serial.begin(9600);
78-
while(!Serial && !Serial.available()){}
79-
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
95+
In successful case it would start with something like this:
8096

81-
Log.notice("Hello, this is a debug message!");
97+
```
98+
[I][main.cpp:117] setup(): Hello # VS1053!
99+
[D][VS1053.cpp:156] begin():
100+
[D][VS1053.cpp:157] begin(): Reset VS1053...
101+
[D][VS1053.cpp:161] begin(): End reset VS1053...
102+
[D][VS1053.cpp:132] testComm(): Slow SPI,Testing VS1053 read/write registers...
103+
[D][VS1053.cpp:132] testComm(): Fast SPI, Testing VS1053 read/write registers again...
104+
[D][VS1053.cpp:183] begin(): endFillByte is 0
82105
```
83106

84107
## Example wiring

platformio.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ platform = espressif8266
1313
board = nodemcuv2
1414
framework = arduino
1515

16+
[env:esp32dev]
17+
platform = espressif32
18+
framework = espidf
19+
board = esp32dev
20+
1621
lib_deps =
1722
ArduinoLog

src/ConsoleLogger.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Licensed under GNU GPLv3 <http://gplv3.fsf.org/>
3+
* Copyright © 2018
4+
*
5+
* @author Marcin Szalomski (github: @baldram | twitter: @baldram)
6+
*/
7+
8+
#ifndef __ESP_VS1053_LIBRARY_CONSOLE_LOGGER__
9+
#define __ESP_VS1053_LIBRARY_CONSOLE_LOGGER__
10+
11+
/**
12+
* To enable debug, add build flag to your platformio.ini as below (depending on platform).
13+
*
14+
* For ESP8266:
15+
* build_flags = -D DEBUG_ESP_PORT=Serial
16+
*
17+
* For ESP32:
18+
* build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
19+
*
20+
*/
21+
#ifdef ARDUINO_ARCH_ESP32
22+
#define LOG(...) ESP_LOGD("ESP_VS1053", __VA_ARGS__)
23+
#elif defined(ARDUINO_ARCH_ESP8266) && defined(DEBUG_ESP_PORT)
24+
#define LOG(...) DEBUG_ESP_PORT.printf(__VA_ARGS__)
25+
#else
26+
#define LOG(...)
27+
#endif
28+
29+
#endif // __ESP_VS1053_LIBRARY_CONSOLE_LOGGER__

src/VS1053.cpp

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* version 1.0.1
77
*
88
* Licensed under GNU GPLv3 <http://gplv3.fsf.org/>
9-
* Copyright © 2017
9+
* Copyright © 2018
1010
*
1111
* @authors baldram, edzelf, MagicCube, maniacbug
1212
*
@@ -30,10 +30,7 @@
3030
* You should have received a copy of the GNU General Public License
3131
* along with this program. If not, see <http://www.gnu.org/licenses/>.
3232
*/
33-
34-
#include <ArduinoLog.h>
35-
#include <VS1053.h>
36-
#include <string>
33+
#include "VS1053.h"
3734

3835
VS1053::VS1053(uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin)
3936
: cs_pin(_cs_pin), dcs_pin(_dcs_pin), dreq_pin(_dreq_pin) {
@@ -119,7 +116,7 @@ bool VS1053::testComm(const char *header) {
119116
uint16_t delta = 300; // 3 for fast SPI
120117

121118
if (!digitalRead(dreq_pin)) {
122-
Log.error("VS1053 not properly installed!" CR);
119+
LOG("VS1053 not properly installed!\n");
123120
// Allow testing without the VS1053 module
124121
pinMode(dreq_pin, INPUT_PULLUP); // DREQ is now input with pull-up
125122
return false; // Return bad result
@@ -132,16 +129,15 @@ bool VS1053::testComm(const char *header) {
132129
delta = 3; // Fast SPI, more loops
133130
}
134131

135-
std::string headerCr = std::string(header) + CR;
136-
Log.notice(headerCr.c_str()); // Show a header
132+
LOG("%s", header); // Show a header
137133

138134
for (i = 0; (i < 0xFFFF) && (cnt < 20); i += delta) {
139135
write_register(SCI_VOL, i); // Write data to SCI_VOL
140136
r1 = read_register(SCI_VOL); // Read back for the first time
141137
r2 = read_register(SCI_VOL); // Read back a second time
142138
if (r1 != r2 || i != r1 || i != r2) // Check for 2 equal reads
143139
{
144-
Log.error("VS1053 error retry SB:%04X R1:%04X R2:%04X" CR, i, r1, r2);
140+
LOG("VS1053 error retry SB:%04X R1:%04X R2:%04X\n", i, r1, r2);
145141
cnt++;
146142
delay(10);
147143
}
@@ -150,46 +146,44 @@ bool VS1053::testComm(const char *header) {
150146
return (cnt == 0); // Return the result
151147
}
152148

153-
bool VS1053::begin() {
154-
bool result = false;
149+
void VS1053::begin() {
155150
pinMode(dreq_pin, INPUT); // DREQ is an input
156151
pinMode(cs_pin, OUTPUT); // The SCI and SDI signals
157152
pinMode(dcs_pin, OUTPUT);
158153
digitalWrite(dcs_pin, HIGH); // Start HIGH for SCI en SDI
159154
digitalWrite(cs_pin, HIGH);
160155
delay(100);
161-
Log.notice("Reset VS1053..." CR);
156+
LOG("\n");
157+
LOG("Reset VS1053...\n");
162158
digitalWrite(dcs_pin, LOW); // Low & Low will bring reset pin low
163159
digitalWrite(cs_pin, LOW);
164160
delay(500);
165-
Log.notice("End reset VS1053..." CR);
161+
LOG("End reset VS1053...\n");
166162
digitalWrite(dcs_pin, HIGH); // Back to normal again
167163
digitalWrite(cs_pin, HIGH);
168164
delay(500);
169165
// Init SPI in slow mode ( 0.2 MHz )
170166
VS1053_SPI = SPISettings(200000, MSBFIRST, SPI_MODE0);
171-
// printDetails ( "Right after reset/startup" ) ;
167+
// printDetails("Right after reset/startup");
172168
delay(20);
173-
// printDetails ( "20 msec after reset" ) ;
174-
result = testComm("Slow SPI,Testing VS1053 read/write registers...");
175-
176-
//softReset();
177-
178-
// Switch on the analog parts
179-
write_register(SCI_AUDATA, 44101); // 44.1kHz stereo
180-
// The next clocksetting allows SPI clocking at 5 MHz, 4 MHz is safe then.
181-
write_register(SCI_CLOCKF, 6 << 12); // Normal clock settings multiplyer 3.0 = 12.2 MHz
182-
// SPI Clock to 4 MHz. Now you can set high speed SPI clock.
183-
VS1053_SPI = SPISettings(4000000, MSBFIRST, SPI_MODE0);
184-
write_register(SCI_MODE, _BV(SM_SDINEW) | _BV(SM_LINE1));
185-
result = testComm("Fast SPI, Testing VS1053 read/write registers again...");
186-
delay(10);
187-
await_data_request();
188-
endFillByte = wram_read(0x1E06) & 0xFF;
189-
Log.notice("endFillByte is %X" CR, endFillByte);
190-
// printDetails ( "After last clocksetting" ) ;
191-
delay(100);
192-
return result;
169+
// printDetails("20 msec after reset");
170+
if (testComm("Slow SPI,Testing VS1053 read/write registers...\n")) {
171+
//softReset();
172+
// Switch on the analog parts
173+
write_register(SCI_AUDATA, 44101); // 44.1kHz stereo
174+
// The next clocksetting allows SPI clocking at 5 MHz, 4 MHz is safe then.
175+
write_register(SCI_CLOCKF, 6 << 12); // Normal clock settings multiplyer 3.0 = 12.2 MHz
176+
// SPI Clock to 4 MHz. Now you can set high speed SPI clock.
177+
VS1053_SPI = SPISettings(4000000, MSBFIRST, SPI_MODE0);
178+
write_register(SCI_MODE, _BV(SM_SDINEW) | _BV(SM_LINE1));
179+
testComm("Fast SPI, Testing VS1053 read/write registers again...\n");
180+
delay(10);
181+
await_data_request();
182+
endFillByte = wram_read(0x1E06) & 0xFF;
183+
LOG("endFillByte is %X\n", endFillByte);
184+
//printDetails("After last clocksetting") ;
185+
delay(100);
186+
}
193187
}
194188

195189
void VS1053::setVolume(uint8_t vol) {
@@ -205,8 +199,7 @@ void VS1053::setVolume(uint8_t vol) {
205199
}
206200
}
207201

208-
void VS1053::setTone(uint8_t *rtone) // Set bass/treble (4 nibbles)
209-
{
202+
void VS1053::setTone(uint8_t *rtone) { // Set bass/treble (4 nibbles)
210203
// Set tone characteristics. See documentation for the 4 nibbles.
211204
uint16_t value = 0; // Value to send to SCI_BASS
212205
int i; // Loop control
@@ -217,8 +210,7 @@ void VS1053::setTone(uint8_t *rtone) // Set bass/treble (4 nibbles)
217210
write_register(SCI_BASS, value); // Volume left and right
218211
}
219212

220-
uint8_t VS1053::getVolume() // Get the currenet volume setting.
221-
{
213+
uint8_t VS1053::getVolume() { // Get the currenet volume setting.
222214
return curvol;
223215
}
224216

@@ -242,7 +234,7 @@ void VS1053::stopSong() {
242234
modereg = read_register(SCI_MODE); // Read status
243235
if ((modereg & _BV(SM_CANCEL)) == 0) {
244236
sdi_send_fillers(2052);
245-
Log.notice("Song stopped correctly after %d msec" CR, i * 10);
237+
LOG("Song stopped correctly after %d msec\n", i * 10);
246238
return;
247239
}
248240
delay(10);
@@ -260,17 +252,15 @@ void VS1053::printDetails(const char *header) {
260252
uint16_t regbuf[16];
261253
uint8_t i;
262254

263-
std::string headerCr = std::string(header) + CR;
264-
Log.notice(headerCr.c_str());
265-
266-
Log.notice("REG Contents" CR);
267-
Log.notice("--- -----" CR);
255+
LOG("%s", header);
256+
LOG("REG Contents\n");
257+
LOG("--- -----\n");
268258
for (i = 0; i <= SCI_num_registers; i++) {
269259
regbuf[i] = read_register(i);
270260
}
271261
for (i = 0; i <= SCI_num_registers; i++) {
272262
delay(5);
273-
Log.notice("%3X - %5X" CR, i, regbuf[i]);
263+
LOG("%3X - %5X\n", i, regbuf[i]);
274264
}
275265
}
276266

@@ -282,8 +272,7 @@ void VS1053::printDetails(const char *header) {
282272
*
283273
* Read more here: http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773
284274
*/
285-
void VS1053::switchToMp3Mode(void)
286-
{
275+
void VS1053::switchToMp3Mode() {
287276
wram_write(0xC017, 3); // GPIO DDR = 3
288277
wram_write(0xC019, 0); // GPIO ODATA = 0
289278
delay(100);

src/VS1053.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <Arduino.h>
3838
#include <SPI.h>
39+
#include "ConsoleLogger.h"
3940

4041
class VS1053 {
4142
private:
@@ -109,7 +110,7 @@ class VS1053 {
109110
// Constructor. Only sets pin values. Doesn't touch the chip. Be sure to call begin()!
110111
VS1053(uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin);
111112

112-
bool begin(); // Begin operation. Sets pins correctly,
113+
void begin(); // Begin operation. Sets pins correctly,
113114
// and prepares SPI bus.
114115
void startSong(); // Prepare to start playing. Call this each
115116
// time a new song starts.

0 commit comments

Comments
 (0)