forked from xiaozhi/xiaozhi-esp32
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc5d724506 | ||
|
|
bba26ef69c | ||
|
|
7fcd40dbe7 | ||
|
|
48a1c5da29 |
@@ -4,7 +4,7 @@
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(PROJECT_VER "1.8.9")
|
||||
set(PROJECT_VER "1.8.6")
|
||||
|
||||
# Add this line to disable the specific warning
|
||||
add_compile_options(-Wno-missing-field-initializers)
|
||||
|
||||
@@ -130,7 +130,7 @@
|
||||
|
||||
## 大模型配置
|
||||
|
||||
如果你已经拥有一个小智 AI 聊天机器人设备,并且已接入官方服务器,可以登录 [xiaozhi.me](https://xiaozhi.me) 控制台进行配置。
|
||||
如果你已经拥有一个的小智 AI 聊天机器人设备,并且已接入官方服务器,可以登录 [xiaozhi.me](https://xiaozhi.me) 控制台进行配置。
|
||||
|
||||
👉 [后台操作视频教程(旧版界面)](https://www.bilibili.com/video/BV1jUCUY2EKM/)
|
||||
|
||||
|
||||
@@ -192,8 +192,6 @@ elseif(CONFIG_BOARD_TYPE_ESP32_CGC_144)
|
||||
set(BOARD_TYPE "esp32-cgc-144")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP_S3_LCD_EV_Board)
|
||||
set(BOARD_TYPE "esp-s3-lcd-ev-board")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP_S3_LCD_EV_Board_2)
|
||||
set(BOARD_TYPE "esp-s3-lcd-ev-board-2")
|
||||
elseif(CONFIG_BOARD_TYPE_ZHENGCHEN_1_54TFT_WIFI)
|
||||
set(BOARD_TYPE "zhengchen-1.54tft-wifi")
|
||||
elseif(CONFIG_BOARD_TYPE_MINSI_K08_DUAL)
|
||||
@@ -210,7 +208,7 @@ elseif(CONFIG_BOARD_TYPE_ELECTRON_BOT)
|
||||
set(BOARD_TYPE "electron-bot")
|
||||
elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI_CAM)
|
||||
set(BOARD_TYPE "bread-compact-wifi-s3cam")
|
||||
elseif(CONFIG_BOARD_TYPE_JIUCHUAN)
|
||||
elseif(CONFIG_BOARD_TYPE_JIUCHUAN )
|
||||
set(BOARD_TYPE "jiuchuan-s3")
|
||||
elseif(CONFIG_BOARD_TYPE_LABPLUS_MPYTHON_V3)
|
||||
set(BOARD_TYPE "labplus-mpython-v3")
|
||||
|
||||
@@ -303,9 +303,6 @@ choice BOARD_TYPE
|
||||
config BOARD_TYPE_ESP_S3_LCD_EV_Board
|
||||
bool "乐鑫ESP S3 LCD EV Board开发板"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
config BOARD_TYPE_ESP_S3_LCD_EV_Board_2
|
||||
bool "乐鑫ESP S3 LCD EV Board 2开发板"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
config BOARD_TYPE_ZHENGCHEN_1_54TFT_WIFI
|
||||
bool "征辰科技1.54(WIFI)"
|
||||
depends on IDF_TARGET_ESP32S3
|
||||
@@ -490,7 +487,7 @@ config USE_AUDIO_PROCESSOR
|
||||
config USE_DEVICE_AEC
|
||||
bool "Enable Device-Side AEC"
|
||||
default n
|
||||
depends on USE_AUDIO_PROCESSOR && (BOARD_TYPE_ESP_BOX_3 || BOARD_TYPE_ESP_BOX || BOARD_TYPE_ESP_BOX_LITE || BOARD_TYPE_LICHUANG_DEV || BOARD_TYPE_ESP32S3_KORVO2_V3 || BOARD_TYPE_ESP32S3_Touch_AMOLED_1_75 || BOARD_TYPE_ESP32S3_Touch_AMOLED_2_06 || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_4B || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_XC || BOARD_TYPE_ESP_S3_LCD_EV_Board_2)
|
||||
depends on USE_AUDIO_PROCESSOR && (BOARD_TYPE_ESP_BOX_3 || BOARD_TYPE_ESP_BOX || BOARD_TYPE_ESP_BOX_LITE || BOARD_TYPE_LICHUANG_DEV || BOARD_TYPE_ESP32S3_KORVO2_V3 || BOARD_TYPE_ESP32S3_Touch_AMOLED_1_75 || BOARD_TYPE_ESP32S3_Touch_AMOLED_2_06 || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_4B || BOARD_TYPE_ESP32P4_WIFI6_Touch_LCD_XC)
|
||||
help
|
||||
因为性能不够,不建议和微信聊天界面风格同时开启
|
||||
|
||||
|
||||
@@ -540,12 +540,6 @@ void AudioService::SetCallbacks(AudioServiceCallbacks& callbacks) {
|
||||
}
|
||||
|
||||
void AudioService::PlaySound(const std::string_view& ogg) {
|
||||
if (!codec_->output_enabled()) {
|
||||
esp_timer_stop(audio_power_timer_);
|
||||
esp_timer_start_periodic(audio_power_timer_, AUDIO_POWER_CHECK_INTERVAL_MS * 1000);
|
||||
codec_->EnableOutput(true);
|
||||
}
|
||||
|
||||
const uint8_t* buf = reinterpret_cast<const uint8_t*>(ogg.data());
|
||||
size_t size = ogg.size();
|
||||
size_t offset = 0;
|
||||
|
||||
@@ -64,7 +64,7 @@ BoxAudioCodec::BoxAudioCodec(void* i2c_master_handle, int input_sample_rate, int
|
||||
|
||||
es7210_codec_cfg_t es7210_cfg = {};
|
||||
es7210_cfg.ctrl_if = in_ctrl_if_;
|
||||
es7210_cfg.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3 | ES7210_SEL_MIC4;
|
||||
es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3 | ES7120_SEL_MIC4;
|
||||
in_codec_if_ = es7210_codec_new(&es7210_cfg);
|
||||
assert(in_codec_if_ != NULL);
|
||||
|
||||
@@ -184,7 +184,6 @@ void BoxAudioCodec::SetOutputVolume(int volume) {
|
||||
}
|
||||
|
||||
void BoxAudioCodec::EnableInput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == input_enabled_) {
|
||||
return;
|
||||
}
|
||||
@@ -208,7 +207,6 @@ void BoxAudioCodec::EnableInput(bool enable) {
|
||||
}
|
||||
|
||||
void BoxAudioCodec::EnableOutput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == output_enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#include <esp_codec_dev.h>
|
||||
#include <esp_codec_dev_defaults.h>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
class BoxAudioCodec : public AudioCodec {
|
||||
private:
|
||||
@@ -19,7 +17,6 @@ private:
|
||||
|
||||
esp_codec_dev_handle_t output_dev_ = nullptr;
|
||||
esp_codec_dev_handle_t input_dev_ = nullptr;
|
||||
std::mutex data_if_mutex_;
|
||||
|
||||
void CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din);
|
||||
|
||||
|
||||
@@ -155,7 +155,6 @@ void Es8311AudioCodec::SetOutputVolume(int volume) {
|
||||
}
|
||||
|
||||
void Es8311AudioCodec::EnableInput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == input_enabled_) {
|
||||
return;
|
||||
}
|
||||
@@ -164,7 +163,6 @@ void Es8311AudioCodec::EnableInput(bool enable) {
|
||||
}
|
||||
|
||||
void Es8311AudioCodec::EnableOutput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == output_enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_codec_dev.h>
|
||||
#include <esp_codec_dev_defaults.h>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
class Es8311AudioCodec : public AudioCodec {
|
||||
private:
|
||||
@@ -20,7 +18,6 @@ private:
|
||||
esp_codec_dev_handle_t dev_ = nullptr;
|
||||
gpio_num_t pa_pin_ = GPIO_NUM_NC;
|
||||
bool pa_inverted_ = false;
|
||||
std::mutex data_if_mutex_;
|
||||
|
||||
void CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din);
|
||||
void UpdateDeviceState();
|
||||
|
||||
@@ -133,7 +133,6 @@ void Es8374AudioCodec::SetOutputVolume(int volume) {
|
||||
}
|
||||
|
||||
void Es8374AudioCodec::EnableInput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == input_enabled_) {
|
||||
return;
|
||||
}
|
||||
@@ -154,7 +153,6 @@ void Es8374AudioCodec::EnableInput(bool enable) {
|
||||
}
|
||||
|
||||
void Es8374AudioCodec::EnableOutput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == output_enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_codec_dev.h>
|
||||
#include <esp_codec_dev_defaults.h>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
class Es8374AudioCodec : public AudioCodec {
|
||||
private:
|
||||
@@ -20,7 +18,6 @@ private:
|
||||
esp_codec_dev_handle_t output_dev_ = nullptr;
|
||||
esp_codec_dev_handle_t input_dev_ = nullptr;
|
||||
gpio_num_t pa_pin_ = GPIO_NUM_NC;
|
||||
std::mutex data_if_mutex_;
|
||||
|
||||
void CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din);
|
||||
|
||||
|
||||
@@ -137,7 +137,6 @@ void Es8388AudioCodec::SetOutputVolume(int volume) {
|
||||
}
|
||||
|
||||
void Es8388AudioCodec::EnableInput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == input_enabled_) {
|
||||
return;
|
||||
}
|
||||
@@ -158,7 +157,6 @@ void Es8388AudioCodec::EnableInput(bool enable) {
|
||||
}
|
||||
|
||||
void Es8388AudioCodec::EnableOutput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == output_enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include <driver/i2c_master.h>
|
||||
#include <esp_codec_dev.h>
|
||||
#include <esp_codec_dev_defaults.h>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
class Es8388AudioCodec : public AudioCodec {
|
||||
private:
|
||||
@@ -19,7 +17,6 @@ private:
|
||||
esp_codec_dev_handle_t output_dev_ = nullptr;
|
||||
esp_codec_dev_handle_t input_dev_ = nullptr;
|
||||
gpio_num_t pa_pin_ = GPIO_NUM_NC;
|
||||
std::mutex data_if_mutex_;
|
||||
|
||||
void CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din);
|
||||
|
||||
|
||||
@@ -140,7 +140,6 @@ void Es8389AudioCodec::SetOutputVolume(int volume) {
|
||||
}
|
||||
|
||||
void Es8389AudioCodec::EnableInput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == input_enabled_) {
|
||||
return;
|
||||
}
|
||||
@@ -161,7 +160,6 @@ void Es8389AudioCodec::EnableInput(bool enable) {
|
||||
}
|
||||
|
||||
void Es8389AudioCodec::EnableOutput(bool enable) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
if (enable == output_enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_codec_dev.h>
|
||||
#include <esp_codec_dev_defaults.h>
|
||||
#include <mutex>
|
||||
|
||||
class Es8389AudioCodec : public AudioCodec {
|
||||
private:
|
||||
@@ -19,7 +18,6 @@ private:
|
||||
esp_codec_dev_handle_t output_dev_ = nullptr;
|
||||
esp_codec_dev_handle_t input_dev_ = nullptr;
|
||||
gpio_num_t pa_pin_ = GPIO_NUM_NC;
|
||||
std::mutex data_if_mutex_;
|
||||
|
||||
void CreateDuplexChannels(gpio_num_t mclk, gpio_num_t bclk, gpio_num_t ws, gpio_num_t dout, gpio_num_t din);
|
||||
|
||||
|
||||
@@ -279,7 +279,6 @@ NoAudioCodecSimplexPdm::NoAudioCodecSimplexPdm(int input_sample_rate, int output
|
||||
}
|
||||
|
||||
int NoAudioCodec::Write(const int16_t* data, int samples) {
|
||||
std::lock_guard<std::mutex> lock(data_if_mutex_);
|
||||
std::vector<int32_t> buffer(samples);
|
||||
|
||||
// output_volume_: 0-100
|
||||
|
||||
@@ -5,12 +5,9 @@
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/i2s_pdm.h>
|
||||
#include <mutex>
|
||||
|
||||
class NoAudioCodec : public AudioCodec {
|
||||
protected:
|
||||
std::mutex data_if_mutex_;
|
||||
|
||||
private:
|
||||
virtual int Write(const int16_t* data, int samples) override;
|
||||
virtual int Read(int16_t* dest, int samples) override;
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ void NoAudioProcessor::Feed(std::vector<int16_t>&& data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.size() != frame_samples_) {
|
||||
ESP_LOGE(TAG, "Feed data size is not equal to frame size, feed size: %u, frame size: %u", data.size(), frame_samples_);
|
||||
return;
|
||||
}
|
||||
|
||||
if (codec_->input_channels() == 2) {
|
||||
// If input channels is 2, we need to fetch the left channel data
|
||||
auto mono_data = std::vector<int16_t>(data.size() / 2);
|
||||
|
||||
@@ -28,7 +28,7 @@ Esp32Camera::Esp32Camera(const camera_config_t& config) {
|
||||
memset(&preview_image_, 0, sizeof(preview_image_));
|
||||
preview_image_.header.magic = LV_IMAGE_HEADER_MAGIC;
|
||||
preview_image_.header.cf = LV_COLOR_FORMAT_RGB565;
|
||||
preview_image_.header.flags = 0;
|
||||
preview_image_.header.flags = LV_IMAGE_FLAGS_ALLOCATED | LV_IMAGE_FLAGS_MODIFIABLE;
|
||||
|
||||
switch (config.frame_size) {
|
||||
case FRAMESIZE_SVGA:
|
||||
|
||||
@@ -141,7 +141,7 @@ void ElectronEmojiDisplay::SetChatMessage(const char* role, const char* content)
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, content);
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置聊天消息 [%s]: %s", role, content);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ void ElectronEmojiDisplay::SetIcon(const char* icon) {
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, icon_message.c_str());
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置图标: %s", icon);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,8 @@ void AdcPdmAudioCodec::EnableInput(bool enable) {
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_codec_dev_open(input_dev_, &fs));
|
||||
} else {
|
||||
ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
|
||||
// ESP_ERROR_CHECK(esp_codec_dev_close(input_dev_));
|
||||
return;
|
||||
}
|
||||
AudioCodec::EnableInput(enable);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <esp_log.h>
|
||||
#include "mmap_generate_emoji.h"
|
||||
#include "emoji_display.h"
|
||||
#include "assets/lang_config.h"
|
||||
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
@@ -147,9 +146,9 @@ void EmojiWidget::SetEmotion(const char* emotion)
|
||||
void EmojiWidget::SetStatus(const char* status)
|
||||
{
|
||||
if (player_) {
|
||||
if (strcmp(status, Lang::Strings::LISTENING) == 0) {
|
||||
if (strcmp(status, "聆听中...") == 0) {
|
||||
player_->StartPlayer(MMAP_EMOJI_ASKING_AAF, true, 15);
|
||||
} else if (strcmp(status, Lang::Strings::STANDBY) == 0) {
|
||||
} else if (strcmp(status, "待命") == 0) {
|
||||
player_->StartPlayer(MMAP_EMOJI_WAKE_AAF, true, 15);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "servo_dog_ctrl.h"
|
||||
#include "led_strip.h"
|
||||
#include "driver/rmt_tx.h"
|
||||
#include "device_state_event.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
@@ -285,14 +284,13 @@ private:
|
||||
ESP_LOGI(TAG, "Create emoji widget, panel: %p, panel_io: %p", panel, panel_io);
|
||||
display_ = new anim::EmojiWidget(panel, panel_io);
|
||||
|
||||
#if CONFIG_ESP_CONSOLE_NONE
|
||||
servo_dog_ctrl_config_t config = {
|
||||
.fl_gpio_num = FL_GPIO_NUM,
|
||||
.fr_gpio_num = FR_GPIO_NUM,
|
||||
.bl_gpio_num = BL_GPIO_NUM,
|
||||
.br_gpio_num = BR_GPIO_NUM,
|
||||
};
|
||||
|
||||
#if CONFIG_ESP_CONSOLE_NONE
|
||||
servo_dog_ctrl_init(&config);
|
||||
#endif
|
||||
}
|
||||
@@ -380,7 +378,7 @@ private:
|
||||
int r = properties["r"].value<int>();
|
||||
int g = properties["g"].value<int>();
|
||||
int b = properties["b"].value<int>();
|
||||
|
||||
|
||||
led_on_ = true;
|
||||
SetLedColor(r, g, b);
|
||||
return true;
|
||||
@@ -397,11 +395,6 @@ public:
|
||||
InitializeSpi();
|
||||
InitializeLcdDisplay();
|
||||
InitializeTools();
|
||||
|
||||
DeviceStateEventManager::GetInstance().RegisterStateChangeCallback([this](DeviceState previous_state, DeviceState current_state) {
|
||||
ESP_LOGD(TAG, "Device state changed from %d to %d", previous_state, current_state);
|
||||
this->GetAudioCodec()->EnableOutput(current_state == kDeviceStateSpeaking);
|
||||
});
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
请确认自己的开发板硬件版本,如果硬件版本,在配置中进行ev_board type进行选择
|
||||
1.4与1.5只有io进行变更
|
||||
可以查看官方文档,确认具体细节https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32s3/esp32-s3-lcd-ev-board/user_guide.html
|
||||
具体调整为:
|
||||
I2C_SCL IO18 -> IO48
|
||||
I2C_SDA IO8 -> IO47
|
||||
LCD_DATA6 IO47 -> IO8
|
||||
LCD_DATA7 IO48 -> IO18
|
||||
|
||||
本版本只支持了800x480的屏幕
|
||||
@@ -1,42 +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_I2S_GPIO_MCLK GPIO_NUM_5
|
||||
#define AUDIO_I2S_GPIO_WS GPIO_NUM_7
|
||||
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_16
|
||||
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_15
|
||||
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_6
|
||||
|
||||
#define BSP_POWER_AMP_IO (IO_EXPANDER_PIN_NUM_0)
|
||||
#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC
|
||||
|
||||
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_47
|
||||
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_48
|
||||
|
||||
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
|
||||
#define AUDIO_CODEC_ES7210_ADDR 0x82
|
||||
|
||||
|
||||
#define BUILTIN_LED_GPIO GPIO_NUM_4
|
||||
#define BOOT_BUTTON_GPIO GPIO_NUM_0
|
||||
|
||||
#define DISPLAY_WIDTH 800
|
||||
#define DISPLAY_HEIGHT 480
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
|
||||
#define DISPLAY_BACKLIGHT_PIN GPIO_NUM_19
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"target": "esp32s3",
|
||||
"builds": [
|
||||
{
|
||||
"name": "esp-s3-lcd-ev-board-2",
|
||||
"sdkconfig_append": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
#include "wifi_board.h"
|
||||
#include "codecs/box_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "led/single_led.h"
|
||||
#include "pin_config.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <wifi_station.h>
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c_master.h>
|
||||
#include "esp_lcd_gc9503.h"
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lcd_panel_io_additions.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
#include <lvgl.h>
|
||||
#include <esp_lcd_touch_gt1151.h>
|
||||
#include <esp_io_expander_tca9554.h>
|
||||
|
||||
#define TAG "ESP_S3_LCD_EV_Board_2"
|
||||
|
||||
LV_FONT_DECLARE(font_puhui_30_4);
|
||||
LV_FONT_DECLARE(font_awesome_30_4);
|
||||
|
||||
class ESP_S3_LCD_EV_Board_2 : public WifiBoard {
|
||||
private:
|
||||
i2c_master_bus_handle_t i2c_bus_;
|
||||
Button boot_button_;
|
||||
LcdDisplay* display_;
|
||||
//add support ev board lcd
|
||||
esp_io_expander_handle_t expander = NULL;
|
||||
|
||||
void InitializeRGB_GC9503V_Display() {
|
||||
ESP_LOGI(TAG, "Init GC9503V");
|
||||
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
|
||||
// add support ev board lcd
|
||||
gpio_config_t io_conf = {
|
||||
.pin_bit_mask = BIT64(GC9503V_PIN_NUM_VSYNC),
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = GPIO_PULLUP_ENABLE,
|
||||
};
|
||||
|
||||
gpio_config(&io_conf);
|
||||
gpio_set_level(GC9503V_PIN_NUM_VSYNC, 1);
|
||||
|
||||
ESP_LOGI(TAG, "Install 3-wire SPI panel IO");
|
||||
spi_line_config_t line_config = {
|
||||
.cs_io_type = IO_TYPE_EXPANDER,
|
||||
.cs_expander_pin = GC9503V_LCD_IO_SPI_CS_1,
|
||||
.scl_io_type = IO_TYPE_EXPANDER,
|
||||
.scl_expander_pin = GC9503V_LCD_IO_SPI_SCL_1,
|
||||
.sda_io_type = IO_TYPE_EXPANDER,
|
||||
.sda_expander_pin = GC9503V_LCD_IO_SPI_SDO_1,
|
||||
.io_expander = expander,
|
||||
};
|
||||
|
||||
esp_lcd_panel_io_3wire_spi_config_t io_config = GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_config, 0);
|
||||
int espok = esp_lcd_new_panel_io_3wire_spi(&io_config, &panel_io);
|
||||
ESP_LOGI(TAG, "Install 3-wire SPI panel IO:%d",espok);
|
||||
|
||||
|
||||
ESP_LOGI(TAG, "Install RGB LCD panel driver");
|
||||
esp_lcd_panel_handle_t panel_handle = NULL;
|
||||
esp_lcd_rgb_panel_config_t rgb_config = {
|
||||
.clk_src = LCD_CLK_SRC_PLL160M,
|
||||
//add support ev board
|
||||
.timings = GC9503_800_480_PANEL_60HZ_RGB_TIMING(),
|
||||
.data_width = 16, // RGB565 in parallel mode, thus 16bit in width
|
||||
.bits_per_pixel = 16,
|
||||
.num_fbs = GC9503V_LCD_RGB_BUFFER_NUMS,
|
||||
.bounce_buffer_size_px = GC9503V_LCD_H_RES * GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT,
|
||||
.dma_burst_size = 64,
|
||||
.hsync_gpio_num = GC9503V_PIN_NUM_HSYNC,
|
||||
.vsync_gpio_num = GC9503V_PIN_NUM_VSYNC,
|
||||
.de_gpio_num = GC9503V_PIN_NUM_DE,
|
||||
.pclk_gpio_num = GC9503V_PIN_NUM_PCLK,
|
||||
.disp_gpio_num = GC9503V_PIN_NUM_DISP_EN,
|
||||
.data_gpio_nums = {
|
||||
GC9503V_PIN_NUM_DATA0,
|
||||
GC9503V_PIN_NUM_DATA1,
|
||||
GC9503V_PIN_NUM_DATA2,
|
||||
GC9503V_PIN_NUM_DATA3,
|
||||
GC9503V_PIN_NUM_DATA4,
|
||||
GC9503V_PIN_NUM_DATA5,
|
||||
GC9503V_PIN_NUM_DATA6,
|
||||
GC9503V_PIN_NUM_DATA7,
|
||||
GC9503V_PIN_NUM_DATA8,
|
||||
GC9503V_PIN_NUM_DATA9,
|
||||
GC9503V_PIN_NUM_DATA10,
|
||||
GC9503V_PIN_NUM_DATA11,
|
||||
GC9503V_PIN_NUM_DATA12,
|
||||
GC9503V_PIN_NUM_DATA13,
|
||||
GC9503V_PIN_NUM_DATA14,
|
||||
GC9503V_PIN_NUM_DATA15,
|
||||
},
|
||||
.flags= {
|
||||
.fb_in_psram = true, // allocate frame buffer in PSRAM
|
||||
}
|
||||
};
|
||||
|
||||
ESP_LOGI(TAG, "Initialize RGB LCD panel");
|
||||
|
||||
gc9503_vendor_config_t vendor_config = {
|
||||
.rgb_config = &rgb_config,
|
||||
.flags = {
|
||||
.mirror_by_cmd = 0,
|
||||
.auto_del_panel_io = 1,
|
||||
},
|
||||
};
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = -1,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
|
||||
// .bits_per_pixel = 16,
|
||||
//add surpport ev board
|
||||
.bits_per_pixel = 18,
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
(esp_lcd_new_panel_gc9503(panel_io, &panel_config, &panel_handle));
|
||||
(esp_lcd_panel_reset(panel_handle));
|
||||
(esp_lcd_panel_init(panel_handle));
|
||||
|
||||
display_ = new RgbLcdDisplay(panel_io, panel_handle,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X,
|
||||
DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_30_4,
|
||||
.icon_font = &font_awesome_30_4,
|
||||
.emoji_font = font_emoji_64_init(),
|
||||
});
|
||||
}
|
||||
void InitializeCodecI2c() {
|
||||
// Initialize I2C peripheral
|
||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
||||
.i2c_port = I2C_NUM_0,
|
||||
.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, &i2c_bus_));
|
||||
|
||||
//add support ev board lcd amp
|
||||
//初始化扩展io口
|
||||
esp_io_expander_new_i2c_tca9554(i2c_bus_, 0x20, &expander);
|
||||
/* Setup power amplifier pin, set default to enable */
|
||||
esp_io_expander_set_dir(expander, BSP_POWER_AMP_IO, IO_EXPANDER_OUTPUT);
|
||||
esp_io_expander_set_level(expander, BSP_POWER_AMP_IO, true);
|
||||
|
||||
}
|
||||
|
||||
void InitializeButtons() {
|
||||
boot_button_.OnClick([this]() {
|
||||
auto& app = Application::GetInstance();
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
});
|
||||
boot_button_.OnPressDown([this]() {
|
||||
Application::GetInstance().StartListening();
|
||||
});
|
||||
boot_button_.OnPressUp([this]() {
|
||||
Application::GetInstance().StopListening();
|
||||
});
|
||||
}
|
||||
|
||||
void InitializeTouch() {
|
||||
esp_lcd_touch_handle_t tp;
|
||||
esp_lcd_touch_config_t tp_cfg = {
|
||||
.x_max = DISPLAY_WIDTH,
|
||||
.y_max = DISPLAY_HEIGHT,
|
||||
.rst_gpio_num = GPIO_NUM_NC,
|
||||
.int_gpio_num = GPIO_NUM_NC,
|
||||
.levels = {
|
||||
.reset = 0,
|
||||
.interrupt = 0,
|
||||
},
|
||||
.flags = {
|
||||
.swap_xy = 0,
|
||||
.mirror_x = 0,
|
||||
.mirror_y = 0,
|
||||
},
|
||||
};
|
||||
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
|
||||
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT1151_CONFIG();
|
||||
tp_io_config.scl_speed_hz = 400 * 1000;
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(i2c_bus_, &tp_io_config, &tp_io_handle));
|
||||
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_gt1151(tp_io_handle, &tp_cfg, &tp));
|
||||
|
||||
const lvgl_port_touch_cfg_t touch_cfg = {
|
||||
.disp = lv_display_get_default(),
|
||||
.handle = tp,
|
||||
};
|
||||
lvgl_port_add_touch(&touch_cfg);
|
||||
}
|
||||
|
||||
public:
|
||||
ESP_S3_LCD_EV_Board_2() : boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializeCodecI2c();
|
||||
InitializeButtons();
|
||||
InitializeRGB_GC9503V_Display();
|
||||
InitializeTouch();
|
||||
}
|
||||
|
||||
|
||||
//es7210用作音频采集
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
static BoxAudioCodec audio_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,
|
||||
GPIO_NUM_NC,
|
||||
AUDIO_CODEC_ES8311_ADDR,
|
||||
AUDIO_CODEC_ES7210_ADDR,
|
||||
true);
|
||||
return &audio_codec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
//添加彩灯显示状态,如果亮度太暗可以去更改默认亮度值 DEFAULT_BRIGHTNESS 在led的sigle_led.cc中
|
||||
virtual Led* GetLed() override {
|
||||
static SingleLed led(BUILTIN_LED_GPIO);
|
||||
return &led;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
DECLARE_BOARD(ESP_S3_LCD_EV_Board_2);
|
||||
@@ -1,504 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_check.h>
|
||||
#include <esp_lcd_panel_commands.h>
|
||||
#include <esp_lcd_panel_interface.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
#include "esp_lcd_gc9503.h"
|
||||
|
||||
#define GC9503_CMD_MADCTL (0xB1) // Memory data access control
|
||||
#define GC9503_CMD_MADCTL_DEFAULT (0x10) // Default value of Memory data access control
|
||||
#define GC9503_CMD_SS_BIT (1 << 0) // Source driver scan direction, 0: top to bottom, 1: bottom to top
|
||||
#define GC9503_CMD_GS_BIT (1 << 1) // Gate driver scan direction, 0: left to right, 1: right to left
|
||||
#define GC9503_CMD_BGR_BIT (1 << 5) // RGB/BGR order, 0: RGB, 1: BGR
|
||||
|
||||
typedef struct
|
||||
{
|
||||
esp_lcd_panel_io_handle_t io;
|
||||
int reset_gpio_num;
|
||||
uint8_t madctl_val; // Save current value of GC9503_CMD_MADCTL register
|
||||
uint8_t colmod_val; // Save current value of LCD_CMD_COLMOD register
|
||||
const gc9503_lcd_init_cmd_t *init_cmds;
|
||||
uint16_t init_cmds_size;
|
||||
struct
|
||||
{
|
||||
unsigned int mirror_by_cmd : 1;
|
||||
unsigned int auto_del_panel_io : 1;
|
||||
unsigned int display_on_off_use_cmd : 1;
|
||||
unsigned int reset_level : 1;
|
||||
} flags;
|
||||
// To save the original functions of RGB panel
|
||||
esp_err_t (*init)(esp_lcd_panel_t *panel);
|
||||
esp_err_t (*del)(esp_lcd_panel_t *panel);
|
||||
esp_err_t (*reset)(esp_lcd_panel_t *panel);
|
||||
esp_err_t (*mirror)(esp_lcd_panel_t *panel, bool x_axis, bool y_axis);
|
||||
esp_err_t (*disp_on_off)(esp_lcd_panel_t *panel, bool on_off);
|
||||
} gc9503_panel_t;
|
||||
|
||||
static const char *TAG = "gc9503";
|
||||
|
||||
static esp_err_t panel_gc9503_send_init_cmds(gc9503_panel_t *gc9503);
|
||||
|
||||
static esp_err_t panel_gc9503_init(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_gc9503_del(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_gc9503_reset(esp_lcd_panel_t *panel);
|
||||
static esp_err_t panel_gc9503_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y);
|
||||
static esp_err_t panel_gc9503_disp_on_off(esp_lcd_panel_t *panel, bool off);
|
||||
|
||||
esp_err_t esp_lcd_new_panel_gc9503(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config,
|
||||
esp_lcd_panel_handle_t *ret_panel)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(io && panel_dev_config && ret_panel, ESP_ERR_INVALID_ARG, TAG, "invalid arguments");
|
||||
gc9503_vendor_config_t *vendor_config = (gc9503_vendor_config_t *)panel_dev_config->vendor_config;
|
||||
ESP_RETURN_ON_FALSE(vendor_config && vendor_config->rgb_config, ESP_ERR_INVALID_ARG, TAG, "`verndor_config` and `rgb_config` are necessary");
|
||||
ESP_RETURN_ON_FALSE(!vendor_config->flags.auto_del_panel_io || !vendor_config->flags.mirror_by_cmd,
|
||||
ESP_ERR_INVALID_ARG, TAG, "`mirror_by_cmd` and `auto_del_panel_io` cannot work together");
|
||||
|
||||
esp_err_t ret = ESP_OK;
|
||||
gpio_config_t io_conf = {0};
|
||||
|
||||
gc9503_panel_t *gc9503 = (gc9503_panel_t *)calloc(1, sizeof(gc9503_panel_t));
|
||||
ESP_RETURN_ON_FALSE(gc9503, ESP_ERR_NO_MEM, TAG, "no mem for gc9503 panel");
|
||||
|
||||
if (panel_dev_config->reset_gpio_num >= 0)
|
||||
{
|
||||
io_conf.mode = GPIO_MODE_OUTPUT;
|
||||
io_conf.pin_bit_mask = 1ULL << panel_dev_config->reset_gpio_num;
|
||||
ESP_GOTO_ON_ERROR(gpio_config(&io_conf), err, TAG, "configure GPIO for RST line failed");
|
||||
}
|
||||
|
||||
gc9503->madctl_val = GC9503_CMD_MADCTL_DEFAULT;
|
||||
switch (panel_dev_config->rgb_ele_order)
|
||||
{
|
||||
case LCD_RGB_ELEMENT_ORDER_RGB:
|
||||
gc9503->madctl_val &= ~GC9503_CMD_BGR_BIT;
|
||||
break;
|
||||
case LCD_RGB_ELEMENT_ORDER_BGR:
|
||||
gc9503->madctl_val |= GC9503_CMD_BGR_BIT;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported color element order");
|
||||
break;
|
||||
}
|
||||
|
||||
gc9503->colmod_val = 0;
|
||||
switch (panel_dev_config->bits_per_pixel)
|
||||
{
|
||||
case 16: // RGB565
|
||||
gc9503->colmod_val = 0x50;
|
||||
break;
|
||||
case 18: // RGB666
|
||||
gc9503->colmod_val = 0x60;
|
||||
break;
|
||||
case 24: // RGB888
|
||||
gc9503->colmod_val = 0x70;
|
||||
break;
|
||||
default:
|
||||
ESP_GOTO_ON_FALSE(false, ESP_ERR_NOT_SUPPORTED, err, TAG, "unsupported pixel width");
|
||||
break;
|
||||
}
|
||||
|
||||
gc9503->io = io;
|
||||
gc9503->init_cmds = vendor_config->init_cmds;
|
||||
gc9503->init_cmds_size = vendor_config->init_cmds_size;
|
||||
gc9503->reset_gpio_num = panel_dev_config->reset_gpio_num;
|
||||
gc9503->flags.reset_level = panel_dev_config->flags.reset_active_high;
|
||||
gc9503->flags.auto_del_panel_io = vendor_config->flags.auto_del_panel_io;
|
||||
gc9503->flags.mirror_by_cmd = vendor_config->flags.mirror_by_cmd;
|
||||
gc9503->flags.display_on_off_use_cmd = (vendor_config->rgb_config->disp_gpio_num >= 0) ? 0 : 1;
|
||||
|
||||
if (gc9503->flags.auto_del_panel_io)
|
||||
{
|
||||
if (gc9503->reset_gpio_num >= 0)
|
||||
{ // Perform hardware reset
|
||||
gpio_set_level(gc9503->reset_gpio_num, gc9503->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(gc9503->reset_gpio_num, !gc9503->flags.reset_level);
|
||||
}
|
||||
else
|
||||
{ // Perform software reset
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), err, TAG, "send command failed");
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
|
||||
/**
|
||||
* In order to enable the 3-wire SPI interface pins (such as SDA and SCK) to share other pins of the RGB interface
|
||||
* (such as HSYNC) and save GPIOs, we need to send LCD initialization commands via the 3-wire SPI interface before
|
||||
* `esp_lcd_new_rgb_panel()` is called.
|
||||
*/
|
||||
ESP_GOTO_ON_ERROR(panel_gc9503_send_init_cmds(gc9503), err, TAG, "send init commands failed");
|
||||
// After sending the initialization commands, the 3-wire SPI interface can be deleted
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_panel_io_del(io), err, TAG, "delete panel IO failed");
|
||||
gc9503->io = NULL;
|
||||
ESP_LOGD(TAG, "delete panel IO");
|
||||
}
|
||||
|
||||
// Create RGB panel
|
||||
ESP_GOTO_ON_ERROR(esp_lcd_new_rgb_panel(vendor_config->rgb_config, ret_panel), err, TAG, "create RGB panel failed");
|
||||
ESP_LOGD(TAG, "new RGB panel @%p", ret_panel);
|
||||
|
||||
// Save the original functions of RGB panel
|
||||
gc9503->init = (*ret_panel)->init;
|
||||
gc9503->del = (*ret_panel)->del;
|
||||
gc9503->reset = (*ret_panel)->reset;
|
||||
gc9503->mirror = (*ret_panel)->mirror;
|
||||
gc9503->disp_on_off = (*ret_panel)->disp_on_off;
|
||||
// Overwrite the functions of RGB panel
|
||||
(*ret_panel)->init = panel_gc9503_init;
|
||||
(*ret_panel)->del = panel_gc9503_del;
|
||||
(*ret_panel)->reset = panel_gc9503_reset;
|
||||
(*ret_panel)->mirror = panel_gc9503_mirror;
|
||||
(*ret_panel)->disp_on_off = panel_gc9503_disp_on_off;
|
||||
(*ret_panel)->user_data = gc9503;
|
||||
ESP_LOGD(TAG, "new gc9503 panel @%p", gc9503);
|
||||
|
||||
// ESP_LOGI(TAG, "LCD panel create success, version: %d.%d.%d", ESP_LCD_GC9503_VER_MAJOR, ESP_LCD_GC9503_VER_MINOR,
|
||||
// ESP_LCD_GC9503_VER_PATCH);
|
||||
return ESP_OK;
|
||||
|
||||
err:
|
||||
if (gc9503)
|
||||
{
|
||||
if (panel_dev_config->reset_gpio_num >= 0)
|
||||
{
|
||||
gpio_reset_pin(panel_dev_config->reset_gpio_num);
|
||||
}
|
||||
free(gc9503);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// *INDENT-OFF*
|
||||
// static const gc9503_lcd_init_cmd_t vendor_specific_init_default[] = {
|
||||
// // {cmd, { data }, data_size, delay_ms}
|
||||
// {0x11, (uint8_t []){0x00}, 0, 120},
|
||||
|
||||
// {0xf0, (uint8_t []){0x55, 0xaa, 0x52, 0x08, 0x00}, 5, 0},
|
||||
// {0xf6, (uint8_t []){0x5a, 0x87}, 2, 0},
|
||||
// {0xc1, (uint8_t []){0x3f}, 1, 0},
|
||||
// {0xc2, (uint8_t []){0x0e}, 1, 0},
|
||||
// {0xc6, (uint8_t []){0xf8}, 1, 0},
|
||||
// {0xc9, (uint8_t []){0x10}, 1, 0},
|
||||
// {0xcd, (uint8_t []){0x25}, 1, 0},
|
||||
// {0xf8, (uint8_t []){0x8a}, 1, 0},
|
||||
// {0xac, (uint8_t []){0x45}, 1, 0},
|
||||
// {0xa0, (uint8_t []){0xdd}, 1, 0},
|
||||
// {0xa7, (uint8_t []){0x47}, 1, 0},
|
||||
// {0xfa, (uint8_t []){0x00, 0x00, 0x00, 0x04}, 4, 0},
|
||||
// {0x86, (uint8_t []){0x99, 0xa3, 0xa3, 0x51}, 4, 0},
|
||||
// {0xa3, (uint8_t []){0xee}, 1, 0},
|
||||
// {0xfd, (uint8_t []){0x3c, 0x3c, 0x00}, 3, 0},
|
||||
// {0x71, (uint8_t []){0x48}, 1, 0},
|
||||
// {0x72, (uint8_t []){0x48}, 1, 0},
|
||||
// {0x73, (uint8_t []){0x00, 0x44}, 2, 0},
|
||||
// {0x97, (uint8_t []){0xee}, 1, 0},
|
||||
// {0x83, (uint8_t []){0x93}, 1, 0},
|
||||
// {0x9a, (uint8_t []){0x72}, 1, 0},
|
||||
// {0x9b, (uint8_t []){0x5a}, 1, 0},
|
||||
// {0x82, (uint8_t []){0x2c, 0x2c}, 2, 0},
|
||||
// {0x6d, (uint8_t []){0x00, 0x1f, 0x19, 0x1a, 0x10, 0x0e, 0x0c, 0x0a, 0x02, 0x07, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
||||
// 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x08, 0x01, 0x09, 0x0b, 0x0d, 0x0f, 0x1a, 0x19, 0x1f, 0x00}, 32, 0},
|
||||
// {0x64, (uint8_t []){0x38, 0x05, 0x01, 0xdb, 0x03, 0x03, 0x38, 0x04, 0x01, 0xdc, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
// {0x65, (uint8_t []){0x38, 0x03, 0x01, 0xdd, 0x03, 0x03, 0x38, 0x02, 0x01, 0xde, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
// {0x66, (uint8_t []){0x38, 0x01, 0x01, 0xdf, 0x03, 0x03, 0x38, 0x00, 0x01, 0xe0, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
// {0x67, (uint8_t []){0x30, 0x01, 0x01, 0xe1, 0x03, 0x03, 0x30, 0x02, 0x01, 0xe2, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
// {0x68, (uint8_t []){0x00, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a}, 13, 0},
|
||||
// {0x60, (uint8_t []){0x38, 0x08, 0x7a, 0x7a, 0x38, 0x09, 0x7a, 0x7a}, 8, 0},
|
||||
// {0x63, (uint8_t []){0x31, 0xe4, 0x7a, 0x7a, 0x31, 0xe5, 0x7a, 0x7a}, 8, 0},
|
||||
// {0x69, (uint8_t []){0x04, 0x22, 0x14, 0x22, 0x14, 0x22, 0x08}, 7, 0},
|
||||
// {0x6b, (uint8_t []){0x07}, 1, 0},
|
||||
// {0x7a, (uint8_t []){0x08, 0x13}, 2, 0},
|
||||
// {0x7b, (uint8_t []){0x08, 0x13}, 2, 0},
|
||||
// {0xd1, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
// 0xff}, 52, 0},
|
||||
// {0xd2, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
// 0xff}, 52, 0},
|
||||
// {0xd3, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
// 0xff}, 52, 0},
|
||||
// {0xd4, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
// 0xff}, 52, 0},
|
||||
// {0xd5, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
// 0xff}, 52, 0},
|
||||
// {0xd6, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
// 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
// 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
// 0xff}, 52, 0},
|
||||
// {0x11, (uint8_t []){0x00}, 0, 120},
|
||||
// {0x29, (uint8_t []){0x00}, 0, 20},
|
||||
// };
|
||||
static const gc9503_lcd_init_cmd_t vendor_specific_init_default[] = {
|
||||
// {0x11, (uint8_t[]){}, 0, 20},
|
||||
|
||||
{0xf0, (uint8_t []){0x55, 0xaa, 0x52, 0x08, 0x00}, 5, 0},
|
||||
{0xf6, (uint8_t []){0x5a, 0x87}, 2, 0},
|
||||
{0xc1, (uint8_t []){0x3f}, 1, 0},
|
||||
{0xc2, (uint8_t []){0x0e}, 1, 0},
|
||||
{0xc6, (uint8_t []){0xf8}, 1, 0},
|
||||
{0xc9, (uint8_t []){0x10}, 1, 0},
|
||||
{0xcd, (uint8_t []){0x25}, 1, 0},
|
||||
{0xf8, (uint8_t []){0x8a}, 1, 0},
|
||||
{0xac, (uint8_t []){0x45}, 1, 0},
|
||||
{0xa0, (uint8_t []){0xdd}, 1, 0},
|
||||
{0xa7, (uint8_t []){0x47}, 1, 0},
|
||||
{0xfa, (uint8_t []){0x00, 0x00, 0x00, 0x04}, 4, 0},
|
||||
{0x86, (uint8_t []){0x99, 0xa3, 0xa3, 0x51}, 4, 0},
|
||||
{0xa3, (uint8_t []){0xee}, 1, 0},
|
||||
{0xfd, (uint8_t []){0x3c, 0x3c, 0x00}, 3, 0},
|
||||
{0x71, (uint8_t []){0x48}, 1, 0},
|
||||
{0x72, (uint8_t []){0x48}, 1, 0},
|
||||
{0x73, (uint8_t []){0x00, 0x44}, 2, 0},
|
||||
{0x97, (uint8_t []){0xee}, 1, 0},
|
||||
{0x83, (uint8_t []){0x93}, 1, 0},
|
||||
{0x9a, (uint8_t []){0x72}, 1, 0},
|
||||
{0x9b, (uint8_t []){0x5a}, 1, 0},
|
||||
{0x82, (uint8_t []){0x2c, 0x2c}, 2, 0},
|
||||
{0x6d, (uint8_t []){0x00, 0x1f, 0x19, 0x1a, 0x10, 0x0e, 0x0c, 0x0a, 0x02, 0x07, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e,
|
||||
0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x08, 0x01, 0x09, 0x0b, 0x0d, 0x0f, 0x1a, 0x19, 0x1f, 0x00}, 32, 0},
|
||||
{0x64, (uint8_t []){0x38, 0x05, 0x01, 0xdb, 0x03, 0x03, 0x38, 0x04, 0x01, 0xdc, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
{0x65, (uint8_t []){0x38, 0x03, 0x01, 0xdd, 0x03, 0x03, 0x38, 0x02, 0x01, 0xde, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
{0x66, (uint8_t []){0x38, 0x01, 0x01, 0xdf, 0x03, 0x03, 0x38, 0x00, 0x01, 0xe0, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
{0x67, (uint8_t []){0x30, 0x01, 0x01, 0xe1, 0x03, 0x03, 0x30, 0x02, 0x01, 0xe2, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a}, 16, 0},
|
||||
{0x68, (uint8_t []){0x00, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a}, 13, 0},
|
||||
{0x60, (uint8_t []){0x38, 0x08, 0x7a, 0x7a, 0x38, 0x09, 0x7a, 0x7a}, 8, 0},
|
||||
{0x63, (uint8_t []){0x31, 0xe4, 0x7a, 0x7a, 0x31, 0xe5, 0x7a, 0x7a}, 8, 0},
|
||||
{0x69, (uint8_t []){0x04, 0x22, 0x14, 0x22, 0x14, 0x22, 0x08}, 7, 0},
|
||||
{0x6b, (uint8_t []){0x07}, 1, 0},
|
||||
{0x7a, (uint8_t []){0x08, 0x13}, 2, 0},
|
||||
{0x7b, (uint8_t []){0x08, 0x13}, 2, 0},
|
||||
{0xd1, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
0xff}, 52, 0},
|
||||
{0xd2, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
0xff}, 52, 0},
|
||||
{0xd3, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
0xff}, 52, 0},
|
||||
{0xd4, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
0xff}, 52, 0},
|
||||
{0xd5, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
0xff}, 52, 0},
|
||||
{0xd6, (uint8_t []){0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
|
||||
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
|
||||
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
|
||||
0xff}, 52, 0},
|
||||
{0x11, (uint8_t []){0x00}, 0, 120},
|
||||
{0x29, (uint8_t []){0x00}, 0, 20},
|
||||
|
||||
};
|
||||
|
||||
// *INDENT-OFF*
|
||||
|
||||
static esp_err_t panel_gc9503_send_init_cmds(gc9503_panel_t *gc9503)
|
||||
{
|
||||
esp_lcd_panel_io_handle_t io = gc9503->io;
|
||||
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, GC9503_CMD_MADCTL, (uint8_t[]){
|
||||
gc9503->madctl_val,
|
||||
},
|
||||
1),
|
||||
TAG, "send command failed");
|
||||
;
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_COLMOD, (uint8_t[]){
|
||||
gc9503->colmod_val,
|
||||
},
|
||||
1),
|
||||
TAG, "send command failed");
|
||||
;
|
||||
|
||||
// Vendor specific initialization, it can be different between manufacturers
|
||||
// should consult the LCD supplier for initialization sequence code
|
||||
const gc9503_lcd_init_cmd_t *init_cmds = NULL;
|
||||
uint16_t init_cmds_size = 0;
|
||||
if (gc9503->init_cmds)
|
||||
{
|
||||
init_cmds = gc9503->init_cmds;
|
||||
init_cmds_size = gc9503->init_cmds_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
init_cmds = vendor_specific_init_default;
|
||||
init_cmds_size = sizeof(vendor_specific_init_default) / sizeof(gc9503_lcd_init_cmd_t);
|
||||
}
|
||||
|
||||
bool is_cmd_overwritten = false;
|
||||
for (int i = 0; i < init_cmds_size; i++)
|
||||
{
|
||||
// Check if the command has been used or conflicts with the internal
|
||||
switch (init_cmds[i].cmd)
|
||||
{
|
||||
case LCD_CMD_MADCTL:
|
||||
is_cmd_overwritten = true;
|
||||
gc9503->madctl_val = ((uint8_t *)init_cmds[i].data)[0];
|
||||
break;
|
||||
case LCD_CMD_COLMOD:
|
||||
is_cmd_overwritten = true;
|
||||
gc9503->colmod_val = ((uint8_t *)init_cmds[i].data)[0];
|
||||
break;
|
||||
default:
|
||||
is_cmd_overwritten = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_cmd_overwritten)
|
||||
{
|
||||
ESP_LOGW(TAG, "The %02Xh command has been used and will be overwritten by external initialization sequence",
|
||||
init_cmds[i].cmd);
|
||||
}
|
||||
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, init_cmds[i].cmd, init_cmds[i].data, init_cmds[i].data_bytes),
|
||||
TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(init_cmds[i].delay_ms));
|
||||
}
|
||||
ESP_LOGD(TAG, "send init commands success");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9503_init(esp_lcd_panel_t *panel)
|
||||
{
|
||||
gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data;
|
||||
|
||||
if (!gc9503->flags.auto_del_panel_io)
|
||||
{
|
||||
ESP_RETURN_ON_ERROR(panel_gc9503_send_init_cmds(gc9503), TAG, "send init commands failed");
|
||||
}
|
||||
// Init RGB panel
|
||||
ESP_RETURN_ON_ERROR(gc9503->init(panel), TAG, "init RGB panel failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9503_del(esp_lcd_panel_t *panel)
|
||||
{
|
||||
gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data;
|
||||
|
||||
if (gc9503->reset_gpio_num >= 0)
|
||||
{
|
||||
gpio_reset_pin(gc9503->reset_gpio_num);
|
||||
}
|
||||
// Delete RGB panel
|
||||
gc9503->del(panel);
|
||||
free(gc9503);
|
||||
ESP_LOGD(TAG, "del gc9503 panel @%p", gc9503);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9503_reset(esp_lcd_panel_t *panel)
|
||||
{
|
||||
gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = gc9503->io;
|
||||
|
||||
// Perform hardware reset
|
||||
if (gc9503->reset_gpio_num >= 0)
|
||||
{
|
||||
gpio_set_level(gc9503->reset_gpio_num, gc9503->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
gpio_set_level(gc9503->reset_gpio_num, !gc9503->flags.reset_level);
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
}
|
||||
else if (io)
|
||||
{ // Perform software reset
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, LCD_CMD_SWRESET, NULL, 0), TAG, "send command failed");
|
||||
vTaskDelay(pdMS_TO_TICKS(120));
|
||||
}
|
||||
// Reset RGB panel
|
||||
ESP_RETURN_ON_ERROR(gc9503->reset(panel), TAG, "reset RGB panel failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9503_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y)
|
||||
{
|
||||
gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = gc9503->io;
|
||||
|
||||
if (gc9503->flags.mirror_by_cmd)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(io, ESP_FAIL, TAG, "Panel IO is deleted, cannot send command");
|
||||
// Control mirror through LCD command
|
||||
if (mirror_x)
|
||||
{
|
||||
gc9503->madctl_val |= GC9503_CMD_GS_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
gc9503->madctl_val &= ~GC9503_CMD_GS_BIT;
|
||||
}
|
||||
if (mirror_y)
|
||||
{
|
||||
gc9503->madctl_val |= GC9503_CMD_SS_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
gc9503->madctl_val &= ~GC9503_CMD_SS_BIT;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, GC9503_CMD_MADCTL, (uint8_t[]){
|
||||
gc9503->madctl_val,
|
||||
},
|
||||
1),
|
||||
TAG, "send command failed");
|
||||
;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Control mirror through RGB panel
|
||||
ESP_RETURN_ON_ERROR(gc9503->mirror(panel, mirror_x, mirror_y), TAG, "RGB panel mirror failed");
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t panel_gc9503_disp_on_off(esp_lcd_panel_t *panel, bool on_off)
|
||||
{
|
||||
gc9503_panel_t *gc9503 = (gc9503_panel_t *)panel->user_data;
|
||||
esp_lcd_panel_io_handle_t io = gc9503->io;
|
||||
int command = 0;
|
||||
|
||||
if (gc9503->flags.display_on_off_use_cmd)
|
||||
{
|
||||
ESP_RETURN_ON_FALSE(io, ESP_FAIL, TAG, "Panel IO is deleted, cannot send command");
|
||||
// Control display on/off through LCD command
|
||||
if (on_off)
|
||||
{
|
||||
command = LCD_CMD_DISPON;
|
||||
}
|
||||
else
|
||||
{
|
||||
command = LCD_CMD_DISPOFF;
|
||||
}
|
||||
ESP_RETURN_ON_ERROR(esp_lcd_panel_io_tx_param(io, command, NULL, 0), TAG, "send command failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Control display on/off through display control signal
|
||||
ESP_RETURN_ON_ERROR(gc9503->disp_on_off(panel, on_off), TAG, "RGB panel disp_on_off failed");
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
* @brief ESP LCD: GC9503
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <esp_lcd_panel_vendor.h>
|
||||
#include <esp_lcd_panel_rgb.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief LCD panel initialization commands.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int cmd; /*<! The specific LCD command */
|
||||
const void *data; /*<! Buffer that holds the command specific data */
|
||||
size_t data_bytes; /*<! Size of `data` in memory, in bytes */
|
||||
unsigned int delay_ms; /*<! Delay in milliseconds after this command */
|
||||
} gc9503_lcd_init_cmd_t;
|
||||
|
||||
/**
|
||||
* @brief LCD panel vendor configuration.
|
||||
*
|
||||
* @note This structure needs to be passed to the `vendor_config` field in `esp_lcd_panel_dev_config_t`.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
const esp_lcd_rgb_panel_config_t *rgb_config; /*!< RGB panel configuration */
|
||||
const gc9503_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array. Set to NULL if using default commands.
|
||||
* The array should be declared as `static const` and positioned outside the function.
|
||||
* Please refer to `vendor_specific_init_default` in source file.
|
||||
*/
|
||||
uint16_t init_cmds_size; /*<! Number of commands in above array */
|
||||
struct {
|
||||
unsigned int mirror_by_cmd: 1; /*<! The `mirror()` function will be implemented by LCD command if set to 1.
|
||||
* Otherwise, the function will be implemented by software.
|
||||
*/
|
||||
unsigned int auto_del_panel_io: 1; /*<! Delete the panel IO instance automatically if set to 1. All `*_by_cmd` flags will be invalid.
|
||||
* If the panel IO pins are sharing other pins of the RGB interface to save GPIOs,
|
||||
* Please set it to 1 to release the panel IO and its pins (except CS signal).
|
||||
*/
|
||||
} flags;
|
||||
} gc9503_vendor_config_t;
|
||||
|
||||
/**
|
||||
* @brief Create LCD panel for model GC9503
|
||||
*
|
||||
* @note When `auto_del_panel_io` is set to 1, this function will first initialize the GC9503 with vendor specific initialization and then calls `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will only initialize RGB.
|
||||
* @note When `auto_del_panel_io` is set to 0, this function will only call `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will initialize both the GC9503 and RGB.
|
||||
* @note Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for initialization sequence code.
|
||||
*
|
||||
* @param[in] io LCD panel IO handle
|
||||
* @param[in] panel_dev_config General panel device configuration (`vendor_config` and `rgb_config` are necessary)
|
||||
* @param[out] ret_panel Returned LCD panel handle
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
* - ESP_OK on success
|
||||
* - Otherwise on fail
|
||||
*/
|
||||
esp_err_t esp_lcd_new_panel_gc9503(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config,
|
||||
esp_lcd_panel_handle_t *ret_panel);
|
||||
|
||||
/**
|
||||
* @brief 3-wire SPI panel IO configuration structure
|
||||
*
|
||||
* @param[in] line_cfg SPI line configuration
|
||||
* @param[in] scl_active_edge SCL signal active edge, 0: rising edge, 1: falling edge
|
||||
*
|
||||
*/
|
||||
#define GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_cfg, scl_active_edge) \
|
||||
{ \
|
||||
.line_config = line_cfg, \
|
||||
.expect_clk_speed = PANEL_IO_3WIRE_SPI_CLK_MAX, \
|
||||
.spi_mode = scl_active_edge ? 1 : 0, \
|
||||
.lcd_cmd_bytes = 1, \
|
||||
.lcd_param_bytes = 1, \
|
||||
.flags = { \
|
||||
.use_dc_bit = 1, \
|
||||
.dc_zero_on_data = 0, \
|
||||
.lsb_first = 0, \
|
||||
.cs_high_active = 0, \
|
||||
.del_keep_cs_inactive = 1, \
|
||||
}, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RGB timing structure
|
||||
*
|
||||
* @note refresh_rate = (pclk_hz * data_width) / (h_res + hsync_pulse_width + hsync_back_porch + hsync_front_porch)
|
||||
* / (v_res + vsync_pulse_width + vsync_back_porch + vsync_front_porch)
|
||||
* / bits_per_pixel
|
||||
* .pclk_hz = 16 * 1000 * 1000, \
|
||||
.h_res = 384, \
|
||||
.v_res = 960, \
|
||||
.hsync_pulse_width = 24, \
|
||||
.hsync_back_porch = 20, \
|
||||
.hsync_front_porch = 40, \
|
||||
.vsync_pulse_width = 30, \
|
||||
.vsync_back_porch = 18, \
|
||||
.vsync_front_porch = 20, \
|
||||
.flags.pclk_active_neg = 0, \
|
||||
|
||||
.hsync_pulse_width = 24, \
|
||||
.hsync_back_porch = 20, \
|
||||
.hsync_front_porch = 40, \
|
||||
.vsync_pulse_width = 30, \
|
||||
.vsync_back_porch = 18, \
|
||||
.vsync_front_porch = 20, \
|
||||
|
||||
*/
|
||||
|
||||
#define GC9503_800_480_PANEL_60HZ_RGB_TIMING() \
|
||||
{ \
|
||||
.pclk_hz = 16 * 1000 * 1000, \
|
||||
.h_res = 800, \
|
||||
.v_res = 480, \
|
||||
.hsync_pulse_width = 10, \
|
||||
.hsync_back_porch = 10, \
|
||||
.hsync_front_porch = 20, \
|
||||
.vsync_pulse_width = 10, \
|
||||
.vsync_back_porch = 10, \
|
||||
.vsync_front_porch = 10, \
|
||||
.flags = { \
|
||||
.hsync_idle_low = 0, \
|
||||
.vsync_idle_low = 0, \
|
||||
.de_idle_high = 0, \
|
||||
.pclk_active_neg = 0, \
|
||||
.pclk_idle_high = 0, \
|
||||
}, \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
//关于开发板和屏幕的资料参考
|
||||
//https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32s3/esp32-s3-lcd-ev-board/user_guide.html
|
||||
|
||||
#define GC9503V_LCD_H_RES 800
|
||||
#define GC9503V_LCD_V_RES 480
|
||||
|
||||
|
||||
#define GC9503V_LCD_LVGL_DIRECT_MODE (1)
|
||||
#define GC9503V_LCD_LVGL_AVOID_TEAR (1)
|
||||
#define GC9503V_LCD_RGB_BOUNCE_BUFFER_MODE (1)
|
||||
#define GC9503V_LCD_DRAW_BUFF_DOUBLE (0)
|
||||
#define GC9503V_LCD_DRAW_BUFF_HEIGHT (100)
|
||||
#define GC9503V_LCD_RGB_BUFFER_NUMS (2)
|
||||
#define GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT (10)
|
||||
|
||||
#define GC9503V_LCD_PIXEL_CLOCK_HZ (16 * 1000 * 1000)
|
||||
#define GC9503V_LCD_BK_LIGHT_ON_LEVEL 1
|
||||
#define GC9503V_LCD_BK_LIGHT_OFF_LEVEL !GC9503V_LCD_BK_LIGHT_ON_LEVEL
|
||||
|
||||
#define GC9503V_PIN_NUM_BK_LIGHT GPIO_NUM_NC //GPIO_NUM_4
|
||||
#define GC9503V_PIN_NUM_HSYNC GPIO_NUM_46
|
||||
#define GC9503V_PIN_NUM_VSYNC GPIO_NUM_3
|
||||
#define GC9503V_PIN_NUM_DE GPIO_NUM_17
|
||||
#define GC9503V_PIN_NUM_PCLK GPIO_NUM_9
|
||||
|
||||
#define GC9503V_PIN_NUM_DATA0 GPIO_NUM_10 // B0
|
||||
#define GC9503V_PIN_NUM_DATA1 GPIO_NUM_11 // B1
|
||||
#define GC9503V_PIN_NUM_DATA2 GPIO_NUM_12 // B2
|
||||
#define GC9503V_PIN_NUM_DATA3 GPIO_NUM_13 // B3
|
||||
#define GC9503V_PIN_NUM_DATA4 GPIO_NUM_14 // B4
|
||||
|
||||
#define GC9503V_PIN_NUM_DATA5 GPIO_NUM_21 // G0
|
||||
#define GC9503V_PIN_NUM_DATA6 GPIO_NUM_8 // G1
|
||||
#define GC9503V_PIN_NUM_DATA7 GPIO_NUM_18 // G2
|
||||
#define GC9503V_PIN_NUM_DATA8 GPIO_NUM_45 // G3
|
||||
#define GC9503V_PIN_NUM_DATA9 GPIO_NUM_38 // G4
|
||||
#define GC9503V_PIN_NUM_DATA10 GPIO_NUM_39 // G5
|
||||
|
||||
#define GC9503V_PIN_NUM_DATA11 GPIO_NUM_40 // R0
|
||||
#define GC9503V_PIN_NUM_DATA12 GPIO_NUM_41 // R1
|
||||
#define GC9503V_PIN_NUM_DATA13 GPIO_NUM_42 // R2
|
||||
#define GC9503V_PIN_NUM_DATA14 GPIO_NUM_2 // R3
|
||||
#define GC9503V_PIN_NUM_DATA15 GPIO_NUM_1 // R4
|
||||
|
||||
#define GC9503V_PIN_NUM_DISP_EN -1
|
||||
|
||||
#define GC9503V_LCD_IO_SPI_CS_1 (IO_EXPANDER_PIN_NUM_1)
|
||||
#define GC9503V_LCD_IO_SPI_SCL_1 (IO_EXPANDER_PIN_NUM_2)
|
||||
#define GC9503V_LCD_IO_SPI_SDO_1 (IO_EXPANDER_PIN_NUM_3)
|
||||
@@ -64,7 +64,7 @@ CoreS3AudioCodec::CoreS3AudioCodec(void* i2c_master_handle, int input_sample_rat
|
||||
|
||||
es7210_codec_cfg_t es7210_cfg = {};
|
||||
es7210_cfg.ctrl_if = in_ctrl_if_;
|
||||
es7210_cfg.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3;
|
||||
es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3;
|
||||
in_codec_if_ = es7210_codec_new(&es7210_cfg);
|
||||
assert(in_codec_if_ != NULL);
|
||||
|
||||
|
||||
@@ -627,7 +627,6 @@ CONFIG_BOARD_TYPE_M5STACK_CORE_S3=y
|
||||
# CONFIG_BOARD_TYPE_MIXGO_NOVA is not set
|
||||
# CONFIG_BOARD_TYPE_GENJUTECH_S3_1_54TFT is not set
|
||||
# CONFIG_BOARD_TYPE_ESP_S3_LCD_EV_Board is not set
|
||||
# CONFIG_BOARD_TYPE_ESP_S3_LCD_EV_Board_2 is not set
|
||||
# CONFIG_BOARD_TYPE_ZHENGCHEN_1_54TFT_WIFI is not set
|
||||
# CONFIG_BOARD_TYPE_MINSI_K08_DUAL is not set
|
||||
# CONFIG_BOARD_TYPE_ZHENGCHEN_1_54TFT_ML307 is not set
|
||||
|
||||
@@ -66,7 +66,7 @@ Tab5AudioCodec::Tab5AudioCodec(void* i2c_master_handle, int input_sample_rate, i
|
||||
|
||||
es7210_codec_cfg_t es7210_cfg = {};
|
||||
es7210_cfg.ctrl_if = in_ctrl_if_;
|
||||
es7210_cfg.mic_selected = ES7210_SEL_MIC1 | ES7210_SEL_MIC2 | ES7210_SEL_MIC3 | ES7210_SEL_MIC4;
|
||||
es7210_cfg.mic_selected = ES7120_SEL_MIC1 | ES7120_SEL_MIC2 | ES7120_SEL_MIC3 | ES7120_SEL_MIC4;
|
||||
in_codec_if_ = es7210_codec_new(&es7210_cfg);
|
||||
assert(in_codec_if_ != NULL);
|
||||
|
||||
|
||||
@@ -142,7 +142,7 @@ void OttoEmojiDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, content);
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置聊天消息 [%s]: %s", role, content);
|
||||
}
|
||||
@@ -164,7 +164,7 @@ void OttoEmojiDisplay::SetIcon(const char* icon) {
|
||||
}
|
||||
|
||||
lv_label_set_text(chat_message_label_, icon_message.c_str());
|
||||
lv_obj_remove_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(chat_message_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
ESP_LOGI(TAG, "设置图标: %s", icon);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
|
||||
void SetupHighTempWarningPopup() {
|
||||
// 创建高温警告弹窗
|
||||
high_temp_popup_ = lv_obj_create(lv_screen_active()); // 使用当前屏幕
|
||||
high_temp_popup_ = lv_obj_create(lv_scr_act()); // 使用当前屏幕
|
||||
lv_obj_set_scrollbar_mode(high_temp_popup_, LV_SCROLLBAR_MODE_OFF);
|
||||
lv_obj_set_size(high_temp_popup_, LV_HOR_RES * 0.9, fonts_.text_font->line_height * 2);
|
||||
lv_obj_align(high_temp_popup_, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
void ShowHighTempWarning() {
|
||||
if (high_temp_popup_ && lv_obj_has_flag(high_temp_popup_, LV_OBJ_FLAG_HIDDEN)) {
|
||||
lv_obj_remove_flag(high_temp_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(high_temp_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ Display::Display() {
|
||||
Display *display = static_cast<Display*>(arg);
|
||||
DisplayLockGuard lock(display);
|
||||
lv_obj_add_flag(display->notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_remove_flag(display->status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(display->status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
},
|
||||
.arg = this,
|
||||
.dispatch_method = ESP_TIMER_TASK,
|
||||
@@ -67,7 +67,7 @@ void Display::SetStatus(const char* status) {
|
||||
return;
|
||||
}
|
||||
lv_label_set_text(status_label_, status);
|
||||
lv_obj_remove_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
last_status_update_time_ = std::chrono::system_clock::now();
|
||||
@@ -83,7 +83,7 @@ void Display::ShowNotification(const char* notification, int duration_ms) {
|
||||
return;
|
||||
}
|
||||
lv_label_set_text(notification_label_, notification);
|
||||
lv_obj_remove_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(notification_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(status_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
esp_timer_stop(notification_timer_);
|
||||
@@ -157,7 +157,7 @@ void Display::UpdateStatusBar(bool update_all) {
|
||||
if (low_battery_popup_ != nullptr) {
|
||||
if (strcmp(icon, FONT_AWESOME_BATTERY_EMPTY) == 0 && discharging) {
|
||||
if (lv_obj_has_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN)) { // 如果低电量提示框隐藏,则显示
|
||||
lv_obj_remove_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(low_battery_popup_, LV_OBJ_FLAG_HIDDEN);
|
||||
app.PlaySound(Lang::Sounds::OGG_LOW_BATTERY);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -105,7 +105,7 @@ SpiLcdDisplay::SpiLcdDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_h
|
||||
ESP_LOGI(TAG, "Initialize LVGL port");
|
||||
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
||||
port_cfg.task_priority = 1;
|
||||
port_cfg.timer_period_ms = 40;
|
||||
port_cfg.timer_period_ms = 50;
|
||||
lvgl_port_init(&port_cfg);
|
||||
|
||||
ESP_LOGI(TAG, "Adding LCD display");
|
||||
@@ -814,11 +814,11 @@ void LcdDisplay::SetPreviewImage(const lv_img_dsc_t* img_dsc) {
|
||||
}
|
||||
|
||||
if (img_dsc != nullptr) {
|
||||
// 设置图片源并显示预览图片
|
||||
lv_image_set_src(preview_image_, img_dsc);
|
||||
// zoom factor 0.5
|
||||
lv_image_set_scale(preview_image_, 128 * width_ / img_dsc->header.w);
|
||||
lv_obj_remove_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
// 设置图片源并显示预览图片
|
||||
lv_image_set_src(preview_image_, img_dsc);
|
||||
lv_obj_clear_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
// 隐藏emotion_label_
|
||||
if (emotion_label_ != nullptr) {
|
||||
lv_obj_add_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
@@ -827,7 +827,7 @@ void LcdDisplay::SetPreviewImage(const lv_img_dsc_t* img_dsc) {
|
||||
// 隐藏预览图片并显示emotion_label_
|
||||
lv_obj_add_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
if (emotion_label_ != nullptr) {
|
||||
lv_obj_remove_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -883,7 +883,7 @@ void LcdDisplay::SetEmotion(const char* emotion) {
|
||||
|
||||
#if !CONFIG_USE_WECHAT_MESSAGE_STYLE
|
||||
// 显示emotion_label_,隐藏preview_image_
|
||||
lv_obj_remove_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
if (preview_image_ != nullptr) {
|
||||
lv_obj_add_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
@@ -900,7 +900,7 @@ void LcdDisplay::SetIcon(const char* icon) {
|
||||
|
||||
#if !CONFIG_USE_WECHAT_MESSAGE_STYLE
|
||||
// 显示emotion_label_,隐藏preview_image_
|
||||
lv_obj_remove_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(emotion_label_, LV_OBJ_FLAG_HIDDEN);
|
||||
if (preview_image_ != nullptr) {
|
||||
lv_obj_add_flag(preview_image_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ OledDisplay::OledDisplay(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_handl
|
||||
lvgl_port_cfg_t port_cfg = ESP_LVGL_PORT_INIT_CONFIG();
|
||||
port_cfg.task_priority = 1;
|
||||
port_cfg.task_stack = 6144;
|
||||
port_cfg.timer_period_ms = 40;
|
||||
port_cfg.timer_period_ms = 50;
|
||||
lvgl_port_init(&port_cfg);
|
||||
|
||||
ESP_LOGI(TAG, "Adding OLED display");
|
||||
@@ -112,7 +112,7 @@ void OledDisplay::SetChatMessage(const char* role, const char* content) {
|
||||
lv_obj_add_flag(content_right_, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_label_set_text(chat_message_label_, content_str.c_str());
|
||||
lv_obj_remove_flag(content_right_, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(content_right_, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,27 +13,26 @@ dependencies:
|
||||
espressif/esp_io_expander_tca9554: ==2.0.0
|
||||
espressif/esp_lcd_panel_io_additions: ^1.0.1
|
||||
78/esp_lcd_nv3023: ~1.0.0
|
||||
78/esp-wifi-connect: ~2.5.1
|
||||
78/esp-wifi-connect: ~2.5.0
|
||||
78/esp-opus-encoder: ~2.4.1
|
||||
78/esp-ml307: ~3.2.8
|
||||
78/esp-ml307: ~3.2.6
|
||||
78/xiaozhi-fonts: ~1.4.0
|
||||
espressif/led_strip: ~3.0.1
|
||||
espressif/esp_codec_dev: ~1.4.0
|
||||
espressif/esp-sr: ~2.1.5
|
||||
espressif/led_strip: ^2.5.5
|
||||
espressif/esp_codec_dev: ~1.3.6
|
||||
espressif/esp-sr: ~2.1.4
|
||||
espressif/button: ~4.1.3
|
||||
espressif/knob: ^1.0.0
|
||||
espressif/esp32-camera: ~2.1.2
|
||||
espressif/esp32-camera: ^2.0.15
|
||||
espressif/esp_lcd_touch_ft5x06: ~1.0.7
|
||||
espressif/esp_lcd_touch_gt911: ^1
|
||||
espressif/esp_lcd_touch_gt1151: ^1
|
||||
waveshare/esp_lcd_touch_cst9217: ^1.0.3
|
||||
espressif/esp_lcd_touch_cst816s: ^1.0.6
|
||||
lvgl/lvgl: ~9.3.0
|
||||
lvgl/lvgl: ~9.2.2
|
||||
esp_lvgl_port: ~2.6.0
|
||||
espressif/esp_io_expander_tca95xx_16bit: ^2.0.0
|
||||
espressif2022/image_player: ==1.1.0~1
|
||||
espressif2022/esp_emote_gfx: ^1.0.0
|
||||
espressif/adc_mic: ^0.2.1
|
||||
espressif/adc_mic: ^0.2.0
|
||||
espressif/esp_mmap_assets: '>=1.2'
|
||||
txp666/otto-emoji-gif-component: ~1.0.2
|
||||
espressif/adc_battery_estimation: ^0.2.0
|
||||
@@ -62,7 +61,7 @@ dependencies:
|
||||
rules:
|
||||
- if: target in [esp32p4]
|
||||
espressif/esp_hosted:
|
||||
version: 2.0.17
|
||||
version: '2.0.17'
|
||||
rules:
|
||||
- if: target in [esp32h2, esp32p4]
|
||||
espressif/esp_wifi_remote:
|
||||
|
||||
@@ -15,7 +15,7 @@ CircularStrip::CircularStrip(gpio_num_t gpio, uint8_t max_leds) : max_leds_(max_
|
||||
led_strip_config_t strip_config = {};
|
||||
strip_config.strip_gpio_num = gpio;
|
||||
strip_config.max_leds = max_leds_;
|
||||
strip_config.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB;
|
||||
strip_config.led_pixel_format = LED_PIXEL_FORMAT_GRB;
|
||||
strip_config.led_model = LED_MODEL_WS2812;
|
||||
|
||||
led_strip_rmt_config_t rmt_config = {};
|
||||
|
||||
@@ -18,7 +18,7 @@ SingleLed::SingleLed(gpio_num_t gpio) {
|
||||
led_strip_config_t strip_config = {};
|
||||
strip_config.strip_gpio_num = gpio;
|
||||
strip_config.max_leds = 1;
|
||||
strip_config.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB;
|
||||
strip_config.led_pixel_format = LED_PIXEL_FORMAT_GRB;
|
||||
strip_config.led_model = LED_MODEL_WS2812;
|
||||
|
||||
led_strip_rmt_config_t rmt_config = {};
|
||||
|
||||
@@ -55,15 +55,13 @@ std::unique_ptr<Http> Ota::SetupHttp() {
|
||||
|
||||
auto network = board.GetNetwork();
|
||||
auto http = network->CreateHttp(0);
|
||||
auto user_agent = std::string(BOARD_NAME "/") + app_desc->version;
|
||||
http->SetHeader("Activation-Version", has_serial_number_ ? "2" : "1");
|
||||
http->SetHeader("Device-Id", SystemInfo::GetMacAddress().c_str());
|
||||
http->SetHeader("Client-Id", board.GetUuid());
|
||||
if (has_serial_number_) {
|
||||
http->SetHeader("Serial-Number", serial_number_.c_str());
|
||||
ESP_LOGI(TAG, "Setup HTTP, User-Agent: %s, Serial-Number: %s", user_agent.c_str(), serial_number_.c_str());
|
||||
}
|
||||
http->SetHeader("User-Agent", user_agent);
|
||||
http->SetHeader("User-Agent", std::string(BOARD_NAME "/") + app_desc->version);
|
||||
http->SetHeader("Accept-Language", Lang::CODE);
|
||||
http->SetHeader("Content-Type", "application/json");
|
||||
|
||||
|
||||
@@ -1,280 +0,0 @@
|
||||
"""
|
||||
实时AFSK解调器 - 基于Goertzel算法
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
from collections import deque
|
||||
|
||||
|
||||
class TraceGoertzel:
|
||||
"""实时Goertzel算法实现"""
|
||||
|
||||
def __init__(self, freq: float, n: int):
|
||||
"""
|
||||
初始化Goertzel算法
|
||||
|
||||
Args:
|
||||
freq: 归一化频率 (目标频率/采样频率)
|
||||
n: 窗口大小
|
||||
"""
|
||||
self.freq = freq
|
||||
self.n = n
|
||||
|
||||
# 预计算系数 - 与参考代码一致
|
||||
self.k = int(freq * n)
|
||||
self.w = 2.0 * np.pi * freq
|
||||
self.cw = np.cos(self.w)
|
||||
self.sw = np.sin(self.w)
|
||||
self.c = 2.0 * self.cw
|
||||
|
||||
# 初始化状态变量 - 使用deque存储最近两个值
|
||||
self.zs = deque([0.0, 0.0], maxlen=2)
|
||||
|
||||
def reset(self):
|
||||
"""重置算法状态"""
|
||||
self.zs.clear()
|
||||
self.zs.extend([0.0, 0.0])
|
||||
|
||||
def __call__(self, xs):
|
||||
"""
|
||||
处理一组采样点 - 与参考代码一致的接口
|
||||
|
||||
Args:
|
||||
xs: 采样点序列
|
||||
|
||||
Returns:
|
||||
计算出的振幅
|
||||
"""
|
||||
self.reset()
|
||||
for x in xs:
|
||||
z1, z2 = self.zs[-1], self.zs[-2] # Z[-1], Z[-2]
|
||||
z0 = x + self.c * z1 - z2 # S[n] = x[n] + C * S[n-1] - S[n-2]
|
||||
self.zs.append(float(z0)) # 更新序列
|
||||
return self.amp
|
||||
|
||||
@property
|
||||
def amp(self) -> float:
|
||||
"""计算当前振幅 - 与参考代码一致"""
|
||||
z1, z2 = self.zs[-1], self.zs[-2]
|
||||
ip = self.cw * z1 - z2
|
||||
qp = self.sw * z1
|
||||
return np.sqrt(ip**2 + qp**2) / (self.n / 2.0)
|
||||
|
||||
|
||||
class PairGoertzel:
|
||||
"""双频Goertzel解调器"""
|
||||
|
||||
def __init__(self, f_sample: int, f_space: int, f_mark: int,
|
||||
bit_rate: int, win_size: int):
|
||||
"""
|
||||
初始化双频解调器
|
||||
|
||||
Args:
|
||||
f_sample: 采样频率
|
||||
f_space: Space频率 (通常对应0)
|
||||
f_mark: Mark频率 (通常对应1)
|
||||
bit_rate: 比特率
|
||||
win_size: Goertzel窗口大小
|
||||
"""
|
||||
assert f_sample % bit_rate == 0, "采样频率必须是比特率的整数倍"
|
||||
|
||||
self.Fs = f_sample
|
||||
self.F0 = f_space
|
||||
self.F1 = f_mark
|
||||
self.bit_rate = bit_rate
|
||||
self.n_per_bit = int(f_sample // bit_rate) # 每个比特的采样点数
|
||||
|
||||
# 计算归一化频率
|
||||
f1 = f_mark / f_sample
|
||||
f0 = f_space / f_sample
|
||||
|
||||
# 初始化Goertzel算法
|
||||
self.g0 = TraceGoertzel(freq=f0, n=win_size)
|
||||
self.g1 = TraceGoertzel(freq=f1, n=win_size)
|
||||
|
||||
# 输入缓冲区
|
||||
self.in_buffer = deque(maxlen=win_size)
|
||||
self.out_count = 0
|
||||
|
||||
print(f"PairGoertzel initialized: f0={f0:.6f}, f1={f1:.6f}, win_size={win_size}, n_per_bit={self.n_per_bit}")
|
||||
|
||||
def __call__(self, s: float):
|
||||
"""
|
||||
处理单个采样点 - 与参考代码一致的接口
|
||||
|
||||
Args:
|
||||
s: 采样点值
|
||||
|
||||
Returns:
|
||||
(amp0, amp1, p1_prob) - 空间频率振幅,标记频率振幅,标记概率
|
||||
"""
|
||||
self.in_buffer.append(s)
|
||||
self.out_count += 1
|
||||
|
||||
amp0, amp1, p1_prob = 0, 0, None
|
||||
|
||||
# 每个比特周期输出一次结果
|
||||
if self.out_count >= self.n_per_bit:
|
||||
amp0 = self.g0(self.in_buffer) # 计算space频率振幅
|
||||
amp1 = self.g1(self.in_buffer) # 计算mark频率振幅
|
||||
p1_prob = amp1 / (amp0 + amp1 + 1e-8) # 计算mark概率
|
||||
self.out_count = 0
|
||||
|
||||
return amp0, amp1, p1_prob
|
||||
|
||||
|
||||
class RealTimeAFSKDecoder:
|
||||
"""实时AFSK解码器 - 基于起始帧触发"""
|
||||
|
||||
def __init__(self, f_sample: int = 16000, mark_freq: int = 1800,
|
||||
space_freq: int = 1500, bitrate: int = 100,
|
||||
s_goertzel: int = 9, threshold: float = 0.5):
|
||||
"""
|
||||
初始化实时AFSK解码器
|
||||
|
||||
Args:
|
||||
f_sample: 采样频率
|
||||
mark_freq: Mark频率
|
||||
space_freq: Space频率
|
||||
bitrate: 比特率
|
||||
s_goertzel: Goertzel窗口大小系数 (win_size = f_sample // mark_freq * s_goertzel)
|
||||
threshold: 判决门限
|
||||
"""
|
||||
self.f_sample = f_sample
|
||||
self.mark_freq = mark_freq
|
||||
self.space_freq = space_freq
|
||||
self.bitrate = bitrate
|
||||
self.threshold = threshold
|
||||
|
||||
# 计算窗口大小 - 与参考代码一致
|
||||
win_size = int(f_sample / mark_freq * s_goertzel)
|
||||
|
||||
# 初始化解调器
|
||||
self.demodulator = PairGoertzel(f_sample, space_freq, mark_freq,
|
||||
bitrate, win_size)
|
||||
|
||||
# 帧定义 - 与参考代码一致
|
||||
self.start_bytes = b'\x01\x02'
|
||||
self.end_bytes = b'\x03\x04'
|
||||
self.start_bits = "".join(format(int(x), '08b') for x in self.start_bytes)
|
||||
self.end_bits = "".join(format(int(x), '08b') for x in self.end_bytes)
|
||||
|
||||
# 状态机
|
||||
self.state = "idle" # idle / entering
|
||||
|
||||
# 存储解调结果
|
||||
self.buffer_prelude:deque = deque(maxlen=len(self.start_bits)) # 判断是否启动
|
||||
self.indicators = [] # 存储概率序列
|
||||
self.signal_bits = "" # 存储比特序列
|
||||
self.text_cache = ""
|
||||
|
||||
# 解码结果
|
||||
self.decoded_messages = []
|
||||
self.total_bits_received = 0
|
||||
|
||||
print(f"Decoder initialized: win_size={win_size}")
|
||||
print(f"Start frame: {self.start_bits} (from {self.start_bytes.hex()})")
|
||||
print(f"End frame: {self.end_bits} (from {self.end_bytes.hex()})")
|
||||
|
||||
def process_audio(self, samples: np.array) -> str:
|
||||
"""
|
||||
处理音频数据并返回解码文本
|
||||
|
||||
Args:
|
||||
audio_data: 音频字节数据 (16-bit PCM)
|
||||
|
||||
Returns:
|
||||
新解码的文本
|
||||
"""
|
||||
new_text = ""
|
||||
# 逐个处理采样点
|
||||
for sample in samples:
|
||||
amp0, amp1, p1_prob = self.demodulator(sample)
|
||||
# 如果有概率输出,记录并判决
|
||||
if p1_prob is not None:
|
||||
bit = '1' if p1_prob > self.threshold else '0'
|
||||
match self.state:
|
||||
case "idle":
|
||||
self.buffer_prelude.append(bit)
|
||||
pass
|
||||
case "entering":
|
||||
self.buffer_prelude.append(bit)
|
||||
self.signal_bits += bit
|
||||
self.total_bits_received += 1
|
||||
case _:
|
||||
pass
|
||||
self.indicators.append(p1_prob)
|
||||
|
||||
# 检查状态机
|
||||
if self.state == "idle" and "".join(self.buffer_prelude) == self.start_bits:
|
||||
self.state = "entering"
|
||||
self.text_cache = ""
|
||||
self.signal_bits = "" # 清空比特序列
|
||||
self.buffer_prelude.clear()
|
||||
elif self.state == "entering" and ("".join(self.buffer_prelude) == self.end_bits or len(self.signal_bits) >= 256):
|
||||
self.state = "idle"
|
||||
self.buffer_prelude.clear()
|
||||
|
||||
# 每收集一定数量的比特后尝试解码
|
||||
if len(self.signal_bits) >= 8:
|
||||
text = self._decode_bits_to_text(self.signal_bits)
|
||||
if len(text) > len(self.text_cache):
|
||||
new_text = text[len(self.text_cache) - len(text):]
|
||||
self.text_cache = text
|
||||
return new_text
|
||||
|
||||
def _decode_bits_to_text(self, bits: str) -> str:
|
||||
"""
|
||||
将比特串解码为文本
|
||||
|
||||
Args:
|
||||
bits: 比特串
|
||||
|
||||
Returns:
|
||||
解码出的文本
|
||||
"""
|
||||
if len(bits) < 8:
|
||||
return ""
|
||||
|
||||
decoded_text = ""
|
||||
byte_count = len(bits) // 8
|
||||
|
||||
for i in range(byte_count):
|
||||
# 提取8位
|
||||
byte_bits = bits[i*8:(i+1)*8]
|
||||
|
||||
# 位转字节
|
||||
byte_val = int(byte_bits, 2)
|
||||
|
||||
# 尝试解码为ASCII字符
|
||||
if 32 <= byte_val <= 126: # 可打印ASCII字符
|
||||
decoded_text += chr(byte_val)
|
||||
elif byte_val == 0: # NULL字符,忽略
|
||||
continue
|
||||
else:
|
||||
# 非可打印字符pass,以十六进制显示
|
||||
pass
|
||||
# decoded_text += f"\\x{byte_val:02X}"
|
||||
|
||||
return decoded_text
|
||||
|
||||
def clear(self):
|
||||
"""清空解码状态"""
|
||||
self.indicators = []
|
||||
self.signal_bits = ""
|
||||
self.decoded_messages = []
|
||||
self.total_bits_received = 0
|
||||
print("解码器状态已清空")
|
||||
|
||||
def get_stats(self) -> dict:
|
||||
"""获取解码统计信息"""
|
||||
return {
|
||||
'prelude_bits': "".join(self.buffer_prelude),
|
||||
"state": self.state,
|
||||
'total_chars': sum(len(msg) for msg in self.text_cache),
|
||||
'buffer_bits': len(self.signal_bits),
|
||||
'mark_freq': self.mark_freq,
|
||||
'space_freq': self.space_freq,
|
||||
'bitrate': self.bitrate,
|
||||
'threshold': self.threshold,
|
||||
}
|
||||
@@ -1,444 +0,0 @@
|
||||
import sys
|
||||
import numpy as np
|
||||
import asyncio
|
||||
import wave
|
||||
from collections import deque
|
||||
import qasync
|
||||
|
||||
import matplotlib
|
||||
matplotlib.use('qtagg')
|
||||
|
||||
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
|
||||
from matplotlib.backends.backend_qtagg import NavigationToolbar2QT as NavigationToolbar # noqa: F401
|
||||
from matplotlib.figure import Figure
|
||||
|
||||
from PyQt6.QtWidgets import (QApplication, QMainWindow, QVBoxLayout, QWidget,
|
||||
QHBoxLayout, QLineEdit, QPushButton, QLabel, QTextEdit)
|
||||
from PyQt6.QtCore import QTimer
|
||||
|
||||
# 导入解码器
|
||||
from demod import RealTimeAFSKDecoder
|
||||
|
||||
|
||||
class UDPServerProtocol(asyncio.DatagramProtocol):
|
||||
"""UDP服务器协议类"""
|
||||
def __init__(self, data_queue):
|
||||
self.client_address = None
|
||||
self.data_queue: deque = data_queue
|
||||
|
||||
def connection_made(self, transport):
|
||||
self.transport = transport
|
||||
|
||||
def datagram_received(self, data, addr):
|
||||
# 如果还没有客户端地址,记录第一个连接的客户端
|
||||
if self.client_address is None:
|
||||
self.client_address = addr
|
||||
print(f"接受来自 {addr} 的连接")
|
||||
|
||||
# 只处理来自已记录客户端的数据
|
||||
if addr == self.client_address:
|
||||
# 将接收到的音频数据添加到队列
|
||||
self.data_queue.extend(data)
|
||||
else:
|
||||
print(f"忽略来自未知地址 {addr} 的数据")
|
||||
|
||||
|
||||
class MatplotlibWidget(QWidget):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
|
||||
# 创建 Matplotlib 的 Figure 对象
|
||||
self.figure = Figure()
|
||||
|
||||
# 创建 FigureCanvas 对象,它是 Figure 的 QWidget 容器
|
||||
self.canvas = FigureCanvas(self.figure)
|
||||
|
||||
# 创建 Matplotlib 的导航工具栏
|
||||
# self.toolbar = NavigationToolbar(self.canvas, self)
|
||||
self.toolbar = None
|
||||
|
||||
# 创建布局
|
||||
layout = QVBoxLayout()
|
||||
layout.addWidget(self.toolbar)
|
||||
layout.addWidget(self.canvas)
|
||||
self.setLayout(layout)
|
||||
|
||||
# 初始化音频数据参数
|
||||
self.freq = 16000 # 采样频率
|
||||
self.time_window = 20 # 显示时间窗口
|
||||
self.wave_data = deque(maxlen=self.freq * self.time_window * 2) # 缓冲队列, 用于分发计算/绘图
|
||||
self.signals = deque(maxlen=self.freq * self.time_window) # 双端队列存储信号数据
|
||||
|
||||
# 创建包含两个子图的画布
|
||||
self.ax1 = self.figure.add_subplot(2, 1, 1)
|
||||
self.ax2 = self.figure.add_subplot(2, 1, 2)
|
||||
|
||||
# 时域子图
|
||||
self.ax1.set_title('Real-time Audio Waveform')
|
||||
self.ax1.set_xlabel('Sample Index')
|
||||
self.ax1.set_ylabel('Amplitude')
|
||||
self.line_time, = self.ax1.plot([], [])
|
||||
self.ax1.grid(True, alpha=0.3)
|
||||
|
||||
# 频域子图
|
||||
self.ax2.set_title('Real-time Frequency Spectrum')
|
||||
self.ax2.set_xlabel('Frequency (Hz)')
|
||||
self.ax2.set_ylabel('Magnitude')
|
||||
self.line_freq, = self.ax2.plot([], [])
|
||||
self.ax2.grid(True, alpha=0.3)
|
||||
|
||||
self.figure.tight_layout()
|
||||
|
||||
# 定时器用于更新图表
|
||||
self.timer = QTimer(self)
|
||||
self.timer.setInterval(100) # 100毫秒更新一次
|
||||
self.timer.timeout.connect(self.update_plot)
|
||||
|
||||
# 初始化AFSK解码器
|
||||
self.decoder = RealTimeAFSKDecoder(
|
||||
f_sample=self.freq,
|
||||
mark_freq=1800,
|
||||
space_freq=1500,
|
||||
bitrate=100,
|
||||
s_goertzel=9,
|
||||
threshold=0.5
|
||||
)
|
||||
|
||||
# 解码结果回调
|
||||
self.decode_callback = None
|
||||
|
||||
def start_plotting(self):
|
||||
"""开始绘图"""
|
||||
self.timer.start()
|
||||
|
||||
def stop_plotting(self):
|
||||
"""停止绘图"""
|
||||
self.timer.stop()
|
||||
|
||||
def update_plot(self):
|
||||
"""更新绘图数据"""
|
||||
if len(self.wave_data) >= 2:
|
||||
# 进行实时解码
|
||||
# 获取最新的音频数据进行解码
|
||||
even = len(self.wave_data) // 2 * 2
|
||||
print(f"length of wave_data: {len(self.wave_data)}")
|
||||
drained = [self.wave_data.popleft() for _ in range(even)]
|
||||
signal = np.frombuffer(bytearray(drained), dtype='<i2') / 32768
|
||||
decoded_text_new = self.decoder.process_audio(signal) # 处理新增信号, 返回全量解码文本
|
||||
if decoded_text_new and self.decode_callback:
|
||||
self.decode_callback(decoded_text_new)
|
||||
self.signals.extend(signal.tolist()) # 将波形数据添加到绘图数据
|
||||
|
||||
if len(self.signals) > 0:
|
||||
# 只显示最近的一段数据,避免图表过于密集
|
||||
signal = np.array(self.signals)
|
||||
max_samples = min(len(signal), self.freq * self.time_window)
|
||||
if len(signal) > max_samples:
|
||||
signal = signal[-max_samples:]
|
||||
|
||||
# 更新时域图
|
||||
x = np.arange(len(signal))
|
||||
self.line_time.set_data(x, signal)
|
||||
|
||||
# 自动调整时域坐标轴范围
|
||||
if len(signal) > 0:
|
||||
self.ax1.set_xlim(0, len(signal))
|
||||
y_min, y_max = np.min(signal), np.max(signal)
|
||||
if y_min != y_max:
|
||||
margin = (y_max - y_min) * 0.1
|
||||
self.ax1.set_ylim(y_min - margin, y_max + margin)
|
||||
else:
|
||||
self.ax1.set_ylim(-1, 1)
|
||||
|
||||
# 计算频谱(短时离散傅立叶变换)
|
||||
if len(signal) > 1:
|
||||
# 计算FFT
|
||||
fft_signal = np.abs(np.fft.fft(signal))
|
||||
frequencies = np.fft.fftfreq(len(signal), 1/self.freq)
|
||||
|
||||
# 只取正频率部分
|
||||
positive_freq_idx = frequencies >= 0
|
||||
freq_positive = frequencies[positive_freq_idx]
|
||||
fft_positive = fft_signal[positive_freq_idx]
|
||||
|
||||
# 更新频域图
|
||||
self.line_freq.set_data(freq_positive, fft_positive)
|
||||
|
||||
# 自动调整频域坐标轴范围
|
||||
if len(fft_positive) > 0:
|
||||
# 限制频率显示范围到0-4000Hz,避免过于密集
|
||||
max_freq_show = min(4000, self.freq // 2)
|
||||
freq_mask = freq_positive <= max_freq_show
|
||||
if np.any(freq_mask):
|
||||
self.ax2.set_xlim(0, max_freq_show)
|
||||
fft_masked = fft_positive[freq_mask]
|
||||
if len(fft_masked) > 0:
|
||||
fft_max = np.max(fft_masked)
|
||||
if fft_max > 0:
|
||||
self.ax2.set_ylim(0, fft_max * 1.1)
|
||||
else:
|
||||
self.ax2.set_ylim(0, 1)
|
||||
|
||||
self.canvas.draw()
|
||||
|
||||
|
||||
class MainWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Acoustic Check")
|
||||
self.setGeometry(100, 100, 1000, 800)
|
||||
|
||||
# 主窗口部件
|
||||
main_widget = QWidget()
|
||||
self.setCentralWidget(main_widget)
|
||||
|
||||
# 主布局
|
||||
main_layout = QVBoxLayout(main_widget)
|
||||
|
||||
# 绘图区域
|
||||
self.matplotlib_widget = MatplotlibWidget()
|
||||
main_layout.addWidget(self.matplotlib_widget)
|
||||
|
||||
# 控制面板
|
||||
control_panel = QWidget()
|
||||
control_layout = QHBoxLayout(control_panel)
|
||||
|
||||
# 监听地址和端口输入
|
||||
control_layout.addWidget(QLabel("监听地址:"))
|
||||
self.address_input = QLineEdit("0.0.0.0")
|
||||
self.address_input.setFixedWidth(120)
|
||||
control_layout.addWidget(self.address_input)
|
||||
|
||||
control_layout.addWidget(QLabel("端口:"))
|
||||
self.port_input = QLineEdit("8000")
|
||||
self.port_input.setFixedWidth(80)
|
||||
control_layout.addWidget(self.port_input)
|
||||
|
||||
# 监听按钮
|
||||
self.listen_button = QPushButton("开始监听")
|
||||
self.listen_button.clicked.connect(self.toggle_listening)
|
||||
control_layout.addWidget(self.listen_button)
|
||||
|
||||
# 状态标签
|
||||
self.status_label = QLabel("状态: 未连接")
|
||||
control_layout.addWidget(self.status_label)
|
||||
|
||||
# 数据统计标签
|
||||
self.data_label = QLabel("接收数据: 0 bytes")
|
||||
control_layout.addWidget(self.data_label)
|
||||
|
||||
# 保存按钮
|
||||
self.save_button = QPushButton("保存音频")
|
||||
self.save_button.clicked.connect(self.save_audio)
|
||||
self.save_button.setEnabled(False)
|
||||
control_layout.addWidget(self.save_button)
|
||||
|
||||
control_layout.addStretch() # 添加弹性空间
|
||||
|
||||
main_layout.addWidget(control_panel)
|
||||
|
||||
# 解码显示区域
|
||||
decode_panel = QWidget()
|
||||
decode_layout = QVBoxLayout(decode_panel)
|
||||
|
||||
# 解码标题
|
||||
decode_title = QLabel("实时AFSK解码结果:")
|
||||
decode_title.setStyleSheet("font-weight: bold; font-size: 14px;")
|
||||
decode_layout.addWidget(decode_title)
|
||||
|
||||
# 解码文本显示
|
||||
self.decode_text = QTextEdit()
|
||||
self.decode_text.setMaximumHeight(150)
|
||||
self.decode_text.setReadOnly(True)
|
||||
self.decode_text.setStyleSheet("font-family: 'Courier New', monospace; font-size: 12px;")
|
||||
decode_layout.addWidget(self.decode_text)
|
||||
|
||||
# 解码控制按钮
|
||||
decode_control_layout = QHBoxLayout()
|
||||
|
||||
# 清空按钮
|
||||
self.clear_decode_button = QPushButton("清空解码")
|
||||
self.clear_decode_button.clicked.connect(self.clear_decode_text)
|
||||
decode_control_layout.addWidget(self.clear_decode_button)
|
||||
|
||||
# 解码统计标签
|
||||
self.decode_stats_label = QLabel("解码统计: 0 bits, 0 chars")
|
||||
decode_control_layout.addWidget(self.decode_stats_label)
|
||||
|
||||
decode_control_layout.addStretch()
|
||||
decode_layout.addLayout(decode_control_layout)
|
||||
|
||||
main_layout.addWidget(decode_panel)
|
||||
|
||||
# 设置解码回调
|
||||
self.matplotlib_widget.decode_callback = self.on_decode_text
|
||||
|
||||
# UDP相关属性
|
||||
self.udp_transport = None
|
||||
self.is_listening = False
|
||||
|
||||
# 数据统计定时器
|
||||
self.stats_timer = QTimer(self)
|
||||
self.stats_timer.setInterval(1000) # 每秒更新一次统计
|
||||
self.stats_timer.timeout.connect(self.update_stats)
|
||||
|
||||
def on_decode_text(self, new_text: str):
|
||||
"""解码文本回调"""
|
||||
if new_text:
|
||||
# 添加新解码的文本
|
||||
current_text = self.decode_text.toPlainText()
|
||||
updated_text = current_text + new_text
|
||||
|
||||
# 限制文本长度,保留最新的1000个字符
|
||||
if len(updated_text) > 1000:
|
||||
updated_text = updated_text[-1000:]
|
||||
|
||||
self.decode_text.setPlainText(updated_text)
|
||||
|
||||
# 滚动到底部
|
||||
cursor = self.decode_text.textCursor()
|
||||
cursor.movePosition(cursor.MoveOperation.End)
|
||||
self.decode_text.setTextCursor(cursor)
|
||||
|
||||
def clear_decode_text(self):
|
||||
"""清空解码文本"""
|
||||
self.decode_text.clear()
|
||||
if hasattr(self.matplotlib_widget, 'decoder'):
|
||||
self.matplotlib_widget.decoder.clear()
|
||||
self.decode_stats_label.setText("解码统计: 0 bits, 0 chars")
|
||||
|
||||
def update_decode_stats(self):
|
||||
"""更新解码统计"""
|
||||
if hasattr(self.matplotlib_widget, 'decoder'):
|
||||
stats = self.matplotlib_widget.decoder.get_stats()
|
||||
stats_text = (
|
||||
f"前置: {stats['prelude_bits']} , 已接收{stats['total_chars']} chars, "
|
||||
f"缓冲: {stats['buffer_bits']} bits, 状态: {stats['state']}"
|
||||
)
|
||||
self.decode_stats_label.setText(stats_text)
|
||||
|
||||
def toggle_listening(self):
|
||||
"""切换监听状态"""
|
||||
if not self.is_listening:
|
||||
self.start_listening()
|
||||
else:
|
||||
self.stop_listening()
|
||||
|
||||
async def start_listening_async(self):
|
||||
"""异步启动UDP监听"""
|
||||
try:
|
||||
address = self.address_input.text().strip()
|
||||
port = int(self.port_input.text().strip())
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
self.udp_transport, protocol = await loop.create_datagram_endpoint(
|
||||
lambda: UDPServerProtocol(self.matplotlib_widget.wave_data),
|
||||
local_addr=(address, port)
|
||||
)
|
||||
|
||||
self.status_label.setText(f"状态: 监听中 ({address}:{port})")
|
||||
print(f"UDP服务器启动, 监听 {address}:{port}")
|
||||
|
||||
except Exception as e:
|
||||
self.status_label.setText(f"状态: 启动失败 - {str(e)}")
|
||||
print(f"UDP服务器启动失败: {e}")
|
||||
self.is_listening = False
|
||||
self.listen_button.setText("开始监听")
|
||||
self.address_input.setEnabled(True)
|
||||
self.port_input.setEnabled(True)
|
||||
|
||||
def start_listening(self):
|
||||
"""开始监听"""
|
||||
try:
|
||||
int(self.port_input.text().strip()) # 验证端口号格式
|
||||
except ValueError:
|
||||
self.status_label.setText("状态: 端口号必须是数字")
|
||||
return
|
||||
|
||||
self.is_listening = True
|
||||
self.listen_button.setText("停止监听")
|
||||
self.address_input.setEnabled(False)
|
||||
self.port_input.setEnabled(False)
|
||||
self.save_button.setEnabled(True)
|
||||
|
||||
# 清空数据队列
|
||||
self.matplotlib_widget.wave_data.clear()
|
||||
|
||||
# 启动绘图和统计更新
|
||||
self.matplotlib_widget.start_plotting()
|
||||
self.stats_timer.start()
|
||||
|
||||
# 异步启动UDP服务器
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.create_task(self.start_listening_async())
|
||||
|
||||
def stop_listening(self):
|
||||
"""停止监听"""
|
||||
self.is_listening = False
|
||||
self.listen_button.setText("开始监听")
|
||||
self.address_input.setEnabled(True)
|
||||
self.port_input.setEnabled(True)
|
||||
|
||||
# 停止UDP服务器
|
||||
if self.udp_transport:
|
||||
self.udp_transport.close()
|
||||
self.udp_transport = None
|
||||
|
||||
# 停止绘图和统计更新
|
||||
self.matplotlib_widget.stop_plotting()
|
||||
self.matplotlib_widget.wave_data.clear()
|
||||
self.stats_timer.stop()
|
||||
|
||||
self.status_label.setText("状态: 已停止")
|
||||
|
||||
def update_stats(self):
|
||||
"""更新数据统计"""
|
||||
data_size = len(self.matplotlib_widget.signals)
|
||||
self.data_label.setText(f"接收数据: {data_size} 采样")
|
||||
|
||||
# 更新解码统计
|
||||
self.update_decode_stats()
|
||||
|
||||
def save_audio(self):
|
||||
"""保存音频数据"""
|
||||
if len(self.matplotlib_widget.signals) > 0:
|
||||
try:
|
||||
signal_data = np.array(self.matplotlib_widget.signals)
|
||||
|
||||
# 保存为WAV文件
|
||||
with wave.open("received_audio.wav", "wb") as wf:
|
||||
wf.setnchannels(1) # 单声道
|
||||
wf.setsampwidth(2) # 采样宽度为2字节
|
||||
wf.setframerate(self.matplotlib_widget.freq) # 设置采样率
|
||||
wf.writeframes(signal_data.tobytes()) # 写入数据
|
||||
|
||||
self.status_label.setText("状态: 音频已保存为 received_audio.wav")
|
||||
print("音频已保存为 received_audio.wav")
|
||||
|
||||
except Exception as e:
|
||||
self.status_label.setText(f"状态: 保存失败 - {str(e)}")
|
||||
print(f"保存音频失败: {e}")
|
||||
else:
|
||||
self.status_label.setText("状态: 没有足够的数据可保存")
|
||||
|
||||
|
||||
async def main():
|
||||
"""异步主函数"""
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
# 设置异步事件循环
|
||||
loop = qasync.QEventLoop(app)
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
window = MainWindow()
|
||||
window.show()
|
||||
|
||||
try:
|
||||
with loop:
|
||||
await loop.run_forever()
|
||||
except KeyboardInterrupt:
|
||||
print("程序被用户中断")
|
||||
finally:
|
||||
# 确保清理资源
|
||||
if window.udp_transport:
|
||||
window.udp_transport.close()
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
音频实时监听与绘图系统主程序
|
||||
基于Qt GUI + Matplotlib + UDP接收 + AFSK解码字符串
|
||||
"""
|
||||
|
||||
import sys
|
||||
import asyncio
|
||||
from graphic import main
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
asyncio.run(main())
|
||||
except KeyboardInterrupt:
|
||||
print("程序被用户中断")
|
||||
except Exception as e:
|
||||
print(f"程序执行出错: {e}")
|
||||
sys.exit(1)
|
||||
@@ -1,23 +0,0 @@
|
||||
# 声波测试
|
||||
该gui用于测试接受小智设备通过`udp`回传的`pcm`转时域/频域, 可以保存窗口长度的声音, 用于判断噪音频率分布和测试声波传输ascii的准确度,
|
||||
|
||||
固件测试需要打开`USE_AUDIO_DEBUGGER`, 并设置好`AUDIO_DEBUG_UDP_SERVER`是本机地址.
|
||||
声波`demod`可以通过`sonic_wifi_config.html`或者上传至`PinMe`的[小智声波配网](https://iqf7jnhi.pinit.eth.limo)来输出声波测试
|
||||
|
||||
# 声波解码测试记录
|
||||
|
||||
> `✓`代表在I2S DIN接收原始PCM信号时就能成功解码, `△`代表需要降噪或额外操作可稳定解码, `X`代表降噪后效果也不好(可能能解部分但非常不稳定)。
|
||||
> 个别ADC需要I2C配置阶段做更精细的降噪调整, 由于设备不通用暂只按照boards内提供的config测试
|
||||
|
||||
| 设备 | ADC | MIC | 效果 | 备注 |
|
||||
| ---- | ---- | --- | --- | ---- |
|
||||
| bread-compact | INMP441 | 集成MEMEMIC | ✓ |
|
||||
| atk-dnesp32s3-box | ES8311 | | ✓ |
|
||||
| magiclick-2p5 | ES8311 | | ✓ |
|
||||
| lichuang-dev | ES7210 | | △ | 测试时需要关掉INPUT_REFERENCE
|
||||
| kevin-box-2 | ES7210 | | △ | 测试时需要关掉INPUT_REFERENCE
|
||||
| m5stack-core-s3 | ES7210 | | △ | 测试时需要关掉INPUT_REFERENCE
|
||||
| xmini-c3 | ES8311 | | △ | 需降噪
|
||||
| atoms3r-echo-base | ES8311 | | △ | 需降噪
|
||||
| atk-dnesp32s3-box0 | ES8311 | | X | 能接收且解码, 但是丢包率很高
|
||||
| movecall-moji-esp32s3 | ES8311 | | X | 能接收且解码, 但是丢包率很高
|
||||
@@ -1,4 +0,0 @@
|
||||
matplotlib==3.10.5
|
||||
numpy==2.3.2
|
||||
PyQt6==6.9.1
|
||||
qasync==0.27.1
|
||||
@@ -1,29 +0,0 @@
|
||||
# ogg_covertor 小智AI OGG 批量转换器
|
||||
|
||||
本脚本为OGG批量转换工具,支持将输入的音频文件转换为小智可使用的OGG格式
|
||||
基于Python第三方库`ffmpeg-python`实现
|
||||
支持OGG和音频之间的互转,响度调节等功能
|
||||
|
||||
# 创建并激活虚拟环境
|
||||
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv venv
|
||||
# 激活虚拟环境
|
||||
source venv/bin/activate # Mac/Linux
|
||||
venv\Scripts\activate # Windows
|
||||
```
|
||||
|
||||
# 安装依赖
|
||||
|
||||
请在虚拟环境中执行
|
||||
|
||||
```bash
|
||||
pip install ffmpeg-python
|
||||
```
|
||||
|
||||
# 运行脚本
|
||||
```bash
|
||||
python ogg_covertor.py
|
||||
```
|
||||
|
||||
@@ -1,230 +0,0 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk, filedialog, messagebox
|
||||
import os
|
||||
import threading
|
||||
import sys
|
||||
import ffmpeg
|
||||
|
||||
class AudioConverterApp:
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
master.title("小智AI OGG音频批量转换工具")
|
||||
master.geometry("680x600") # 调整窗口高度
|
||||
|
||||
# 初始化变量
|
||||
self.mode = tk.StringVar(value="audio_to_ogg")
|
||||
self.output_dir = tk.StringVar()
|
||||
self.output_dir.set(os.path.abspath("output"))
|
||||
self.enable_loudnorm = tk.BooleanVar(value=True)
|
||||
self.target_lufs = tk.DoubleVar(value=-16.0)
|
||||
|
||||
# 创建UI组件
|
||||
self.create_widgets()
|
||||
self.redirect_output()
|
||||
|
||||
def create_widgets(self):
|
||||
# 模式选择
|
||||
mode_frame = ttk.LabelFrame(self.master, text="转换模式")
|
||||
mode_frame.grid(row=0, column=0, padx=10, pady=5, sticky="ew")
|
||||
|
||||
ttk.Radiobutton(mode_frame, text="音频转到OGG", variable=self.mode,
|
||||
value="audio_to_ogg", command=self.toggle_settings,
|
||||
width=12).grid(row=0, column=0, padx=5)
|
||||
ttk.Radiobutton(mode_frame, text="OGG转回音频", variable=self.mode,
|
||||
value="ogg_to_audio", command=self.toggle_settings,
|
||||
width=12).grid(row=0, column=1, padx=5)
|
||||
|
||||
# 响度设置
|
||||
self.loudnorm_frame = ttk.Frame(self.master)
|
||||
self.loudnorm_frame.grid(row=1, column=0, padx=10, pady=5, sticky="ew")
|
||||
|
||||
ttk.Checkbutton(self.loudnorm_frame, text="启用响度调整",
|
||||
variable=self.enable_loudnorm, width=15
|
||||
).grid(row=0, column=0, padx=2)
|
||||
ttk.Entry(self.loudnorm_frame, textvariable=self.target_lufs,
|
||||
width=6).grid(row=0, column=1, padx=2)
|
||||
ttk.Label(self.loudnorm_frame, text="LUFS").grid(row=0, column=2, padx=2)
|
||||
|
||||
# 文件选择
|
||||
file_frame = ttk.LabelFrame(self.master, text="输入文件")
|
||||
file_frame.grid(row=2, column=0, padx=10, pady=5, sticky="nsew")
|
||||
|
||||
# 文件操作按钮
|
||||
ttk.Button(file_frame, text="选择文件", command=self.select_files,
|
||||
width=12).grid(row=0, column=0, padx=5, pady=2)
|
||||
ttk.Button(file_frame, text="移除选中", command=self.remove_selected,
|
||||
width=12).grid(row=0, column=1, padx=5, pady=2)
|
||||
ttk.Button(file_frame, text="清空列表", command=self.clear_files,
|
||||
width=12).grid(row=0, column=2, padx=5, pady=2)
|
||||
|
||||
# 文件列表(使用Treeview)
|
||||
self.tree = ttk.Treeview(file_frame, columns=("selected", "filename"),
|
||||
show="headings", height=8)
|
||||
self.tree.heading("selected", text="选中", anchor=tk.W)
|
||||
self.tree.heading("filename", text="文件名", anchor=tk.W)
|
||||
self.tree.column("selected", width=60, anchor=tk.W)
|
||||
self.tree.column("filename", width=600, anchor=tk.W)
|
||||
self.tree.grid(row=1, column=0, columnspan=3, sticky="nsew", padx=5, pady=2)
|
||||
self.tree.bind("<ButtonRelease-1>", self.on_tree_click)
|
||||
|
||||
# 输出目录
|
||||
output_frame = ttk.LabelFrame(self.master, text="输出目录")
|
||||
output_frame.grid(row=3, column=0, padx=10, pady=5, sticky="ew")
|
||||
|
||||
ttk.Entry(output_frame, textvariable=self.output_dir, width=60
|
||||
).grid(row=0, column=0, padx=5, sticky="ew")
|
||||
ttk.Button(output_frame, text="浏览", command=self.select_output_dir,
|
||||
width=8).grid(row=0, column=1, padx=5)
|
||||
|
||||
# 转换按钮区域
|
||||
button_frame = ttk.Frame(self.master)
|
||||
button_frame.grid(row=4, column=0, padx=10, pady=10, sticky="ew")
|
||||
|
||||
ttk.Button(button_frame, text="转换全部文件", command=lambda: self.start_conversion(True),
|
||||
width=15).pack(side=tk.LEFT, padx=5)
|
||||
ttk.Button(button_frame, text="转换选中文件", command=lambda: self.start_conversion(False),
|
||||
width=15).pack(side=tk.LEFT, padx=5)
|
||||
|
||||
# 日志区域
|
||||
log_frame = ttk.LabelFrame(self.master, text="日志")
|
||||
log_frame.grid(row=5, column=0, padx=10, pady=5, sticky="nsew")
|
||||
|
||||
self.log_text = tk.Text(log_frame, height=14, width=80)
|
||||
self.log_text.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
# 配置布局权重
|
||||
self.master.columnconfigure(0, weight=1)
|
||||
self.master.rowconfigure(2, weight=1)
|
||||
self.master.rowconfigure(5, weight=3)
|
||||
file_frame.columnconfigure(0, weight=1)
|
||||
file_frame.rowconfigure(1, weight=1)
|
||||
|
||||
def toggle_settings(self):
|
||||
if self.mode.get() == "audio_to_ogg":
|
||||
self.loudnorm_frame.grid()
|
||||
else:
|
||||
self.loudnorm_frame.grid_remove()
|
||||
|
||||
def select_files(self):
|
||||
file_types = [
|
||||
("音频文件", "*.wav *.mogg *.ogg *.flac") if self.mode.get() == "audio_to_ogg"
|
||||
else ("ogg文件", "*.ogg")
|
||||
]
|
||||
|
||||
files = filedialog.askopenfilenames(filetypes=file_types)
|
||||
for f in files:
|
||||
self.tree.insert("", tk.END, values=("[ ]", os.path.basename(f)), tags=(f,))
|
||||
|
||||
def on_tree_click(self, event):
|
||||
"""处理复选框点击事件"""
|
||||
region = self.tree.identify("region", event.x, event.y)
|
||||
if region == "cell":
|
||||
col = self.tree.identify_column(event.x)
|
||||
item = self.tree.identify_row(event.y)
|
||||
if col == "#1": # 点击的是选中列
|
||||
current_val = self.tree.item(item, "values")[0]
|
||||
new_val = "[√]" if current_val == "[ ]" else "[ ]"
|
||||
self.tree.item(item, values=(new_val, self.tree.item(item, "values")[1]))
|
||||
|
||||
def remove_selected(self):
|
||||
"""移除选中的文件"""
|
||||
to_remove = []
|
||||
for item in self.tree.get_children():
|
||||
if self.tree.item(item, "values")[0] == "[√]":
|
||||
to_remove.append(item)
|
||||
for item in reversed(to_remove):
|
||||
self.tree.delete(item)
|
||||
|
||||
def clear_files(self):
|
||||
"""清空所有文件"""
|
||||
for item in self.tree.get_children():
|
||||
self.tree.delete(item)
|
||||
|
||||
def select_output_dir(self):
|
||||
path = filedialog.askdirectory()
|
||||
if path:
|
||||
self.output_dir.set(path)
|
||||
|
||||
def redirect_output(self):
|
||||
class StdoutRedirector:
|
||||
def __init__(self, text_widget):
|
||||
self.text_widget = text_widget
|
||||
self.original_stdout = sys.stdout
|
||||
|
||||
def write(self, message):
|
||||
self.text_widget.insert(tk.END, message)
|
||||
self.text_widget.see(tk.END)
|
||||
self.original_stdout.write(message)
|
||||
|
||||
def flush(self):
|
||||
self.original_stdout.flush()
|
||||
|
||||
sys.stdout = StdoutRedirector(self.log_text)
|
||||
|
||||
def start_conversion(self, convert_all):
|
||||
"""开始转换"""
|
||||
input_files = []
|
||||
for item in self.tree.get_children():
|
||||
if convert_all or self.tree.item(item, "values")[0] == "[√]":
|
||||
input_files.append(self.tree.item(item, "tags")[0])
|
||||
|
||||
if not input_files:
|
||||
msg = "没有找到可转换的文件" if convert_all else "没有选中任何文件"
|
||||
messagebox.showwarning("警告", msg)
|
||||
return
|
||||
|
||||
os.makedirs(self.output_dir.get(), exist_ok=True)
|
||||
|
||||
try:
|
||||
if self.mode.get() == "audio_to_ogg":
|
||||
target_lufs = self.target_lufs.get() if self.enable_loudnorm.get() else None
|
||||
thread = threading.Thread(target=self.convert_audio_to_ogg, args=(target_lufs, input_files))
|
||||
else:
|
||||
thread = threading.Thread(target=self.convert_ogg_to_audio, args=(input_files,))
|
||||
|
||||
thread.start()
|
||||
except Exception as e:
|
||||
print(f"转换初始化失败: {str(e)}")
|
||||
|
||||
def convert_audio_to_ogg(self, target_lufs, input_files):
|
||||
"""音频转到ogg转换逻辑"""
|
||||
for input_path in input_files:
|
||||
try:
|
||||
filename = os.path.basename(input_path)
|
||||
base_name = os.path.splitext(filename)[0]
|
||||
output_path = os.path.join(self.output_dir.get(), f"{base_name}.ogg")
|
||||
|
||||
print(f"正在转换: {filename}")
|
||||
(
|
||||
ffmpeg
|
||||
.input(input_path)
|
||||
.output(output_path, acodec='libopus', audio_bitrate='16k', ac=1, ar=16000, frame_duration=60)
|
||||
.run(overwrite_output=True)
|
||||
)
|
||||
print(f"转换成功: {filename}\n")
|
||||
except Exception as e:
|
||||
print(f"转换失败: {str(e)}\n")
|
||||
|
||||
def convert_ogg_to_audio(self, input_files):
|
||||
"""ogg转回音频转换逻辑"""
|
||||
for input_path in input_files:
|
||||
try:
|
||||
filename = os.path.basename(input_path)
|
||||
base_name = os.path.splitext(filename)[0]
|
||||
output_path = os.path.join(self.output_dir.get(), f"{base_name}.ogg")
|
||||
|
||||
print(f"正在转换: {filename}")
|
||||
(
|
||||
ffmpeg
|
||||
.input(input_path)
|
||||
.output(output_path, acodec='libopus', audio_bitrate='16k', ac=1, ar=16000, frame_duration=60)
|
||||
.run(overwrite_output=True)
|
||||
)
|
||||
print(f"转换成功: {filename}\n")
|
||||
except Exception as e:
|
||||
print(f"转换失败: {str(e)}\n")
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
app = AudioConverterApp(root)
|
||||
root.mainloop()
|
||||
@@ -73,80 +73,40 @@ def get_board_name(folder):
|
||||
return basename.split("_")[1]
|
||||
raise Exception(f"Unknown board name: {basename}")
|
||||
|
||||
def find_app_partition(data):
|
||||
partition_begin = 0x8000
|
||||
partition_end = partition_begin + 0x4000
|
||||
# find the first parition with type 0x00
|
||||
for i in range(partition_begin, partition_end, 0x20):
|
||||
# magic is aa 50
|
||||
if data[i] == 0xaa and data[i + 1] == 0x50:
|
||||
# type is app
|
||||
if data[i + 2] == 0x00:
|
||||
# read offset and size
|
||||
offset = struct.unpack("<I", data[i + 4:i + 8])[0]
|
||||
size = struct.unpack("<I", data[i + 8:i + 12])[0]
|
||||
# then 16 bytes is label
|
||||
label = data[i + 12:i + 28].decode("utf-8").strip('\0')
|
||||
print(f"found app partition at 0x{i:08x}, offset: 0x{offset:08x}, size: 0x{size:08x}, label: {label}")
|
||||
return {
|
||||
"offset": offset,
|
||||
"size": size,
|
||||
"label": label,
|
||||
}
|
||||
return None
|
||||
|
||||
def read_binary(dir_path):
|
||||
merged_bin_path = os.path.join(dir_path, "merged-binary.bin")
|
||||
merged_bin_data = open(merged_bin_path, "rb").read()
|
||||
|
||||
# find app partition
|
||||
app_partition = find_app_partition(merged_bin_data)
|
||||
if app_partition is None:
|
||||
print("no app partition found")
|
||||
return
|
||||
app_data = merged_bin_data[app_partition["offset"]:app_partition["offset"] + app_partition["size"]]
|
||||
# check magic
|
||||
if app_data[0] != 0xE9:
|
||||
print("not a valid image")
|
||||
if merged_bin_data[0x100000] == 0xE9:
|
||||
data = merged_bin_data[0x100000:]
|
||||
elif merged_bin_data[0x200000] == 0xE9:
|
||||
data = merged_bin_data[0x200000:]
|
||||
elif merged_bin_data[0xe0000] == 0xE9:
|
||||
data = merged_bin_data[0xe0000:]
|
||||
else:
|
||||
print(dir_path, "is not a valid image")
|
||||
return
|
||||
# get flash size
|
||||
flash_size = get_flash_size(app_data[0x3] >> 4)
|
||||
chip_id = get_chip_id_string(app_data[0xC])
|
||||
flash_size = get_flash_size(data[0x3] >> 4)
|
||||
chip_id = get_chip_id_string(data[0xC])
|
||||
# get segments
|
||||
segment_count = app_data[0x1]
|
||||
segment_count = data[0x1]
|
||||
segments = []
|
||||
offset = 0x18
|
||||
image_size = 0x18
|
||||
for i in range(segment_count):
|
||||
segment_size = struct.unpack("<I", app_data[offset + 4:offset + 8])[0]
|
||||
image_size += 8 + segment_size
|
||||
segment_size = struct.unpack("<I", data[offset + 4:offset + 8])[0]
|
||||
offset += 8
|
||||
segment_data = app_data[offset:offset + segment_size]
|
||||
segment_data = data[offset:offset + segment_size]
|
||||
offset += segment_size
|
||||
segments.append(segment_data)
|
||||
assert offset < len(app_data), "offset is out of bounds"
|
||||
|
||||
# add checksum size
|
||||
image_size += 1
|
||||
image_size = (image_size + 15) & ~15
|
||||
# hash appended
|
||||
if app_data[0x17] == 1:
|
||||
image_size += 32
|
||||
print(f"image size: {image_size}")
|
||||
|
||||
# verify the remaining data are all 0xFF
|
||||
for i in range(image_size, len(app_data)):
|
||||
if app_data[i] != 0xFF:
|
||||
print(f"Failed to verify image, data at 0x{i:08x} is not 0xFF")
|
||||
return
|
||||
|
||||
image_data = app_data[:image_size]
|
||||
assert offset < len(data), "offset is out of bounds"
|
||||
|
||||
# extract bin file
|
||||
bin_path = os.path.join(dir_path, "xiaozhi.bin")
|
||||
if not os.path.exists(bin_path):
|
||||
print("extract bin file to", bin_path)
|
||||
open(bin_path, "wb").write(image_data)
|
||||
open(bin_path, "wb").write(data)
|
||||
|
||||
# The app desc is in the first segment
|
||||
desc = get_app_desc(segments[0])
|
||||
@@ -155,7 +115,7 @@ def read_binary(dir_path):
|
||||
"flash_size": flash_size,
|
||||
"board": get_board_name(dir_path),
|
||||
"application": desc,
|
||||
"firmware_size": image_size,
|
||||
"firmware_size": len(data),
|
||||
}
|
||||
|
||||
def extract_zip(zip_path, extract_path):
|
||||
|
||||
@@ -47,13 +47,11 @@ CONFIG_LV_USE_CLIB_MALLOC=y
|
||||
CONFIG_LV_USE_CLIB_STRING=y
|
||||
CONFIG_LV_USE_CLIB_SPRINTF=y
|
||||
CONFIG_LV_USE_IMGFONT=y
|
||||
CONFIG_LV_USE_ASSERT_STYLE=y
|
||||
CONFIG_LV_USE_GIF=y
|
||||
|
||||
# Use compressed font
|
||||
CONFIG_LV_FONT_FMT_TXT_LARGE=y
|
||||
CONFIG_LV_USE_FONT_COMPRESSED=n
|
||||
CONFIG_LV_USE_FONT_PLACEHOLDER=n
|
||||
CONFIG_LV_USE_FONT_COMPRESSED=y
|
||||
CONFIG_LV_USE_FONT_PLACEHOLDER=y
|
||||
|
||||
# Disable extra widgets to save flash size
|
||||
CONFIG_LV_USE_ANIMIMG=n
|
||||
|
||||
Reference in New Issue
Block a user