You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by gi...@git.apache.org on 2017/06/07 18:40:27 UTC

[GitHub] vrahane commented on a change in pull request #258: MYNEWT-744 SensorAPI: improvements

vrahane commented on a change in pull request #258: MYNEWT-744 SensorAPI: improvements
URL: https://github.com/apache/incubator-mynewt-core/pull/258#discussion_r120711292
 
 

 ##########
 File path: hw/bsp/ruuvi_tag_revb2/src/hal_bsp.c
 ##########
 @@ -187,71 +164,62 @@ hal_bsp_get_nvic_priority(int irq_num, uint32_t pri)
     return cfg_pri;
 }
 
-#if MYNEWT_VAL(LSM303DLHC_PRESENT) || MYNEWT_VAL(BNO055_PRESENT)
+/**
+ * BME280 Sensor default configuration used by the creator package
+ *
+ * @return 0 on success, non-zero on failure
+ */
+#if MYNEWT_VAL(BME280_ONB)
 static int
-accel_init(struct os_dev *dev, void *arg)
+config_bme280_sensor(void)
 {
-   return (0);
-}
-#endif
+    int rc;
+    struct os_dev *dev;
+    struct bme280_cfg bmecfg;
 
-#if MYNEWT_VAL(TSL2561_PRESENT)
-static int
-slinky_light_init(struct os_dev *dev, void *arg)
-{
-    return (0);
-}
-#endif
+    dev = (struct os_dev *) os_dev_open("bme280_0", OS_TIMEOUT_NEVER, NULL);
+    assert(dev != NULL);
 
-#if MYNEWT_VAL(TCS34725_PRESENT)
-static int
-color_init(struct os_dev *dev, void *arg)
-{
-    return (0);
-}
-#endif
+    if (!(dev->od_flags & OS_DEV_F_STATUS_READY)) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
 
-#if MYNEWT_VAL(BME280_PRESENT)
-static int
-press_init(struct os_dev *dev, void *arg)
-{
-    return (0);
+    memset(&bmecfg, 0, sizeof(bmecfg));
+
+    bmecfg.bc_mode = BME280_MODE_NORMAL;
+    bmecfg.bc_iir = BME280_FILTER_X16;
+    bmecfg.bc_sby_dur = BME280_STANDBY_MS_0_5;
+    bmecfg.bc_boc[0].boc_type = SENSOR_TYPE_RELATIVE_HUMIDITY;
+    bmecfg.bc_boc[1].boc_type = SENSOR_TYPE_PRESSURE;
+    bmecfg.bc_boc[2].boc_type = SENSOR_TYPE_AMBIENT_TEMPERATURE;
+    bmecfg.bc_boc[0].boc_oversample = BME280_SAMPLING_X1;
+    bmecfg.bc_boc[1].boc_oversample = BME280_SAMPLING_X16;
+    bmecfg.bc_boc[2].boc_oversample = BME280_SAMPLING_X2;
+    bmecfg.bc_s_mask = SENSOR_TYPE_AMBIENT_TEMPERATURE|
+                       SENSOR_TYPE_PRESSURE|
+                       SENSOR_TYPE_RELATIVE_HUMIDITY;
+
+    rc = bme280_config((struct bme280 *)dev, &bmecfg);
+
+err:
+    os_dev_close(dev);
+    return rc;
 }
 #endif
 
 static void
 sensor_dev_create(void)
 {
     int rc;
-
     (void)rc;
-#if MYNEWT_VAL(LSM303DLHC_PRESENT)
-    rc = os_dev_create((struct os_dev *) &lsm303dlhc, "accel0",
-      OS_DEV_INIT_PRIMARY, 0, accel_init, NULL);
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(BNO055_PRESENT)
-    rc = os_dev_create((struct os_dev *) &bno055, "accel1",
-      OS_DEV_INIT_PRIMARY, 0, accel_init, NULL);
-    assert(rc == 0);
-#endif
 
-#if MYNEWT_VAL(TSL2561_PRESENT)
-    rc = os_dev_create((struct os_dev *) &tsl2561, "light0",
-      OS_DEV_INIT_PRIMARY, 0, light_init, NULL);
-    assert(rc == 0);
-#endif
-
-#if MYNEWT_VAL(TCS34725_PRESENT)
-    rc = os_dev_create((struct os_dev *) &tcs34725, "color0",
-      OS_DEV_INIT_PRIMARY, 0, color_init, NULL);
+#if MYNEWT_VAL(BME280_ONB)
+    rc = os_dev_create((struct os_dev *) &bme280, "bme280",
+      OS_DEV_INIT_PRIMARY, 0, bme280_init, (void *)&spi_0_itf_bme);
     assert(rc == 0);
-#endif
 
-#if MYNEWT_VAL(BME280_PRESENT)
-    rc = os_dev_create((struct os_dev *) &bme280, "bme280",
-      OS_DEV_INIT_PRIMARY, 0, press_init, NULL);
+    rc = config_bme280_sensor();
 
 Review comment:
   The consensus was, there would be an initial config that happens at the bsp level. The user of the sensor can then go and re-config the sensor in the app if needed.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services