add new boards
This commit is contained in:
parent
a701d5918e
commit
b0bc81b921
@ -55,7 +55,10 @@ Application::~Application() {
|
|||||||
opus_decoder_destroy(opus_decoder_);
|
opus_decoder_destroy(opus_decoder_);
|
||||||
}
|
}
|
||||||
if (audio_encode_task_stack_ != nullptr) {
|
if (audio_encode_task_stack_ != nullptr) {
|
||||||
free(audio_encode_task_stack_);
|
heap_caps_free(audio_encode_task_stack_);
|
||||||
|
}
|
||||||
|
if (main_loop_task_stack_ != nullptr) {
|
||||||
|
heap_caps_free(main_loop_task_stack_);
|
||||||
}
|
}
|
||||||
if (audio_device_ != nullptr) {
|
if (audio_device_ != nullptr) {
|
||||||
delete audio_device_;
|
delete audio_device_;
|
||||||
@ -132,6 +135,8 @@ void Application::Start() {
|
|||||||
|
|
||||||
audio_device_ = board.CreateAudioDevice();
|
audio_device_ = board.CreateAudioDevice();
|
||||||
audio_device_->Initialize();
|
audio_device_->Initialize();
|
||||||
|
audio_device_->EnableOutput(true);
|
||||||
|
audio_device_->EnableInput(true);
|
||||||
audio_device_->OnInputData([this](std::vector<int16_t>&& data) {
|
audio_device_->OnInputData([this](std::vector<int16_t>&& data) {
|
||||||
if (16000 != AUDIO_INPUT_SAMPLE_RATE) {
|
if (16000 != AUDIO_INPUT_SAMPLE_RATE) {
|
||||||
if (audio_device_->input_channels() == 2) {
|
if (audio_device_->input_channels() == 2) {
|
||||||
@ -176,7 +181,7 @@ void Application::Start() {
|
|||||||
|
|
||||||
// OPUS encoder / decoder use a lot of stack memory
|
// OPUS encoder / decoder use a lot of stack memory
|
||||||
const size_t opus_stack_size = 4096 * 8;
|
const size_t opus_stack_size = 4096 * 8;
|
||||||
audio_encode_task_stack_ = (StackType_t*)malloc(opus_stack_size);
|
audio_encode_task_stack_ = (StackType_t*)heap_caps_malloc(opus_stack_size, MALLOC_CAP_SPIRAM);
|
||||||
audio_encode_task_ = xTaskCreateStatic([](void* arg) {
|
audio_encode_task_ = xTaskCreateStatic([](void* arg) {
|
||||||
Application* app = (Application*)arg;
|
Application* app = (Application*)arg;
|
||||||
app->AudioEncodeTask();
|
app->AudioEncodeTask();
|
||||||
@ -189,68 +194,7 @@ void Application::Start() {
|
|||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}, "play_audio", 4096 * 4, this, 4, NULL);
|
}, "play_audio", 4096 * 4, this, 4, NULL);
|
||||||
|
|
||||||
#ifdef CONFIG_USE_AFE_SR
|
board.StartNetwork();
|
||||||
wake_word_detect_.Initialize(audio_device_->input_channels(), audio_device_->input_reference());
|
|
||||||
wake_word_detect_.OnVadStateChange([this](bool speaking) {
|
|
||||||
Schedule([this, speaking]() {
|
|
||||||
auto& builtin_led = BuiltinLed::GetInstance();
|
|
||||||
if (chat_state_ == kChatStateListening) {
|
|
||||||
if (speaking) {
|
|
||||||
builtin_led.SetRed(32);
|
|
||||||
} else {
|
|
||||||
builtin_led.SetRed(8);
|
|
||||||
}
|
|
||||||
builtin_led.TurnOn();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
wake_word_detect_.OnWakeWordDetected([this]() {
|
|
||||||
Schedule([this]() {
|
|
||||||
if (chat_state_ == kChatStateIdle) {
|
|
||||||
// Encode the wake word data and start websocket client at the same time
|
|
||||||
// They both consume a lot of time (700ms), so we can do them in parallel
|
|
||||||
wake_word_detect_.EncodeWakeWordData();
|
|
||||||
|
|
||||||
SetChatState(kChatStateConnecting);
|
|
||||||
if (ws_client_ == nullptr) {
|
|
||||||
StartWebSocketClient();
|
|
||||||
}
|
|
||||||
if (ws_client_ && ws_client_->IsConnected()) {
|
|
||||||
auto encoded = wake_word_detect_.GetWakeWordStream();
|
|
||||||
// Send the wake word data to the server
|
|
||||||
ws_client_->Send(encoded.data(), encoded.size(), true);
|
|
||||||
opus_encoder_.ResetState();
|
|
||||||
// Send a ready message to indicate the server that the wake word data is sent
|
|
||||||
SetChatState(kChatStateWakeWordDetected);
|
|
||||||
// If connected, the hello message is already sent, so we can start communication
|
|
||||||
audio_processor_.Start();
|
|
||||||
ESP_LOGI(TAG, "Audio processor started");
|
|
||||||
} else {
|
|
||||||
SetChatState(kChatStateIdle);
|
|
||||||
}
|
|
||||||
} else if (chat_state_ == kChatStateSpeaking) {
|
|
||||||
AbortSpeaking();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resume detection
|
|
||||||
wake_word_detect_.StartDetection();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
wake_word_detect_.StartDetection();
|
|
||||||
|
|
||||||
audio_processor_.Initialize(audio_device_->input_channels(), audio_device_->input_reference());
|
|
||||||
audio_processor_.OnOutput([this](std::vector<int16_t>&& data) {
|
|
||||||
Schedule([this, data = std::move(data)]() {
|
|
||||||
if (chat_state_ == kChatStateListening) {
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
|
||||||
audio_encode_queue_.emplace_back(std::move(data));
|
|
||||||
cv_.notify_all();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Blink the LED to indicate the device is running
|
// Blink the LED to indicate the device is running
|
||||||
builtin_led.SetGreen();
|
builtin_led.SetGreen();
|
||||||
builtin_led.BlinkOnce();
|
builtin_led.BlinkOnce();
|
||||||
@ -317,11 +261,13 @@ void Application::Start() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
xTaskCreate([](void* arg) {
|
const size_t main_loop_stack_size = 4096 * 2;
|
||||||
|
main_loop_task_stack_ = (StackType_t*)heap_caps_malloc(main_loop_stack_size, MALLOC_CAP_SPIRAM);
|
||||||
|
xTaskCreateStatic([](void* arg) {
|
||||||
Application* app = (Application*)arg;
|
Application* app = (Application*)arg;
|
||||||
app->MainLoop();
|
app->MainLoop();
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}, "main_loop", 4096 * 2, this, 5, NULL);
|
}, "main_loop", main_loop_stack_size, this, 1, main_loop_task_stack_, &main_loop_task_buffer_);
|
||||||
|
|
||||||
// Launch a task to check for new firmware version
|
// Launch a task to check for new firmware version
|
||||||
xTaskCreate([](void* arg) {
|
xTaskCreate([](void* arg) {
|
||||||
@ -330,7 +276,69 @@ void Application::Start() {
|
|||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}, "check_new_version", 4096 * 2, this, 1, NULL);
|
}, "check_new_version", 4096 * 2, this, 1, NULL);
|
||||||
|
|
||||||
chat_state_ = kChatStateIdle;
|
#ifdef CONFIG_USE_AFE_SR
|
||||||
|
wake_word_detect_.Initialize(audio_device_->input_channels(), audio_device_->input_reference());
|
||||||
|
wake_word_detect_.OnVadStateChange([this](bool speaking) {
|
||||||
|
Schedule([this, speaking]() {
|
||||||
|
auto& builtin_led = BuiltinLed::GetInstance();
|
||||||
|
if (chat_state_ == kChatStateListening) {
|
||||||
|
if (speaking) {
|
||||||
|
builtin_led.SetRed(32);
|
||||||
|
} else {
|
||||||
|
builtin_led.SetRed(8);
|
||||||
|
}
|
||||||
|
builtin_led.TurnOn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wake_word_detect_.OnWakeWordDetected([this]() {
|
||||||
|
Schedule([this]() {
|
||||||
|
if (chat_state_ == kChatStateIdle) {
|
||||||
|
// Encode the wake word data and start websocket client at the same time
|
||||||
|
// They both consume a lot of time (700ms), so we can do them in parallel
|
||||||
|
wake_word_detect_.EncodeWakeWordData();
|
||||||
|
|
||||||
|
SetChatState(kChatStateConnecting);
|
||||||
|
if (ws_client_ == nullptr) {
|
||||||
|
StartWebSocketClient();
|
||||||
|
}
|
||||||
|
if (ws_client_ && ws_client_->IsConnected()) {
|
||||||
|
auto encoded = wake_word_detect_.GetWakeWordStream();
|
||||||
|
// Send the wake word data to the server
|
||||||
|
ws_client_->Send(encoded.data(), encoded.size(), true);
|
||||||
|
opus_encoder_.ResetState();
|
||||||
|
// Send a ready message to indicate the server that the wake word data is sent
|
||||||
|
SetChatState(kChatStateWakeWordDetected);
|
||||||
|
// If connected, the hello message is already sent, so we can start communication
|
||||||
|
audio_processor_.Start();
|
||||||
|
ESP_LOGI(TAG, "Audio processor started");
|
||||||
|
} else {
|
||||||
|
SetChatState(kChatStateIdle);
|
||||||
|
}
|
||||||
|
} else if (chat_state_ == kChatStateSpeaking) {
|
||||||
|
AbortSpeaking();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resume detection
|
||||||
|
wake_word_detect_.StartDetection();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
wake_word_detect_.StartDetection();
|
||||||
|
|
||||||
|
audio_processor_.Initialize(audio_device_->input_channels(), audio_device_->input_reference());
|
||||||
|
audio_processor_.OnOutput([this](std::vector<int16_t>&& data) {
|
||||||
|
Schedule([this, data = std::move(data)]() {
|
||||||
|
if (chat_state_ == kChatStateListening) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
audio_encode_queue_.emplace_back(std::move(data));
|
||||||
|
cv_.notify_all();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SetChatState(kChatStateIdle);
|
||||||
display_.UpdateDisplay();
|
display_.UpdateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,6 +404,7 @@ void Application::SetChatState(ChatState state) {
|
|||||||
case kChatStateUnknown:
|
case kChatStateUnknown:
|
||||||
case kChatStateIdle:
|
case kChatStateIdle:
|
||||||
builtin_led.TurnOff();
|
builtin_led.TurnOff();
|
||||||
|
audio_device_->EnableOutput(false);
|
||||||
break;
|
break;
|
||||||
case kChatStateConnecting:
|
case kChatStateConnecting:
|
||||||
builtin_led.SetBlue();
|
builtin_led.SetBlue();
|
||||||
@ -408,6 +417,7 @@ void Application::SetChatState(ChatState state) {
|
|||||||
case kChatStateSpeaking:
|
case kChatStateSpeaking:
|
||||||
builtin_led.SetGreen();
|
builtin_led.SetGreen();
|
||||||
builtin_led.TurnOn();
|
builtin_led.TurnOn();
|
||||||
|
audio_device_->EnableOutput(true);
|
||||||
break;
|
break;
|
||||||
case kChatStateWakeWordDetected:
|
case kChatStateWakeWordDetected:
|
||||||
builtin_led.SetBlue();
|
builtin_led.SetBlue();
|
||||||
@ -474,21 +484,23 @@ void Application::AudioEncodeTask() {
|
|||||||
audio_decode_queue_.pop_front();
|
audio_decode_queue_.pop_front();
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
int frame_size = opus_decode_sample_rate_ * opus_duration_ms_ / 1000;
|
if (packet->type == kAudioPacketTypeData && !skip_to_end_) {
|
||||||
packet->pcm.resize(frame_size);
|
int frame_size = opus_decode_sample_rate_ * opus_duration_ms_ / 1000;
|
||||||
|
packet->pcm.resize(frame_size);
|
||||||
|
|
||||||
int ret = opus_decode(opus_decoder_, packet->opus.data(), packet->opus.size(), packet->pcm.data(), frame_size, 0);
|
int ret = opus_decode(opus_decoder_, packet->opus.data(), packet->opus.size(), packet->pcm.data(), frame_size, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ESP_LOGE(TAG, "Failed to decode audio, error code: %d", ret);
|
ESP_LOGE(TAG, "Failed to decode audio, error code: %d", ret);
|
||||||
delete packet;
|
delete packet;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opus_decode_sample_rate_ != AUDIO_OUTPUT_SAMPLE_RATE) {
|
if (opus_decode_sample_rate_ != AUDIO_OUTPUT_SAMPLE_RATE) {
|
||||||
int target_size = output_resampler_.GetOutputSamples(frame_size);
|
int target_size = output_resampler_.GetOutputSamples(frame_size);
|
||||||
std::vector<int16_t> resampled(target_size);
|
std::vector<int16_t> resampled(target_size);
|
||||||
output_resampler_.Process(packet->pcm.data(), frame_size, resampled.data());
|
output_resampler_.Process(packet->pcm.data(), frame_size, resampled.data());
|
||||||
packet->pcm = std::move(resampled);
|
packet->pcm = std::move(resampled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|||||||
@ -122,9 +122,9 @@ private:
|
|||||||
OpusResampler input_resampler_;
|
OpusResampler input_resampler_;
|
||||||
OpusResampler output_resampler_;
|
OpusResampler output_resampler_;
|
||||||
|
|
||||||
TaskHandle_t check_new_version_task_ = nullptr;
|
TaskHandle_t main_loop_task_ = nullptr;
|
||||||
StaticTask_t check_new_version_task_buffer_;
|
StaticTask_t main_loop_task_buffer_;
|
||||||
StackType_t* check_new_version_task_stack_ = nullptr;
|
StackType_t* main_loop_task_stack_ = nullptr;
|
||||||
|
|
||||||
void MainLoop();
|
void MainLoop();
|
||||||
BinaryProtocol3* AllocateBinaryProtocol3(const uint8_t* payload, size_t payload_size);
|
BinaryProtocol3* AllocateBinaryProtocol3(const uint8_t* payload, size_t payload_size);
|
||||||
|
|||||||
@ -176,15 +176,15 @@ int AudioDevice::Write(const int16_t* data, int samples) {
|
|||||||
int AudioDevice::Read(int16_t* dest, int samples) {
|
int AudioDevice::Read(int16_t* dest, int samples) {
|
||||||
size_t bytes_read;
|
size_t bytes_read;
|
||||||
|
|
||||||
int32_t bit32_buffer_[samples];
|
int32_t bit32_buffer[samples];
|
||||||
if (i2s_channel_read(rx_handle_, bit32_buffer_, samples * sizeof(int32_t), &bytes_read, portMAX_DELAY) != ESP_OK) {
|
if (i2s_channel_read(rx_handle_, bit32_buffer, samples * sizeof(int32_t), &bytes_read, portMAX_DELAY) != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Read Failed!");
|
ESP_LOGE(TAG, "Read Failed!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
samples = bytes_read / sizeof(int32_t);
|
samples = bytes_read / sizeof(int32_t);
|
||||||
for (int i = 0; i < samples; i++) {
|
for (int i = 0; i < samples; i++) {
|
||||||
int32_t value = bit32_buffer_[i] >> 12;
|
int32_t value = bit32_buffer[i] >> 12;
|
||||||
dest[i] = (value > INT16_MAX) ? INT16_MAX : (value < -INT16_MAX) ? -INT16_MAX : (int16_t)value;
|
dest[i] = (value > INT16_MAX) ? INT16_MAX : (value < -INT16_MAX) ? -INT16_MAX : (int16_t)value;
|
||||||
}
|
}
|
||||||
return samples;
|
return samples;
|
||||||
@ -224,3 +224,19 @@ void AudioDevice::SetOutputVolume(int volume) {
|
|||||||
output_volume_ = volume;
|
output_volume_ = volume;
|
||||||
ESP_LOGI(TAG, "Set output volume to %d", output_volume_);
|
ESP_LOGI(TAG, "Set output volume to %d", output_volume_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioDevice::EnableInput(bool enable) {
|
||||||
|
if (enable == input_enabled_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
input_enabled_ = enable;
|
||||||
|
ESP_LOGI(TAG, "Set input enable to %s", enable ? "true" : "false");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioDevice::EnableOutput(bool enable) {
|
||||||
|
if (enable == output_enabled_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
output_enabled_ = enable;
|
||||||
|
ESP_LOGI(TAG, "Set output enable to %s", enable ? "true" : "false");
|
||||||
|
}
|
||||||
|
|||||||
@ -17,6 +17,8 @@ public:
|
|||||||
void OnInputData(std::function<void(std::vector<int16_t>&& data)> callback);
|
void OnInputData(std::function<void(std::vector<int16_t>&& data)> callback);
|
||||||
void OutputData(std::vector<int16_t>& data);
|
void OutputData(std::vector<int16_t>& data);
|
||||||
virtual void SetOutputVolume(int volume);
|
virtual void SetOutputVolume(int volume);
|
||||||
|
virtual void EnableInput(bool enable);
|
||||||
|
virtual void EnableOutput(bool enable);
|
||||||
|
|
||||||
inline bool duplex() const { return duplex_; }
|
inline bool duplex() const { return duplex_; }
|
||||||
inline bool input_reference() const { return input_reference_; }
|
inline bool input_reference() const { return input_reference_; }
|
||||||
@ -36,6 +38,8 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
bool duplex_ = false;
|
bool duplex_ = false;
|
||||||
bool input_reference_ = false;
|
bool input_reference_ = false;
|
||||||
|
bool input_enabled_ = false;
|
||||||
|
bool output_enabled_ = false;
|
||||||
int input_sample_rate_ = 0;
|
int input_sample_rate_ = 0;
|
||||||
int output_sample_rate_ = 0;
|
int output_sample_rate_ = 0;
|
||||||
int input_channels_ = 1;
|
int input_channels_ = 1;
|
||||||
|
|||||||
@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
// static const char *TAG = "Board";
|
// static const char *TAG = "Board";
|
||||||
|
|
||||||
bool Board::GetBatteryVoltage(int &voltage) {
|
bool Board::GetBatteryVoltage(int &voltage, bool& charging) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,12 +20,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void Initialize() = 0;
|
virtual void Initialize() = 0;
|
||||||
|
virtual void StartNetwork() = 0;
|
||||||
virtual ~Board() = default;
|
virtual ~Board() = default;
|
||||||
virtual AudioDevice* CreateAudioDevice() = 0;
|
virtual AudioDevice* CreateAudioDevice() = 0;
|
||||||
virtual Http* CreateHttp() = 0;
|
virtual Http* CreateHttp() = 0;
|
||||||
virtual WebSocket* CreateWebSocket() = 0;
|
virtual WebSocket* CreateWebSocket() = 0;
|
||||||
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) = 0;
|
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) = 0;
|
||||||
virtual bool GetBatteryVoltage(int &voltage);
|
virtual bool GetBatteryVoltage(int &voltage, bool& charging);
|
||||||
virtual std::string GetJson() = 0;
|
virtual std::string GetJson() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@ -32,7 +32,7 @@ void BoxAudioDevice::Initialize() {
|
|||||||
|
|
||||||
// Initialize I2C peripheral
|
// Initialize I2C peripheral
|
||||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
i2c_master_bus_config_t i2c_bus_cfg = {
|
||||||
.i2c_port = I2C_NUM_0,
|
.i2c_port = I2C_NUM_1,
|
||||||
.sda_io_num = (gpio_num_t)AUDIO_CODEC_I2C_SDA_PIN,
|
.sda_io_num = (gpio_num_t)AUDIO_CODEC_I2C_SDA_PIN,
|
||||||
.scl_io_num = (gpio_num_t)AUDIO_CODEC_I2C_SCL_PIN,
|
.scl_io_num = (gpio_num_t)AUDIO_CODEC_I2C_SCL_PIN,
|
||||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||||
@ -47,6 +47,28 @@ void BoxAudioDevice::Initialize() {
|
|||||||
|
|
||||||
CreateDuplexChannels();
|
CreateDuplexChannels();
|
||||||
|
|
||||||
|
#ifdef AUDIO_CODEC_USE_PCA9557
|
||||||
|
// Initialize PCA9557
|
||||||
|
i2c_device_config_t pca9557_cfg = {
|
||||||
|
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||||
|
.device_address = 0x19,
|
||||||
|
.scl_speed_hz = 400000,
|
||||||
|
.scl_wait_us = 0,
|
||||||
|
.flags = {
|
||||||
|
.disable_ack_check = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
i2c_master_dev_handle_t pca9557_handle;
|
||||||
|
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_master_handle_, &pca9557_cfg, &pca9557_handle));
|
||||||
|
assert(pca9557_handle != NULL);
|
||||||
|
auto pca9557_set_register = [](i2c_master_dev_handle_t pca9557_handle, uint8_t data_addr, uint8_t data) {
|
||||||
|
uint8_t data_[2] = {data_addr, data};
|
||||||
|
ESP_ERROR_CHECK(i2c_master_transmit(pca9557_handle, data_, 2, 50));
|
||||||
|
};
|
||||||
|
pca9557_set_register(pca9557_handle, 0x03, 0xfd);
|
||||||
|
pca9557_set_register(pca9557_handle, 0x01, 0x02);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Do initialize of related interface: data_if, ctrl_if and gpio_if
|
// Do initialize of related interface: data_if, ctrl_if and gpio_if
|
||||||
audio_codec_i2s_cfg_t i2s_cfg = {
|
audio_codec_i2s_cfg_t i2s_cfg = {
|
||||||
.port = I2S_NUM_0,
|
.port = I2S_NUM_0,
|
||||||
@ -58,8 +80,8 @@ void BoxAudioDevice::Initialize() {
|
|||||||
|
|
||||||
// Output
|
// Output
|
||||||
audio_codec_i2c_cfg_t i2c_cfg = {
|
audio_codec_i2c_cfg_t i2c_cfg = {
|
||||||
.port = I2C_NUM_0,
|
.port = I2C_NUM_1,
|
||||||
.addr = ES8311_CODEC_DEFAULT_ADDR,
|
.addr = AUDIO_CODEC_ES8311_ADDR,
|
||||||
.bus_handle = i2c_master_handle_,
|
.bus_handle = i2c_master_handle_,
|
||||||
};
|
};
|
||||||
out_ctrl_if_ = audio_codec_new_i2c_ctrl(&i2c_cfg);
|
out_ctrl_if_ = audio_codec_new_i2c_ctrl(&i2c_cfg);
|
||||||
@ -87,20 +109,8 @@ void BoxAudioDevice::Initialize() {
|
|||||||
output_dev_ = esp_codec_dev_new(&dev_cfg);
|
output_dev_ = esp_codec_dev_new(&dev_cfg);
|
||||||
assert(output_dev_ != NULL);
|
assert(output_dev_ != NULL);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, output_volume_));
|
|
||||||
|
|
||||||
// Play 16bit 1 channel
|
|
||||||
esp_codec_dev_sample_info_t fs = {
|
|
||||||
.bits_per_sample = 16,
|
|
||||||
.channel = 1,
|
|
||||||
.channel_mask = 0,
|
|
||||||
.sample_rate = (uint32_t)output_sample_rate_,
|
|
||||||
.mclk_multiple = 0,
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(esp_codec_dev_open(output_dev_, &fs));
|
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
i2c_cfg.addr = ES7210_CODEC_DEFAULT_ADDR;
|
i2c_cfg.addr = AUDIO_CODEC_ES7210_ADDR;
|
||||||
in_ctrl_if_ = audio_codec_new_i2c_ctrl(&i2c_cfg);
|
in_ctrl_if_ = audio_codec_new_i2c_ctrl(&i2c_cfg);
|
||||||
assert(in_ctrl_if_ != NULL);
|
assert(in_ctrl_if_ != NULL);
|
||||||
|
|
||||||
@ -115,16 +125,6 @@ void BoxAudioDevice::Initialize() {
|
|||||||
input_dev_ = esp_codec_dev_new(&dev_cfg);
|
input_dev_ = esp_codec_dev_new(&dev_cfg);
|
||||||
assert(input_dev_ != NULL);
|
assert(input_dev_ != NULL);
|
||||||
|
|
||||||
fs.channel = 4;
|
|
||||||
if (input_channels_ == 1) {
|
|
||||||
fs.channel_mask = ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0);
|
|
||||||
} else {
|
|
||||||
fs.channel_mask = ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0) | ESP_CODEC_DEV_MAKE_CHANNEL_MASK(1);
|
|
||||||
}
|
|
||||||
ESP_ERROR_CHECK(esp_codec_dev_open(input_dev_, &fs));
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_codec_dev_set_in_channel_gain(input_dev_, ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0), 30.0));
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "BoxAudioDevice initialized");
|
ESP_LOGI(TAG, "BoxAudioDevice initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,12 +219,12 @@ void BoxAudioDevice::CreateDuplexChannels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int BoxAudioDevice::Read(int16_t *buffer, int samples) {
|
int BoxAudioDevice::Read(int16_t *buffer, int samples) {
|
||||||
ESP_ERROR_CHECK(esp_codec_dev_read(input_dev_, (void*)buffer, samples * sizeof(int16_t)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_read(input_dev_, (void*)buffer, samples * sizeof(int16_t)));
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BoxAudioDevice::Write(const int16_t *buffer, int samples) {
|
int BoxAudioDevice::Write(const int16_t *buffer, int samples) {
|
||||||
ESP_ERROR_CHECK(esp_codec_dev_write(output_dev_, (void*)buffer, samples * sizeof(int16_t)));
|
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_codec_dev_write(output_dev_, (void*)buffer, samples * sizeof(int16_t)));
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,3 +232,47 @@ void BoxAudioDevice::SetOutputVolume(int volume) {
|
|||||||
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, volume));
|
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, volume));
|
||||||
AudioDevice::SetOutputVolume(volume);
|
AudioDevice::SetOutputVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BoxAudioDevice::EnableInput(bool enable) {
|
||||||
|
if (enable == input_enabled_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (enable) {
|
||||||
|
esp_codec_dev_sample_info_t fs = {
|
||||||
|
.bits_per_sample = 16,
|
||||||
|
.channel = 4,
|
||||||
|
.channel_mask = ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0),
|
||||||
|
.sample_rate = (uint32_t)output_sample_rate_,
|
||||||
|
.mclk_multiple = 0,
|
||||||
|
};
|
||||||
|
if (input_reference_) {
|
||||||
|
fs.channel_mask |= ESP_CODEC_DEV_MAKE_CHANNEL_MASK(1);
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(esp_codec_dev_open(input_dev_, &fs));
|
||||||
|
ESP_ERROR_CHECK(esp_codec_dev_set_in_channel_gain(input_dev_, ESP_CODEC_DEV_MAKE_CHANNEL_MASK(0), 30.0));
|
||||||
|
} else {
|
||||||
|
ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
|
||||||
|
}
|
||||||
|
AudioDevice::EnableInput(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BoxAudioDevice::EnableOutput(bool enable) {
|
||||||
|
if (enable == output_enabled_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (enable) {
|
||||||
|
// Play 16bit 1 channel
|
||||||
|
esp_codec_dev_sample_info_t fs = {
|
||||||
|
.bits_per_sample = 16,
|
||||||
|
.channel = 1,
|
||||||
|
.channel_mask = 0,
|
||||||
|
.sample_rate = (uint32_t)output_sample_rate_,
|
||||||
|
.mclk_multiple = 0,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(esp_codec_dev_open(output_dev_, &fs));
|
||||||
|
ESP_ERROR_CHECK(esp_codec_dev_set_out_vol(output_dev_, output_volume_));
|
||||||
|
} else {
|
||||||
|
ESP_ERROR_CHECK(esp_codec_dev_close(output_dev_));
|
||||||
|
}
|
||||||
|
AudioDevice::EnableOutput(enable);
|
||||||
|
}
|
||||||
|
|||||||
@ -12,8 +12,10 @@ class BoxAudioDevice : public AudioDevice {
|
|||||||
public:
|
public:
|
||||||
BoxAudioDevice();
|
BoxAudioDevice();
|
||||||
virtual ~BoxAudioDevice();
|
virtual ~BoxAudioDevice();
|
||||||
void Initialize() override;
|
virtual void Initialize() override;
|
||||||
void SetOutputVolume(int volume) override;
|
virtual void SetOutputVolume(int volume) override;
|
||||||
|
virtual void EnableInput(bool enable) override;
|
||||||
|
virtual void EnableOutput(bool enable) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
i2c_master_bus_handle_t i2c_master_handle_ = nullptr;
|
i2c_master_bus_handle_t i2c_master_handle_ = nullptr;
|
||||||
|
|||||||
@ -38,6 +38,20 @@ elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_0)
|
|||||||
list(APPEND SOURCES ${BOARD_SOURCES} "Ml307Board.cc")
|
list(APPEND SOURCES ${BOARD_SOURCES} "Ml307Board.cc")
|
||||||
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE})
|
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE})
|
||||||
list(APPEND SOURCES "BoxAudioDevice.cc")
|
list(APPEND SOURCES "BoxAudioDevice.cc")
|
||||||
|
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_1)
|
||||||
|
# add all files from boards/kevin-box-1
|
||||||
|
set(BOARD_TYPE "kevin-box-1")
|
||||||
|
file(GLOB BOARD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc)
|
||||||
|
list(APPEND SOURCES ${BOARD_SOURCES} "Ml307Board.cc")
|
||||||
|
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE})
|
||||||
|
list(APPEND SOURCES "BoxAudioDevice.cc")
|
||||||
|
elseif(CONFIG_BOARD_TYPE_LICHUANG_DEV)
|
||||||
|
# add all files from boards/lichuang-dev
|
||||||
|
set(BOARD_TYPE "lichuang-dev")
|
||||||
|
file(GLOB BOARD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc)
|
||||||
|
list(APPEND SOURCES ${BOARD_SOURCES} "WifiBoard.cc")
|
||||||
|
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE})
|
||||||
|
list(APPEND SOURCES "BoxAudioDevice.cc")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CONFIG_USE_AFE_SR)
|
if(CONFIG_USE_AFE_SR)
|
||||||
|
|||||||
@ -17,15 +17,14 @@ Display::Display(int sda_pin, int scl_pin) : sda_pin_(sda_pin), scl_pin_(scl_pin
|
|||||||
ESP_LOGI(TAG, "Display not connected");
|
ESP_LOGI(TAG, "Display not connected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "Display Pins: %d, %d", sda_pin_, scl_pin_);
|
|
||||||
|
|
||||||
i2c_master_bus_config_t bus_config = {
|
i2c_master_bus_config_t bus_config = {
|
||||||
.i2c_port = I2C_NUM_1,
|
.i2c_port = I2C_NUM_0,
|
||||||
.sda_io_num = (gpio_num_t)sda_pin_,
|
.sda_io_num = (gpio_num_t)sda_pin_,
|
||||||
.scl_io_num = (gpio_num_t)scl_pin_,
|
.scl_io_num = (gpio_num_t)scl_pin_,
|
||||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||||
.glitch_ignore_cnt = 7,
|
.glitch_ignore_cnt = 7,
|
||||||
.intr_priority = 1,
|
.intr_priority = 0,
|
||||||
.trans_queue_depth = 0,
|
.trans_queue_depth = 0,
|
||||||
.flags = {
|
.flags = {
|
||||||
.enable_internal_pullup = 1,
|
.enable_internal_pullup = 1,
|
||||||
@ -47,7 +46,7 @@ Display::Display(int sda_pin, int scl_pin) : sda_pin_(sda_pin), scl_pin_(scl_pin
|
|||||||
.dc_low_on_data = 0,
|
.dc_low_on_data = 0,
|
||||||
.disable_control_phase = 0,
|
.disable_control_phase = 0,
|
||||||
},
|
},
|
||||||
.scl_speed_hz = 400 * 1000,
|
.scl_speed_hz = 100 * 1000,
|
||||||
};
|
};
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c_v2(i2c_bus_, &io_config, &panel_io_));
|
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c_v2(i2c_bus_, &io_config, &panel_io_));
|
||||||
@ -71,7 +70,6 @@ Display::Display(int sda_pin, int scl_pin) : sda_pin_(sda_pin), scl_pin_(scl_pin
|
|||||||
ESP_LOGE(TAG, "Failed to initialize display");
|
ESP_LOGE(TAG, "Failed to initialize display");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_, true, true));
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Initialize LVGL");
|
ESP_LOGI(TAG, "Initialize LVGL");
|
||||||
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
||||||
@ -94,8 +92,8 @@ Display::Display(int sda_pin, int scl_pin) : sda_pin_(sda_pin), scl_pin_(scl_pin
|
|||||||
.monochrome = true,
|
.monochrome = true,
|
||||||
.rotation = {
|
.rotation = {
|
||||||
.swap_xy = false,
|
.swap_xy = false,
|
||||||
.mirror_x = true,
|
.mirror_x = DISPLAY_MIRROR_X,
|
||||||
.mirror_y = true,
|
.mirror_y = DISPLAY_MIRROR_Y,
|
||||||
},
|
},
|
||||||
.flags = {
|
.flags = {
|
||||||
.buff_dma = 1,
|
.buff_dma = 1,
|
||||||
@ -227,8 +225,12 @@ void Display::UpdateDisplay() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int battery_voltage;
|
int battery_voltage;
|
||||||
if (board.GetBatteryVoltage(battery_voltage)) {
|
bool charging;
|
||||||
|
if (board.GetBatteryVoltage(battery_voltage, charging)) {
|
||||||
text += "\n" + std::to_string(battery_voltage) + "mV";
|
text += "\n" + std::to_string(battery_voltage) + "mV";
|
||||||
|
if (charging) {
|
||||||
|
text += " (Charging)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SetText(text);
|
SetText(text);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,10 @@ choice BOARD_TYPE
|
|||||||
bool "ESP BOX 3"
|
bool "ESP BOX 3"
|
||||||
config BOARD_TYPE_KEVIN_BOX_0
|
config BOARD_TYPE_KEVIN_BOX_0
|
||||||
bool "Kevin Box 0"
|
bool "Kevin Box 0"
|
||||||
|
config BOARD_TYPE_KEVIN_BOX_1
|
||||||
|
bool "Kevin Box 1"
|
||||||
|
config BOARD_TYPE_LICHUANG_DEV
|
||||||
|
bool "立创开发板"
|
||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
config USE_AFE_SR
|
config USE_AFE_SR
|
||||||
|
|||||||
@ -51,9 +51,10 @@ void Ml307Board::StartNetwork() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Ml307Board::StartModem() {
|
void Ml307Board::StartModem() {
|
||||||
|
auto& display = Application::GetInstance().GetDisplay();
|
||||||
|
display.SetText(std::string("Starting modem"));
|
||||||
modem_.SetDebug(false);
|
modem_.SetDebug(false);
|
||||||
modem_.SetBaudRate(921600);
|
modem_.SetBaudRate(921600);
|
||||||
StartNetwork();
|
|
||||||
|
|
||||||
auto& application = Application::GetInstance();
|
auto& application = Application::GetInstance();
|
||||||
// If low power, the material ready event will be triggered by the modem because of a reset
|
// If low power, the material ready event will be triggered by the modem because of a reset
|
||||||
|
|||||||
@ -9,11 +9,11 @@ protected:
|
|||||||
Ml307AtModem modem_;
|
Ml307AtModem modem_;
|
||||||
|
|
||||||
void StartModem();
|
void StartModem();
|
||||||
void StartNetwork();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Ml307Board();
|
Ml307Board();
|
||||||
virtual void Initialize() override;
|
virtual void Initialize() override;
|
||||||
|
virtual void StartNetwork() override;
|
||||||
virtual AudioDevice* CreateAudioDevice() override;
|
virtual AudioDevice* CreateAudioDevice() override;
|
||||||
virtual Http* CreateHttp() override;
|
virtual Http* CreateHttp() override;
|
||||||
virtual WebSocket* CreateWebSocket() override;
|
virtual WebSocket* CreateWebSocket() override;
|
||||||
|
|||||||
@ -29,7 +29,7 @@ static std::string rssi_to_string(int rssi) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiBoard::StartWifi() {
|
void WifiBoard::StartNetwork() {
|
||||||
auto& application = Application::GetInstance();
|
auto& application = Application::GetInstance();
|
||||||
auto& display = application.GetDisplay();
|
auto& display = application.GetDisplay();
|
||||||
auto& builtin_led = BuiltinLed::GetInstance();
|
auto& builtin_led = BuiltinLed::GetInstance();
|
||||||
@ -45,13 +45,15 @@ void WifiBoard::StartWifi() {
|
|||||||
auto& wifi_ap = WifiConfigurationAp::GetInstance();
|
auto& wifi_ap = WifiConfigurationAp::GetInstance();
|
||||||
wifi_ap.SetSsidPrefix("Xiaozhi");
|
wifi_ap.SetSsidPrefix("Xiaozhi");
|
||||||
wifi_ap.Start();
|
wifi_ap.Start();
|
||||||
wifi_config_mode_ = true;
|
// Wait forever until reset after configuration
|
||||||
|
while (true) {
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WifiBoard::Initialize() {
|
void WifiBoard::Initialize() {
|
||||||
ESP_LOGI(TAG, "Initializing WifiBoard");
|
ESP_LOGI(TAG, "Initializing WifiBoard");
|
||||||
StartWifi();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Http* WifiBoard::CreateHttp() {
|
Http* WifiBoard::CreateHttp() {
|
||||||
@ -90,10 +92,12 @@ std::string WifiBoard::GetJson() {
|
|||||||
auto& wifi_station = WifiStation::GetInstance();
|
auto& wifi_station = WifiStation::GetInstance();
|
||||||
std::string board_type = BOARD_TYPE;
|
std::string board_type = BOARD_TYPE;
|
||||||
std::string board_json = std::string("{\"type\":\"" + board_type + "\",");
|
std::string board_json = std::string("{\"type\":\"" + board_type + "\",");
|
||||||
board_json += "\"ssid\":\"" + wifi_station.GetSsid() + "\",";
|
if (!wifi_config_mode_) {
|
||||||
board_json += "\"rssi\":" + std::to_string(wifi_station.GetRssi()) + ",";
|
board_json += "\"ssid\":\"" + wifi_station.GetSsid() + "\",";
|
||||||
board_json += "\"channel\":" + std::to_string(wifi_station.GetChannel()) + ",";
|
board_json += "\"rssi\":" + std::to_string(wifi_station.GetRssi()) + ",";
|
||||||
board_json += "\"ip\":\"" + wifi_station.GetIpAddress() + "\",";
|
board_json += "\"channel\":" + std::to_string(wifi_station.GetChannel()) + ",";
|
||||||
|
board_json += "\"ip\":\"" + wifi_station.GetIpAddress() + "\",";
|
||||||
|
}
|
||||||
board_json += "\"mac\":\"" + SystemInfo::GetMacAddress() + "\"}";
|
board_json += "\"mac\":\"" + SystemInfo::GetMacAddress() + "\"}";
|
||||||
return board_json;
|
return board_json;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,10 @@
|
|||||||
class WifiBoard : public Board {
|
class WifiBoard : public Board {
|
||||||
protected:
|
protected:
|
||||||
bool wifi_config_mode_ = false;
|
bool wifi_config_mode_ = false;
|
||||||
virtual void StartWifi();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void Initialize() override;
|
virtual void Initialize() override;
|
||||||
|
virtual void StartNetwork() override;
|
||||||
virtual Http* CreateHttp() override;
|
virtual Http* CreateHttp() override;
|
||||||
virtual WebSocket* CreateWebSocket() override;
|
virtual WebSocket* CreateWebSocket() override;
|
||||||
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override;
|
virtual bool GetNetworkState(std::string& network_name, int& signal_quality, std::string& signal_quality_text) override;
|
||||||
|
|||||||
@ -31,11 +31,12 @@
|
|||||||
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_40
|
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_40
|
||||||
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_39
|
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_39
|
||||||
|
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 128
|
|
||||||
#define DISPLAY_HEIGHT 32
|
|
||||||
#define DISPLAY_SDA_PIN GPIO_NUM_41
|
#define DISPLAY_SDA_PIN GPIO_NUM_41
|
||||||
#define DISPLAY_SCL_PIN GPIO_NUM_42
|
#define DISPLAY_SCL_PIN GPIO_NUM_42
|
||||||
|
#define DISPLAY_WIDTH 128
|
||||||
|
#define DISPLAY_HEIGHT 32
|
||||||
|
#define DISPLAY_MIRROR_X true
|
||||||
|
#define DISPLAY_MIRROR_Y true
|
||||||
|
|
||||||
|
|
||||||
#define ML307_RX_PIN GPIO_NUM_11
|
#define ML307_RX_PIN GPIO_NUM_11
|
||||||
|
|||||||
@ -32,9 +32,11 @@
|
|||||||
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_40
|
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_40
|
||||||
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_39
|
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_39
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 128
|
|
||||||
#define DISPLAY_HEIGHT 32
|
|
||||||
#define DISPLAY_SDA_PIN GPIO_NUM_41
|
#define DISPLAY_SDA_PIN GPIO_NUM_41
|
||||||
#define DISPLAY_SCL_PIN GPIO_NUM_42
|
#define DISPLAY_SCL_PIN GPIO_NUM_42
|
||||||
|
#define DISPLAY_WIDTH 128
|
||||||
|
#define DISPLAY_HEIGHT 32
|
||||||
|
#define DISPLAY_MIRROR_X true
|
||||||
|
#define DISPLAY_MIRROR_Y true
|
||||||
|
|
||||||
#endif // _BOARD_CONFIG_H_
|
#endif // _BOARD_CONFIG_H_
|
||||||
|
|||||||
@ -17,16 +17,20 @@
|
|||||||
#define AUDIO_CODEC_PA_PIN GPIO_NUM_46
|
#define AUDIO_CODEC_PA_PIN GPIO_NUM_46
|
||||||
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_8
|
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_8
|
||||||
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_18
|
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_18
|
||||||
|
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||||
|
#define AUDIO_CODEC_ES7210_ADDR ES7210_CODEC_DEFAULT_ADDR
|
||||||
|
|
||||||
#define BUILTIN_LED_GPIO GPIO_NUM_NC
|
#define BUILTIN_LED_GPIO GPIO_NUM_NC
|
||||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||||
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC
|
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC
|
||||||
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC
|
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 128
|
|
||||||
#define DISPLAY_HEIGHT 64
|
|
||||||
#define DISPLAY_SDA_PIN GPIO_NUM_NC
|
#define DISPLAY_SDA_PIN GPIO_NUM_NC
|
||||||
#define DISPLAY_SCL_PIN GPIO_NUM_NC
|
#define DISPLAY_SCL_PIN GPIO_NUM_NC
|
||||||
|
#define DISPLAY_WIDTH 128
|
||||||
|
#define DISPLAY_HEIGHT 64
|
||||||
|
#define DISPLAY_MIRROR_X true
|
||||||
|
#define DISPLAY_MIRROR_Y true
|
||||||
|
|
||||||
|
|
||||||
#endif // _BOARD_CONFIG_H_
|
#endif // _BOARD_CONFIG_H_
|
||||||
|
|||||||
@ -72,10 +72,11 @@ public:
|
|||||||
return new BoxAudioDevice();
|
return new BoxAudioDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool GetBatteryVoltage(int &voltage) override {
|
virtual bool GetBatteryVoltage(int &voltage, bool& charging) override {
|
||||||
int adc_reading;
|
int adc_reading;
|
||||||
ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle_, ADC_CHANNEL_0, &adc_reading));
|
ESP_ERROR_CHECK(adc_oneshot_read(adc1_handle_, ADC_CHANNEL_0, &adc_reading));
|
||||||
ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_handle_, adc_reading, &voltage));
|
ESP_ERROR_CHECK(adc_cali_raw_to_voltage(adc1_cali_handle_, adc_reading, &voltage));
|
||||||
|
charging = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -17,16 +17,20 @@
|
|||||||
#define AUDIO_CODEC_PA_PIN GPIO_NUM_40
|
#define AUDIO_CODEC_PA_PIN GPIO_NUM_40
|
||||||
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_39
|
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_39
|
||||||
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_38
|
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_38
|
||||||
|
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||||
|
#define AUDIO_CODEC_ES7210_ADDR ES7210_CODEC_DEFAULT_ADDR
|
||||||
|
|
||||||
#define BUILTIN_LED_GPIO GPIO_NUM_8
|
#define BUILTIN_LED_GPIO GPIO_NUM_8
|
||||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||||
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_6
|
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_6
|
||||||
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_7
|
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_7
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 128
|
|
||||||
#define DISPLAY_HEIGHT 64
|
|
||||||
#define DISPLAY_SDA_PIN GPIO_NUM_4
|
#define DISPLAY_SDA_PIN GPIO_NUM_4
|
||||||
#define DISPLAY_SCL_PIN GPIO_NUM_5
|
#define DISPLAY_SCL_PIN GPIO_NUM_5
|
||||||
|
#define DISPLAY_WIDTH 128
|
||||||
|
#define DISPLAY_HEIGHT 64
|
||||||
|
#define DISPLAY_MIRROR_X true
|
||||||
|
#define DISPLAY_MIRROR_Y true
|
||||||
|
|
||||||
#define ML307_RX_PIN GPIO_NUM_17
|
#define ML307_RX_PIN GPIO_NUM_17
|
||||||
#define ML307_TX_PIN GPIO_NUM_16
|
#define ML307_TX_PIN GPIO_NUM_16
|
||||||
|
|||||||
93
main/boards/kevin-box-1/KevinBoxBoard.cc
Normal file
93
main/boards/kevin-box-1/KevinBoxBoard.cc
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
#include "Ml307Board.h"
|
||||||
|
#include "BoxAudioDevice.h"
|
||||||
|
|
||||||
|
#include <esp_log.h>
|
||||||
|
#include <esp_spiffs.h>
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
#include <esp_adc/adc_oneshot.h>
|
||||||
|
#include <esp_adc/adc_cali.h>
|
||||||
|
#include <esp_adc/adc_cali_scheme.h>
|
||||||
|
|
||||||
|
static const char *TAG = "KevinBoxBoard";
|
||||||
|
|
||||||
|
class KevinBoxBoard : public Ml307Board {
|
||||||
|
private:
|
||||||
|
adc_oneshot_unit_handle_t adc1_handle_;
|
||||||
|
adc_cali_handle_t adc1_cali_handle_;
|
||||||
|
|
||||||
|
void MountStorage() {
|
||||||
|
// Mount the storage partition
|
||||||
|
esp_vfs_spiffs_conf_t conf = {
|
||||||
|
.base_path = "/storage",
|
||||||
|
.partition_label = "storage",
|
||||||
|
.max_files = 5,
|
||||||
|
.format_if_mount_failed = true,
|
||||||
|
};
|
||||||
|
esp_vfs_spiffs_register(&conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Enable4GModule() {
|
||||||
|
// Make GPIO15 HIGH to enable the 4G module
|
||||||
|
gpio_config_t ml307_enable_config = {
|
||||||
|
.pin_bit_mask = (1ULL << 15),
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
};
|
||||||
|
gpio_config(&ml307_enable_config);
|
||||||
|
gpio_set_level(GPIO_NUM_15, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void InitializeADC() {
|
||||||
|
adc_oneshot_unit_init_cfg_t init_config1 = {};
|
||||||
|
init_config1.unit_id = ADC_UNIT_1;
|
||||||
|
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config1, &adc1_handle_));
|
||||||
|
|
||||||
|
//-------------ADC1 Config---------------//
|
||||||
|
adc_oneshot_chan_cfg_t config = {
|
||||||
|
.atten = ADC_ATTEN_DB_12,
|
||||||
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle_, ADC_CHANNEL_0, &config));
|
||||||
|
|
||||||
|
adc_cali_curve_fitting_config_t cali_config = {
|
||||||
|
.unit_id = ADC_UNIT_1,
|
||||||
|
.chan = ADC_CHANNEL_0,
|
||||||
|
.atten = ADC_ATTEN_DB_12,
|
||||||
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(adc_cali_create_scheme_curve_fitting(&cali_config, &adc1_cali_handle_));
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
virtual void Initialize() override {
|
||||||
|
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
||||||
|
InitializeADC();
|
||||||
|
MountStorage();
|
||||||
|
Enable4GModule();
|
||||||
|
|
||||||
|
gpio_config_t charging_io = {
|
||||||
|
.pin_bit_mask = (1ULL << 2),
|
||||||
|
.mode = GPIO_MODE_INPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
};
|
||||||
|
gpio_config(&charging_io);
|
||||||
|
|
||||||
|
Ml307Board::Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual AudioDevice* CreateAudioDevice() override {
|
||||||
|
return new BoxAudioDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool GetBatteryVoltage(int &voltage, bool& charging) override {
|
||||||
|
ESP_ERROR_CHECK(adc_oneshot_get_calibrated_result(adc1_handle_, adc1_cali_handle_, ADC_CHANNEL_0, &voltage));
|
||||||
|
charging = gpio_get_level(GPIO_NUM_2) == 0;
|
||||||
|
ESP_LOGI(TAG, "Battery voltage: %d, Charging: %d", voltage, charging);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DECLARE_BOARD(KevinBoxBoard);
|
||||||
39
main/boards/kevin-box-1/config.h
Normal file
39
main/boards/kevin-box-1/config.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#ifndef _BOARD_CONFIG_H_
|
||||||
|
#define _BOARD_CONFIG_H_
|
||||||
|
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
|
||||||
|
#define AUDIO_INPUT_SAMPLE_RATE 24000
|
||||||
|
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
|
||||||
|
|
||||||
|
#define AUDIO_INPUT_REFERENCE true
|
||||||
|
|
||||||
|
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_42
|
||||||
|
#define AUDIO_I2S_GPIO_LRCK GPIO_NUM_47
|
||||||
|
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_48
|
||||||
|
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_45
|
||||||
|
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_21
|
||||||
|
|
||||||
|
#define AUDIO_CODEC_PA_PIN GPIO_NUM_17
|
||||||
|
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_39
|
||||||
|
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_38
|
||||||
|
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||||
|
#define AUDIO_CODEC_ES7210_ADDR ES7210_CODEC_DEFAULT_ADDR
|
||||||
|
|
||||||
|
#define BUILTIN_LED_GPIO GPIO_NUM_8
|
||||||
|
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||||
|
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_6
|
||||||
|
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_7
|
||||||
|
|
||||||
|
#define DISPLAY_SDA_PIN GPIO_NUM_4
|
||||||
|
#define DISPLAY_SCL_PIN GPIO_NUM_5
|
||||||
|
#define DISPLAY_WIDTH 128
|
||||||
|
#define DISPLAY_HEIGHT 64
|
||||||
|
#define DISPLAY_MIRROR_X false
|
||||||
|
#define DISPLAY_MIRROR_Y false
|
||||||
|
|
||||||
|
#define ML307_RX_PIN GPIO_NUM_20
|
||||||
|
#define ML307_TX_PIN GPIO_NUM_19
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _BOARD_CONFIG_H_
|
||||||
20
main/boards/lichuang-dev/LiChuangDevBoard.cc
Normal file
20
main/boards/lichuang-dev/LiChuangDevBoard.cc
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "WifiBoard.h"
|
||||||
|
#include "BoxAudioDevice.h"
|
||||||
|
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
#define TAG "LiChuangDevBoard"
|
||||||
|
|
||||||
|
class LiChuangDevBoard : public WifiBoard {
|
||||||
|
public:
|
||||||
|
virtual void Initialize() override {
|
||||||
|
ESP_LOGI(TAG, "Initializing LiChuangDevBoard");
|
||||||
|
WifiBoard::Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual AudioDevice* CreateAudioDevice() override {
|
||||||
|
return new BoxAudioDevice();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DECLARE_BOARD(LiChuangDevBoard);
|
||||||
37
main/boards/lichuang-dev/config.h
Normal file
37
main/boards/lichuang-dev/config.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef _BOARD_CONFIG_H_
|
||||||
|
#define _BOARD_CONFIG_H_
|
||||||
|
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
|
||||||
|
#define AUDIO_INPUT_SAMPLE_RATE 24000
|
||||||
|
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
|
||||||
|
|
||||||
|
#define AUDIO_INPUT_REFERENCE true
|
||||||
|
|
||||||
|
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_38
|
||||||
|
#define AUDIO_I2S_GPIO_LRCK GPIO_NUM_13
|
||||||
|
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_14
|
||||||
|
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_12
|
||||||
|
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_45
|
||||||
|
|
||||||
|
#define AUDIO_CODEC_USE_PCA9557
|
||||||
|
#define AUDIO_CODEC_PA_PIN GPIO_NUM_40
|
||||||
|
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_1
|
||||||
|
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_2
|
||||||
|
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||||
|
#define AUDIO_CODEC_ES7210_ADDR 0x82
|
||||||
|
|
||||||
|
#define BUILTIN_LED_GPIO GPIO_NUM_48
|
||||||
|
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||||
|
#define VOLUME_UP_BUTTON_GPIO GPIO_NUM_NC
|
||||||
|
#define VOLUME_DOWN_BUTTON_GPIO GPIO_NUM_NC
|
||||||
|
|
||||||
|
#define DISPLAY_SDA_PIN GPIO_NUM_NC
|
||||||
|
#define DISPLAY_SCL_PIN GPIO_NUM_NC
|
||||||
|
#define DISPLAY_WIDTH 128
|
||||||
|
#define DISPLAY_HEIGHT 64
|
||||||
|
#define DISPLAY_MIRROR_X false
|
||||||
|
#define DISPLAY_MIRROR_Y false
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _BOARD_CONFIG_H_
|
||||||
Loading…
Reference in New Issue
Block a user