Skip to content

Commit 5694877

Browse files
committed
Adding possiblity to not initialize speaker
1 parent f958999 commit 5694877

File tree

8 files changed

+10079
-3050
lines changed

8 files changed

+10079
-3050
lines changed

examples/Basics/speak/speak.ino

Lines changed: 10060 additions & 31 deletions
Large diffs are not rendered by default.

examples/FactoryTest/FactoryTest/FactoryTest.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ int checkAETCC608AInit() {
476476

477477
myECCX08.end();
478478
Wire1.begin(21, 22, 100000UL);
479+
return 0;
479480
}
480481

481482
int checkSDCard() {

src/M5Core2.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
M5Core2::M5Core2() : isInited(0) {}
77

88
void M5Core2::begin(bool LCDEnable, bool SDEnable, bool SerialEnable,
9-
bool I2CEnable, mbus_mode_t mode) {
9+
bool I2CEnable, mbus_mode_t mode, bool SpeakerEnable) {
1010
// Correct init once
1111
if (isInited == true) {
1212
return;
@@ -43,7 +43,10 @@ void M5Core2::begin(bool LCDEnable, bool SDEnable, bool SerialEnable,
4343
}
4444

4545
// TONE
46-
Spk.begin();
46+
47+
if (SpeakerEnable == true) {
48+
Spk.begin();
49+
}
4750

4851
if (SerialEnable == true) {
4952
Serial.println("OK");

src/M5Core2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class M5Core2 {
8888
M5Core2();
8989
void begin(bool LCDEnable = true, bool SDEnable = true,
9090
bool SerialEnable = true, bool I2CEnable = false,
91-
mbus_mode_t mode = kMBusModeOutput);
91+
mbus_mode_t mode = kMBusModeOutput, bool SpeakerEnable = true);
9292
void update();
9393

9494
void shutdown();

src/Speaker.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,13 @@ void Speaker::Write1Byte(uint8_t Addr, uint8_t Data) {
8787
Wire1.endTransmission();
8888
}
8989

90-
void Speaker::DingDong(void) {
90+
const size_t Speaker::PlaySound(const unsigned char* data,
91+
const size_t& amount_of_bytes) {
9192
size_t bytes_written = 0;
92-
i2s_write(Speak_I2S_NUMBER, ding, 35988, &bytes_written, portMAX_DELAY);
93+
if (data == nullptr) {
94+
return bytes_written;
95+
}
96+
i2s_write(Speak_I2S_NUMBER, data, amount_of_bytes, &bytes_written,
97+
portMAX_DELAY);
98+
return bytes_written;
9399
}

src/Speaker.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <freertos/task.h>
66
#include <driver/i2s.h>
77
#include <esp_err.h>
8-
#include <utility/ding.c>
98
#include <Wire.h>
109

1110
#define CONFIG_I2S_BCK_PIN 12 //定义I2S相关端口
@@ -21,13 +20,15 @@
2120

2221
class Speaker {
2322
private:
24-
size_t bytes_written = 0;
2523
void Write1Byte(uint8_t Addr, uint8_t Data);
2624
uint8_t Read8bit(uint8_t Addr);
2725

2826
public:
2927
void begin(void);
3028
bool InitI2SSpeakOrMic(int mode);
31-
void DingDong(void);
29+
// Plays the given amount of bytes from the given data array and returns the amount of bytes,
30+
// that were actually played by the speaker.
31+
const size_t PlaySound(const unsigned char* data,
32+
const size_t& amount_of_bytes);
3233
};
3334
#endif

src/utility/In_eSPI.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,6 @@ static inline void swap_coord(T &a, T &b) {
607607
b = t;
608608
}
609609

610-
#ifndef min
611-
// Return minimum of two numbers, may already be defined
612-
#define min(a, b) (((a) < (b)) ? (a) : (b))
613-
#endif
614-
615610
// This structure allows sketches to retrieve the user setup parameters at runtime
616611
// by calling getSetup(), zero impact on code size unless used, mainly for diagnostics
617612
typedef struct {

src/utility/ding.c

Lines changed: 0 additions & 3006 deletions
This file was deleted.

0 commit comments

Comments
 (0)