You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2017/02/24 19:38:38 UTC

[43/50] incubator-mynewt-core git commit: SensorAPI: BNO055 Adding config to the sensor

SensorAPI: BNO055 Adding config to the sensor

- some cleanup as well


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e4d0f04a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e4d0f04a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e4d0f04a

Branch: refs/heads/develop
Commit: e4d0f04a2b19691ed5b5e34a09d1d5f5d044ba2c
Parents: 30b53c0
Author: Vipul Rahane <vi...@apache.org>
Authored: Tue Feb 21 18:22:45 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Tue Feb 21 18:22:45 2017 -0800

----------------------------------------------------------------------
 apps/slinky/src/main.c                          |   8 +
 hw/bsp/nrf52dk/src/hal_bsp.c                    |  49 ++++++
 .../sensors/bno055/include/bno055/bno055.h      | 165 +++++++++++++++----
 hw/drivers/sensors/bno055/src/bno055.c          | 155 ++++++++++-------
 hw/drivers/sensors/bno055/src/bno055_priv.h     |  94 -----------
 hw/drivers/sensors/bno055/src/bno055_shell.c    |  19 ++-
 hw/sensor/include/sensor/euler.h                |   4 +-
 hw/sensor/src/sensor_shell.c                    |  50 +++++-
 8 files changed, 350 insertions(+), 194 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 9eef0c0..1bbce7b 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -304,6 +304,14 @@ config_sensor(void)
         goto err;
     }
 
+    bcfg.bc_units = BNO055_ACC_UNIT_MS2   | BNO055_ANGRATE_UNIT_DPS |
+                  BNO055_EULER_UNIT_DEG | BNO055_TEMP_UNIT_DEGC   |
+                  BNO055_DO_FORMAT_ANDROID;
+
+    bcfg.bc_opr_mode = BNO055_OPR_MODE_ACCONLY;
+
+    bcfg.bc_pwr_mode = BNO055_PWR_MODE_NORMAL;
+
     rc = bno055_config((struct bno055 *) dev, &bcfg);
     if (rc) {
         os_dev_close(dev);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/hw/bsp/nrf52dk/src/hal_bsp.c
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/src/hal_bsp.c b/hw/bsp/nrf52dk/src/hal_bsp.c
index 40ce57b..a2909c3 100644
--- a/hw/bsp/nrf52dk/src/hal_bsp.c
+++ b/hw/bsp/nrf52dk/src/hal_bsp.c
@@ -42,6 +42,20 @@
 #endif
 #include "os/os_dev.h"
 #include "bsp.h"
+#include <lsm303dlhc/lsm303dlhc.h>
+#include <tsl2561/tsl2561.h>
+#include <bno055/bno055.h>
+
+#if MYNEWT_VAL(LSM303DLHC_PRESENT)
+static struct lsm303dlhc lsm303dlhc;
+#endif
+#if MYNEWT_VAL(TSL2561_PRESENT)
+static struct tsl2561 tsl2561;
+#endif
+#if MYNEWT_VAL(BNO055_PRESENT)
+static struct bno055 bno055;
+#endif
+
 
 #if MYNEWT_VAL(UART_0)
 static struct uart_dev os_bsp_uart0;
@@ -151,6 +165,23 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
     return cfg_pri;
 }
 
+#if MYNEWT_VAL(LSM303DLHC_PRESENT) || MYNEWT_VAL(BNO055_PRESENT)
+static int
+slinky_accel_init(struct os_dev *dev, void *arg)
+{
+    return (0);
+}
+#endif
+
+#if MYNEWT_VAL(TSL2561_PRESENT)
+static int
+slinky_light_init(struct os_dev *dev, void *arg)
+{
+    return (0);
+}
+#endif
+
+
 void
 hal_bsp_init(void)
 {
@@ -214,4 +245,22 @@ hal_bsp_init(void)
     assert(rc == 0);
 #endif
 
+#if MYNEWT_VAL(LSM303DLHC_PRESENT)
+    rc = os_dev_create((struct os_dev *) &lsm303dlhc, "accel0",
+            OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIMARY, slinky_accel_init, NULL);
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(BNO055_PRESENT)
+    rc = os_dev_create((struct os_dev *) &bno055, "accel1",
+            OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIMARY, slinky_accel_init, NULL);
+    assert(rc == 0);
+#endif
+
+#if MYNEWT_VAL(TSL2561_PRESENT)
+    rc = os_dev_create((struct os_dev *) &tsl2561, "light0",
+            OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIMARY, slinky_light_init, NULL);
+    assert(rc == 0);
+#endif
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/hw/drivers/sensors/bno055/include/bno055/bno055.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/include/bno055/bno055.h b/hw/drivers/sensors/bno055/include/bno055/bno055.h
index 8aade64..b8ceb02 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -28,8 +28,106 @@
 extern "C" {
 #endif
 
+/* Power modes */
+#define BNO055_PWR_MODE_NORMAL                                  0X00
+#define BNO055_PWR_MODE_LOWPOWER                                0X01
+#define BNO055_PWR_MODE_SUSPEND                                 0X02
+
+/* Operation Modes */
+#define BNO055_OPR_MODE_CONFIG                                  0X00
+#define BNO055_OPR_MODE_ACCONLY                                 0X01
+#define BNO055_OPR_MODE_MAGONLY                                 0X02
+#define BNO055_OPR_MODE_GYRONLY                                 0X03
+#define BNO055_OPR_MODE_ACCMAG                                  0X04
+#define BNO055_OPR_MODE_ACCGYRO                                 0X05
+#define BNO055_OPR_MODE_MAGGYRO                                 0X06
+#define BNO055_OPR_MODE_AMG                                     0X07
+#define BNO055_OPR_MODE_IMUPLUS                                 0X08
+#define BNO055_OPR_MODE_COMPASS                                 0X09
+#define BNO055_OPR_MODE_M4G                                     0X0A
+#define BNO055_OPR_MODE_NDOF_FMC_OFF                            0X0B
+#define BNO055_OPR_MODE_NDOF                                    0X0C
+
+#define BNO055_ACC_UNIT_MS2                                      0x0
+#define BNO055_ACC_UNIT_MG                                       0x1
+#define BNO055_ANGRATE_UNIT_DPS                             (0 << 1)
+#define BNO055_ANGRATE_UNIT_RPS                             (1 << 1)
+#define BNO055_EULER_UNIT_DEG                               (0 << 2)
+#define BNO055_EULER_UNIT_RAD                               (1 << 2)
+#define BNO055_TEMP_UNIT_DEGC                               (0 << 4)
+#define BNO055_TEMP_UNIT_DEGF                               (1 << 4)
+#define BNO055_DO_FORMAT_WINDOWS                            (0 << 7)
+#define BNO055_DO_FORMAT_ANDROID                            (1 << 7)
+
+/* Accelerometer config */
+#define BNO055_ACC_CFG_2G                                        0x0
+#define BNO055_ACC_CFG_4G                                        0x1
+#define BNO055_ACC_CFG_8G                                        0x2
+#define BNO055_ACC_CFG_16G                                       0x3
+
+#define BNO055_ACC_CFG_BW_7_81HZ                          (0x0 << 2)
+#define BNO055_ACC_CFG_BW_15_63HZ                         (0x1 << 2)
+#define BNO055_ACC_CFG_BW_31_25HZ                         (0x2 << 2)
+#define BNO055_ACC_CFG_BW_6_25HZ                          (0x3 << 2)
+#define BNO055_ACC_CFG_BW_125HZ                           (0x4 << 2)
+#define BNO055_ACC_CFG_BW_250HZ                           (0x5 << 2)
+#define BNO055_ACC_CFG_BW_500HZ                           (0x6 << 2)
+#define BNO055_ACC_CFG_BW_1000HZ                          (0x7 << 2)
+
+#define BNO055_ACC_CFG_OPR_MODE_NORMAL                    (0x0 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_SUSPEND                   (0x1 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_LOWPWR1                   (0x2 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_STD                       (0x3 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_LOWPWR2                   (0x4 << 5)
+#define BNO055_ACC_CFG_OPR_MODE_DSUSPEND                  (0x5 << 5)
+
+/* Gyroscope config */
+#define BNO055_GYR_CFG_RNG_2000DPS                               0x0
+#define BNO055_GYR_CFG_RNG_1000DPS                               0x1
+#define BNO055_GYR_CFG_RNG_500DPS                                0x2
+#define BNO055_GYR_CFG_RNG_250DPS                                0x3
+#define BNO055_GYR_CFG_RNG_125DPS                                0x4
+
+#define BNO055_GYR_CFG_BW_523HZ                           (0x0 << 3)
+#define BNO055_GYR_CFG_BW_230HZ                           (0x1 << 3)
+#define BNO055_GYR_CFG_BW_116HZ                           (0x2 << 3)
+#define BNO055_GYR_CFG_BW_47HZ                            (0x3 << 3)
+#define BNO055_GYR_CFG_BW_23HZ                            (0x4 << 3)
+#define BNO055_GYR_CFG_BW_12HZ                            (0x5 << 3)
+#define BNO055_GYR_CFG_BW_64HZ                            (0x6 << 3)
+#define BNO055_GYR_CFG_BW_32HZ                            (0x7 << 3)
+
+#define BNO055_GYR_CFG_OPR_MODE_NORMAL                    (0x0 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_FAST_PWR_UP               (0x1 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_DSUSPEND                  (0x2 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_SUSPEND                   (0x3 << 5)
+#define BNO055_GYR_CFG_OPR_MODE_ADV_PWR_SAVE              (0x4 << 5)
+
+/* Magnetometer config */
+#define BNO055_MAG_CFG_BW_2HZ                                    0x0
+#define BNO055_MAG_CFG_BW_6HZ                                    0x1
+#define BNO055_MAG_CFG_BW_8HZ                                    0x2
+#define BNO055_MAG_CFG_BW_10HZ                                   0x3
+#define BNO055_MAG_CFG_BW_15HZ                                   0x4
+#define BNO055_MAG_CFG_BW_20HZ                                   0x5
+#define BNO055_MAG_CFG_BW_25HZ                                   0x6
+#define BNO055_MAG_CFG_BW_30HZ                                   0x7
+
+#define BNO055_MAG_CFG_OPR_MODE_LOWPWR                    (0x0 << 3)
+#define BNO055_MAG_CFG_OPR_MODE_REG                       (0x1 << 3)
+#define BNO055_MAG_CFG_OPR_MODE_EREG                      (0x2 << 3)
+#define BNO055_MAG_CFG_OPR_MODE_HIGHACC                   (0x3 << 3)
+
+#define BNO055_MAG_CFG_PWR_MODE_NORMAL                    (0x0 << 5)
+#define BNO055_MAG_CFG_PWR_MODE_SLEEP                     (0x1 << 5)
+#define BNO055_MAG_CFG_PWR_MODE_SUSPEND                   (0x2 << 5)
+#define BNO055_MAG_CFG_PWR_MODE_FORCE_MODE                (0x3 << 5)
+
+
 struct bno055_cfg {
-    uint8_t bc_mode;
+    uint8_t bc_opr_mode;
+    uint8_t bc_pwr_mode;
+    uint8_t bc_units;
 };
 
 struct bno055 {
@@ -121,67 +219,70 @@ int
 bno055_get_rev_info(struct bno055_rev_info *ri);
 
 /**
- * Gets system status, test results and errors if any from the sensor
+ * Set power mode for the sensor
  *
- * @param ptr to system status
- * @param ptr to self test result
- * @param ptr to system error
+ * @return mode
  */
 int
-bno055_get_sys_status(uint8_t *system_status, uint8_t *self_test_result,
-                      uint8_t *system_error);
-
-int
-bno055_get_chip_id(uint8_t *id);
+bno055_set_pwr_mode(uint8_t mode);
 
 /**
- * Read current operational mode of the sensor
+ * Setting units for the bno055 sensor
  *
- * @return mode
+ * @param power mode for the sensor
+ * @return 0 on success, non-zero on failure
  */
-uint8_t
-bno055_get_opr_mode(void);
+int
+bno055_set_units(uint8_t val);
 
 /**
  * Read current power mode of the sensor
  *
- * @return mode
+ * @param ptr to mode variableto fill up
+ * @return 0 on success, non-zero on failure
  */
-uint8_t
-bno055_get_pwr_mode(void);
+int
+bno055_get_pwr_mode(uint8_t *mode);
 
 /**
- * Set power mode for the sensor
+ * Read current operational mode of the sensor
  *
- * @return mode
+ * @param ptr to mode variable to fill up
+ * @return 0 on success, non-zero on failure
  */
 int
-bno055_set_pwr_mode(uint8_t mode);
+bno055_get_opr_mode(uint8_t *mode);
 
 /**
- * Get power mode for the sensor
+ * Get units of the sensor
  *
- * @return mode
+ * @param ptr to the units variable
+ * @return 0 on success, non-zero on failure
  */
-uint8_t
-bno055_get_pwr_mode(void);
+int
+bno055_get_units(uint8_t *units);
 
 /**
- * Setting units for the bno055 sensor
+ * Gets system status, test results and errors if any from the sensor
  *
- * @param power mode for the sensor
- * @return 0 on success, non-zero on failure
+ * @param ptr to system status
+ * @param ptr to self test result
+ * @param ptr to system error
  */
+
 int
-bno055_set_units(uint8_t val);
+bno055_get_sys_status(uint8_t *system_status, uint8_t *self_test_result,
+                      uint8_t *system_error);
 
 /**
- * Read current power mode of the sensor
+ * Get chip ID from the sensor
  *
- * @return mode
+ * @param Pointer to the variable to fill up chip ID in
+ * @return 0 on success, non-zero on failure
  */
-uint8_t
-bno055_get_units(void);
+int
+bno055_get_chip_id(uint8_t *id);
+
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index 014473f..d1043f2 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -102,10 +102,6 @@ static const struct sensor_driver g_bno055_sensor_driver = {
     bno055_sensor_get_config
 };
 
-static uint8_t g_bno055_opr_mode;
-static uint8_t g_bno055_pwr_mode;
-static uint8_t g_bno055_units;
-
 /**
  * Writes a single byte to the specified register
  *
@@ -263,12 +259,12 @@ bno055_set_opr_mode(uint8_t mode)
 {
     int rc;
 
-    rc = bno055_write8(BNO055_OPR_MODE_ADDR, BNO055_OPERATION_MODE_CONFIG);
+    rc = bno055_write8(BNO055_OPR_MODE_ADDR, BNO055_OPR_MODE_CONFIG);
     if (rc) {
         goto err;
     }
 
-    os_time_delay(OS_TICKS_PER_SEC/1000 * 19);
+    os_time_delay((OS_TICKS_PER_SEC * 19)/1000 + 1);
 
     rc = bno055_write8(BNO055_OPR_MODE_ADDR, mode);
     if (rc) {
@@ -276,9 +272,7 @@ bno055_set_opr_mode(uint8_t mode)
     }
 
     /* Refer table 3-6 in the datasheet for the delay values */
-    os_time_delay(OS_TICKS_PER_SEC/1000 * 7);
-
-    g_bno055_opr_mode = mode;
+    os_time_delay((OS_TICKS_PER_SEC * 7)/1000 + 1);
 
     return 0;
 err:
@@ -301,7 +295,6 @@ bno055_set_pwr_mode(uint8_t mode)
         goto err;
     }
 
-    g_bno055_pwr_mode = mode;
     return 0;
 err:
     return rc;
@@ -310,12 +303,25 @@ err:
 /**
  * Read current power mode of the sensor
  *
- * @return mode
+ * @param ptr to mode variableto fill up
+ * @return 0 on success, non-zero on failure
  */
-uint8_t
-bno055_get_pwr_mode(void)
+int
+bno055_get_pwr_mode(uint8_t *mode)
 {
-    return g_bno055_pwr_mode;
+    int rc;
+    uint8_t val;
+
+    rc = bno055_read8(BNO055_PWR_MODE_ADDR, &val);
+    if (rc) {
+        goto err;
+    }
+
+    *mode = val;
+
+    return 0;
+err:
+    return rc;
 }
 
 /**
@@ -334,32 +340,57 @@ bno055_set_units(uint8_t val)
         goto err;
     }
 
-    g_bno055_units = val;
     return 0;
 err:
     return rc;
 }
 
 /**
- * Read current power mode of the sensor
+ * Get units of the sensor
  *
- * @return mode
+ * @param ptr to the units variable
+ * @return 0 on success, non-zero on failure
  */
-uint8_t
-bno055_get_units(void)
+int
+bno055_get_units(uint8_t *units)
 {
-    return g_bno055_units;
+    int rc;
+    uint8_t val;
+
+    rc = bno055_read8(BNO055_UNIT_SEL_ADDR, &val);
+    if (rc) {
+        goto err;
+    }
+
+    *units = val;
+
+    return 0;
+err:
+    return rc;
 }
 
 /**
  * Read current operational mode of the sensor
  *
- * @return mode
+ * @param ptr to mode variable to fill up
+ * @return 0 on success, non-zero on failure
  */
-uint8_t
-bno055_get_opr_mode(void)
+int
+bno055_get_opr_mode(uint8_t *mode)
 {
-    return g_bno055_opr_mode;
+    int rc;
+    uint8_t val;
+
+    rc = bno055_read8(BNO055_OPR_MODE_ADDR, &val);
+    if (rc) {
+        goto err;
+    }
+
+    *mode = val;
+
+    return 0;
+err:
+    return rc;
 }
 
 /**
@@ -403,9 +434,11 @@ bno055_init(struct os_dev *dev, void *arg)
     }
 
     /* Add the accelerometer/magnetometer driver */
-    rc = sensor_set_driver(sensor, SENSOR_TYPE_ACCELEROMETER |
-            SENSOR_TYPE_MAGNETIC_FIELD,
-            (struct sensor_driver *) &g_bno055_sensor_driver);
+    rc = sensor_set_driver(sensor, SENSOR_TYPE_ACCELEROMETER         |
+            SENSOR_TYPE_MAGNETIC_FIELD | SENSOR_TYPE_GYROSCOPE       |
+            SENSOR_TYPE_TEMPERATURE    | SENSOR_TYPE_ROTATION_VECTOR |
+            SENSOR_TYPE_GRAVITY        | SENSOR_TYPE_LINEAR_ACCEL    |
+            SENSOR_TYPE_EULER, (struct sensor_driver *) &g_bno055_sensor_driver);
     if (rc != 0) {
         goto err;
     }
@@ -448,23 +481,23 @@ err:
 /**
  * Use external crystal 32.768KHz
  *
+ * @param operational mode of the sensor
  * @return 0 on success, non-zero on failure
  */
 static int
-bno055_set_ext_xtal_use(uint8_t use_xtal)
+bno055_set_ext_xtal_use(uint8_t use_xtal, uint8_t mode)
 {
     int rc;
-    uint8_t prev_mode;
-
-    prev_mode = g_bno055_opr_mode;
 
-    /* Switch to config mode */
-    rc = bno055_set_opr_mode(BNO055_OPERATION_MODE_CONFIG);
-    if (rc) {
-        goto err;
+    if (mode != BNO055_OPR_MODE_CONFIG) {
+        /* Switch to config mode */
+        rc = bno055_set_opr_mode(BNO055_OPR_MODE_CONFIG);
+        if (rc) {
+            goto err;
+        }
     }
 
-    os_time_delay(OS_TICKS_PER_SEC/1000 * 25);
+    os_time_delay((OS_TICKS_PER_SEC * 25)/1000 + 1);
 
     rc = bno055_write8(BNO055_PAGE_ID_ADDR, 0);
     if (rc) {
@@ -485,16 +518,14 @@ bno055_set_ext_xtal_use(uint8_t use_xtal)
         }
     }
 
-    os_time_delay(OS_TICKS_PER_SEC/1000 * 10);
+    os_time_delay((OS_TICKS_PER_SEC * 10)/1000 + 1);
 
     /* Reset to previous operating mode */
-    rc = bno055_set_opr_mode(prev_mode);
+    rc = bno055_set_opr_mode(mode);
     if (rc) {
         goto err;
     }
 
-    os_time_delay(OS_TICKS_PER_SEC/1000 * 20);
-
     return 0;
 err:
     return rc;
@@ -506,9 +537,6 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
 {
     int rc;
     uint8_t id;
-    uint8_t prev_mode;
-
-    prev_mode = g_bno055_opr_mode;
 
     /* Check if we can read the chip address */
     rc = bno055_get_chip_id(&id);
@@ -517,7 +545,7 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
     }
 
     if (id != BNO055_ID) {
-        os_time_delay(OS_TICKS_PER_SEC/1000 * 100);
+        os_time_delay((OS_TICKS_PER_SEC * 100)/1000 + 1);
 
         rc = bno055_get_chip_id(&id);
         if (rc) {
@@ -536,13 +564,13 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
         goto err;
     }
 
-    rc = bno055_set_opr_mode(BNO055_OPERATION_MODE_CONFIG);
+    rc = bno055_set_opr_mode(BNO055_OPR_MODE_CONFIG);
     if (rc) {
         goto err;
     }
 
     /* Set to normal power mode */
-    rc = bno055_set_pwr_mode(BNO055_POWER_MODE_NORMAL);
+    rc = bno055_set_pwr_mode(cfg->bc_pwr_mode);
     if (rc) {
         goto err;
     }
@@ -552,22 +580,20 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
         goto err;
     }
 
-    os_time_delay(OS_TICKS_PER_SEC/1000 * 10);
+    os_time_delay((OS_TICKS_PER_SEC * 10)/1000 + 1);
 
     /**
      * As per Section 5.5 in the BNO055 Datasheet,
      * external crystal should be used for accurate
      * results
      */
-    rc = bno055_set_ext_xtal_use(1);
+    rc = bno055_set_ext_xtal_use(1, BNO055_OPR_MODE_CONFIG);
     if (rc) {
         goto err;
     }
 
     /* Setting units and data output format */
-    rc = bno055_set_units(BNO055_ACC_UNIT_MS2 | BNO055_ANGRATE_UNIT_DPS |
-                          BNO055_EULER_UNIT_DEG | BNO055_TEMP_UNIT_DEGC |
-                          BNO055_DO_FORMAT_ANDROID);
+    rc = bno055_set_units(cfg->bc_units);
     if (rc) {
         goto err;
     }
@@ -575,8 +601,8 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
     /* Overwrite the configuration data. */
     memcpy(&bno055->cfg, cfg, sizeof(*cfg));
 
-    /* Change back to previous mode */
-    rc = bno055_set_opr_mode(prev_mode);
+    /* Change mode to requested mode */
+    rc = bno055_set_opr_mode(cfg->bc_opr_mode);
     if (rc) {
         goto err;
     }
@@ -705,7 +731,10 @@ bno055_get_vector_data(void *datastruct, int type)
     y = ((int16_t)payload[2]) | (((int16_t)payload[3]) << 8);
     z = ((int16_t)payload[4]) | (((int16_t)payload[5]) << 8);
 
-    units = bno055_get_units();
+    rc = bno055_get_units(&units);
+    if (rc) {
+        goto err;
+    }
 
     acc_div  = units & BNO055_ACC_UNIT_MG ? 1.0:100.0;
     gyro_div = units & BNO055_ANGRATE_UNIT_RPS ? 900.0:16.0;
@@ -770,13 +799,21 @@ bno055_get_temp(int8_t *temp)
     uint8_t div;
 
     rc = bno055_read8(BNO055_TEMP_ADDR, (uint8_t *)temp);
+    if (rc) {
+        goto err;
+    }
 
-    units = bno055_get_units();
+    rc = bno055_get_units(&units);
+    if (rc) {
+        goto err;
+    }
 
     div = units & BNO055_TEMP_UNIT_DEGF ? 2 : 1;
 
     *temp = *temp/div;
 
+    return 0;
+err:
     return rc;
 }
 
@@ -911,7 +948,7 @@ bno055_get_sys_status(uint8_t *system_status, uint8_t *self_test_result, uint8_t
         }
     }
 
-    os_time_delay(OS_TICKS_PER_SEC/1000 * 200);
+    os_time_delay((OS_TICKS_PER_SEC * 200)/1000 + 1);
 
     return 0;
 err:
@@ -996,7 +1033,11 @@ bno055_sensor_get_config(struct sensor *sensor, sensor_type_t type,
         goto err;
     }
 
-    cfg->sc_valtype = SENSOR_VALUE_TYPE_FLOAT_TRIPLET;
+    if (type != SENSOR_TYPE_TEMPERATURE) {
+        cfg->sc_valtype = SENSOR_VALUE_TYPE_FLOAT_TRIPLET;
+    } else {
+        cfg->sc_valtype = SENSOR_VALUE_TYPE_INT32;
+    }
 
     return (0);
 err:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/hw/drivers/sensors/bno055/src/bno055_priv.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_priv.h b/hw/drivers/sensors/bno055/src/bno055_priv.h
index 8bb0ea1..d98d3d0 100644
--- a/hw/drivers/sensors/bno055/src/bno055_priv.h
+++ b/hw/drivers/sensors/bno055/src/bno055_priv.h
@@ -102,16 +102,6 @@
 #define BNO055_UNIT_SEL_ADDR                                    0X3B
 
 #define BNO055_DATA_SELECT_ADDR                                 0X3C
-#define BNO055_ACC_UNIT_MS2                                      0x0
-#define BNO055_ACC_UNIT_MG                                       0x1
-#define BNO055_ANGRATE_UNIT_DPS                             (0 << 1)
-#define BNO055_ANGRATE_UNIT_RPS                             (1 << 1)
-#define BNO055_EULER_UNIT_DEG                               (0 << 2)
-#define BNO055_EULER_UNIT_RAD                               (1 << 2)
-#define BNO055_TEMP_UNIT_DEGC                               (0 << 4)
-#define BNO055_TEMP_UNIT_DEGF                               (1 << 4)
-#define BNO055_DO_FORMAT_WINDOWS                            (0 << 7)
-#define BNO055_DO_FORMAT_ANDROID                            (1 << 7)
 
 /* Mode registers */
 #define BNO055_OPR_MODE_ADDR                                    0X3D
@@ -179,26 +169,6 @@
 #define BNO055_MAG_RADIUS_LSB_ADDR                              0X69
 #define BNO055_MAG_RADIUS_MSB_ADDR                              0X6A
 
-/* Power modes */
-#define BNO055_POWER_MODE_NORMAL                                0X00
-#define BNO055_POWER_MODE_LOWPOWER                              0X01
-#define BNO055_POWER_MODE_SUSPEND                               0X02
-
-/* Operation Modes */
-#define BNO055_OPERATION_MODE_CONFIG                            0X00
-#define BNO055_OPERATION_MODE_ACCONLY                           0X01
-#define BNO055_OPERATION_MODE_MAGONLY                           0X02
-#define BNO055_OPERATION_MODE_GYRONLY                           0X03
-#define BNO055_OPERATION_MODE_ACCMAG                            0X04
-#define BNO055_OPERATION_MODE_ACCGYRO                           0X05
-#define BNO055_OPERATION_MODE_MAGGYRO                           0X06
-#define BNO055_OPERATION_MODE_AMG                               0X07
-#define BNO055_OPERATION_MODE_IMUPLUS                           0X08
-#define BNO055_OPERATION_MODE_COMPASS                           0X09
-#define BNO055_OPERATION_MODE_M4G                               0X0A
-#define BNO055_OPERATION_MODE_NDOF_FMC_OFF                      0X0B
-#define BNO055_OPERATION_MODE_NDOF                              0X0C
-
 /* Remap config - Default: 0x24 */
 #define BNO055_REMAP_CONFIG_P0                                  0x21
 #define BNO055_REMAP_CONFIG_P1                                  0x24
@@ -248,68 +218,4 @@
 #define BNO055_GYRO_ANY_MOTION_THRES_ADDR                       0X1E
 #define BNO055_GYRO_ANY_MOTION_SET_ADDR                         0X1F
 
-/* Accelerometer config */
-#define BNO055_ACC_CFG_2G                                        0x0
-#define BNO055_ACC_CFG_4G                                        0x1
-#define BNO055_ACC_CFG_8G                                        0x2
-#define BNO055_ACC_CFG_16G                                       0x3
-
-#define BNO055_ACC_CFG_BW_7_81HZ                          (0x0 << 2)
-#define BNO055_ACC_CFG_BW_15_63HZ                         (0x1 << 2)
-#define BNO055_ACC_CFG_BW_31_25HZ                         (0x2 << 2)
-#define BNO055_ACC_CFG_BW_6_25HZ                          (0x3 << 2)
-#define BNO055_ACC_CFG_BW_125HZ                           (0x4 << 2)
-#define BNO055_ACC_CFG_BW_250HZ                           (0x5 << 2)
-#define BNO055_ACC_CFG_BW_500HZ                           (0x6 << 2)
-#define BNO055_ACC_CFG_BW_1000HZ                          (0x7 << 2)
-
-#define BNO055_ACC_CFG_OPR_MODE_NORMAL                    (0x0 << 5)
-#define BNO055_ACC_CFG_OPR_MODE_SUSPEND                   (0x1 << 5)
-#define BNO055_ACC_CFG_OPR_MODE_LOWPWR1                   (0x2 << 5)
-#define BNO055_ACC_CFG_OPR_MODE_STD                       (0x3 << 5)
-#define BNO055_ACC_CFG_OPR_MODE_LOWPWR2                   (0x4 << 5)
-#define BNO055_ACC_CFG_OPR_MODE_DSUSPEND                  (0x5 << 5)
-
-/* Gyroscope config */
-#define BNO055_GYR_CFG_RNG_2000DPS                               0x0
-#define BNO055_GYR_CFG_RNG_1000DPS                               0x1
-#define BNO055_GYR_CFG_RNG_500DPS                                0x2
-#define BNO055_GYR_CFG_RNG_250DPS                                0x3
-#define BNO055_GYR_CFG_RNG_125DPS                                0x4
-
-#define BNO055_GYR_CFG_BW_523HZ                           (0x0 << 3)
-#define BNO055_GYR_CFG_BW_230HZ                           (0x1 << 3)
-#define BNO055_GYR_CFG_BW_116HZ                           (0x2 << 3)
-#define BNO055_GYR_CFG_BW_47HZ                            (0x3 << 3)
-#define BNO055_GYR_CFG_BW_23HZ                            (0x4 << 3)
-#define BNO055_GYR_CFG_BW_12HZ                            (0x5 << 3)
-#define BNO055_GYR_CFG_BW_64HZ                            (0x6 << 3)
-#define BNO055_GYR_CFG_BW_32HZ                            (0x7 << 3)
-
-#define BNO055_GYR_CFG_OPR_MODE_NORMAL                    (0x0 << 5)
-#define BNO055_GYR_CFG_OPR_MODE_FAST_PWR_UP               (0x1 << 5)
-#define BNO055_GYR_CFG_OPR_MODE_DSUSPEND                  (0x2 << 5)
-#define BNO055_GYR_CFG_OPR_MODE_SUSPEND                   (0x3 << 5)
-#define BNO055_GYR_CFG_OPR_MODE_ADV_PWR_SAVE              (0x4 << 5)
-
-/* Magnetometer config */
-#define BNO055_MAG_CFG_BW_2HZ                                    0x0
-#define BNO055_MAG_CFG_BW_6HZ                                    0x1
-#define BNO055_MAG_CFG_BW_8HZ                                    0x2
-#define BNO055_MAG_CFG_BW_10HZ                                   0x3
-#define BNO055_MAG_CFG_BW_15HZ                                   0x4
-#define BNO055_MAG_CFG_BW_20HZ                                   0x5
-#define BNO055_MAG_CFG_BW_25HZ                                   0x6
-#define BNO055_MAG_CFG_BW_30HZ                                   0x7
-
-#define BNO055_MAG_CFG_OPR_MODE_LOWPWR                    (0x0 << 3)
-#define BNO055_MAG_CFG_OPR_MODE_REG                       (0x1 << 3)
-#define BNO055_MAG_CFG_OPR_MODE_EREG                      (0x2 << 3)
-#define BNO055_MAG_CFG_OPR_MODE_HIGHACC                   (0x3 << 3)
-
-#define BNO055_MAG_CFG_PWR_MODE_NORMAL                    (0x0 << 5)
-#define BNO055_MAG_CFG_PWR_MODE_SLEEP                     (0x1 << 5)
-#define BNO055_MAG_CFG_PWR_MODE_SUSPEND                   (0x2 << 5)
-#define BNO055_MAG_CFG_PWR_MODE_FORCE_MODE                (0x3 << 5)
-
 #define BNO055_ID                                               0xA0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/hw/drivers/sensors/bno055/src/bno055_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_shell.c b/hw/drivers/sensors/bno055/src/bno055_shell.c
index 4e0b3f7..5a74dfd 100644
--- a/hw/drivers/sensors/bno055/src/bno055_shell.c
+++ b/hw/drivers/sensors/bno055/src/bno055_shell.c
@@ -33,7 +33,6 @@
 #include "hal/hal_i2c.h"
 
 #if MYNEWT_VAL(BNO055_CLI)
-extern uint8_t g_bno055_mode;
 
 static int bno055_shell_cmd(int argc, char **argv);
 
@@ -254,8 +253,11 @@ bno055_shell_cmd_opr_mode(int argc, char **argv)
 
     /* Display the mode */
     if (argc == 2) {
-        val = bno055_get_opr_mode();
-        console_printf("%u\n", (unsigned int)val);
+        rc = bno055_get_opr_mode((uint8_t *)&val);
+        if (rc) {
+            goto err;
+        }
+        console_printf("%u\n", ((unsigned int)(*(uint8_t *)&val)));
     }
 
     /* Update the mode */
@@ -264,7 +266,7 @@ bno055_shell_cmd_opr_mode(int argc, char **argv)
             return bno055_shell_err_invalid_arg(argv[2]);
         }
         /* Make sure mode is valid */
-        if (val > BNO055_OPERATION_MODE_NDOF) {
+        if (val > BNO055_OPR_MODE_NDOF) {
             return bno055_shell_err_invalid_arg(argv[2]);
         }
 
@@ -291,7 +293,10 @@ bno055_shell_cmd_pwr_mode(int argc, char **argv)
 
     /* Display the mode */
     if (argc == 2) {
-        val = bno055_get_pwr_mode();
+        rc = bno055_get_pwr_mode((uint8_t *)&val);
+        if (rc) {
+            goto err;
+        }
         console_printf("%u\n", (unsigned int)val);
     }
 
@@ -301,7 +306,7 @@ bno055_shell_cmd_pwr_mode(int argc, char **argv)
             return bno055_shell_err_invalid_arg(argv[2]);
         }
         /* Make sure mode is valid */
-        if (val > BNO055_POWER_MODE_SUSPEND) {
+        if (val > BNO055_PWR_MODE_SUSPEND) {
             return bno055_shell_err_invalid_arg(argv[2]);
         }
 
@@ -328,7 +333,7 @@ bno055_shell_units_cmd(int argc, char **argv)
 
     /* Display the units */
     if (argc == 2) {
-        val = bno055_get_units();
+        rc = bno055_get_units((uint8_t *)&val);
         console_printf("Acc, linear acc, gravity: %s\n"
                        "Mag field strength: Micro Tesla\n"
                        "Ang rate: %s\n"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/hw/sensor/include/sensor/euler.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/euler.h b/hw/sensor/include/sensor/euler.h
index 5ddd44f..0b23ad1 100644
--- a/hw/sensor/include/sensor/euler.h
+++ b/hw/sensor/include/sensor/euler.h
@@ -39,9 +39,9 @@ struct sensor_euler_data {
 } __attribute__((packed));
 
 /**
- * Accelerometer data is unused for this field.
+ * Euler angles data is unused for this field.
  */
-#define SENSOR_ACCEL_DATA_UNUSED (-1)
+#define SENSOR_EULER_DATA_UNUSED (-1)
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e4d0f04a/hw/sensor/src/sensor_shell.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
index bd73cfa..545653f 100644
--- a/hw/sensor/src/sensor_shell.c
+++ b/hw/sensor/src/sensor_shell.c
@@ -34,6 +34,8 @@
 #include "sensor/accel.h"
 #include "sensor/mag.h"
 #include "sensor/light.h"
+#include "sensor/quat.h"
+#include "sensor/euler.h"
 #include "console/console.h"
 #include "shell/shell.h"
 
@@ -48,12 +50,13 @@ sensor_display_help(void)
 {
     console_printf("Possible commands for sensor are:\n");
     console_printf("  list\n");
+    console_printf("  read\n");
 }
 
 static void
 sensor_cmd_display_sensor(struct sensor *sensor)
 {
-    console_printf("sensor dev = %s, type = %lld\n", sensor->s_dev->od_name,
+    console_printf("sensor dev = %s, type = 0x%llx\n", sensor->s_dev->od_name,
             sensor->s_types);
 }
 
@@ -100,13 +103,19 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
     struct sensor_accel_data *sad;
     struct sensor_mag_data *smd;
     struct sensor_light_data *sld;
+    struct sensor_euler_data *sed;
+    struct sensor_quat_data *sqd;
+    int8_t *temperature;
     char tmpstr[13];
 
     ctx = (struct sensor_shell_read_ctx *) arg;
 
     ++ctx->num_entries;
 
-    if (ctx->type == SENSOR_TYPE_ACCELEROMETER) {
+    if (ctx->type == SENSOR_TYPE_ACCELEROMETER ||
+        ctx->type == SENSOR_TYPE_LINEAR_ACCEL  ||
+        ctx->type == SENSOR_TYPE_GRAVITY) {
+
         sad = (struct sensor_accel_data *) data;
         if (sad->sad_x != SENSOR_ACCEL_DATA_UNUSED) {
             console_printf("x = %s ", sensor_ftostr(sad->sad_x, tmpstr, 13));
@@ -148,6 +157,43 @@ sensor_shell_read_listener(struct sensor *sensor, void *arg, void *data)
         console_printf("\n");
     }
 
+    if (ctx->type == SENSOR_TYPE_TEMPERATURE) {
+        temperature = (int8_t *) data;
+        console_printf("temprature = %d", *temperature);
+        console_printf("\n");
+    }
+
+    if (ctx->type == SENSOR_TYPE_EULER) {
+        sed = (struct sensor_euler_data *) data;
+        if (sed->sed_h != SENSOR_EULER_DATA_UNUSED) {
+            console_printf("h = %s", sensor_ftostr(sed->sed_h, tmpstr, 13));
+        }
+        if (sed->sed_r != SENSOR_EULER_DATA_UNUSED) {
+            console_printf("r = %s", sensor_ftostr(sed->sed_r, tmpstr, 13));
+        }
+        if (sed->sed_p != SENSOR_EULER_DATA_UNUSED) {
+            console_printf("p = %s", sensor_ftostr(sed->sed_p, tmpstr, 13));
+        }
+        console_printf("\n");
+    }
+
+    if (ctx->type == SENSOR_TYPE_ROTATION_VECTOR) {
+        sqd = (struct sensor_quat_data *) data;
+        if (sqd->sqd_x != SENSOR_QUAT_DATA_UNUSED) {
+            console_printf("x = %s ", sensor_ftostr(sqd->sqd_x, tmpstr, 13));
+        }
+        if (sqd->sqd_y != SENSOR_QUAT_DATA_UNUSED) {
+            console_printf("y = %s ", sensor_ftostr(sqd->sqd_y, tmpstr, 13));
+        }
+        if (sqd->sqd_z != SENSOR_QUAT_DATA_UNUSED) {
+            console_printf("z = %s ", sensor_ftostr(sqd->sqd_z, tmpstr, 13));
+        }
+        if (sqd->sqd_w != SENSOR_QUAT_DATA_UNUSED) {
+            console_printf("w = %s ", sensor_ftostr(sqd->sqd_w, tmpstr, 13));
+        }
+        console_printf("\n");
+    }
+
     return (0);
 }