Skip to content

Commit

Permalink
feat(esp32s3-eye): LCD
Browse files Browse the repository at this point in the history
  • Loading branch information
casaroli committed Oct 10, 2023
1 parent 7a12aa2 commit c5a94d8
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
161 changes: 161 additions & 0 deletions boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_board_lcd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/****************************************************************************
* 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, true); */

/* OOPS! Looks like turning this on on V2.1
* boards will fry the backlight :O
*/

/* Turn off LCD backlight instead */

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);
}
19 changes: 19 additions & 0 deletions boards/xtensa/esp32s3/esp32s3-eye/src/esp32s3_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
# include "esp32s3_spi.h"
#endif

#ifdef CONFIG_LCD_DEV
# include <nuttx/board.h>
# include <nuttx/lcd/lcd_dev.h>
#endif

#include "esp32s3-eye.h"

/****************************************************************************
Expand Down Expand Up @@ -163,6 +168,20 @@ int esp32s3_bringup(void)
}
#endif

#ifdef CONFIG_ESP32S3_EYE_LCD
ret = board_lcd_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: board_lcd_initialize() failed: %d\n", ret);
}

ret = lcddev_register(0);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: lcddev_register() failed: %d\n", ret);
}
#endif

/* If we got here then perhaps not all initialization was successful, but
* at least enough succeeded to bring-up NSH with perhaps reduced
* capabilities.
Expand Down

0 comments on commit c5a94d8

Please sign in to comment.