]> git.itanic.dy.fi Git - BME280_driver/commitdiff
Updated interface design and examples.
authorBosch Sensortec <github@bosch-sensortec.com>
Mon, 6 Jul 2020 06:05:30 +0000 (08:05 +0200)
committerKevin Goveas <kevin.goveas@bosch-sensortec.com>
Mon, 6 Jul 2020 06:08:21 +0000 (08:08 +0200)
LICENSE
README.md
bme280.c
bme280.h
bme280_defs.h
examples/bsd_userspace.c
examples/linux_userspace.c

diff --git a/LICENSE b/LICENSE
index df241f2528a30f3312f22229cbc07830cf05dcff..315dfa23097dbf96367cd4033ac557698844b1f0 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -6,15 +6,15 @@ Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
 1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
+    notice, this list of conditions and the following disclaimer.
 
 2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
 
 3. Neither the name of the copyright holder nor the names of its
-   contributors may be used to endorse or promote products derived from
-   this software without specific prior written permission.
+    contributors may be used to endorse or promote products derived from
+    this software without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
index 312aeff761f93a477bd8b3edcd9a26d5cae409d8..0a0e398033830301c2b7bc5d4601e98bc32ac522 100644 (file)
--- a/README.md
+++ b/README.md
@@ -34,7 +34,9 @@ struct bme280_dev dev;
 int8_t rslt = BME280_OK;\r
 \r
 /* Sensor_0 interface over SPI with native chip select line */\r
-dev.dev_id = 0;\r
+uint8_t dev_addr = 0;\r
+\r
+dev.intf_ptr = &dev_addr;\r
 dev.intf = BME280_SPI_INTF;\r
 dev.read = user_spi_read;\r
 dev.write = user_spi_write;\r
@@ -46,8 +48,9 @@ rslt = bme280_init(&dev);
 ``` c\r
 struct bme280_dev dev;\r
 int8_t rslt = BME280_OK;\r
+uint8_t dev_addr = BME280_I2C_ADDR_PRIM;\r
 \r
-dev.dev_id = BME280_I2C_ADDR_PRIM;\r
+dev.intf_ptr = &dev_addr;\r
 dev.intf = BME280_I2C_INTF;\r
 dev.read = user_i2c_read;\r
 dev.write = user_i2c_write;\r
@@ -119,7 +122,7 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
     while (1) {\r
         rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev);\r
         /* Wait for the measurement to complete and print data @25Hz */\r
-        dev->delay_ms(req_delay);\r
+        dev->delay_ms(req_delay, dev->intf_ptr);\r
         rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);\r
         print_sensor_data(&comp_data);\r
     }\r
@@ -161,7 +164,7 @@ int8_t stream_sensor_data_normal_mode(struct bme280_dev *dev)
        printf("Temperature, Pressure, Humidity\r\n");\r
        while (1) {\r
                /* Delay while the sensor completes a measurement */\r
-               dev->delay_ms(70);\r
+               dev->delay_ms(70, dev->intf_ptr);\r
                rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);\r
                print_sensor_data(&comp_data);\r
        }\r
@@ -182,7 +185,7 @@ void print_sensor_data(struct bme280_data *comp_data)
 ### Templates for function pointers\r
 ``` c\r
 \r
-void user_delay_ms(uint32_t period)\r
+void user_delay_ms(uint32_t period, void *intf_ptr)\r
 {\r
     /*\r
      * Return control or wait,\r
@@ -190,12 +193,12 @@ void user_delay_ms(uint32_t period)
      */\r
 }\r
 \r
-int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)\r
+int8_t user_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)\r
 {\r
     int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */\r
 \r
     /*\r
-     * The parameter dev_id can be used as a variable to select which Chip Select pin has\r
+     * The parameter intf_ptr can be used as a variable to select which Chip Select pin has\r
      * to be set low to activate the relevant device on the SPI bus\r
      */\r
 \r
@@ -216,12 +219,12 @@ int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16
     return rslt;\r
 }\r
 \r
-int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)\r
+int8_t user_spi_write(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)\r
 {\r
     int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */\r
 \r
     /*\r
-     * The parameter dev_id can be used as a variable to select which Chip Select pin has\r
+     * The parameter intf_ptr can be used as a variable to select which Chip Select pin has\r
      * to be set low to activate the relevant device on the SPI bus\r
      */\r
 \r
@@ -242,12 +245,12 @@ int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint1
     return rslt;\r
 }\r
 \r
-int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)\r
+int8_t user_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)\r
 {\r
     int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */\r
 \r
     /*\r
-     * The parameter dev_id can be used as a variable to store the I2C address of the device\r
+     * The parameter intf_ptr can be used as a variable to store the I2C address of the device\r
      */\r
 \r
     /*\r
@@ -269,12 +272,12 @@ int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16
     return rslt;\r
 }\r
 \r
-int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)\r
+int8_t user_i2c_write(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)\r
 {\r
     int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */\r
 \r
     /*\r
-     * The parameter dev_id can be used as a variable to store the I2C address of the device\r
+     * The parameter intf_ptr can be used as a variable to store the I2C address of the device\r
      */\r
 \r
     /*\r
index c3eabb58f7ce7412b924144775c9550e44b131d6..cabefc20e34c6dbce2298c553a52f1b76690ad34 100644 (file)
--- a/bme280.c
+++ b/bme280.c
@@ -30,9 +30,9 @@
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
 * POSSIBILITY OF SUCH DAMAGE.\r
 *\r
-* @file        bme280.c\r
-* @date        2020-01-24\r
-* @version     v3.4.3\r
+* @file       bme280.c\r
+* @date       2020-03-28\r
+* @version    v3.5.0\r
 *\r
 */\r
 \r
 \r
 /**\name Internal macros */\r
 /* To identify osr settings selected by user */\r
-#define OVERSAMPLING_SETTINGS   UINT8_C(0x07)\r
+#define OVERSAMPLING_SETTINGS    UINT8_C(0x07)\r
 \r
 /* To identify filter and standby settings selected by user */\r
-#define FILTER_STANDBY_SETTINGS UINT8_C(0x18)\r
+#define FILTER_STANDBY_SETTINGS  UINT8_C(0x18)\r
 \r
 /*!\r
  * @brief This internal API puts the device to sleep mode.\r
  * @param[in] dev : Structure instance of bme280_dev.\r
  *\r
  * @return Result of API execution status.\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
-static int8_t put_device_to_sleep(const struct bme280_dev *dev);\r
+static int8_t put_device_to_sleep(struct bme280_dev *dev);\r
 \r
 /*!\r
  * @brief This internal API writes the power mode in the sensor.\r
  *\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] dev         : Structure instance of bme280_dev.\r
  * @param[in] sensor_mode : Variable which contains the power mode to be set.\r
  *\r
  * @return Result of API execution status.\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
-static int8_t write_power_mode(uint8_t sensor_mode, const struct bme280_dev *dev);\r
+static int8_t write_power_mode(uint8_t sensor_mode, struct bme280_dev *dev);\r
 \r
 /*!\r
  * @brief This internal API is used to validate the device pointer for\r
@@ -76,7 +84,11 @@ static int8_t write_power_mode(uint8_t sensor_mode, const struct bme280_dev *dev
  * @param[in] dev : Structure instance of bme280_dev.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
 static int8_t null_ptr_check(const struct bme280_dev *dev);\r
 \r
@@ -84,12 +96,13 @@ static int8_t null_ptr_check(const struct bme280_dev *dev);
  * @brief This internal API interleaves the register address between the\r
  * register data buffer for burst write operation.\r
  *\r
- * @param[in] reg_addr : Contains the register address array.\r
+ * @param[in] reg_addr   : Contains the register address array.\r
  * @param[out] temp_buff : Contains the temporary buffer to store the\r
  * register data and register address.\r
- * @param[in] reg_data : Contains the register data to be written in the\r
+ * @param[in] reg_data   : Contains the register data to be written in the\r
  * temporary buffer.\r
- * @param[in] len : No of bytes of data to be written for burst write.\r
+ * @param[in] len        : No of bytes of data to be written for burst write.\r
+ *\r
  */\r
 static void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, const uint8_t *reg_data, uint8_t len);\r
 \r
@@ -100,7 +113,11 @@ static void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, con
  * @param[in] dev : Structure instance of bme280_dev.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
 static int8_t get_calib_data(struct bme280_dev *dev);\r
 \r
@@ -108,8 +125,9 @@ static int8_t get_calib_data(struct bme280_dev *dev);
  *  @brief This internal API is used to parse the temperature and\r
  *  pressure calibration data and store it in the device structure.\r
  *\r
- *  @param[out] dev : Structure instance of bme280_dev to store the calib data.\r
+ *  @param[out] dev     : Structure instance of bme280_dev to store the calib data.\r
  *  @param[in] reg_data : Contains the calibration data to be parsed.\r
+ *\r
  */\r
 static void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);\r
 \r
@@ -117,8 +135,9 @@ static void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_d
  *  @brief This internal API is used to parse the humidity calibration data\r
  *  and store it in device structure.\r
  *\r
- *  @param[out] dev : Structure instance of bme280_dev to store the calib data.\r
+ *  @param[out] dev     : Structure instance of bme280_dev to store the calib data.\r
  *  @param[in] reg_data : Contains calibration data to be parsed.\r
+ *\r
  */\r
 static void parse_humidity_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);\r
 \r
@@ -129,10 +148,10 @@ static void parse_humidity_calib_data(const uint8_t *reg_data, struct bme280_dev
  * return the compensated pressure data in double data type.\r
  *\r
  * @param[in] uncomp_data : Contains the uncompensated pressure data.\r
- * @param[in] calib_data : Pointer to the calibration data structure.\r
+ * @param[in] calib_data  : Pointer to the calibration data structure.\r
+ *\r
+ * @return Compensated pressure data in double.\r
  *\r
- * @return Compensated pressure data.\r
- * @retval Compensated pressure data in double.\r
  */\r
 static double compensate_pressure(const struct bme280_uncomp_data *uncomp_data,\r
                                   const struct bme280_calib_data *calib_data);\r
@@ -142,10 +161,10 @@ static double compensate_pressure(const struct bme280_uncomp_data *uncomp_data,
  * return the compensated humidity data in double data type.\r
  *\r
  * @param[in] uncomp_data : Contains the uncompensated humidity data.\r
- * @param[in] calib_data : Pointer to the calibration data structure.\r
+ * @param[in] calib_data  : Pointer to the calibration data structure.\r
+ *\r
+ * @return Compensated humidity data in double.\r
  *\r
- * @return Compensated humidity data.\r
- * @retval Compensated humidity data in double.\r
  */\r
 static double compensate_humidity(const struct bme280_uncomp_data *uncomp_data,\r
                                   const struct bme280_calib_data *calib_data);\r
@@ -155,10 +174,10 @@ static double compensate_humidity(const struct bme280_uncomp_data *uncomp_data,
  * return the compensated temperature data in double data type.\r
  *\r
  * @param[in] uncomp_data : Contains the uncompensated temperature data.\r
- * @param[in] calib_data : Pointer to calibration data structure.\r
+ * @param[in] calib_data  : Pointer to calibration data structure.\r
+ *\r
+ * @return Compensated temperature data in double.\r
  *\r
- * @return Compensated temperature data.\r
- * @retval Compensated temperature data in double.\r
  */\r
 static double compensate_temperature(const struct bme280_uncomp_data *uncomp_data,\r
                                      struct bme280_calib_data *calib_data);\r
@@ -170,10 +189,10 @@ static double compensate_temperature(const struct bme280_uncomp_data *uncomp_dat
  * return the compensated temperature data in integer data type.\r
  *\r
  * @param[in] uncomp_data : Contains the uncompensated temperature data.\r
- * @param[in] calib_data : Pointer to calibration data structure.\r
+ * @param[in] calib_data  : Pointer to calibration data structure.\r
+ *\r
+ * @return Compensated temperature data in integer.\r
  *\r
- * @return Compensated temperature data.\r
- * @retval Compensated temperature data in integer.\r
  */\r
 static int32_t compensate_temperature(const struct bme280_uncomp_data *uncomp_data,\r
                                       struct bme280_calib_data *calib_data);\r
@@ -183,10 +202,10 @@ static int32_t compensate_temperature(const struct bme280_uncomp_data *uncomp_da
  * return the compensated pressure data in integer data type.\r
  *\r
  * @param[in] uncomp_data : Contains the uncompensated pressure data.\r
- * @param[in] calib_data : Pointer to the calibration data structure.\r
+ * @param[in] calib_data  : Pointer to the calibration data structure.\r
+ *\r
+ * @return Compensated pressure data in integer.\r
  *\r
- * @return Compensated pressure data.\r
- * @retval Compensated pressure data in integer.\r
  */\r
 static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data,\r
                                     const struct bme280_calib_data *calib_data);\r
@@ -196,10 +215,10 @@ static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data
  * return the compensated humidity data in integer data type.\r
  *\r
  * @param[in] uncomp_data : Contains the uncompensated humidity data.\r
- * @param[in] calib_data : Pointer to the calibration data structure.\r
+ * @param[in] calib_data  : Pointer to the calibration data structure.\r
+ *\r
+ * @return Compensated humidity data in integer.\r
  *\r
- * @return Compensated humidity data.\r
- * @retval Compensated humidity data in integer.\r
  */\r
 static uint32_t compensate_humidity(const struct bme280_uncomp_data *uncomp_data,\r
                                     const struct bme280_calib_data *calib_data);\r
@@ -210,26 +229,33 @@ static uint32_t compensate_humidity(const struct bme280_uncomp_data *uncomp_data
  * @brief This internal API is used to identify the settings which the user\r
  * wants to modify in the sensor.\r
  *\r
- * @param[in] sub_settings : Contains the settings subset to identify particular\r
+ * @param[in] sub_settings     : Contains the settings subset to identify particular\r
  * group of settings which the user is interested to change.\r
  * @param[in] desired_settings : Contains the user specified settings.\r
  *\r
  * @return Indicates whether user is interested to modify the settings which\r
  * are related to sub_settings.\r
- * @retval True -> User wants to modify this group of settings\r
- * @retval False -> User does not want to modify this group of settings\r
+ * @return True -> User wants to modify this group of settings\r
+ * @return False -> User does not want to modify this group of settings\r
+ *\r
  */\r
 static uint8_t are_settings_changed(uint8_t sub_settings, uint8_t desired_settings);\r
 \r
 /*!\r
- * @brief This API sets the humidity oversampling settings of the sensor.\r
+ * @brief This API sets the humidity over sampling settings of the sensor.\r
  *\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] dev      : Structure instance of bme280_dev.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
-static int8_t set_osr_humidity_settings(const struct bme280_settings *settings, const struct bme280_dev *dev);\r
+static int8_t set_osr_humidity_settings(const struct bme280_settings *settings, struct bme280_dev *dev);\r
 \r
 /*!\r
  * @brief This internal API sets the oversampling settings for pressure,\r
@@ -237,14 +263,19 @@ static int8_t set_osr_humidity_settings(const struct bme280_settings *settings,
  *\r
  * @param[in] desired_settings : Variable used to select the settings which\r
  * are to be set.\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] settings         : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
+ * @param[in] dev              : Structure instance of bme280_dev.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
-static int8_t set_osr_settings(uint8_t desired_settings,\r
-                               const struct bme280_settings *settings,\r
-                               const struct bme280_dev *dev);\r
+static int8_t set_osr_settings(uint8_t desired_settings, const struct bme280_settings *settings,\r
+                               struct bme280_dev *dev);\r
 \r
 /*!\r
  * @brief This API sets the pressure and/or temperature oversampling settings\r
@@ -253,21 +284,29 @@ static int8_t set_osr_settings(uint8_t desired_settings,
  * @param[in] dev : Structure instance of bme280_dev.\r
  * @param[in] desired_settings: variable to select the pressure and/or\r
  * temperature oversampling settings.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
 static int8_t set_osr_press_temp_settings(uint8_t desired_settings,\r
                                           const struct bme280_settings *settings,\r
-                                          const struct bme280_dev *dev);\r
+                                          struct bme280_dev *dev);\r
 \r
 /*!\r
  * @brief This internal API fills the pressure oversampling settings provided by\r
  * the user in the data buffer so as to write in the sensor.\r
  *\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
  * @param[out] reg_data : Variable which is filled according to the pressure\r
  * oversampling data provided by the user.\r
+ *\r
  */\r
 static void fill_osr_press_settings(uint8_t *reg_data, const struct bme280_settings *settings);\r
 \r
@@ -275,9 +314,11 @@ static void fill_osr_press_settings(uint8_t *reg_data, const struct bme280_setti
  * @brief This internal API fills the temperature oversampling settings provided\r
  * by the user in the data buffer so as to write in the sensor.\r
  *\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
  * @param[out] reg_data : Variable which is filled according to the temperature\r
  * oversampling data provided by the user.\r
+ *\r
  */\r
 static void fill_osr_temp_settings(uint8_t *reg_data, const struct bme280_settings *settings);\r
 \r
@@ -286,23 +327,30 @@ static void fill_osr_temp_settings(uint8_t *reg_data, const struct bme280_settin
  * in the sensor according to the settings selected by the user.\r
  *\r
  * @param[in] dev : Structure instance of bme280_dev.\r
- * @param[in] desired_settings : variable to select the filter and/or\r
- * standby duration settings.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
+ * @param[in] settings : Structure instance of bme280_settings.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
 static int8_t set_filter_standby_settings(uint8_t desired_settings,\r
                                           const struct bme280_settings *settings,\r
-                                          const struct bme280_dev *dev);\r
+                                          struct bme280_dev *dev);\r
 \r
 /*!\r
  * @brief This internal API fills the filter settings provided by the user\r
  * in the data buffer so as to write in the sensor.\r
  *\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
  * @param[out] reg_data : Variable which is filled according to the filter\r
  * settings data provided by the user.\r
+ *\r
  */\r
 static void fill_filter_settings(uint8_t *reg_data, const struct bme280_settings *settings);\r
 \r
@@ -310,9 +358,11 @@ static void fill_filter_settings(uint8_t *reg_data, const struct bme280_settings
  * @brief This internal API fills the standby duration settings provided by the\r
  * user in the data buffer so as to write in the sensor.\r
  *\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be set in the sensor.\r
  * @param[out] reg_data : Variable which is filled according to the standby\r
  * settings data provided by the user.\r
+ *\r
  */\r
 static void fill_standby_settings(uint8_t *reg_data, const struct bme280_settings *settings);\r
 \r
@@ -321,8 +371,10 @@ static void fill_standby_settings(uint8_t *reg_data, const struct bme280_setting
  * and humidity), filter and standby duration settings and store in the\r
  * device structure.\r
  *\r
- * @param[out] dev : Structure instance of bme280_dev.\r
+ * @param[in] settings : Pointer variable which contains the settings to\r
+ * be get in the sensor.\r
  * @param[in] reg_data : Register data to be parsed.\r
+ *\r
  */\r
 static void parse_device_settings(const uint8_t *reg_data, struct bme280_settings *settings);\r
 \r
@@ -335,9 +387,13 @@ static void parse_device_settings(const uint8_t *reg_data, struct bme280_setting
  * be set in the sensor.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
-static int8_t reload_device_settings(const struct bme280_settings *settings, const struct bme280_dev *dev);\r
+static int8_t reload_device_settings(const struct bme280_settings *settings, struct bme280_dev *dev);\r
 \r
 /****************** Global Function Definitions *******************************/\r
 \r
@@ -371,16 +427,18 @@ int8_t bme280_init(struct bme280_dev *dev)
 \r
                 /* Reset the sensor */\r
                 rslt = bme280_soft_reset(dev);\r
+\r
                 if (rslt == BME280_OK)\r
                 {\r
                     /* Read the calibration data */\r
                     rslt = get_calib_data(dev);\r
                 }\r
+\r
                 break;\r
             }\r
 \r
             /* Wait for 1 ms */\r
-            dev->delay_ms(1);\r
+            dev->delay_us(1000, dev->intf_ptr);\r
             --try_count;\r
         }\r
 \r
@@ -397,7 +455,7 @@ int8_t bme280_init(struct bme280_dev *dev)
 /*!\r
  * @brief This API reads the data from the given register address of the sensor.\r
  */\r
-int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bme280_dev *dev)\r
+int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
 \r
@@ -405,7 +463,7 @@ int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const
     rslt = null_ptr_check(dev);\r
 \r
     /* Proceed if null check is fine */\r
-    if (rslt == BME280_OK)\r
+    if ((rslt == BME280_OK) && (reg_data != NULL))\r
     {\r
         /* If interface selected is SPI */\r
         if (dev->intf != BME280_I2C_INTF)\r
@@ -414,14 +472,18 @@ int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const
         }\r
 \r
         /* Read the data  */\r
-        rslt = dev->read(dev->dev_id, reg_addr, reg_data, len);\r
+        dev->intf_rslt = dev->read(reg_addr, reg_data, len, dev->intf_ptr);\r
 \r
         /* Check for communication error */\r
-        if (rslt != BME280_OK)\r
+        if (dev->intf_rslt != BME280_INTF_RET_SUCCESS)\r
         {\r
             rslt = BME280_E_COMM_FAIL;\r
         }\r
     }\r
+    else\r
+    {\r
+        rslt = BME280_E_NULL_PTR;\r
+    }\r
 \r
     return rslt;\r
 }\r
@@ -430,7 +492,7 @@ int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const
  * @brief This API writes the given data to the register address\r
  * of the sensor.\r
  */\r
-int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, const struct bme280_dev *dev)\r
+int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t temp_buff[20]; /* Typically not to write more than 10 registers */\r
@@ -439,6 +501,7 @@ int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len,
     {\r
         len = 10;\r
     }\r
+\r
     uint16_t temp_len;\r
     uint8_t reg_addr_cnt;\r
 \r
@@ -474,10 +537,11 @@ int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len,
             {\r
                 temp_len = len;\r
             }\r
-            rslt = dev->write(dev->dev_id, reg_addr[0], temp_buff, temp_len);\r
+\r
+            dev->intf_rslt = dev->write(reg_addr[0], temp_buff, temp_len, dev->intf_ptr);\r
 \r
             /* Check for communication error */\r
-            if (rslt != BME280_OK)\r
+            if (dev->intf_rslt != BME280_INTF_RET_SUCCESS)\r
             {\r
                 rslt = BME280_E_COMM_FAIL;\r
             }\r
@@ -499,7 +563,7 @@ int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len,
  * @brief This API sets the oversampling, filter and standby duration\r
  * (normal mode) settings in the sensor.\r
  */\r
-int8_t bme280_set_sensor_settings(uint8_t desired_settings, const struct bme280_dev *dev)\r
+int8_t bme280_set_sensor_settings(uint8_t desired_settings, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t sensor_mode;\r
@@ -511,10 +575,12 @@ int8_t bme280_set_sensor_settings(uint8_t desired_settings, const struct bme280_
     if (rslt == BME280_OK)\r
     {\r
         rslt = bme280_get_sensor_mode(&sensor_mode, dev);\r
+\r
         if ((rslt == BME280_OK) && (sensor_mode != BME280_SLEEP_MODE))\r
         {\r
             rslt = put_device_to_sleep(dev);\r
         }\r
+\r
         if (rslt == BME280_OK)\r
         {\r
             /* Check if user wants to change oversampling\r
@@ -554,6 +620,7 @@ int8_t bme280_get_sensor_settings(struct bme280_dev *dev)
     if (rslt == BME280_OK)\r
     {\r
         rslt = bme280_get_regs(BME280_CTRL_HUM_ADDR, reg_data, 4, dev);\r
+\r
         if (rslt == BME280_OK)\r
         {\r
             parse_device_settings(reg_data, &dev->settings);\r
@@ -566,13 +633,14 @@ int8_t bme280_get_sensor_settings(struct bme280_dev *dev)
 /*!\r
  * @brief This API sets the power mode of the sensor.\r
  */\r
-int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev)\r
+int8_t bme280_set_sensor_mode(uint8_t sensor_mode, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t last_set_mode;\r
 \r
     /* Check for null pointer in the device structure*/\r
     rslt = null_ptr_check(dev);\r
+\r
     if (rslt == BME280_OK)\r
     {\r
         rslt = bme280_get_sensor_mode(&last_set_mode, dev);\r
@@ -598,13 +666,14 @@ int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev)
 /*!\r
  * @brief This API gets the power mode of the sensor.\r
  */\r
-int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev)\r
+int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
 \r
     /* Check for null pointer in the device structure*/\r
     rslt = null_ptr_check(dev);\r
-    if (rslt == BME280_OK)\r
+\r
+    if ((rslt == BME280_OK) && (sensor_mode != NULL))\r
     {\r
         /* Read the power mode register */\r
         rslt = bme280_get_regs(BME280_PWR_CTRL_ADDR, sensor_mode, 1, dev);\r
@@ -612,6 +681,10 @@ int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev
         /* Assign the power mode in the device structure */\r
         *sensor_mode = BME280_GET_BITS_POS_0(*sensor_mode, BME280_SENSOR_MODE);\r
     }\r
+    else\r
+    {\r
+        rslt = BME280_E_NULL_PTR;\r
+    }\r
 \r
     return rslt;\r
 }\r
@@ -619,7 +692,7 @@ int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev
 /*!\r
  * @brief This API performs the soft reset of the sensor.\r
  */\r
-int8_t bme280_soft_reset(const struct bme280_dev *dev)\r
+int8_t bme280_soft_reset(struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t reg_addr = BME280_RESET_ADDR;\r
@@ -644,15 +717,15 @@ int8_t bme280_soft_reset(const struct bme280_dev *dev)
             do\r
             {\r
                 /* As per data sheet - Table 1, startup time is 2 ms. */\r
-                dev->delay_ms(2);\r
+                dev->delay_us(2000, dev->intf_ptr);\r
                 rslt = bme280_get_regs(BME280_STATUS_REG_ADDR, &status_reg, 1, dev);\r
+\r
             } while ((rslt == BME280_OK) && (try_run--) && (status_reg & BME280_STATUS_IM_UPDATE));\r
 \r
             if (status_reg & BME280_STATUS_IM_UPDATE)\r
             {\r
                 rslt = BME280_E_NVM_COPY_FAILED;\r
             }\r
-\r
         }\r
     }\r
 \r
@@ -676,10 +749,12 @@ int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data
 \r
     /* Check for null pointer in the device structure*/\r
     rslt = null_ptr_check(dev);\r
+\r
     if ((rslt == BME280_OK) && (comp_data != NULL))\r
     {\r
         /* Read the pressure and temperature data from the sensor */\r
         rslt = bme280_get_regs(BME280_DATA_ADDR, reg_data, BME280_P_T_H_DATA_LEN, dev);\r
+\r
         if (rslt == BME280_OK)\r
         {\r
             /* Parse the read data from the sensor */\r
@@ -753,11 +828,13 @@ int8_t bme280_compensate_data(uint8_t sensor_comp,
             /* Compensate the temperature data */\r
             comp_data->temperature = compensate_temperature(uncomp_data, calib_data);\r
         }\r
+\r
         if (sensor_comp & BME280_PRESS)\r
         {\r
             /* Compensate the pressure data */\r
             comp_data->pressure = compensate_pressure(uncomp_data, calib_data);\r
         }\r
+\r
         if (sensor_comp & BME280_HUM)\r
         {\r
             /* Compensate the humidity data */\r
@@ -826,9 +903,7 @@ uint32_t bme280_cal_meas_delay(const struct bme280_settings *settings)
  * @brief This internal API sets the oversampling settings for pressure,\r
  * temperature and humidity in the sensor.\r
  */\r
-static int8_t set_osr_settings(uint8_t desired_settings,\r
-                               const struct bme280_settings *settings,\r
-                               const struct bme280_dev *dev)\r
+static int8_t set_osr_settings(uint8_t desired_settings, const struct bme280_settings *settings, struct bme280_dev *dev)\r
 {\r
     int8_t rslt = BME280_W_INVALID_OSR_MACRO;\r
 \r
@@ -836,6 +911,7 @@ static int8_t set_osr_settings(uint8_t desired_settings,
     {\r
         rslt = set_osr_humidity_settings(settings, dev);\r
     }\r
+\r
     if (desired_settings & (BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL))\r
     {\r
         rslt = set_osr_press_temp_settings(desired_settings, settings, dev);\r
@@ -847,7 +923,7 @@ static int8_t set_osr_settings(uint8_t desired_settings,
 /*!\r
  * @brief This API sets the humidity oversampling settings of the sensor.\r
  */\r
-static int8_t set_osr_humidity_settings(const struct bme280_settings *settings, const struct bme280_dev *dev)\r
+static int8_t set_osr_humidity_settings(const struct bme280_settings *settings, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t ctrl_hum;\r
@@ -866,6 +942,7 @@ static int8_t set_osr_humidity_settings(const struct bme280_settings *settings,
     {\r
         reg_addr = BME280_CTRL_MEAS_ADDR;\r
         rslt = bme280_get_regs(reg_addr, &ctrl_meas, 1, dev);\r
+\r
         if (rslt == BME280_OK)\r
         {\r
             rslt = bme280_set_regs(&reg_addr, &ctrl_meas, 1, dev);\r
@@ -881,19 +958,21 @@ static int8_t set_osr_humidity_settings(const struct bme280_settings *settings,
  */\r
 static int8_t set_osr_press_temp_settings(uint8_t desired_settings,\r
                                           const struct bme280_settings *settings,\r
-                                          const struct bme280_dev *dev)\r
+                                          struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t reg_addr = BME280_CTRL_MEAS_ADDR;\r
     uint8_t reg_data;\r
 \r
     rslt = bme280_get_regs(reg_addr, &reg_data, 1, dev);\r
+\r
     if (rslt == BME280_OK)\r
     {\r
         if (desired_settings & BME280_OSR_PRESS_SEL)\r
         {\r
             fill_osr_press_settings(&reg_data, settings);\r
         }\r
+\r
         if (desired_settings & BME280_OSR_TEMP_SEL)\r
         {\r
             fill_osr_temp_settings(&reg_data, settings);\r
@@ -912,19 +991,21 @@ static int8_t set_osr_press_temp_settings(uint8_t desired_settings,
  */\r
 static int8_t set_filter_standby_settings(uint8_t desired_settings,\r
                                           const struct bme280_settings *settings,\r
-                                          const struct bme280_dev *dev)\r
+                                          struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t reg_addr = BME280_CONFIG_ADDR;\r
     uint8_t reg_data;\r
 \r
     rslt = bme280_get_regs(reg_addr, &reg_data, 1, dev);\r
+\r
     if (rslt == BME280_OK)\r
     {\r
         if (desired_settings & BME280_FILTER_SEL)\r
         {\r
             fill_filter_settings(&reg_data, settings);\r
         }\r
+\r
         if (desired_settings & BME280_STANDBY_SEL)\r
         {\r
             fill_standby_settings(&reg_data, settings);\r
@@ -990,7 +1071,7 @@ static void parse_device_settings(const uint8_t *reg_data, struct bme280_setting
 /*!\r
  * @brief This internal API writes the power mode in the sensor.\r
  */\r
-static int8_t write_power_mode(uint8_t sensor_mode, const struct bme280_dev *dev)\r
+static int8_t write_power_mode(uint8_t sensor_mode, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t reg_addr = BME280_PWR_CTRL_ADDR;\r
@@ -1016,17 +1097,19 @@ static int8_t write_power_mode(uint8_t sensor_mode, const struct bme280_dev *dev
 /*!\r
  * @brief This internal API puts the device to sleep mode.\r
  */\r
-static int8_t put_device_to_sleep(const struct bme280_dev *dev)\r
+static int8_t put_device_to_sleep(struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
     uint8_t reg_data[4];\r
     struct bme280_settings settings;\r
 \r
     rslt = bme280_get_regs(BME280_CTRL_HUM_ADDR, reg_data, 4, dev);\r
+\r
     if (rslt == BME280_OK)\r
     {\r
         parse_device_settings(reg_data, &settings);\r
         rslt = bme280_soft_reset(dev);\r
+\r
         if (rslt == BME280_OK)\r
         {\r
             rslt = reload_device_settings(&settings, dev);\r
@@ -1040,11 +1123,12 @@ static int8_t put_device_to_sleep(const struct bme280_dev *dev)
  * @brief This internal API reloads the already existing device settings in\r
  * the sensor after soft reset.\r
  */\r
-static int8_t reload_device_settings(const struct bme280_settings *settings, const struct bme280_dev *dev)\r
+static int8_t reload_device_settings(const struct bme280_settings *settings, struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
 \r
     rslt = set_osr_settings(BME280_ALL_SETTINGS_SEL, settings, dev);\r
+\r
     if (rslt == BME280_OK)\r
     {\r
         rslt = set_filter_standby_settings(BME280_ALL_SETTINGS_SEL, settings, dev);\r
@@ -1073,6 +1157,7 @@ static double compensate_temperature(const struct bme280_uncomp_data *uncomp_dat
     var2 = (var2 * var2) * ((double)calib_data->dig_t3);\r
     calib_data->t_fine = (int32_t)(var1 + var2);\r
     temperature = (var1 + var2) / 5120.0;\r
+\r
     if (temperature < temperature_min)\r
     {\r
         temperature = temperature_min;\r
@@ -1115,6 +1200,7 @@ static double compensate_pressure(const struct bme280_uncomp_data *uncomp_data,
         var1 = ((double)calib_data->dig_p9) * pressure * pressure / 2147483648.0;\r
         var2 = pressure * ((double)calib_data->dig_p8) / 32768.0;\r
         pressure = pressure + (var1 + var2 + ((double)calib_data->dig_p7)) / 16.0;\r
+\r
         if (pressure < pressure_min)\r
         {\r
             pressure = pressure_min;\r
@@ -1238,6 +1324,7 @@ static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data
         var2 = (((int64_t)calib_data->dig_p8) * var4) / 524288;\r
         var4 = ((var4 + var1 + var2) / 256) + (((int64_t)calib_data->dig_p7) * 16);\r
         pressure = (uint32_t)(((var4 / 2) * 100) / 128);\r
+\r
         if (pressure < pressure_min)\r
         {\r
             pressure = pressure_min;\r
@@ -1286,6 +1373,7 @@ static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data
     {\r
         var5 = (uint32_t)((uint32_t)1048576) - uncomp_data->pressure;\r
         pressure = ((uint32_t)(var5 - (uint32_t)(var2 / 4096))) * 3125;\r
+\r
         if (pressure < 0x80000000)\r
         {\r
             pressure = (pressure << 1) / ((uint32_t)var1);\r
@@ -1294,9 +1382,11 @@ static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data
         {\r
             pressure = (pressure / (uint32_t)var1) * 2;\r
         }\r
+\r
         var1 = (((int32_t)calib_data->dig_p9) * ((int32_t)(((pressure / 8) * (pressure / 8)) / 8192))) / 4096;\r
         var2 = (((int32_t)(pressure / 4)) * ((int32_t)calib_data->dig_p8)) / 8192;\r
         pressure = (uint32_t)((int32_t)pressure + ((var1 + var2 + calib_data->dig_p7) / 16));\r
+\r
         if (pressure < pressure_min)\r
         {\r
             pressure = pressure_min;\r
@@ -1345,6 +1435,7 @@ static uint32_t compensate_humidity(const struct bme280_uncomp_data *uncomp_data
     var5 = (var5 < 0 ? 0 : var5);\r
     var5 = (var5 > 419430400 ? 419430400 : var5);\r
     humidity = (uint32_t)(var5 / 4096);\r
+\r
     if (humidity > humidity_max)\r
     {\r
         humidity = humidity_max;\r
@@ -1368,6 +1459,7 @@ static int8_t get_calib_data(struct bme280_dev *dev)
 \r
     /* Read the calibration data from the sensor */\r
     rslt = bme280_get_regs(reg_addr, calib_data, BME280_TEMP_PRESS_CALIB_DATA_LEN, dev);\r
+\r
     if (rslt == BME280_OK)\r
     {\r
         /* Parse temperature and pressure calibration data and store\r
@@ -1378,6 +1470,7 @@ static int8_t get_calib_data(struct bme280_dev *dev)
 \r
         /* Read the humidity calibration data from the sensor */\r
         rslt = bme280_get_regs(reg_addr, calib_data, BME280_HUMIDITY_CALIB_DATA_LEN, dev);\r
+\r
         if (rslt == BME280_OK)\r
         {\r
             /* Parse humidity calibration data and store it in\r
@@ -1481,7 +1574,7 @@ static int8_t null_ptr_check(const struct bme280_dev *dev)
 {\r
     int8_t rslt;\r
 \r
-    if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_ms == NULL))\r
+    if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL))\r
     {\r
         /* Device structure pointer is not valid */\r
         rslt = BME280_E_NULL_PTR;\r
index 9f9f5afcdb9054fa020fb9a13907dac2ced4a563..fd9599003177699ebe14b99fbef2e8d7a7c5d336 100644 (file)
--- a/bme280.h
+++ b/bme280.h
@@ -30,9 +30,9 @@
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
 * POSSIBILITY OF SUCH DAMAGE.\r
 *\r
-* @file        bme280.h\r
-* @date        2020-01-24\r
-* @version     v3.4.3\r
+* @file       bme280.h\r
+* @date       2020-03-28\r
+* @version    v3.5.0\r
 *\r
 */\r
 \r
  */\r
 \r
 /*!\r
- * @defgroup BME280 SENSOR API\r
+ * @defgroup bme280 BME280\r
+ * @brief <a href="https://www.bosch-sensortec.com/bst/products/all_products/bme280">Product Overview</a>\r
+ * and  <a href="https://github.com/BoschSensortec/BME280_driver">Sensor API Source Code</a>\r
  */\r
+\r
 #ifndef BME280_H_\r
 #define BME280_H_\r
 \r
@@ -54,47 +57,97 @@ extern "C" {
 /* Header includes */\r
 #include "bme280_defs.h"\r
 \r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280ApiInit Initialization\r
+ * @brief Initialize the sensor and device structure\r
+ */\r
+\r
 /*!\r
- *  @brief This API is the entry point.\r
- *  It reads the chip-id and calibration data from the sensor.\r
+ * \ingroup bme280ApiInit\r
+ * \page bme280_api_bme280_init bme280_init\r
+ * \code\r
+ * int8_t bme280_init(struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API reads the chip-id of the sensor which is the first step to\r
+ * verify the sensor and also calibrates the sensor\r
+ * As this API is the entry point, call this API before using other APIs.\r
+ *\r
+ * @param[in,out] dev : Structure instance of bme280_dev\r
+ *\r
+ * @return Result of API execution status.\r
  *\r
- *  @param[in,out] dev : Structure instance of bme280_dev\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
  *\r
- *  @return Result of API execution status\r
- *  @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
  */\r
 int8_t bme280_init(struct bme280_dev *dev);\r
 \r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280ApiRegister Registers\r
+ * @brief Generic API for accessing sensor registers\r
+ */\r
+\r
 /*!\r
- * @brief This API writes the given data to the register address\r
- * of the sensor.\r
+ * \ingroup bme280ApiRegister\r
+ * \page bme280_api_bme280_set_regs bme280_set_regs\r
+ * \code\r
+ * int8_t bme280_set_regs(const uint8_t reg_addr, const uint8_t *reg_data, uint8_t len, struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API writes the given data to the register address of the sensor\r
  *\r
- * @param[in] reg_addr : Register address from where the data to be written.\r
+ * @param[in] reg_addr : Register addresses to where the data is to be written\r
  * @param[in] reg_data : Pointer to data buffer which is to be written\r
- * in the sensor.\r
- * @param[in] len : No of bytes of data to write..\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ *                       in the reg_addr of sensor.\r
+ * @param[in] len      : No of bytes of data to write\r
+ * @param[in,out] dev  : Structure instance of bme280_dev\r
+ *\r
+ * @return Result of API execution status.\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
  *\r
- * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
  */\r
-int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, const struct bme280_dev *dev);\r
+int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, struct bme280_dev *dev);\r
 \r
 /*!\r
- * @brief This API reads the data from the given register address of the sensor.\r
+ * \ingroup bme280ApiRegister\r
+ * \page bme280_api_bme280_get_regs bme280_get_regs\r
+ * \code\r
+ * int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint8_t len, struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API reads the data from the given register address of sensor.\r
  *\r
- * @param[in] reg_addr : Register address from where the data to be read\r
+ * @param[in] reg_addr  : Register address from where the data to be read\r
  * @param[out] reg_data : Pointer to data buffer to store the read data.\r
- * @param[in] len : No of bytes of data to be read.\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in] len       : No of bytes of data to be read.\r
+ * @param[in,out] dev   : Structure instance of bme280_dev.\r
  *\r
- * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ * @return Result of API execution status.\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
+ */\r
+int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, struct bme280_dev *dev);\r
+\r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280ApiSensorSettings Sensor Settings\r
+ * @brief Generic API for accessing sensor settings\r
  */\r
-int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bme280_dev *dev);\r
 \r
 /*!\r
- * @brief This API sets the oversampling, filter and standby duration\r
+ * \ingroup bme280ApiSensorSettings\r
+ * \page bme280_api_bme280_set_sensor_settings bme280_set_sensor_settings\r
+ * \code\r
+ * int8_t bme280_set_sensor_settings(uint8_t desired_settings, const struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API sets the oversampling, filter and standby duration\r
  * (normal mode) settings in the sensor.\r
  *\r
  * @param[in] dev : Structure instance of bme280_dev.\r
@@ -114,23 +167,47 @@ int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const
  * BME280_STANDBY_SEL  |   To set standby duration setting.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
-int8_t bme280_set_sensor_settings(uint8_t desired_settings, const struct bme280_dev *dev);\r
+int8_t bme280_set_sensor_settings(uint8_t desired_settings, struct bme280_dev *dev);\r
 \r
 /*!\r
- * @brief This API gets the oversampling, filter and standby duration\r
+ * \ingroup bme280ApiSensorSettings\r
+ * \page bme280_api_bme280_get_sensor_settings bme280_get_sensor_settings\r
+ * \code\r
+ * int8_t bme280_get_sensor_settings(struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API gets the oversampling, filter and standby duration\r
  * (normal mode) settings from the sensor.\r
  *\r
  * @param[in,out] dev : Structure instance of bme280_dev.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
 int8_t bme280_get_sensor_settings(struct bme280_dev *dev);\r
 \r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280ApiSensorMode Sensor Mode\r
+ * @brief Generic API for configuring sensor power mode\r
+ */\r
+\r
 /*!\r
- * @brief This API sets the power mode of the sensor.\r
+ * \ingroup bme280ApiSensorMode\r
+ * \page bme280_api_bme280_set_sensor_mode bme280_set_sensor_mode\r
+ * \code\r
+ * int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API sets the power mode of the sensor.\r
  *\r
  * @param[in] dev : Structure instance of bme280_dev.\r
  * @param[in] sensor_mode : Variable which contains the power mode to be set.\r
@@ -142,12 +219,21 @@ int8_t bme280_get_sensor_settings(struct bme280_dev *dev);
  *     3                | BME280_NORMAL_MODE\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
-int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev);\r
+int8_t bme280_set_sensor_mode(uint8_t sensor_mode, struct bme280_dev *dev);\r
 \r
 /*!\r
- * @brief This API gets the power mode of the sensor.\r
+ * \ingroup bme280ApiSensorMode\r
+ * \page bme280_api_bme280_get_sensor_mode bme280_get_sensor_mode\r
+ * \code\r
+ * int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API gets the power mode of the sensor.\r
  *\r
  * @param[in] dev : Structure instance of bme280_dev.\r
  * @param[out] sensor_mode : Pointer variable to store the power mode.\r
@@ -159,22 +245,52 @@ int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev)
  *     3                | BME280_NORMAL_MODE\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
+ */\r
+int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, struct bme280_dev *dev);\r
+\r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280ApiSystem System\r
+ * @brief API that performs system-level operations\r
  */\r
-int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev);\r
 \r
 /*!\r
- * @brief This API performs the soft reset of the sensor.\r
+ * \ingroup bme280ApiSystem\r
+ * \page bme280_api_bme280_soft_reset bme280_soft_reset\r
+ * \code\r
+ * int8_t bme280_soft_reset(struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API soft-resets the sensor.\r
  *\r
- * @param[in] dev : Structure instance of bme280_dev.\r
+ * @param[in,out] dev : Structure instance of bme280_dev.\r
  *\r
- * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.\r
+ * @return Result of API execution status.\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
+ */\r
+int8_t bme280_soft_reset(struct bme280_dev *dev);\r
+\r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280ApiSensorData Sensor Data\r
+ * @brief Data processing of sensor\r
  */\r
-int8_t bme280_soft_reset(const struct bme280_dev *dev);\r
 \r
 /*!\r
- * @brief This API reads the pressure, temperature and humidity data from the\r
+ * \ingroup bme280ApiSensorData\r
+ * \page bme280_api_bme280_get_sensor_data bme280_get_sensor_data\r
+ * \code\r
+ * int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data, struct bme280_dev *dev);\r
+ * \endcode\r
+ * @details This API reads the pressure, temperature and humidity data from the\r
  * sensor, compensates the data and store it in the bme280_data structure\r
  * instance passed by the user.\r
  *\r
@@ -192,22 +308,40 @@ int8_t bme280_soft_reset(const struct bme280_dev *dev);
  * @param[in] dev : Structure instance of bme280_dev.\r
  *\r
  * @return Result of API execution status\r
- * @retval zero -> Success / +ve value -> Warning / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
 int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data, struct bme280_dev *dev);\r
 \r
 /*!\r
- *  @brief This API is used to parse the pressure, temperature and\r
+ * \ingroup bme280ApiSensorData\r
+ * \page bme280_api_bme280_parse_sensor_data bme280_parse_sensor_data\r
+ * \code\r
+ * void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data);\r
+ * \endcode\r
+ *  @details This API is used to parse the pressure, temperature and\r
  *  humidity data and store it in the bme280_uncomp_data structure instance.\r
  *\r
  *  @param[in] reg_data     : Contains register data which needs to be parsed\r
  *  @param[out] uncomp_data : Contains the uncompensated pressure, temperature\r
  *  and humidity data.\r
+ *\r
  */\r
 void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data);\r
 \r
 /*!\r
- * @brief This API is used to compensate the pressure and/or\r
+ * \ingroup bme280ApiSensorData\r
+ * \page bme280_api_bme280_compensate_data bme280_compensate_data\r
+ * \code\r
+ * int8_t bme280_compensate_data(uint8_t sensor_comp,\r
+ *                             const struct bme280_uncomp_data *uncomp_data,\r
+ *                             struct bme280_data *comp_data,\r
+ *                             struct bme280_calib_data *calib_data);\r
+ * \endcode\r
+ * @details This API is used to compensate the pressure and/or\r
  * temperature and/or humidity data according to the component selected by the\r
  * user.\r
  *\r
@@ -220,14 +354,29 @@ void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data
  * @param[in] calib_data : Pointer to the calibration data structure.\r
  *\r
  * @return Result of API execution status.\r
- * @retval zero -> Success / -ve value -> Error\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval > 0 -> Warning.\r
+ * @retval < 0 -> Fail.\r
+ *\r
  */\r
 int8_t bme280_compensate_data(uint8_t sensor_comp,\r
                               const struct bme280_uncomp_data *uncomp_data,\r
                               struct bme280_data *comp_data,\r
                               struct bme280_calib_data *calib_data);\r
 \r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280ApiSensorDelay Sensor Delay\r
+ * @brief Generic API for measuring sensor delay\r
+ */\r
+\r
 /*!\r
+ * \ingroup bme280ApiSensorDelay\r
+ * \page bme280_api_bme280_cal_meas_delay bme280_cal_meas_delay\r
+ * \code\r
+ * uint32_t bme280_cal_meas_delay(const struct bme280_settings *settings);\r
+ * \endcode\r
  * @brief This API is used to calculate the maximum delay in milliseconds required for the\r
  * temperature/pressure/humidity(which ever are enabled) measurement to complete.\r
  * The delay depends upon the number of sensors enabled and their oversampling configuration.\r
@@ -235,8 +384,8 @@ int8_t bme280_compensate_data(uint8_t sensor_comp,
  * @param[in] settings : contains the oversampling configurations.\r
  *\r
  * @return delay required in milliseconds.\r
+ *\r
  */\r
-\r
 uint32_t bme280_cal_meas_delay(const struct bme280_settings *settings);\r
 \r
 #ifdef __cplusplus\r
index cf141cd083d2a7d0dc09b7707488b2d7d519b3e0..686ba6ab138568eaef19314a4252833d55cdcb1b 100644 (file)
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
 * POSSIBILITY OF SUCH DAMAGE.\r
 *\r
-* @file        bme280_defs.h\r
-* @date        2020-01-24\r
-* @version     v3.4.3\r
+* @file       bme280_defs.h\r
+* @date       2020-03-28\r
+* @version    v3.5.0\r
 *\r
 */\r
 \r
-/*! @file bme280_defs.h\r
- * @brief Sensor driver for BME280 sensor\r
- */\r
-\r
-/*!\r
- * @defgroup BME280 SENSOR API\r
- * @brief\r
- */\r
 #ifndef BME280_DEFS_H_\r
 #define BME280_DEFS_H_\r
 \r
 /********************************************************/\r
 \r
 #if !defined(UINT8_C) && !defined(INT8_C)\r
-#define INT8_C(x)   S8_C(x)\r
-#define UINT8_C(x)  U8_C(x)\r
+#define INT8_C(x)    S8_C(x)\r
+#define UINT8_C(x)   U8_C(x)\r
 #endif\r
 \r
 #if !defined(UINT16_C) && !defined(INT16_C)\r
-#define INT16_C(x)  S16_C(x)\r
-#define UINT16_C(x) U16_C(x)\r
+#define INT16_C(x)   S16_C(x)\r
+#define UINT16_C(x)  U16_C(x)\r
 #endif\r
 \r
 #if !defined(INT32_C) && !defined(UINT32_C)\r
-#define INT32_C(x)  S32_C(x)\r
-#define UINT32_C(x) U32_C(x)\r
+#define INT32_C(x)   S32_C(x)\r
+#define UINT32_C(x)  U32_C(x)\r
 #endif\r
 \r
 #if !defined(INT64_C) && !defined(UINT64_C)\r
-#define INT64_C(x)  S64_C(x)\r
-#define UINT64_C(x) U64_C(x)\r
+#define INT64_C(x)   S64_C(x)\r
+#define UINT64_C(x)  U64_C(x)\r
 #endif\r
 \r
 /**@}*/\r
 /**\name C standard macros */\r
 #ifndef NULL\r
 #ifdef __cplusplus\r
-#define NULL 0\r
+#define NULL         0\r
 #else\r
-#define NULL ((void *) 0)\r
+#define NULL         ((void *) 0)\r
 #endif\r
 #endif\r
 \r
 /********************************************************/\r
 \r
-#ifndef BME280_64BIT_ENABLE /* Check if 64-bit integer (using BME280_64BIT_ENABLE) is enabled */\r
-#ifndef BME280_32BIT_ENABLE /* Check if 32-bit integer (using BME280_32BIT_ENABLE) is enabled */\r
-#ifndef BME280_FLOAT_ENABLE /* If any of the integer data types not enabled then enable BME280_FLOAT_ENABLE */\r
+#ifndef BME280_64BIT_ENABLE /*< Check if 64-bit integer (using BME280_64BIT_ENABLE) is enabled */\r
+#ifndef BME280_32BIT_ENABLE /*< Check if 32-bit integer (using BME280_32BIT_ENABLE) is enabled */\r
+#ifndef BME280_FLOAT_ENABLE /*< If any of the integer data types not enabled then enable BME280_FLOAT_ENABLE */\r
 #define BME280_FLOAT_ENABLE\r
 #endif\r
 #endif\r
 #endif\r
 \r
 #ifndef TRUE\r
-#define TRUE                              UINT8_C(1)\r
+#define TRUE                                      UINT8_C(1)\r
 #endif\r
 #ifndef FALSE\r
-#define FALSE                             UINT8_C(0)\r
+#define FALSE                                     UINT8_C(0)\r
+#endif\r
+\r
+/**\r
+ * BME280_INTF_RET_TYPE is the read/write interface return type which can be overwritten by the build system.\r
+ */\r
+#ifndef BME280_INTF_RET_TYPE\r
+#define BME280_INTF_RET_TYPE                      int8_t\r
+#endif\r
+\r
+/**\r
+ * The last error code from read/write interface is stored in the device structure as intf_rslt.\r
+ */\r
+#ifndef BME280_INTF_RET_SUCCESS\r
+#define BME280_INTF_RET_SUCCESS                   INT8_C(0)\r
 #endif\r
 \r
 /**\name I2C addresses */\r
-#define BME280_I2C_ADDR_PRIM              UINT8_C(0x76)\r
-#define BME280_I2C_ADDR_SEC               UINT8_C(0x77)\r
+#define BME280_I2C_ADDR_PRIM                      UINT8_C(0x76)\r
+#define BME280_I2C_ADDR_SEC                       UINT8_C(0x77)\r
 \r
 /**\name BME280 chip identifier */\r
-#define BME280_CHIP_ID                    UINT8_C(0x60)\r
+#define BME280_CHIP_ID                            UINT8_C(0x60)\r
 \r
 /**\name Register Address */\r
-#define BME280_CHIP_ID_ADDR               UINT8_C(0xD0)\r
-#define BME280_RESET_ADDR                 UINT8_C(0xE0)\r
-#define BME280_TEMP_PRESS_CALIB_DATA_ADDR UINT8_C(0x88)\r
-#define BME280_HUMIDITY_CALIB_DATA_ADDR   UINT8_C(0xE1)\r
-#define BME280_PWR_CTRL_ADDR              UINT8_C(0xF4)\r
-#define BME280_CTRL_HUM_ADDR              UINT8_C(0xF2)\r
-#define BME280_CTRL_MEAS_ADDR             UINT8_C(0xF4)\r
-#define BME280_CONFIG_ADDR                UINT8_C(0xF5)\r
-#define BME280_DATA_ADDR                  UINT8_C(0xF7)\r
+#define BME280_CHIP_ID_ADDR                       UINT8_C(0xD0)\r
+#define BME280_RESET_ADDR                         UINT8_C(0xE0)\r
+#define BME280_TEMP_PRESS_CALIB_DATA_ADDR         UINT8_C(0x88)\r
+#define BME280_HUMIDITY_CALIB_DATA_ADDR           UINT8_C(0xE1)\r
+#define BME280_PWR_CTRL_ADDR                      UINT8_C(0xF4)\r
+#define BME280_CTRL_HUM_ADDR                      UINT8_C(0xF2)\r
+#define BME280_CTRL_MEAS_ADDR                     UINT8_C(0xF4)\r
+#define BME280_CONFIG_ADDR                        UINT8_C(0xF5)\r
+#define BME280_DATA_ADDR                          UINT8_C(0xF7)\r
 \r
 /**\name API success code */\r
-#define BME280_OK                         INT8_C(0)\r
+#define BME280_OK                                 INT8_C(0)\r
 \r
 /**\name API error codes */\r
-#define BME280_E_NULL_PTR                 INT8_C(-1)\r
-#define BME280_E_DEV_NOT_FOUND            INT8_C(-2)\r
-#define BME280_E_INVALID_LEN              INT8_C(-3)\r
-#define BME280_E_COMM_FAIL                INT8_C(-4)\r
-#define BME280_E_SLEEP_MODE_FAIL          INT8_C(-5)\r
-#define BME280_E_NVM_COPY_FAILED          INT8_C(-6)\r
+#define BME280_E_NULL_PTR                         INT8_C(-1)\r
+#define BME280_E_DEV_NOT_FOUND                    INT8_C(-2)\r
+#define BME280_E_INVALID_LEN                      INT8_C(-3)\r
+#define BME280_E_COMM_FAIL                        INT8_C(-4)\r
+#define BME280_E_SLEEP_MODE_FAIL                  INT8_C(-5)\r
+#define BME280_E_NVM_COPY_FAILED                  INT8_C(-6)\r
 \r
 /**\name API warning codes */\r
-#define BME280_W_INVALID_OSR_MACRO        INT8_C(1)\r
+#define BME280_W_INVALID_OSR_MACRO                INT8_C(1)\r
 \r
 /**\name Macros related to size */\r
-#define BME280_TEMP_PRESS_CALIB_DATA_LEN  UINT8_C(26)\r
-#define BME280_HUMIDITY_CALIB_DATA_LEN    UINT8_C(7)\r
-#define BME280_P_T_H_DATA_LEN             UINT8_C(8)\r
+#define BME280_TEMP_PRESS_CALIB_DATA_LEN          UINT8_C(26)\r
+#define BME280_HUMIDITY_CALIB_DATA_LEN            UINT8_C(7)\r
+#define BME280_P_T_H_DATA_LEN                     UINT8_C(8)\r
 \r
 /**\name Sensor power modes */\r
-#define BME280_SLEEP_MODE                 UINT8_C(0x00)\r
-#define BME280_FORCED_MODE                UINT8_C(0x01)\r
-#define BME280_NORMAL_MODE                UINT8_C(0x03)\r
+#define BME280_SLEEP_MODE                         UINT8_C(0x00)\r
+#define BME280_FORCED_MODE                        UINT8_C(0x01)\r
+#define BME280_NORMAL_MODE                        UINT8_C(0x03)\r
 \r
 /**\name Macro to combine two 8 bit data's to form a 16 bit data */\r
-#define BME280_CONCAT_BYTES(msb, lsb)            (((uint16_t)msb << 8) | (uint16_t)lsb)\r
+#define BME280_CONCAT_BYTES(msb, lsb)             (((uint16_t)msb << 8) | (uint16_t)lsb)\r
 \r
 #define BME280_SET_BITS(reg_data, bitname, data) \\r
     ((reg_data & ~(bitname##_MSK)) | \\r
     ((reg_data & ~(bitname##_MSK)) | \\r
      (data & bitname##_MSK))\r
 \r
-#define BME280_GET_BITS(reg_data, bitname)       ((reg_data & (bitname##_MSK)) >> \\r
-                                                  (bitname##_POS))\r
-#define BME280_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))\r
+#define BME280_GET_BITS(reg_data, bitname)        ((reg_data & (bitname##_MSK)) >> \\r
+                                                   (bitname##_POS))\r
+#define BME280_GET_BITS_POS_0(reg_data, bitname)  (reg_data & (bitname##_MSK))\r
 \r
 /**\name Macros for bit masking */\r
-#define BME280_SENSOR_MODE_MSK      UINT8_C(0x03)\r
-#define BME280_SENSOR_MODE_POS      UINT8_C(0x00)\r
+#define BME280_SENSOR_MODE_MSK                    UINT8_C(0x03)\r
+#define BME280_SENSOR_MODE_POS                    UINT8_C(0x00)\r
 \r
-#define BME280_CTRL_HUM_MSK         UINT8_C(0x07)\r
-#define BME280_CTRL_HUM_POS         UINT8_C(0x00)\r
+#define BME280_CTRL_HUM_MSK                       UINT8_C(0x07)\r
+#define BME280_CTRL_HUM_POS                       UINT8_C(0x00)\r
 \r
-#define BME280_CTRL_PRESS_MSK       UINT8_C(0x1C)\r
-#define BME280_CTRL_PRESS_POS       UINT8_C(0x02)\r
+#define BME280_CTRL_PRESS_MSK                     UINT8_C(0x1C)\r
+#define BME280_CTRL_PRESS_POS                     UINT8_C(0x02)\r
 \r
-#define BME280_CTRL_TEMP_MSK        UINT8_C(0xE0)\r
-#define BME280_CTRL_TEMP_POS        UINT8_C(0x05)\r
+#define BME280_CTRL_TEMP_MSK                      UINT8_C(0xE0)\r
+#define BME280_CTRL_TEMP_POS                      UINT8_C(0x05)\r
 \r
-#define BME280_FILTER_MSK           UINT8_C(0x1C)\r
-#define BME280_FILTER_POS           UINT8_C(0x02)\r
+#define BME280_FILTER_MSK                         UINT8_C(0x1C)\r
+#define BME280_FILTER_POS                         UINT8_C(0x02)\r
 \r
-#define BME280_STANDBY_MSK          UINT8_C(0xE0)\r
-#define BME280_STANDBY_POS          UINT8_C(0x05)\r
+#define BME280_STANDBY_MSK                        UINT8_C(0xE0)\r
+#define BME280_STANDBY_POS                        UINT8_C(0x05)\r
 \r
 /**\name Sensor component selection macros\r
  * These values are internal for API implementation. Don't relate this to\r
  * data sheet.\r
  */\r
-#define BME280_PRESS                UINT8_C(1)\r
-#define BME280_TEMP                 UINT8_C(1 << 1)\r
-#define BME280_HUM                  UINT8_C(1 << 2)\r
-#define BME280_ALL                  UINT8_C(0x07)\r
+#define BME280_PRESS                              UINT8_C(1)\r
+#define BME280_TEMP                               UINT8_C(1 << 1)\r
+#define BME280_HUM                                UINT8_C(1 << 2)\r
+#define BME280_ALL                                UINT8_C(0x07)\r
 \r
 /**\name Settings selection macros */\r
-#define BME280_OSR_PRESS_SEL        UINT8_C(1)\r
-#define BME280_OSR_TEMP_SEL         UINT8_C(1 << 1)\r
-#define BME280_OSR_HUM_SEL          UINT8_C(1 << 2)\r
-#define BME280_FILTER_SEL           UINT8_C(1 << 3)\r
-#define BME280_STANDBY_SEL          UINT8_C(1 << 4)\r
-#define BME280_ALL_SETTINGS_SEL     UINT8_C(0x1F)\r
+#define BME280_OSR_PRESS_SEL                      UINT8_C(1)\r
+#define BME280_OSR_TEMP_SEL                       UINT8_C(1 << 1)\r
+#define BME280_OSR_HUM_SEL                        UINT8_C(1 << 2)\r
+#define BME280_FILTER_SEL                         UINT8_C(1 << 3)\r
+#define BME280_STANDBY_SEL                        UINT8_C(1 << 4)\r
+#define BME280_ALL_SETTINGS_SEL                   UINT8_C(0x1F)\r
 \r
 /**\name Oversampling macros */\r
-#define BME280_NO_OVERSAMPLING      UINT8_C(0x00)\r
-#define BME280_OVERSAMPLING_1X      UINT8_C(0x01)\r
-#define BME280_OVERSAMPLING_2X      UINT8_C(0x02)\r
-#define BME280_OVERSAMPLING_4X      UINT8_C(0x03)\r
-#define BME280_OVERSAMPLING_8X      UINT8_C(0x04)\r
-#define BME280_OVERSAMPLING_16X     UINT8_C(0x05)\r
+#define BME280_NO_OVERSAMPLING                    UINT8_C(0x00)\r
+#define BME280_OVERSAMPLING_1X                    UINT8_C(0x01)\r
+#define BME280_OVERSAMPLING_2X                    UINT8_C(0x02)\r
+#define BME280_OVERSAMPLING_4X                    UINT8_C(0x03)\r
+#define BME280_OVERSAMPLING_8X                    UINT8_C(0x04)\r
+#define BME280_OVERSAMPLING_16X                   UINT8_C(0x05)\r
 \r
 /**\name Measurement delay calculation macros  */\r
-#define BME280_MEAS_OFFSET          UINT16_C(1250)\r
-#define BME280_MEAS_DUR             UINT16_C(2300)\r
-#define BME280_PRES_HUM_MEAS_OFFSET UINT16_C(575)\r
-#define BME280_MEAS_SCALING_FACTOR  UINT16_C(1000)\r
+#define BME280_MEAS_OFFSET                        UINT16_C(1250)\r
+#define BME280_MEAS_DUR                           UINT16_C(2300)\r
+#define BME280_PRES_HUM_MEAS_OFFSET               UINT16_C(575)\r
+#define BME280_MEAS_SCALING_FACTOR                UINT16_C(1000)\r
 \r
 /**\name Standby duration selection macros */\r
-#define BME280_STANDBY_TIME_0_5_MS  (0x00)\r
-#define BME280_STANDBY_TIME_62_5_MS (0x01)\r
-#define BME280_STANDBY_TIME_125_MS  (0x02)\r
-#define BME280_STANDBY_TIME_250_MS  (0x03)\r
-#define BME280_STANDBY_TIME_500_MS  (0x04)\r
-#define BME280_STANDBY_TIME_1000_MS (0x05)\r
-#define BME280_STANDBY_TIME_10_MS   (0x06)\r
-#define BME280_STANDBY_TIME_20_MS   (0x07)\r
+#define BME280_STANDBY_TIME_0_5_MS                (0x00)\r
+#define BME280_STANDBY_TIME_62_5_MS               (0x01)\r
+#define BME280_STANDBY_TIME_125_MS                (0x02)\r
+#define BME280_STANDBY_TIME_250_MS                (0x03)\r
+#define BME280_STANDBY_TIME_500_MS                (0x04)\r
+#define BME280_STANDBY_TIME_1000_MS               (0x05)\r
+#define BME280_STANDBY_TIME_10_MS                 (0x06)\r
+#define BME280_STANDBY_TIME_20_MS                 (0x07)\r
 \r
 /**\name Filter coefficient selection macros */\r
-#define BME280_FILTER_COEFF_OFF     (0x00)\r
-#define BME280_FILTER_COEFF_2       (0x01)\r
-#define BME280_FILTER_COEFF_4       (0x02)\r
-#define BME280_FILTER_COEFF_8       (0x03)\r
-#define BME280_FILTER_COEFF_16      (0x04)\r
+#define BME280_FILTER_COEFF_OFF                   (0x00)\r
+#define BME280_FILTER_COEFF_2                     (0x01)\r
+#define BME280_FILTER_COEFF_4                     (0x02)\r
+#define BME280_FILTER_COEFF_8                     (0x03)\r
+#define BME280_FILTER_COEFF_16                    (0x04)\r
 \r
-#define BME280_STATUS_REG_ADDR      (0xF3)\r
-#define BME280_SOFT_RESET_COMMAND   (0xB6)\r
-#define BME280_STATUS_IM_UPDATE     (0x01)\r
+#define BME280_STATUS_REG_ADDR                    (0xF3)\r
+#define BME280_SOFT_RESET_COMMAND                 (0xB6)\r
+#define BME280_STATUS_IM_UPDATE                   (0x01)\r
 \r
 /*!\r
  * @brief Interface selection Enums\r
  */\r
 enum bme280_intf {\r
-    /*! SPI interface */\r
+    /*< SPI interface */\r
     BME280_SPI_INTF,\r
-\r
-    /*! I2C interface */\r
+    /*< I2C interface */\r
     BME280_I2C_INTF\r
 };\r
 \r
 /*!\r
  * @brief Type definitions\r
  */\r
-typedef int8_t (*bme280_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);\r
-typedef void (*bme280_delay_fptr_t)(uint32_t period);\r
+\r
+/*!\r
+ * @brief Bus communication function pointer which should be mapped to\r
+ * the platform specific read functions of the user\r
+ *\r
+ * @param[in] reg_addr       : Register address from which data is read.\r
+ * @param[out] reg_data     : Pointer to data buffer where read data is stored.\r
+ * @param[in] len            : Number of bytes of data to be read.\r
+ * @param[in, out] intf_ptr  : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs.\r
+ *\r
+ * @retval   0 -> Success.\r
+ * @retval Non zero value -> Fail.\r
+ *\r
+ */\r
+typedef BME280_INTF_RET_TYPE (*bme280_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);\r
+\r
+/*!\r
+ * @brief Bus communication function pointer which should be mapped to\r
+ * the platform specific write functions of the user\r
+ *\r
+ * @param[in] reg_addr      : Register address to which the data is written.\r
+ * @param[in] reg_data     : Pointer to data buffer in which data to be written\r
+ *                            is stored.\r
+ * @param[in] len           : Number of bytes of data to be written.\r
+ * @param[in, out] intf_ptr : Void pointer that can enable the linking of descriptors\r
+ *                            for interface related call backs\r
+ *\r
+ * @retval   0   -> Success.\r
+ * @retval Non zero value -> Fail.\r
+ *\r
+ */\r
+typedef BME280_INTF_RET_TYPE (*bme280_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len,\r
+                                                    void *intf_ptr);\r
+\r
+/*!\r
+ * @brief Delay function pointer which should be mapped to\r
+ * delay function of the user\r
+ *\r
+ * @param[in] period              : Delay in microseconds.\r
+ * @param[in, out] intf_ptr       : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs\r
+ *\r
+ */\r
+typedef void (*bme280_delay_us_fptr_t)(uint32_t period, void *intf_ptr);\r
 \r
 /*!\r
  * @brief Calibration data\r
  */\r
 struct bme280_calib_data\r
 {\r
-    /**\r
-     * @ Trim Variables\r
-     */\r
-\r
-    /**@{*/\r
+    /*< Calibration coefficient for the temperature sensor */\r
     uint16_t dig_t1;\r
+\r
+    /*< Calibration coefficient for the temperature sensor */\r
     int16_t dig_t2;\r
+\r
+    /*< Calibration coefficient for the temperature sensor */\r
     int16_t dig_t3;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     uint16_t dig_p1;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p2;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p3;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p4;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p5;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p6;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p7;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p8;\r
+\r
+    /*< Calibration coefficient for the pressure sensor */\r
     int16_t dig_p9;\r
+\r
+    /*< Calibration coefficient for the humidity sensor */\r
     uint8_t dig_h1;\r
+\r
+    /*< Calibration coefficient for the humidity sensor */\r
     int16_t dig_h2;\r
+\r
+    /*< Calibration coefficient for the humidity sensor */\r
     uint8_t dig_h3;\r
+\r
+    /*< Calibration coefficient for the humidity sensor */\r
     int16_t dig_h4;\r
+\r
+    /*< Calibration coefficient for the humidity sensor */\r
     int16_t dig_h5;\r
+\r
+    /*< Calibration coefficient for the humidity sensor */\r
     int8_t dig_h6;\r
-    int32_t t_fine;\r
 \r
-    /**@}*/\r
+    /*< Variable to store the intermediate temperature coefficient */\r
+    int32_t t_fine;\r
 };\r
 \r
 /*!\r
@@ -292,28 +370,28 @@ struct bme280_calib_data
 #ifdef BME280_FLOAT_ENABLE\r
 struct bme280_data\r
 {\r
-    /*! Compensated pressure */\r
+    /*< Compensated pressure */\r
     double pressure;\r
 \r
-    /*! Compensated temperature */\r
+    /*< Compensated temperature */\r
     double temperature;\r
 \r
-    /*! Compensated humidity */\r
+    /*< Compensated humidity */\r
     double humidity;\r
 };\r
 #else\r
 struct bme280_data\r
 {\r
-    /*! Compensated pressure */\r
+    /*< Compensated pressure */\r
     uint32_t pressure;\r
 \r
-    /*! Compensated temperature */\r
+    /*< Compensated temperature */\r
     int32_t temperature;\r
 \r
-    /*! Compensated humidity */\r
+    /*< Compensated humidity */\r
     uint32_t humidity;\r
 };\r
-#endif /* BME280_USE_FLOATING_POINT */\r
+#endif /*! BME280_USE_FLOATING_POINT */\r
 \r
 /*!\r
  * @brief bme280 sensor structure which comprises of uncompensated temperature,\r
@@ -321,13 +399,13 @@ struct bme280_data
  */\r
 struct bme280_uncomp_data\r
 {\r
-    /*! un-compensated pressure */\r
+    /*< un-compensated pressure */\r
     uint32_t pressure;\r
 \r
-    /*! un-compensated temperature */\r
+    /*< un-compensated temperature */\r
     uint32_t temperature;\r
 \r
-    /*! un-compensated humidity */\r
+    /*< un-compensated humidity */\r
     uint32_t humidity;\r
 };\r
 \r
@@ -337,19 +415,19 @@ struct bme280_uncomp_data
  */\r
 struct bme280_settings\r
 {\r
-    /*! pressure oversampling */\r
+    /*< pressure oversampling */\r
     uint8_t osr_p;\r
 \r
-    /*! temperature oversampling */\r
+    /*< temperature oversampling */\r
     uint8_t osr_t;\r
 \r
-    /*! humidity oversampling */\r
+    /*< humidity oversampling */\r
     uint8_t osr_h;\r
 \r
-    /*! filter coefficient */\r
+    /*< filter coefficient */\r
     uint8_t filter;\r
 \r
-    /*! standby time */\r
+    /*< standby time */\r
     uint8_t standby_time;\r
 };\r
 \r
@@ -358,31 +436,35 @@ struct bme280_settings
  */\r
 struct bme280_dev\r
 {\r
-    /*! Chip Id */\r
+    /*< Chip Id */\r
     uint8_t chip_id;\r
 \r
-    /*! Device Id */\r
-    uint8_t dev_id;\r
+    /*< Interface function pointer used to enable the device address for I2C and chip selection for SPI */\r
+    void *intf_ptr;\r
 \r
-    /*! SPI/I2C interface */\r
+    /*< Interface Selection\r
+     * For SPI, intf = BME280_SPI_INTF\r
+     * For I2C, intf = BME280_I2C_INTF\r
+     * */\r
     enum bme280_intf intf;\r
 \r
-    /*! Read function pointer */\r
-    bme280_com_fptr_t read;\r
+    /*< Read function pointer */\r
+    bme280_read_fptr_t read;\r
 \r
-    /*! Write function pointer */\r
-    bme280_com_fptr_t write;\r
+    /*< Write function pointer */\r
+    bme280_write_fptr_t write;\r
 \r
-    /*! Delay function pointer */\r
-    bme280_delay_fptr_t delay_ms;\r
+    /*< Delay function pointer */\r
+    bme280_delay_us_fptr_t delay_us;\r
 \r
-    /*! Trim data */\r
+    /*< Trim data */\r
     struct bme280_calib_data calib_data;\r
 \r
-    /*! Sensor settings */\r
+    /*< Sensor settings */\r
     struct bme280_settings settings;\r
+\r
+    /*< Variable to store result of read/write function */\r
+    BME280_INTF_RET_TYPE intf_rslt;\r
 };\r
 \r
 #endif /* BME280_DEFS_H_ */\r
-/** @}*/\r
-/** @}*/\r
index 5e32da3562fbfa24c49e3e6c0ae43f72ea8a3a69..411a459aef6ce8db7d68f7a961e2754ceddaf871 100644 (file)
@@ -4,7 +4,15 @@
  * tested: NanoPi NEO.\r
  * Use like: ./bme280 /dev/iic0\r
  */\r
-#include "bme280.h"\r
+\r
+#ifdef __KERNEL__\r
+#include <sys/ioctl.h>\r
+#include <dev/iicbus/iic.h>\r
+#endif\r
+\r
+/******************************************************************************/\r
+/*!                         System header files                               */\r
+\r
 #include <string.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <sys/types.h>\r
 #include <fcntl.h>\r
 \r
-#include <sys/ioctl.h>\r
-#include <dev/iicbus/iic.h>\r
-\r
-int fd;\r
+/******************************************************************************/\r
+/*!                         Own header files                                  */\r
+#include <iic.h>\r
+#include "bme280.h"\r
 \r
-int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);\r
-void user_delay_ms(uint32_t period);\r
-int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);\r
-void print_sensor_data(struct bme280_data *comp_data);\r
-int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev);\r
+/******************************************************************************/\r
+/*!                               Structures                                  */\r
 \r
+/* Structure that contains identifier details used in example */\r
+struct identifier\r
+{\r
+    /* Variable to hold device address */\r
+    uint8_t dev_addr;\r
+\r
+    /* Variable that contains file descriptor */\r
+    int8_t fd;\r
+};\r
+\r
+/******************************************************************************/\r
+/*!                           Functions                                       */\r
+\r
+/*!\r
+ *  @brief Function for reading the sensor's registers through I2C bus.\r
+ *\r
+ *  @param[in] reg_addr       : Register address.\r
+ *  @param[out] data          : Pointer to the data buffer to store the read data.\r
+ *  @param[in] len            : No of bytes to read.\r
+ *  @param[in, out] intf_ptr  : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs.\r
+ *\r
+ *  @return Status of execution\r
+ *\r
+ *  @retval 0 -> Success\r
+ *  @retval > 0 -> Failure Info\r
+ *\r
+ */\r
+int8_t user_i2c_read(uint8_t reg_addr, uint8_t *data, uint32_t len, void *intf_ptr);\r
+\r
+/*!\r
+ *  @brief Function that creates a mandatory delay required in some of the APIs.\r
+ *\r
+ * @param[in] period              : Delay in microseconds.\r
+ * @param[in, out] intf_ptr       : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs\r
+ *  @return void.\r
+ *\r
+ */\r
+void user_delay_us(uint32_t period, void *intf_ptr);\r
+\r
+/*!\r
+ *  @brief Function for writing the sensor's registers through I2C bus.\r
+ *\r
+ *  @param[in] reg_addr       : Register address.\r
+ *  @param[in] data           : Pointer to the data buffer whose value is to be written.\r
+ *  @param[in] len            : No of bytes to write.\r
+ *  @param[in, out] intf_ptr  : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs\r
+ *\r
+ *  @return Status of execution\r
+ *\r
+ *  @retval BME280_OK -> Success\r
+ *  @retval BME280_E_COMM_FAIL -> Communication failure.\r
+ *\r
+ */\r
+int8_t user_i2c_write(uint8_t reg_addr, const uint8_t *data, uint32_t len, void *intf_ptr);\r
+\r
+/*!\r
+ * @brief Function for print the temperature, humidity and pressure data.\r
+ *\r
+ * @param[out] comp_data    :   Structure instance of bme280_data\r
+ *\r
+ * @note Sensor data whose can be read\r
+ *\r
+ * sens_list\r
+ * --------------\r
+ * Pressure\r
+ * Temperature\r
+ * Humidity\r
+ *\r
+ */\r
+static void print_sensor_data(struct bme280_data *comp_data);\r
+\r
+/*!\r
+ * @brief Function reads temperature, humidity and pressure data in forced mode.\r
+ *\r
+ * @param[in] dev   :   Structure instance of bme280_dev.\r
+ *\r
+ * @return Result of API execution status\r
+ *\r
+ * @retval BME280_OK - Success.\r
+ * @retval BME280_E_NULL_PTR - Error: Null pointer error\r
+ * @retval BME280_E_COMM_FAIL - Error: Communication fail error\r
+ * @retval BME280_E_NVM_COPY_FAILED - Error: NVM copy failed\r
+ *\r
+ */\r
+static int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev);\r
 \r
-int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)\r
+/*!\r
+ * @brief This function reading the sensor's registers through I2C bus.\r
+ */\r
+int8_t user_i2c_read(uint8_t reg_addr, uint8_t *data, uint32_t len, void *intf_ptr)\r
 {\r
+    struct identifier id;\r
+\r
+    id = *((struct identifier *)intf_ptr);\r
+\r
     struct iic_msg msgs[2] = {\r
-        {id << 1 | IIC_M_WR, IIC_M_WR, 1, &reg_addr},\r
-        {id << 1 | IIC_M_RD, IIC_M_RD, len, data},\r
+        { id.dev_addr << 1 | IIC_M_WR, IIC_M_WR, 1, &reg_addr }, { id.dev_addr << 1 | IIC_M_RD, IIC_M_RD, len, data },\r
     };\r
 \r
-    struct iic_rdwr_data rdwr_data = {msgs, 2};\r
+    struct iic_rdwr_data rdwr_data = { msgs, 2 };\r
+\r
+    int error = ioctl(id.fd, I2CRDWR, &rdwr_data);\r
 \r
-    int error = ioctl(fd, I2CRDWR, &rdwr_data);\r
-    if (error) {\r
+    if (error)\r
+    {\r
         return BME280_E_COMM_FAIL;\r
     }\r
 \r
     return BME280_OK;\r
 }\r
 \r
-\r
-void user_delay_ms(uint32_t period)\r
+/*!\r
+ * @brief This function provides the delay for required time (Microseconds) as per the input provided in some of the\r
+ * APIs\r
+ */\r
+void user_delay_us(uint32_t period, void *intf_ptr)\r
 {\r
-    usleep(period * 1000);\r
+    usleep(period);\r
 }\r
 \r
-\r
-int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)\r
+/*!\r
+ * @brief This function for writing the sensor's registers through I2C bus.\r
+ */\r
+int8_t user_i2c_write(uint8_t reg_addr, const uint8_t *data, uint32_t len, void *intf_ptr)\r
 {\r
-    uint8_t *buf = malloc( (1 + len) * sizeof(uint8_t) );\r
-    if (buf == NULL) {\r
+    struct identifier id;\r
+\r
+    id = *((struct identifier *)intf_ptr);\r
+\r
+    uint8_t *buf = malloc((1 + len) * sizeof(uint8_t));\r
+\r
+    if (buf == NULL)\r
+    {\r
         return BME280_E_COMM_FAIL;\r
     }\r
 \r
     buf[0] = reg_addr;\r
 \r
-    for (int i = 0; i < len; i++) {\r
-        buf[i+1] = data[i];\r
+    for (uint8_t i = 0; i < len; i++)\r
+    {\r
+        buf[i + 1] = data[i];\r
     }\r
 \r
     struct iic_msg msg;\r
 \r
-    msg.slave = id << 1 | !IIC_M_RD;\r
+    msg.slave = id.dev_addr << 1 | !IIC_M_RD;\r
     msg.flags = !IIC_M_RD;\r
     msg.len = (1 + len) * sizeof(uint8_t);\r
     msg.buf = buf;\r
 \r
-    struct iic_rdwr_data rdwr_data = {&msg, 1};\r
+    struct iic_rdwr_data rdwr_data = { &msg, 1 };\r
+\r
+    int error = ioctl(id.fd, I2CRDWR, &rdwr_data);\r
 \r
-    int error = ioctl(fd, I2CRDWR, &rdwr_data);\r
-    if (error) {\r
+    if (error)\r
+    {\r
         free(buf);\r
+\r
         return BME280_E_COMM_FAIL;\r
     }\r
 \r
@@ -81,10 +197,13 @@ int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
     return BME280_OK;\r
 }\r
 \r
-\r
+/*!\r
+ * @brief This API used to print the sensor temperature, pressure and humidity data.\r
+ */\r
 void print_sensor_data(struct bme280_data *comp_data)\r
 {\r
     float temp, press, hum;\r
+\r
 #ifdef BME280_FLOAT_ENABLE\r
     temp = comp_data->temperature;\r
     press = 0.01 * comp_data->pressure;\r
@@ -103,7 +222,9 @@ void print_sensor_data(struct bme280_data *comp_data)
     printf("%0.2lf deg C, %0.2lf hPa, %0.2lf%%\n", temp, press, hum);\r
 }\r
 \r
-\r
+/*!\r
+ * @brief This API reads the sensor temperature, pressure and humidity data in forced mode.\r
+ */\r
 int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)\r
 {\r
     int8_t rslt;\r
@@ -122,10 +243,12 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
     if (rslt != BME280_OK)\r
     {\r
         fprintf(stderr, "Failed to set sensor settings (code %+d).", rslt);\r
+\r
         return rslt;\r
     }\r
 \r
     printf("Temperature, Pressure, Humidity\n");\r
+\r
     /* Continuously stream sensor data */\r
     while (1)\r
     {\r
@@ -135,55 +258,58 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
             fprintf(stderr, "Failed to set sensor mode (code %+d).", rslt);\r
             break;\r
         }\r
+\r
         /* Wait for the measurement to complete and print data @25Hz */\r
-        dev->delay_ms(40);\r
+        dev->delay_us(40000, dev->intf_ptr);\r
         rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);\r
         if (rslt != BME280_OK)\r
         {\r
             fprintf(stderr, "Failed to get sensor data (code %+d).", rslt);\r
             break;\r
         }\r
+\r
         print_sensor_data(&comp_data);\r
-        dev->delay_ms(1000);\r
+        dev->delay_us(1000000, dev->intf_ptr);\r
     }\r
 \r
     return rslt;\r
 }\r
 \r
-\r
-\r
+/*!\r
+ * @brief This function starts execution of the program.\r
+ */\r
 int main(int argc, char* argv[])\r
 {\r
     struct bme280_dev dev;\r
     int8_t rslt = BME280_OK;\r
 \r
+    struct identifier id;\r
+\r
     if (argc < 2)\r
     {\r
         fprintf(stderr, "Missing argument for i2c bus.\n");\r
         exit(1);\r
     }\r
 \r
-    // make sure to select BME280_I2C_ADDR_PRIM\r
-    // or BME280_I2C_ADDR_SEC as needed\r
-    dev.dev_id =\r
-#if 1\r
-        BME280_I2C_ADDR_PRIM\r
-#else\r
-        BME280_I2C_ADDR_SEC\r
-#endif\r
-;\r
+    if ((id.fd = open(argv[1], O_RDWR)) < 0)\r
+    {\r
+        fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]);\r
+        exit(1);\r
+    }\r
+\r
+    /*\r
+     * make sure to select BME280_I2C_ADDR_PRIM\r
+     * or BME280_I2C_ADDR_SEC as needed\r
+     */\r
+    id.dev_addr = BME280_I2C_ADDR_PRIM;\r
 \r
     dev.intf = BME280_I2C_INTF;\r
     dev.read = user_i2c_read;\r
     dev.write = user_i2c_write;\r
-    dev.delay_ms = user_delay_ms;\r
+    dev.delay_us = user_delay_us;\r
 \r
-\r
-    if ((fd = open(argv[1], O_RDWR)) < 0)\r
-    {\r
-        fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]);\r
-        exit(1);\r
-    }\r
+    /* Update interface pointer with the structure that contains both device address and file descriptor */\r
+    dev.intf_ptr = &id;\r
 \r
     rslt = bme280_init(&dev);\r
     if (rslt != BME280_OK)\r
@@ -198,5 +324,6 @@ int main(int argc, char* argv[])
         fprintf(stderr, "Failed to stream sensor data (code %+d).\n", rslt);\r
         exit(1);\r
     }\r
+\r
     return 0;\r
 }\r
index 62c8eb5cce8ac05ed257852fe7ef0ba36a8a426a..0b8fc9a8305ede0843c746ba5776475f52232c85 100644 (file)
@@ -1,13 +1,18 @@
-/*\r
- * Copyright (C) 2020 Bosch Sensortec GmbH\r
- *\r
- * The license is available at root folder\r
+/**\\r
+ * Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.\r
  *\r
+ * SPDX-License-Identifier: BSD-3-Clause\r
+ **/\r
+\r
+/**\r
+ * \ingroup bme280\r
+ * \defgroup bme280Examples Examples\r
+ * @brief Reference Examples\r
  */\r
 \r
 /*!\r
- * @ingroup bme280GroupExample\r
- * @defgroup bme280GroupExample linux_userspace\r
+ * @ingroup bme280Examples\r
+ * @defgroup bme280GroupExampleLU linux_userspace\r
  * @brief Linux userspace test code, simple and mose code directly from the doco.\r
  * compile like this: gcc linux_userspace.c ../bme280.c -I ../ -o bme280\r
  * tested: Raspberry Pi.\r
 /*!                         Own header files                                  */\r
 #include "bme280.h"\r
 \r
-/*****************************************************************************/\r
-/*!                         Global variables                                 */\r
-int fd;\r
+/******************************************************************************/\r
+/*!                               Structures                                  */\r
+\r
+/* Structure that contains identifier details used in example */\r
+struct identifier\r
+{\r
+    /* Variable to hold device address */\r
+    uint8_t dev_addr;\r
+\r
+    /* Variable that contains file descriptor */\r
+    int8_t fd;\r
+};\r
 \r
 /****************************************************************************/\r
 /*!                         Functions                                       */\r
@@ -43,11 +57,13 @@ int fd;
 /*!\r
  *  @brief Function that creates a mandatory delay required in some of the APIs.\r
  *\r
- *  @param[in] period  : The required wait time in microseconds.\r
+ * @param[in] period              : Delay in microseconds.\r
+ * @param[in, out] intf_ptr       : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs\r
  *  @return void.\r
  *\r
  */\r
-void user_delay_ms(uint32_t period);\r
+void user_delay_us(uint32_t period, void *intf_ptr);\r
 \r
 /*!\r
  * @brief Function for print the temperature, humidity and pressure data.\r
@@ -68,10 +84,11 @@ void print_sensor_data(struct bme280_data *comp_data);
 /*!\r
  *  @brief Function for reading the sensor's registers through I2C bus.\r
  *\r
- *  @param[in] id       : Sensor I2C address.\r
- *  @param[in] reg_addr : Register address.\r
- *  @param[out] data    : Pointer to the data buffer to store the read data.\r
- *  @param[in] len      : No of bytes to read.\r
+ *  @param[in] reg_addr       : Register address.\r
+ *  @param[out] data          : Pointer to the data buffer to store the read data.\r
+ *  @param[in] len            : No of bytes to read.\r
+ *  @param[in, out] intf_ptr  : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs.\r
  *\r
  *  @return Status of execution\r
  *\r
@@ -79,15 +96,16 @@ void print_sensor_data(struct bme280_data *comp_data);
  *  @retval > 0 -> Failure Info\r
  *\r
  */\r
-int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);\r
+int8_t user_i2c_read(uint8_t reg_addr, uint8_t *data, uint32_t len, void *intf_ptr);\r
 \r
 /*!\r
  *  @brief Function for writing the sensor's registers through I2C bus.\r
  *\r
- *  @param[in] id       : Sensor I2C address.\r
- *  @param[in] reg_addr : Register address.\r
- *  @param[in] data     : Pointer to the data buffer whose value is to be written.\r
- *  @param[in] len      : No of bytes to write.\r
+ *  @param[in] reg_addr       : Register address.\r
+ *  @param[in] data           : Pointer to the data buffer whose value is to be written.\r
+ *  @param[in] len            : No of bytes to write.\r
+ *  @param[in, out] intf_ptr  : Void pointer that can enable the linking of descriptors\r
+ *                                  for interface related call backs\r
  *\r
  *  @return Status of execution\r
  *\r
@@ -95,7 +113,7 @@ int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
  *  @retval BME280_E_COMM_FAIL -> Communication failure.\r
  *\r
  */\r
-int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);\r
+int8_t user_i2c_write(uint8_t reg_addr, const uint8_t *data, uint32_t len, void *intf_ptr);\r
 \r
 /*!\r
  * @brief Function reads temperature, humidity and pressure data in forced mode.\r
@@ -119,6 +137,8 @@ int main(int argc, char* argv[])
 {\r
     struct bme280_dev dev;\r
 \r
+    struct identifier id;\r
+\r
     /* Variable to define the result */\r
     int8_t rslt = BME280_OK;\r
 \r
@@ -128,29 +148,32 @@ int main(int argc, char* argv[])
         exit(1);\r
     }\r
 \r
-    /* Make sure to select BME280_I2C_ADDR_PRIM or BME280_I2C_ADDR_SEC as needed */\r
-    dev.dev_id = BME280_I2C_ADDR_PRIM;\r
-\r
-    /* dev.dev_id = BME280_I2C_ADDR_SEC; */\r
-    dev.intf = BME280_I2C_INTF;\r
-    dev.read = user_i2c_read;\r
-    dev.write = user_i2c_write;\r
-    dev.delay_ms = user_delay_ms;\r
-\r
-    if ((fd = open(argv[1], O_RDWR)) < 0)\r
+    if ((id.fd = open(argv[1], O_RDWR)) < 0)\r
     {\r
         fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]);\r
         exit(1);\r
     }\r
 \r
 #ifdef __KERNEL__\r
-    if (ioctl(fd, I2C_SLAVE, dev.dev_id) < 0)\r
+    if (ioctl(id.fd, I2C_SLAVE, id.dev_addr) < 0)\r
     {\r
         fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n");\r
         exit(1);\r
     }\r
+\r
 #endif\r
 \r
+    /* Make sure to select BME280_I2C_ADDR_PRIM or BME280_I2C_ADDR_SEC as needed */\r
+    id.dev_addr = BME280_I2C_ADDR_PRIM;\r
+\r
+    dev.intf = BME280_I2C_INTF;\r
+    dev.read = user_i2c_read;\r
+    dev.write = user_i2c_write;\r
+    dev.delay_us = user_delay_us;\r
+\r
+    /* Update interface pointer with the structure that contains both device address and file descriptor */\r
+    dev.intf_ptr = &id;\r
+\r
     /* Initialize the bme280 */\r
     rslt = bme280_init(&dev);\r
     if (rslt != BME280_OK)\r
@@ -172,10 +195,14 @@ int main(int argc, char* argv[])
 /*!\r
  * @brief This function reading the sensor's registers through I2C bus.\r
  */\r
-int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)\r
+int8_t user_i2c_read(uint8_t reg_addr, uint8_t *data, uint32_t len, void *intf_ptr)\r
 {\r
-    write(fd, &reg_addr, 1);\r
-    read(fd, data, len);\r
+    struct identifier id;\r
+\r
+    id = *((struct identifier *)intf_ptr);\r
+\r
+    write(id.fd, &reg_addr, 1);\r
+    read(id.fd, data, len);\r
 \r
     return 0;\r
 }\r
@@ -184,23 +211,25 @@ int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)
  * @brief This function provides the delay for required time (Microseconds) as per the input provided in some of the\r
  * APIs\r
  */\r
-void user_delay_ms(uint32_t period)\r
+void user_delay_us(uint32_t period, void *intf_ptr)\r
 {\r
-    /* Milliseconds convert to microseconds */\r
-    usleep(period * 1000);\r
+    usleep(period);\r
 }\r
 \r
 /*!\r
  * @brief This function for writing the sensor's registers through I2C bus.\r
  */\r
-int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len)\r
+int8_t user_i2c_write(uint8_t reg_addr, const uint8_t *data, uint32_t len, void *intf_ptr)\r
 {\r
-    int8_t *buf;\r
+    uint8_t *buf;\r
+    struct identifier id;\r
+\r
+    id = *((struct identifier *)intf_ptr);\r
 \r
     buf = malloc(len + 1);\r
     buf[0] = reg_addr;\r
     memcpy(buf + 1, data, len);\r
-    if (write(fd, buf, len + 1) < len)\r
+    if (write(id.fd, buf, len + 1) < (uint16_t)len)\r
     {\r
         return BME280_E_COMM_FAIL;\r
     }\r
@@ -287,7 +316,7 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
         }\r
 \r
         /* Wait for the measurement to complete and print data */\r
-        dev->delay_ms(req_delay);\r
+        dev->delay_us(req_delay, dev->intf_ptr);\r
         rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);\r
         if (rslt != BME280_OK)\r
         {\r