You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2018/11/23 16:16:37 UTC

[mynewt-core] 05/26: hw/mcu/nordic: Add I2C bus driver support to nrf52xxx

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

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

commit cc6d3f7bb0d8df60372c342d9426c1f1b40fb91f
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Nov 5 17:28:22 2018 +0100

    hw/mcu/nordic: Add I2C bus driver support to nrf52xxx
---
 hw/mcu/nordic/nrf52xxx/pkg.yml            |  8 ++++++++
 hw/mcu/nordic/nrf52xxx/src/nrf52_periph.c | 32 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/hw/mcu/nordic/nrf52xxx/pkg.yml b/hw/mcu/nordic/nrf52xxx/pkg.yml
index 8ba4e48..7b11033 100644
--- a/hw/mcu/nordic/nrf52xxx/pkg.yml
+++ b/hw/mcu/nordic/nrf52xxx/pkg.yml
@@ -67,3 +67,11 @@ pkg.deps.PWM_2:
 
 pkg.deps.PWM_3:
     - "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
+
+pkg.deps.I2C_0:
+    - "@apache-mynewt-core/hw/bus"
+    - "@apache-mynewt-core/hw/bus/i2c"
+
+pkg.deps.I2C_1:
+    - "@apache-mynewt-core/hw/bus"
+    - "@apache-mynewt-core/hw/bus/i2c"
diff --git a/hw/mcu/nordic/nrf52xxx/src/nrf52_periph.c b/hw/mcu/nordic/nrf52xxx/src/nrf52_periph.c
index f951aaa..56887b4 100644
--- a/hw/mcu/nordic/nrf52xxx/src/nrf52_periph.c
+++ b/hw/mcu/nordic/nrf52xxx/src/nrf52_periph.c
@@ -24,6 +24,10 @@
 #include "hal/hal_i2c.h"
 #include "hal/hal_spi.h"
 #include "bsp/bsp.h"
+#if MYNEWT_VAL(I2C_0) || MYNEWT_VAL(I2C_1)
+#include "bus/bus.h"
+#include "bus/i2c.h"
+#endif
 #include "nrfx.h"
 #if MYNEWT_VAL(ADC_0)
 #include "adc/adc.h"
@@ -86,19 +90,37 @@ static const struct nrf52_uart_cfg os_bsp_uart1_cfg = {
 #endif
 
 #if MYNEWT_VAL(I2C_0)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static const struct bus_i2c_dev_cfg i2c0_cfg = {
+    .i2c_num = 0,
+    .pin_sda = MYNEWT_VAL(I2C_0_PIN_SDA),
+    .pin_scl = MYNEWT_VAL(I2C_0_PIN_SCL),
+};
+static struct bus_i2c_dev i2c0_bus;
+#else
 static const struct nrf52_hal_i2c_cfg hal_i2c0_cfg = {
     .scl_pin = MYNEWT_VAL(I2C_0_PIN_SCL),
     .sda_pin = MYNEWT_VAL(I2C_0_PIN_SDA),
     .i2c_frequency = MYNEWT_VAL(I2C_0_FREQ_KHZ),
 };
 #endif
+#endif
 #if MYNEWT_VAL(I2C_1)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+static const struct bus_i2c_dev_cfg i2c1_cfg = {
+    .i2c_num = 1,
+    .pin_sda = MYNEWT_VAL(I2C_1_PIN_SDA),
+    .pin_scl = MYNEWT_VAL(I2C_1_PIN_SCL),
+};
+static struct bus_i2c_dev i2c1_bus;
+#else
 static const struct nrf52_hal_i2c_cfg hal_i2c1_cfg = {
     .scl_pin = MYNEWT_VAL(I2C_1_PIN_SCL),
     .sda_pin = MYNEWT_VAL(I2C_1_PIN_SDA),
     .i2c_frequency = MYNEWT_VAL(I2C_1_FREQ_KHZ),
 };
 #endif
+#endif
 
 #if MYNEWT_VAL(SPI_0_MASTER)
 static const struct nrf52_hal_spi_cfg os_bsp_spi0m_cfg = {
@@ -279,13 +301,23 @@ nrf52_periph_create_i2c(void)
     (void)rc;
 
 #if MYNEWT_VAL(I2C_0)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    rc = bus_i2c_dev_create("i2c0", &i2c0_bus, (struct bus_i2c_dev_cfg *)&i2c0_cfg);
+    assert(rc == 0);
+#else
     rc = hal_i2c_init(0, (void *)&hal_i2c0_cfg);
     assert(rc == 0);
 #endif
+#endif
 #if MYNEWT_VAL(I2C_1)
+#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
+    rc = bus_i2c_dev_create("i2c1", &i2c1_bus, (struct bus_i2c_dev_cfg *)&i2c1_cfg);
+    assert(rc == 0);
+#else
     rc = hal_i2c_init(1, (void *)&hal_i2c1_cfg);
     assert(rc == 0);
 #endif
+#endif
 }
 
 static void