Upgrade Playlist Features

This commit is contained in:
2025-12-09 17:20:01 +08:00
parent 577990de69
commit 8bd2780688
683 changed files with 91812 additions and 81260 deletions

View File

@@ -1,53 +1,53 @@
#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_
#include <driver/gpio.h>
#define AUDIO_INPUT_SAMPLE_RATE 16000
#define AUDIO_OUTPUT_SAMPLE_RATE 16000
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_5
#define AUDIO_I2S_GPIO_WS GPIO_NUM_7
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_16
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_15
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_6
#define BSP_POWER_AMP_IO (IO_EXPANDER_PIN_NUM_0)
#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC
//如果开发板是V1.4 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p4
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_8
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_18
#endif
//如果开发板是V1.5 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p5
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_47
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_48
#endif
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
#define AUDIO_CODEC_ES7210_ADDR 0x82
#define BUILTIN_LED_GPIO GPIO_NUM_4
#define BOOT_BUTTON_GPIO GPIO_NUM_0
#define DISPLAY_WIDTH 480
#define DISPLAY_HEIGHT 480
#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_19
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
#endif // _BOARD_CONFIG_H_
#ifndef _BOARD_CONFIG_H_
#define _BOARD_CONFIG_H_
#include <driver/gpio.h>
#define AUDIO_INPUT_SAMPLE_RATE 16000
#define AUDIO_OUTPUT_SAMPLE_RATE 16000
#define AUDIO_I2S_GPIO_MCLK GPIO_NUM_5
#define AUDIO_I2S_GPIO_WS GPIO_NUM_7
#define AUDIO_I2S_GPIO_BCLK GPIO_NUM_16
#define AUDIO_I2S_GPIO_DIN GPIO_NUM_15
#define AUDIO_I2S_GPIO_DOUT GPIO_NUM_6
#define BSP_POWER_AMP_IO (IO_EXPANDER_PIN_NUM_0)
#define AUDIO_CODEC_PA_PIN GPIO_NUM_NC
//如果开发板是V1.4 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p4
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_8
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_18
#endif
//如果开发板是V1.5 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p5
#define AUDIO_CODEC_I2C_SDA_PIN GPIO_NUM_47
#define AUDIO_CODEC_I2C_SCL_PIN GPIO_NUM_48
#endif
#define AUDIO_CODEC_ES8311_ADDR ES8311_CODEC_DEFAULT_ADDR
#define AUDIO_CODEC_ES7210_ADDR 0x82
#define BUILTIN_LED_GPIO GPIO_NUM_4
#define BOOT_BUTTON_GPIO GPIO_NUM_0
#define DISPLAY_WIDTH 480
#define DISPLAY_HEIGHT 480
#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_19
#define DISPLAY_BACKLIGHT_OUTPUT_INVERT false
#endif // _BOARD_CONFIG_H_

View File

@@ -1,17 +1,17 @@
{
"target": "esp32s3",
"builds": [
{
"name": "esp-s3-lcd-ev-board-1p4",
"sdkconfig_append": [
"CONFIG_ESP_S3_LCD_EV_Board_1p4=y"
]
},
{
"name": "esp-s3-lcd-ev-board-1p5",
"sdkconfig_append": [
"CONFIG_ESP_S3_LCD_EV_Board_1p5=y"
]
}
]
}
{
"target": "esp32s3",
"builds": [
{
"name": "esp-s3-lcd-ev-board-1p4",
"sdkconfig_append": [
"CONFIG_ESP_S3_LCD_EV_Board_1p4=y"
]
},
{
"name": "esp-s3-lcd-ev-board-1p5",
"sdkconfig_append": [
"CONFIG_ESP_S3_LCD_EV_Board_1p5=y"
]
}
]
}

View File

@@ -1,204 +1,204 @@
#include "wifi_board.h"
#include "codecs/box_audio_codec.h"
#include "display/lcd_display.h"
#include "application.h"
#include "button.h"
#include "led/single_led.h"
#include "pin_config.h"
#include "config.h"
#include <wifi_station.h>
#include <esp_log.h>
#include <driver/i2c_master.h>
#include "esp_lcd_gc9503.h"
#include <esp_lcd_panel_io.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lcd_panel_io_additions.h>
#include "esp_io_expander_tca9554.h"
#define TAG "ESP_S3_LCD_EV_Board"
class ESP_S3_LCD_EV_Board : public WifiBoard {
private:
i2c_master_bus_handle_t codec_i2c_bus_;
Button boot_button_;
LcdDisplay* display_;
//add support ev board lcd
esp_io_expander_handle_t expander = NULL;
void InitializeRGB_GC9503V_Display() {
ESP_LOGI(TAG, "Init GC9503V");
esp_lcd_panel_io_handle_t panel_io = nullptr;
//add support ev board lcd
gpio_config_t io_conf = {
.pin_bit_mask = BIT64(GC9503V_PIN_NUM_VSYNC),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
};
gpio_config(&io_conf);
gpio_set_level(GC9503V_PIN_NUM_VSYNC, 1);
ESP_LOGI(TAG, "Install 3-wire SPI panel IO");
spi_line_config_t line_config = {
.cs_io_type = IO_TYPE_EXPANDER,
.cs_expander_pin = GC9503V_LCD_IO_SPI_CS_1,
.scl_io_type = IO_TYPE_EXPANDER,
.scl_expander_pin = GC9503V_LCD_IO_SPI_SCL_1,
.sda_io_type = IO_TYPE_EXPANDER,
.sda_expander_pin = GC9503V_LCD_IO_SPI_SDO_1,
.io_expander = expander,
};
esp_lcd_panel_io_3wire_spi_config_t io_config = GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_config, 0);
int espok = esp_lcd_new_panel_io_3wire_spi(&io_config, &panel_io);
ESP_LOGI(TAG, "Install 3-wire SPI panel IO:%d",espok);
ESP_LOGI(TAG, "Install RGB LCD panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_rgb_panel_config_t rgb_config = {
.clk_src = LCD_CLK_SRC_PLL160M,
//.timings = GC9503_376_960_PANEL_60HZ_RGB_TIMING(),
//add support ev board
.timings = GC9503_480_480_PANEL_60HZ_RGB_TIMING(),
.data_width = 16, // RGB565 in parallel mode, thus 16bit in width
.bits_per_pixel = 16,
.num_fbs = GC9503V_LCD_RGB_BUFFER_NUMS,
.bounce_buffer_size_px = GC9503V_LCD_H_RES * GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT,
.dma_burst_size = 64,
.hsync_gpio_num = GC9503V_PIN_NUM_HSYNC,
.vsync_gpio_num = GC9503V_PIN_NUM_VSYNC,
.de_gpio_num = GC9503V_PIN_NUM_DE,
.pclk_gpio_num = GC9503V_PIN_NUM_PCLK,
.disp_gpio_num = GC9503V_PIN_NUM_DISP_EN,
.data_gpio_nums = {
GC9503V_PIN_NUM_DATA0,
GC9503V_PIN_NUM_DATA1,
GC9503V_PIN_NUM_DATA2,
GC9503V_PIN_NUM_DATA3,
GC9503V_PIN_NUM_DATA4,
GC9503V_PIN_NUM_DATA5,
GC9503V_PIN_NUM_DATA6,
GC9503V_PIN_NUM_DATA7,
GC9503V_PIN_NUM_DATA8,
GC9503V_PIN_NUM_DATA9,
GC9503V_PIN_NUM_DATA10,
GC9503V_PIN_NUM_DATA11,
GC9503V_PIN_NUM_DATA12,
GC9503V_PIN_NUM_DATA13,
GC9503V_PIN_NUM_DATA14,
GC9503V_PIN_NUM_DATA15,
},
.flags= {
.fb_in_psram = true, // allocate frame buffer in PSRAM
}
};
ESP_LOGI(TAG, "Initialize RGB LCD panel");
gc9503_vendor_config_t vendor_config = {
.rgb_config = &rgb_config,
.flags = {
.mirror_by_cmd = 0,
.auto_del_panel_io = 1,
},
};
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = -1,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
// .bits_per_pixel = 16,
//add surpport ev board
.bits_per_pixel = 18,
.vendor_config = &vendor_config,
};
(esp_lcd_new_panel_gc9503(panel_io, &panel_config, &panel_handle));
(esp_lcd_panel_reset(panel_handle));
(esp_lcd_panel_init(panel_handle));
display_ = new RgbLcdDisplay(panel_io, panel_handle,
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X,
DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
}
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_));
//add support ev board lcd amp
//初始化扩展io口
esp_io_expander_new_i2c_tca9554(codec_i2c_bus_, 0x20, &expander);
/* Setup power amplifier pin, set default to enable */
esp_io_expander_set_dir(expander, BSP_POWER_AMP_IO, IO_EXPANDER_OUTPUT);
esp_io_expander_set_level(expander, BSP_POWER_AMP_IO, true);
}
void InitializeButtons() {
boot_button_.OnClick([this]() {
auto& app = Application::GetInstance();
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
ResetWifiConfiguration();
}
});
boot_button_.OnPressDown([this]() {
Application::GetInstance().StartListening();
});
boot_button_.OnPressUp([this]() {
Application::GetInstance().StopListening();
});
}
public:
ESP_S3_LCD_EV_Board() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeCodecI2c();
InitializeButtons();
InitializeRGB_GC9503V_Display();
}
virtual AudioCodec* GetAudioCodec() override {
static BoxAudioCodec audio_codec(
codec_i2c_bus_,
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,
GPIO_NUM_NC,
AUDIO_CODEC_ES8311_ADDR,
AUDIO_CODEC_ES7210_ADDR,
true);
return &audio_codec;
}
virtual Display* GetDisplay() override {
return display_;
}
//添加彩灯显示状态,如果亮度太暗可以去更改默认亮度值 DEFAULT_BRIGHTNESS 在led的sigle_led.cc中
virtual Led* GetLed() override {
static SingleLed led(BUILTIN_LED_GPIO);
return &led;
}
};
DECLARE_BOARD(ESP_S3_LCD_EV_Board);
#include "wifi_board.h"
#include "codecs/box_audio_codec.h"
#include "display/lcd_display.h"
#include "application.h"
#include "button.h"
#include "led/single_led.h"
#include "pin_config.h"
#include "config.h"
#include <wifi_station.h>
#include <esp_log.h>
#include <driver/i2c_master.h>
#include "esp_lcd_gc9503.h"
#include <esp_lcd_panel_io.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lcd_panel_io_additions.h>
#include "esp_io_expander_tca9554.h"
#define TAG "ESP_S3_LCD_EV_Board"
class ESP_S3_LCD_EV_Board : public WifiBoard {
private:
i2c_master_bus_handle_t codec_i2c_bus_;
Button boot_button_;
LcdDisplay* display_;
//add support ev board lcd
esp_io_expander_handle_t expander = NULL;
void InitializeRGB_GC9503V_Display() {
ESP_LOGI(TAG, "Init GC9503V");
esp_lcd_panel_io_handle_t panel_io = nullptr;
//add support ev board lcd
gpio_config_t io_conf = {
.pin_bit_mask = BIT64(GC9503V_PIN_NUM_VSYNC),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
};
gpio_config(&io_conf);
gpio_set_level(GC9503V_PIN_NUM_VSYNC, 1);
ESP_LOGI(TAG, "Install 3-wire SPI panel IO");
spi_line_config_t line_config = {
.cs_io_type = IO_TYPE_EXPANDER,
.cs_expander_pin = GC9503V_LCD_IO_SPI_CS_1,
.scl_io_type = IO_TYPE_EXPANDER,
.scl_expander_pin = GC9503V_LCD_IO_SPI_SCL_1,
.sda_io_type = IO_TYPE_EXPANDER,
.sda_expander_pin = GC9503V_LCD_IO_SPI_SDO_1,
.io_expander = expander,
};
esp_lcd_panel_io_3wire_spi_config_t io_config = GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_config, 0);
int espok = esp_lcd_new_panel_io_3wire_spi(&io_config, &panel_io);
ESP_LOGI(TAG, "Install 3-wire SPI panel IO:%d",espok);
ESP_LOGI(TAG, "Install RGB LCD panel driver");
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_rgb_panel_config_t rgb_config = {
.clk_src = LCD_CLK_SRC_PLL160M,
//.timings = GC9503_376_960_PANEL_60HZ_RGB_TIMING(),
//add support ev board
.timings = GC9503_480_480_PANEL_60HZ_RGB_TIMING(),
.data_width = 16, // RGB565 in parallel mode, thus 16bit in width
.bits_per_pixel = 16,
.num_fbs = GC9503V_LCD_RGB_BUFFER_NUMS,
.bounce_buffer_size_px = GC9503V_LCD_H_RES * GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT,
.dma_burst_size = 64,
.hsync_gpio_num = GC9503V_PIN_NUM_HSYNC,
.vsync_gpio_num = GC9503V_PIN_NUM_VSYNC,
.de_gpio_num = GC9503V_PIN_NUM_DE,
.pclk_gpio_num = GC9503V_PIN_NUM_PCLK,
.disp_gpio_num = GC9503V_PIN_NUM_DISP_EN,
.data_gpio_nums = {
GC9503V_PIN_NUM_DATA0,
GC9503V_PIN_NUM_DATA1,
GC9503V_PIN_NUM_DATA2,
GC9503V_PIN_NUM_DATA3,
GC9503V_PIN_NUM_DATA4,
GC9503V_PIN_NUM_DATA5,
GC9503V_PIN_NUM_DATA6,
GC9503V_PIN_NUM_DATA7,
GC9503V_PIN_NUM_DATA8,
GC9503V_PIN_NUM_DATA9,
GC9503V_PIN_NUM_DATA10,
GC9503V_PIN_NUM_DATA11,
GC9503V_PIN_NUM_DATA12,
GC9503V_PIN_NUM_DATA13,
GC9503V_PIN_NUM_DATA14,
GC9503V_PIN_NUM_DATA15,
},
.flags= {
.fb_in_psram = true, // allocate frame buffer in PSRAM
}
};
ESP_LOGI(TAG, "Initialize RGB LCD panel");
gc9503_vendor_config_t vendor_config = {
.rgb_config = &rgb_config,
.flags = {
.mirror_by_cmd = 0,
.auto_del_panel_io = 1,
},
};
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = -1,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
// .bits_per_pixel = 16,
//add surpport ev board
.bits_per_pixel = 18,
.vendor_config = &vendor_config,
};
(esp_lcd_new_panel_gc9503(panel_io, &panel_config, &panel_handle));
(esp_lcd_panel_reset(panel_handle));
(esp_lcd_panel_init(panel_handle));
display_ = new RgbLcdDisplay(panel_io, panel_handle,
DISPLAY_WIDTH, DISPLAY_HEIGHT, DISPLAY_OFFSET_X, DISPLAY_OFFSET_Y, DISPLAY_MIRROR_X,
DISPLAY_MIRROR_Y, DISPLAY_SWAP_XY);
}
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_));
//add support ev board lcd amp
//初始化扩展io口
esp_io_expander_new_i2c_tca9554(codec_i2c_bus_, 0x20, &expander);
/* Setup power amplifier pin, set default to enable */
esp_io_expander_set_dir(expander, BSP_POWER_AMP_IO, IO_EXPANDER_OUTPUT);
esp_io_expander_set_level(expander, BSP_POWER_AMP_IO, true);
}
void InitializeButtons() {
boot_button_.OnClick([this]() {
auto& app = Application::GetInstance();
if (app.GetDeviceState() == kDeviceStateStarting && !WifiStation::GetInstance().IsConnected()) {
ResetWifiConfiguration();
}
});
boot_button_.OnPressDown([this]() {
Application::GetInstance().StartListening();
});
boot_button_.OnPressUp([this]() {
Application::GetInstance().StopListening();
});
}
public:
ESP_S3_LCD_EV_Board() : boot_button_(BOOT_BUTTON_GPIO) {
InitializeCodecI2c();
InitializeButtons();
InitializeRGB_GC9503V_Display();
}
virtual AudioCodec* GetAudioCodec() override {
static BoxAudioCodec audio_codec(
codec_i2c_bus_,
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,
GPIO_NUM_NC,
AUDIO_CODEC_ES8311_ADDR,
AUDIO_CODEC_ES7210_ADDR,
true);
return &audio_codec;
}
virtual Display* GetDisplay() override {
return display_;
}
//添加彩灯显示状态,如果亮度太暗可以去更改默认亮度值 DEFAULT_BRIGHTNESS 在led的sigle_led.cc中
virtual Led* GetLed() override {
static SingleLed led(BUILTIN_LED_GPIO);
return &led;
}
};
DECLARE_BOARD(ESP_S3_LCD_EV_Board);

View File

@@ -1,154 +1,154 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include "esp_bit_defs.h"
#include "esp_check.h"
#include "esp_log.h"
#include "esp_io_expander.h"
#include "esp_io_expander_tca9554.h"
/* I2C communication related */
#define I2C_TIMEOUT_MS (1000)
#define I2C_CLK_SPEED (400000)
#define IO_COUNT (8)
/* Register address */
#define INPUT_REG_ADDR (0x00)
#define OUTPUT_REG_ADDR (0x01)
#define DIRECTION_REG_ADDR (0x03)
/* Default register value on power-up */
#define DIR_REG_DEFAULT_VAL (0xff)
#define OUT_REG_DEFAULT_VAL (0xff)
/**
* @brief Device Structure Type
*
*/
typedef struct {
esp_io_expander_t base;
i2c_master_dev_handle_t i2c_handle;
struct {
uint8_t direction;
uint8_t output;
} regs;
} esp_io_expander_tca9554_t;
static char *TAG = "tca9554";
static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value);
static esp_err_t write_output_reg(esp_io_expander_handle_t handle, uint32_t value);
static esp_err_t read_output_reg(esp_io_expander_handle_t handle, uint32_t *value);
static esp_err_t write_direction_reg(esp_io_expander_handle_t handle, uint32_t value);
static esp_err_t read_direction_reg(esp_io_expander_handle_t handle, uint32_t *value);
static esp_err_t reset(esp_io_expander_t *handle);
static esp_err_t del(esp_io_expander_t *handle);
esp_err_t esp_io_expander_new_i2c_tca9554(i2c_master_bus_handle_t i2c_bus, uint32_t dev_addr, esp_io_expander_handle_t *handle_ret)
{
ESP_RETURN_ON_FALSE(handle_ret != NULL, ESP_ERR_INVALID_ARG, TAG, "Invalid handle_ret");
// Allocate memory for driver object
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)calloc(1, sizeof(esp_io_expander_tca9554_t));
ESP_RETURN_ON_FALSE(tca9554 != NULL, ESP_ERR_NO_MEM, TAG, "Malloc failed");
// Add new I2C device
esp_err_t ret = ESP_OK;
const i2c_device_config_t i2c_dev_cfg = {
.device_address = dev_addr,
.scl_speed_hz = I2C_CLK_SPEED,
};
ESP_GOTO_ON_ERROR(i2c_master_bus_add_device(i2c_bus, &i2c_dev_cfg, &tca9554->i2c_handle), err, TAG, "Add new I2C device failed");
tca9554->base.config.io_count = IO_COUNT;
tca9554->base.config.flags.dir_out_bit_zero = 1;
tca9554->base.read_input_reg = read_input_reg;
tca9554->base.write_output_reg = write_output_reg;
tca9554->base.read_output_reg = read_output_reg;
tca9554->base.write_direction_reg = write_direction_reg;
tca9554->base.read_direction_reg = read_direction_reg;
tca9554->base.del = del;
tca9554->base.reset = reset;
/* Reset configuration and register status */
ESP_GOTO_ON_ERROR(reset(&tca9554->base), err, TAG, "Reset failed");
*handle_ret = &tca9554->base;
return ESP_OK;
err:
free(tca9554);
return ret;
}
static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
uint8_t temp = 0;
ESP_RETURN_ON_ERROR(i2c_master_transmit_receive(tca9554->i2c_handle, (uint8_t[]) {
INPUT_REG_ADDR
}, 1, &temp, sizeof(temp), I2C_TIMEOUT_MS), TAG, "Read input reg failed");
*value = temp;
return ESP_OK;
}
static esp_err_t write_output_reg(esp_io_expander_handle_t handle, uint32_t value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
value &= 0xff;
uint8_t data[] = {OUTPUT_REG_ADDR, value};
ESP_RETURN_ON_ERROR(i2c_master_transmit(tca9554->i2c_handle, data, sizeof(data), I2C_TIMEOUT_MS), TAG, "Write output reg failed");
tca9554->regs.output = value;
return ESP_OK;
}
static esp_err_t read_output_reg(esp_io_expander_handle_t handle, uint32_t *value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
*value = tca9554->regs.output;
return ESP_OK;
}
static esp_err_t write_direction_reg(esp_io_expander_handle_t handle, uint32_t value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
value &= 0xff;
uint8_t data[] = {DIRECTION_REG_ADDR, value};
ESP_RETURN_ON_ERROR(i2c_master_transmit(tca9554->i2c_handle, data, sizeof(data), I2C_TIMEOUT_MS), TAG, "Write direction reg failed");
tca9554->regs.direction = value;
return ESP_OK;
}
static esp_err_t read_direction_reg(esp_io_expander_handle_t handle, uint32_t *value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
*value = tca9554->regs.direction;
return ESP_OK;
}
static esp_err_t reset(esp_io_expander_t *handle)
{
ESP_RETURN_ON_ERROR(write_direction_reg(handle, DIR_REG_DEFAULT_VAL), TAG, "Write dir reg failed");
ESP_RETURN_ON_ERROR(write_output_reg(handle, OUT_REG_DEFAULT_VAL), TAG, "Write output reg failed");
return ESP_OK;
}
static esp_err_t del(esp_io_expander_t *handle)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
ESP_RETURN_ON_ERROR(i2c_master_bus_rm_device(tca9554->i2c_handle), TAG, "Remove I2C device failed");
free(tca9554);
return ESP_OK;
}
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#include "esp_bit_defs.h"
#include "esp_check.h"
#include "esp_log.h"
#include "esp_io_expander.h"
#include "esp_io_expander_tca9554.h"
/* I2C communication related */
#define I2C_TIMEOUT_MS (1000)
#define I2C_CLK_SPEED (400000)
#define IO_COUNT (8)
/* Register address */
#define INPUT_REG_ADDR (0x00)
#define OUTPUT_REG_ADDR (0x01)
#define DIRECTION_REG_ADDR (0x03)
/* Default register value on power-up */
#define DIR_REG_DEFAULT_VAL (0xff)
#define OUT_REG_DEFAULT_VAL (0xff)
/**
* @brief Device Structure Type
*
*/
typedef struct {
esp_io_expander_t base;
i2c_master_dev_handle_t i2c_handle;
struct {
uint8_t direction;
uint8_t output;
} regs;
} esp_io_expander_tca9554_t;
static char *TAG = "tca9554";
static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value);
static esp_err_t write_output_reg(esp_io_expander_handle_t handle, uint32_t value);
static esp_err_t read_output_reg(esp_io_expander_handle_t handle, uint32_t *value);
static esp_err_t write_direction_reg(esp_io_expander_handle_t handle, uint32_t value);
static esp_err_t read_direction_reg(esp_io_expander_handle_t handle, uint32_t *value);
static esp_err_t reset(esp_io_expander_t *handle);
static esp_err_t del(esp_io_expander_t *handle);
esp_err_t esp_io_expander_new_i2c_tca9554(i2c_master_bus_handle_t i2c_bus, uint32_t dev_addr, esp_io_expander_handle_t *handle_ret)
{
ESP_RETURN_ON_FALSE(handle_ret != NULL, ESP_ERR_INVALID_ARG, TAG, "Invalid handle_ret");
// Allocate memory for driver object
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)calloc(1, sizeof(esp_io_expander_tca9554_t));
ESP_RETURN_ON_FALSE(tca9554 != NULL, ESP_ERR_NO_MEM, TAG, "Malloc failed");
// Add new I2C device
esp_err_t ret = ESP_OK;
const i2c_device_config_t i2c_dev_cfg = {
.device_address = dev_addr,
.scl_speed_hz = I2C_CLK_SPEED,
};
ESP_GOTO_ON_ERROR(i2c_master_bus_add_device(i2c_bus, &i2c_dev_cfg, &tca9554->i2c_handle), err, TAG, "Add new I2C device failed");
tca9554->base.config.io_count = IO_COUNT;
tca9554->base.config.flags.dir_out_bit_zero = 1;
tca9554->base.read_input_reg = read_input_reg;
tca9554->base.write_output_reg = write_output_reg;
tca9554->base.read_output_reg = read_output_reg;
tca9554->base.write_direction_reg = write_direction_reg;
tca9554->base.read_direction_reg = read_direction_reg;
tca9554->base.del = del;
tca9554->base.reset = reset;
/* Reset configuration and register status */
ESP_GOTO_ON_ERROR(reset(&tca9554->base), err, TAG, "Reset failed");
*handle_ret = &tca9554->base;
return ESP_OK;
err:
free(tca9554);
return ret;
}
static esp_err_t read_input_reg(esp_io_expander_handle_t handle, uint32_t *value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
uint8_t temp = 0;
ESP_RETURN_ON_ERROR(i2c_master_transmit_receive(tca9554->i2c_handle, (uint8_t[]) {
INPUT_REG_ADDR
}, 1, &temp, sizeof(temp), I2C_TIMEOUT_MS), TAG, "Read input reg failed");
*value = temp;
return ESP_OK;
}
static esp_err_t write_output_reg(esp_io_expander_handle_t handle, uint32_t value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
value &= 0xff;
uint8_t data[] = {OUTPUT_REG_ADDR, value};
ESP_RETURN_ON_ERROR(i2c_master_transmit(tca9554->i2c_handle, data, sizeof(data), I2C_TIMEOUT_MS), TAG, "Write output reg failed");
tca9554->regs.output = value;
return ESP_OK;
}
static esp_err_t read_output_reg(esp_io_expander_handle_t handle, uint32_t *value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
*value = tca9554->regs.output;
return ESP_OK;
}
static esp_err_t write_direction_reg(esp_io_expander_handle_t handle, uint32_t value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
value &= 0xff;
uint8_t data[] = {DIRECTION_REG_ADDR, value};
ESP_RETURN_ON_ERROR(i2c_master_transmit(tca9554->i2c_handle, data, sizeof(data), I2C_TIMEOUT_MS), TAG, "Write direction reg failed");
tca9554->regs.direction = value;
return ESP_OK;
}
static esp_err_t read_direction_reg(esp_io_expander_handle_t handle, uint32_t *value)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
*value = tca9554->regs.direction;
return ESP_OK;
}
static esp_err_t reset(esp_io_expander_t *handle)
{
ESP_RETURN_ON_ERROR(write_direction_reg(handle, DIR_REG_DEFAULT_VAL), TAG, "Write dir reg failed");
ESP_RETURN_ON_ERROR(write_output_reg(handle, OUT_REG_DEFAULT_VAL), TAG, "Write output reg failed");
return ESP_OK;
}
static esp_err_t del(esp_io_expander_t *handle)
{
esp_io_expander_tca9554_t *tca9554 = (esp_io_expander_tca9554_t *)__containerof(handle, esp_io_expander_tca9554_t, base);
ESP_RETURN_ON_ERROR(i2c_master_bus_rm_device(tca9554->i2c_handle), TAG, "Remove I2C device failed");
free(tca9554);
return ESP_OK;
}

View File

@@ -1,90 +1,90 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP IO expander: TCA9554
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "driver/i2c_master.h"
#include "esp_io_expander.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Create a TCA9554(A) IO expander object
*
* @param[in] i2c_bus I2C bus handle. Obtained from `i2c_new_master_bus()`
* @param[in] dev_addr I2C device address of chip. Can be `ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_XXX` or `ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_XXX`.
* @param[out] handle_ret Handle to created IO expander object
*
* @return
* - ESP_OK: Success, otherwise returns ESP_ERR_xxx
*/
esp_err_t esp_io_expander_new_i2c_tca9554(i2c_master_bus_handle_t i2c_bus, uint32_t dev_addr, esp_io_expander_handle_t *handle_ret);
/**
* @brief I2C address of the TCA9554
*
* The 8-bit address format is as follows:
*
* (Slave Address)
* ┌─────────────────┷─────────────────┐
* ┌─────┐─────┐─────┐─────┐─────┐─────┐─────┐─────┐
* | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W |
* └─────┘─────┘─────┘─────┘─────┘─────┘─────┘─────┘
* └────────┯────────┘ └─────┯──────┘
* (Fixed) (Hareware Selectable)
*
* And the 7-bit slave address is the most important data for users.
* For example, if a chip's A0,A1,A2 are connected to GND, it's 7-bit slave address is 0100000b(0x20).
* Then users can use `ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000` to init it.
*/
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000 (0x20)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_001 (0x21)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_010 (0x22)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_011 (0x23)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_100 (0x24)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_101 (0x25)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_110 (0x26)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_111 (0x27)
/**
* @brief I2C address of the TCA9554A
*
* The 8-bit address format is as follows:
*
* (Slave Address)
* ┌─────────────────┷─────────────────┐
* ┌─────┐─────┐─────┐─────┐─────┐─────┐─────┐─────┐
* | 0 | 1 | 1 | 1 | A2 | A1 | A0 | R/W |
* └─────┘─────┘─────┘─────┘─────┘─────┘─────┘─────┘
* └────────┯────────┘ └─────┯──────┘
* (Fixed) (Hareware Selectable)
*
* And the 7-bit slave address is the most important data for users.
* For example, if a chip's A0,A1,A2 are connected to GND, it's 7-bit slave address is 0111000b(0x38).
* Then users can use `ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_000` to init it.
*/
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_000 (0x38)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_001 (0x39)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_010 (0x3A)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_011 (0x3B)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_100 (0x3C)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_101 (0x3D)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_110 (0x3E)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_111 (0x3F)
#ifdef __cplusplus
}
#endif
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP IO expander: TCA9554
*/
#pragma once
#include <stdint.h>
#include "esp_err.h"
#include "driver/i2c_master.h"
#include "esp_io_expander.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Create a TCA9554(A) IO expander object
*
* @param[in] i2c_bus I2C bus handle. Obtained from `i2c_new_master_bus()`
* @param[in] dev_addr I2C device address of chip. Can be `ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_XXX` or `ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_XXX`.
* @param[out] handle_ret Handle to created IO expander object
*
* @return
* - ESP_OK: Success, otherwise returns ESP_ERR_xxx
*/
esp_err_t esp_io_expander_new_i2c_tca9554(i2c_master_bus_handle_t i2c_bus, uint32_t dev_addr, esp_io_expander_handle_t *handle_ret);
/**
* @brief I2C address of the TCA9554
*
* The 8-bit address format is as follows:
*
* (Slave Address)
* ┌─────────────────┷─────────────────┐
* ┌─────┐─────┐─────┐─────┐─────┐─────┐─────┐─────┐
* | 0 | 1 | 0 | 0 | A2 | A1 | A0 | R/W |
* └─────┘─────┘─────┘─────┘─────┘─────┘─────┘─────┘
* └────────┯────────┘ └─────┯──────┘
* (Fixed) (Hareware Selectable)
*
* And the 7-bit slave address is the most important data for users.
* For example, if a chip's A0,A1,A2 are connected to GND, it's 7-bit slave address is 0100000b(0x20).
* Then users can use `ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000` to init it.
*/
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_000 (0x20)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_001 (0x21)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_010 (0x22)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_011 (0x23)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_100 (0x24)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_101 (0x25)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_110 (0x26)
#define ESP_IO_EXPANDER_I2C_TCA9554_ADDRESS_111 (0x27)
/**
* @brief I2C address of the TCA9554A
*
* The 8-bit address format is as follows:
*
* (Slave Address)
* ┌─────────────────┷─────────────────┐
* ┌─────┐─────┐─────┐─────┐─────┐─────┐─────┐─────┐
* | 0 | 1 | 1 | 1 | A2 | A1 | A0 | R/W |
* └─────┘─────┘─────┘─────┘─────┘─────┘─────┘─────┘
* └────────┯────────┘ └─────┯──────┘
* (Fixed) (Hareware Selectable)
*
* And the 7-bit slave address is the most important data for users.
* For example, if a chip's A0,A1,A2 are connected to GND, it's 7-bit slave address is 0111000b(0x38).
* Then users can use `ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_000` to init it.
*/
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_000 (0x38)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_001 (0x39)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_010 (0x3A)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_011 (0x3B)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_100 (0x3C)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_101 (0x3D)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_110 (0x3E)
#define ESP_IO_EXPANDER_I2C_TCA9554A_ADDRESS_111 (0x3F)
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,167 +1,167 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LCD: GC9503
*/
#pragma once
#include <stdint.h>
#include <esp_lcd_panel_vendor.h>
#include <esp_lcd_panel_rgb.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief LCD panel initialization commands.
*
*/
typedef struct {
int cmd; /*<! The specific LCD command */
const void *data; /*<! Buffer that holds the command specific data */
size_t data_bytes; /*<! Size of `data` in memory, in bytes */
unsigned int delay_ms; /*<! Delay in milliseconds after this command */
} gc9503_lcd_init_cmd_t;
/**
* @brief LCD panel vendor configuration.
*
* @note This structure needs to be passed to the `vendor_config` field in `esp_lcd_panel_dev_config_t`.
*
*/
typedef struct {
const esp_lcd_rgb_panel_config_t *rgb_config; /*!< RGB panel configuration */
const gc9503_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array. Set to NULL if using default commands.
* The array should be declared as `static const` and positioned outside the function.
* Please refer to `vendor_specific_init_default` in source file.
*/
uint16_t init_cmds_size; /*<! Number of commands in above array */
struct {
unsigned int mirror_by_cmd: 1; /*<! The `mirror()` function will be implemented by LCD command if set to 1.
* Otherwise, the function will be implemented by software.
*/
unsigned int auto_del_panel_io: 1; /*<! Delete the panel IO instance automatically if set to 1. All `*_by_cmd` flags will be invalid.
* If the panel IO pins are sharing other pins of the RGB interface to save GPIOs,
* Please set it to 1 to release the panel IO and its pins (except CS signal).
*/
} flags;
} gc9503_vendor_config_t;
/**
* @brief Create LCD panel for model GC9503
*
* @note When `auto_del_panel_io` is set to 1, this function will first initialize the GC9503 with vendor specific initialization and then calls `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will only initialize RGB.
* @note When `auto_del_panel_io` is set to 0, this function will only call `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will initialize both the GC9503 and RGB.
* @note Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for initialization sequence code.
*
* @param[in] io LCD panel IO handle
* @param[in] panel_dev_config General panel device configuration (`vendor_config` and `rgb_config` are necessary)
* @param[out] ret_panel Returned LCD panel handle
* @return
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_OK on success
* - Otherwise on fail
*/
esp_err_t esp_lcd_new_panel_gc9503(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config,
esp_lcd_panel_handle_t *ret_panel);
/**
* @brief 3-wire SPI panel IO configuration structure
*
* @param[in] line_cfg SPI line configuration
* @param[in] scl_active_edge SCL signal active edge, 0: rising edge, 1: falling edge
*
*/
#define GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_cfg, scl_active_edge) \
{ \
.line_config = line_cfg, \
.expect_clk_speed = PANEL_IO_3WIRE_SPI_CLK_MAX, \
.spi_mode = scl_active_edge ? 1 : 0, \
.lcd_cmd_bytes = 1, \
.lcd_param_bytes = 1, \
.flags = { \
.use_dc_bit = 1, \
.dc_zero_on_data = 0, \
.lsb_first = 0, \
.cs_high_active = 0, \
.del_keep_cs_inactive = 1, \
}, \
}
/**
* @brief RGB timing structure
*
* @note refresh_rate = (pclk_hz * data_width) / (h_res + hsync_pulse_width + hsync_back_porch + hsync_front_porch)
* / (v_res + vsync_pulse_width + vsync_back_porch + vsync_front_porch)
* / bits_per_pixel
* .pclk_hz = 16 * 1000 * 1000, \
.h_res = 384, \
.v_res = 960, \
.hsync_pulse_width = 24, \
.hsync_back_porch = 20, \
.hsync_front_porch = 40, \
.vsync_pulse_width = 30, \
.vsync_back_porch = 18, \
.vsync_front_porch = 20, \
.flags.pclk_active_neg = 0, \
.hsync_pulse_width = 24, \
.hsync_back_porch = 20, \
.hsync_front_porch = 40, \
.vsync_pulse_width = 30, \
.vsync_back_porch = 18, \
.vsync_front_porch = 20, \
*/
#define GC9503_480_480_PANEL_60HZ_RGB_TIMING() \
{ \
.pclk_hz = 16 * 1000 * 1000, \
.h_res = 480, \
.v_res = 480, \
.hsync_pulse_width = 10, \
.hsync_back_porch = 10, \
.hsync_front_porch = 20, \
.vsync_pulse_width = 10, \
.vsync_back_porch = 10, \
.vsync_front_porch = 10, \
.flags = { \
.hsync_idle_low = 0, \
.vsync_idle_low = 0, \
.de_idle_high = 0, \
.pclk_active_neg = 0, \
.pclk_idle_high = 0, \
}, \
}
#define GC9503_376_960_PANEL_60HZ_RGB_TIMING() \
{ \
.pclk_hz = 16 * 1000 * 1000, \
.h_res = 376, \
.v_res = 960, \
.hsync_pulse_width = 8, \
.hsync_back_porch = 30, \
.hsync_front_porch = 30, \
.vsync_pulse_width = 8, \
.vsync_back_porch = 16, \
.vsync_front_porch = 16, \
.flags = { \
.hsync_idle_low = 0, \
.vsync_idle_low = 0, \
.de_idle_high = 0, \
.pclk_active_neg = 0, \
.pclk_idle_high = 0, \
}, \
}
#ifdef __cplusplus
}
#endif
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief ESP LCD: GC9503
*/
#pragma once
#include <stdint.h>
#include <esp_lcd_panel_vendor.h>
#include <esp_lcd_panel_rgb.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief LCD panel initialization commands.
*
*/
typedef struct {
int cmd; /*<! The specific LCD command */
const void *data; /*<! Buffer that holds the command specific data */
size_t data_bytes; /*<! Size of `data` in memory, in bytes */
unsigned int delay_ms; /*<! Delay in milliseconds after this command */
} gc9503_lcd_init_cmd_t;
/**
* @brief LCD panel vendor configuration.
*
* @note This structure needs to be passed to the `vendor_config` field in `esp_lcd_panel_dev_config_t`.
*
*/
typedef struct {
const esp_lcd_rgb_panel_config_t *rgb_config; /*!< RGB panel configuration */
const gc9503_lcd_init_cmd_t *init_cmds; /*!< Pointer to initialization commands array. Set to NULL if using default commands.
* The array should be declared as `static const` and positioned outside the function.
* Please refer to `vendor_specific_init_default` in source file.
*/
uint16_t init_cmds_size; /*<! Number of commands in above array */
struct {
unsigned int mirror_by_cmd: 1; /*<! The `mirror()` function will be implemented by LCD command if set to 1.
* Otherwise, the function will be implemented by software.
*/
unsigned int auto_del_panel_io: 1; /*<! Delete the panel IO instance automatically if set to 1. All `*_by_cmd` flags will be invalid.
* If the panel IO pins are sharing other pins of the RGB interface to save GPIOs,
* Please set it to 1 to release the panel IO and its pins (except CS signal).
*/
} flags;
} gc9503_vendor_config_t;
/**
* @brief Create LCD panel for model GC9503
*
* @note When `auto_del_panel_io` is set to 1, this function will first initialize the GC9503 with vendor specific initialization and then calls `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will only initialize RGB.
* @note When `auto_del_panel_io` is set to 0, this function will only call `esp_lcd_new_rgb_panel()` to create an RGB LCD panel. And the `esp_lcd_panel_init()` function will initialize both the GC9503 and RGB.
* @note Vendor specific initialization can be different between manufacturers, should consult the LCD supplier for initialization sequence code.
*
* @param[in] io LCD panel IO handle
* @param[in] panel_dev_config General panel device configuration (`vendor_config` and `rgb_config` are necessary)
* @param[out] ret_panel Returned LCD panel handle
* @return
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_OK on success
* - Otherwise on fail
*/
esp_err_t esp_lcd_new_panel_gc9503(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *panel_dev_config,
esp_lcd_panel_handle_t *ret_panel);
/**
* @brief 3-wire SPI panel IO configuration structure
*
* @param[in] line_cfg SPI line configuration
* @param[in] scl_active_edge SCL signal active edge, 0: rising edge, 1: falling edge
*
*/
#define GC9503_PANEL_IO_3WIRE_SPI_CONFIG(line_cfg, scl_active_edge) \
{ \
.line_config = line_cfg, \
.expect_clk_speed = PANEL_IO_3WIRE_SPI_CLK_MAX, \
.spi_mode = scl_active_edge ? 1 : 0, \
.lcd_cmd_bytes = 1, \
.lcd_param_bytes = 1, \
.flags = { \
.use_dc_bit = 1, \
.dc_zero_on_data = 0, \
.lsb_first = 0, \
.cs_high_active = 0, \
.del_keep_cs_inactive = 1, \
}, \
}
/**
* @brief RGB timing structure
*
* @note refresh_rate = (pclk_hz * data_width) / (h_res + hsync_pulse_width + hsync_back_porch + hsync_front_porch)
* / (v_res + vsync_pulse_width + vsync_back_porch + vsync_front_porch)
* / bits_per_pixel
* .pclk_hz = 16 * 1000 * 1000, \
.h_res = 384, \
.v_res = 960, \
.hsync_pulse_width = 24, \
.hsync_back_porch = 20, \
.hsync_front_porch = 40, \
.vsync_pulse_width = 30, \
.vsync_back_porch = 18, \
.vsync_front_porch = 20, \
.flags.pclk_active_neg = 0, \
.hsync_pulse_width = 24, \
.hsync_back_porch = 20, \
.hsync_front_porch = 40, \
.vsync_pulse_width = 30, \
.vsync_back_porch = 18, \
.vsync_front_porch = 20, \
*/
#define GC9503_480_480_PANEL_60HZ_RGB_TIMING() \
{ \
.pclk_hz = 16 * 1000 * 1000, \
.h_res = 480, \
.v_res = 480, \
.hsync_pulse_width = 10, \
.hsync_back_porch = 10, \
.hsync_front_porch = 20, \
.vsync_pulse_width = 10, \
.vsync_back_porch = 10, \
.vsync_front_porch = 10, \
.flags = { \
.hsync_idle_low = 0, \
.vsync_idle_low = 0, \
.de_idle_high = 0, \
.pclk_active_neg = 0, \
.pclk_idle_high = 0, \
}, \
}
#define GC9503_376_960_PANEL_60HZ_RGB_TIMING() \
{ \
.pclk_hz = 16 * 1000 * 1000, \
.h_res = 376, \
.v_res = 960, \
.hsync_pulse_width = 8, \
.hsync_back_porch = 30, \
.hsync_front_porch = 30, \
.vsync_pulse_width = 8, \
.vsync_back_porch = 16, \
.vsync_front_porch = 16, \
.flags = { \
.hsync_idle_low = 0, \
.vsync_idle_low = 0, \
.de_idle_high = 0, \
.pclk_active_neg = 0, \
.pclk_idle_high = 0, \
}, \
}
#ifdef __cplusplus
}
#endif

View File

@@ -1,62 +1,62 @@
#pragma once
//关于开发板和屏幕的资料参考
//https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32s3/esp32-s3-lcd-ev-board/user_guide.html
#define GC9503V_LCD_H_RES 480
#define GC9503V_LCD_V_RES 480
#define GC9503V_LCD_LVGL_DIRECT_MODE (1)
#define GC9503V_LCD_LVGL_AVOID_TEAR (1)
#define GC9503V_LCD_RGB_BOUNCE_BUFFER_MODE (1)
#define GC9503V_LCD_DRAW_BUFF_DOUBLE (0)
#define GC9503V_LCD_DRAW_BUFF_HEIGHT (100)
#define GC9503V_LCD_RGB_BUFFER_NUMS (2)
#define GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT (10)
#define GC9503V_LCD_PIXEL_CLOCK_HZ (16 * 1000 * 1000)
#define GC9503V_LCD_BK_LIGHT_ON_LEVEL 1
#define GC9503V_LCD_BK_LIGHT_OFF_LEVEL !GC9503V_LCD_BK_LIGHT_ON_LEVEL
#define GC9503V_PIN_NUM_BK_LIGHT GPIO_NUM_NC //GPIO_NUM_4
#define GC9503V_PIN_NUM_HSYNC GPIO_NUM_46
#define GC9503V_PIN_NUM_VSYNC GPIO_NUM_3
#define GC9503V_PIN_NUM_DE GPIO_NUM_17
#define GC9503V_PIN_NUM_PCLK GPIO_NUM_9
#define GC9503V_PIN_NUM_DATA0 GPIO_NUM_10 // B0
#define GC9503V_PIN_NUM_DATA1 GPIO_NUM_11 // B1
#define GC9503V_PIN_NUM_DATA2 GPIO_NUM_12 // B2
#define GC9503V_PIN_NUM_DATA3 GPIO_NUM_13 // B3
#define GC9503V_PIN_NUM_DATA4 GPIO_NUM_14 // B4
#define GC9503V_PIN_NUM_DATA5 GPIO_NUM_21 // G0
//如果开发板是V1.4 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p4
#define GC9503V_PIN_NUM_DATA6 GPIO_NUM_47 // G1
#define GC9503V_PIN_NUM_DATA7 GPIO_NUM_48 // G2
#endif
//如果开发板是V1.5 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p5
#define GC9503V_PIN_NUM_DATA6 GPIO_NUM_8 // G1
#define GC9503V_PIN_NUM_DATA7 GPIO_NUM_18 // G2
#endif
#define GC9503V_PIN_NUM_DATA8 GPIO_NUM_45 // G3
#define GC9503V_PIN_NUM_DATA9 GPIO_NUM_38 // G4
#define GC9503V_PIN_NUM_DATA10 GPIO_NUM_39 // G5
#define GC9503V_PIN_NUM_DATA11 GPIO_NUM_40 // R0
#define GC9503V_PIN_NUM_DATA12 GPIO_NUM_41 // R1
#define GC9503V_PIN_NUM_DATA13 GPIO_NUM_42 // R2
#define GC9503V_PIN_NUM_DATA14 GPIO_NUM_2 // R3
#define GC9503V_PIN_NUM_DATA15 GPIO_NUM_1 // R4
#define GC9503V_PIN_NUM_DISP_EN -1
#define GC9503V_LCD_IO_SPI_CS_1 (IO_EXPANDER_PIN_NUM_1)
#define GC9503V_LCD_IO_SPI_SCL_1 (IO_EXPANDER_PIN_NUM_2)
#pragma once
//关于开发板和屏幕的资料参考
//https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32s3/esp32-s3-lcd-ev-board/user_guide.html
#define GC9503V_LCD_H_RES 480
#define GC9503V_LCD_V_RES 480
#define GC9503V_LCD_LVGL_DIRECT_MODE (1)
#define GC9503V_LCD_LVGL_AVOID_TEAR (1)
#define GC9503V_LCD_RGB_BOUNCE_BUFFER_MODE (1)
#define GC9503V_LCD_DRAW_BUFF_DOUBLE (0)
#define GC9503V_LCD_DRAW_BUFF_HEIGHT (100)
#define GC9503V_LCD_RGB_BUFFER_NUMS (2)
#define GC9503V_LCD_RGB_BOUNCE_BUFFER_HEIGHT (10)
#define GC9503V_LCD_PIXEL_CLOCK_HZ (16 * 1000 * 1000)
#define GC9503V_LCD_BK_LIGHT_ON_LEVEL 1
#define GC9503V_LCD_BK_LIGHT_OFF_LEVEL !GC9503V_LCD_BK_LIGHT_ON_LEVEL
#define GC9503V_PIN_NUM_BK_LIGHT GPIO_NUM_NC //GPIO_NUM_4
#define GC9503V_PIN_NUM_HSYNC GPIO_NUM_46
#define GC9503V_PIN_NUM_VSYNC GPIO_NUM_3
#define GC9503V_PIN_NUM_DE GPIO_NUM_17
#define GC9503V_PIN_NUM_PCLK GPIO_NUM_9
#define GC9503V_PIN_NUM_DATA0 GPIO_NUM_10 // B0
#define GC9503V_PIN_NUM_DATA1 GPIO_NUM_11 // B1
#define GC9503V_PIN_NUM_DATA2 GPIO_NUM_12 // B2
#define GC9503V_PIN_NUM_DATA3 GPIO_NUM_13 // B3
#define GC9503V_PIN_NUM_DATA4 GPIO_NUM_14 // B4
#define GC9503V_PIN_NUM_DATA5 GPIO_NUM_21 // G0
//如果开发板是V1.4 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p4
#define GC9503V_PIN_NUM_DATA6 GPIO_NUM_47 // G1
#define GC9503V_PIN_NUM_DATA7 GPIO_NUM_48 // G2
#endif
//如果开发板是V1.5 IO 定义为
#ifdef CONFIG_ESP_S3_LCD_EV_Board_1p5
#define GC9503V_PIN_NUM_DATA6 GPIO_NUM_8 // G1
#define GC9503V_PIN_NUM_DATA7 GPIO_NUM_18 // G2
#endif
#define GC9503V_PIN_NUM_DATA8 GPIO_NUM_45 // G3
#define GC9503V_PIN_NUM_DATA9 GPIO_NUM_38 // G4
#define GC9503V_PIN_NUM_DATA10 GPIO_NUM_39 // G5
#define GC9503V_PIN_NUM_DATA11 GPIO_NUM_40 // R0
#define GC9503V_PIN_NUM_DATA12 GPIO_NUM_41 // R1
#define GC9503V_PIN_NUM_DATA13 GPIO_NUM_42 // R2
#define GC9503V_PIN_NUM_DATA14 GPIO_NUM_2 // R3
#define GC9503V_PIN_NUM_DATA15 GPIO_NUM_1 // R4
#define GC9503V_PIN_NUM_DISP_EN -1
#define GC9503V_LCD_IO_SPI_CS_1 (IO_EXPANDER_PIN_NUM_1)
#define GC9503V_LCD_IO_SPI_SCL_1 (IO_EXPANDER_PIN_NUM_2)
#define GC9503V_LCD_IO_SPI_SDO_1 (IO_EXPANDER_PIN_NUM_3)