You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/01/19 04:07:25 UTC

[GitHub] [incubator-nuttx] patacongo commented on a change in pull request #2717: I2C bitbang driver (and nRF52 implementation)

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



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

Review comment:
       > Right. Is `spin_lock_irqsave` OK? Not entirely sure when to use it instead of `enter_critical_section`.
   
   You can use spin_lock_irqsave() when the thread cannot possibly suspend itself within the critical section.  If you can tolerate jitter from interrupt processing, sched_lock() will keep the thread in place, i.e., that it cannot be suspended.




----------------------------------------------------------------
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:
users@infra.apache.org