v01d commented on a change in pull request #2717:
URL: https://github.com/apache/incubator-nuttx/pull/2717#discussion_r560149625



##########
File path: drivers/i2c/i2c_bitbang.c
##########
@@ -0,0 +1,340 @@
+/****************************************************************************
+ * arch/arm/src/nrf52/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 <errno.h>
+#include <debug.h>
+
+#include <nuttx/irq.h>
+#include <nuttx/arch.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/kmalloc.h>
+#include <arch/board/board.h>
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/i2c/i2c_bitbang.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct i2c_bitbang_dev_s
+{
+  struct i2c_master_s i2c;
+  struct i2c_bitbang_lower_dev_s *lower;
+
+#ifdef CONFIG_I2C_BITBANG_NO_DELAY
+  uint32_t delay;
+#endif
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int i2c_bitbang_transfer(FAR struct i2c_master_s *dev,
+                                FAR struct i2c_msg_s *msgs, int count);
+
+static int i2c_bitbang_set_scl(FAR struct i2c_bitbang_dev_s *dev,
+                               bool high);
+static void i2c_bitbang_set_sda(FAR struct i2c_bitbang_dev_s *dev,
+                                bool high);
+
+static int i2c_bitbang_wait_ack(FAR struct i2c_bitbang_dev_s *dev);
+static void i2c_bitbang_send(FAR struct i2c_bitbang_dev_s *dev,
+                             uint8_t data);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+struct i2c_ops_s g_i2c_ops =
+{
+  .transfer = i2c_bitbang_transfer
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: i2c_bitbang_transfer
+ ****************************************************************************/
+
+static int i2c_bitbang_transfer(FAR struct i2c_master_s *dev,
+                                FAR struct i2c_msg_s *msgs, int count)
+{
+  FAR struct i2c_bitbang_dev_s *priv = (FAR struct i2c_bitbang_dev_s *)dev;
+  int ret = OK;
+  int i;
+
+  for (i = 0; i < count; i++)
+    {
+      uint8_t addr;
+      FAR struct i2c_msg_s *msg = &msgs[i];
+
+#ifdef CONFIG_I2C_BITBANG_NO_DELAY
+      /* Compute delay from frequency */
+
+      priv->delay = ((1000000 / msg->frequency) / 2) -

Review comment:
       I think that it will reduce overhead of calling the pin handling 
functions if I use the variable from internal structure instead of passing via 
stack.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to