You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/01/26 16:59:41 UTC

[incubator-nuttx] branch master updated (90ffb03 -> 0261e58)

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

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


    from 90ffb03  include: nuttx: nx: nxstyle fixes
     new 7723ce4  arch: cxd56xx: Add I2C bitbang lower driver
     new 0261e58  boards: cxd56xx: Add I2C bitbang driver registration

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/arm/src/cxd56xx/Make.defs                     |  4 +
 .../cxd56_i2c_bitbang.c}                           | 96 +++++++---------------
 .../arm/src/cxd56xx/cxd56_i2c_bitbang.h            | 27 +++---
 boards/arm/cxd56xx/common/src/Make.defs            |  4 +
 .../src/{cxd56_i2cdev.c => cxd56_i2cdev_bitbang.c} | 31 +++++--
 .../arm/cxd56xx/spresense/include/cxd56_i2cdev.h   | 20 +++++
 6 files changed, 92 insertions(+), 90 deletions(-)
 copy arch/arm/src/{nrf52/nrf52_i2c_bitbang.c => cxd56xx/cxd56_i2c_bitbang.c} (61%)
 copy include/nuttx/timers/arch_alarm.h => arch/arm/src/cxd56xx/cxd56_i2c_bitbang.h (80%)
 copy boards/arm/cxd56xx/common/src/{cxd56_i2cdev.c => cxd56_i2cdev_bitbang.c} (72%)


[incubator-nuttx] 01/02: arch: cxd56xx: Add I2C bitbang lower driver

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7723ce46ceb59f8e87fb22630017427b8288aa0d
Author: baggio63446333 <ba...@users.noreply.github.com>
AuthorDate: Tue Jan 26 11:49:15 2021 +0900

    arch: cxd56xx: Add I2C bitbang lower driver
    
    Add I2C bitbang lower driver for cxd56xx.
---
 arch/arm/src/cxd56xx/Make.defs           |   4 +
 arch/arm/src/cxd56xx/cxd56_i2c_bitbang.c | 141 +++++++++++++++++++++++++++++++
 arch/arm/src/cxd56xx/cxd56_i2c_bitbang.h |  51 +++++++++++
 3 files changed, 196 insertions(+)

diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs
index 66d3142..4f56e6e 100644
--- a/arch/arm/src/cxd56xx/Make.defs
+++ b/arch/arm/src/cxd56xx/Make.defs
@@ -149,6 +149,10 @@ ifeq ($(CONFIG_CXD56_I2C),y)
 CHIP_CSRCS += cxd56_i2c.c
 endif
 
+ifeq ($(CONFIG_I2C_BITBANG),y)
+CHIP_CSRCS += cxd56_i2c_bitbang.c
+endif
+
 ifeq ($(CONFIG_CXD56_DMAC),y)
 CHIP_CSRCS += cxd56_dmac.c
 endif
diff --git a/arch/arm/src/cxd56xx/cxd56_i2c_bitbang.c b/arch/arm/src/cxd56xx/cxd56_i2c_bitbang.c
new file mode 100644
index 0000000..e045b43
--- /dev/null
+++ b/arch/arm/src/cxd56xx/cxd56_i2c_bitbang.c
@@ -0,0 +1,141 @@
+/****************************************************************************
+ * arch/arm/src/cxd56/cxd56_i2c_bitbang.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 <nuttx/i2c/i2c_master.h>
+#include <nuttx/i2c/i2c_bitbang.h>
+#include <nuttx/kmalloc.h>
+#include <arch/board/board.h>
+#include <arch/chip/pin.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct cxd56_i2c_bitbang_dev_s
+{
+  struct i2c_bitbang_lower_dev_s lower;
+  uint32_t sda_pin;
+  uint32_t scl_pin;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static void i2c_bb_initialize(FAR struct i2c_bitbang_lower_dev_s *lower);
+
+static void i2c_bb_set_scl(FAR struct i2c_bitbang_lower_dev_s *lower,
+                           bool high);
+static void i2c_bb_set_sda(FAR struct i2c_bitbang_lower_dev_s *lower,
+                           bool high);
+
+static bool i2c_bb_get_scl(FAR struct i2c_bitbang_lower_dev_s *lower);
+static bool i2c_bb_get_sda(FAR struct i2c_bitbang_lower_dev_s *lower);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+const static struct i2c_bitbang_lower_ops_s g_ops =
+{
+  .initialize = i2c_bb_initialize,
+  .set_scl    = i2c_bb_set_scl,
+  .set_sda    = i2c_bb_set_sda,
+  .get_scl    = i2c_bb_get_scl,
+  .get_sda    = i2c_bb_get_sda
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void i2c_bb_initialize(FAR struct i2c_bitbang_lower_dev_s *lower)
+{
+  struct cxd56_i2c_bitbang_dev_s *dev = lower->priv;
+
+  /* Set to input enable and pull-up */
+
+  board_gpio_config(dev->scl_pin, 0, true, true, PIN_PULLUP);
+  board_gpio_config(dev->sda_pin, 0, true, true, PIN_PULLUP);
+}
+
+static void i2c_bb_set_scl(FAR struct i2c_bitbang_lower_dev_s *lower,
+                           bool high)
+{
+  struct cxd56_i2c_bitbang_dev_s *dev = lower->priv;
+  int value;
+
+  /* If set high, pin is pulled up by output disable */
+
+  value = (high) ? -1 : 0;
+  board_gpio_write(dev->scl_pin, value);
+}
+
+static void i2c_bb_set_sda(FAR struct i2c_bitbang_lower_dev_s *lower,
+                           bool high)
+{
+  struct cxd56_i2c_bitbang_dev_s *dev = lower->priv;
+  int value;
+
+  /* If set high, pin is pulled up by output disable */
+
+  value = (high) ? -1 : 0;
+  board_gpio_write(dev->sda_pin, value);
+}
+
+static bool i2c_bb_get_scl(FAR struct i2c_bitbang_lower_dev_s *lower)
+{
+  struct cxd56_i2c_bitbang_dev_s *dev = lower->priv;
+
+  return board_gpio_read(dev->scl_pin);
+}
+
+static bool i2c_bb_get_sda(FAR struct i2c_bitbang_lower_dev_s *lower)
+{
+  struct cxd56_i2c_bitbang_dev_s *dev = lower->priv;
+
+  return board_gpio_read(dev->sda_pin);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+struct i2c_master_s *cxd56_i2c_bitbang_initialize(uint32_t sda_pin,
+                                                  uint32_t scl_pin)
+{
+  struct cxd56_i2c_bitbang_dev_s *dev =
+      (struct cxd56_i2c_bitbang_dev_s *)
+          kmm_zalloc(sizeof(struct cxd56_i2c_bitbang_dev_s));
+
+  DEBUGASSERT(dev);
+
+  dev->lower.ops = &g_ops;
+  dev->lower.priv = dev;
+  dev->scl_pin = scl_pin;
+  dev->sda_pin = sda_pin;
+
+  return i2c_bitbang_initialize(&dev->lower);
+}
diff --git a/arch/arm/src/cxd56xx/cxd56_i2c_bitbang.h b/arch/arm/src/cxd56xx/cxd56_i2c_bitbang.h
new file mode 100644
index 0000000..1311552
--- /dev/null
+++ b/arch/arm/src/cxd56xx/cxd56_i2c_bitbang.h
@@ -0,0 +1,51 @@
+/****************************************************************************
+ * arch/arm/src/cxd56/cxd56_i2c_bitbang.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 __ARCH_ARM_SRC_CXD56_CXD56_I2C_BITBANG_H
+#define __ARCH_ARM_SRC_CXD56_CXD56_I2C_BITBANG_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/i2c/i2c_master.h>
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+struct i2c_master_s *cxd56_i2c_bitbang_initialize(uint32_t sda_pin,
+                                                  uint32_t scl_pin);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ARCH_ARM_SRC_CXD56_CXD56_I2C_BITBANG_H */


[incubator-nuttx] 02/02: boards: cxd56xx: Add I2C bitbang driver registration

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0261e58a8b0e71caef99ed995b8b92a28a0fc3a1
Author: baggio63446333 <ba...@users.noreply.github.com>
AuthorDate: Tue Jan 26 12:38:12 2021 +0900

    boards: cxd56xx: Add I2C bitbang driver registration
    
    Add board API to register i2c bitbang driver as i2c device.
---
 boards/arm/cxd56xx/common/src/Make.defs            |  4 ++
 .../src/cxd56_i2cdev_bitbang.c}                    | 76 +++++++++++++---------
 .../arm/cxd56xx/spresense/include/cxd56_i2cdev.h   | 20 ++++++
 3 files changed, 68 insertions(+), 32 deletions(-)

diff --git a/boards/arm/cxd56xx/common/src/Make.defs b/boards/arm/cxd56xx/common/src/Make.defs
index f54527e..0895c22 100644
--- a/boards/arm/cxd56xx/common/src/Make.defs
+++ b/boards/arm/cxd56xx/common/src/Make.defs
@@ -136,6 +136,10 @@ ifeq ($(CONFIG_CXD56_I2C_DRIVER),y)
 CSRCS += cxd56_i2cdev.c
 endif
 
+ifeq ($(CONFIG_I2C_BITBANG),y)
+CSRCS += cxd56_i2cdev_bitbang.c
+endif
+
 ifeq ($(CONFIG_CXD56_SPI_DRIVER),y)
 CSRCS += cxd56_spidev.c
 endif
diff --git a/boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h b/boards/arm/cxd56xx/common/src/cxd56_i2cdev_bitbang.c
similarity index 57%
copy from boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h
copy to boards/arm/cxd56xx/common/src/cxd56_i2cdev_bitbang.c
index e5d200f..1e101de 100644
--- a/boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h
+++ b/boards/arm/cxd56xx/common/src/cxd56_i2cdev_bitbang.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h
+ * boards/arm/cxd56xx/common/src/cxd56_i2cdev_bitbang.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -18,54 +18,66 @@
  *
  ****************************************************************************/
 
-#ifndef __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_I2CDEV_H
-#define __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_I2CDEV_H
-
 /****************************************************************************
  * Included Files
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <nuttx/i2c/i2c_master.h>
 
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-#ifndef __ASSEMBLY__
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
+#include <stdio.h>
+#include <debug.h>
+#include <errno.h>
 
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C"
-{
-#else
-#define EXTERN extern
-#endif
+#include "cxd56_i2c_bitbang.h"
 
 /****************************************************************************
- * Public Function Prototypes
+ * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: board_i2cdev_initialize
+ * Name: board_i2cdev_bitbang_initialize
  *
  * Description:
- *   Initialize i2c driver and register the /dev/i2c device.
+ *   Initialize i2c bitbang driver and register as the /dev/i2c device.
+ *
+ * Input Parameters:
+ *   sda_pin - The pin number used as I2C SDA signal
+ *   scl_pin - The pin number used as I2C SCL signal
+ *
+ * Returned Value:
+ *   OK on success; Negated errno on failure.
  *
  ****************************************************************************/
 
-#ifdef CONFIG_CXD56_I2C_DRIVER
-int board_i2cdev_initialize(int bus);
-#endif
+int board_i2cdev_bitbang_initialize(uint32_t sda_pin, uint32_t scl_pin)
+{
+  int ret = 0;
+  FAR struct i2c_master_s *i2c;
+  int port;
 
-#undef EXTERN
-#if defined(__cplusplus)
-}
+  /* Use a sda pin number as port number */
+
+  port = sda_pin;
+
+  _info("Initializing /dev/i2c%d..\n", port);
+
+  /* Initialize i2c bitbang device */
+
+  i2c = cxd56_i2c_bitbang_initialize(sda_pin, scl_pin);
+  if (!i2c)
+    {
+      _err("ERROR: Failed to initialize i2c%d.\n", port);
+      return -ENODEV;
+    }
+
+#ifdef CONFIG_I2C_DRIVER
+  ret = i2c_register(i2c, port);
+  if (ret < 0)
+    {
+      _err("ERROR: Failed to register i2c%d: %d\n", port, ret);
+    }
 #endif
 
-#endif /* __ASSEMBLY__ */
-#endif /* __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_I2CDEV_H */
+  return ret;
+}
diff --git a/boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h b/boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h
index e5d200f..2f043dd 100644
--- a/boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h
+++ b/boards/arm/cxd56xx/spresense/include/cxd56_i2cdev.h
@@ -26,6 +26,7 @@
  ****************************************************************************/
 
 #include <nuttx/config.h>
+#include <stdint.h>
 
 /****************************************************************************
  * Public Types
@@ -62,6 +63,25 @@ extern "C"
 int board_i2cdev_initialize(int bus);
 #endif
 
+/****************************************************************************
+ * Name: board_i2cdev_bitbang_initialize
+ *
+ * Description:
+ *   Initialize i2c bitbang driver and register as the /dev/i2c device.
+ *
+ * Input Parameters:
+ *   sda_pin - The pin number used as I2C SDA signal
+ *   scl_pin - The pin number used as I2C SCL signal
+ *
+ * Returned Value:
+ *   OK on success; Negated errno on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_I2C_BITBANG
+int board_i2cdev_bitbang_initialize(uint32_t sda_pin, uint32_t scl_pin);
+#endif
+
 #undef EXTERN
 #if defined(__cplusplus)
 }