forked from xiaozhi/xiaozhi-esp32
* 改korvo板lcd cs引脚为NC,使用TCA9554扩展的IO3来拉低控制LCD CS * Update esp32s3_korvo2_v3_board.cc --------- Co-authored-by: Xiaoxia <terrence@tenclass.com>
164 lines
7.1 KiB
C++
164 lines
7.1 KiB
C++
#include "wifi_board.h"
|
|
#include "audio_codecs/no_audio_codec.h"
|
|
#include "display/lcd_display.h"
|
|
#include "system_reset.h"
|
|
#include "application.h"
|
|
#include "button.h"
|
|
#include "config.h"
|
|
#include "iot/thing_manager.h"
|
|
|
|
#include <esp_log.h>
|
|
#include "i2c_device.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>
|
|
#include <esp_timer.h>
|
|
#include "esp_io_expander_tca9554.h"
|
|
|
|
#define TAG "waveshare_lcd_1_85"
|
|
|
|
LV_FONT_DECLARE(font_puhui_16_4);
|
|
LV_FONT_DECLARE(font_awesome_16_4);
|
|
|
|
|
|
class CustomBoard : public WifiBoard {
|
|
private:
|
|
Button boot_button_;
|
|
i2c_master_bus_handle_t i2c_bus_;
|
|
esp_io_expander_handle_t io_expander = NULL;
|
|
LcdDisplay* display_;
|
|
|
|
void InitializeI2c() {
|
|
// Initialize I2C peripheral
|
|
i2c_master_bus_config_t i2c_bus_cfg = {
|
|
.i2c_port = (i2c_port_t)0,
|
|
.sda_io_num = I2C_SDA_IO,
|
|
.scl_io_num = I2C_SCL_IO,
|
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
|
};
|
|
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &i2c_bus_));
|
|
}
|
|
|
|
void InitializeTca9554(void)
|
|
{
|
|
esp_err_t ret = esp_io_expander_new_i2c_tca9554(i2c_bus_, I2C_ADDRESS, &io_expander);
|
|
if(ret != ESP_OK)
|
|
ESP_LOGE(TAG, "TCA9554 create returned error");
|
|
|
|
// uint32_t input_level_mask = 0;
|
|
// ret = esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, IO_EXPANDER_INPUT); // 设置引脚 EXIO0 和 EXIO1 模式为输入
|
|
// ret = esp_io_expander_get_level(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, &input_level_mask); // 获取引脚 EXIO0 和 EXIO1 的电平状态,存放在 input_level_mask 中
|
|
|
|
// ret = esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3, IO_EXPANDER_OUTPUT); // 设置引脚 EXIO2 和 EXIO3 模式为输出
|
|
// ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3, 1); // 将引脚电平设置为 1
|
|
// ret = esp_io_expander_print_state(io_expander); // 打印引脚状态
|
|
|
|
ret = esp_io_expander_set_dir(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, IO_EXPANDER_OUTPUT); // 设置引脚 EXIO0 和 EXIO1 模式为输出
|
|
ESP_ERROR_CHECK(ret);
|
|
ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, 1); // 复位 LCD 与 TouchPad
|
|
ESP_ERROR_CHECK(ret);
|
|
vTaskDelay(pdMS_TO_TICKS(300));
|
|
ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, 0); // 复位 LCD 与 TouchPad
|
|
ESP_ERROR_CHECK(ret);
|
|
vTaskDelay(pdMS_TO_TICKS(300));
|
|
ret = esp_io_expander_set_level(io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, 1); // 复位 LCD 与 TouchPad
|
|
ESP_ERROR_CHECK(ret);
|
|
}
|
|
|
|
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_16_4,
|
|
.icon_font = &font_awesome_16_4,
|
|
.emoji_font = font_emoji_64_init(),
|
|
});
|
|
}
|
|
|
|
void InitializeButtons() {
|
|
boot_button_.OnClick([this]() {
|
|
auto& app = Application::GetInstance();
|
|
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
|
|
ResetWifiConfiguration();
|
|
}
|
|
app.ToggleChatState();
|
|
});
|
|
}
|
|
|
|
// 物联网初始化,添加对 AI 可见设备
|
|
void InitializeIot() {
|
|
auto& thing_manager = iot::ThingManager::GetInstance();
|
|
thing_manager.AddThing(iot::CreateThing("Speaker"));
|
|
thing_manager.AddThing(iot::CreateThing("Backlight"));
|
|
}
|
|
|
|
public:
|
|
CustomBoard() :
|
|
boot_button_(BOOT_BUTTON_GPIO) {
|
|
InitializeI2c();
|
|
InitializeTca9554();
|
|
InitializeSpi();
|
|
Initializest77916Display();
|
|
InitializeButtons();
|
|
InitializeIot();
|
|
}
|
|
|
|
virtual AudioCodec* GetAudioCodec() override {
|
|
static NoAudioCodecSimplex audio_codec(AUDIO_INPUT_SAMPLE_RATE, AUDIO_OUTPUT_SAMPLE_RATE,
|
|
AUDIO_I2S_SPK_GPIO_BCLK, AUDIO_I2S_SPK_GPIO_LRCK, AUDIO_I2S_SPK_GPIO_DOUT, I2S_STD_SLOT_BOTH, AUDIO_I2S_MIC_GPIO_SCK, AUDIO_I2S_MIC_GPIO_WS, AUDIO_I2S_MIC_GPIO_DIN, I2S_STD_SLOT_RIGHT); // I2S_STD_SLOT_LEFT / I2S_STD_SLOT_RIGHT / I2S_STD_SLOT_BOTH
|
|
|
|
return &audio_codec;
|
|
}
|
|
|
|
virtual Display* GetDisplay() override {
|
|
return display_;
|
|
}
|
|
};
|
|
|
|
DECLARE_BOARD(CustomBoard);
|