Skip to content

Commit 051a0ba

Browse files
committed
add iot speaker for boards
1 parent d31901e commit 051a0ba

File tree

6 files changed

+58
-14
lines changed

6 files changed

+58
-14
lines changed

main/audio_codecs/no_audio_codec.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n
137137
output_sample_rate_ = output_sample_rate;
138138

139139
// Create a new channel for speaker
140-
i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_1, I2S_ROLE_MASTER);
140+
i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)1, I2S_ROLE_MASTER);
141141
tx_chan_cfg.dma_desc_num = 6;
142142
tx_chan_cfg.dma_frame_num = 240;
143143
tx_chan_cfg.auto_clear_after_cb = true;
@@ -147,7 +147,12 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n
147147

148148

149149
i2s_std_config_t tx_std_cfg = {
150-
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG((uint32_t)output_sample_rate_),
150+
.clk_cfg = {
151+
.sample_rate_hz = (uint32_t)output_sample_rate_,
152+
.clk_src = I2S_CLK_SRC_DEFAULT,
153+
.ext_clk_freq_hz = 0,
154+
.mclk_multiple = I2S_MCLK_MULTIPLE_256
155+
},
151156
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_MONO),
152157
.gpio_cfg = {
153158
.mclk = I2S_GPIO_UNUSED,
@@ -163,9 +168,9 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n
163168
},
164169
};
165170
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &tx_std_cfg));
166-
171+
#if SOC_I2S_SUPPORTS_PDM_RX
167172
// Create a new channel for MIC in PDM mode
168-
i2s_chan_config_t rx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
173+
i2s_chan_config_t rx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)0, I2S_ROLE_MASTER);
169174
ESP_ERROR_CHECK(i2s_new_channel(&rx_chan_cfg, NULL, &rx_handle_));
170175
i2s_pdm_rx_config_t pdm_rx_cfg = {
171176
.clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG((uint32_t)input_sample_rate_),
@@ -181,6 +186,9 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n
181186
},
182187
};
183188
ESP_ERROR_CHECK(i2s_channel_init_pdm_rx_mode(rx_handle_, &pdm_rx_cfg));
189+
#else
190+
ESP_LOGE(TAG, "PDM is not supported");
191+
#endif
184192
ESP_LOGI(TAG, "Simplex channels created");
185193
}
186194

main/boards/esp-box-3/esp_box3_board.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "button.h"
66
#include "led.h"
77
#include "config.h"
8+
#include "iot/thing_manager.h"
89

910
#include <esp_log.h>
1011
#include <driver/i2c_master.h>
@@ -39,10 +40,17 @@ class EspBox3Board : public WifiBoard {
3940
});
4041
}
4142

43+
// 物联网初始化,添加对 AI 可见设备
44+
void InitializeIot() {
45+
auto& thing_manager = iot::ThingManager::GetInstance();
46+
thing_manager.AddThing(iot::CreateThing("Speaker"));
47+
}
48+
4249
public:
4350
EspBox3Board() : boot_button_(BOOT_BUTTON_GPIO) {
4451
InitializeI2c();
4552
InitializeButtons();
53+
InitializeIot();
4654
}
4755

4856
virtual Led* GetBuiltinLed() override {

main/boards/kevin-box-1/kevin_box_board.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#include "button.h"
66
#include "led.h"
77
#include "config.h"
8+
#include "iot/thing_manager.h"
89

910
#include <esp_log.h>
1011
#include <esp_spiffs.h>
1112
#include <driver/gpio.h>
1213
#include <driver/i2c_master.h>
1314

14-
static const char *TAG = "KevinBoxBoard";
15+
#define TAG "KevinBoxBoard"
1516

1617
class KevinBoxBoard : public Ml307Board {
1718
private:
@@ -95,8 +96,7 @@ class KevinBoxBoard : public Ml307Board {
9596
});
9697

9798
volume_up_button_.OnLongPress([this]() {
98-
auto codec = GetAudioCodec();
99-
codec->SetOutputVolume(100);
99+
GetAudioCodec()->SetOutputVolume(100);
100100
GetDisplay()->ShowNotification("最大音量");
101101
});
102102

@@ -111,12 +111,17 @@ class KevinBoxBoard : public Ml307Board {
111111
});
112112

113113
volume_down_button_.OnLongPress([this]() {
114-
auto codec = GetAudioCodec();
115-
codec->SetOutputVolume(0);
114+
GetAudioCodec()->SetOutputVolume(0);
116115
GetDisplay()->ShowNotification("已静音");
117116
});
118117
}
119118

119+
// 物联网初始化,添加对 AI 可见设备
120+
void InitializeIot() {
121+
auto& thing_manager = iot::ThingManager::GetInstance();
122+
thing_manager.AddThing(iot::CreateThing("Speaker"));
123+
}
124+
120125
public:
121126
KevinBoxBoard() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
122127
boot_button_(BOOT_BUTTON_GPIO),
@@ -128,6 +133,7 @@ class KevinBoxBoard : public Ml307Board {
128133
Enable4GModule();
129134

130135
InitializeButtons();
136+
InitializeIot();
131137
}
132138

133139
virtual Led* GetBuiltinLed() override {

main/boards/kevin-box-2/kevin_box_board.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
#include "led.h"
77
#include "config.h"
88
#include "axp2101.h"
9+
#include "iot/thing_manager.h"
910

1011
#include <esp_log.h>
1112
#include <esp_spiffs.h>
1213
#include <driver/gpio.h>
1314
#include <driver/i2c_master.h>
1415
#include <esp_timer.h>
1516

16-
static const char *TAG = "KevinBoxBoard";
17+
#define TAG "KevinBoxBoard"
1718

1819
class KevinBoxBoard : public Ml307Board {
1920
private:
@@ -136,8 +137,7 @@ class KevinBoxBoard : public Ml307Board {
136137
});
137138

138139
volume_up_button_.OnLongPress([this]() {
139-
auto codec = GetAudioCodec();
140-
codec->SetOutputVolume(100);
140+
GetAudioCodec()->SetOutputVolume(100);
141141
GetDisplay()->ShowNotification("最大音量");
142142
});
143143

@@ -152,12 +152,17 @@ class KevinBoxBoard : public Ml307Board {
152152
});
153153

154154
volume_down_button_.OnLongPress([this]() {
155-
auto codec = GetAudioCodec();
156-
codec->SetOutputVolume(0);
155+
GetAudioCodec()->SetOutputVolume(0);
157156
GetDisplay()->ShowNotification("已静音");
158157
});
159158
}
160159

160+
// 物联网初始化,添加对 AI 可见设备
161+
void InitializeIot() {
162+
auto& thing_manager = iot::ThingManager::GetInstance();
163+
thing_manager.AddThing(iot::CreateThing("Speaker"));
164+
}
165+
161166
public:
162167
KevinBoxBoard() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
163168
boot_button_(BOOT_BUTTON_GPIO),
@@ -172,6 +177,7 @@ class KevinBoxBoard : public Ml307Board {
172177

173178
InitializeButtons();
174179
InitializePowerSaveTimer();
180+
InitializeIot();
175181
}
176182

177183
virtual Led* GetBuiltinLed() override {

main/boards/kevin-c3/kevin_box_board.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "button.h"
55
#include "led.h"
66
#include "config.h"
7+
#include "iot/thing_manager.h"
78

89
#include <wifi_station.h>
910
#include <esp_log.h>
@@ -48,10 +49,17 @@ class KevinBoxBoard : public WifiBoard {
4849
});
4950
}
5051

52+
// 物联网初始化,添加对 AI 可见设备
53+
void InitializeIot() {
54+
auto& thing_manager = iot::ThingManager::GetInstance();
55+
thing_manager.AddThing(iot::CreateThing("Speaker"));
56+
}
57+
5158
public:
5259
KevinBoxBoard() : boot_button_(BOOT_BUTTON_GPIO) {
5360
InitializeCodecI2c();
5461
InitializeButtons();
62+
InitializeIot();
5563
}
5664

5765
virtual Led* GetBuiltinLed() override {

main/boards/lichuang-dev/lichuang_dev_board.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "led.h"
77
#include "config.h"
88
#include "i2c_device.h"
9+
#include "iot/thing_manager.h"
910

1011
#include <esp_log.h>
1112
#include <esp_lcd_panel_vendor.h>
@@ -119,12 +120,19 @@ class LichuangDevBoard : public WifiBoard {
119120
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
120121
}
121122

123+
// 物联网初始化,添加对 AI 可见设备
124+
void InitializeIot() {
125+
auto& thing_manager = iot::ThingManager::GetInstance();
126+
thing_manager.AddThing(iot::CreateThing("Speaker"));
127+
}
128+
122129
public:
123130
LichuangDevBoard() : boot_button_(BOOT_BUTTON_GPIO) {
124131
InitializeI2c();
125132
InitializeSpi();
126133
InitializeSt7789Display();
127134
InitializeButtons();
135+
InitializeIot();
128136
}
129137

130138
virtual Led* GetBuiltinLed() override {

0 commit comments

Comments
 (0)