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:52 UTC

[mynewt-core] 08/10: bus/i2c_da1469x: Split configure function

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 b46da65c7e6ec2ffd2f7307c2c6bb49c5491a08c
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 30 16:15:05 2021 +0200

    bus/i2c_da1469x: Split configure function
    
    configure function needed by i2c interface sets up controller
    to be used with specific node (device with address and speed).
    
    This introduces local configuration functions that configures
    controller without node.
    It will be useful for configuration of controller to scan for
    any devices with specific address.
    Without this probing i2c bus would require creation of dummy
    nodes.
---
 hw/bus/drivers/i2c_da1469x/src/i2c_da1469x.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/hw/bus/drivers/i2c_da1469x/src/i2c_da1469x.c b/hw/bus/drivers/i2c_da1469x/src/i2c_da1469x.c
index c20b29f..b361abb 100644
--- a/hw/bus/drivers/i2c_da1469x/src/i2c_da1469x.c
+++ b/hw/bus/drivers/i2c_da1469x/src/i2c_da1469x.c
@@ -413,17 +413,13 @@ i2c_da1469x_enable(struct bus_dev *bdev)
 }
 
 static int
-i2c_da1469x_configure(struct bus_dev *bdev, struct bus_node *bnode)
+i2c_da1469x_configure_controller(struct bus_i2c_dev *dev, uint8_t address, uint16_t freq)
 {
-    struct bus_i2c_dev *dev = (struct bus_i2c_dev *)bdev;
-    struct bus_i2c_node *node = (struct bus_i2c_node *)bnode;
-    struct bus_i2c_node *current_node = (struct bus_i2c_node *)bdev->configured_for;
     I2C_Type *i2c_regs;
     uint32_t speed;
     int rc = 0;
 
     BUS_DEBUG_VERIFY_DEV(dev);
-    BUS_DEBUG_VERIFY_NODE(node);
 
     i2c_regs = da1469x_i2c[dev->cfg.i2c_num].regs;
 
@@ -431,13 +427,9 @@ i2c_da1469x_configure(struct bus_dev *bdev, struct bus_node *bnode)
         i2c_regs->I2C_ENABLE_REG &= ~(1U << I2C_I2C_ENABLE_REG_I2C_EN_Pos);
     }
 
-    i2c_regs->I2C_TAR_REG = node->addr & I2C_I2C_TAR_REG_IC_TAR_Msk;
+    i2c_regs->I2C_TAR_REG = address & I2C_I2C_TAR_REG_IC_TAR_Msk;
 
-    if (current_node && (current_node->freq == node->freq)) {
-        goto end;
-    }
-
-    switch (node->freq) {
+    switch (freq) {
     case 100:
         speed = 1;
         break;
@@ -458,6 +450,18 @@ end:
 }
 
 static int
+i2c_da1469x_configure(struct bus_dev *bdev, struct bus_node *bnode)
+{
+    struct bus_i2c_dev *dev = (struct bus_i2c_dev *)bdev;
+    struct bus_i2c_node *node = (struct bus_i2c_node *)bnode;
+
+    BUS_DEBUG_VERIFY_DEV(dev);
+    BUS_DEBUG_VERIFY_NODE(node);
+
+    return i2c_da1469x_configure_controller(dev, node->addr, node->freq);
+}
+
+static int
 i2c_da1469x_translate_abort(uint32_t abort_code)
 {
     if (abort_code &