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/01/18 07:46:12 UTC

[incubator-nuttx] branch master updated: nrf52: Add simple i2c test configuration

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 3a64783  nrf52: Add simple i2c test configuration
3a64783 is described below

commit 3a647832735755c7535cd74999bb113b06b604ef
Author: Brennan Ashton <ba...@brennanashton.com>
AuthorDate: Sun Jan 17 15:16:36 2021 -0800

    nrf52: Add simple i2c test configuration
    
    Signed-off-by: Brennan Ashton <ba...@brennanashton.com>
---
 arch/arm/src/nrf52/nrf52_i2c.c                     |  6 +-
 .../arm/nrf52/nrf52-feather/configs/i2c/defconfig  | 50 ++++++++++++
 boards/arm/nrf52/nrf52-feather/include/board.h     |  5 ++
 boards/arm/nrf52/nrf52-feather/src/Makefile        |  4 +
 boards/arm/nrf52/nrf52-feather/src/nrf52-feather.h | 26 +++++-
 boards/arm/nrf52/nrf52-feather/src/nrf52_bringup.c |  6 ++
 boards/arm/nrf52/nrf52-feather/src/nrf52_i2c.c     | 95 ++++++++++++++++++++++
 7 files changed, 188 insertions(+), 4 deletions(-)

diff --git a/arch/arm/src/nrf52/nrf52_i2c.c b/arch/arm/src/nrf52/nrf52_i2c.c
index 6dcc579..2a4233f 100644
--- a/arch/arm/src/nrf52/nrf52_i2c.c
+++ b/arch/arm/src/nrf52/nrf52_i2c.c
@@ -370,7 +370,7 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
                                         NRF52_TWIM_ERRORSRC_OFFSET) & 0x7;
               if (regval != 0)
                 {
-                  i2cerr("Error SRC: %x\n", regval);
+                  i2cerr("Error SRC: 0x%08" PRIx32 "\n", regval);
                   ret = -1;
                   nrf52_i2c_putreg(priv,
                                   NRF52_TWIM_ERRORSRC_OFFSET, 0x7);
@@ -421,7 +421,7 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
                                       NRF52_TWIM_ERRORSRC_OFFSET) & 0x7;
             if (regval != 0)
               {
-                i2cerr("Error SRC: %x\n", regval);
+                i2cerr("Error SRC: 0x%08" PRIx32 "\n", regval);
                 ret = -1;
                 nrf52_i2c_putreg(priv,
                                  NRF52_TWIM_ERRORSRC_OFFSET, 0x7);
@@ -468,7 +468,7 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
                                 NRF52_TWIM_ERRORSRC_OFFSET) & 0x7;
       if (regval != 0)
         {
-          i2cerr("Error SRC: %x\n", regval);
+          i2cerr("Error SRC: 0x%08" PRIx32 "\n", regval);
           ret = -1;
           nrf52_i2c_putreg(priv,
                            NRF52_TWIM_ERRORSRC_OFFSET, 0x7);
diff --git a/boards/arm/nrf52/nrf52-feather/configs/i2c/defconfig b/boards/arm/nrf52/nrf52-feather/configs/i2c/defconfig
new file mode 100644
index 0000000..6caaead
--- /dev/null
+++ b/boards/arm/nrf52/nrf52-feather/configs/i2c/defconfig
@@ -0,0 +1,50 @@
+#
+# 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_FPU is not set
+# CONFIG_NSH_DISABLE_IFCONFIG is not set
+# CONFIG_NSH_DISABLE_PS is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="nrf52-feather"
+CONFIG_ARCH_BOARD_NRF52_FEATHER=y
+CONFIG_ARCH_CHIP="nrf52"
+CONFIG_ARCH_CHIP_NRF52832=y
+CONFIG_ARCH_CHIP_NRF52=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_STDARG_H=y
+CONFIG_BOARD_LOOPSPERMSEC=5500
+CONFIG_BUILTIN=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_I2C=y
+CONFIG_I2C_POLLED=y
+CONFIG_MAX_TASKS=16
+CONFIG_MM_REGIONS=2
+CONFIG_NFILE_DESCRIPTORS=8
+CONFIG_NRF52_I2C0_MASTER=y
+CONFIG_NRF52_UART0=y
+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=65535
+CONFIG_RAM_START=0x20000000
+CONFIG_RAW_BINARY=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SDCLONE_DISABLE=y
+CONFIG_START_DAY=26
+CONFIG_START_MONTH=3
+CONFIG_SYMTAB_ORDEREDBYNAME=y
+CONFIG_SYSTEM_I2CTOOL=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TASK_NAME_SIZE=0
+CONFIG_UART0_SERIAL_CONSOLE=y
+CONFIG_USER_ENTRYPOINT="nsh_main"
diff --git a/boards/arm/nrf52/nrf52-feather/include/board.h b/boards/arm/nrf52/nrf52-feather/include/board.h
index 50f74fd..e031d65 100644
--- a/boards/arm/nrf52/nrf52-feather/include/board.h
+++ b/boards/arm/nrf52/nrf52-feather/include/board.h
@@ -106,4 +106,9 @@
 #define BOARD_UART0_RX_PIN  (GPIO_INPUT  | GPIO_PORT0 | GPIO_PIN(8))
 #define BOARD_UART0_TX_PIN  (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(6))
 
+/* I2C Pins *****************************************************************/
+
+#define BOARD_I2C0_SCL_PIN (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT0 | GPIO_PIN(26))
+#define BOARD_I2C0_SDA_PIN (GPIO_INPUT  | GPIO_PORT0 | GPIO_PIN(25))
+
 #endif /* __BOARDS_ARM_NRF52_NRF52_FEATHER_INCLUDE_BOARD_H */
diff --git a/boards/arm/nrf52/nrf52-feather/src/Makefile b/boards/arm/nrf52/nrf52-feather/src/Makefile
index 65fb5d6..63e9b4b 100644
--- a/boards/arm/nrf52/nrf52-feather/src/Makefile
+++ b/boards/arm/nrf52/nrf52-feather/src/Makefile
@@ -47,4 +47,8 @@ else
 CSRCS += nrf52_userleds.c
 endif
 
+ifeq ($(CONFIG_I2C),y)
+CSRCS += nrf52_i2c.c
+endif
+
 include $(TOPDIR)/boards/Board.mk
diff --git a/boards/arm/nrf52/nrf52-feather/src/nrf52-feather.h b/boards/arm/nrf52/nrf52-feather/src/nrf52-feather.h
index db862d5..c280fe1 100644
--- a/boards/arm/nrf52/nrf52-feather/src/nrf52-feather.h
+++ b/boards/arm/nrf52/nrf52-feather/src/nrf52-feather.h
@@ -71,10 +71,34 @@
 #ifndef __ASSEMBLY__
 
 /****************************************************************************
- * Public Functions
+ * Public Functions Prototypes
  ****************************************************************************/
 
 /****************************************************************************
+ * Name: nrf52_i2c_register
+ *
+ * Description:
+ *   Register one I2C drivers for the I2C tool.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_I2C
+int nrf52_i2c_register(int bus);
+#endif
+
+/****************************************************************************
+ * Name: nrf52_i2ctool
+ *
+ * Description:
+ *   Register I2C drivers for the I2C tool.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSTEM_I2CTOOL
+int nrf52_i2ctool(void);
+#endif
+
+/****************************************************************************
  * Name: nrf52_bringup
  *
  * Description:
diff --git a/boards/arm/nrf52/nrf52-feather/src/nrf52_bringup.c b/boards/arm/nrf52/nrf52-feather/src/nrf52_bringup.c
index 78cbf7d..b1db6c8 100644
--- a/boards/arm/nrf52/nrf52-feather/src/nrf52_bringup.c
+++ b/boards/arm/nrf52/nrf52-feather/src/nrf52_bringup.c
@@ -50,6 +50,8 @@
 #  include <nuttx/leds/userled.h>
 #endif
 
+#include "nrf52-feather.h"
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -92,6 +94,10 @@ int nrf52_bringup(void)
     }
 #endif
 
+#if defined(CONFIG_I2C) && defined(CONFIG_SYSTEM_I2CTOOL)
+  nrf52_i2ctool();
+#endif
+
   UNUSED(ret);
   return OK;
 }
diff --git a/boards/arm/nrf52/nrf52-feather/src/nrf52_i2c.c b/boards/arm/nrf52/nrf52-feather/src/nrf52_i2c.c
new file mode 100644
index 0000000..3eb976a
--- /dev/null
+++ b/boards/arm/nrf52/nrf52-feather/src/nrf52_i2c.c
@@ -0,0 +1,95 @@
+/****************************************************************************
+ * boards/arm/nrf52/nrf52-feather/src/nrf52_i2c.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 <syslog.h>
+
+#ifdef CONFIG_I2C
+#  include "nrf52_i2c.h"
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nrf52_i2c_register
+ *
+ * Description:
+ *   Register one I2C drivers for the I2C tool.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_I2C
+int nrf52_i2c_register(int bus)
+{
+  struct i2c_master_s *i2c;
+  int ret = OK;
+
+  i2c = nrf52_i2cbus_initialize(bus);
+  if (i2c == NULL)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
+    }
+  else
+    {
+      ret = i2c_register(i2c, bus);
+      if (ret < 0)
+        {
+          syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
+                 bus, ret);
+          nrf52_i2cbus_uninitialize(i2c);
+        }
+    }
+
+  return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: nrf52_i2ctool
+ *
+ * Description:
+ *   Register I2C drivers for the I2C tool.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SYSTEM_I2CTOOL
+int nrf52_i2ctool(void)
+{
+  int ret = OK;
+#ifdef CONFIG_NRF52_I2C0_MASTER
+  ret = nrf52_i2c_register(0);
+  if (ret != OK)
+    {
+      return ret;
+    }
+#endif
+
+#ifdef CONFIG_NRF52_I2C1_MASTER
+  ret = nrf52_i2c_register(0);
+#endif
+  return ret;
+}
+#endif