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:43 UTC
[incubator-nuttx] 02/02: boards: cxd56xx: Add I2C bitbang driver
registration
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)
}