From 181ad49ffd654605d1f350daffa81f9a01c9dd8e Mon Sep 17 00:00:00 2001 From: Peter Bee Date: Mon, 17 May 2021 16:48:35 +0800 Subject: [PATCH] Support for Waveshare Pico-LCD-1.x modules Add support for Chinese brand LCDs. The 1.14" and 1.3" modules are tested. Module details: https://www.waveshare.com/wiki/Pico-LCD-1.14 https://www.waveshare.com/wiki/Pico-LCD-1.3 Signed-off-by: Peter Bee --- boards/arm/rp2040/common/src/rp2040_st7789.c | 37 +++++-- boards/arm/rp2040/raspberrypi-pico/Kconfig | 7 ++ .../configs/waveshare-lcd-1.14/defconfig | 99 +++++++++++++++++++ .../configs/waveshare-lcd-1.3/defconfig | 96 ++++++++++++++++++ .../rp2040/raspberrypi-pico/src/rp2040_spi.c | 13 +++ 5 files changed, 246 insertions(+), 6 deletions(-) create mode 100644 boards/arm/rp2040/raspberrypi-pico/configs/waveshare-lcd-1.14/defconfig create mode 100644 boards/arm/rp2040/raspberrypi-pico/configs/waveshare-lcd-1.3/defconfig diff --git a/boards/arm/rp2040/common/src/rp2040_st7789.c b/boards/arm/rp2040/common/src/rp2040_st7789.c index bc7084789c..24cd8fd453 100644 --- a/boards/arm/rp2040/common/src/rp2040_st7789.c +++ b/boards/arm/rp2040/common/src/rp2040_st7789.c @@ -42,7 +42,15 @@ * Pre-processor Definitions ****************************************************************************/ -#define LCD_SPI_PORTNO 0 +#define LCD_SPI_PORTNO CONFIG_RP2040_LCD_SPI_CH + +#if LCD_SPI_PORTNO +#define LCD_DC CONFIG_RP2040_SPI1_GPIO +#define LCD_RST 12 +#define LCD_BL 13 +#else +#define LCD_DC CONFIG_RP2040_SPI0_GPIO +#endif /**************************************************************************** * Private Data @@ -76,9 +84,25 @@ int board_lcd_initialize(void) /* SPI RX is not used. Same pin is used as LCD Data/Command control */ - rp2040_gpio_init(CONFIG_RP2040_SPI0_GPIO); - rp2040_gpio_setdir(CONFIG_RP2040_SPI0_GPIO, true); - rp2040_gpio_put(CONFIG_RP2040_SPI0_GPIO, true); + 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; } @@ -97,11 +121,12 @@ FAR struct lcd_dev_s *board_lcd_getdev(int devno) g_lcd = st7789_lcdinitialize(g_spidev); if (!g_lcd) { - lcderr("ERROR: Failed to bind SPI port 0 to LCD %d\n", devno); + lcderr("ERROR: Failed to bind SPI port %d to LCD %d\n", LCD_SPI_PORTNO, + devno); } else { - lcdinfo("SPI port 0 bound to LCD %d\n", devno); + lcdinfo("SPI port %d bound to LCD %d\n", LCD_SPI_PORTNO, devno); return g_lcd; } diff --git a/boards/arm/rp2040/raspberrypi-pico/Kconfig b/boards/arm/rp2040/raspberrypi-pico/Kconfig index 769fb26c97..042ade6714 100644 --- a/boards/arm/rp2040/raspberrypi-pico/Kconfig +++ b/boards/arm/rp2040/raspberrypi-pico/Kconfig @@ -63,6 +63,13 @@ config RP2040_SPI1_GPIO range -1 29 depends on RP2040_SPI1 +config RP2040_LCD_SPI_CH + int "RP2040 LCD SPI channel number" + default 0 + range 0 1 + depends on LCD + ---help--- + Select SPI channel number to use LCD display. config RP2040_ENC28J60_SPI_CH int "ENC28J60 SPI channel number" diff --git a/boards/arm/rp2040/raspberrypi-pico/configs/waveshare-lcd-1.14/defconfig b/boards/arm/rp2040/raspberrypi-pico/configs/waveshare-lcd-1.14/defconfig new file mode 100644 index 0000000000..1c06fccedd --- /dev/null +++ b/boards/arm/rp2040/raspberrypi-pico/configs/waveshare-lcd-1.14/defconfig @@ -0,0 +1,99 @@ +# +# 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_EXAMPLES_NXLINES_DEFAULT_COLORS is not set +# 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_NXFONTS_DISABLE_16BPP is not set +# CONFIG_NX_DISABLE_16BPP is not set +# CONFIG_NX_PACKEDMSFIRST is not set +# CONFIG_NX_WRITEONLY 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_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=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_EXAMPLES_NX=y +CONFIG_EXAMPLES_NXDEMO=y +CONFIG_EXAMPLES_NXDEMO_BPP=16 +CONFIG_EXAMPLES_NXHELLO=y +CONFIG_EXAMPLES_NXHELLO_BPP=16 +CONFIG_EXAMPLES_NXLINES=y +CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x0320 +CONFIG_EXAMPLES_NXLINES_BORDERCOLOR=0xffe0 +CONFIG_EXAMPLES_NXLINES_BORDERWIDTH=4 +CONFIG_EXAMPLES_NXLINES_BPP=16 +CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR=0xf7bb +CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xffe0 +CONFIG_EXAMPLES_NX_BPP=16 +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_I2C=y +CONFIG_LCD=y +CONFIG_LCD_DEV=y +CONFIG_LCD_FRAMEBUFFER=y +CONFIG_LCD_MAXCONTRAST=255 +CONFIG_LCD_NOGETRUN=y +CONFIG_LCD_ST7789=y +CONFIG_LCD_ST7789_FREQUENCY=64000000 +CONFIG_LCD_ST7789_XOFFSET=53 +CONFIG_LCD_ST7789_XRES=135 +CONFIG_LCD_ST7789_YOFFSET=40 +CONFIG_LCD_ST7789_YRES=240 +CONFIG_MAX_TASKS=8 +CONFIG_MQ_MAXMSGSIZE=64 +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_NX=y +CONFIG_NXFONTS_PACKEDMSFIRST=y +CONFIG_NXFONT_SANS40X49B=y +CONFIG_NX_BLOCKING=y +CONFIG_RAM_SIZE=270336 +CONFIG_RAM_START=0x20000000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RP2040_LCD_SPI_CH=1 +CONFIG_RP2040_SPI1=y +CONFIG_RP2040_SPI1_GPIO=8 +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_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_SPITOOL=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/configs/waveshare-lcd-1.3/defconfig b/boards/arm/rp2040/raspberrypi-pico/configs/waveshare-lcd-1.3/defconfig new file mode 100644 index 0000000000..2a8472d2ff --- /dev/null +++ b/boards/arm/rp2040/raspberrypi-pico/configs/waveshare-lcd-1.3/defconfig @@ -0,0 +1,96 @@ +# +# 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_EXAMPLES_NXLINES_DEFAULT_COLORS is not set +# 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_NXFONTS_DISABLE_16BPP is not set +# CONFIG_NX_DISABLE_16BPP is not set +# CONFIG_NX_PACKEDMSFIRST is not set +# CONFIG_NX_WRITEONLY 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_ASSERTIONS=y +CONFIG_DEBUG_FEATURES=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_EXAMPLES_NX=y +CONFIG_EXAMPLES_NXDEMO=y +CONFIG_EXAMPLES_NXDEMO_BPP=16 +CONFIG_EXAMPLES_NXHELLO=y +CONFIG_EXAMPLES_NXHELLO_BPP=16 +CONFIG_EXAMPLES_NXLINES=y +CONFIG_EXAMPLES_NXLINES_BGCOLOR=0x0320 +CONFIG_EXAMPLES_NXLINES_BORDERCOLOR=0xffe0 +CONFIG_EXAMPLES_NXLINES_BORDERWIDTH=4 +CONFIG_EXAMPLES_NXLINES_BPP=16 +CONFIG_EXAMPLES_NXLINES_CIRCLECOLOR=0xf7bb +CONFIG_EXAMPLES_NXLINES_LINECOLOR=0xffe0 +CONFIG_EXAMPLES_NX_BPP=16 +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_I2C=y +CONFIG_LCD=y +CONFIG_LCD_DEV=y +CONFIG_LCD_FRAMEBUFFER=y +CONFIG_LCD_MAXCONTRAST=255 +CONFIG_LCD_NOGETRUN=y +CONFIG_LCD_ST7789=y +CONFIG_LCD_ST7789_FREQUENCY=64000000 +CONFIG_LCD_ST7789_YRES=240 +CONFIG_MAX_TASKS=8 +CONFIG_MQ_MAXMSGSIZE=64 +CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_NX=y +CONFIG_NXFONTS_PACKEDMSFIRST=y +CONFIG_NXFONT_SANS40X49B=y +CONFIG_NX_BLOCKING=y +CONFIG_RAM_SIZE=270336 +CONFIG_RAM_START=0x20000000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RP2040_LCD_SPI_CH=1 +CONFIG_RP2040_SPI1=y +CONFIG_RP2040_SPI1_GPIO=8 +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_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_SPITOOL=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 fef438d54c..a0c688366e 100644 --- a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_spi.c +++ b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_spi.c @@ -131,6 +131,19 @@ 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 (devid == SPIDEV_DISPLAY(0)) + { + /* This is the Data/Command control pad which determines whether the + * data bits are data or a command. + */ + + rp2040_gpio_put(CONFIG_RP2040_SPI1_GPIO, !cmd); + + return OK; + } +#endif + return -ENODEV; } #endif