[mynewt-core] branch master updated: BMP388 Pressure/temperature sensor i2c communtication optimization (#2376)

2020-09-20 Thread vipulrahane
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
 new a351a4d  BMP388 Pressure/temperature sensor i2c communtication 
optimization (#2376)
a351a4d is described below

commit a351a4dca423d6676e7b8c1e72db6fed87744bd9
Author: Philip Burkhardt <63323391+supervillain...@users.noreply.github.com>
AuthorDate: Sun Sep 20 12:24:52 2020 -0700

BMP388 Pressure/temperature sensor i2c communtication optimization (#2376)

* Add hybrid streaming mode that works without an interrupt pin
---
 hw/drivers/sensors/bmp388/include/bmp388/bmp388.h |   2 +
 hw/drivers/sensors/bmp388/src/bmp388.c| 249 +-
 hw/drivers/sensors/bmp388/syscfg.yml  |   5 +
 3 files changed, 253 insertions(+), 3 deletions(-)

diff --git a/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h 
b/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
index 41b8f94..30d09dc 100644
--- a/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
+++ b/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
@@ -381,6 +381,7 @@ enum bmp388_int_type {
 enum bmp388_read_mode {
 BMP388_READ_M_POLL = 0,
 BMP388_READ_M_STREAM = 1,
+BMP388_READ_M_HYBRID = 2,
 };
 
 /* Read mode configuration */
@@ -719,6 +720,7 @@ struct bmp388 {
 #endif
 /* Variable used to hold stats data */
 STATS_SECT_DECL(bmp388_stat_section) stats;
+bool bmp388_cfg_complete;
 };
 
 /**
diff --git a/hw/drivers/sensors/bmp388/src/bmp388.c 
b/hw/drivers/sensors/bmp388/src/bmp388.c
index 412f6b9..b3b9aa7 100644
--- a/hw/drivers/sensors/bmp388/src/bmp388.c
+++ b/hw/drivers/sensors/bmp388/src/bmp388.c
@@ -3142,7 +3142,7 @@ bmp388_stream_read(struct sensor *sensor,
 /* FIFO object to be assigned to device structure */
 struct bmp3_fifo fifo;
 /* Pressure and temperature array of structures with maximum frame size */
-struct bmp3_data sensor_data[74];
+struct bmp3_data sensor_data[MYNEWT_VAL(BMP388_FIFO_CONVERTED_DATA_SIZE)];
 /* Loop Variable */
 uint8_t i;
 uint16_t frame_length;
@@ -3231,8 +3231,9 @@ bmp388_stream_read(struct sensor *sensor,
 #endif
 
 if (time_ms != 0) {
-if (time_ms > BMP388_MAX_STREAM_MS)
+if (time_ms > BMP388_MAX_STREAM_MS) {
 time_ms = BMP388_MAX_STREAM_MS;
+}
 rc = os_time_ms_to_ticks(time_ms, _ticks);
 if (rc) {
 goto err;
@@ -3366,6 +3367,246 @@ err:
 return rc;
 }
 
+int
+bmp388_hybrid_read(struct sensor *sensor,
+   sensor_type_t sensor_type,
+   sensor_data_func_t read_func,
+   void *read_arg,
+   uint32_t time_ms)
+{
+int rc;
+struct bmp388 *bmp388;
+struct bmp388_cfg *cfg;
+os_time_t time_ticks;
+os_time_t stop_ticks = 0;
+uint16_t try_count;
+
+#if MYNEWT_VAL(BMP388_FIFO_ENABLE)
+/* FIFO object to be assigned to device structure */
+struct bmp3_fifo fifo;
+/* Pressure and temperature array of structures with maximum frame size */
+struct bmp3_data sensor_data[MYNEWT_VAL(BMP388_FIFO_CONVERTED_DATA_SIZE)];
+/* Loop Variable */
+uint8_t i;
+uint16_t frame_length;
+/* Enable fifo */
+fifo.settings.mode = BMP3_ENABLE;
+/* Enable Pressure sensor for fifo */
+fifo.settings.press_en = BMP3_ENABLE;
+/* Enable temperature sensor for fifo */
+fifo.settings.temp_en = BMP3_ENABLE;
+/* Enable fifo time */
+fifo.settings.time_en = BMP3_ENABLE;
+/* No subsampling for FIFO */
+fifo.settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING;
+fifo.sensortime_updated = false;
+uint16_t current_fifo_len;
+#else
+struct bmp3_data sensor_data;
+#endif
+
+/* If the read isn't looking for pressure or temperature data, don't do 
anything. */
+if ((!(sensor_type & SENSOR_TYPE_PRESSURE)) &&
+(!(sensor_type & SENSOR_TYPE_TEMPERATURE))) {
+BMP388_LOG_ERROR("unsupported sensor type for bmp388\n");
+return SYS_EINVAL;
+}
+
+bmp388 = (struct bmp388 *)SENSOR_GET_DEVICE(sensor);
+
+cfg = >cfg;
+
+if (cfg->read_mode.mode != BMP388_READ_M_HYBRID) {
+BMP388_LOG_ERROR("*bmp388_hybrid_read mode is not hybrid\n");
+return SYS_EINVAL;
+}
+
+if (bmp388->bmp388_cfg_complete == false) {
+/* no interrupt feature */
+/* enable normal mode for fifo feature */
+rc = bmp388_set_normal_mode(bmp388);
+if (rc) {
+BMP388_LOG_ERROR("**bmp388_set_normal_mode failed %d\n", rc);
+goto error;
+}
+
+rc = bmp3_fifo_flush(>bmp3_dev); 
+if(rc) {
+BMP388_LOG_ERROR("fifo flush failed, error=0x%02x\n", rc);
+goto error;
+}
+
+rc = bmp388_set_fifo_cfg(bmp388, cfg->fifo_mode, cfg->fifo_threshold);
+  

[mynewt-core] branch master updated: BMP388 Pressure/temperature sensor i2c communtication optimization (#2376)

2020-09-20 Thread vipulrahane
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
 new a351a4d  BMP388 Pressure/temperature sensor i2c communtication 
optimization (#2376)
a351a4d is described below

commit a351a4dca423d6676e7b8c1e72db6fed87744bd9
Author: Philip Burkhardt <63323391+supervillain...@users.noreply.github.com>
AuthorDate: Sun Sep 20 12:24:52 2020 -0700

BMP388 Pressure/temperature sensor i2c communtication optimization (#2376)

* Add hybrid streaming mode that works without an interrupt pin
---
 hw/drivers/sensors/bmp388/include/bmp388/bmp388.h |   2 +
 hw/drivers/sensors/bmp388/src/bmp388.c| 249 +-
 hw/drivers/sensors/bmp388/syscfg.yml  |   5 +
 3 files changed, 253 insertions(+), 3 deletions(-)

diff --git a/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h 
b/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
index 41b8f94..30d09dc 100644
--- a/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
+++ b/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
@@ -381,6 +381,7 @@ enum bmp388_int_type {
 enum bmp388_read_mode {
 BMP388_READ_M_POLL = 0,
 BMP388_READ_M_STREAM = 1,
+BMP388_READ_M_HYBRID = 2,
 };
 
 /* Read mode configuration */
@@ -719,6 +720,7 @@ struct bmp388 {
 #endif
 /* Variable used to hold stats data */
 STATS_SECT_DECL(bmp388_stat_section) stats;
+bool bmp388_cfg_complete;
 };
 
 /**
diff --git a/hw/drivers/sensors/bmp388/src/bmp388.c 
b/hw/drivers/sensors/bmp388/src/bmp388.c
index 412f6b9..b3b9aa7 100644
--- a/hw/drivers/sensors/bmp388/src/bmp388.c
+++ b/hw/drivers/sensors/bmp388/src/bmp388.c
@@ -3142,7 +3142,7 @@ bmp388_stream_read(struct sensor *sensor,
 /* FIFO object to be assigned to device structure */
 struct bmp3_fifo fifo;
 /* Pressure and temperature array of structures with maximum frame size */
-struct bmp3_data sensor_data[74];
+struct bmp3_data sensor_data[MYNEWT_VAL(BMP388_FIFO_CONVERTED_DATA_SIZE)];
 /* Loop Variable */
 uint8_t i;
 uint16_t frame_length;
@@ -3231,8 +3231,9 @@ bmp388_stream_read(struct sensor *sensor,
 #endif
 
 if (time_ms != 0) {
-if (time_ms > BMP388_MAX_STREAM_MS)
+if (time_ms > BMP388_MAX_STREAM_MS) {
 time_ms = BMP388_MAX_STREAM_MS;
+}
 rc = os_time_ms_to_ticks(time_ms, _ticks);
 if (rc) {
 goto err;
@@ -3366,6 +3367,246 @@ err:
 return rc;
 }
 
+int
+bmp388_hybrid_read(struct sensor *sensor,
+   sensor_type_t sensor_type,
+   sensor_data_func_t read_func,
+   void *read_arg,
+   uint32_t time_ms)
+{
+int rc;
+struct bmp388 *bmp388;
+struct bmp388_cfg *cfg;
+os_time_t time_ticks;
+os_time_t stop_ticks = 0;
+uint16_t try_count;
+
+#if MYNEWT_VAL(BMP388_FIFO_ENABLE)
+/* FIFO object to be assigned to device structure */
+struct bmp3_fifo fifo;
+/* Pressure and temperature array of structures with maximum frame size */
+struct bmp3_data sensor_data[MYNEWT_VAL(BMP388_FIFO_CONVERTED_DATA_SIZE)];
+/* Loop Variable */
+uint8_t i;
+uint16_t frame_length;
+/* Enable fifo */
+fifo.settings.mode = BMP3_ENABLE;
+/* Enable Pressure sensor for fifo */
+fifo.settings.press_en = BMP3_ENABLE;
+/* Enable temperature sensor for fifo */
+fifo.settings.temp_en = BMP3_ENABLE;
+/* Enable fifo time */
+fifo.settings.time_en = BMP3_ENABLE;
+/* No subsampling for FIFO */
+fifo.settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING;
+fifo.sensortime_updated = false;
+uint16_t current_fifo_len;
+#else
+struct bmp3_data sensor_data;
+#endif
+
+/* If the read isn't looking for pressure or temperature data, don't do 
anything. */
+if ((!(sensor_type & SENSOR_TYPE_PRESSURE)) &&
+(!(sensor_type & SENSOR_TYPE_TEMPERATURE))) {
+BMP388_LOG_ERROR("unsupported sensor type for bmp388\n");
+return SYS_EINVAL;
+}
+
+bmp388 = (struct bmp388 *)SENSOR_GET_DEVICE(sensor);
+
+cfg = >cfg;
+
+if (cfg->read_mode.mode != BMP388_READ_M_HYBRID) {
+BMP388_LOG_ERROR("*bmp388_hybrid_read mode is not hybrid\n");
+return SYS_EINVAL;
+}
+
+if (bmp388->bmp388_cfg_complete == false) {
+/* no interrupt feature */
+/* enable normal mode for fifo feature */
+rc = bmp388_set_normal_mode(bmp388);
+if (rc) {
+BMP388_LOG_ERROR("**bmp388_set_normal_mode failed %d\n", rc);
+goto error;
+}
+
+rc = bmp3_fifo_flush(>bmp3_dev); 
+if(rc) {
+BMP388_LOG_ERROR("fifo flush failed, error=0x%02x\n", rc);
+goto error;
+}
+
+rc = bmp388_set_fifo_cfg(bmp388, cfg->fifo_mode, cfg->fifo_threshold);
+  

[mynewt-core] branch master updated: BMP388 Pressure/temperature sensor i2c communtication optimization (#2376)

2020-09-20 Thread vipulrahane
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
 new a351a4d  BMP388 Pressure/temperature sensor i2c communtication 
optimization (#2376)
a351a4d is described below

commit a351a4dca423d6676e7b8c1e72db6fed87744bd9
Author: Philip Burkhardt <63323391+supervillain...@users.noreply.github.com>
AuthorDate: Sun Sep 20 12:24:52 2020 -0700

BMP388 Pressure/temperature sensor i2c communtication optimization (#2376)

* Add hybrid streaming mode that works without an interrupt pin
---
 hw/drivers/sensors/bmp388/include/bmp388/bmp388.h |   2 +
 hw/drivers/sensors/bmp388/src/bmp388.c| 249 +-
 hw/drivers/sensors/bmp388/syscfg.yml  |   5 +
 3 files changed, 253 insertions(+), 3 deletions(-)

diff --git a/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h 
b/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
index 41b8f94..30d09dc 100644
--- a/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
+++ b/hw/drivers/sensors/bmp388/include/bmp388/bmp388.h
@@ -381,6 +381,7 @@ enum bmp388_int_type {
 enum bmp388_read_mode {
 BMP388_READ_M_POLL = 0,
 BMP388_READ_M_STREAM = 1,
+BMP388_READ_M_HYBRID = 2,
 };
 
 /* Read mode configuration */
@@ -719,6 +720,7 @@ struct bmp388 {
 #endif
 /* Variable used to hold stats data */
 STATS_SECT_DECL(bmp388_stat_section) stats;
+bool bmp388_cfg_complete;
 };
 
 /**
diff --git a/hw/drivers/sensors/bmp388/src/bmp388.c 
b/hw/drivers/sensors/bmp388/src/bmp388.c
index 412f6b9..b3b9aa7 100644
--- a/hw/drivers/sensors/bmp388/src/bmp388.c
+++ b/hw/drivers/sensors/bmp388/src/bmp388.c
@@ -3142,7 +3142,7 @@ bmp388_stream_read(struct sensor *sensor,
 /* FIFO object to be assigned to device structure */
 struct bmp3_fifo fifo;
 /* Pressure and temperature array of structures with maximum frame size */
-struct bmp3_data sensor_data[74];
+struct bmp3_data sensor_data[MYNEWT_VAL(BMP388_FIFO_CONVERTED_DATA_SIZE)];
 /* Loop Variable */
 uint8_t i;
 uint16_t frame_length;
@@ -3231,8 +3231,9 @@ bmp388_stream_read(struct sensor *sensor,
 #endif
 
 if (time_ms != 0) {
-if (time_ms > BMP388_MAX_STREAM_MS)
+if (time_ms > BMP388_MAX_STREAM_MS) {
 time_ms = BMP388_MAX_STREAM_MS;
+}
 rc = os_time_ms_to_ticks(time_ms, _ticks);
 if (rc) {
 goto err;
@@ -3366,6 +3367,246 @@ err:
 return rc;
 }
 
+int
+bmp388_hybrid_read(struct sensor *sensor,
+   sensor_type_t sensor_type,
+   sensor_data_func_t read_func,
+   void *read_arg,
+   uint32_t time_ms)
+{
+int rc;
+struct bmp388 *bmp388;
+struct bmp388_cfg *cfg;
+os_time_t time_ticks;
+os_time_t stop_ticks = 0;
+uint16_t try_count;
+
+#if MYNEWT_VAL(BMP388_FIFO_ENABLE)
+/* FIFO object to be assigned to device structure */
+struct bmp3_fifo fifo;
+/* Pressure and temperature array of structures with maximum frame size */
+struct bmp3_data sensor_data[MYNEWT_VAL(BMP388_FIFO_CONVERTED_DATA_SIZE)];
+/* Loop Variable */
+uint8_t i;
+uint16_t frame_length;
+/* Enable fifo */
+fifo.settings.mode = BMP3_ENABLE;
+/* Enable Pressure sensor for fifo */
+fifo.settings.press_en = BMP3_ENABLE;
+/* Enable temperature sensor for fifo */
+fifo.settings.temp_en = BMP3_ENABLE;
+/* Enable fifo time */
+fifo.settings.time_en = BMP3_ENABLE;
+/* No subsampling for FIFO */
+fifo.settings.down_sampling = BMP3_FIFO_NO_SUBSAMPLING;
+fifo.sensortime_updated = false;
+uint16_t current_fifo_len;
+#else
+struct bmp3_data sensor_data;
+#endif
+
+/* If the read isn't looking for pressure or temperature data, don't do 
anything. */
+if ((!(sensor_type & SENSOR_TYPE_PRESSURE)) &&
+(!(sensor_type & SENSOR_TYPE_TEMPERATURE))) {
+BMP388_LOG_ERROR("unsupported sensor type for bmp388\n");
+return SYS_EINVAL;
+}
+
+bmp388 = (struct bmp388 *)SENSOR_GET_DEVICE(sensor);
+
+cfg = >cfg;
+
+if (cfg->read_mode.mode != BMP388_READ_M_HYBRID) {
+BMP388_LOG_ERROR("*bmp388_hybrid_read mode is not hybrid\n");
+return SYS_EINVAL;
+}
+
+if (bmp388->bmp388_cfg_complete == false) {
+/* no interrupt feature */
+/* enable normal mode for fifo feature */
+rc = bmp388_set_normal_mode(bmp388);
+if (rc) {
+BMP388_LOG_ERROR("**bmp388_set_normal_mode failed %d\n", rc);
+goto error;
+}
+
+rc = bmp3_fifo_flush(>bmp3_dev); 
+if(rc) {
+BMP388_LOG_ERROR("fifo flush failed, error=0x%02x\n", rc);
+goto error;
+}
+
+rc = bmp388_set_fifo_cfg(bmp388, cfg->fifo_mode, cfg->fifo_threshold);
+