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/03/03 00:54:29 UTC

incubator-mynewt-core git commit: SensorAPI BNO055: Add default config

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 58378ccfa -> 4af79d477


SensorAPI BNO055: Add default config

- Improve config


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/4af79d47
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4af79d47
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4af79d47

Branch: refs/heads/develop
Commit: 4af79d47775b64093b3b2a27e7b7d3fe457b5818
Parents: 58378cc
Author: Vipul Rahane <vi...@apache.org>
Authored: Thu Mar 2 16:53:13 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Thu Mar 2 16:54:15 2017 -0800

----------------------------------------------------------------------
 apps/sensors_test/src/main.c                    |   2 +
 .../sensors/bno055/include/bno055/bno055.h      |  55 ++++--
 hw/drivers/sensors/bno055/src/bno055.c          | 177 ++++++++++++++++---
 3 files changed, 196 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4af79d47/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index 3c5cedd..b79b2b5 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -312,6 +312,8 @@ config_sensor(void)
 
     bcfg.bc_pwr_mode = BNO055_PWR_MODE_NORMAL;
 
+    bcfg.bc_use_ext_xtal = 1;
+
     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/4af79d47/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 0529a2d..f04c2ae 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -60,10 +60,10 @@ extern "C" {
 #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_RNG_2G                                    0x0
+#define BNO055_ACC_CFG_RNG_4G                                    0x1
+#define BNO055_ACC_CFG_RNG_8G                                    0x2
+#define BNO055_ACC_CFG_RNG_16G                                   0x3
 
 #define BNO055_ACC_CFG_BW_7_81HZ                          (0x0 << 2)
 #define BNO055_ACC_CFG_BW_15_63HZ                         (0x1 << 2)
@@ -104,14 +104,14 @@ extern "C" {
 #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_ODR_2HZ                                    0x0
+#define BNO055_MAG_CFG_ODR_6HZ                                    0x1
+#define BNO055_MAG_CFG_ODR_8HZ                                    0x2
+#define BNO055_MAG_CFG_ODR_10HZ                                   0x3
+#define BNO055_MAG_CFG_ODR_15HZ                                   0x4
+#define BNO055_MAG_CFG_ODR_20HZ                                   0x5
+#define BNO055_MAG_CFG_ODR_25HZ                                   0x6
+#define BNO055_MAG_CFG_ODR_30HZ                                   0x7
 
 #define BNO055_MAG_CFG_OPR_MODE_LOWPWR                    (0x0 << 3)
 #define BNO055_MAG_CFG_OPR_MODE_REG                       (0x1 << 3)
@@ -123,10 +123,41 @@ extern "C" {
 #define BNO055_MAG_CFG_PWR_MODE_SUSPEND                   (0x2 << 5)
 #define BNO055_MAG_CFG_PWR_MODE_FORCE_MODE                (0x3 << 5)
 
+/*
+ * Just a placeholder to specify resolution/axis x:13 bits, y:13 bits,
+ * z:15 bits
+ */
+#define BNO055_MAG_RES_13_13_15                                 0x00
+
+#define BNO055_AXIS_CFG_P0                                      0x00
+#define BNO055_AXIS_CFG_P1                                      0x01 /* Default */
+#define BNO055_AXIS_CFG_P2                                      0x02
+#define BNO055_AXIS_CFG_P3                                      0x03
+#define BNO055_AXIS_CFG_P4                                      0x04
+#define BNO055_AXIS_CFG_P5                                      0x05
+#define BNO055_AXIS_CFG_P6                                      0x06
+#define BNO055_AXIS_CFG_P7                                      0x07
+
 struct bno055_cfg {
     uint8_t bc_opr_mode;
     uint8_t bc_pwr_mode;
     uint8_t bc_units;
+    uint8_t bc_placement;
+    uint8_t bc_acc_range;
+    uint8_t bc_acc_bw;
+    uint8_t bc_acc_opr_mode;
+    uint8_t bc_acc_res;
+    uint8_t bc_gyro_range;
+    uint8_t bc_gyro_bw;
+    uint8_t bc_gyro_opr_mode;
+    uint8_t bc_gyro_res;
+    uint8_t bc_mag_odr;
+    uint8_t bc_mag_xy_rep;
+    uint8_t bc_mag_z_rep;
+    uint8_t bc_mag_res;
+    uint8_t bc_mag_pwr_mode;
+    uint8_t bc_mag_opr_mode;
+    uint8_t bc_use_ext_xtal;
 };
 
 struct bno055 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4af79d47/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 fb98197..4b9f32c 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -44,33 +44,11 @@
 #if MYNEWT_VAL(BNO055_STATS)
 /* Define the stats section and records */
 STATS_SECT_START(bno055_stat_section)
-    STATS_SECT_ENTRY(samples_acc_2g)
-    STATS_SECT_ENTRY(samples_acc_4g)
-    STATS_SECT_ENTRY(samples_acc_8g)
-    STATS_SECT_ENTRY(samples_acc_16g)
-    STATS_SECT_ENTRY(samples_mag_1_3g)
-    STATS_SECT_ENTRY(samples_mag_1_9g)
-    STATS_SECT_ENTRY(samples_mag_2_5g)
-    STATS_SECT_ENTRY(samples_mag_4_0g)
-    STATS_SECT_ENTRY(samples_mag_4_7g)
-    STATS_SECT_ENTRY(samples_mag_5_6g)
-    STATS_SECT_ENTRY(samples_mag_8_1g)
     STATS_SECT_ENTRY(errors)
 STATS_SECT_END
 
 /* Define stat names for querying */
 STATS_NAME_START(bno055_stat_section)
-    STATS_NAME(bno055_stat_section, samples_acc_2g)
-    STATS_NAME(bno055_stat_section, samples_acc_4g)
-    STATS_NAME(bno055_stat_section, samples_acc_8g)
-    STATS_NAME(bno055_stat_section, samples_acc_16g)
-    STATS_NAME(bno055_stat_section, samples_mag_1_3g)
-    STATS_NAME(bno055_stat_section, samples_mag_1_9g)
-    STATS_NAME(bno055_stat_section, samples_mag_2_5g)
-    STATS_NAME(bno055_stat_section, samples_mag_4_0g)
-    STATS_NAME(bno055_stat_section, samples_mag_4_7g)
-    STATS_NAME(bno055_stat_section, samples_mag_5_6g)
-    STATS_NAME(bno055_stat_section, samples_mag_8_1g)
     STATS_NAME(bno055_stat_section, errors)
 STATS_NAME_END(bno055_stat_section)
 
@@ -444,6 +422,31 @@ err:
     return rc;
 }
 
+static int
+bno055_default_cfg(struct bno055_cfg *cfg)
+{
+    cfg->bc_opr_mode = BNO055_OPR_MODE_ACCONLY;
+    cfg->bc_pwr_mode = BNO055_PWR_MODE_NORMAL;
+    cfg->bc_units = BNO055_DO_FORMAT_ANDROID|
+                    BNO055_ACC_UNIT_MS2|
+                    BNO055_ANGRATE_UNIT_DPS|
+                    BNO055_EULER_UNIT_DEG|
+                    BNO055_TEMP_UNIT_DEGC;
+    cfg->bc_placement = BNO055_AXIS_CFG_P1;
+    cfg->bc_acc_range = BNO055_ACC_CFG_RNG_4G;
+    cfg->bc_acc_bw = BNO055_ACC_CFG_BW_6_25HZ;
+    cfg->bc_acc_res = 14;
+    cfg->bc_gyro_range = BNO055_GYR_CFG_RNG_2000DPS;
+    cfg->bc_gyro_bw = BNO055_GYR_CFG_BW_32HZ;
+    cfg->bc_gyro_res = 16;
+    cfg->bc_mag_odr = BNO055_MAG_CFG_ODR_2HZ;
+    cfg->bc_mag_xy_rep = 15;
+    cfg->bc_mag_z_rep = 16;
+    cfg->bc_mag_res = BNO055_MAG_RES_13_13_15;
+
+    return 0;
+}
+
 /**
  * Expects to be called back through os_dev_create().
  *
@@ -461,6 +464,11 @@ bno055_init(struct os_dev *dev, void *arg)
 
     bno055 = (struct bno055 *) dev;
 
+    rc = bno055_default_cfg(&bno055->cfg);
+    if (rc) {
+        goto err;
+    }
+
 #if MYNEWT_VAL(BNO055_LOG)
     log_register("bno055", &_log, &log_console_handler, NULL, LOG_SYSLEVEL);
 #endif
@@ -582,6 +590,117 @@ err:
     return rc;
 }
 
+int
+bno055_placement_cfg(uint8_t placement)
+{
+    uint8_t remap_cfg;
+    uint8_t remap_sign;
+    int rc;
+
+    rc = SYS_EOK;
+
+    switch(placement) {
+
+    case BNO055_AXIS_CFG_P0:
+        remap_cfg = BNO055_REMAP_CONFIG_P0;
+        remap_sign = BNO055_REMAP_SIGN_P0;
+        break;
+    case BNO055_AXIS_CFG_P1:
+        remap_cfg = BNO055_REMAP_CONFIG_P1;
+        remap_sign = BNO055_REMAP_SIGN_P1;
+        break;
+    case BNO055_AXIS_CFG_P2:
+        remap_cfg = BNO055_REMAP_CONFIG_P2;
+        remap_sign = BNO055_REMAP_SIGN_P2;
+        break;
+    case BNO055_AXIS_CFG_P3:
+        remap_cfg = BNO055_REMAP_CONFIG_P3;
+        remap_sign = BNO055_REMAP_SIGN_P3;
+        break;
+    case BNO055_AXIS_CFG_P4:
+        remap_cfg = BNO055_REMAP_CONFIG_P4;
+        remap_sign = BNO055_REMAP_SIGN_P4;
+        break;
+    case BNO055_AXIS_CFG_P5:
+        remap_cfg = BNO055_REMAP_CONFIG_P5;
+        remap_sign = BNO055_REMAP_SIGN_P5;
+        break;
+    case BNO055_AXIS_CFG_P6:
+        remap_cfg = BNO055_REMAP_CONFIG_P6;
+        remap_sign = BNO055_REMAP_SIGN_P6;
+        break;
+    case BNO055_AXIS_CFG_P7:
+        remap_cfg = BNO055_REMAP_CONFIG_P7;
+        remap_sign = BNO055_REMAP_SIGN_P7;
+        break;
+    default:
+        BNO055_ERR("Invalid Axis config, Assuming P1(default) \n");
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    rc = bno055_write8(BNO055_AXIS_MAP_CONFIG_ADDR, remap_cfg);
+    if (rc) {
+        goto err;
+    }
+
+    rc = bno055_write8(BNO055_AXIS_MAP_SIGN_ADDR, remap_sign);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+int
+bno055_acc_cfg(struct bno055_cfg *cfg)
+{
+    int rc;
+
+    rc = bno055_write8(BNO055_ACCEL_CONFIG_ADDR, cfg->bc_acc_range|
+                       cfg->bc_acc_bw|cfg->bc_acc_opr_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+int
+bno055_mag_cfg(struct bno055_cfg *cfg)
+{
+    int rc;
+
+    rc = bno055_write8(BNO055_MAG_CONFIG_ADDR, cfg->bc_mag_odr|
+                       cfg->bc_mag_pwr_mode|cfg->bc_mag_opr_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+int
+bno055_gyro_cfg(struct bno055_cfg *cfg)
+{
+    int rc;
+
+    rc = bno055_write8(BNO055_GYRO_CONFIG_ADDR, cfg->bc_gyro_range|
+                       cfg->bc_gyro_bw|cfg->bc_gyro_opr_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
 
 int
 bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
@@ -629,22 +748,28 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
         goto err;
     }
 
+    bno055->cfg.bc_pwr_mode = cfg->bc_pwr_mode;
+
     /**
      * As per Section 5.5 in the BNO055 Datasheet,
      * external crystal should be used for accurate
      * results
      */
-    rc = bno055_set_ext_xtal_use(1, BNO055_OPR_MODE_CONFIG);
+    rc = bno055_set_ext_xtal_use(cfg->bc_use_ext_xtal, BNO055_OPR_MODE_CONFIG);
     if (rc) {
         goto err;
     }
 
+    bno055->cfg.bc_use_ext_xtal = cfg->bc_use_ext_xtal;
+
     /* Setting units and data output format */
     rc = bno055_set_units(cfg->bc_units);
     if (rc) {
         goto err;
     }
 
+    bno055->cfg.bc_units = cfg->bc_units;
+
     /* Change mode to requested mode */
     rc = bno055_set_opr_mode(cfg->bc_opr_mode);
     if (rc) {
@@ -674,12 +799,12 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
 
         if (cfg->bc_opr_mode != mode) {
             BNO055_ERR("Config mode and read mode do not match.\n");
-            return rc;
+            rc = SYS_EINVAL;
+            goto err;
         }
     }
 
-    /* Overwrite the configuration data. */
-    memcpy(&bno055->cfg, cfg, sizeof(*cfg));
+    bno055->cfg.bc_opr_mode = cfg->bc_opr_mode;
 
     return 0;
 err: