You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2022/02/14 08:11:45 UTC

[mynewt-core] 01/10: bus/i2c: Add probe functionality

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

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 4b5826f8b2c362aae3247af6592d3b292a14431c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 30 15:25:56 2021 +0200

    bus/i2c: Add probe functionality
    
    This adds probe function to I2C bus driver operations.
    It will allow to use i2c_scan module for bus driver
    builds.
---
 hw/bus/drivers/i2c_common/include/bus/drivers/i2c_common.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/bus/drivers/i2c_common/include/bus/drivers/i2c_common.h b/hw/bus/drivers/i2c_common/include/bus/drivers/i2c_common.h
index 9f70123..e7fa161 100644
--- a/hw/bus/drivers/i2c_common/include/bus/drivers/i2c_common.h
+++ b/hw/bus/drivers/i2c_common/include/bus/drivers/i2c_common.h
@@ -90,6 +90,11 @@ struct bus_i2c_node {
 #endif
 };
 
+struct i2c_dev_ops {
+    struct bus_dev_ops bus_ops;
+    int (*probe)(struct bus_i2c_dev *dev, uint16_t address, os_time_t timeout);
+};
+
 /**
  * Create bus I2C node
  *
@@ -113,6 +118,14 @@ bus_i2c_node_create(const char *name, struct bus_i2c_node *node,
                          bus_node_init_func, (void *)cfg);
 }
 
+static inline int
+bus_i2c_probe(struct bus_i2c_dev *dev, uint16_t address, int timeout)
+{
+    struct i2c_dev_ops *i2c_ops = (struct i2c_dev_ops *)dev->bdev.dops;
+
+    return i2c_ops->probe ? i2c_ops->probe(dev, address, timeout) : SYS_ENOTSUP;
+}
+
 #ifdef __cplusplus
 }
 #endif