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



##########
File path: arch/arm/src/nrf52/nrf52_i2c_bitbang.c
##########
@@ -0,0 +1,147 @@
+/****************************************************************************
+ * arch/arm/src/nrf52/nrf52_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 "nrf52_gpio.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct nrf52_i2c_bitbang_dev_s
+{
+  struct i2c_bitbang_lower_dev_s lower;
+  nrf52_pinset_t sda_pin;
+  nrf52_pinset_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
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void i2c_bb_initialize(FAR struct i2c_bitbang_lower_dev_s *lower)
+{
+  struct nrf52_i2c_bitbang_dev_s *dev = lower->priv;
+
+  nrf52_gpio_config(GPIO_INPUT | GPIO_DRIVE_S0D1 | dev->scl_pin);
+  nrf52_gpio_config(GPIO_INPUT | GPIO_DRIVE_S0D1 | dev->sda_pin);
+}
+
+static void i2c_bb_set_scl(FAR struct i2c_bitbang_lower_dev_s *lower,
+                           bool high)
+{
+  struct nrf52_i2c_bitbang_dev_s *dev = lower->priv;
+
+  nrf52_gpio_config(GPIO_OUTPUT | GPIO_DRIVE_S0D1 |
+                    (high ? GPIO_VALUE_ONE : GPIO_VALUE_ZERO) |
+                    dev->scl_pin);
+}
+
+static void i2c_bb_set_sda(FAR struct i2c_bitbang_lower_dev_s *lower,
+                           bool high)
+{
+  struct nrf52_i2c_bitbang_dev_s *dev = lower->priv;
+
+  nrf52_gpio_config(GPIO_OUTPUT | GPIO_DRIVE_S0D1 |
+                    (high ? GPIO_VALUE_ONE : GPIO_VALUE_ZERO) |
+                    dev->sda_pin);
+}
+
+static bool i2c_bb_get_scl(FAR struct i2c_bitbang_lower_dev_s *lower)
+{
+  struct nrf52_i2c_bitbang_dev_s *dev = lower->priv;
+
+  nrf52_gpio_config(GPIO_INPUT | GPIO_DRIVE_S0D1 | dev->scl_pin);

Review comment:
       I think that it is better to have the lower half be really lean since it 
will otherwise add overhead to pin toggling. Anyway, it could be considered 
later on and tested to compare if timings are affected or not.
   
   I still have to analyze timings of this implementation and see if I can 
actually reach required timings.




----------------------------------------------------------------
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