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

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,643 @@
/****************************************************************************
* boards/xtensa/esp32s3/esp32s3-box/src/esp32s3_board_lcd_ili9342c.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 <stdio.h>
#include <stdbool.h>
#include <debug.h>
#include <errno.h>
#include <sys/param.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/signal.h>
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/ili9341.h>
#include <arch/board/board.h>
#include "esp32s3_gpio.h"
#include "esp32s3_spi.h"
#include "hardware/esp32s3_gpio_sigmap.h"
#include "esp32s3-box.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ILI9342C_FREQUENCY (40 * 1000 * 1000)
/****************************************************************************
* Private Types
****************************************************************************/
struct ili9342c_config_data
{
uint8_t cmd;
uint8_t data_bytes;
uint8_t data[16];
};
struct ili9342c_lcd_dev
{
struct ili9341_lcd_s ili9342c_lcd;
struct spi_dev_s *spi_dev;
struct lcd_dev_s *lcd;
};
/****************************************************************************
* Private Data
****************************************************************************/
/* ILI9342C Initialization Configuration */
static const struct ili9342c_config_data g_lcd_config[] =
{
{
/* SW reset */
ILI9341_SOFTWARE_RESET, 0
},
{
/* 200 ms delay */
0x80, 1,
{
0xfa
}
},
{
/* Power contorl B, power control = 0, DC_ENA = 1 */
ILI9341_POWER_CONTROL_B, 3,
{
0x00, 0xaa, 0xe0
}
},
{
/* Power on sequence control */
ILI9341_POWER_ON_SEQUENCE_CONTROL, 4,
{
0x67, 0x03, 0x12, 0x81
}
},
{
/* Driver timing control A */
ILI9341_DRIVER_TIMING_CTL_A, 3,
{
0x8a, 0x01, 0x78
}
},
{
/* Power control A, Vcore=1.6V, DDVDH=5.6V */
ILI9341_POWER_CONTROL_A, 5,
{
0x39, 0x2c, 0x00, 0x34, 0x02
}
},
{
/* Pump ratio control, DDVDH=2xVCl */
ILI9341_PUMP_RATIO_CONTROL, 1,
{
0x20
}
},
{
/* Driver timing control, all=0 unit */
ILI9341_DRIVER_TIMING_CTL_B, 2,
{
0x00, 0x00
}
},
{
/* Power control 1, GVDD=4.75V */
ILI9341_POWER_CONTROL_1, 1,
{
0x23
}
},
{
/* Power control 2, DDVDH=VCl*2, VGH=VCl*7, VGL=-VCl*3 */
ILI9341_POWER_CONTROL_2, 1,
{
0x11
}
},
{
/* VCOM control 1, VCOMH=4.025V, VCOML=-0.950V */
ILI9341_VCOM_CONTROL_1, 2,
{
0x43, 0x4c
}
},
{
/* VCOM control 2, VCOMH=VMH-2, VCOML=VML-2 */
ILI9341_VCOM_CONTROL_2, 1,
{
0xa0
}
},
{
/* Memory access contorl, MX=MY=0, MV=1, ML=0, BGR=1, MH=0 */
ILI9341_MEMORY_ACCESS_CONTROL, 1,
{
0x28
}
},
{
/* Pixel format, 16bits/pixel for RGB/MCU interface */
ILI9341_PIXEL_FORMAT_SET, 1,
{
0x55
}
},
{
/* Frame rate control, f=fosc, 70Hz fps */
ILI9341_FRAME_RATE_CONTROL_NORMAL, 2,
{
0x00, 0x1b
}
},
{
/* Disable 3G gamma */
ILI9341_ENABLE_3_GAMMA_CONTROL, 1,
{
0x0
}
},
{
/* Gamma set, curve 1 */
ILI9341_GAMMA_SET, 1,
{
0x01
}
},
{
/* Positive gamma correction */
ILI9341_POSITIVE_GAMMA_CORRECTION, 15,
{
0x1f, 0x36, 0x36, 0x3a, 0x0c, 0x05, 0x4f, 0x87,
0x3c, 0x08, 0x11, 0x35, 0x19, 0x13, 0x00
}
},
{
/* Negative gamma correction */
ILI9341_NEGATIVE_GAMMA_CORRECTION, 15,
{
0x00, 0x09, 0x09, 0x05, 0x13, 0x0a, 0x30, 0x78,
0x43, 0x07, 0x0e, 0x0a, 0x26, 0x2c, 0x1f
}
},
{
/* Column address set, SC=0, EC=0xEF */
ILI9341_COLUMN_ADDRESS_SET, 4,
{
0x00, 0x00, 0x00, 0xef
}
},
{
/* Page address set, SP=0, EP=0x013F */
ILI9341_PAGE_ADDRESS_SET, 4,
{
0x00, 0x00, 0x01, 0x3f
}
},
{
/* Memory write */
ILI9341_MEMORY_WRITE, 0
},
{
/* Entry mode set, Low vol detect disabled, normal display */
ILI9341_ENTRY_MODE_SET, 1,
{
0x07
}
},
{
/* Display function control */
ILI9341_DISPLAY_FUNCTION_CTL, 3,
{
0x08, 0x82, 0x27
}
},
{
/* Sleep out */
ILI9341_SLEEP_OUT, 0
},
{
/* Display on */
ILI9341_DISPLAY_ON, 0
},
{
/* Invert colors */
ILI9341_DISP_INVERSION_OFF, 0,
},
{
ILI9341_MEMORY_ACCESS_CONTROL, 1,
{
0xc8
}
}
};
static struct ili9342c_lcd_dev g_lcddev;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: ili9342c_select
*
* Description:
* Select the SPI, locking and re-configuring if necessary
*
* Input Parameters:
* spi - Reference to the public driver structure
*
* Returned Value:
* None.
*
****************************************************************************/
static void ili9342c_select(struct ili9341_lcd_s *lcd)
{
struct ili9342c_lcd_dev *priv = (struct ili9342c_lcd_dev *)lcd;
SPI_LOCK(priv->spi_dev, true);
SPI_SELECT(priv->spi_dev, SPIDEV_DISPLAY(0), true);
}
/****************************************************************************
* Name: ili9342c_deselect
*
* Description:
* De-select the SPI
*
* Input Parameters:
* spi - Reference to the public driver structure
*
* Returned Value:
* None.
*
****************************************************************************/
static void ili9342c_deselect(struct ili9341_lcd_s *lcd)
{
struct ili9342c_lcd_dev *priv = (struct ili9342c_lcd_dev *)lcd;
SPI_SELECT(priv->spi_dev, SPIDEV_DISPLAY(0), false);
SPI_LOCK(priv->spi_dev, false);
}
/****************************************************************************
* Name: ili9342c_sendcmd
*
* Description:
* Send a command to the lcd driver.
*
* Input Parameters:
* lcd - Reference to the ili9341_lcd_s driver structure
* cmd - command to send
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
static int ili9342c_sendcmd(struct ili9341_lcd_s *lcd, const uint8_t cmd)
{
struct ili9342c_lcd_dev *priv = (struct ili9342c_lcd_dev *)lcd;
lcdinfo("cmd=%02x\n", cmd);
SPI_SETBITS(priv->spi_dev, 8);
SPI_CMDDATA(priv->spi_dev, SPIDEV_DISPLAY(0), true);
SPI_SEND(priv->spi_dev, cmd);
return 0;
}
/****************************************************************************
* Name: stm32_ili93414ws_sendparam
*
* Description:
* Send a parameter to the lcd driver.
*
* Input Parameters:
* lcd - Reference to the ili9341_lcd_s driver structure
* param - parameter to send
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
static int ili9342c_sendparam(struct ili9341_lcd_s *lcd, const uint8_t param)
{
struct ili9342c_lcd_dev *priv = (struct ili9342c_lcd_dev *)lcd;
lcdinfo("param=%02x\n", param);
SPI_SETBITS(priv->spi_dev, 8);
SPI_CMDDATA(priv->spi_dev, SPIDEV_DISPLAY(0), false);
SPI_SEND(priv->spi_dev, param);
return 0;
}
/****************************************************************************
* Name: stm32_ili93414ws_sendgram
*
* Description:
* Send a number of pixel words to the lcd driver gram.
*
* Input Parameters:
* lcd - Reference to the ili9341_lcd_s driver structure
* wd - Reference to the words to send
* nwords - number of words to send
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
static int ili9342c_sendgram(struct ili9341_lcd_s *lcd,
const uint16_t *wd,
uint32_t nwords)
{
struct ili9342c_lcd_dev *priv = (struct ili9342c_lcd_dev *)lcd;
lcdinfo("lcd:%p, wd=%p, nwords=%" PRIu32 "\n", lcd, wd, nwords);
SPI_SETBITS(priv->spi_dev, 16);
SPI_CMDDATA(priv->spi_dev, SPIDEV_DISPLAY(0), false);
SPI_SNDBLOCK(priv->spi_dev, wd, nwords);
return 0;
}
/****************************************************************************
* Name: stm32_ili93414ws_backlight
*
* Description:
* Set the backlight level of the connected display.
*
* Input Parameters:
* spi - Reference to the public driver structure
* level - backligth level
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
static int ili9342c_backlight(struct ili9341_lcd_s *lcd, int level)
{
if (level > 0)
{
lcd->sendcmd(lcd, ILI9341_WRITE_CTRL_DISPLAY);
lcd->sendparam(lcd, 0x24);
}
else
{
lcd->sendcmd(lcd, ILI9341_WRITE_CTRL_DISPLAY);
lcd->sendparam(lcd, 0x0);
}
return 0;
}
/****************************************************************************
* Name: esp32s3_initializa_ili9342c
*
* Description:
* Initialize the device structure to control the LCD Single chip driver.
*
* Input Parameters:
*
* Returned Value:
* On success, this function returns a reference to the LCD control object
* for the specified ILI9341 LCD Single chip driver connected as 4 wire
* serial (spi). NULL is returned on any failure.
*
****************************************************************************/
static struct ili9341_lcd_s *esp32s3_initializa_ili9342c(int spi_port)
{
struct ili9341_lcd_s *ili9342c_lcd = &g_lcddev.ili9342c_lcd;
/* Initialize non-SPI GPIOs */
esp32s3_configgpio(DISPLAY_DC, OUTPUT);
esp32s3_configgpio(DISPLAY_RST, OUTPUT);
esp32s3_configgpio(DISPLAY_BCKL, OUTPUT);
/* Reset LCD */
nxsig_usleep(10 * 1000);
esp32s3_gpiowrite(DISPLAY_RST, true);
nxsig_usleep(10 * 1000);
esp32s3_gpiowrite(DISPLAY_RST, false);
nxsig_usleep(50 * 1000);
/* Turn on LCD backlight */
esp32s3_gpiowrite(DISPLAY_BCKL, true);
g_lcddev.spi_dev = esp32s3_spibus_initialize(spi_port);
if (!g_lcddev.spi_dev)
{
lcderr("ERROR: Failed to initialize SPI port %d\n", spi_port);
return NULL;
}
SPI_SETMODE(g_lcddev.spi_dev, SPIDEV_MODE0);
SPI_SETBITS(g_lcddev.spi_dev, 8);
SPI_SETFREQUENCY(g_lcddev.spi_dev, ILI9342C_FREQUENCY);
ili9342c_lcd->select = ili9342c_select;
ili9342c_lcd->deselect = ili9342c_deselect;
ili9342c_lcd->sendcmd = ili9342c_sendcmd;
ili9342c_lcd->sendparam = ili9342c_sendparam;
ili9342c_lcd->recvparam = NULL;
ili9342c_lcd->sendgram = ili9342c_sendgram;
ili9342c_lcd->recvgram = NULL;
ili9342c_lcd->backlight = ili9342c_backlight;
return ili9342c_lcd;
}
/****************************************************************************
* Name: ili9342c_configure
*
* Description:
* Configuration ILI9342C with given command and parameters.
*
* Returned Value:
* None.
*
****************************************************************************/
static void ili9342c_configure(struct ili9341_lcd_s *lcd,
uint8_t cmd,
uint8_t data_bytes,
const uint8_t *data)
{
lcd->select(lcd);
lcd->sendcmd(lcd, cmd);
if (data_bytes)
{
for (int i = 0; i < data_bytes; i++)
{
lcd->sendparam(lcd, data[i]);
}
}
lcd->deselect(lcd);
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_lcd_initialize
*
* Description:
* Initialize the LCD video hardware. The initial state of the LCD is
* fully initialized, display memory cleared, and the LCD ready to use, but
* with the power setting at 0 (full off).
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
int board_lcd_initialize(void)
{
struct ili9341_lcd_s *ili9342c_lcd;
ili9342c_lcd = esp32s3_initializa_ili9342c(DISPLAY_SPI);
if (!ili9342c_lcd)
{
lcderr("ERROR: Failed to initialize ILI9341\n");
return -ENODEV;
}
g_lcddev.lcd = ili9341_initialize(ili9342c_lcd, 0);
if (!g_lcddev.lcd)
{
lcderr("ERROR: st7789_lcdinitialize() failed\n");
return -ENODEV;
}
for (int i = 0; i < nitems(g_lcd_config); i++)
{
ili9342c_configure(ili9342c_lcd,
g_lcd_config[i].cmd,
g_lcd_config[i].data_bytes,
g_lcd_config[i].data);
}
return OK;
}
/****************************************************************************
* Name: board_lcd_getdev
*
* Description:
* Return a a reference to the LCD object for the specified LCD. This
* allows support for multiple LCD devices.
*
* Input Parameters:
* devno - LCD device nmber
*
* Returned Value:
* LCD device pointer if success or NULL if failed.
*
****************************************************************************/
struct lcd_dev_s *board_lcd_getdev(int devno)
{
if (!g_lcddev.lcd)
{
lcderr("ERROR: Failed to bind SPI port 4 to LCD %d\n", devno);
}
else
{
lcdinfo("SPI port %d bound to LCD %d\n", DISPLAY_SPI, devno);
return g_lcddev.lcd;
}
return NULL;
}
/****************************************************************************
* Name: board_lcd_uninitialize
*
* Description:
* Uninitialize the LCD support
*
* Returned Value:
* None
*
****************************************************************************/
void board_lcd_uninitialize(void)
{
/* Turn the display off */
g_lcddev.lcd->setpower(g_lcddev.lcd, 0);
}

View File

@ -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;
}

View File

@ -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