Add Moji board (#103)

* Boards add Moji adaptation

* add README
This commit is contained in:
MOV
2025-01-23 23:42:00 +08:00
committed by GitHub
parent 64058e4093
commit 7a40c084ba
5 changed files with 275 additions and 1 deletions

View File

@@ -71,7 +71,9 @@ elseif(CONFIG_BOARD_TYPE_ESP32S3_Touch_AMOLED_1_8)
elseif(CONFIG_BOARD_TYPE_BREAD_COMPACT_WIFI_LCD)
set(BOARD_TYPE "bread-compact-wifi-lcd")
elseif(CONFIG_BOARD_TYPE_LILYGO_T_CIRCLE_S3)
set(BOARD_TYPE "lilygo-t-circle-s3")
set(BOARD_TYPE "lilygo-t-circle-s3")
elseif(CONFIG_BOARD_TYPE_MOVECALL_MOJI_ESP32S3)
set(BOARD_TYPE "movecall-moji-esp32s3")
endif()
file(GLOB BOARD_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/boards/${BOARD_TYPE}/*.cc)
list(APPEND SOURCES ${BOARD_SOURCES})

View File

@@ -72,6 +72,8 @@ choice BOARD_TYPE
bool "Waveshare ESP32-S3-Touch-AMOLED-1.8"
config BOARD_TYPE_LILYGO_T_CIRCLE_S3
bool "LILYGO T-Circle-S3"
config BOARD_TYPE_MOVECALL_MOJI_ESP32S3
bool "Movecall Moji 小智AI衍生版"
endchoice
choice DISPLAY_LCD_TYPE

View File

@@ -0,0 +1,26 @@
# 编译配置命令
**配置编译目标为 ESP32S3**
```bash
idf.py set-target esp32s3
```
**打开 menuconfig**
```bash
idf.py menuconfig
```
**选择板子:**
```
Xiaozhi Assistant -> Board Type -> Movecall Moji 小智AI衍生版
```
**编译:**
```bash
idf.py build
```

View File

@@ -0,0 +1,38 @@
#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_
// Movecall Moji configuration
#include <driver/gpio.h>
#define AUDIO_INPUT_SAMPLE_RATE 24000
#define AUDIO_OUTPUT_SAMPLE_RATE 24000
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_6
#define AUDIO_I2S_GPIO_WS GPIO_NUM_12
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_14
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_13
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_11
#define AUDIO_CODEC_PA_PIN GPIO_NUM_9
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_5
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_4
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
#define BUILTIN_LED_GPIO GPIO_NUM_15
#define BOOT_BUTTON_GPIO GPIO_NUM_0
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 240
#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_3
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
#endif // _BOARD_CONFIG_H_

View File

@@ -0,0 +1,206 @@
#include "wifi_board.h"
#include "audio_codecs/es8311_audio_codec.h"
// #include "display/ssd1306_display.h"
#include "display/lcd_display.h"
#include "display/no_display.h"
#include "application.h"
#include "button.h"
#include "config.h"
#include "iot/thing_manager.h"
#include "led/single_led.h"
#include <wifi_station.h>
#include <esp_log.h>
#include <esp_efuse_table.h>
#include <driver/i2c_master.h>
#include <esp_lcd_panel_io.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lcd_gc9a01.h>
#include "driver/gpio.h"
#include "driver/spi_master.h"
#define TAG "MovecallMojiESP32S3"
LV_FONT_DECLARE(font_puhui_16_4);
LV_FONT_DECLARE(font_awesome_16_4);
static const gc9a01_lcd_init_cmd_t gc9107_lcd_init_cmds[] = {
// {cmd, { data }, data_size, delay_ms}
{0xef, (uint8_t[]){0x00}, 0, 0},
{0xeb, (uint8_t[]){0x14}, 0, 0},
{0xfe, (uint8_t[]){0x00}, 0, 0},
{0xef, (uint8_t[]){0x00}, 0, 0},
{0xEB, (uint8_t[]){0x14}, 1, 0},
{0x84, (uint8_t[]){0x40}, 1, 0},
{0x85, (uint8_t[]){0xFF}, 1, 0},
{0x86, (uint8_t[]){0xFF}, 1, 0},
{0x87, (uint8_t[]){0xFF}, 1, 0},
{0x88, (uint8_t[]){0x0A}, 1, 0},
{0x89, (uint8_t[]){0x21}, 1, 0},
{0x8A, (uint8_t[]){0x00}, 1, 0},
{0x8B, (uint8_t[]){0x80}, 1, 0},
{0x8C, (uint8_t[]){0x01}, 1, 0},
{0x8D, (uint8_t[]){0x01}, 1, 0},
{0x8E, (uint8_t[]){0xFF}, 1, 0},
{0x8F, (uint8_t[]){0xFF}, 1, 0},
{0xB6, (uint8_t[]){0x00, 0x20,}, 2, 0},
{0x3A, (uint8_t[]){0x05}, 1, 0},
{0x90, (uint8_t[]){0x08, 0x08, 0x08, 0x08}, 4, 0},
{0xBD, (uint8_t[]){0x06}, 1, 0},
{0xBC, (uint8_t[]){0x00}, 1, 0},
{0xFF, (uint8_t[]){0x60, 0x01, 0x04}, 3, 0},
{0xC3, (uint8_t[]){0x13}, 1, 0},
{0xC4, (uint8_t[]){0x13}, 1, 0},
{0xC9, (uint8_t[]){0x22}, 1, 0},
{0xBE, (uint8_t[]){0x11}, 1, 0},
{0xE1, (uint8_t[]){0x10, 0x0E}, 2, 0},
{0xDF, (uint8_t[]){0x21, 0x0c, 0x02}, 3, 0},
{0xF0, (uint8_t[]){0x45, 0x09, 0x08, 0x08, 0x26, 0x2A}, 6, 0},
{0xF1, (uint8_t[]){0x43, 0x70, 0x72, 0x36, 0x37, 0x6F}, 6, 0},
{0xF2, (uint8_t[]){0x45, 0x09, 0x08, 0x08, 0x26, 0x2A}, 6, 0},
{0xF3, (uint8_t[]){0x43, 0x70, 0x72, 0x36, 0x37, 0x6F}, 6, 0},
{0xED, (uint8_t[]){0x1B, 0x0B}, 2, 0},
{0xAE, (uint8_t[]){0x77}, 1, 0},
{0xCD, (uint8_t[]){0x63}, 1, 0},
{0x70, (uint8_t[]){0x07, 0x07, 0x04, 0x0E, 0x0F, 0x09, 0x07, 0x08, 0x03}, 9, 0},
{0xE8, (uint8_t[]){0x34}, 1, 0},
{0x62, (uint8_t[]){0x18, 0x0D, 0x71, 0xED, 0x70, 0x70, 0x18, 0x0F, 0x71, 0xEF, 0x70, 0x70}, 12, 0},
{0x63, (uint8_t[]){0x18, 0x11, 0x71, 0xF1, 0x70, 0x70, 0x18, 0x13, 0x71, 0xF3, 0x70, 0x70}, 12, 0},
{0x64, (uint8_t[]){0x28, 0x29, 0xF1, 0x01, 0xF1, 0x00, 0x07}, 7, 0},
{0x66, (uint8_t[]){0x3C, 0x00, 0xCD, 0x67, 0x45, 0x45, 0x10, 0x00, 0x00, 0x00}, 10, 0},
{0x67, (uint8_t[]){0x00, 0x3C, 0x00, 0x00, 0x00, 0x01, 0x54, 0x10, 0x32, 0x98}, 10, 0},
{0x74, (uint8_t[]){0x10, 0x85, 0x80, 0x00, 0x00, 0x4E, 0x00}, 7, 0},
{0x98, (uint8_t[]){0x3e, 0x07}, 2, 0},
{0x35, (uint8_t[]){0x00}, 0, 0},
{0x11, (uint8_t[]){0x00}, 0, 120},
{0x29, (uint8_t[]){0x00}, 0, 20},
// GC9A01_INVON
{0x21, (uint8_t[]){0x00}, 0, 20},
};
class MovecallMojiESP32S3 : public WifiBoard {
private:
i2c_master_bus_handle_t codec_i2c_bus_;
Button boot_button_;
Display* display_;
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, &codec_i2c_bus_));
}
// SPI初始化
void InitializeSpi() {
ESP_LOGI(TAG, "Initialize SPI bus");
spi_bus_config_t buscfg = {};
buscfg.mosi_io_num = GPIO_NUM_17;
buscfg.miso_io_num = GPIO_NUM_NC;
buscfg.sclk_io_num = GPIO_NUM_16;
buscfg.quadwp_io_num = GPIO_NUM_NC;
buscfg.quadhd_io_num = GPIO_NUM_NC;
buscfg.max_transfer_sz = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint16_t);
ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));
}
// GC9107初始化
void InitializeGc9107Display() {
ESP_LOGI(TAG, "Init GC9107 display");
ESP_LOGI(TAG, "Install panel IO");
esp_lcd_panel_io_handle_t io_handle = NULL;
esp_lcd_panel_io_spi_config_t io_config = {};
io_config.cs_gpio_num = GPIO_NUM_15;
io_config.dc_gpio_num = GPIO_NUM_7;
io_config.spi_mode = 0;
io_config.pclk_hz = 40 * 1000 * 1000;
io_config.trans_queue_depth = 10;
io_config.lcd_cmd_bits = 8;
io_config.lcd_param_bits = 8;
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &io_handle));
ESP_LOGI(TAG, "Install GC9A01 panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
gc9a01_vendor_config_t gc9107_vendor_config = {
.init_cmds = gc9107_lcd_init_cmds,
.init_cmds_size = sizeof(gc9107_lcd_init_cmds) / sizeof(gc9a01_lcd_init_cmd_t),
};
esp_lcd_panel_dev_config_t panel_config = {};
panel_config.reset_gpio_num = GPIO_NUM_18; // Set to -1 if not use
panel_config.rgb_endian = LCD_RGB_ELEMENT_ORDER_BGR;//LCD_RGB_ENDIAN_RGB;
panel_config.bits_per_pixel = 16; // Implemented by LCD command `3Ah` (16/18)
panel_config.vendor_config = &gc9107_vendor_config;
ESP_ERROR_CHECK(esp_lcd_new_panel_gc9a01(io_handle, &panel_config, &panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
display_ = new LcdDisplay(io_handle, panel_handle, 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,
&font_puhui_16_4, &font_awesome_16_4);
}
void InitializeButtons() {
boot_button_.OnClick([this]() {
auto& app = Application::GetInstance();
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
ResetWifiConfiguration();
}
app.ToggleChatState();
});
boot_button_.OnPressDown([this]() {
Application::GetInstance().StartListening();
});
boot_button_.OnPressUp([this]() {
Application::GetInstance().StopListening();
});
}
// 物联网初始化,添加对 AI 可见设备
void InitializeIot() {
auto& thing_manager = iot::ThingManager::GetInstance();
thing_manager.AddThing(iot::CreateThing("Speaker"));
}
public:
MovecallMojiESP32S3() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeCodecI2c();
InitializeSpi();
InitializeGc9107Display();
InitializeButtons();
InitializeIot();
}
virtual Led* GetLed() override {
static SingleLed led_strip(BUILTIN_LED_GPIO);
return &led_strip;
}
virtual Display* GetDisplay() override {
return display_;
}
virtual AudioCodec* GetAudioCodec() override {
static Es8311AudioCodec audio_codec(codec_i2c_bus_, I2C_NUM_0, AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
AUDIO_I2S_GPIO_MCLK, AUDIO_I2S_GPIO_BCLK, AUDIO_I2S_GPIO_WS, AUDIO_I2S_GPIO_DOUT, AUDIO_I2S_GPIO_DIN,
AUDIO_CODEC_PA_PIN, AUDIO_CODEC_ES8311_ADDR);
return &audio_codec;
}
};
DECLARE_BOARD(MovecallMojiESP32S3);