diff --git a/boards/xtensa/esp32/common/src/Make.defs b/boards/xtensa/esp32/common/src/Make.defs index 3d91a0e8cb7..3bf716925e3 100644 --- a/boards/xtensa/esp32/common/src/Make.defs +++ b/boards/xtensa/esp32/common/src/Make.defs @@ -130,6 +130,10 @@ ifeq ($(CONFIG_LCD_ILI9341),y) CSRCS += esp32_ili9341.c endif +ifeq ($(CONFIG_LCD_GC9A01),y) + CSRCS += esp32_gc9a01.c +endif + ifeq ($(CONFIG_LCD_ST7789),y) CSRCS += esp32_st7789.c endif diff --git a/boards/xtensa/esp32/common/src/esp32_board_spi.c b/boards/xtensa/esp32/common/src/esp32_board_spi.c index b7c367d75e8..a714de15afd 100644 --- a/boards/xtensa/esp32/common/src/esp32_board_spi.c +++ b/boards/xtensa/esp32/common/src/esp32_board_spi.c @@ -73,7 +73,7 @@ static inline uint8_t spi_status(struct spi_dev_s *dev, uint32_t devid) static inline int spi_cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) { -#if defined(CONFIG_LCD_ILI9341) || defined(CONFIG_LCD_SSD1680) || defined(CONFIG_LCD_ST7789) +#if defined(CONFIG_LCD_ILI9341) || defined(CONFIG_LCD_SSD1680) || defined(CONFIG_LCD_ST7789) || defined(CONFIG_LCD_GC9A01) if (devid == SPIDEV_DISPLAY(0)) { /* This is the Data/Command control pad which determines whether the diff --git a/boards/xtensa/esp32/common/src/esp32_gc9a01.c b/boards/xtensa/esp32/common/src/esp32_gc9a01.c new file mode 100644 index 00000000000..db17a29ddfe --- /dev/null +++ b/boards/xtensa/esp32/common/src/esp32_gc9a01.c @@ -0,0 +1,132 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/src/esp32_gc9a01.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 "esp32_gpio.h" +#include "esp32_spi.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct spi_dev_s *g_spidev; +static struct lcd_dev_s *g_lcd = NULL; + +/**************************************************************************** + * 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). + * + ****************************************************************************/ + +int board_lcd_initialize(void) +{ + g_spidev = esp32_spibus_initialize(DISPLAY_SPI); + if (!g_spidev) + { + lcderr("ERROR: Failed to initialize SPI port %d\n", DISPLAY_SPI); + return -ENODEV; + } + + lcdinfo("Initialized SPI port %d\n", DISPLAY_SPI); + + /* SPI RX is not used. Same pin is used as LCD Data/Command control */ + + esp32_configgpio(DISPLAY_DC, OUTPUT); + esp32_gpiowrite(DISPLAY_DC, true); + + /* Pull LCD_RESET high */ + + esp32_configgpio(DISPLAY_RST, OUTPUT); + esp32_gpiowrite(DISPLAY_RST, false); + up_mdelay(50); + esp32_gpiowrite(DISPLAY_RST, true); + up_mdelay(50); + + /* Set full brightness */ + + esp32_configgpio(DISPLAY_BCKL, OUTPUT); + esp32_gpiowrite(DISPLAY_BCKL, true); + 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. + * + ****************************************************************************/ + +struct lcd_dev_s *board_lcd_getdev(int devno) +{ + g_lcd = gc9a01_lcdinitialize(g_spidev); + if (!g_lcd) + { + lcderr("ERROR: Failed to bind SPI port %d to LCD %d\n", + DISPLAY_SPI, devno); + } + else + { + lcdinfo("SPI port %d bound to LCD %d\n", DISPLAY_SPI, devno); + return g_lcd; + } + + return NULL; +} + +/**************************************************************************** + * Name: board_lcd_uninitialize + * + * Description: + * Uninitialize the LCD support + * + ****************************************************************************/ + +void board_lcd_uninitialize(void) +{ + /* Turn the display off */ + + g_lcd->setpower(g_lcd, 0); +}