From c9b4348b81b94c47a2168d70b2f9df10ce675ecd Mon Sep 17 00:00:00 2001 From: transistorretorcido Date: Wed, 21 Jul 2021 21:36:48 -0300 Subject: [PATCH] added st7735 LCD based support added st7735 LCD based support --- boards/arm/rp2040/common/src/Make.defs | 4 + boards/arm/rp2040/common/src/rp2040_st7735.c | 149 ++++++++++++++++++ boards/arm/rp2040/raspberrypi-pico/README.txt | 13 ++ .../raspberrypi-pico/configs/st7735/defconfig | 62 ++++++++ .../rp2040/raspberrypi-pico/src/rp2040_spi.c | 2 +- 5 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 boards/arm/rp2040/common/src/rp2040_st7735.c create mode 100644 boards/arm/rp2040/raspberrypi-pico/configs/st7735/defconfig diff --git a/boards/arm/rp2040/common/src/Make.defs b/boards/arm/rp2040/common/src/Make.defs index 1b68a12ee4..752224b42c 100644 --- a/boards/arm/rp2040/common/src/Make.defs +++ b/boards/arm/rp2040/common/src/Make.defs @@ -38,6 +38,10 @@ ifeq ($(CONFIG_LCD_ST7789),y) CSRCS += rp2040_st7789.c endif +ifeq ($(CONFIG_LCD_ST7735),y) +CSRCS += rp2040_st7735.c +endif + ifeq ($(CONFIG_USBMSC),y) CSRCS += rp2040_usbmsc.c endif diff --git a/boards/arm/rp2040/common/src/rp2040_st7735.c b/boards/arm/rp2040/common/src/rp2040_st7735.c new file mode 100644 index 0000000000..1f1f42fedb --- /dev/null +++ b/boards/arm/rp2040/common/src/rp2040_st7735.c @@ -0,0 +1,149 @@ +/**************************************************************************** + * boards/arm/rp2040/common/src/rp2040_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 + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "rp2040_spi.h" +#include "rp2040_gpio.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LCD_SPI_PORTNO 1 + +#if LCD_SPI_PORTNO +#define LCD_DC CONFIG_RP2040_SPI1_GPIO +#define LCD_RST 10 +#define LCD_BL 11 +#else +#define LCD_DC CONFIG_RP2040_SPI0_GPIO +#endif + +/**************************************************************************** + * 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 = rp2040_spibus_initialize(LCD_SPI_PORTNO); + if (!g_spidev) + { + lcderr("ERROR: Failed to initialize SPI port %d\n", LCD_SPI_PORTNO); + return -ENODEV; + } + + /* SPI RX is not used. Same pin is used as LCD Data/Command control */ + + rp2040_gpio_init(LCD_DC); + rp2040_gpio_setdir(LCD_DC, true); + rp2040_gpio_put(LCD_DC, true); + +#if LCD_SPI_PORTNO + + /* Pull LCD_RESET high */ + + rp2040_gpio_init(LCD_RST); + rp2040_gpio_setdir(LCD_RST, true); + rp2040_gpio_put(LCD_RST, true); + + /* Set full brightness */ + + rp2040_gpio_init(LCD_BL); + rp2040_gpio_setdir(LCD_BL, true); + rp2040_gpio_put(LCD_BL, true); + +#endif + + 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. + * + ****************************************************************************/ + +FAR 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); +} diff --git a/boards/arm/rp2040/raspberrypi-pico/README.txt b/boards/arm/rp2040/raspberrypi-pico/README.txt index c043cd320a..0eb7399719 100644 --- a/boards/arm/rp2040/raspberrypi-pico/README.txt +++ b/boards/arm/rp2040/raspberrypi-pico/README.txt @@ -106,6 +106,19 @@ Defconfigs DAT1 (NC) * Card hot swapping is not supported. +- st7735 + st7735 SPI LCD support + Connection: + st7735 Raspberry Pi Pico + GND ----- GND (Pin 3 or 38 or ...) + VCC ----- 5V Vbus (Pin 40) + SDA ----- GP15 (SPI1 TX) (Pin 20) + SCK ----- GP14 (SPI1 SCK) (Pin 19) + CS ----- GP13 (SPI1 CSn) (Pin 17) + AO(D/C) ----- GP12 (SPI1 RX) (Pin 16) + BL ----- GP11 (Pin 15) + RESET ----- GP10 (Pin 14) + - enc28j60 ENC28J60 SPI ethernet controller support - IP address is configured by DHCP. diff --git a/boards/arm/rp2040/raspberrypi-pico/configs/st7735/defconfig b/boards/arm/rp2040/raspberrypi-pico/configs/st7735/defconfig new file mode 100644 index 0000000000..9b70409ebf --- /dev/null +++ b/boards/arm/rp2040/raspberrypi-pico/configs/st7735/defconfig @@ -0,0 +1,62 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_FS_PROCFS_EXCLUDE_ENVIRON is not set +# CONFIG_LIBC_LONG_LONG is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_DISABLE_DATE is not set +# CONFIG_NSH_DISABLE_LOSMART is not set +# CONFIG_NSH_DISABLE_PRINTF is not set +# CONFIG_NSH_DISABLE_TRUNCATE is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="raspberrypi-pico" +CONFIG_ARCH_BOARD_RASPBERRYPI_PICO=y +CONFIG_ARCH_CHIP="rp2040" +CONFIG_ARCH_CHIP_RP2040=y +CONFIG_ARCH_RAMVECTORS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BOARD_LOOPSPERMSEC=10450 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DISABLE_POSIX_TIMERS=y +CONFIG_DRIVERS_VIDEO=y +CONFIG_EXAMPLES_FB=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_LCD=y +CONFIG_LCD_FRAMEBUFFER=y +CONFIG_LCD_PORTRAIT=y +CONFIG_LCD_ST7735=y +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_RAM_SIZE=270336 +CONFIG_RAM_START=0x20000000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RP2040_SPI1=y +CONFIG_RP2040_SPI1_GPIO=12 +CONFIG_RP2040_SPI=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_SPI_CMDDATA=y +CONFIG_START_DAY=9 +CONFIG_START_MONTH=2 +CONFIG_START_YEAR=2021 +CONFIG_SYSLOG_CONSOLE=y +CONFIG_SYSTEM_NSH=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_VIDEO_FB=y diff --git a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_spi.c b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_spi.c index a0c688366e..2d21633aa8 100644 --- a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_spi.c +++ b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_spi.c @@ -131,7 +131,7 @@ uint8_t rp2040_spi1status(FAR struct spi_dev_s *dev, uint32_t devid) #ifdef CONFIG_SPI_CMDDATA int rp2040_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd) { -#ifdef CONFIG_LCD_ST7789 +#if defined (CONFIG_LCD_ST7789) || (CONFIG_LCD_ST7735) if (devid == SPIDEV_DISPLAY(0)) { /* This is the Data/Command control pad which determines whether the