forked from xiaozhi/xiaozhi-esp32
feat: support JC3636W518 of taiji-pi-s3 board. (#131)
This commit is contained in:
@@ -87,6 +87,8 @@ elseif(CONFIG_BOARD_TYPE_ATK_DNESP32S3_BOX)
|
||||
set(BOARD_TYPE "atk-dnesp32s3-box")
|
||||
elseif(CONFIG_BOARD_TYPE_DU_CHATX)
|
||||
set(BOARD_TYPE "du-chatx")
|
||||
elseif(CONFIG_BOARD_TYPE_ESP32S3_Taiji_Pi)
|
||||
set(BOARD_TYPE "taiji-pi-s3")
|
||||
endif()
|
||||
file(GLOB BOARD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc)
|
||||
list(APPEND SOURCES ${BOARD_SOURCES})
|
||||
|
||||
@@ -86,6 +86,8 @@ choice BOARD_TYPE
|
||||
bool "正点原子DNESP32S3-BOX"
|
||||
config BOARD_TYPE_DU_CHATX
|
||||
bool "嘟嘟开发板CHATX(wifi)"
|
||||
config BOARD_TYPE_ESP32S3_Taiji_Pi
|
||||
bool "太极小派esp32s3"
|
||||
endchoice
|
||||
|
||||
choice DISPLAY_LCD_TYPE
|
||||
|
||||
25
main/boards/taiji-pi-s3/README.md
Normal file
25
main/boards/taiji-pi-s3/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# 编译配置命令
|
||||
|
||||
**配置编译目标为 ESP32S3:**
|
||||
|
||||
```bash
|
||||
idf.py set-target esp32s3
|
||||
```
|
||||
|
||||
**打开 menuconfig:**
|
||||
|
||||
```bash
|
||||
idf.py menuconfig
|
||||
```
|
||||
|
||||
**选择板子:**
|
||||
|
||||
```
|
||||
Xiaozhi Assistant -> Board Type -> 太极小派esp32s3
|
||||
```
|
||||
|
||||
**编译:**
|
||||
|
||||
```bash
|
||||
idf.py build
|
||||
```
|
||||
67
main/boards/taiji-pi-s3/config.h
Normal file
67
main/boards/taiji-pi-s3/config.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#ifndef _BOARD_CONFIG_H_
|
||||
#define _BOARD_CONFIG_H_
|
||||
|
||||
// Taiji Pi S3 Board configuration
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_master.h>
|
||||
|
||||
#define AUDIO_INPUT_REFERENCE true
|
||||
#define AUDIO_INPUT_SAMPLE_RATE 24000
|
||||
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
|
||||
#define AUDIO_DEFAULT_OUTPUT_VOLUME 80
|
||||
|
||||
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_21
|
||||
#define AUDIO_I2S_GPIO_WS GPIO_NUM_16
|
||||
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_18
|
||||
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_NC
|
||||
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_17
|
||||
#define AUDIO_MUTE_PIN GPIO_NUM_48 // 低电平静音
|
||||
|
||||
#define AUDIO_MIC_WS_PIN GPIO_NUM_45
|
||||
#define AUDIO_MIC_SD_PIN GPIO_NUM_46
|
||||
#define AUDIO_MIC_SCK_PIN GPIO_NUM_42
|
||||
|
||||
#define DISPLAY_WIDTH 360
|
||||
#define DISPLAY_HEIGHT 360
|
||||
#define DISPLAY_MIRROR_X false
|
||||
#define DISPLAY_MIRROR_Y false
|
||||
#define DISPLAY_SWAP_XY false
|
||||
|
||||
#define QSPI_LCD_H_RES (360)
|
||||
#define QSPI_LCD_V_RES (360)
|
||||
#define QSPI_LCD_BIT_PER_PIXEL (16)
|
||||
|
||||
#define QSPI_LCD_HOST SPI2_HOST
|
||||
#define QSPI_PIN_NUM_LCD_PCLK GPIO_NUM_9
|
||||
#define QSPI_PIN_NUM_LCD_CS GPIO_NUM_10
|
||||
#define QSPI_PIN_NUM_LCD_DATA0 GPIO_NUM_11
|
||||
#define QSPI_PIN_NUM_LCD_DATA1 GPIO_NUM_12
|
||||
#define QSPI_PIN_NUM_LCD_DATA2 GPIO_NUM_13
|
||||
#define QSPI_PIN_NUM_LCD_DATA3 GPIO_NUM_14
|
||||
#define QSPI_PIN_NUM_LCD_RST GPIO_NUM_47
|
||||
#define QSPI_PIN_NUM_LCD_BL GPIO_NUM_15
|
||||
|
||||
#define DISPLAY_OFFSET_X 0
|
||||
#define DISPLAY_OFFSET_Y 0
|
||||
|
||||
#define TP_PORT (I2C_NUM_1)
|
||||
#define TP_PIN_NUM_TP_SDA (GPIO_NUM_7)
|
||||
#define TP_PIN_NUM_TP_SCL (GPIO_NUM_8)
|
||||
#define TP_PIN_NUM_TP_RST (GPIO_NUM_40)
|
||||
#define TP_PIN_NUM_TP_INT (GPIO_NUM_41)
|
||||
|
||||
#define DISPLAY_BACKLIGHT_PIN QSPI_PIN_NUM_LCD_BL
|
||||
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
|
||||
|
||||
#define TAIJIPI_ST77916_PANEL_BUS_QSPI_CONFIG(sclk, d0, d1, d2, d3, max_trans_sz) \
|
||||
{ \
|
||||
.data0_io_num = d0, \
|
||||
.data1_io_num = d1, \
|
||||
.sclk_io_num = sclk, \
|
||||
.data2_io_num = d2, \
|
||||
.data3_io_num = d3, \
|
||||
.max_transfer_sz = max_trans_sz, \
|
||||
}
|
||||
|
||||
#endif // _BOARD_CONFIG_H_
|
||||
221
main/boards/taiji-pi-s3/taiji_pi_s3.cc
Normal file
221
main/boards/taiji-pi-s3/taiji_pi_s3.cc
Normal file
@@ -0,0 +1,221 @@
|
||||
#include "wifi_board.h"
|
||||
#include "audio_codecs/no_audio_codec.h"
|
||||
#include "display/lcd_display.h"
|
||||
#include "application.h"
|
||||
#include "i2c_device.h"
|
||||
#include "config.h"
|
||||
#include "iot/thing_manager.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
#include <driver/i2c.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <wifi_station.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include "esp_lcd_st77916.h"
|
||||
|
||||
#define TAG "TaijiPiS3Board"
|
||||
|
||||
|
||||
LV_FONT_DECLARE(font_puhui_20_4);
|
||||
LV_FONT_DECLARE(font_awesome_20_4);
|
||||
|
||||
class Cst816s : public I2cDevice {
|
||||
public:
|
||||
struct TouchPoint_t {
|
||||
int num = 0;
|
||||
int x = -1;
|
||||
int y = -1;
|
||||
};
|
||||
Cst816s(i2c_master_bus_handle_t i2c_bus, uint8_t addr) : I2cDevice(i2c_bus, addr) {
|
||||
uint8_t chip_id = ReadReg(0xA3);
|
||||
ESP_LOGI(TAG, "Get chip ID: 0x%02X", chip_id);
|
||||
read_buffer_ = new uint8_t[6];
|
||||
}
|
||||
|
||||
~Cst816s() {
|
||||
delete[] read_buffer_;
|
||||
}
|
||||
|
||||
void UpdateTouchPoint() {
|
||||
ReadRegs(0x02, read_buffer_, 6);
|
||||
tp_.num = read_buffer_[0] & 0x0F;
|
||||
tp_.x = ((read_buffer_[1] & 0x0F) << 8) | read_buffer_[2];
|
||||
tp_.y = ((read_buffer_[3] & 0x0F) << 8) | read_buffer_[4];
|
||||
}
|
||||
|
||||
const TouchPoint_t& GetTouchPoint() {
|
||||
return tp_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t* read_buffer_ = nullptr;
|
||||
TouchPoint_t tp_;
|
||||
};
|
||||
|
||||
class TaijiPiS3Board : public WifiBoard {
|
||||
private:
|
||||
i2c_master_bus_handle_t i2c_bus_;
|
||||
Cst816s* cst816s_;
|
||||
LcdDisplay* display_;
|
||||
|
||||
void InitializeI2c() {
|
||||
// Initialize I2C peripheral
|
||||
i2c_master_bus_config_t i2c_bus_cfg = {
|
||||
.i2c_port = (i2c_port_t)1,
|
||||
.sda_io_num = TP_PIN_NUM_TP_SDA,
|
||||
.scl_io_num = TP_PIN_NUM_TP_SCL,
|
||||
.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_));
|
||||
}
|
||||
|
||||
static void touchpad_daemon(void* param) {
|
||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
||||
auto& board = (TaijiPiS3Board&)Board::GetInstance();
|
||||
auto touchpad = board.GetTouchpad();
|
||||
bool was_touched = false;
|
||||
while (1) {
|
||||
touchpad->UpdateTouchPoint();
|
||||
if (touchpad->GetTouchPoint().num > 0) {
|
||||
// On press
|
||||
if (!was_touched) {
|
||||
was_touched = true;
|
||||
Application::GetInstance().ToggleChatState();
|
||||
}
|
||||
}
|
||||
// On release
|
||||
else if (was_touched) {
|
||||
was_touched = false;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(50));
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void InitializeCst816sTouchPad() {
|
||||
ESP_LOGI(TAG, "Init Cst816s");
|
||||
cst816s_ = new Cst816s(i2c_bus_, 0x15);
|
||||
xTaskCreate(touchpad_daemon, "tp", 2048, NULL, 5, NULL);
|
||||
}
|
||||
|
||||
void BspLcdBlSet(int brightness_percent)
|
||||
{
|
||||
if (brightness_percent > 100) {
|
||||
brightness_percent = 100;
|
||||
}
|
||||
if (brightness_percent < 0) {
|
||||
brightness_percent = 0;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Setting LCD backlight: %d%%", brightness_percent);
|
||||
uint32_t duty_cycle = (1023 * brightness_percent) / 100; // LEDC resolution set to 10bits, thus: 100% = 1023
|
||||
ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, duty_cycle);
|
||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0);
|
||||
}
|
||||
|
||||
void InitializeSpi() {
|
||||
ESP_LOGI(TAG, "Initialize QSPI bus");
|
||||
|
||||
const spi_bus_config_t bus_config = TAIJIPI_ST77916_PANEL_BUS_QSPI_CONFIG(QSPI_PIN_NUM_LCD_PCLK,
|
||||
QSPI_PIN_NUM_LCD_DATA0,
|
||||
QSPI_PIN_NUM_LCD_DATA1,
|
||||
QSPI_PIN_NUM_LCD_DATA2,
|
||||
QSPI_PIN_NUM_LCD_DATA3,
|
||||
QSPI_LCD_H_RES * 80 * sizeof(uint16_t));
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(QSPI_LCD_HOST, &bus_config, SPI_DMA_CH_AUTO));
|
||||
}
|
||||
|
||||
void Initializest77916Display() {
|
||||
|
||||
esp_lcd_panel_io_handle_t panel_io = nullptr;
|
||||
esp_lcd_panel_handle_t panel = nullptr;
|
||||
|
||||
ESP_LOGI(TAG, "Install panel IO");
|
||||
|
||||
const esp_lcd_panel_io_spi_config_t io_config = ST77916_PANEL_IO_QSPI_CONFIG(QSPI_PIN_NUM_LCD_CS, NULL, NULL);
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)QSPI_LCD_HOST, &io_config, &panel_io));
|
||||
|
||||
ESP_LOGI(TAG, "Install ST77916 panel driver");
|
||||
|
||||
st77916_vendor_config_t vendor_config = {
|
||||
.flags = {
|
||||
.use_qspi_interface = 1,
|
||||
},
|
||||
};
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = QSPI_PIN_NUM_LCD_RST,
|
||||
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, // Implemented by LCD command `36h`
|
||||
.bits_per_pixel = QSPI_LCD_BIT_PER_PIXEL, // Implemented by LCD command `3Ah` (16/18)
|
||||
.vendor_config = &vendor_config,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_lcd_new_panel_st77916(panel_io, &panel_config, &panel));
|
||||
|
||||
esp_lcd_panel_reset(panel);
|
||||
esp_lcd_panel_init(panel);
|
||||
esp_lcd_panel_disp_on_off(panel, true);
|
||||
esp_lcd_panel_swap_xy(panel, DISPLAY_SWAP_XY);
|
||||
esp_lcd_panel_mirror(panel, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y);
|
||||
|
||||
display_ = new LcdDisplay(panel_io, panel, DISPLAY_BACKLIGHT_PIN, DISPLAY_BACKLIGHT_OUTPUT_INVERT,
|
||||
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X, DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY,
|
||||
{
|
||||
.text_font = &font_puhui_20_4,
|
||||
.icon_font = &font_awesome_20_4,
|
||||
.emoji_font = font_emoji_64_init(),
|
||||
});
|
||||
}
|
||||
|
||||
// 物联网初始化,添加对 AI 可见设备
|
||||
void InitializeIot() {
|
||||
auto& thing_manager = iot::ThingManager::GetInstance();
|
||||
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
||||
}
|
||||
void InitializeMute() {
|
||||
gpio_reset_pin(AUDIO_MUTE_PIN);
|
||||
/* Set the GPIO as a push/pull output */
|
||||
gpio_set_direction(AUDIO_MUTE_PIN, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(AUDIO_MUTE_PIN, 1);
|
||||
}
|
||||
|
||||
public:
|
||||
TaijiPiS3Board() {
|
||||
InitializeI2c();
|
||||
InitializeCst816sTouchPad();
|
||||
InitializeSpi();
|
||||
Initializest77916Display();
|
||||
InitializeIot();
|
||||
InitializeMute();
|
||||
}
|
||||
|
||||
virtual AudioCodec* GetAudioCodec() override {
|
||||
static NoAudioCodec* audio_codec = nullptr;
|
||||
if (audio_codec == nullptr) {
|
||||
audio_codec = new NoAudioCodecSimplex(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
||||
AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT,
|
||||
AUDIO_MIC_SCK_PIN, AUDIO_MIC_WS_PIN, AUDIO_MIC_SD_PIN);
|
||||
}
|
||||
return audio_codec;
|
||||
}
|
||||
|
||||
virtual Display* GetDisplay() override {
|
||||
return display_;
|
||||
}
|
||||
|
||||
virtual bool GetBatteryLevel(int &level, bool& charging) override {
|
||||
level = 100; charging = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
Cst816s* GetTouchpad() {
|
||||
return cst816s_;
|
||||
}
|
||||
};
|
||||
|
||||
DECLARE_BOARD(TaijiPiS3Board);
|
||||
@@ -5,6 +5,7 @@ dependencies:
|
||||
public: true
|
||||
espressif/esp_lcd_ili9341: "==1.2.0"
|
||||
espressif/esp_lcd_gc9a01: "^2.0.1"
|
||||
espressif/esp_lcd_st77916: "^1.0.1"
|
||||
78/esp_lcd_nv3023: "~1.0.0"
|
||||
78/esp-wifi-connect: "~2.1.0"
|
||||
78/esp-opus-encoder: "~2.1.0"
|
||||
|
||||
Reference in New Issue
Block a user