boards/esp32s3-box: Support hardware version 3

config/lvgl: For old ESP32-S3-BOX board
config/lvgl-3: For new ESP32-S3-BOX-3 board
This commit is contained in:
Dong Heng
2023-10-07 11:54:32 +08:00
committed by Xiang Xiao
parent be72a6e26f
commit 1cb17b8a6a
9 changed files with 1226 additions and 7 deletions
+23 -2
View File
@@ -5,6 +5,17 @@
if ARCH_BOARD_ESP32S3_BOX
choice
prompt "ESP32-S3-BOX Version"
default ESP32_S3_BOX_3
config ESP32_S3_BOX
bool "ESP32-S3-BOX(old)"
config ESP32_S3_BOX_3
bool "ESP32-S3-BOX-3"
endchoice
config ESP32S3_STORAGE_MTD_OFFSET
hex "Storage MTD base address in SPI Flash"
default 0x180000 if !ESP32S3_HAVE_OTA_PARTITION
@@ -57,7 +68,10 @@ config ESP32S3_BOX_LCD
select LCD_DEV
select LCD_ST7789
---help---
Enable board LCD support, IC is LCD_ST7789V.
Enable board LCD support, IC is:
ESP32-S3-BOX: ST7789V
ESP32-S3-BOX-3: ILI9342C
config ESP32S3_BOARD_TOUCHSCREEN
bool "Enable Board Touchscreen"
@@ -66,7 +80,10 @@ config ESP32S3_BOARD_TOUCHSCREEN
select INPUT
select INPUT_TOUCHSCREEN
---help---
Enable board touchscreen support, IC is TT21100.
Enable board touchscreen support, IC is:
ESP32-S3-BOX: TT21100
ESP32-S3-BOX-3: GT911
menu "Board Touchscreen Configuration"
depends on ESP32S3_BOARD_TOUCHSCREEN
@@ -78,10 +95,12 @@ config ESP32S3_BOARD_TOUCHSCREEN_PATH
config ESP32S3_BOARD_TOUCHSCREEN_WIDTH
int "Touchscreen Width"
default 320
depends on ESP32_S3_BOX
config ESP32S3_BOARD_TOUCHSCREEN_HEIGHT
int "Touchscreen Height"
default 240
depends on ESP32_S3_BOX
config ESP32S3_BOARD_TOUCHSCREEN_SAMPLE_CACHES
int "Touchscreen Sample Cache Number"
@@ -94,10 +113,12 @@ config ESP32S3_BOARD_TOUCHSCREEN_SAMPLE_DELAYS
config ESP32S3_BOARD_TOUCHSCREEN_X_MIRROR
bool "Touchscreen X Mirror"
default y
depends on ESP32_S3_BOX
config ESP32S3_BOARD_TOUCHSCREEN_Y_MIRROR
bool "Touchscreen Y Mirror"
default n
depends on ESP32_S3_BOX
endmenu # Touchscreen Configuration
@@ -0,0 +1,86 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_LEDS is not set
# CONFIG_ESP32S3_RTC is not set
# CONFIG_LCD_ST7789_INVCOLOR is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_SPI_EXCHANGE is not set
CONFIG_ARCH="xtensa"
CONFIG_ARCH_BOARD="esp32s3-box"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32S3_BOX=y
CONFIG_ARCH_CHIP="esp32s3"
CONFIG_ARCH_CHIP_ESP32S3=y
CONFIG_ARCH_CHIP_ESP32S3WROOM2=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_XTENSA=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_ASSERTIONS_EXPRESSION=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_ESP32S3_BOARD_TOUCHSCREEN=y
CONFIG_ESP32S3_BOX_LCD=y
CONFIG_ESP32S3_I2C0_SCLPIN=18
CONFIG_ESP32S3_I2C0_SDAPIN=8
CONFIG_ESP32S3_SPI2_CLKPIN=7
CONFIG_ESP32S3_SPI2_CSPIN=5
CONFIG_ESP32S3_SPI2_MISOPIN=21
CONFIG_ESP32S3_SPI2_MOSIPIN=6
CONFIG_ESP32S3_SPIRAM=y
CONFIG_ESP32S3_SPIRAM_MODE_OCT=y
CONFIG_ESP32S3_SPIRAM_SPEED_80M=y
CONFIG_ESP32S3_SPI_SWCS=y
CONFIG_ESP32S3_USBSERIAL=y
CONFIG_EXAMPLES_LVGLDEMO=y
CONFIG_FS_PROCFS=y
CONFIG_GRAPHICS_LVGL=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=3072
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_LCD_ILI9341=y
CONFIG_LCD_ILI9341_IFACE0=y
CONFIG_LCD_RPORTRAIT=y
CONFIG_LV_COLOR_16_SWAP=y
CONFIG_LV_FONT_MONTSERRAT_20=y
CONFIG_LV_MEMCPY_MEMSET_STD=y
CONFIG_LV_MEM_CUSTOM=y
CONFIG_LV_PORT_LCDDEV_DOUBLE_BUFFER=y
CONFIG_LV_PORT_LCDDEV_FULL_SCREEN_BUFFER=y
CONFIG_LV_PORT_USE_LCDDEV=y
CONFIG_LV_PORT_USE_TOUCHPAD=y
CONFIG_LV_TICK_CUSTOM=y
CONFIG_LV_TICK_CUSTOM_INCLUDE="port/lv_port_tick.h"
CONFIG_LV_USE_DEMO_WIDGETS=y
CONFIG_LV_USE_LOG=y
CONFIG_MM_REGIONS=2
CONFIG_NDEBUG=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SPI_CMDDATA=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSLOG_BUFFER=y
CONFIG_SYSTEM_NSH=y
@@ -41,6 +41,7 @@ CONFIG_ESP32S3_SPIRAM_MODE_OCT=y
CONFIG_ESP32S3_SPIRAM_SPEED_80M=y
CONFIG_ESP32S3_SPI_SWCS=y
CONFIG_ESP32S3_USBSERIAL=y
CONFIG_ESP32_S3_BOX=y
CONFIG_EXAMPLES_LVGLDEMO=y
CONFIG_FS_PROCFS=y
CONFIG_GRAPHICS_LVGL=y
@@ -38,11 +38,19 @@ CSRCS += esp32s3_board_spi.c
endif
ifeq ($(CONFIG_ESP32S3_BOX_LCD),y)
CSRCS += esp32s3_board_lcd.c
ifeq ($(CONFIG_ESP32_S3_BOX),y)
CSRCS += esp32s3_board_lcd_st7789.c
else
CSRCS += esp32s3_board_lcd_ili9342c.c
endif
endif
ifeq ($(CONFIG_ESP32S3_BOARD_TOUCHSCREEN),y)
CSRCS += esp32s3_board_touchsceen.c
ifeq ($(CONFIG_ESP32_S3_BOX),y)
CSRCS += esp32s3_board_touchsceen_tt21100.c
else
CSRCS += esp32s3_board_touchsceen_gt911.c
endif
endif
DEPPATH += --dep-path board
@@ -52,7 +52,12 @@
*/
#define DISPLAY_DC 4
#define DISPLAY_BCKL 45
#ifdef CONFIG_ESP32_S3_BOX
# define DISPLAY_BCKL 45
#else
# define DISPLAY_BCKL 47
#endif
#define DISPLAY_RST 48
/* Touchpad */
@@ -64,7 +69,12 @@
* SDA: 8
*/
#define TOUCHSCEEN_ADDR 0x24
#ifdef CONFIG_ESP32_S3_BOX
# define TOUCHSCEEN_ADDR 0x24
#else
# define TOUCHSCEEN_ADDR 0x5d
#endif
#define TOUCHSCEEN_CLOCK (400 * 1000)
#define TOUCHSCEEN_INT 3
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,450 @@
/****************************************************************************
* boards/xtensa/esp32s3/esp32s3-box/src/esp32s3_board_touchsceen_gt911.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <syslog.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <string.h>
#include <nuttx/spinlock.h>
#include <nuttx/wqueue.h>
#include <nuttx/input/touchscreen.h>
#include "esp32s3_i2c.h"
#include "esp32s3_gpio.h"
#include "hardware/esp32s3_gpio_sigmap.h"
#include "esp32s3-box.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* GT911 maximum report frame size */
#define GT911_BUFFER_SIZE 41
#define GT911_TOUCHPOINTS 5
/* GT911 board configuration */
#define GT911_ADDR TOUCHSCEEN_ADDR
#define GT911_CLOCK TOUCHSCEEN_CLOCK
#define GT911_PATH CONFIG_ESP32S3_BOARD_TOUCHSCREEN_PATH
#define GT911_WORK_DELAY CONFIG_ESP32S3_BOARD_TOUCHSCREEN_SAMPLE_DELAYS
#define GT911_SAMPLE_CACHES CONFIG_ESP32S3_BOARD_TOUCHSCREEN_SAMPLE_CACHES
/* GT911 registers address */
#define GT911_READ_XY_REG 0x814e
#define GT911_READ_DATA_REG 0x814f
#define GT911_CONFIG_REG 0x8047
#define GT911_PRODUCT_ID_REG 0x8140
/****************************************************************************
* Private Types
****************************************************************************/
/* This structure describes the state of one GT911 driver instance */
struct gt911_dev_s
{
struct touch_lowerhalf_s touch_lower; /* Touchsrceen lowerhalf */
bool has_report; /* Mark if report event */
struct i2c_master_s *i2c; /* I2C master port */
struct work_s work; /* Read sample data work */
spinlock_t lock; /* Device specific lock. */
uint8_t buffer[GT911_BUFFER_SIZE]; /* Read buffer */
};
/* This structure describes the frame of touchpoint */
struct gt911_touchpoint_s
{
uint8_t id; /* Not used */
uint16_t x; /* Touch X-axis */
uint16_t y; /* Touch Y-axis */
uint16_t pressure; /* Touch pressure */
uint8_t reserved; /* Not used */
}
__attribute__((packed));
/* This structure describes the frame of touchpoint */
struct gt911_data_s
{
uint8_t touchpoints : 4; /* Touch point number */
uint8_t has_key : 1; /* 1: key is inpressed */
uint8_t proximity_valid : 1; /* Not used */
uint8_t large_detected : 1; /* 1: large-area touch */
uint8_t buffer_status : 1; /* 1: input data is valid */
struct gt911_touchpoint_s touchpoint[0];
}
__attribute__((packed));
/****************************************************************************
* Private Data
****************************************************************************/
struct gt911_dev_s g_gt911_dev;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: gt911_write_reg
*
* Description:
* Read GT911 continuous registers value.
*
* Input Parameters:
* dev - GT911 object pointer
* reg - Register start address
* buf - Register value buffer
* buflen - Register value buffer length
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
static int gt911_read_reg(struct gt911_dev_s *dev,
uint16_t reg,
uint8_t *buf,
int buflen)
{
int ret;
/* Send the Register Address, MSB first */
uint8_t regbuf[2] =
{
reg >> 8, /* First Byte: MSB */
reg & 0xff /* Second Byte: LSB */
};
/* Compose the I2C Messages */
struct i2c_msg_s msgv[2] =
{
{
/* Send the I2C Register Address */
.frequency = GT911_CLOCK,
.addr = GT911_ADDR,
.flags = 0,
.buffer = regbuf,
.length = sizeof(regbuf)
},
{
/* Receive the I2C Register Values */
.frequency = GT911_CLOCK,
.addr = GT911_ADDR,
.flags = I2C_M_READ,
.buffer = buf,
.length = buflen
}
};
const int msgv_len = sizeof(msgv) / sizeof(msgv[0]);
iinfo("reg=0x%x, buflen=%d\n", reg, buflen);
DEBUGASSERT(dev && dev->i2c && buf);
/* Execute the I2C Transfer */
ret = I2C_TRANSFER(dev->i2c, msgv, msgv_len);
if (ret < 0)
{
ierr("I2C Read failed: %d\n", ret);
return ret;
}
#ifdef CONFIG_DEBUG_INPUT_INFO
iinfodumpbuffer("gt911_read_reg", buf, buflen);
#endif /* CONFIG_DEBUG_INPUT_INFO */
return 0;
}
/****************************************************************************
* Name: gt911_write_reg
*
* Description:
* Write GT911 register value.
*
* Input Parameters:
* dev - GT911 object pointer
* reg - Register address
* val - Register value
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
static int gt911_write_reg(struct gt911_dev_s *dev,
uint16_t reg,
uint8_t val)
{
int ret;
/* Send the Register Address, MSB first */
uint8_t regbuf[3] =
{
reg >> 8, /* First Byte: MSB */
reg & 0xff, /* Second Byte: LSB */
val,
};
/* Compose the I2C Messages */
struct i2c_msg_s msgv[1] =
{
{
/* Send the I2C Register Address */
.frequency = GT911_CLOCK,
.addr = GT911_ADDR,
.flags = 0,
.buffer = regbuf,
.length = sizeof(regbuf)
}
};
const int msgv_len = sizeof(msgv) / sizeof(msgv[0]);
iinfo("reg=0x%x, val=%d\n", reg, val);
DEBUGASSERT(dev && dev->i2c);
/* Execute the I2C Transfer */
ret = I2C_TRANSFER(dev->i2c, msgv, msgv_len);
if (ret < 0)
{
ierr("I2C Write failed: %d\n", ret);
return ret;
}
return 0;
}
/****************************************************************************
* Name: gt911_touch_event
*
* Description:
* Process touch event. Read touchpoint data and send to touch event.
*
* Input Parameters:
* dev - GT911 object pointer
*
* Returned Value:
* None
*
****************************************************************************/
static void gt911_touch_event(struct gt911_dev_s *dev)
{
struct gt911_data_s *data = (struct gt911_data_s *)dev->buffer;
struct gt911_touchpoint_s *tp = data->touchpoint;
struct touch_sample_s sample;
struct touch_point_s *point = sample.point;
memset(&sample, 0, sizeof(sample));
sample.npoints = 1;
point->x = tp->x;
point->y = tp->y;
point->pressure = tp->pressure;
point->flags = TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
if (data->buffer_status)
{
point->flags |= TOUCH_DOWN;
dev->has_report = true;
}
else
{
point->flags |= TOUCH_UP;
dev->has_report = false;
}
touch_event(dev->touch_lower.priv, &sample);
}
/****************************************************************************
* Name: gt911_event
*
* Description:
* Process GT911 event.
*
* Input Parameters:
* dev - GT911 object pointer
*
* Returned Value:
* None
*
****************************************************************************/
static void gt911_event(struct gt911_dev_s *dev)
{
struct gt911_data_s *data = (struct gt911_data_s *)dev->buffer;
if (!data->has_key)
{
gt911_touch_event(dev);
}
else
{
ierr("ERROR: event is invalid\n");
}
}
/****************************************************************************
* Name: gt911_worker
*
* Description:
* Process GT911 work, read GT911 report frame and process it.
*
* Input Parameters:
* arg - GT911 object pointer
*
* Returned Value:
* None
*
****************************************************************************/
static void gt911_worker(FAR void *arg)
{
int ret;
struct gt911_dev_s *dev = (struct gt911_dev_s *)arg;
struct gt911_data_s *data = (struct gt911_data_s *)dev->buffer;
clock_t delay = GT911_WORK_DELAY;
bool touched = false;
ret = gt911_read_reg(dev, GT911_READ_XY_REG, dev->buffer, 1);
if (ret != 0)
{
ierr("ERROR: I2C_TRANSFER() failed: %d\n", ret);
goto exit;
}
if (data->buffer_status &&
(data->touchpoints > 0) &&
(data->touchpoints < GT911_TOUCHPOINTS))
{
ret = gt911_read_reg(dev, GT911_READ_DATA_REG,
&dev->buffer[1], data->touchpoints * 8);
if (ret != 0)
{
ierr("ERROR: I2C_TRANSFER() failed: %d\n", ret);
goto exit;
}
touched = true;
}
else if (dev->has_report)
{
touched = true;
}
ret = gt911_write_reg(dev, GT911_READ_XY_REG, 0);
if (ret != 0)
{
ierr("ERROR: I2C_TRANSFER() failed: %d\n", ret);
goto exit;
}
if (touched)
{
gt911_event(dev);
delay = 1;
}
exit:
ret = work_queue(LPWORK, &dev->work, gt911_worker, dev, delay);
if (ret != 0)
{
ierr("ERROR: work_queue() failed: %d\n", ret);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_touchscreen_initialize
*
* Description:
* Initialize touchpad.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_touchscreen_initialize(void)
{
int ret;
struct gt911_dev_s *dev = &g_gt911_dev;
dev->i2c = esp32s3_i2cbus_initialize(TOUCHSCEEN_I2C);
if (!dev->i2c)
{
syslog(LOG_ERR, "ERROR: Failed to initialize I2C port %d\n",
TOUCHSCEEN_I2C);
return -ENODEV;
}
ret = touch_register(&dev->touch_lower, GT911_PATH,
GT911_SAMPLE_CACHES);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: touch_register() failed: %d\n", ret);
return ret;
}
ret = work_queue(LPWORK, &dev->work, gt911_worker,
dev, GT911_WORK_DELAY);
if (ret != 0)
{
syslog(LOG_ERR, "ERROR: work_queue() failed: %d\n", ret);
return ret;
}
return 0;
}
@@ -1,5 +1,5 @@
/****************************************************************************
* boards/xtensa/esp32s3/esp32s3-box/src/esp32s3_board_touchsceen.c
* boards/xtensa/esp32s3/esp32s3-box/src/esp32s3_board_touchsceen_tt21100.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with