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:46 UTC
[mynewt-core] 02/10: hw/bus/i2c: Add probe to i2c_hal driver
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 2628c6bc588b319235efd4135fea02d328dc2a56
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 30 15:31:14 2021 +0200
hw/bus/i2c: Add probe to i2c_hal driver
This adds probe function to generic i2c_hal driver.
---
hw/bus/drivers/i2c_hal/src/i2c_hal.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/hw/bus/drivers/i2c_hal/src/i2c_hal.c b/hw/bus/drivers/i2c_hal/src/i2c_hal.c
index 3e2f675..2c6ed68 100644
--- a/hw/bus/drivers/i2c_hal/src/i2c_hal.c
+++ b/hw/bus/drivers/i2c_hal/src/i2c_hal.c
@@ -178,13 +178,30 @@ static int bus_i2c_disable(struct bus_dev *bdev)
return 0;
}
-static const struct bus_dev_ops bus_i2c_hal_ops = {
- .init_node = bus_i2c_init_node,
- .enable = bus_i2c_enable,
- .configure = bus_i2c_configure,
- .read = bus_i2c_read,
- .write = bus_i2c_write,
- .disable = bus_i2c_disable,
+static int
+bus_i2c_hal_probe(struct bus_i2c_dev *dev, uint16_t address, os_time_t timeout)
+{
+ int rc;
+
+ rc = os_error_to_sys(os_mutex_pend(&dev->bdev.lock, timeout));
+
+ if (rc == 0) {
+ rc = bus_i2c_translate_hal_error(hal_i2c_master_probe(dev->cfg.i2c_num, address, timeout));
+ os_mutex_release(&dev->bdev.lock);
+ }
+ return rc;
+}
+
+static const struct i2c_dev_ops bus_i2c_hal_ops = {
+ .bus_ops = {
+ .init_node = bus_i2c_init_node,
+ .enable = bus_i2c_enable,
+ .configure = bus_i2c_configure,
+ .read = bus_i2c_read,
+ .write = bus_i2c_write,
+ .disable = bus_i2c_disable,
+ },
+ .probe = bus_i2c_hal_probe,
};
int