Skip to content

Commit cb65d23

Browse files
committed
Fix lots of warnings;
Optimizing speak and record example
1 parent fb820a5 commit cb65d23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+19963
-19831
lines changed

examples/Basics/record/record.ino

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,20 @@
11
/*
22
*******************************************************************************
3-
* Copyright (c) 2021 by M5Stack
3+
* Copyright (c) 2023 by M5Stack
44
* Equipped with M5Core2 sample source code
55
* 配套 M5Core2 示例源代码
66
* Visit for more information: https://docs.m5stack.com/en/core/core2
77
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
88
*
99
* Describe: NS4168--I2S power amplifier. 功放示例
10-
* Date: 2022/2/22
10+
* Date: 2023/7/31
1111
*******************************************************************************
1212
*/
1313
#include <M5Core2.h>
14-
#include <driver/i2s.h>
15-
16-
#define CONFIG_I2S_BCK_PIN 12 // Define I2S related ports. 定义I2S相关端口
17-
#define CONFIG_I2S_LRCK_PIN 0
18-
#define CONFIG_I2S_DATA_PIN 2
19-
#define CONFIG_I2S_DATA_IN_PIN 34
20-
21-
#define Speak_I2S_NUMBER I2S_NUM_0 // Define the speaker port. 定义扬声器端口
22-
23-
#define MODE_MIC 0 // Define the working mode. 定义工作模式
24-
#define MODE_SPK 1
25-
#define DATA_SIZE 1024
2614

2715
uint8_t microphonedata0[1024 * 100];
2816
int data_offset = 0;
2917

30-
bool InitI2SSpeakOrMic(int mode) { // Init I2S. 初始化I2S
31-
esp_err_t err = ESP_OK;
32-
33-
i2s_driver_uninstall(
34-
Speak_I2S_NUMBER); // Uninstall the I2S driver. 卸载I2S驱动
35-
i2s_config_t i2s_config = {
36-
.mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode.
37-
// 设置I2S工作模式
38-
.sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率
39-
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB.
40-
// 固定为12位立体声MSB
41-
.channel_format =
42-
I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式
43-
.communication_format =
44-
I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication.
45-
// 设置通讯格式
46-
.intr_alloc_flags =
47-
ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志
48-
.dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数
49-
.dma_buf_len = 128, // DMA buffer length. DMA缓冲区长度
50-
};
51-
if (mode == MODE_MIC) {
52-
i2s_config.mode =
53-
(i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM);
54-
} else {
55-
i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX);
56-
i2s_config.use_apll = false; // I2S clock setup. I2S时钟设置
57-
i2s_config.tx_desc_auto_clear =
58-
true; // Enables auto-cleanup descriptors for understreams.
59-
// 开启欠流自动清除描述符
60-
}
61-
// Install and drive I2S. 安装并驱动I2S
62-
err += i2s_driver_install(Speak_I2S_NUMBER, &i2s_config, 0, NULL);
63-
64-
i2s_pin_config_t tx_pin_config;
65-
#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0))
66-
tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE;
67-
#endif
68-
tx_pin_config.bck_io_num =
69-
CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin.
70-
// 将BCK链接至CONFIG_I2S_BCK_PIN引脚
71-
tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ...
72-
tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ...
73-
tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; // ...
74-
err +=
75-
i2s_set_pin(Speak_I2S_NUMBER,
76-
&tx_pin_config); // Set the I2S pin number. 设置I2S引脚编号
77-
err += i2s_set_clk(
78-
Speak_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT,
79-
I2S_CHANNEL_MONO); // Set the clock and bitwidth used by I2S Rx and Tx.
80-
// 设置I2S RX、Tx使用的时钟和位宽
81-
return true;
82-
}
83-
8418
void DisplayInit(void) { // Initialize the display. 显示屏初始化
8519
M5.Lcd.fillScreen(WHITE); // Set the screen background color to white.
8620
// 设置屏幕背景色为白色
@@ -94,7 +28,8 @@ the program in the setUp () function will be run, and this part will only be run
9428
once. 在 M5Core2
9529
启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
9630
void setup() {
97-
M5.begin(true, true, true, true); // Init M5Core2. 初始化 M5Core2
31+
M5.begin(true, true, true, true, kMBusModeOutput,
32+
true); // Init M5Core2. 初始化 M5Core2
9833
M5.Axp.SetSpkEnable(true); // Enable speaker power. 启用扬声器电源
9934
DisplayInit();
10035
M5.Lcd.setTextColor(RED);
@@ -122,7 +57,7 @@ void loop() {
12257
delay(100);
12358
M5.Axp.SetLDOEnable(3, false);
12459
data_offset = 0;
125-
InitI2SSpeakOrMic(MODE_MIC);
60+
M5.Spk.InitI2SSpeakOrMic(MODE_MIC);
12661
size_t byte_read;
12762
while (1) {
12863
i2s_read(Speak_I2S_NUMBER, (char *)(microphonedata0 + data_offset),
@@ -131,7 +66,7 @@ void loop() {
13166
if (data_offset == 1024 * 100 || M5.Touch.ispressed() != true) break;
13267
}
13368
size_t bytes_written;
134-
InitI2SSpeakOrMic(MODE_SPK);
69+
M5.Spk.InitI2SSpeakOrMic(MODE_SPK);
13570
i2s_write(Speak_I2S_NUMBER, microphonedata0, data_offset, &bytes_written,
13671
portMAX_DELAY);
13772
}

examples/Basics/speak/speak.ino

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,69 @@
11
/*
22
*******************************************************************************
3-
* Copyright (c) 2021 by M5Stack
3+
* Copyright (c) 2023 by M5Stack
44
* Equipped with M5Core2 sample source code
55
* 配套 M5Core2 示例源代码
66
* Visit for more information: https://docs.m5stack.com/en/core/core2
77
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
88
*
99
* Describe: Speaker example. 喇叭示例
10-
* Date: 2022/7/26
10+
* Date: 2023/7/31
1111
*******************************************************************************
1212
*/
1313
#include <M5Core2.h>
1414

15+
extern const unsigned char previewR[120264];
16+
17+
void DisplayInit(void) { // Initialize the display. 显示屏初始化
18+
M5.Lcd.fillScreen(WHITE); // Set the screen background color to white.
19+
// 设置屏幕背景色为白色
20+
M5.Lcd.setTextColor(
21+
BLACK); // Set the text color to black. 设置文字颜色为黑色
22+
M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2
23+
}
24+
25+
/* After M5Core2 is started or reset
26+
the program in the setUp () function will be run, and this part will only be run once.
27+
在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
28+
void setup() {
29+
M5.begin(true, true, true, true, mbus_mode_t::kMBusModeOutput,
30+
true); // Init M5Core2. 初始化 M5Core2
31+
DisplayInit();
32+
M5.Lcd.setTextColor(RED);
33+
M5.Lcd.setCursor(10,
34+
10); // Set the cursor at (10,10). 将光标设在(10,10)处
35+
M5.Lcd.printf("Speak Test!"); // The screen prints the formatted string and
36+
// wraps it. 屏幕打印格式化字符串并换行
37+
M5.Lcd.setTextColor(BLACK);
38+
M5.Lcd.setCursor(10, 26);
39+
M5.Lcd.printf("Press Left Button to listen DingDong!");
40+
M5.Spk.PlaySound(
41+
previewR,
42+
sizeof(previewR)); // Play the DingDong sound. 播放 DingDong 声音
43+
delay(100);
44+
}
45+
46+
/* After the program in setup() runs, it runs the program in loop()
47+
The loop() function is an infinite loop in which the program runs repeatedly
48+
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
49+
loop()函数是一个死循环,其中的程序会不断的重复运行 */
50+
void loop() {
51+
TouchPoint_t pos =
52+
M5.Touch.getPressPoint(); // Stores the touch coordinates in pos.
53+
// 将触摸坐标存储在pos.内
54+
if (pos.y > 240)
55+
if (pos.x < 109) {
56+
M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达
57+
delay(100);
58+
M5.Axp.SetLDOEnable(3, false);
59+
delay(100);
60+
M5.Spk.PlaySound(
61+
previewR,
62+
sizeof(previewR)); // Play the DingDong sound. 播放 DingDong 声音
63+
}
64+
delay(10);
65+
}
66+
1567
const unsigned char previewR[120264] = {
1668
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1769
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -10035,53 +10087,3 @@ const unsigned char previewR[120264] = {
1003510087
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1003610088
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1003710089
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
10038-
10039-
void DisplayInit(void) { // Initialize the display. 显示屏初始化
10040-
M5.Lcd.fillScreen(WHITE); // Set the screen background color to white.
10041-
// 设置屏幕背景色为白色
10042-
M5.Lcd.setTextColor(
10043-
BLACK); // Set the text color to black. 设置文字颜色为黑色
10044-
M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2
10045-
}
10046-
10047-
//在 M5Core
10048-
//启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。
10049-
void setup() {
10050-
M5.begin(true, true, true, true, mbus_mode_t::kMBusModeOutput,
10051-
true); // Init M5Core2. 初始化 M5Core2
10052-
DisplayInit();
10053-
M5.Lcd.setTextColor(RED);
10054-
M5.Lcd.setCursor(10,
10055-
10); // Set the cursor at (10,10). 将光标设在(10,10)处
10056-
M5.Lcd.printf("Speak Test!"); // The screen prints the formatted string and
10057-
// wraps it. 屏幕打印格式化字符串并换行
10058-
M5.Lcd.setTextColor(BLACK);
10059-
M5.Lcd.setCursor(10, 26);
10060-
M5.Lcd.printf("Press Left Button to listen DingDong!");
10061-
M5.Spk.PlaySound(
10062-
previewR,
10063-
sizeof(previewR)); // Play the DingDong sound. 播放 DingDong 声音
10064-
delay(100);
10065-
}
10066-
10067-
/* After the program in setup() runs, it runs the program in loop()
10068-
The loop() function is an infinite loop in which the program runs repeatedly
10069-
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
10070-
loop()函数是一个死循环,其中的程序会不断的重复运行 */
10071-
void loop() {
10072-
TouchPoint_t pos =
10073-
M5.Touch.getPressPoint(); // Stores the touch coordinates in pos.
10074-
// 将触摸坐标存储在pos.内
10075-
if (pos.y > 240)
10076-
if (pos.x < 109) {
10077-
M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达
10078-
delay(100);
10079-
M5.Axp.SetLDOEnable(3, false);
10080-
delay(100);
10081-
M5.Spk.PlaySound(
10082-
previewR,
10083-
sizeof(
10084-
previewR)); // Play the DingDong sound. 播放 DingDong 声音
10085-
}
10086-
delay(10);
10087-
}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "git",
1111
"url": "https://github.com/m5stack/M5Core2.git"
1212
},
13-
"version": "0.1.5",
13+
"version": "0.1.6",
1414
"frameworks": "arduino",
1515
"platforms": "espressif32",
1616
"headers": "M5Core2.h"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5Core2
2-
version=0.1.5
2+
version=0.1.6
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=Library for M5Stack Core2 development kit

src/Fonts/Custom/Orbitron_Light_24.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ const GFXfont Orbitron_Light_24 PROGMEM = {
393393
24,
394394
#ifdef USE_M5_FONT_CREATOR
395395
0,
396+
nullptr,
396397
0,
397398
#endif
398399
};

src/Fonts/Custom/Orbitron_Light_32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ const GFXfont Orbitron_Light_32 PROGMEM = {
582582
32,
583583
#ifdef USE_M5_FONT_CREATOR
584584
0,
585+
nullptr,
585586
0,
586587
#endif
587588
};

src/Fonts/Custom/Roboto_Thin_24.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ const GFXfont Roboto_Thin_24 PROGMEM = {
332332
29,
333333
#ifdef USE_M5_FONT_CREATOR
334334
0,
335+
nullptr,
335336
0,
336337
#endif
337338
};

src/Fonts/Custom/Satisfy_24.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ const GFXfont Satisfy_24 PROGMEM = {
392392
36,
393393
#ifdef USE_M5_FONT_CREATOR
394394
0,
395+
nullptr,
395396
0,
396397
#endif
397398
};

src/Fonts/Custom/Yellowtail_32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ const GFXfont Yellowtail_32 PROGMEM = {
581581
45,
582582
#ifdef USE_M5_FONT_CREATOR
583583
0,
584+
nullptr,
584585
0,
585586
#endif
586587
};

0 commit comments

Comments
 (0)