Lines Matching +full:temperature +full:- +full:coefficient
1 /* Driver for Infineon DPS310 temperature and pressure sensor */
6 * SPDX-License-Identifier: Apache-2.0
89 * Oversampling and measurement rates configuration for pressure and temperature
103 /* Helper macro to set temperature and pressure config register */
107 /* Setup constants depending on temperature oversampling factor */
225 /* Temperature Sensor Calibration Coefficients */
232 /* Temperature Values */
235 /* Last raw temperature value for temperature compensation */
253 /* Temperature sensor compensation values */ in dps310_calib_coeff_creation()
254 comp->c0 = (((uint16_t)raw_coef[0]) << 4) + (raw_coef[1] >> 4); in dps310_calib_coeff_creation()
255 /* coefficient is 2nd compliment */ in dps310_calib_coeff_creation()
256 if (comp->c0 > POW_2_11_MINUS_1) { in dps310_calib_coeff_creation()
257 comp->c0 = comp->c0 - POW_2_12; in dps310_calib_coeff_creation()
260 comp->c1 = (((uint16_t)(raw_coef[1] & 0x0F)) << 8) + raw_coef[2]; in dps310_calib_coeff_creation()
261 /* coefficient is 2nd compliment */ in dps310_calib_coeff_creation()
262 if (comp->c1 > POW_2_11_MINUS_1) { in dps310_calib_coeff_creation()
263 comp->c1 = comp->c1 - POW_2_12; in dps310_calib_coeff_creation()
267 comp->c00 = (((uint32_t)raw_coef[3]) << 12) + (((uint16_t)raw_coef[4]) << 4) + in dps310_calib_coeff_creation()
269 /* coefficient is 2nd compliment */ in dps310_calib_coeff_creation()
270 if (comp->c00 > POW_2_19_MINUS_1) { in dps310_calib_coeff_creation()
271 comp->c00 = comp->c00 - POW_2_20; in dps310_calib_coeff_creation()
274 comp->c10 = (((uint32_t)(raw_coef[5] & 0x0F)) << 16) + in dps310_calib_coeff_creation()
276 /* coefficient is 2nd compliment */ in dps310_calib_coeff_creation()
277 if (comp->c10 > POW_2_19_MINUS_1) { in dps310_calib_coeff_creation()
278 comp->c10 = comp->c10 - POW_2_20; in dps310_calib_coeff_creation()
281 comp->c01 = (int16_t) sys_get_be16(&raw_coef[8]); in dps310_calib_coeff_creation()
282 comp->c11 = (int16_t) sys_get_be16(&raw_coef[10]); in dps310_calib_coeff_creation()
283 comp->c20 = (int16_t) sys_get_be16(&raw_coef[12]); in dps310_calib_coeff_creation()
284 comp->c21 = (int16_t) sys_get_be16(&raw_coef[14]); in dps310_calib_coeff_creation()
285 comp->c30 = (int16_t) sys_get_be16(&raw_coef[16]); in dps310_calib_coeff_creation()
291 const struct dps310_cfg *config = dev->config; in poll_rdy()
295 int res = i2c_reg_read_byte_dt(&config->i2c, reg_addr, ®); in poll_rdy()
313 /* Trigger a temperature measurement and wait until the result is stored */
316 const struct dps310_cfg *config = dev->config; in dps310_trigger_temperature()
318 /* command to start temperature measurement */ in dps310_trigger_temperature()
324 /* trigger temperature measurement */ in dps310_trigger_temperature()
325 int res = i2c_write_dt(&config->i2c, tmp_meas_cmd, sizeof(tmp_meas_cmd)); in dps310_trigger_temperature()
335 LOG_DBG("Poll timeout for temperature"); in dps310_trigger_temperature()
345 const struct dps310_cfg *config = dev->config; in dps310_trigger_pressure()
354 int res = i2c_write_dt(&config->i2c, psr_meas_cmd, sizeof(psr_meas_cmd)); in dps310_trigger_pressure()
373 * you have this bug if you measure around 60°C when temperature is around 20°C
378 const struct dps310_cfg *config = dev->config; in dps310_hw_bug_fix()
388 /* Then update high gain value for Temperature */ in dps310_hw_bug_fix()
397 int res = i2c_write_dt(&config->i2c, hw_bug_fix_sequence[i], 2); in dps310_hw_bug_fix()
406 * Scale and compensate the raw temperature measurement value to micro °C
412 struct dps310_data *data = dev->data; in dps310_scale_temperature()
413 const struct dps310_cal_coeff *comp = &data->comp; in dps310_scale_temperature()
416 int32_t tmp_p0 = (1000000 / 2) * comp->c0; in dps310_scale_temperature()
420 (((int64_t)1000000) * comp->c1 * tmp_raw) / IFX_DPS310_SF_TMP; in dps310_scale_temperature()
422 /* calculate the temperature corresponding to the datasheet */ in dps310_scale_temperature()
426 data->tmp_val1 = tmp_final / 1000000; in dps310_scale_temperature()
427 data->tmp_val2 = tmp_final % 1000000; in dps310_scale_temperature()
431 * Scale and temperature compensate the raw pressure measurement value to
436 struct dps310_data *data = dev->data; in dps310_scale_pressure()
437 const struct dps310_cal_coeff *comp = &data->comp; in dps310_scale_pressure()
443 float psr_final = comp->c00; in dps310_scale_pressure()
445 psr_final += psr * (comp->c10 + psr * (comp->c20 + psr * comp->c30)); in dps310_scale_pressure()
446 psr_final += tmp * comp->c01; in dps310_scale_pressure()
447 psr_final += tmp * psr * (comp->c11 + psr * comp->c21); in dps310_scale_pressure()
453 data->psr_val1 = psr_final; in dps310_scale_pressure()
454 data->psr_val2 = (psr_final - data->psr_val1) * 1000000; in dps310_scale_pressure()
464 res -= POW_2_24; in raw_to_int24()
470 /* perform a single measurement of temperature and pressure */
473 struct dps310_data *data = dev->data; in dps310_measure_tmp_psr()
474 const struct dps310_cfg *config = dev->config; in dps310_measure_tmp_psr()
484 /* memory for pressure and temperature raw values */ in dps310_measure_tmp_psr()
487 /* read pressure and temperature raw values in one continuous read */ in dps310_measure_tmp_psr()
488 int res = i2c_write_read_dt(&config->i2c, ®_ADDR_PSR_B2, 1, in dps310_measure_tmp_psr()
498 data->raw_tmp = raw_to_int24(&value_raw[3]); in dps310_measure_tmp_psr()
500 dps310_scale_temperature(dev, data->raw_tmp); in dps310_measure_tmp_psr()
501 dps310_scale_pressure(dev, data->raw_tmp, psr_raw); in dps310_measure_tmp_psr()
508 * uses the stored temperature value for sensor temperature compensation
509 * temperature must be measured regularly for good temperature compensation
513 struct dps310_data *data = dev->data; in dps310_measure_psr()
514 const struct dps310_cfg *config = dev->config; in dps310_measure_psr()
525 int res = i2c_write_read_dt(&config->i2c, ®_ADDR_PSR_B2, 1, in dps310_measure_psr()
535 dps310_scale_pressure(dev, data->raw_tmp, psr_raw); in dps310_measure_psr()
540 /* perform a single temperature measurement */
543 struct dps310_data *data = dev->data; in dps310_measure_tmp()
544 const struct dps310_cfg *config = dev->config; in dps310_measure_tmp()
546 /* measure temperature */ in dps310_measure_tmp()
551 /* memory for temperature raw value */ in dps310_measure_tmp()
554 /* read temperature raw values in one continuous read */ in dps310_measure_tmp()
555 int res = i2c_write_read_dt(&config->i2c, ®_ADDR_TMP_B2, 1, in dps310_measure_tmp()
563 data->raw_tmp = raw_to_int24(&value_raw[0]); in dps310_measure_tmp()
565 dps310_scale_temperature(dev, data->raw_tmp); in dps310_measure_tmp()
573 struct dps310_data *data = dev->data; in dps310_init()
574 const struct dps310_cfg *config = dev->config; in dps310_init()
576 if (!device_is_ready(config->i2c.bus)) { in dps310_init()
578 return -ENODEV; in dps310_init()
582 int res = i2c_reg_read_byte_dt(&config->i2c, IFX_DPS310_REG_ADDR_PRODUCT_ID, &product_id); in dps310_init()
586 return -EINVAL; in dps310_init()
591 return -EINVAL; in dps310_init()
601 return -EIO; in dps310_init()
607 res = i2c_write_read_dt(&config->i2c, ®_ADDR_CALIB_COEFF_0, 1, &raw_coef, 18); in dps310_init()
610 return -EIO; in dps310_init()
614 dps310_calib_coeff_creation(raw_coef, &data->comp); in dps310_init()
617 * check which temperature sensor was used for calibration and use it in dps310_init()
622 res = i2c_write_read_dt(&config->i2c, ®_ADDR_COEF_SRCE, 1, &tmp_coef_srce, in dps310_init()
626 return -EIO; in dps310_init()
632 /* merge with temperature measurement configuration */ in dps310_init()
644 res = i2c_write_dt(&config->i2c, config_seq, sizeof(config_seq)); in dps310_init()
647 return -EIO; in dps310_init()
666 LOG_ERR("Failed to measure temperature"); in dps310_sample_fetch()
667 return -EIO; in dps310_sample_fetch()
673 return -EIO; in dps310_sample_fetch()
678 LOG_ERR("Failed to measure temperature and pressure"); in dps310_sample_fetch()
679 return -EIO; in dps310_sample_fetch()
683 return -EINVAL; in dps310_sample_fetch()
694 struct dps310_data *data = dev->data; in dps310_channel_get()
698 val->val1 = data->tmp_val1; in dps310_channel_get()
699 val->val2 = data->tmp_val2; in dps310_channel_get()
702 val->val1 = data->psr_val1; in dps310_channel_get()
703 val->val2 = data->psr_val2; in dps310_channel_get()
706 return -ENOTSUP; in dps310_channel_get()