You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/01/17 13:28:47 UTC

[incubator-nuttx] branch pr119 updated: Nrf52 imrpovements (#119)

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

aguettouche pushed a commit to branch pr119
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/pr119 by this push:
     new 4a4b67d  Nrf52 imrpovements (#119)
4a4b67d is described below

commit 4a4b67d3b5817de791b4590192ce1399aeb63f23
Author: Mateusz Szafoni <ra...@users.noreply.github.com>
AuthorDate: Fri Jan 17 14:28:37 2020 +0100

    Nrf52 imrpovements (#119)
    
    * arch/arm/src/nrf52/hardware/nrf52_twi.h: fix typo
    
    * arch/arm/src/nrf52/nrf52_i2c.c: add interrupts support and some debug messages
    
    * boards/arm/nrf52/nrf52840-dk: add support for hts221 and lsm303agr; boards/arm/nrf52/nrf52840-dk: fix issues noted by nxstyle
---
 arch/arm/src/nrf52/hardware/nrf52_twi.h            |   2 +-
 arch/arm/src/nrf52/nrf52_i2c.c                     | 160 +++++++++++++++++---
 boards/arm/nrf52/nrf52840-dk/src/Makefile          |   8 +
 boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h     |  26 +++-
 boards/arm/nrf52/nrf52840-dk/src/nrf52_autoleds.c  |   4 +
 boards/arm/nrf52/nrf52840-dk/src/nrf52_boot.c      |   6 +-
 boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c   |  20 +++
 .../src/{nrf52840-dk.h => nrf52_hts221.c}          | 168 ++++++++++++---------
 .../src/{nrf52_lsm6dsl.c => nrf52_lsm303agr.c}     |  36 ++---
 boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c   |  14 +-
 boards/arm/nrf52/nrf52840-dk/src/nrf52_spi.c       |   4 +-
 11 files changed, 323 insertions(+), 125 deletions(-)

diff --git a/arch/arm/src/nrf52/hardware/nrf52_twi.h b/arch/arm/src/nrf52/hardware/nrf52_twi.h
index 219ed20..fafa08a 100644
--- a/arch/arm/src/nrf52/hardware/nrf52_twi.h
+++ b/arch/arm/src/nrf52/hardware/nrf52_twi.h
@@ -169,7 +169,7 @@
 
 #define TWIM_FREQUENCY_100KBPS              (0x01980000) /* 100 kbps */
 #define TWIM_FREQUENCY_250KBPS              (0x04000000) /* 250 kbps */
-#define TWIM_FREQUENCY_400KBPS              (0x64000000) /* 400 kbps */
+#define TWIM_FREQUENCY_400KBPS              (0x06400000) /* 400 kbps */
 
 /* RXDMAXCNT Register */
 
diff --git a/arch/arm/src/nrf52/nrf52_i2c.c b/arch/arm/src/nrf52/nrf52_i2c.c
index dd64971..d5291f3 100644
--- a/arch/arm/src/nrf52/nrf52_i2c.c
+++ b/arch/arm/src/nrf52/nrf52_i2c.c
@@ -59,9 +59,9 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#ifndef CONFIG_I2C_POLLED
-#  error I2C irq not supported yet
-#endif
+/* I2C errors not functional yet */
+
+#undef CONFIG_NRF52_I2C_ERRORS
 
 /****************************************************************************
  * Private Types
@@ -76,6 +76,7 @@ struct nrf52_i2c_priv_s
   uint32_t                scl_pin;  /* SCL pin configuration */
   uint32_t                sda_pin;  /* SDA pin configuration */
   int                     refs;     /* Reference count */
+  int                     status;   /* I2C transfer status */
 #ifndef CONFIG_I2C_POLLED
   uint32_t                irq;      /* TWI interrupt */
 #endif
@@ -231,6 +232,12 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
   priv->msgv = msgs;
   priv->msgc = count;
 
+  /* Reset I2C transfer status */
+
+  priv->status = OK;
+
+  i2cinfo("I2C TRANSFER count=%d\n", count);
+
   /* Do we need change I2C bus freqency ? */
 
   if (priv->msgv->frequency != priv->freq)
@@ -284,6 +291,9 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
       priv->flags = priv->msgv->flags;
       priv->addr  = priv->msgv->addr;
 
+      i2cinfo("ptr=%p dcnt=%d flags=%d addr=%d\n",
+              priv->ptr, priv->dcnt, priv->flags, priv->addr);
+
       /* Write TWI address */
 
       regval = priv->addr;
@@ -314,21 +324,13 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
           /* Clear event */
 
           nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_LASTTX_OFFSET, 0);
-#endif
-
-          /* TWIM stop */
-
-          nrf52_i2c_putreg(priv, NRF52_TWIM_TASKS_STOP_OFFSET, 1);
-
-          /* Wait for stop event */
+#else
+          nxsem_wait(&priv->sem_isr);
 
-#ifdef CONFIG_I2C_POLLED
-          while (nrf52_i2c_getreg(priv,
-                                  NRF52_TWIM_EVENTS_STOPPED_OFFSET) != 1);
-
-          /* Clear event */
-
-          nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_STOPPED_OFFSET, 0);
+          if (priv->status < 0)
+            {
+              goto errout;
+            }
 #endif
         }
       else
@@ -352,16 +354,17 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
 #ifdef CONFIG_I2C_POLLED
           while (nrf52_i2c_getreg(priv,
                                   NRF52_TWIM_EVENTS_LASTRX_OFFSET) != 1);
-#endif
-          /* Stop TWIM */
 
-          nrf52_i2c_putreg(priv, NRF52_TWIM_TASKS_STOP_OFFSET, 1);
+          /* Clear event */
 
-          /* Wait for stop event */
+          nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_LASTRX_OFFSET, 0);
+#else
+          nxsem_wait(&priv->sem_isr);
 
-#ifdef CONFIG_I2C_POLLED
-          while (nrf52_i2c_getreg(priv,
-                                  NRF52_TWIM_EVENTS_STOPPED_OFFSET) != 1);
+          if (priv->status < 0)
+            {
+              goto errout;
+            }
 #endif
         }
 
@@ -372,6 +375,28 @@ static int nrf52_i2c_transfer(FAR struct i2c_master_s *dev,
     }
   while (priv->msgc > 0);
 
+  /* TWIM stop */
+
+  nrf52_i2c_putreg(priv, NRF52_TWIM_TASKS_STOP_OFFSET, 1);
+
+  /* Wait for stop event */
+
+#ifdef CONFIG_I2C_POLLED
+  while (nrf52_i2c_getreg(priv,
+                          NRF52_TWIM_EVENTS_STOPPED_OFFSET) != 1);
+
+  /* Clear event */
+
+  nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_STOPPED_OFFSET, 0);
+#else
+  nxsem_wait(&priv->sem_isr);
+
+  if (priv->status < 0)
+    {
+      goto errout;
+    }
+#endif
+
 errout:
     return ret;
 }
@@ -408,7 +433,80 @@ static int nrf52_i2c_reset(FAR struct i2c_master_s *dev)
 #ifndef CONFIG_I2C_POLLED
 static int nrf52_i2c_isr(int irq, void *context, FAR void *arg)
 {
-#error not implemented
+  FAR struct nrf52_i2c_priv_s *priv = (FAR struct nrf52_i2c_priv_s *)arg;
+
+  /* Reset I2C status */
+
+  priv->status = OK;
+
+  if ((priv->flags & I2C_M_READ) == 0)
+    {
+      if (nrf52_i2c_getreg(priv, NRF52_TWIM_EVENTS_LASTTX_OFFSET) == 1)
+        {
+          i2cinfo("I2C LASTTX\n");
+
+          /* TX done */
+
+          nxsem_post(&priv->sem_isr);
+
+          /* Clear event */
+
+          nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_LASTTX_OFFSET, 0);
+
+          return OK;
+        }
+    }
+  else
+    {
+      if (nrf52_i2c_getreg(priv, NRF52_TWIM_EVENTS_LASTRX_OFFSET) == 1)
+        {
+          i2cinfo("I2C LASTRX\n");
+
+          /* RX done */
+
+          nxsem_post(&priv->sem_isr);
+
+          /* Clear event */
+
+          nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_LASTRX_OFFSET, 0);
+
+          return OK;
+        }
+    }
+
+  if (nrf52_i2c_getreg(priv, NRF52_TWIM_EVENTS_STOPPED_OFFSET) == 1)
+    {
+      i2cinfo("I2C STOPPED\n");
+
+      /* STOPPED event */
+
+      nxsem_post(&priv->sem_isr);
+
+      /* Clear event */
+
+      nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_STOPPED_OFFSET, 0);
+    }
+
+#ifdef CONFIG_NRF52_I2C_ERRORS
+  if (nrf52_i2c_getreg(priv, NRF52_TWIM_EVENTS_ERROR_OFFSET) == 1)
+    {
+      i2cerr("I2C ERROR\n");
+
+      /* Set ERROR status */
+
+      priv->status = ERROR;
+
+      /* ERROR event */
+
+      nxsem_post(&priv->sem_isr);
+
+      /* Clear event */
+
+      nrf52_i2c_putreg(priv, NRF52_TWIM_EVENTS_ERROR_OFFSET, 0);
+    }
+#endif
+
+  return OK;
 }
 #endif
 
@@ -454,6 +552,16 @@ static int nrf52_i2c_init(FAR struct nrf52_i2c_priv_s *priv)
   nrf52_i2c_putreg(priv, NRF52_TWIS_ENABLE_OFFSET, TWIM_ENABLE_EN);
 
 #ifndef CONFIG_I2C_POLLED
+  /* Enable I2C interrupts */
+
+#ifdef CONFIG_NRF52_I2C_ERRORS
+  regval = (TWIM_INT_LASTRX | TWIM_INT_LASTTX | TWIM_INT_STOPPED |
+            TWIM_INT_ERROR);
+#else
+  regval = (TWIM_INT_LASTRX | TWIM_INT_LASTTX | TWIM_INT_STOPPED);
+#endif
+  nrf52_i2c_putreg(priv, NRF52_TWIM_INTEN_OFFSET, regval);
+
   /* Attach error and event interrupts to the ISRs */
 
   irq_attach(priv->irq, nrf52_i2c_isr, priv);
@@ -560,6 +668,8 @@ FAR struct i2c_master_s *nrf52_i2cbus_initialize(int port)
   FAR struct nrf52_i2c_priv_s *priv = NULL;
   irqstate_t flags;
 
+  i2cinfo("I2C INITIALIZE port=%d\n", port);
+
   /* Get interface */
 
   switch (port)
diff --git a/boards/arm/nrf52/nrf52840-dk/src/Makefile b/boards/arm/nrf52/nrf52840-dk/src/Makefile
index 53dd1d7..c2e8905 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/Makefile
+++ b/boards/arm/nrf52/nrf52840-dk/src/Makefile
@@ -60,6 +60,14 @@ ifeq ($(CONFIG_SENSORS_LSM6DSL),y)
 CSRCS += nrf52_lsm6dsl.c
 endif
 
+ifeq ($(CONFIG_SENSORS_LSM303AGR),y)
+CSRCS += nrf52_lsm303agr.c
+endif
+
+ifeq ($(CONFIG_SENSORS_HTS221),y)
+CSRCS += nrf52_hts221.c
+endif
+
 ifeq ($(CONFIG_LPWAN_SX127X),y)
 CSRCS += nrf52_sx127x.c
 endif
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h b/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h
index c209e1b..7db93cb 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h
@@ -128,11 +128,35 @@ void nrf52_spidev_initialize(void);
  *
  ****************************************************************************/
 
-#ifdef CONFIG_SENSORS_LSM303AGR
+#ifdef CONFIG_SENSORS_LSM6DSL
 int nrf52_lsm6dsl_initialize(char *devpath);
 #endif
 
 /*****************************************************************************
+ * Name: nrf52_lsm303agr_initialize
+ *
+ * Description:
+ *   Initialize I2C-based LSM303AGR.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SENSORS_LSM303AGR
+int nrf52_lsm303agr_initialize(char *devpath);
+#endif
+
+/*****************************************************************************
+ * Name: nrf52_hts221_initialize
+ *
+ * Description:
+ *   Initialize I2C-based HTS221.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SENSORS_HTS221
+int nrf52_hts221_initialize(char *devpath);
+#endif
+
+/*****************************************************************************
  * Name: nrf52_lpwaninitialize
  *
  * Description:
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_autoleds.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_autoleds.c
index 41420f6..b2966fb 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_autoleds.c
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_autoleds.c
@@ -54,6 +54,10 @@
 
 #ifdef CONFIG_ARCH_LEDS
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
 #define LED_ON 0
 #define LED_OFF 1
 
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_boot.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_boot.c
index 1e8bad1..df0d51c 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_boot.c
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_boot.c
@@ -85,9 +85,9 @@ void nrf52_board_initialize(void)
  * Description:
  *   If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional
  *   initialization call will be performed in the boot-up sequence to a
- *   function called board_late_initialize().  board_late_initialize() will be
- *   called immediately after up_initialize() is called and just before the
- *   initial application is started.  This additional initialization phase
+ *   function called board_late_initialize().  board_late_initialize() will
+ *   be called immediately after up_initialize() is called and just before
+ *   the initial application is started. This additional initialization phase
  *   may be used, for example, to initialize board-specific device drivers.
  *
  ****************************************************************************/
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c
index 732efa2..50ca453 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_bringup.c
@@ -144,6 +144,26 @@ int nrf52_bringup(void)
     }
 #endif  /* CONFIG_SENSORS_LSM6DSL */
 
+#ifdef CONFIG_SENSORS_LSM303AGR
+  ret = nrf52_lsm303agr_initialize("/dev/lsm303agr0");
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "ERROR: Failed to initialize LSM303AGR driver: %d\n",
+             ret);
+    }
+#endif  /* CONFIG_SENSORS_LSM303AGR */
+
+#ifdef CONFIG_SENSORS_HTS221
+  ret = nrf52_hts221_initialize("/dev/hts2210");
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "ERROR: Failed to initialize HTS221 driver: %d\n",
+             ret);
+    }
+#endif  /* CONFIG_SENSORS_HTS221 */
+
 #ifdef CONFIG_LPWAN_SX127X
   ret = nrf52_lpwaninitialize();
   if (ret < 0)
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h b/boards/arm/nrf52/nrf52840-dk/src/nrf52_hts221.c
similarity index 52%
copy from boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h
copy to boards/arm/nrf52/nrf52840-dk/src/nrf52_hts221.c
index c209e1b..0dc8d91 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_hts221.c
@@ -1,7 +1,7 @@
 /****************************************************************************
- * boards/arm/nrf52/nrf52840-dk/src/nrf52840-dk.h
+ * boards/arm/nrf52/nrf52840-dk/src/nrf52_hts221.c
  *
- *   Copyright (C) 2019 Gregory Nutt. All rights reserved.
+ *   Copyright (C) 2020 Greg Nutt. All rights reserved.
  *   Author: Mateusz Szafoni <ra...@railab.me>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -30,118 +30,146 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
- *
  ****************************************************************************/
 
-#ifndef __BOARDS_ARM_NRF52_NRF52840_DK_SRC_NRF52840_DK_H
-#define __BOARDS_ARM_NRF52_NRF52840_DK_SRC_NRF52840_DK_H
-
 /****************************************************************************
  * Included Files
  ****************************************************************************/
 
 #include <nuttx/config.h>
-#include <nuttx/compiler.h>
+#include <nuttx/arch.h>
+
+#include <errno.h>
+#include <debug.h>
 
-#include "nrf52_gpio.h"
+#include <nuttx/board.h>
+#include "nrf52_i2c.h"
+#include "nrf52840-dk.h"
+#include <nuttx/sensors/hts221.h>
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* LED definitions **********************************************************/
-
-/* Definitions to configure LED GPIO as outputs */
+#ifndef CONFIG_NRF52_I2C0_MASTER
+#  error "HTS221 driver requires CONFIG_NRF52_I2C0_MASTER to be enabled"
+#endif
 
-#define GPIO_LED1  (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(13))
-#define GPIO_LED2  (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(14))
-#define GPIO_LED3  (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(15))
-#define GPIO_LED4  (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN(16))
+/* HTS221 I2C address */
 
-/* Button definitions *******************************************************/
+#define HTS221HUM_ADDR (0xbe >> 1) /* 7-bit */
 
-/* Board supports four buttons. */
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
 
-#define GPIO_BUTTON1 (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN(11))
-#define GPIO_BUTTON2 (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN(12))
-#define GPIO_BUTTON3 (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN(24))
-#define GPIO_BUTTON4 (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN(25))
+static int nrf52_hts221_irq_attach(FAR struct hts221_config_s *state,
+                                   xcpt_t isr, FAR void *arg);
+static void nrf52_hts221_irq_enable(FAR const struct hts221_config_s *state,
+                                   bool enable);
+static void nrf52_hts221_irq_clear(FAR const struct hts221_config_s *state);
+static int nrf52_hts221_set_power(FAR const struct hts221_config_s *state,
+                                  bool on);
 
-/* Dragino LORA shield (v1.4) - RF98 module (based on SX127X)
- * RESET - P1.11 (D9)
- * CS    - P1.12 (D10)
- * DIO0  - P1.03 (D2)
- */
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
 
-#define GPIO_SX127X_RESET (GPIO_PORT1 | GPIO_PIN(11))
-#define GPIO_SX127X_CS    (GPIO_OUTPUT | GPIO_PORT1 | GPIO_PIN(12))
-#define GPIO_SX127X_DIO0  (GPIO_INPUT  | GPIO_PORT1 | GPIO_PIN(3))
+static hts221_config_t g_hts221_config =
+{
+  .irq_attach = nrf52_hts221_irq_attach,
+  .irq_enable = nrf52_hts221_irq_enable,
+  .irq_clear  = nrf52_hts221_irq_clear,
+  .set_power  = nrf52_hts221_set_power
+};
 
 /****************************************************************************
- * Public Types
+ * Private Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Public data
+ * Name: nrf52_hts221_irq_attach
  ****************************************************************************/
 
-#ifndef __ASSEMBLY__
+static int nrf52_hts221_irq_attach(FAR struct hts221_config_s *state,
+                                   xcpt_t isr, FAR void *arg)
+{
+  sinfo("Attach HTS221 IRQ\n");
+
+  /* TODO: IRQ on rising edge */
+
+  /* nrf52_gpiosetevent(GPIO_HTS221_IRQ, true, false, false, isr, arg); */
+
+  return OK;
+}
 
 /****************************************************************************
- * Public Functions
+ * Name: nrf52_hts221_irq_enable
  ****************************************************************************/
 
+static void nrf52_hts221_irq_enable(FAR const struct hts221_config_s *state,
+                                   bool enable)
+{
+  return;
+}
+
 /****************************************************************************
- * Name: nrf52_bringup
- *
- * Description:
- *   Perform architecture-specific initialization
- *
- *   CONFIG_BOARD_LATE_INITIALIZE=y :
- *     Called from board_late_initialize().
- *
- *   CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_LIB_BOARDCTL=y :
- *     Called from the NSH library
- *
+ * Name: nrf52_hts221_irq_clear
  ****************************************************************************/
 
-int nrf52_bringup(void);
+static void nrf52_hts221_irq_clear(FAR const struct hts221_config_s *state)
+{
+  return;
+}
 
 /****************************************************************************
- * Name: nrf52_spidev_initialize
- *
- * Description:
- *   Called to configure SPI chip select GPIO pins for the
- *   nrf52840-dk board.
- *
+ * Name: nrf52_hts221_set_power
  ****************************************************************************/
 
-#ifdef CONFIG_NRF52_SPI_MASTER
-void nrf52_spidev_initialize(void);
-#endif
+static int nrf52_hts221_set_power(FAR const struct hts221_config_s *state,
+                                  bool on)
+{
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
 
-/*****************************************************************************
- * Name: nrf52_lsm6dsl_initialize
+/****************************************************************************
+ * Name: nrf52_hts221_initialize
  *
  * Description:
- *   Initialize I2C-based LSM6DSL.
+ *   Initialize I2C-based HTS221.
  *
  ****************************************************************************/
 
-#ifdef CONFIG_SENSORS_LSM303AGR
-int nrf52_lsm6dsl_initialize(char *devpath);
-#endif
+int nrf52_hts221_initialize(char *devpath)
+{
+  FAR struct i2c_master_s *i2c;
+  int ret = OK;
 
-/*****************************************************************************
- * Name: nrf52_lpwaninitialize
- *
- * Description:
- *   Initialize SX127X LPWAN interaface.
- ****************************************************************************/
+  sninfo("Initializing HTS221!\n");
+
+#ifdef CONFIG_NRF52_I2C0_MASTER
+  i2c = nrf52_i2cbus_initialize(0);
+  if (i2c == NULL)
+    {
+      return -ENODEV;
+    }
+
+  sninfo("INFO: Initializing HTS221 hum-temp sensor over I2C%d\n", ret);
+
+  ret = hts221_register(devpath, i2c, HTS221HUM_ADDR, &g_hts221_config);
+  if (ret < 0)
+    {
+      snerr("ERROR: Failed to initialize HTS221 hum-temp driver %s\n",
+            devpath);
+      return -ENODEV;
+    }
 
-#ifdef CONFIG_LPWAN_SX127X
-int nrf52_lpwaninitialize(void);
+  sninfo("INFO: HTS221 sensor has been initialized successfully\n");
 #endif
 
-#endif /* __ASSEMBLY__ */
-#endif /* __BOARDS_ARM_NRF52_NRF52840_DK_SRC_NRF52840_DK_H */
+  return ret;
+}
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm303agr.c
similarity index 78%
copy from boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c
copy to boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm303agr.c
index 7185662..3b657be 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm303agr.c
@@ -1,7 +1,7 @@
-/*****************************************************************************
- * boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c
+/****************************************************************************
+ * boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm303agr.c
  *
- *   Copyright (C) 2019 Greg Nutt. All rights reserved.
+ *   Copyright (C) 2020 Greg Nutt. All rights reserved.
  *   Author: Mateusz Szafoni <ra...@railab.me>
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  ****************************************************************************/
 
-/*****************************************************************************
+/****************************************************************************
  * Included Files
  ****************************************************************************/
 
@@ -45,33 +45,34 @@
 #include <nuttx/board.h>
 #include "nrf52_i2c.h"
 #include "nrf52840-dk.h"
-#include <nuttx/sensors/lsm6dsl.h>
+#include <nuttx/sensors/lsm303agr.h>
 
-/*****************************************************************************
+/****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
 #ifndef CONFIG_NRF52_I2C0_MASTER
-#  error "LSM6DSL driver requires CONFIG_NRF52_I2C0_MASTER to be enabled"
+#  error "LSM303AGR driver requires CONFIG_NRF52_I2C0_MASTER to be enabled"
 #endif
 
-/*****************************************************************************
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
-/*****************************************************************************
- * Name: nrf52_lsm6dsl_initialize
+/****************************************************************************
+ * Name: nrf52_lsm303agr_initialize
  *
  * Description:
- *   Initialize I2C-based LSM6DSL.
+ *   Initialize I2C-based LSM303AGR.
+ *
  ****************************************************************************/
 
-int nrf52_lsm6dsl_initialize(char *devpath)
+int nrf52_lsm303agr_initialize(char *devpath)
 {
   FAR struct i2c_master_s *i2c;
   int ret = OK;
 
-  sninfo("Initializing LMS6DSL!\n");
+  sninfo("Initializing LSM303AGR!\n");
 
 #ifdef CONFIG_NRF52_I2C0_MASTER
   i2c = nrf52_i2cbus_initialize(0);
@@ -80,17 +81,18 @@ int nrf52_lsm6dsl_initialize(char *devpath)
       return -ENODEV;
     }
 
-  sninfo("INFO: Initializing LMS6DSL accelero-gyro sensor over I2C%d\n", ret);
+  sninfo("INFO: Initializing LSM303AGR accelero-magnet sensor over I2C%d\n",
+         ret);
 
-  ret = lsm6dsl_sensor_register(devpath, i2c, LSM6DSLACCEL_ADDR1);
+  ret = lsm303agr_sensor_register(devpath, i2c, LSM303AGRMAGNETO_ADDR);
   if (ret < 0)
     {
-      snerr("ERROR: Failed to initialize LMS6DSL accelero-gyro driver %s\n",
+      snerr("ERROR: Failed to initialize LSM303AGR acc-gyro driver %s\n",
             devpath);
       return -ENODEV;
     }
 
-  sninfo("INFO: LMS6DSL sensor has been initialized successfully\n");
+  sninfo("INFO: LSM303AGR sensor has been initialized successfully\n");
 #endif
 
   return ret;
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c
index 7185662..b1a8249 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c
@@ -1,4 +1,4 @@
-/*****************************************************************************
+/****************************************************************************
  * boards/arm/nrf52/nrf52840-dk/src/nrf52_lsm6dsl.c
  *
  *   Copyright (C) 2019 Greg Nutt. All rights reserved.
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  ****************************************************************************/
 
-/*****************************************************************************
+/****************************************************************************
  * Included Files
  ****************************************************************************/
 
@@ -47,7 +47,7 @@
 #include "nrf52840-dk.h"
 #include <nuttx/sensors/lsm6dsl.h>
 
-/*****************************************************************************
+/****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
@@ -55,15 +55,16 @@
 #  error "LSM6DSL driver requires CONFIG_NRF52_I2C0_MASTER to be enabled"
 #endif
 
-/*****************************************************************************
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
-/*****************************************************************************
+/****************************************************************************
  * Name: nrf52_lsm6dsl_initialize
  *
  * Description:
  *   Initialize I2C-based LSM6DSL.
+ *
  ****************************************************************************/
 
 int nrf52_lsm6dsl_initialize(char *devpath)
@@ -80,7 +81,8 @@ int nrf52_lsm6dsl_initialize(char *devpath)
       return -ENODEV;
     }
 
-  sninfo("INFO: Initializing LMS6DSL accelero-gyro sensor over I2C%d\n", ret);
+  sninfo("INFO: Initializing LMS6DSL accelero-gyro sensor over I2C%d\n",
+         ret);
 
   ret = lsm6dsl_sensor_register(devpath, i2c, LSM6DSLACCEL_ADDR1);
   if (ret < 0)
diff --git a/boards/arm/nrf52/nrf52840-dk/src/nrf52_spi.c b/boards/arm/nrf52/nrf52840-dk/src/nrf52_spi.c
index 2f66c20..94377ec 100644
--- a/boards/arm/nrf52/nrf52840-dk/src/nrf52_spi.c
+++ b/boards/arm/nrf52/nrf52840-dk/src/nrf52_spi.c
@@ -99,8 +99,8 @@ void nrf52_spidev_initialize(void)
  *      functions in your board-specific logic. These functions will perform
  *      chip selection and status operations using GPIOs in the way your
  *      board is configured.
- *   3. Add a calls to nrf52_spibus_initialize() in your low level application
- *      initialization logic
+ *   3. Add a calls to nrf52_spibus_initialize() in your low level
+ *      application initialization logic
  *   4. The handle returned by nrf52_spibus_initialize() may then be used to
  *      bind the SPI driver to higher level logic (e.g., calling
  *      mmcsd_spislotinitialize(), for example, will bind the SPI driver to