forked from xiaozhi/xiaozhi-esp32
增加LilyGo T-Circle-S3和T-CameraPlus-S3的屏幕背光和低功耗模式 (#304)
* 增加LilyGo T-Circle-S3和T-CameraPlus-S3的屏幕背光和低功耗模式 * 增加LilyGo T-Circle-S3和T-CameraPlus-S3的屏幕背光和低功耗模式
This commit is contained in:
33
main/boards/lilygo-t-cameraplus-s3/README.md
Normal file
33
main/boards/lilygo-t-cameraplus-s3/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# 编译配置命令
|
||||
|
||||
**配置编译目标为 ESP32S3:**
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32s3
|
||||
```
|
||||
|
||||
**打开 menuconfig:**
|
||||
|
||||
```bash
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
**选择板子:**
|
||||
|
||||
```
|
||||
Xiaozhi Assistant -> Board Type -> LILYGO T-CameraPlus-S3
|
||||
```
|
||||
|
||||
**修改 psram 配置:**
|
||||
|
||||
```
|
||||
Component config -> ESP PSRAM -> SPI RAM config -> Mode (QUAD/OCT) -> Quad Mode PSRAM
|
||||
```
|
||||
|
||||
**编译:**
|
||||
|
||||
```bash
|
||||
idf.py build
|
||||
```
|
||||
|
||||
<a href="https://github.com/Xinyuan-LilyGO/T-CameraPlus-S3" target="_blank" title="LILYGO T-Circle-S3">LILYGO T-CameraPlus-S3</a>
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "power_save_timer.h"
|
||||
#include "i2c_device.h"
|
||||
#include "iot/thing_manager.h"
|
||||
|
||||
@@ -57,6 +58,25 @@ private:
|
||||
Cst816x *cst816d_;
|
||||
LcdDisplay *display_;
|
||||
Button key1_button_;
|
||||
PowerSaveTimer* power_save_timer_;
|
||||
|
||||
void InitializePowerSaveTimer() {
|
||||
power_save_timer_ = new PowerSaveTimer(-1, 60, 300);
|
||||
power_save_timer_->OnEnterSleepMode([this]() {
|
||||
ESP_LOGI(TAG, "Enabling sleep mode");
|
||||
auto display = GetDisplay();
|
||||
display->SetChatMessage("system", "");
|
||||
display->SetEmotion("sleepy");
|
||||
GetBacklight()->SetBrightness(10);
|
||||
});
|
||||
power_save_timer_->OnExitSleepMode([this]() {
|
||||
auto display = GetDisplay();
|
||||
display->SetChatMessage("system", "");
|
||||
display->SetEmotion("neutral");
|
||||
GetBacklight()->RestoreBrightness();
|
||||
});
|
||||
power_save_timer_->SetEnabled(true);
|
||||
}
|
||||
|
||||
void InitI2c(){
|
||||
// Initialize I2C peripheral
|
||||
@@ -179,6 +199,7 @@ private:
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
power_save_timer_->WakeUp();
|
||||
app.ToggleChatState();
|
||||
});
|
||||
}
|
||||
@@ -187,10 +208,12 @@ private:
|
||||
void InitializeIot() {
|
||||
auto &thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
||||
}
|
||||
|
||||
public:
|
||||
LilygoTCameraPlusS3Board() : key1_button_(KEY1_BUTTON_GPIO) {
|
||||
InitializePowerSaveTimer();
|
||||
InitI2c();
|
||||
InitCst816d();
|
||||
I2cDetect();
|
||||
@@ -218,6 +241,13 @@ public:
|
||||
virtual Display *GetDisplay() override{
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual void SetPowerSaveMode(bool enabled) override {
|
||||
if (!enabled) {
|
||||
power_save_timer_->WakeUp();
|
||||
}
|
||||
WifiBoard::SetPowerSaveMode(enabled);
|
||||
}
|
||||
|
||||
virtual Backlight* GetBacklight() override {
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
|
||||
@@ -114,17 +114,13 @@ int Tcamerapluss3AudioCodec::Read(int16_t *dest, int samples){
|
||||
return samples;
|
||||
}
|
||||
|
||||
void AdjustTcamerapluss3Volume(const int16_t *input_data, int16_t *output_data, size_t samples, float volume){
|
||||
for (size_t i = 0; i < samples; i++){
|
||||
output_data[i] = (float)input_data[i] * volume;
|
||||
}
|
||||
}
|
||||
|
||||
int Tcamerapluss3AudioCodec::Write(const int16_t *data, int samples){
|
||||
if (output_enabled_){
|
||||
size_t bytes_read;
|
||||
auto output_data = (int16_t *)malloc(samples * sizeof(int16_t));
|
||||
AdjustTcamerapluss3Volume(data, output_data, samples, (float)(volume_ / 100.0));
|
||||
for (size_t i = 0; i < samples; i++){
|
||||
output_data[i] = (float)data[i] * (float)(volume_ / 100.0);
|
||||
}
|
||||
i2s_channel_write(tx_handle_, output_data, samples * sizeof(int16_t), &bytes_read, portMAX_DELAY);
|
||||
free(output_data);
|
||||
}
|
||||
|
||||
28
main/boards/lilygo-t-circle-s3/README.md
Normal file
28
main/boards/lilygo-t-circle-s3/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# 编译配置命令
|
||||
|
||||
**配置编译目标为 ESP32S3:**
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32s3
|
||||
```
|
||||
|
||||
**打开 menuconfig:**
|
||||
|
||||
```bash
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
**选择板子:**
|
||||
|
||||
```
|
||||
Xiaozhi Assistant -> Board Type -> LILYGO T-Circle-S3
|
||||
```
|
||||
|
||||
|
||||
**编译:**
|
||||
|
||||
```bash
|
||||
idf.py build
|
||||
```
|
||||
|
||||
<a href="https://github.com/Xinyuan-LilyGO/T-Circle-S3" target="_blank" title="LILYGO T-Circle-S3">LILYGO T-Circle-S3</a>
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "application.h"
|
||||
#include "button.h"
|
||||
#include "config.h"
|
||||
#include "power_save_timer.h"
|
||||
#include "i2c_device.h"
|
||||
#include "iot/thing_manager.h"
|
||||
|
||||
@@ -59,6 +60,25 @@ private:
|
||||
Cst816x *cst816d_;
|
||||
LcdDisplay *display_;
|
||||
Button boot_button_;
|
||||
PowerSaveTimer* power_save_timer_;
|
||||
|
||||
void InitializePowerSaveTimer() {
|
||||
power_save_timer_ = new PowerSaveTimer(-1, 60, 300);
|
||||
power_save_timer_->OnEnterSleepMode([this]() {
|
||||
ESP_LOGI(TAG, "Enabling sleep mode");
|
||||
auto display = GetDisplay();
|
||||
display->SetChatMessage("system", "");
|
||||
display->SetEmotion("sleepy");
|
||||
GetBacklight()->SetBrightness(10);
|
||||
});
|
||||
power_save_timer_->OnExitSleepMode([this]() {
|
||||
auto display = GetDisplay();
|
||||
display->SetChatMessage("system", "");
|
||||
display->SetEmotion("neutral");
|
||||
GetBacklight()->RestoreBrightness();
|
||||
});
|
||||
power_save_timer_->SetEnabled(true);
|
||||
}
|
||||
|
||||
void InitI2c(){
|
||||
// Initialize I2C peripheral
|
||||
@@ -197,6 +217,7 @@ private:
|
||||
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
||||
ResetWifiConfiguration();
|
||||
}
|
||||
power_save_timer_->WakeUp();
|
||||
app.ToggleChatState();
|
||||
});
|
||||
}
|
||||
@@ -205,10 +226,12 @@ private:
|
||||
void InitializeIot() {
|
||||
auto &thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
||||
}
|
||||
|
||||
public:
|
||||
LilygoTCircleS3Board() : boot_button_(BOOT_BUTTON_GPIO) {
|
||||
InitializePowerSaveTimer();
|
||||
InitI2c();
|
||||
InitCst816d();
|
||||
I2cDetect();
|
||||
@@ -236,6 +259,13 @@ public:
|
||||
virtual Display *GetDisplay() override{
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual void SetPowerSaveMode(bool enabled) override {
|
||||
if (!enabled) {
|
||||
power_save_timer_->WakeUp();
|
||||
}
|
||||
WifiBoard::SetPowerSaveMode(enabled);
|
||||
}
|
||||
|
||||
virtual Backlight* GetBacklight() override {
|
||||
static PwmBacklight backlight(DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT);
|
||||
|
||||
@@ -132,17 +132,13 @@ int Tcircles3AudioCodec::Read(int16_t *dest, int samples){
|
||||
return samples;
|
||||
}
|
||||
|
||||
void AdjustTcircles3Volume(const int16_t *input_data, int16_t *output_data, size_t samples, float volume){
|
||||
for (size_t i = 0; i < samples; i++){
|
||||
output_data[i] = (float)input_data[i] * volume;
|
||||
}
|
||||
}
|
||||
|
||||
int Tcircles3AudioCodec::Write(const int16_t *data, int samples){
|
||||
if (output_enabled_){
|
||||
size_t bytes_read;
|
||||
auto output_data = (int16_t *)malloc(samples * sizeof(int16_t));
|
||||
AdjustTcircles3Volume(data, output_data, samples, (float)(volume_ / 100.0));
|
||||
for (size_t i = 0; i < samples; i++){
|
||||
output_data[i] = (float)data[i] * (float)(volume_ / 100.0);
|
||||
}
|
||||
i2s_channel_write(tx_handle_, output_data, samples * sizeof(int16_t), &bytes_read, portMAX_DELAY);
|
||||
free(output_data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user