Skip to content

Commit

Permalink
add iot speaker for boards
Browse files Browse the repository at this point in the history
  • Loading branch information
78 committed Dec 6, 2024
1 parent d31901e commit 051a0ba
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
16 changes: 12 additions & 4 deletions main/audio_codecs/no_audio_codec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n
output_sample_rate_ = output_sample_rate;

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


i2s_std_config_t tx_std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG((uint32_t)output_sample_rate_),
.clk_cfg = {
.sample_rate_hz = (uint32_t)output_sample_rate_,
.clk_src = I2S_CLK_SRC_DEFAULT,
.ext_clk_freq_hz = 0,
.mclk_multiple = I2S_MCLK_MULTIPLE_256
},
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_MONO),
.gpio_cfg = {
.mclk = I2S_GPIO_UNUSED,
Expand All @@ -163,9 +168,9 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n
},
};
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle_, &tx_std_cfg));

#if SOC_I2S_SUPPORTS_PDM_RX
// Create a new channel for MIC in PDM mode
i2s_chan_config_t rx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_0, I2S_ROLE_MASTER);
i2s_chan_config_t rx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG((i2s_port_t)0, I2S_ROLE_MASTER);
ESP_ERROR_CHECK(i2s_new_channel(&rx_chan_cfg, NULL, &rx_handle_));
i2s_pdm_rx_config_t pdm_rx_cfg = {
.clk_cfg = I2S_PDM_RX_CLK_DEFAULT_CONFIG((uint32_t)input_sample_rate_),
Expand All @@ -181,6 +186,9 @@ NoAudioCodec::NoAudioCodec(int input_sample_rate, int output_sample_rate, gpio_n
},
};
ESP_ERROR_CHECK(i2s_channel_init_pdm_rx_mode(rx_handle_, &pdm_rx_cfg));
#else
ESP_LOGE(TAG, "PDM is not supported");
#endif
ESP_LOGI(TAG, "Simplex channels created");
}

Expand Down
8 changes: 8 additions & 0 deletions main/boards/esp-box-3/esp_box3_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "button.h"
#include "led.h"
#include "config.h"
#include "iot/thing_manager.h"

#include <esp_log.h>
#include <driver/i2c_master.h>
Expand Down Expand Up @@ -39,10 +40,17 @@ class EspBox3Board : public WifiBoard {
});
}

// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
}

public:
EspBox3Board() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeI2c();
InitializeButtons();
InitializeIot();
}

virtual Led* GetBuiltinLed() override {
Expand Down
16 changes: 11 additions & 5 deletions main/boards/kevin-box-1/kevin_box_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
#include "button.h"
#include "led.h"
#include "config.h"
#include "iot/thing_manager.h"

#include <esp_log.h>
#include <esp_spiffs.h>
#include <driver/gpio.h>
#include <driver/i2c_master.h>

static const char *TAG = "KevinBoxBoard";
#define TAG "KevinBoxBoard"

class KevinBoxBoard : public Ml307Board {
private:
Expand Down Expand Up @@ -95,8 +96,7 @@ class KevinBoxBoard : public Ml307Board {
});

volume_up_button_.OnLongPress([this]() {
auto codec = GetAudioCodec();
codec->SetOutputVolume(100);
GetAudioCodec()->SetOutputVolume(100);
GetDisplay()->ShowNotification("最大音量");
});

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

volume_down_button_.OnLongPress([this]() {
auto codec = GetAudioCodec();
codec->SetOutputVolume(0);
GetAudioCodec()->SetOutputVolume(0);
GetDisplay()->ShowNotification("已静音");
});
}

// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
}

public:
KevinBoxBoard() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
boot_button_(BOOT_BUTTON_GPIO),
Expand All @@ -128,6 +133,7 @@ class KevinBoxBoard : public Ml307Board {
Enable4GModule();

InitializeButtons();
InitializeIot();
}

virtual Led* GetBuiltinLed() override {
Expand Down
16 changes: 11 additions & 5 deletions main/boards/kevin-box-2/kevin_box_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
#include "led.h"
#include "config.h"
#include "axp2101.h"
#include "iot/thing_manager.h"

#include <esp_log.h>
#include <esp_spiffs.h>
#include <driver/gpio.h>
#include <driver/i2c_master.h>
#include <esp_timer.h>

static const char *TAG = "KevinBoxBoard";
#define TAG "KevinBoxBoard"

class KevinBoxBoard : public Ml307Board {
private:
Expand Down Expand Up @@ -136,8 +137,7 @@ class KevinBoxBoard : public Ml307Board {
});

volume_up_button_.OnLongPress([this]() {
auto codec = GetAudioCodec();
codec->SetOutputVolume(100);
GetAudioCodec()->SetOutputVolume(100);
GetDisplay()->ShowNotification("最大音量");
});

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

volume_down_button_.OnLongPress([this]() {
auto codec = GetAudioCodec();
codec->SetOutputVolume(0);
GetAudioCodec()->SetOutputVolume(0);
GetDisplay()->ShowNotification("已静音");
});
}

// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
}

public:
KevinBoxBoard() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
boot_button_(BOOT_BUTTON_GPIO),
Expand All @@ -172,6 +177,7 @@ class KevinBoxBoard : public Ml307Board {

InitializeButtons();
InitializePowerSaveTimer();
InitializeIot();
}

virtual Led* GetBuiltinLed() override {
Expand Down
8 changes: 8 additions & 0 deletions main/boards/kevin-c3/kevin_box_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "button.h"
#include "led.h"
#include "config.h"
#include "iot/thing_manager.h"

#include <wifi_station.h>
#include <esp_log.h>
Expand Down Expand Up @@ -48,10 +49,17 @@ class KevinBoxBoard : public WifiBoard {
});
}

// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
}

public:
KevinBoxBoard() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeCodecI2c();
InitializeButtons();
InitializeIot();
}

virtual Led* GetBuiltinLed() override {
Expand Down
8 changes: 8 additions & 0 deletions main/boards/lichuang-dev/lichuang_dev_board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "led.h"
#include "config.h"
#include "i2c_device.h"
#include "iot/thing_manager.h"

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

// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
}

public:
LichuangDevBoard() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeI2c();
InitializeSpi();
InitializeSt7789Display();
InitializeButtons();
InitializeIot();
}

virtual Led* GetBuiltinLed() override {
Expand Down

0 comments on commit 051a0ba

Please sign in to comment.