diff --git a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/Make.defs b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/Make.defs index 01f634b3cf7..c67548ec16a 100644 --- a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/Make.defs +++ b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/Make.defs @@ -52,3 +52,7 @@ endif ifeq ($(CONFIG_IOEXPANDER_PCA9557),y) CSRCS += esp32s3_pca9557.c endif + +ifeq ($(CONFIG_LCD),y) +CSRCS += esp32s3_board_lcd.c +endif diff --git a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3-szpi.h b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3-szpi.h index cd92e1984a8..bf84ddf189d 100644 --- a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3-szpi.h +++ b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3-szpi.h @@ -27,6 +27,7 @@ * Included Files ****************************************************************************/ +#include #include #include #include @@ -35,8 +36,9 @@ * Pre-processor Definitions ****************************************************************************/ -#define GPIO_LCD_DC (39) -#define GPIO_LCD_RST (-1) +#define GPIO_LCD_DC (39) +#define GPIO_LCD_RST (-1) +#define SZPI_LCD_CS_PATH "/dev/gpio0" /**************************************************************************** * Public Types diff --git a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_lcd.c b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_lcd.c new file mode 100644 index 00000000000..b7d36e69a08 --- /dev/null +++ b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_lcd.c @@ -0,0 +1,167 @@ +/**************************************************************************** + * boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_lcd.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "esp32s3_gpio.h" +#include "esp32s3_spi.h" +#include "hardware/esp32s3_gpio_sigmap.h" + +#include "esp32s3-szpi.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) +{ + ssize_t n; + int fd; + + /* Pull down C/S */ + + fd = nx_open(SZPI_LCD_CS_PATH, O_RDWR); + if (fd < 0) + { + spierr("open C/S pin failed\n"); + return -ENODEV; + } + + n = nx_write(fd, "1", 1); + nx_close(fd); + if (n != 1) + { + spierr("write C/S pin failed\n"); + return -EIO; + } + + /* Turn on LCD backlight */ + + g_spidev = esp32s3_spibus_initialize(ESP32S3_SPI2); + if (!g_spidev) + { + lcderr("ERROR: Failed to initialize SPI port %d\n", ESP32S3_SPI2); + 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_SPI2, devno); + } + else + { + lcdinfo("SPI port %d bound to LCD %d\n", ESP32S3_SPI2, 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); +} diff --git a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_spi.c b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_spi.c index 8bc3a3bcf56..271874ab15a 100644 --- a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_spi.c +++ b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/src/esp32s3_board_spi.c @@ -28,9 +28,11 @@ #include #include +#include #include #include +#include #include "esp32s3_gpio.h" #include "esp32s3-szpi.h" @@ -85,6 +87,29 @@ int esp32s3_spi2_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) #endif +#if defined(CONFIG_ESP32S3_SPI2) && defined(CONFIG_ESP32S3_SPI_UDCS) +void esp32s3_spi2_select(struct spi_dev_s *dev, uint32_t devid, bool select) +{ + ssize_t n; + int fd; + + fd = nx_open(SZPI_LCD_CS_PATH, O_RDWR); + if (fd < 0) + { + spierr("open C/S pin failed\n"); + return; + } + + n = nx_write(fd, select ? "0" : "1", 1); + if (n != 1) + { + spierr("write C/S pin failed\n"); + } + + nx_close(fd); +} +#endif + /**************************************************************************** * Name: esp32s3_spi3_status ****************************************************************************/