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


The following commit(s) were added to refs/heads/master by this push:
     new 0dca280  hw/mcu/nrf52: Fix gpio handling in clear i2c bus
0dca280 is described below

commit 0dca2802f6c9903000f0356ad3f73084e3183b91
Author: Jerzy Kasenberg <jerzy.kasenb...@codecoup.pl>
AuthorDate: Thu Sep 26 15:16:23 2019 +0200

    hw/mcu/nrf52: Fix gpio handling in clear i2c bus
    
    nrf52840 can have two GPIO ports.
    Code was not handling correctly pins from port 1.
    Writes outside PIN_CNF array were done for port 1 pins.
    Now pin index is taken from HAL_GPIO_INDEX() macro as in all
    other places.
---
 hw/mcu/nordic/nrf52xxx/src/hal_i2c.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c 
b/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c
index e71c1d2..baa645d 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_i2c.c
@@ -216,19 +216,23 @@ hal_i2c_clear_bus(int scl_pin, int sda_pin)
 {
     int i;
     NRF_GPIO_Type *scl_port, *sda_port;
+    int scl_pin_ix;
+    int sda_pin_ix;
     /* Resolve which GPIO port these pins belong to */
     scl_port = HAL_GPIO_PORT(scl_pin);
     sda_port = HAL_GPIO_PORT(sda_pin);
+    scl_pin_ix = HAL_GPIO_INDEX(scl_pin);
+    sda_pin_ix = HAL_GPIO_INDEX(sda_pin);
 
     /* Input connected, standard-low disconnected-high, pull-ups */
-    scl_port->PIN_CNF[scl_pin] = NRF52_SCL_PIN_CONF;
-    sda_port->PIN_CNF[sda_pin] = NRF52_SDA_PIN_CONF;
+    scl_port->PIN_CNF[scl_pin_ix] = NRF52_SCL_PIN_CONF;
+    sda_port->PIN_CNF[sda_pin_ix] = NRF52_SDA_PIN_CONF;
 
     hal_gpio_write(scl_pin, 1);
     hal_gpio_write(sda_pin, 1);
 
-    scl_port->PIN_CNF[scl_pin] = NRF52_SCL_PIN_CONF_CLR;
-    sda_port->PIN_CNF[sda_pin] = NRF52_SDA_PIN_CONF_CLR;
+    scl_port->PIN_CNF[scl_pin_ix] = NRF52_SCL_PIN_CONF_CLR;
+    sda_port->PIN_CNF[sda_pin_ix] = NRF52_SDA_PIN_CONF_CLR;
 
     hal_i2c_delay_us(4);
 
@@ -258,8 +262,8 @@ hal_i2c_clear_bus(int scl_pin, int sda_pin)
 
 ret:
     /* Restore GPIO config */
-    scl_port->PIN_CNF[scl_pin] = NRF52_SCL_PIN_CONF;
-    sda_port->PIN_CNF[sda_pin] = NRF52_SDA_PIN_CONF;
+    scl_port->PIN_CNF[scl_pin_ix] = NRF52_SCL_PIN_CONF;
+    sda_port->PIN_CNF[sda_pin_ix] = NRF52_SDA_PIN_CONF;
 }
 
 int

Reply via email to