You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/09/15 04:02:32 UTC

[incubator-nuttx] branch master updated: esp32-wrover: Add support to LCD1602 with I2C Backpack

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 60d4ee1  esp32-wrover: Add support to LCD1602 with I2C Backpack
60d4ee1 is described below

commit 60d4ee11eef88972f7eeffd9d0b1ca5967395964
Author: Alan C. Assis <ac...@gmail.com>
AuthorDate: Tue Sep 14 16:50:33 2021 -0300

    esp32-wrover: Add support to LCD1602 with I2C Backpack
---
 .../esp32/common/include/esp32_lcd_backpack.h      | 83 ++++++++++++++++++
 boards/xtensa/esp32/common/src/Make.defs           |  4 +
 .../xtensa/esp32/common/src/esp32_lcd_backpack.c   | 98 ++++++++++++++++++++++
 .../esp32-wrover-kit/configs/lcd1602/defconfig     | 51 +++++++++++
 .../esp32/esp32-wrover-kit/src/esp32_bringup.c     | 15 ++++
 5 files changed, 251 insertions(+)

diff --git a/boards/xtensa/esp32/common/include/esp32_lcd_backpack.h b/boards/xtensa/esp32/common/include/esp32_lcd_backpack.h
new file mode 100644
index 0000000..7a3ebfa
--- /dev/null
+++ b/boards/xtensa/esp32/common/include/esp32_lcd_backpack.h
@@ -0,0 +1,83 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/include/esp32_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 __ESP32_LCD_BACKPACK_H
+#define __ESP32_LCD_BACKPACK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * 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 /* __ESP3232_LCD_BACKPACK_H */
diff --git a/boards/xtensa/esp32/common/src/Make.defs b/boards/xtensa/esp32/common/src/Make.defs
index d8dfeb5..7ff7021 100644
--- a/boards/xtensa/esp32/common/src/Make.defs
+++ b/boards/xtensa/esp32/common/src/Make.defs
@@ -54,6 +54,10 @@ ifeq ($(CONFIG_CAN_MCP2515),y)
   CSRCS += esp32_mcp2515.c
 endif
 
+ifeq ($(CONFIG_LCD_BACKPACK),y)
+  CSRCS += esp32_lcd_backpack.c
+endif
+
 ifeq ($(CONFIG_LCD_ILI9341),y)
   CSRCS += esp32_ili9341.c
 endif
diff --git a/boards/xtensa/esp32/common/src/esp32_lcd_backpack.c b/boards/xtensa/esp32/common/src/esp32_lcd_backpack.c
new file mode 100644
index 0000000..137165b
--- /dev/null
+++ b/boards/xtensa/esp32/common/src/esp32_lcd_backpack.c
@@ -0,0 +1,98 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_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 <nuttx/config.h>
+
+#include <errno.h>
+#include <debug.h>
+#include <syslog.h>
+#include <stdio.h>
+
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/lcd/pcf8574_lcd_backpack.h>
+
+#include "esp32_board_i2c.h"
+#include "esp32_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_SAINSMART;
+  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 I2C1 */
+
+  i2c = esp32_i2cbus_initialize(busno);
+  if (i2c == NULL)
+    {
+      return -ENODEV;
+    }
+
+  /* Register 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/xtensa/esp32/esp32-wrover-kit/configs/lcd1602/defconfig b/boards/xtensa/esp32/esp32-wrover-kit/configs/lcd1602/defconfig
new file mode 100644
index 0000000..9c8b7db
--- /dev/null
+++ b/boards/xtensa/esp32/esp32-wrover-kit/configs/lcd1602/defconfig
@@ -0,0 +1,51 @@
+#
+# 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_ARCH_LEDS is not set
+# CONFIG_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+# CONFIG_NSH_CMDPARMS is not set
+CONFIG_ARCH="xtensa"
+CONFIG_ARCH_BOARD="esp32-wrover-kit"
+CONFIG_ARCH_BOARD_ESP32_WROVERKIT=y
+CONFIG_ARCH_CHIP="esp32"
+CONFIG_ARCH_CHIP_ESP32=y
+CONFIG_ARCH_CHIP_ESP32WROVER=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_XTENSA=y
+CONFIG_BOARD_LOOPSPERMSEC=16717
+CONFIG_BUILTIN=y
+CONFIG_ESP32_I2C0=y
+CONFIG_ESP32_UART0=y
+CONFIG_EXAMPLES_SLCD=y
+CONFIG_FS_PROCFS=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_I2C=y
+CONFIG_IDLETHREAD_STACKSIZE=3072
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LCD_BACKPACK=y
+CONFIG_MM_REGIONS=3
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAM_SIZE=114688
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_SLCD=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_SYSTEM_NSH=y
+CONFIG_UART0_SERIAL_CONSOLE=y
+CONFIG_USER_ENTRYPOINT="nsh_main"
diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c
index b7517d2..2a6152b 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_bringup.c
@@ -94,6 +94,10 @@
 #  include "esp32_rtc_lowerhalf.h"
 #endif
 
+#ifdef CONFIG_LCD_BACKPACK
+#  include "esp32_lcd_backpack.h"
+#endif
+
 #include "esp32-wrover-kit.h"
 
 /****************************************************************************
@@ -148,6 +152,17 @@ int esp32_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_MMCSD
   ret = esp32_mmcsd_initialize(0);
   if (ret < 0)