diff --git a/boards/arm/rp2040/common/include/rp2040_lcd_backpack.h b/boards/arm/rp2040/common/include/rp2040_lcd_backpack.h new file mode 100644 index 0000000000..1caf310795 --- /dev/null +++ b/boards/arm/rp2040/common/include/rp2040_lcd_backpack.h @@ -0,0 +1,83 @@ +/**************************************************************************** + * boards/arm/rp2040/common/include/rp2040_lcd_backpack.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __RP2040_LCD_BACKPACK_H +#define __RP2040_LCD_BACKPACK_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_lcd_backpack_init + * + * Description: + * Initialize the LCD1602 display controlled by Backpack with PCF8574 + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/slcd0" + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_lcd_backpack_init(int devno, int busno, int rows, int cols); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __RP2040_LCD_BACKPACK_H */ diff --git a/boards/arm/rp2040/common/src/Make.defs b/boards/arm/rp2040/common/src/Make.defs index 32199ac7cf..1b68a12ee4 100644 --- a/boards/arm/rp2040/common/src/Make.defs +++ b/boards/arm/rp2040/common/src/Make.defs @@ -62,6 +62,10 @@ ifeq ($(CONFIG_ENC28J60),y) CSRCS += rp2040_enc28j60.c endif +ifeq ($(CONFIG_LCD_BACKPACK),y) + CSRCS += rp2040_lcd_backpack.c +endif + DEPPATH += --dep-path src VPATH += :src CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src) diff --git a/boards/arm/rp2040/common/src/rp2040_lcd_backpack.c b/boards/arm/rp2040/common/src/rp2040_lcd_backpack.c new file mode 100644 index 0000000000..7b1b8360c6 --- /dev/null +++ b/boards/arm/rp2040/common/src/rp2040_lcd_backpack.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * boards/arm/rp2040/common/src/rp2040_lcd_backpack.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 "rp2040_i2c.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_lcd_backpack_init + * + * Description: + * Initialize the LCD1602 display controlled by Backpack with PCF8574 + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/slcd0" + * + * Returned Value: + * Zero (OK) on success; a negated errno value on failure. + * + ****************************************************************************/ + +int board_lcd_backpack_init(int devno, int busno, int rows, int cols) +{ + FAR struct pcf8574_lcd_backpack_config_s cfg = + LCD_I2C_BACKPACK_CFG_ROBOT; + FAR struct i2c_master_s *i2c; + char devpath[12]; + int ret; + + /* Setup the LCD row and cols size. + * Note: We are using the LCD_I2C_BACKPACK_CFG_SAINSMART config that + * defined the I2C Address to 0x27 to PCF8574. Double check if all + * the bits (pins) from PCF8574 connected to the LCD controller + * are correct with this LCD CFG definition. + */ + + cfg.rows = rows; + cfg.cols = cols; + + /* Initialize the I2C0 */ + + i2c = rp2040_i2cbus_initialize(busno); + if (i2c == NULL) + { + return -ENODEV; + } + + /* Regiter the Segment LCD */ + + snprintf(devpath, 12, "/dev/slcd%d", devno); + ret = pcf8574_lcd_backpack_register(devpath, i2c, &cfg); + if (ret < 0) + { + lcderr("ERROR: pcf8574_lcd_backpack_register(%s) failed: %d\n", + devpath, ret); + return ret; + } + + return OK; +} diff --git a/boards/arm/rp2040/raspberrypi-pico/README.txt b/boards/arm/rp2040/raspberrypi-pico/README.txt index 1126568565..c043cd320a 100644 --- a/boards/arm/rp2040/raspberrypi-pico/README.txt +++ b/boards/arm/rp2040/raspberrypi-pico/README.txt @@ -83,7 +83,15 @@ Defconfigs VCC ----- 3V3 OUT (Pin 36) SDA ----- GP4 (I2C0 SDA) (Pin 6) SCL ----- GP5 (I2C0 SCL) (Pin 7) - + +- lcd1602 + LCD 1602 Segment LCD Disaply (I2C) + Connection: + PCF8574 BackPack Raspberry Pi Pico + GND ----- GND (Pin 3 or 38 or ...) + VCC ----- 5V Vbus (Pin 40) + SDA ----- GP4 (I2C0 SDA) (Pin 6) + SCL ----- GP5 (I2C0 SCL) (Pin 7) - spisd SD card support (SPI connection) Connection: diff --git a/boards/arm/rp2040/raspberrypi-pico/configs/lcd1602/defconfig b/boards/arm/rp2040/raspberrypi-pico/configs/lcd1602/defconfig new file mode 100644 index 0000000000..5829a23f44 --- /dev/null +++ b/boards/arm/rp2040/raspberrypi-pico/configs/lcd1602/defconfig @@ -0,0 +1,60 @@ +# +# 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_EXAMPLES_HELLO=y +CONFIG_EXAMPLES_SLCD=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_LCD_BACKPACK=y +CONFIG_LCD_LCD1602=y +CONFIG_MAX_TASKS=8 +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_I2C0=y +CONFIG_RP2040_I2C0_GPIO=4 +CONFIG_RP2040_I2C=y +CONFIG_RP2040_I2C_DRIVER=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_SDCLONE_DISABLE=y +CONFIG_SLCD=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" diff --git a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c index 12da0f765c..96ee480461 100644 --- a/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c +++ b/boards/arm/rp2040/raspberrypi-pico/src/rp2040_bringup.c @@ -33,6 +33,10 @@ #include "rp2040_pico.h" +#ifdef CONFIG_LCD_BACKPACK +# include "rp2040_lcd_backpack.h" +#endif + #ifdef CONFIG_VIDEO_FB # include #endif @@ -134,6 +138,17 @@ int rp2040_bringup(void) } #endif +#ifdef CONFIG_LCD_BACKPACK + /* slcd:0, i2c:0, rows=2, cols=16 */ + + ret = board_lcd_backpack_init(0, 0, 2, 16); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize PCF8574 LCD, error %d\n", ret); + return ret; + } +#endif + #ifdef CONFIG_RP2040_I2S ret = board_i2sdev_initialize(0); if (ret < 0)