From 7dddf02692d358fb6e753a12134b03be65f4706a Mon Sep 17 00:00:00 2001 From: Cellie Date: Fri, 5 Jan 2024 15:51:34 +0100 Subject: [PATCH 1/5] WIP --- examples/M5StackDemo/M5StackDemo.ino | 61 ++++++++++++++++ examples/M5StackDemo/SampleMp3.h | 101 +++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 examples/M5StackDemo/M5StackDemo.ino create mode 100644 examples/M5StackDemo/SampleMp3.h diff --git a/examples/M5StackDemo/M5StackDemo.ino b/examples/M5StackDemo/M5StackDemo.ino new file mode 100644 index 0000000..0127918 --- /dev/null +++ b/examples/M5StackDemo/M5StackDemo.ino @@ -0,0 +1,61 @@ +/* This is an example that shows how to use the VS1053 library together with M5Stack displays. + In this example a M5Stack Grey is used. + */ +#include +#include /* https://github.com/m5stack/M5GFX */ + +#define VS1053_CS 13 +#define VS1053_DCS 26 +#define VS1053_DREQ 36 +#define SPI_CLK_PIN 18 +#define SPI_MISO_PIN 19 +#define SPI_MOSI_PIN 23 + +#define VOLUME 100 // volume level 0-100 + +// This ESP_VS1053_Library +#include + +#include "SampleMp3.h" + +M5GFX display; +VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ); + +void setup() +{ + Serial.begin(115200); + Serial.println("\n\nM5Stack Grey + VS1053 Demo"); + + // initialize SPI with the M5Stack defined pins + SPI.begin(SPI_CLK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN); + + /* Start the M5 display */ + display.init(); + display.setTextSize((float)display.width() / 160); + display.println("VS1053 + M5Stack display"); + + Serial.println("Disabling M5Stack DAC"); + pinMode(25, OUTPUT); // 25 on Grey and Fire + digitalWrite(25, 0); + + Serial.println("Hello VS1053!"); + // initialize a player + player.begin(); + if (player.getChipVersion() == 4) + { // Only perform an update if we really are using a VS1053, not. eg. VS1003 + player.loadDefaultVs1053Patches(); + } + player.switchToMp3Mode(); // optional, some boards require this + player.setVolume(VOLUME); +} + +void loop() +{ + Serial.println("Playing sound... "); + + // play mp3 flow each second + static auto cnt = 0; + player.playChunk(sampleMp3, sizeof(sampleMp3)); + display.printf("Played %i times\n", ++cnt); + delay(1000); +} diff --git a/examples/M5StackDemo/SampleMp3.h b/examples/M5StackDemo/SampleMp3.h new file mode 100644 index 0000000..77395de --- /dev/null +++ b/examples/M5StackDemo/SampleMp3.h @@ -0,0 +1,101 @@ +/** + * A test sound for ESP_VS1053_Library usage example. + * https://github.com/baldram/ESP_VS1053_Library + * If you like this project, please add a star. + * + * Copyright (C) 2018 Marcin Szalomski + * Licensed under GNU GPL v3 + */ +unsigned char sampleMp3[] = { + 0x49, 0x44, 0x33, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x54, 0x53, + 0x53, 0x45, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x03, 0x4c, 0x61, 0x76, + 0x66, 0x35, 0x38, 0x2e, 0x32, 0x30, 0x2e, 0x31, 0x30, 0x30, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xe3, 0x40, + 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x6e, + 0x66, 0x6f, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x04, 0x14, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, + 0x4c, 0x4c, 0x4c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, + 0x7f, 0x7f, 0x7f, 0x7f, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, + 0x99, 0x99, 0x99, 0x99, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, + 0xb3, 0xb3, 0xb3, 0xb3, 0xb3, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, + 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, + 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x61, + 0x76, 0x63, 0x35, 0x38, 0x2e, 0x33, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x02, 0xfa, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x14, 0x18, 0x80, 0x8d, 0xcc, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xff, 0xe3, 0x20, 0xc4, 0x00, 0x14, 0x11, 0xaa, 0xee, 0x5f, 0x41, + 0x10, 0x02, 0x1b, 0x6d, 0xb6, 0xd6, 0xd8, 0xc0, 0xb2, 0xcb, 0xc6, 0x31, + 0x8c, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x31, 0x8c, 0x63, + 0x18, 0xc8, 0x42, 0x10, 0x84, 0xf9, 0xce, 0x73, 0xfd, 0x08, 0x46, 0xe7, + 0x39, 0xff, 0xd0, 0x84, 0x21, 0x3f, 0x39, 0xce, 0xfd, 0x3f, 0xfe, 0xa7, + 0x21, 0x19, 0x4e, 0x1c, 0x0c, 0x3f, 0xff, 0x04, 0x01, 0x00, 0xc6, 0x27, + 0x07, 0xdf, 0xff, 0x82, 0x00, 0x84, 0xe1, 0x70, 0xff, 0x7f, 0xfe, 0xa0, + 0x40, 0x13, 0x07, 0xc3, 0xff, 0xff, 0xfe, 0x08, 0x02, 0x07, 0x15, 0x6d, + 0xd0, 0x28, 0x14, 0x0b, 0x45, 0xb6, 0xd0, 0x84, 0x01, 0xff, 0xe3, 0x22, + 0xc4, 0x0a, 0x17, 0x31, 0xd6, 0xf6, 0x5f, 0x81, 0x68, 0x02, 0xa1, 0x5d, + 0xae, 0xd5, 0x55, 0x11, 0xfa, 0x3f, 0xd2, 0xfe, 0xc8, 0xd5, 0xfd, 0x24, + 0x91, 0x5a, 0xef, 0x5b, 0x7a, 0x29, 0x24, 0xc6, 0x4e, 0xb6, 0xb7, 0xff, + 0x55, 0x4b, 0x32, 0xff, 0x5d, 0x48, 0x53, 0x5b, 0x13, 0x43, 0xc8, 0xe6, + 0x45, 0x97, 0xd4, 0x3c, 0x9f, 0xde, 0xc0, 0xe5, 0x37, 0x41, 0x89, 0xbb, + 0xfe, 0x5c, 0x71, 0xc2, 0xfe, 0x13, 0x11, 0x0e, 0x5e, 0x84, 0xaa, 0xd8, + 0x26, 0xb2, 0x42, 0xe1, 0x47, 0x94, 0xac, 0x1b, 0x1c, 0xfd, 0x9e, 0x50, + 0x2f, 0x42, 0x17, 0x6a, 0x41, 0x15, 0x6a, 0x7e, 0x6d, 0xb6, 0xdb, 0x49, + 0x00, 0x0a, 0x45, 0xb5, 0x55, 0x7f, 0xff, 0xe3, 0x20, 0xc4, 0x09, 0x16, + 0x6a, 0x5e, 0xd8, 0x1f, 0x81, 0x88, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xfd, 0x49, 0xea, 0x32, 0x34, 0x33, 0xf2, 0x91, 0x12, 0x76, 0x41, 0x33, + 0x35, 0xbb, 0x2d, 0x05, 0xa2, 0x64, 0xb5, 0x7f, 0x49, 0x8c, 0x8b, 0xcc, + 0xcc, 0x9f, 0xa3, 0x53, 0xff, 0xef, 0xad, 0x32, 0x44, 0x5c, 0xe5, 0x72, + 0xfa, 0x6f, 0x52, 0x4e, 0x43, 0x4b, 0x80, 0xd2, 0x85, 0xf0, 0x1a, 0x49, + 0x52, 0x5f, 0xc4, 0x62, 0x1c, 0xd3, 0x98, 0x38, 0x70, 0xfc, 0x9d, 0x47, + 0x6a, 0xff, 0xfa, 0xd2, 0xb3, 0x18, 0x5e, 0xc5, 0xcf, 0x38, 0xab, 0x92, + 0xa7, 0x95, 0xec, 0x4a, 0x12, 0xed, 0xa6, 0x8c, 0x76, 0x98, 0x2b, 0x7f, + 0xff, 0xfd, 0xff, 0xe3, 0x22, 0xc4, 0x0a, 0x16, 0xe2, 0x96, 0xb4, 0x7f, + 0xc5, 0x88, 0x00, 0x93, 0x47, 0x55, 0xd1, 0xaf, 0x7d, 0x14, 0x96, 0xa4, + 0x1d, 0x6a, 0x4d, 0x4b, 0x56, 0xa4, 0x57, 0xff, 0x54, 0x7a, 0x2f, 0x18, + 0x3b, 0x56, 0xd4, 0x2e, 0x82, 0x94, 0xf5, 0xd7, 0x7b, 0xdb, 0x7d, 0x5a, + 0xfe, 0xdd, 0x17, 0xa4, 0xbf, 0xff, 0xe8, 0xa3, 0x44, 0x7c, 0x01, 0x72, + 0x44, 0x51, 0x90, 0x21, 0xce, 0x22, 0xa6, 0xac, 0xb3, 0x95, 0x23, 0x49, + 0x49, 0x16, 0x56, 0xc7, 0xcc, 0xd0, 0x29, 0x9f, 0x40, 0x55, 0x8f, 0x1d, + 0x62, 0x69, 0x3f, 0x25, 0x56, 0x77, 0xd9, 0xff, 0xfc, 0xb3, 0x7c, 0x56, + 0xaa, 0x92, 0x5b, 0x25, 0x8c, 0x66, 0x02, 0xff, 0xff, 0xd8, 0xc7, 0xff, + 0xe3, 0x20, 0xc4, 0x0a, 0x13, 0xaa, 0xa2, 0xcc, 0x7e, 0x0a, 0x93, 0x72, + 0x14, 0xa9, 0x5e, 0x81, 0x19, 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0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa +}; From 97bd5420b89580ebadca5cc2410653acbcf08a5b Mon Sep 17 00:00:00 2001 From: Cellie Date: Sat, 6 Jan 2024 14:19:10 +0100 Subject: [PATCH 2/5] Cleanup --- examples/M5StackDemo/M5StackDemo.ino | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/M5StackDemo/M5StackDemo.ino b/examples/M5StackDemo/M5StackDemo.ino index 0127918..c8d2edb 100644 --- a/examples/M5StackDemo/M5StackDemo.ino +++ b/examples/M5StackDemo/M5StackDemo.ino @@ -1,9 +1,18 @@ /* This is an example that shows how to use the VS1053 library together with M5Stack displays. In this example a M5Stack Grey is used. + + The SPI bus is shared between the M5Stack display and the VS1053 codec board. + This code is not thread safe. + + Let the display and VS1053 take turns to use the SPI bus. */ -#include #include /* https://github.com/m5stack/M5GFX */ +// This ESP_VS1053_Library +#include + +#include "SampleMp3.h" + #define VS1053_CS 13 #define VS1053_DCS 26 #define VS1053_DREQ 36 @@ -13,11 +22,6 @@ #define VOLUME 100 // volume level 0-100 -// This ESP_VS1053_Library -#include - -#include "SampleMp3.h" - M5GFX display; VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ); @@ -26,7 +30,7 @@ void setup() Serial.begin(115200); Serial.println("\n\nM5Stack Grey + VS1053 Demo"); - // initialize SPI with the M5Stack defined pins + // Initialize SPI with the M5Stack SPI pins SPI.begin(SPI_CLK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN); /* Start the M5 display */ @@ -34,9 +38,10 @@ void setup() display.setTextSize((float)display.width() / 160); display.println("VS1053 + M5Stack display"); - Serial.println("Disabling M5Stack DAC"); - pinMode(25, OUTPUT); // 25 on Grey and Fire - digitalWrite(25, 0); + Serial.println("Disabling M5Stack DAC and internal speaker"); + const auto DAC_PIN = 25; // on Grey and Fire + pinMode(DAC_PIN, OUTPUT); + digitalWrite(DAC_PIN, 0); Serial.println("Hello VS1053!"); // initialize a player From 298a1a7f8becf32a840835f40c463da310570dd1 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sat, 6 Jan 2024 14:28:52 +0100 Subject: [PATCH 3/5] cleanup --- examples/M5StackDemo/M5StackDemo.ino | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/M5StackDemo/M5StackDemo.ino b/examples/M5StackDemo/M5StackDemo.ino index c8d2edb..0cfb01f 100644 --- a/examples/M5StackDemo/M5StackDemo.ino +++ b/examples/M5StackDemo/M5StackDemo.ino @@ -1,9 +1,9 @@ -/* This is an example that shows how to use the VS1053 library together with M5Stack displays. +/* This is an example that shows how to use the VS1053 library together with M5Stack Core displays. In this example a M5Stack Grey is used. The SPI bus is shared between the M5Stack display and the VS1053 codec board. - This code is not thread safe. - + Note: this code is not thread safe. + Let the display and VS1053 take turns to use the SPI bus. */ #include /* https://github.com/m5stack/M5GFX */ @@ -35,12 +35,11 @@ void setup() /* Start the M5 display */ display.init(); - display.setTextSize((float)display.width() / 160); display.println("VS1053 + M5Stack display"); Serial.println("Disabling M5Stack DAC and internal speaker"); const auto DAC_PIN = 25; // on Grey and Fire - pinMode(DAC_PIN, OUTPUT); + pinMode(DAC_PIN, OUTPUT); digitalWrite(DAC_PIN, 0); Serial.println("Hello VS1053!"); From 1d93fbc27bafed85be44d2636f6f9d23812f528d Mon Sep 17 00:00:00 2001 From: Cellie Date: Sat, 6 Jan 2024 14:31:27 +0100 Subject: [PATCH 4/5] LGTM --- examples/M5StackDemo/M5StackDemo.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/M5StackDemo/M5StackDemo.ino b/examples/M5StackDemo/M5StackDemo.ino index 0cfb01f..f589fe2 100644 --- a/examples/M5StackDemo/M5StackDemo.ino +++ b/examples/M5StackDemo/M5StackDemo.ino @@ -2,8 +2,8 @@ In this example a M5Stack Grey is used. The SPI bus is shared between the M5Stack display and the VS1053 codec board. - Note: this code is not thread safe. + Note: this code is not thread safe. Let the display and VS1053 take turns to use the SPI bus. */ #include /* https://github.com/m5stack/M5GFX */ From 0647a54a255cde4ca1d76bb4e2db359e1429f147 Mon Sep 17 00:00:00 2001 From: Cellie Date: Sat, 6 Jan 2024 14:59:33 +0100 Subject: [PATCH 5/5] Update comments --- examples/M5StackDemo/M5StackDemo.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/M5StackDemo/M5StackDemo.ino b/examples/M5StackDemo/M5StackDemo.ino index f589fe2..508a122 100644 --- a/examples/M5StackDemo/M5StackDemo.ino +++ b/examples/M5StackDemo/M5StackDemo.ino @@ -3,10 +3,11 @@ The SPI bus is shared between the M5Stack display and the VS1053 codec board. - Note: this code is not thread safe. - Let the display and VS1053 take turns to use the SPI bus. + Let the display and VS1053 take turns using the SPI bus. */ -#include /* https://github.com/m5stack/M5GFX */ + +// The M5Stack display driver library: https://github.com/m5stack/M5GFX +#include // This ESP_VS1053_Library #include