forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esp32s3-devkit: Add support to ST7735 SPI LCD
- Loading branch information
1 parent
19eb4d7
commit cd3e93e
Showing
5 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_st7735.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/**************************************************************************** | ||
* boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_st7735.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/spi/spi.h> | ||
#include <nuttx/lcd/lcd.h> | ||
#include <nuttx/lcd/st7735.h> | ||
|
||
#include "esp32s3_spi.h" | ||
#include "esp32s3_gpio.h" | ||
#include "esp32s3-devkit.h" | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
#define LCD_SPI_PORTNO 2 | ||
|
||
/**************************************************************************** | ||
* 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 = esp32s3_spibus_initialize(LCD_SPI_PORTNO); | ||
if (!g_spidev) | ||
{ | ||
lcderr("ERROR: Failed to initialize SPI port %d\n", LCD_SPI_PORTNO); | ||
return -ENODEV; | ||
} | ||
|
||
/* Data/Control PIN */ | ||
|
||
esp32s3_configgpio(GPIO_LCD_DC, OUTPUT); | ||
esp32s3_gpiowrite(GPIO_LCD_DC, true); | ||
|
||
/* Reset device */ | ||
|
||
esp32s3_configgpio(GPIO_LCD_RST, OUTPUT); | ||
esp32s3_gpiowrite(GPIO_LCD_RST, false); | ||
usleep(10000); | ||
esp32s3_gpiowrite(GPIO_LCD_RST, true); | ||
usleep(100000); | ||
|
||
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 = st7735_lcdinitialize(g_spidev); | ||
if (!g_lcd) | ||
{ | ||
lcderr("ERROR: Failed to bind SPI port %d to LCD %d\n", LCD_SPI_PORTNO, | ||
devno); | ||
} | ||
else | ||
{ | ||
lcdinfo("SPI port %d bound to LCD %d\n", LCD_SPI_PORTNO, 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); | ||
} |