+ rslt = bme280_compensate_data(sensor_comp, &uncomp_data, comp_data, &dev->calib_data);
+ }
+ } else {
+ rslt = BME280_E_NULL_PTR;
+ }
+
+ return rslt;
+}
+
+/*!
+ * @brief This API is used to parse the pressure, temperature and
+ * humidity data and store it in the bme280_uncomp_data structure instance.
+ */
+void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data)
+{
+ /* Variables to store the sensor data */
+ uint32_t data_xlsb;
+ uint32_t data_lsb;
+ uint32_t data_msb;
+
+ /* Store the parsed register values for pressure data */
+ data_msb = (uint32_t)reg_data[0] << 12;
+ data_lsb = (uint32_t)reg_data[1] << 4;
+ data_xlsb = (uint32_t)reg_data[2] >> 4;
+ uncomp_data->pressure = data_msb | data_lsb | data_xlsb;
+
+ /* Store the parsed register values for temperature data */
+ data_msb = (uint32_t)reg_data[3] << 12;
+ data_lsb = (uint32_t)reg_data[4] << 4;
+ data_xlsb = (uint32_t)reg_data[5] >> 4;
+ uncomp_data->temperature = data_msb | data_lsb | data_xlsb;
+
+ /* Store the parsed register values for temperature data */
+ data_lsb = (uint32_t)reg_data[6] << 8;
+ data_msb = (uint32_t)reg_data[7];
+ uncomp_data->humidity = data_msb | data_lsb;
+}
+
+
+/*!
+ * @brief This API is used to compensate the pressure and/or
+ * temperature and/or humidity data according to the component selected
+ * by the user.
+ */
+int8_t bme280_compensate_data(uint8_t sensor_comp, const struct bme280_uncomp_data *uncomp_data,
+ struct bme280_data *comp_data, struct bme280_calib_data *calib_data)
+{
+ int8_t rslt = BME280_OK;
+
+ if ((uncomp_data != NULL) && (comp_data != NULL) && (calib_data != NULL)) {
+ /* Initialize to zero */
+ comp_data->temperature = 0;
+ comp_data->pressure = 0;
+ comp_data->humidity = 0;
+ /* If pressure or temperature component is selected */
+ if (sensor_comp & (BME280_PRESS | BME280_TEMP | BME280_HUM)) {
+ /* Compensate the temperature data */
+ comp_data->temperature = compensate_temperature(uncomp_data, calib_data);
+ }
+ if (sensor_comp & BME280_PRESS) {
+ /* Compensate the pressure data */
+ comp_data->pressure = compensate_pressure(uncomp_data, calib_data);
+ }
+ if (sensor_comp & BME280_HUM) {
+ /* Compensate the humidity data */
+ comp_data->humidity = compensate_humidity(uncomp_data, calib_data);