Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ elseif(CONFIG_BOARD_TYPE_YUNLIAO_S3)
set(BUILTIN_TEXT_FONT font_puhui_basic_20_4)
set(BUILTIN_ICON_FONT font_awesome_20_4)
set(DEFAULT_EMOJI_COLLECTION twemoji_64)
elseif(CONFIG_BOARD_TYPE_PDI_CHATBOX_V1)
set(BOARD_TYPE "pdi-chatbox-v1")
endif()

file(GLOB BOARD_SOURCES
Expand Down
3 changes: 3 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ choice BOARD_TYPE
config BOARD_TYPE_YUNLIAO_S3
bool "小智云聊-S3"
depends on IDF_TARGET_ESP32S3
config BOARD_TYPE_PDI_CHATBOX_V1
bool "Dandefly.AIoT"
depends on IDF_TARGET_ESP32S3
endchoice

choice ESP_S3_LCD_EV_Board_Version_TYPE
Expand Down
34 changes: 34 additions & 0 deletions main/boards/pdi-chatbox-v1/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_

#include <driver/gpio.h>

#define POWER_OFF_TIMER 60

#define AUDIO_INPUT_SAMPLE_RATE 24000
#define AUDIO_OUTPUT_SAMPLE_RATE 24000

#define AUDIO_INPUT_REFERENCE true

#define AUDIO_PA_CTRL GPIO_NUM_8

#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_38
#define AUDIO_I2S_GPIO_WS GPIO_NUM_13
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_14
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_12
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_45

#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_1
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_2
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
#define AUDIO_CODEC_ES7210_ADDR 0x82

#define KEY_HOLD_GPIO GPIO_NUM_5

#define BAT_ADC_GPIO GPIO_NUM_9

#define BUILTIN_LED_GPIO GPIO_NUM_48

#define BOOT_BUTTON_GPIO GPIO_NUM_4

#endif // _BOARD_CONFIG_H_
11 changes: 11 additions & 0 deletions main/boards/pdi-chatbox-v1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"target": "esp32s3",
"builds": [
{
"name": "pdi-chatbox-v1",
"sdkconfig_append": [
"CONFIG_USE_DEVICE_AEC=y"
]
}
]
}
181 changes: 181 additions & 0 deletions main/boards/pdi-chatbox-v1/led_eye.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#include "Led_Eye.h"
#include "application.h"
#include <esp_log.h>

#define TAG "LEDEYE"

#define DEFAULT_BRIGHTNESS 32
#define HIGH_BRIGHTNESS 64
#define LOW_BRIGHTNESS 18

#define BLINK_INFINITE -1


LedEye::LedEye(gpio_num_t gpio) {
assert(gpio != GPIO_NUM_NC);
led_strip_config_t strip_config = {};
strip_config.strip_gpio_num = gpio;
strip_config.max_leds = LED_MAX_NUM;
strip_config.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB;
strip_config.led_model = LED_MODEL_WS2812;
led_strip_rmt_config_t rmt_config = {};
rmt_config.resolution_hz = 10 * 1000 * 1000; // 10MHz

ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip_));
led_strip_clear(led_strip_);

esp_timer_create_args_t blink_timer_args = {
.callback = [](void *arg) {
auto led = static_cast<LedEye*>(arg);
led->OnBlinkTimer();
},
.arg = this,
.dispatch_method = ESP_TIMER_TASK,
.name = "blink_timer",
.skip_unhandled_events = false,
};
ESP_ERROR_CHECK(esp_timer_create(&blink_timer_args, &blink_timer_));
}

LedEye::~LedEye() {
esp_timer_stop(blink_timer_);
if (led_strip_ != nullptr) {
led_strip_del(led_strip_);
}
}

void LedEye::SetSingleColor(uint8_t index,uint8_t red,uint8_t green,uint8_t blue) {
cyc_blink_flag=0;
colors[index].red=red;
colors[index].green=green;
colors[index].blue=blue;
}

void LedEye::SetAllColor(uint8_t red,uint8_t green,uint8_t blue) {
cyc_blink_flag=0;
for(uint8_t i=0;i<LED_MAX_NUM;i++){
colors[i].red=red;
colors[i].green=green;
colors[i].blue=blue;
}
}

void LedEye::TurnOn() {
if (led_strip_ == nullptr) {
return;
}
std::lock_guard<std::mutex> lock(mutex_);
esp_timer_stop(blink_timer_);
for(uint8_t i=0;i<LED_MAX_NUM;i++){
led_strip_set_pixel(led_strip_, i, colors[i].red, colors[i].green, colors[i].blue);
}
led_strip_refresh(led_strip_);
}

void LedEye::TurnOff() {
if (led_strip_ == nullptr) {
return;
}
std::lock_guard<std::mutex> lock(mutex_);
esp_timer_stop(blink_timer_);
led_strip_clear(led_strip_);
cyc_blink_flag=0;
}

void LedEye::BlinkOnce() {
Blink(1, 100);
}

void LedEye::Blink(int times, int interval_ms) {
StartBlinkTask(times, interval_ms);
}

void LedEye::StartContinuousBlink(int interval_ms) {
StartBlinkTask(BLINK_INFINITE, interval_ms);
}

void LedEye::StartBlink(int interval_ms) {
cyc_blink_flag=1;
StartBlinkTask(BLINK_INFINITE, interval_ms);
}

void LedEye::StartBlinkTask(int times, int interval_ms) {
if (led_strip_ == nullptr) {
return;
}

std::lock_guard<std::mutex> lock(mutex_);
esp_timer_stop(blink_timer_);

blink_counter_ = times * 2;
blink_interval_ms_ = interval_ms;
esp_timer_start_periodic(blink_timer_, interval_ms * 1000);
}

void LedEye::OnBlinkTimer() {
std::lock_guard<std::mutex> lock(mutex_);
blink_counter_--;
if (blink_counter_ & 1) {
for(uint8_t i=0;i<LED_MAX_NUM;i++){
led_strip_set_pixel(led_strip_, i, colors[i].red, colors[i].green, colors[i].blue);
}
led_strip_refresh(led_strip_);
} else {
led_strip_clear(led_strip_);
if (blink_counter_ == 0) {
if(cyc_blink_flag){
blink_counter_=BLINK_INFINITE*2;
}
else{
esp_timer_stop(blink_timer_);
}
}
}
}

void LedEye::OnStateChanged() {
auto& app = Application::GetInstance();
auto device_state = app.GetDeviceState();
switch (device_state) {
case kDeviceStateStarting:
// R
SetAllColor(DEFAULT_BRIGHTNESS, 0, 0);
StartContinuousBlink(100);
break;
case kDeviceStateWifiConfiguring:
SetAllColor(DEFAULT_BRIGHTNESS, 0, 0);
break;
case kDeviceStateIdle:
TurnOff();
break;
case kDeviceStateConnecting:
SetAllColor(DEFAULT_BRIGHTNESS, 0, 0);
StartContinuousBlink(50);
TurnOn();
break;
case kDeviceStateListening:
//B
SetAllColor(0, 0, HIGH_BRIGHTNESS);
TurnOn();
StartBlink(500);
break;
case kDeviceStateSpeaking:
//G
SetAllColor(0, HIGH_BRIGHTNESS, 0);
TurnOn();
StartBlink(500);
break;
case kDeviceStateUpgrading:
SetAllColor(LOW_BRIGHTNESS, 0, 0);
StartContinuousBlink(100);
break;
case kDeviceStateActivating:
//R
SetAllColor(LOW_BRIGHTNESS, 0, 0);
StartContinuousBlink(100);
break;
default:
ESP_LOGW(TAG, "Unknown led strip event: %d", device_state);
return;
}
}
46 changes: 46 additions & 0 deletions main/boards/pdi-chatbox-v1/led_eye.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#ifndef _Double_Led_LED_H_
#define _Double_Led_LED_H_

#include "led/led.h"
#include <driver/gpio.h>
#include <led_strip.h>
#include <esp_timer.h>
#include <atomic>
#include <mutex>

#define LED_MAX_NUM 2

struct Color {
uint8_t red = 0, green = 0, blue = 0;
};

class LedEye : public Led {
public:
LedEye(gpio_num_t gpio);
virtual ~LedEye();
void OnStateChanged() override;

private:
std::mutex mutex_;
TaskHandle_t blink_task_ = nullptr;
led_strip_handle_t led_strip_ = nullptr;
struct Color colors[LED_MAX_NUM];
uint8_t cyc_blink_flag;
int blink_counter_ = 0;
int blink_interval_ms_ = 0;
esp_timer_handle_t blink_timer_ = nullptr;

void StartBlinkTask(int times, int interval_ms);
void OnBlinkTimer();

void BlinkOnce();
void Blink(int times, int interval_ms);
void StartContinuousBlink(int interval_ms);
void StartBlink(int interval_ms);
void TurnOn();
void TurnOff();
void SetSingleColor(uint8_t index,uint8_t red,uint8_t green,uint8_t blue);
void SetAllColor(uint8_t red,uint8_t green,uint8_t blue);
};

#endif // _LedEye_LED_H_
Loading