commit
cabb29a1bb
@ -6,12 +6,9 @@ set(SOURCES "audio_codec.cc"
|
|||||||
"display/st7789_display.cc"
|
"display/st7789_display.cc"
|
||||||
"display/ssd1306_display.cc"
|
"display/ssd1306_display.cc"
|
||||||
"board.cc"
|
"board.cc"
|
||||||
"boards/wifi_board.cc"
|
|
||||||
"boards/ml307_board.cc"
|
|
||||||
"protocol.cc"
|
"protocol.cc"
|
||||||
"protocols/mqtt_protocol.cc"
|
"protocols/mqtt_protocol.cc"
|
||||||
"system_info.cc"
|
"system_info.cc"
|
||||||
"system_reset.cc"
|
|
||||||
"application.cc"
|
"application.cc"
|
||||||
"button.cc"
|
"button.cc"
|
||||||
"led.cc"
|
"led.cc"
|
||||||
@ -21,6 +18,11 @@ set(SOURCES "audio_codec.cc"
|
|||||||
)
|
)
|
||||||
set(INCLUDE_DIRS ".")
|
set(INCLUDE_DIRS ".")
|
||||||
|
|
||||||
|
# 添加板级公共文件
|
||||||
|
file(GLOB BOARD_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boards/common/*.cc)
|
||||||
|
list(APPEND SOURCES ${BOARD_COMMON_SOURCES})
|
||||||
|
list(APPEND INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/boards/common)
|
||||||
|
|
||||||
# 根据 BOARD_TYPE 配置添加对应的板级文件
|
# 根据 BOARD_TYPE 配置添加对应的板级文件
|
||||||
if(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI)
|
if(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI)
|
||||||
set(BOARD_TYPE "bread-compact-wifi")
|
set(BOARD_TYPE "bread-compact-wifi")
|
||||||
@ -28,8 +30,6 @@ elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_ML307)
|
|||||||
set(BOARD_TYPE "bread-compact-ml307")
|
set(BOARD_TYPE "bread-compact-ml307")
|
||||||
elseif(CONFIG_BOARD_TYPE_ESP_BOX_3)
|
elseif(CONFIG_BOARD_TYPE_ESP_BOX_3)
|
||||||
set(BOARD_TYPE "esp-box-3")
|
set(BOARD_TYPE "esp-box-3")
|
||||||
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_0)
|
|
||||||
set(BOARD_TYPE "kevin-box-0")
|
|
||||||
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_1)
|
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_1)
|
||||||
set(BOARD_TYPE "kevin-box-1")
|
set(BOARD_TYPE "kevin-box-1")
|
||||||
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_2)
|
elseif(CONFIG_BOARD_TYPE_KEVIN_BOX_2)
|
||||||
|
|||||||
@ -29,8 +29,6 @@ choice BOARD_TYPE
|
|||||||
bool "面包板新版接线(ML307 AT)"
|
bool "面包板新版接线(ML307 AT)"
|
||||||
config BOARD_TYPE_ESP_BOX_3
|
config BOARD_TYPE_ESP_BOX_3
|
||||||
bool "ESP BOX 3"
|
bool "ESP BOX 3"
|
||||||
config BOARD_TYPE_KEVIN_BOX_0
|
|
||||||
bool "Kevin Box 0"
|
|
||||||
config BOARD_TYPE_KEVIN_BOX_1
|
config BOARD_TYPE_KEVIN_BOX_1
|
||||||
bool "Kevin Box 1"
|
bool "Kevin Box 1"
|
||||||
config BOARD_TYPE_KEVIN_BOX_2
|
config BOARD_TYPE_KEVIN_BOX_2
|
||||||
|
|||||||
@ -76,7 +76,7 @@ void Application::CheckNewVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Application::Alert(const std::string&& title, const std::string&& message) {
|
void Application::Alert(const std::string&& title, const std::string&& message) {
|
||||||
ESP_LOGE(TAG, "Alert: %s, %s", title.c_str(), message.c_str());
|
ESP_LOGW(TAG, "Alert: %s, %s", title.c_str(), message.c_str());
|
||||||
auto display = Board::GetInstance().GetDisplay();
|
auto display = Board::GetInstance().GetDisplay();
|
||||||
display->ShowNotification(std::string(title + "\n" + message));
|
display->ShowNotification(std::string(title + "\n" + message));
|
||||||
|
|
||||||
@ -373,7 +373,6 @@ void Application::SetChatState(ChatState state) {
|
|||||||
"listening",
|
"listening",
|
||||||
"speaking",
|
"speaking",
|
||||||
"wake_word_detected",
|
"wake_word_detected",
|
||||||
"testing",
|
|
||||||
"upgrading",
|
"upgrading",
|
||||||
"invalid_state"
|
"invalid_state"
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "boards/ml307_board.h"
|
#include "ml307_board.h"
|
||||||
#include "audio_codecs/no_audio_codec.h"
|
#include "audio_codecs/no_audio_codec.h"
|
||||||
#include "display/ssd1306_display.h"
|
#include "display/ssd1306_display.h"
|
||||||
#include "system_reset.h"
|
#include "system_reset.h"
|
||||||
@ -18,6 +18,7 @@ private:
|
|||||||
Button boot_button_;
|
Button boot_button_;
|
||||||
Button volume_up_button_;
|
Button volume_up_button_;
|
||||||
Button volume_down_button_;
|
Button volume_down_button_;
|
||||||
|
SystemReset system_reset_;
|
||||||
|
|
||||||
void InitializeDisplayI2c() {
|
void InitializeDisplayI2c() {
|
||||||
i2c_master_bus_config_t bus_config = {
|
i2c_master_bus_config_t bus_config = {
|
||||||
@ -77,13 +78,14 @@ public:
|
|||||||
CompactMl307Board() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
|
CompactMl307Board() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
|
||||||
boot_button_(BOOT_BUTTON_GPIO),
|
boot_button_(BOOT_BUTTON_GPIO),
|
||||||
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
||||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO),
|
||||||
|
system_reset_(RESET_NVS_BUTTON_GPIO, RESET_FACTORY_BUTTON_GPIO) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Initialize() override {
|
virtual void Initialize() override {
|
||||||
ESP_LOGI(TAG, "Initializing CompactMl307Board");
|
ESP_LOGI(TAG, "Initializing CompactMl307Board");
|
||||||
// Check if the reset button is pressed
|
// Check if the reset button is pressed
|
||||||
SystemReset::GetInstance().CheckButtons();
|
system_reset_.CheckButtons();
|
||||||
|
|
||||||
InitializeDisplayI2c();
|
InitializeDisplayI2c();
|
||||||
InitializeButtons();
|
InitializeButtons();
|
||||||
|
|||||||
@ -31,6 +31,8 @@
|
|||||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||||
#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 RESET_NVS_BUTTON_GPIO GPIO_NUM_1
|
||||||
|
#define RESET_FACTORY_BUTTON_GPIO GPIO_NUM_2
|
||||||
|
|
||||||
#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
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "boards/wifi_board.h"
|
#include "wifi_board.h"
|
||||||
#include "audio_codecs/no_audio_codec.h"
|
#include "audio_codecs/no_audio_codec.h"
|
||||||
#include "display/ssd1306_display.h"
|
#include "display/ssd1306_display.h"
|
||||||
#include "system_reset.h"
|
#include "system_reset.h"
|
||||||
@ -18,6 +18,7 @@ private:
|
|||||||
Button boot_button_;
|
Button boot_button_;
|
||||||
Button volume_up_button_;
|
Button volume_up_button_;
|
||||||
Button volume_down_button_;
|
Button volume_down_button_;
|
||||||
|
SystemReset system_reset_;
|
||||||
|
|
||||||
void InitializeDisplayI2c() {
|
void InitializeDisplayI2c() {
|
||||||
i2c_master_bus_config_t bus_config = {
|
i2c_master_bus_config_t bus_config = {
|
||||||
@ -77,13 +78,14 @@ public:
|
|||||||
CompactWifiBoard() :
|
CompactWifiBoard() :
|
||||||
boot_button_(BOOT_BUTTON_GPIO),
|
boot_button_(BOOT_BUTTON_GPIO),
|
||||||
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
||||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO),
|
||||||
|
system_reset_(RESET_NVS_BUTTON_GPIO, RESET_FACTORY_BUTTON_GPIO) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Initialize() override {
|
virtual void Initialize() override {
|
||||||
ESP_LOGI(TAG, "Initializing CompactWifiBoard");
|
ESP_LOGI(TAG, "Initializing CompactWifiBoard");
|
||||||
// Check if the reset button is pressed
|
// Check if the reset button is pressed
|
||||||
SystemReset::GetInstance().CheckButtons();
|
system_reset_.CheckButtons();
|
||||||
|
|
||||||
InitializeDisplayI2c();
|
InitializeDisplayI2c();
|
||||||
InitializeButtons();
|
InitializeButtons();
|
||||||
|
|||||||
@ -32,6 +32,8 @@
|
|||||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||||
#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 RESET_NVS_BUTTON_GPIO GPIO_NUM_1
|
||||||
|
#define RESET_FACTORY_BUTTON_GPIO GPIO_NUM_2
|
||||||
|
|
||||||
#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
|
||||||
|
|||||||
31
main/boards/common/i2c_device.cc
Normal file
31
main/boards/common/i2c_device.cc
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "i2c_device.h"
|
||||||
|
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
#define TAG "I2cDevice"
|
||||||
|
|
||||||
|
|
||||||
|
I2cDevice::I2cDevice(i2c_master_bus_handle_t i2c_bus, uint8_t addr) {
|
||||||
|
i2c_device_config_t i2c_device_cfg = {
|
||||||
|
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||||
|
.device_address = addr,
|
||||||
|
.scl_speed_hz = 100000,
|
||||||
|
.scl_wait_us = 0,
|
||||||
|
.flags = {
|
||||||
|
.disable_ack_check = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus, &i2c_device_cfg, &i2c_device_));
|
||||||
|
assert(i2c_device_ != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void I2cDevice::WriteReg(uint8_t reg, uint8_t value) {
|
||||||
|
uint8_t buffer[2] = {reg, value};
|
||||||
|
ESP_ERROR_CHECK(i2c_master_transmit(i2c_device_, buffer, 2, 100));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t I2cDevice::ReadReg(uint8_t reg) {
|
||||||
|
uint8_t buffer[1];
|
||||||
|
ESP_ERROR_CHECK(i2c_master_transmit_receive(i2c_device_, ®, 1, buffer, 1, 100));
|
||||||
|
return buffer[0];
|
||||||
|
}
|
||||||
17
main/boards/common/i2c_device.h
Normal file
17
main/boards/common/i2c_device.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef I2C_DEVICE_H
|
||||||
|
#define I2C_DEVICE_H
|
||||||
|
|
||||||
|
#include <driver/i2c_master.h>
|
||||||
|
|
||||||
|
class I2cDevice {
|
||||||
|
public:
|
||||||
|
I2cDevice(i2c_master_bus_handle_t i2c_bus, uint8_t addr);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
i2c_master_dev_handle_t i2c_device_;
|
||||||
|
|
||||||
|
void WriteReg(uint8_t reg, uint8_t value);
|
||||||
|
uint8_t ReadReg(uint8_t reg);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // I2C_DEVICE_H
|
||||||
@ -11,12 +11,12 @@
|
|||||||
#define TAG "SystemReset"
|
#define TAG "SystemReset"
|
||||||
|
|
||||||
|
|
||||||
SystemReset::SystemReset() {
|
SystemReset::SystemReset(gpio_num_t reset_nvs_pin, gpio_num_t reset_factory_pin) : reset_nvs_pin_(reset_nvs_pin), reset_factory_pin_(reset_factory_pin) {
|
||||||
// Configure GPIO1, GPIO2 as INPUT, reset NVS flash if the button is pressed
|
// Configure GPIO1, GPIO2 as INPUT, reset NVS flash if the button is pressed
|
||||||
gpio_config_t io_conf;
|
gpio_config_t io_conf;
|
||||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||||
io_conf.mode = GPIO_MODE_INPUT;
|
io_conf.mode = GPIO_MODE_INPUT;
|
||||||
io_conf.pin_bit_mask = (1ULL << GPIO_NUM_1) | (1ULL << GPIO_NUM_2);
|
io_conf.pin_bit_mask = (1ULL << reset_nvs_pin_) | (1ULL << reset_factory_pin_);
|
||||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||||
gpio_config(&io_conf);
|
gpio_config(&io_conf);
|
||||||
@ -24,13 +24,13 @@ SystemReset::SystemReset() {
|
|||||||
|
|
||||||
|
|
||||||
void SystemReset::CheckButtons() {
|
void SystemReset::CheckButtons() {
|
||||||
if (gpio_get_level(GPIO_NUM_2) == 0) {
|
if (gpio_get_level(reset_factory_pin_) == 0) {
|
||||||
ESP_LOGI(TAG, "Button is pressed, reset to factory");
|
ESP_LOGI(TAG, "Button is pressed, reset to factory");
|
||||||
ResetNvsFlash();
|
ResetNvsFlash();
|
||||||
ResetToFactory();
|
ResetToFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_get_level(GPIO_NUM_1) == 0) {
|
if (gpio_get_level(reset_nvs_pin_) == 0) {
|
||||||
ESP_LOGI(TAG, "Button is pressed, reset NVS flash");
|
ESP_LOGI(TAG, "Button is pressed, reset NVS flash");
|
||||||
ResetNvsFlash();
|
ResetNvsFlash();
|
||||||
}
|
}
|
||||||
21
main/boards/common/system_reset.h
Normal file
21
main/boards/common/system_reset.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef _SYSTEM_RESET_H
|
||||||
|
#define _SYSTEM_RESET_H
|
||||||
|
|
||||||
|
#include <driver/gpio.h>
|
||||||
|
|
||||||
|
class SystemReset {
|
||||||
|
public:
|
||||||
|
SystemReset(gpio_num_t reset_nvs_pin, gpio_num_t reset_factory_pin); // 构造函数私有化
|
||||||
|
void CheckButtons();
|
||||||
|
|
||||||
|
private:
|
||||||
|
gpio_num_t reset_nvs_pin_;
|
||||||
|
gpio_num_t reset_factory_pin_;
|
||||||
|
|
||||||
|
void ResetNvsFlash();
|
||||||
|
void ResetToFactory();
|
||||||
|
void RestartInSeconds(int seconds);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#include "boards/wifi_board.h"
|
#include "wifi_board.h"
|
||||||
#include "audio_codecs/box_audio_codec.h"
|
#include "audio_codecs/box_audio_codec.h"
|
||||||
#include "display/no_display.h"
|
#include "display/no_display.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
#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_0
|
|
||||||
#define AUDIO_I2S_GPIO_WS 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_40
|
|
||||||
#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 true
|
|
||||||
#define DISPLAY_MIRROR_Y true
|
|
||||||
|
|
||||||
#define ML307_RX_PIN GPIO_NUM_17
|
|
||||||
#define ML307_TX_PIN GPIO_NUM_16
|
|
||||||
|
|
||||||
|
|
||||||
#endif // _BOARD_CONFIG_H_
|
|
||||||
@ -1,156 +0,0 @@
|
|||||||
#include "boards/ml307_board.h"
|
|
||||||
#include "audio_codecs/box_audio_codec.h"
|
|
||||||
#include "display/ssd1306_display.h"
|
|
||||||
#include "application.h"
|
|
||||||
#include "button.h"
|
|
||||||
#include "led.h"
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <esp_log.h>
|
|
||||||
#include <esp_spiffs.h>
|
|
||||||
#include <driver/gpio.h>
|
|
||||||
#include <driver/i2c_master.h>
|
|
||||||
|
|
||||||
static const char *TAG = "KevinBoxBoard";
|
|
||||||
|
|
||||||
class KevinBoxBoard : public Ml307Board {
|
|
||||||
private:
|
|
||||||
i2c_master_bus_handle_t display_i2c_bus_;
|
|
||||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
|
||||||
Button boot_button_;
|
|
||||||
Button volume_up_button_;
|
|
||||||
Button volume_down_button_;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeDisplayI2c() {
|
|
||||||
i2c_master_bus_config_t bus_config = {
|
|
||||||
.i2c_port = I2C_NUM_0,
|
|
||||||
.sda_io_num = DISPLAY_SDA_PIN,
|
|
||||||
.scl_io_num = DISPLAY_SCL_PIN,
|
|
||||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
|
||||||
.glitch_ignore_cnt = 7,
|
|
||||||
.intr_priority = 0,
|
|
||||||
.trans_queue_depth = 0,
|
|
||||||
.flags = {
|
|
||||||
.enable_internal_pullup = 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &display_i2c_bus_));
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeCodecI2c() {
|
|
||||||
// Initialize I2C peripheral
|
|
||||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
|
||||||
.i2c_port = I2C_NUM_1,
|
|
||||||
.sda_io_num = AUDIO_CODEC_I2C_SDA_PIN,
|
|
||||||
.scl_io_num = AUDIO_CODEC_I2C_SCL_PIN,
|
|
||||||
.clk_source = I2C_CLK_SRC_DEFAULT,
|
|
||||||
.glitch_ignore_cnt = 7,
|
|
||||||
.intr_priority = 0,
|
|
||||||
.trans_queue_depth = 0,
|
|
||||||
.flags = {
|
|
||||||
.enable_internal_pullup = 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &codec_i2c_bus_));
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeButtons() {
|
|
||||||
boot_button_.OnClick([this]() {
|
|
||||||
Application::GetInstance().ToggleChatState();
|
|
||||||
});
|
|
||||||
|
|
||||||
volume_up_button_.OnClick([this]() {
|
|
||||||
auto codec = GetAudioCodec();
|
|
||||||
auto volume = codec->output_volume() + 10;
|
|
||||||
if (volume > 100) {
|
|
||||||
volume = 100;
|
|
||||||
}
|
|
||||||
codec->SetOutputVolume(volume);
|
|
||||||
GetDisplay()->ShowNotification("Volume\n" + std::to_string(volume));
|
|
||||||
});
|
|
||||||
|
|
||||||
volume_up_button_.OnLongPress([this]() {
|
|
||||||
auto codec = GetAudioCodec();
|
|
||||||
codec->SetOutputVolume(100);
|
|
||||||
GetDisplay()->ShowNotification("Volume\n100");
|
|
||||||
});
|
|
||||||
|
|
||||||
volume_down_button_.OnClick([this]() {
|
|
||||||
auto codec = GetAudioCodec();
|
|
||||||
auto volume = codec->output_volume() - 10;
|
|
||||||
if (volume < 0) {
|
|
||||||
volume = 0;
|
|
||||||
}
|
|
||||||
codec->SetOutputVolume(volume);
|
|
||||||
GetDisplay()->ShowNotification("Volume\n" + std::to_string(volume));
|
|
||||||
});
|
|
||||||
|
|
||||||
volume_down_button_.OnLongPress([this]() {
|
|
||||||
auto codec = GetAudioCodec();
|
|
||||||
codec->SetOutputVolume(0);
|
|
||||||
GetDisplay()->ShowNotification("Volume\n0");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
KevinBoxBoard() : Ml307Board(ML307_TX_PIN, ML307_RX_PIN, 4096),
|
|
||||||
boot_button_(BOOT_BUTTON_GPIO),
|
|
||||||
volume_up_button_(VOLUME_UP_BUTTON_GPIO),
|
|
||||||
volume_down_button_(VOLUME_DOWN_BUTTON_GPIO) {
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Initialize() override {
|
|
||||||
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
|
||||||
InitializeDisplayI2c();
|
|
||||||
InitializeCodecI2c();
|
|
||||||
MountStorage();
|
|
||||||
Enable4GModule();
|
|
||||||
|
|
||||||
InitializeButtons();
|
|
||||||
|
|
||||||
Ml307Board::Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Led* GetBuiltinLed() override {
|
|
||||||
static Led led(BUILTIN_LED_GPIO);
|
|
||||||
return &led;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual AudioCodec* GetAudioCodec() override {
|
|
||||||
static BoxAudioCodec audio_codec(codec_i2c_bus_, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
|
||||||
AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
|
|
||||||
AUDIO_CODEC_PA_PIN, AUDIO_CODEC_ES8311_ADDR, AUDIO_CODEC_ES7210_ADDR, AUDIO_INPUT_REFERENCE);
|
|
||||||
return &audio_codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Display* GetDisplay() override {
|
|
||||||
static Ssd1306Display display(display_i2c_bus_, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
|
||||||
return &display;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
DECLARE_BOARD(KevinBoxBoard);
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
#include "boards/ml307_board.h"
|
#include "ml307_board.h"
|
||||||
#include "audio_codecs/box_audio_codec.h"
|
#include "audio_codecs/box_audio_codec.h"
|
||||||
#include "display/ssd1306_display.h"
|
#include "display/ssd1306_display.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
|
|||||||
@ -4,17 +4,7 @@
|
|||||||
|
|
||||||
static const char *TAG = "AXP2101";
|
static const char *TAG = "AXP2101";
|
||||||
|
|
||||||
bool Axp2101::Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address) {
|
Axp2101::Axp2101(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
|
||||||
i2c_device_config_t axp2101_cfg = {
|
|
||||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
|
||||||
.device_address = (uint16_t)i2c_device_address,
|
|
||||||
.scl_speed_hz = 100000,
|
|
||||||
.scl_wait_us = 0,
|
|
||||||
.flags = {
|
|
||||||
.disable_ack_check = 0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus, &axp2101_cfg, &i2c_device_));
|
|
||||||
|
|
||||||
WriteReg(0x93, 0x1c); // 配置aldo2输出为3.3v
|
WriteReg(0x93, 0x1c); // 配置aldo2输出为3.3v
|
||||||
|
|
||||||
@ -46,20 +36,6 @@ bool Axp2101::Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address
|
|||||||
|
|
||||||
WriteReg(0x24, 0x01); // set Vsys for PWROFF threshold to 3.2V (default - 2.6V and kill battery)
|
WriteReg(0x24, 0x01); // set Vsys for PWROFF threshold to 3.2V (default - 2.6V and kill battery)
|
||||||
WriteReg(0x50, 0x14); // set TS pin to EXTERNAL input (not temperature)
|
WriteReg(0x50, 0x14); // set TS pin to EXTERNAL input (not temperature)
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Axp2101::WriteReg(uint8_t reg, uint8_t value) {
|
|
||||||
uint8_t buffer[2];
|
|
||||||
buffer[0] = reg;
|
|
||||||
buffer[1] = value;
|
|
||||||
ESP_ERROR_CHECK(i2c_master_transmit(i2c_device_, buffer, 2, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Axp2101::ReadReg(uint8_t reg) {
|
|
||||||
uint8_t buffer[1];
|
|
||||||
ESP_ERROR_CHECK(i2c_master_transmit_receive(i2c_device_, ®, 1, buffer, 1, 100));
|
|
||||||
return buffer[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Axp2101::IsCharging() {
|
bool Axp2101::IsCharging() {
|
||||||
|
|||||||
@ -1,22 +1,15 @@
|
|||||||
#ifndef __AXP2101_H__
|
#ifndef __AXP2101_H__
|
||||||
#define __AXP2101_H__
|
#define __AXP2101_H__
|
||||||
|
|
||||||
#include <driver/i2c_master.h>
|
#include "i2c_device.h"
|
||||||
|
|
||||||
class Axp2101 {
|
class Axp2101 : public I2cDevice {
|
||||||
public:
|
public:
|
||||||
Axp2101() = default;
|
Axp2101(i2c_master_bus_handle_t i2c_bus, uint8_t addr);
|
||||||
bool Initialize(i2c_master_bus_handle_t i2c_bus, int i2c_device_address);
|
|
||||||
bool IsCharging();
|
bool IsCharging();
|
||||||
bool IsChargingDone();
|
bool IsChargingDone();
|
||||||
int GetBatteryLevel();
|
int GetBatteryLevel();
|
||||||
void PowerOff();
|
void PowerOff();
|
||||||
|
|
||||||
private:
|
|
||||||
i2c_master_dev_handle_t i2c_device_ = nullptr;
|
|
||||||
|
|
||||||
void WriteReg(uint8_t reg, uint8_t value);
|
|
||||||
uint8_t ReadReg(uint8_t reg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#include "boards/ml307_board.h"
|
#include "ml307_board.h"
|
||||||
#include "audio_codecs/box_audio_codec.h"
|
#include "audio_codecs/box_audio_codec.h"
|
||||||
#include "display/ssd1306_display.h"
|
#include "display/ssd1306_display.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
@ -18,7 +18,7 @@ class KevinBoxBoard : public Ml307Board {
|
|||||||
private:
|
private:
|
||||||
i2c_master_bus_handle_t display_i2c_bus_;
|
i2c_master_bus_handle_t display_i2c_bus_;
|
||||||
i2c_master_bus_handle_t codec_i2c_bus_;
|
i2c_master_bus_handle_t codec_i2c_bus_;
|
||||||
Axp2101 axp2101_;
|
Axp2101* axp2101_ = nullptr;
|
||||||
Button boot_button_;
|
Button boot_button_;
|
||||||
Button volume_up_button_;
|
Button volume_up_button_;
|
||||||
Button volume_down_button_;
|
Button volume_down_button_;
|
||||||
@ -130,7 +130,7 @@ public:
|
|||||||
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
ESP_LOGI(TAG, "Initializing KevinBoxBoard");
|
||||||
InitializeDisplayI2c();
|
InitializeDisplayI2c();
|
||||||
InitializeCodecI2c();
|
InitializeCodecI2c();
|
||||||
axp2101_.Initialize(codec_i2c_bus_, AXP2101_I2C_ADDR);
|
axp2101_ = new Axp2101(codec_i2c_bus_, AXP2101_I2C_ADDR);
|
||||||
|
|
||||||
MountStorage();
|
MountStorage();
|
||||||
Enable4GModule();
|
Enable4GModule();
|
||||||
@ -158,8 +158,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual bool GetBatteryLevel(int &level, bool& charging) override {
|
virtual bool GetBatteryLevel(int &level, bool& charging) override {
|
||||||
level = axp2101_.GetBatteryLevel();
|
level = axp2101_->GetBatteryLevel();
|
||||||
charging = axp2101_.IsCharging();
|
charging = axp2101_->IsCharging();
|
||||||
ESP_LOGI(TAG, "Battery level: %d, Charging: %d", level, charging);
|
ESP_LOGI(TAG, "Battery level: %d, Charging: %d", level, charging);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,10 @@
|
|||||||
#define DISPLAY_HEIGHT 240
|
#define DISPLAY_HEIGHT 240
|
||||||
#define DISPLAY_MIRROR_X true
|
#define DISPLAY_MIRROR_X true
|
||||||
#define DISPLAY_MIRROR_Y false
|
#define DISPLAY_MIRROR_Y false
|
||||||
|
#define DISPLAY_SWAP_XY true
|
||||||
|
|
||||||
|
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_42
|
||||||
|
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT true
|
||||||
|
|
||||||
|
|
||||||
#endif // _BOARD_CONFIG_H_
|
#endif // _BOARD_CONFIG_H_
|
||||||
|
|||||||
@ -1,22 +1,42 @@
|
|||||||
#include "boards/wifi_board.h"
|
#include "wifi_board.h"
|
||||||
#include "audio_codecs/box_audio_codec.h"
|
#include "audio_codecs/box_audio_codec.h"
|
||||||
#include "display/st7789_display.h"
|
#include "display/st7789_display.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "i2c_device.h"
|
||||||
|
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
#include <esp_lcd_panel_vendor.h>
|
#include <esp_lcd_panel_vendor.h>
|
||||||
#include <driver/i2c_master.h>
|
#include <driver/i2c_master.h>
|
||||||
#include <driver/spi_common.h>
|
#include <driver/spi_common.h>
|
||||||
|
|
||||||
#define TAG "LichuangDevBoard"
|
#define TAG "LichuangDevBoard"
|
||||||
|
|
||||||
|
|
||||||
|
class Pca9557 : public I2cDevice {
|
||||||
|
public:
|
||||||
|
Pca9557(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
|
||||||
|
WriteReg(0x01, 0x03);
|
||||||
|
WriteReg(0x03, 0xf8);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetOutputState(uint8_t bit, uint8_t level) {
|
||||||
|
uint8_t data = ReadReg(0x01);
|
||||||
|
data = (data & ~(1 << bit)) | (level << bit);
|
||||||
|
WriteReg(0x01, data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class LichuangDevBoard : public WifiBoard {
|
class LichuangDevBoard : public WifiBoard {
|
||||||
private:
|
private:
|
||||||
i2c_master_bus_handle_t i2c_bus_;
|
i2c_master_bus_handle_t i2c_bus_;
|
||||||
i2c_master_dev_handle_t pca9557_handle_;
|
i2c_master_dev_handle_t pca9557_handle_;
|
||||||
Button boot_button_;
|
Button boot_button_;
|
||||||
|
St7789Display* display_;
|
||||||
|
Pca9557* pca9557_;
|
||||||
|
|
||||||
void InitializeI2c() {
|
void InitializeI2c() {
|
||||||
// Initialize I2C peripheral
|
// Initialize I2C peripheral
|
||||||
@ -33,39 +53,9 @@ private:
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
|
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
|
||||||
}
|
|
||||||
|
|
||||||
void Pca9557ReadRegister(uint8_t addr, uint8_t* data) {
|
// Initialize PCA9557
|
||||||
uint8_t tmp[1] = {addr};
|
pca9557_ = new Pca9557(i2c_bus_, 0x19);
|
||||||
ESP_ERROR_CHECK(i2c_master_transmit_receive(pca9557_handle_, tmp, 1, data, 1, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pca9557WriteRegister(uint8_t addr, uint8_t data) {
|
|
||||||
uint8_t tmp[2] = {addr, data};
|
|
||||||
ESP_ERROR_CHECK(i2c_master_transmit(pca9557_handle_, tmp, 2, 100));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Pca9557SetOutputState(uint8_t bit, uint8_t level) {
|
|
||||||
uint8_t data;
|
|
||||||
Pca9557ReadRegister(0x01, &data);
|
|
||||||
data = (data & ~(1 << bit)) | (level << bit);
|
|
||||||
Pca9557WriteRegister(0x01, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializePca9557() {
|
|
||||||
i2c_device_config_t pca9557_cfg = {
|
|
||||||
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
|
||||||
.device_address = 0x19,
|
|
||||||
.scl_speed_hz = 100000,
|
|
||||||
.scl_wait_us = 0,
|
|
||||||
.flags = {
|
|
||||||
.disable_ack_check = 0,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus_, &pca9557_cfg, &pca9557_handle_));
|
|
||||||
assert(pca9557_handle_ != NULL);
|
|
||||||
Pca9557WriteRegister(0x01, 0x03);
|
|
||||||
Pca9557WriteRegister(0x03, 0xf8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeSpi() {
|
void InitializeSpi() {
|
||||||
@ -85,38 +75,7 @@ private:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
void InitializeSt7789Display() {
|
||||||
LichuangDevBoard() : boot_button_(BOOT_BUTTON_GPIO) {
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void Initialize() override {
|
|
||||||
ESP_LOGI(TAG, "Initializing LichuangDevBoard");
|
|
||||||
InitializeI2c();
|
|
||||||
InitializePca9557();
|
|
||||||
InitializeSpi();
|
|
||||||
InitializeButtons();
|
|
||||||
WifiBoard::Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Led* GetBuiltinLed() override {
|
|
||||||
static Led led(GPIO_NUM_NC);
|
|
||||||
return &led;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual AudioCodec* GetAudioCodec() override {
|
|
||||||
static BoxAudioCodec* audio_codec = nullptr;
|
|
||||||
if (audio_codec == nullptr) {
|
|
||||||
audio_codec = new BoxAudioCodec(i2c_bus_, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
|
||||||
AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
|
|
||||||
GPIO_NUM_NC, AUDIO_CODEC_ES8311_ADDR, AUDIO_CODEC_ES7210_ADDR, AUDIO_INPUT_REFERENCE);
|
|
||||||
audio_codec->SetOutputVolume(AUDIO_DEFAULT_OUTPUT_VOLUME);
|
|
||||||
}
|
|
||||||
return audio_codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Display* GetDisplay() override {
|
|
||||||
static St7789Display* display = nullptr;
|
|
||||||
if (display == nullptr) {
|
|
||||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||||
esp_lcd_panel_handle_t panel = nullptr;
|
esp_lcd_panel_handle_t panel = nullptr;
|
||||||
// 液晶屏控制IO初始化
|
// 液晶屏控制IO初始化
|
||||||
@ -140,15 +99,47 @@ public:
|
|||||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
|
ESP_ERROR_CHECK(esp_lcd_new_panel_st7789(panel_io, &panel_config, &panel));
|
||||||
|
|
||||||
esp_lcd_panel_reset(panel);
|
esp_lcd_panel_reset(panel);
|
||||||
Pca9557SetOutputState(0, 0);
|
pca9557_->SetOutputState(0, 0);
|
||||||
|
|
||||||
esp_lcd_panel_init(panel);
|
esp_lcd_panel_init(panel);
|
||||||
esp_lcd_panel_invert_color(panel, true);
|
esp_lcd_panel_invert_color(panel, true);
|
||||||
esp_lcd_panel_swap_xy(panel, true);
|
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||||
display = new St7789Display(panel_io, panel, GPIO_NUM_42, DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
display_ = new St7789Display(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
|
||||||
|
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
|
||||||
}
|
}
|
||||||
return display;
|
|
||||||
|
public:
|
||||||
|
LichuangDevBoard() : boot_button_(BOOT_BUTTON_GPIO) {
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Initialize() override {
|
||||||
|
ESP_LOGI(TAG, "Initializing LichuangDevBoard");
|
||||||
|
InitializeI2c();
|
||||||
|
InitializeSpi();
|
||||||
|
InitializeSt7789Display();
|
||||||
|
InitializeButtons();
|
||||||
|
WifiBoard::Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Led* GetBuiltinLed() override {
|
||||||
|
static Led led(GPIO_NUM_NC);
|
||||||
|
return &led;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual AudioCodec* GetAudioCodec() override {
|
||||||
|
static BoxAudioCodec* audio_codec = nullptr;
|
||||||
|
if (audio_codec == nullptr) {
|
||||||
|
audio_codec = new BoxAudioCodec(i2c_bus_, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||||
|
AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
|
||||||
|
GPIO_NUM_NC, AUDIO_CODEC_ES8311_ADDR, AUDIO_CODEC_ES7210_ADDR, AUDIO_INPUT_REFERENCE);
|
||||||
|
audio_codec->SetOutputVolume(AUDIO_DEFAULT_OUTPUT_VOLUME);
|
||||||
|
}
|
||||||
|
return audio_codec;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual Display* GetDisplay() override {
|
||||||
|
return display_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -9,9 +9,11 @@
|
|||||||
#define TAG "St7789Display"
|
#define TAG "St7789Display"
|
||||||
#define LCD_LEDC_CH LEDC_CHANNEL_0
|
#define LCD_LEDC_CH LEDC_CHANNEL_0
|
||||||
|
|
||||||
St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, gpio_num_t backlight_pin,
|
St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||||
int width, int height, bool mirror_x, bool mirror_y)
|
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||||
: panel_io_(panel_io), panel_(panel), mirror_x_(mirror_x), mirror_y_(mirror_y) {
|
int width, int height, bool mirror_x, bool mirror_y, bool swap_xy)
|
||||||
|
: panel_io_(panel_io), panel_(panel), backlight_pin_(backlight_pin), backlight_output_invert_(backlight_output_invert),
|
||||||
|
mirror_x_(mirror_x), mirror_y_(mirror_y), swap_xy_(swap_xy) {
|
||||||
width_ = width;
|
width_ = width;
|
||||||
height_ = height;
|
height_ = height;
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ St7789Display::St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
|
|||||||
.vres = static_cast<uint32_t>(height_),
|
.vres = static_cast<uint32_t>(height_),
|
||||||
.monochrome = false,
|
.monochrome = false,
|
||||||
.rotation = {
|
.rotation = {
|
||||||
.swap_xy = true,
|
.swap_xy = swap_xy_,
|
||||||
.mirror_x = mirror_x_,
|
.mirror_x = mirror_x_,
|
||||||
.mirror_y = mirror_y_,
|
.mirror_y = mirror_y_,
|
||||||
},
|
},
|
||||||
@ -86,7 +88,7 @@ void St7789Display::InitializeBacklight(gpio_num_t backlight_pin) {
|
|||||||
.duty = 0,
|
.duty = 0,
|
||||||
.hpoint = 0,
|
.hpoint = 0,
|
||||||
.flags = {
|
.flags = {
|
||||||
.output_invert = true
|
.output_invert = backlight_output_invert_,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const ledc_timer_config_t backlight_timer = {
|
const ledc_timer_config_t backlight_timer = {
|
||||||
@ -103,6 +105,10 @@ void St7789Display::InitializeBacklight(gpio_num_t backlight_pin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void St7789Display::SetBacklight(uint8_t brightness) {
|
void St7789Display::SetBacklight(uint8_t brightness) {
|
||||||
|
if (backlight_pin_ == GPIO_NUM_NC) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (brightness > 100) {
|
if (brightness > 100) {
|
||||||
brightness = 100;
|
brightness = 100;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,11 @@ class St7789Display : public Display {
|
|||||||
private:
|
private:
|
||||||
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
esp_lcd_panel_io_handle_t panel_io_ = nullptr;
|
||||||
esp_lcd_panel_handle_t panel_ = nullptr;
|
esp_lcd_panel_handle_t panel_ = nullptr;
|
||||||
|
gpio_num_t backlight_pin_ = GPIO_NUM_NC;
|
||||||
|
bool backlight_output_invert_ = false;
|
||||||
bool mirror_x_ = false;
|
bool mirror_x_ = false;
|
||||||
bool mirror_y_ = false;
|
bool mirror_y_ = false;
|
||||||
|
bool swap_xy_ = false;
|
||||||
|
|
||||||
void InitializeBacklight(gpio_num_t backlight_pin);
|
void InitializeBacklight(gpio_num_t backlight_pin);
|
||||||
void SetBacklight(uint8_t brightness);
|
void SetBacklight(uint8_t brightness);
|
||||||
@ -21,8 +24,9 @@ private:
|
|||||||
virtual void Unlock() override;
|
virtual void Unlock() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel, gpio_num_t backlight_pin,
|
St7789Display(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handle_t panel,
|
||||||
int width, int height, bool mirror_x, bool mirror_y);
|
gpio_num_t backlight_pin, bool backlight_output_invert,
|
||||||
|
int width, int height, bool mirror_x, bool mirror_y, bool swap_xy);
|
||||||
~St7789Display();
|
~St7789Display();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
#ifndef _SYSTEM_RESET_H
|
|
||||||
#define _SYSTEM_RESET_H
|
|
||||||
|
|
||||||
class SystemReset {
|
|
||||||
public:
|
|
||||||
static SystemReset& GetInstance() {
|
|
||||||
static SystemReset instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckButtons();
|
|
||||||
|
|
||||||
private:
|
|
||||||
SystemReset(); // 构造函数私有化
|
|
||||||
SystemReset(const SystemReset&) = delete; // 禁用拷贝构造
|
|
||||||
SystemReset& operator=(const SystemReset&) = delete; // 禁用赋值操作
|
|
||||||
|
|
||||||
void ResetNvsFlash();
|
|
||||||
void ResetToFactory();
|
|
||||||
void RestartInSeconds(int seconds);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -24,10 +24,7 @@ WakeWordDetect::~WakeWordDetect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wake_word_encode_task_stack_ != nullptr) {
|
if (wake_word_encode_task_stack_ != nullptr) {
|
||||||
free(wake_word_encode_task_stack_);
|
heap_caps_free(wake_word_encode_task_stack_);
|
||||||
}
|
|
||||||
if (audio_detection_task_stack_ != nullptr) {
|
|
||||||
heap_caps_free(audio_detection_task_stack_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vEventGroupDelete(event_group_);
|
vEventGroupDelete(event_group_);
|
||||||
@ -80,13 +77,11 @@ void WakeWordDetect::Initialize(int channels, bool reference) {
|
|||||||
|
|
||||||
afe_detection_data_ = esp_afe_sr_v1.create_from_config(&afe_config);
|
afe_detection_data_ = esp_afe_sr_v1.create_from_config(&afe_config);
|
||||||
|
|
||||||
const size_t audio_detection_task_stack_size = 4096 * 2;
|
xTaskCreate([](void* arg) {
|
||||||
audio_detection_task_stack_ = (StackType_t*)heap_caps_malloc(audio_detection_task_stack_size, MALLOC_CAP_SPIRAM);
|
|
||||||
xTaskCreateStatic([](void* arg) {
|
|
||||||
auto this_ = (WakeWordDetect*)arg;
|
auto this_ = (WakeWordDetect*)arg;
|
||||||
this_->AudioDetectionTask();
|
this_->AudioDetectionTask();
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}, "audio_detection", audio_detection_task_stack_size, this, 1, audio_detection_task_stack_, &audio_detection_task_buffer_);
|
}, "audio_detection", 4096 * 2, this, 1, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WakeWordDetect::OnWakeWordDetected(std::function<void()> callback) {
|
void WakeWordDetect::OnWakeWordDetected(std::function<void()> callback) {
|
||||||
@ -173,7 +168,7 @@ void WakeWordDetect::EncodeWakeWordData() {
|
|||||||
xEventGroupClearBits(event_group_, WAKE_WORD_ENCODED_EVENT);
|
xEventGroupClearBits(event_group_, WAKE_WORD_ENCODED_EVENT);
|
||||||
wake_word_opus_.clear();
|
wake_word_opus_.clear();
|
||||||
if (wake_word_encode_task_stack_ == nullptr) {
|
if (wake_word_encode_task_stack_ == nullptr) {
|
||||||
wake_word_encode_task_stack_ = (StackType_t*)malloc(4096 * 8);
|
wake_word_encode_task_stack_ = (StackType_t*)heap_caps_malloc(4096 * 8, MALLOC_CAP_SPIRAM);
|
||||||
}
|
}
|
||||||
wake_word_encode_task_ = xTaskCreateStatic([](void* arg) {
|
wake_word_encode_task_ = xTaskCreateStatic([](void* arg) {
|
||||||
auto this_ = (WakeWordDetect*)arg;
|
auto this_ = (WakeWordDetect*)arg;
|
||||||
|
|||||||
@ -42,10 +42,6 @@ private:
|
|||||||
int channels_;
|
int channels_;
|
||||||
bool reference_;
|
bool reference_;
|
||||||
|
|
||||||
TaskHandle_t audio_detection_task_ = nullptr;
|
|
||||||
StaticTask_t audio_detection_task_buffer_;
|
|
||||||
StackType_t* audio_detection_task_stack_ = nullptr;
|
|
||||||
|
|
||||||
TaskHandle_t wake_word_encode_task_ = nullptr;
|
TaskHandle_t wake_word_encode_task_ = nullptr;
|
||||||
StaticTask_t wake_word_encode_task_buffer_;
|
StaticTask_t wake_word_encode_task_buffer_;
|
||||||
StackType_t* wake_word_encode_task_stack_ = nullptr;
|
StackType_t* wake_word_encode_task_stack_ = nullptr;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user