From 9deeae0dee552733a5d5922b9b750095ed2709fa Mon Sep 17 00:00:00 2001 From: Peter Bee Date: Wed, 18 Jan 2023 15:35:09 +0800 Subject: [PATCH] boards/arm/rp2040: add gc9a01 drivers Added gc9a01 drivers to rp2040 Signed-off-by: Peter Bee --- boards/arm/rp2040/common/src/Make.defs | 4 + boards/arm/rp2040/common/src/rp2040_gc9a01.c | 156 +++++++++++++++++++ boards/arm/rp2040/common/src/rp2040_spi.c | 2 +- 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 boards/arm/rp2040/common/src/rp2040_gc9a01.c diff --git a/boards/arm/rp2040/common/src/Make.defs b/boards/arm/rp2040/common/src/Make.defs index d5dc2ca842..097386d9cb 100644 --- a/boards/arm/rp2040/common/src/Make.defs +++ b/boards/arm/rp2040/common/src/Make.defs @@ -59,6 +59,10 @@ ifeq ($(CONFIG_LCD_ST7735),y) CSRCS += rp2040_st7735.c endif +ifeq ($(CONFIG_LCD_GC9A01),y) +CSRCS += rp2040_gc9a01.c +endif + ifeq ($(CONFIG_USBMSC),y) CSRCS += rp2040_usbmsc.c endif diff --git a/boards/arm/rp2040/common/src/rp2040_gc9a01.c b/boards/arm/rp2040/common/src/rp2040_gc9a01.c new file mode 100644 index 0000000000..2abef5f2c4 --- /dev/null +++ b/boards/arm/rp2040/common/src/rp2040_gc9a01.c @@ -0,0 +1,156 @@ +/**************************************************************************** + * boards/arm/rp2040/common/src/rp2040_gc9a01.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 CONFIG_RP2040_LCD_SPI_CH + +#if LCD_SPI_PORTNO +#define LCD_DC CONFIG_RP2040_SPI1_RX_GPIO +#define LCD_RST 12 +#define LCD_BL 25 +#else +#define LCD_DC CONFIG_RP2040_SPI0_RX_GPIO +#endif + +#ifndef CONFIG_SPI_CMDDATA +# error "The GC9A01 driver requires CONFIG_SPI_CMDATA in the config" +#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, false); + up_mdelay(50); + rp2040_gpio_put(LCD_RST, true); + up_mdelay(50); + + /* 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. + * + ****************************************************************************/ + +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", 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/common/src/rp2040_spi.c b/boards/arm/rp2040/common/src/rp2040_spi.c index d6b39b192c..a2f0fea777 100644 --- a/boards/arm/rp2040/common/src/rp2040_spi.c +++ b/boards/arm/rp2040/common/src/rp2040_spi.c @@ -131,7 +131,7 @@ uint8_t rp2040_spi1status(struct spi_dev_s *dev, uint32_t devid) #ifdef CONFIG_SPI_CMDDATA int rp2040_spi1cmddata(struct spi_dev_s *dev, uint32_t devid, bool cmd) { -#if defined (CONFIG_LCD_ST7789) || (CONFIG_LCD_ST7735) +#if defined (CONFIG_LCD_ST7789) || defined (CONFIG_LCD_ST7735) || defined (CONFIG_LCD_GC9A01) if (devid == SPIDEV_DISPLAY(0)) { /* This is the Data/Command control pad which determines whether the