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

[mynewt-core] 06/10: bus/i2c_nrf5340: 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 b2f2ba04a609ec8884487a062881e05db88548bc
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Jun 30 15:49:26 2021 +0200

    bus/i2c_nrf5340: 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_nrf5340/src/i2c_nrf5340.c | 36 +++++++++++++++-------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c b/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c
index 22871e3..c183b59 100644
--- a/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c
+++ b/hw/bus/drivers/i2c_nrf5340/src/i2c_nrf5340.c
@@ -202,28 +202,14 @@ bus_i2c_nrf5340_enable(struct bus_dev *bdev)
 }
 
 static int
-bus_i2c_nrf5340_configure(struct bus_dev *bdev, struct bus_node *bnode)
+bus_i2c_nrf5340_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;
     NRF_TWIM_Type *nrf_twim;
-    int rc;
-
-    BUS_DEBUG_VERIFY_DEV(dev);
-    BUS_DEBUG_VERIFY_NODE(node);
+    int rc = 0;
 
     nrf_twim = twims[dev->cfg.i2c_num].nrf_twim;
 
-    nrf_twim->ADDRESS = node->addr;
-
-    if (current_node && (current_node->freq == node->freq)) {
-        return 0;
-    }
-
-    rc = 0;
-
-    switch (node->freq) {
+    switch (freq) {
     case 100:
         nrf_twim->FREQUENCY = TWIM_FREQUENCY_FREQUENCY_K100;
         break;
@@ -240,10 +226,26 @@ bus_i2c_nrf5340_configure(struct bus_dev *bdev, struct bus_node *bnode)
         rc = SYS_EIO;
     }
 
+    if (rc == 0) {
+        nrf_twim->ADDRESS = address;
+    }
+
     return rc;
 }
 
 static int
+bus_i2c_nrf5340_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 bus_i2c_nrf5340_configure_controller(dev, node->addr, node->freq);
+}
+
+static int
 bus_i2c_nrf5340_read(struct bus_dev *bdev, struct bus_node *bnode,
                      uint8_t *buf, uint16_t length, os_time_t timeout,
                      uint16_t flags)