feat(esp32s3-eye): SPI and LCD

LCD is connected to SPI2 and uses DC signalling.
This commit is contained in:
Marco Casaroli 2023-10-10 10:59:50 +00:00 committed by Alan Carvalho de Assis
parent 20b5d2b84c
commit effab1bd61
6 changed files with 377 additions and 0 deletions

View File

@ -48,4 +48,15 @@ config ESP32S3_SPIFLASH_LITTLEFS
endchoice endchoice
config ESP32S3_EYE_LCD
bool "Enable ESP32-S3 LCD"
default n
select ESP32S3_SPI2
select SPI_CMDDATA
select LCD
select LCD_DEV
select LCD_ST7789
---help---
Enable board LCD support, IC is LCD_ST7789V.
endif # ARCH_BOARD_ESP32S3_EYE endif # ARCH_BOARD_ESP32S3_EYE

View File

@ -37,6 +37,14 @@ ifeq ($(CONFIG_DEV_GPIO),y)
CSRCS += esp32s3_gpio.c CSRCS += esp32s3_gpio.c
endif endif
ifeq ($(CONFIG_ESP32S3_SPI),y)
CSRCS += esp32s3_board_spi.c
endif
ifeq ($(CONFIG_ESP32S3_EYE_LCD),y)
CSRCS += esp32s3_board_lcd.c
endif
DEPPATH += --dep-path board DEPPATH += --dep-path board
VPATH += :board VPATH += :board
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board

View File

@ -38,6 +38,11 @@
/* BOOT Button */ /* BOOT Button */
#define BUTTON_BOOT 0 #define BUTTON_BOOT 0
/* Display */
#define ESP32S3_EYE_DISPLAY_SPI 2
#define ESP32S3_EYE_DISPLAY_DC 43
#define ESP32S3_EYE_DISPLAY_BCKL 48
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
@ -97,6 +102,45 @@ int esp32s3_gpio_init(void);
int board_spiflash_init(void); int board_spiflash_init(void);
#endif #endif
/****************************************************************************
* 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).
*
****************************************************************************/
#ifdef CONFIG_ESP32S3_EYE_LCD
int board_lcd_initialize(void);
#endif
/****************************************************************************
* Name: board_lcd_getdev
*
* Description:
* Return a reference to the LCD object for the specified LCD. This allows
* support for multiple LCD devices.
*
****************************************************************************/
#ifdef CONFIG_ESP32S3_EYE_LCD
struct lcd_dev_s *board_lcd_getdev(int lcddev);
#endif
/****************************************************************************
* Name: board_lcd_uninitialize
*
* Description:
* Uninitialize the LCD support.
*
****************************************************************************/
#ifdef CONFIG_ESP32S3_EYE_LCD
void board_lcd_uninitialize(void);
#endif
/**************************************************************************** /****************************************************************************
* Name: board_i2c_init * Name: board_i2c_init
* *

View File

@ -0,0 +1,153 @@
/****************************************************************************
* boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.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 <nuttx/arch.h>
#include <nuttx/board.h>
#include <nuttx/signal.h>
#include <nuttx/spi/spi.h>
#include <nuttx/lcd/lcd.h>
#include <nuttx/lcd/st7789.h>
#include <arch/board/board.h>
#include "esp32s3_gpio.h"
#include "esp32s3_spi.h"
#include "hardware/esp32s3_gpio_sigmap.h"
#include "esp32s3-eye.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
static struct spi_dev_s *g_spidev;
static struct lcd_dev_s *g_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)
{
/* Initialize non-SPI GPIOs */
esp32s3_configgpio(ESP32S3_EYE_DISPLAY_DC, OUTPUT);
esp32s3_configgpio(ESP32S3_EYE_DISPLAY_BCKL, OUTPUT);
/* Turn on LCD backlight */
esp32s3_gpiowrite(ESP32S3_EYE_DISPLAY_BCKL, false);
g_spidev = esp32s3_spibus_initialize(ESP32S3_EYE_DISPLAY_SPI);
if (!g_spidev)
{
lcderr("ERROR: Failed to initialize SPI port %d\n",
ESP32S3_EYE_DISPLAY_SPI);
return -ENODEV;
}
g_lcd = st7789_lcdinitialize(g_spidev);
if (!g_lcd)
{
lcderr("ERROR: st7789_lcdinitialize() failed\n");
return -ENODEV;
}
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_lcd)
{
lcderr("ERROR: Failed to bind SPI port %d to LCD %d\n",
ESP32S3_EYE_DISPLAY_SPI, devno);
}
else
{
lcdinfo("SPI port %d bound to LCD %d\n",
ESP32S3_EYE_DISPLAY_SPI,
devno);
return g_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_lcd->setpower(g_lcd, 0);
}

View File

@ -0,0 +1,126 @@
/****************************************************************************
* boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_spi.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 <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/spi/spi.h>
#include "esp32s3_gpio.h"
#include "esp32s3-eye.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: esp32s3_spi2_status
****************************************************************************/
#ifdef CONFIG_ESP32S3_SPI2
uint8_t esp32s3_spi2_status(struct spi_dev_s *dev, uint32_t devid)
{
uint8_t status = 0;
return status;
}
#endif
/****************************************************************************
* Name: esp32s3_spi2_cmddata
****************************************************************************/
#if defined(CONFIG_ESP32S3_SPI2) && defined(CONFIG_SPI_CMDDATA)
int esp32s3_spi2_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*/
esp32s3_gpiowrite(ESP32S3_EYE_DISPLAY_DC, !cmd);
return OK;
}
spiinfo("devid: %" PRIu32 " CMD: %s\n", devid, cmd ? "command" :
"data");
return -ENODEV;
}
#endif
/****************************************************************************
* Name: esp32s3_spi3_status
****************************************************************************/
#ifdef CONFIG_ESP32S3_SPI3
uint8_t esp32s3_spi3_status(struct spi_dev_s *dev, uint32_t devid)
{
uint8_t status = 0;
return status;
}
#endif
/****************************************************************************
* Name: esp32s3_spi3_cmddata
****************************************************************************/
#if defined(CONFIG_ESP32S3_SPI3) && defined(CONFIG_SPI_CMDDATA)
int esp32s3_spi3_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd)
{
if (devid == SPIDEV_DISPLAY(0))
{
/* This is the Data/Command control pad which determines whether the
* data bits are data or a command.
*/
esp32s3_gpiowrite(CONFIG_ESP32S3_SPI3_MISOPIN, !cmd);
return OK;
}
spiinfo("devid: %" PRIu32 " CMD: %s\n", devid, cmd ? "command" :
"data");
return -ENODEV;
}
#endif

View File

@ -70,6 +70,15 @@
# include <nuttx/input/buttons.h> # include <nuttx/input/buttons.h>
#endif #endif
#ifdef CONFIG_ESP32S3_SPI
# include "esp32s3_spi.h"
#endif
#ifdef CONFIG_LCD_DEV
# include <nuttx/board.h>
# include <nuttx/lcd/lcd_dev.h>
#endif
#include "esp32s3-eye.h" #include "esp32s3-eye.h"
/**************************************************************************** /****************************************************************************
@ -206,6 +215,32 @@ int esp32s3_bringup(void)
{ {
syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret); syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret);
} }
#endif
#ifdef CONFIG_ESP32S3_EYE_LCD
#ifdef CONFIG_VIDEO_FB
ret = fb_register(0, 0);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize Frame Buffer Driver.\n");
return ret;
}
#elif defined(CONFIG_LCD)
ret = board_lcd_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize LCD.\n");
return ret;
}
ret = lcddev_register(0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: lcddev_register() failed: %d\n", ret);
}
#endif
#endif #endif
/* If we got here then perhaps not all initialization was successful, but /* If we got here then perhaps not all initialization was successful, but