EFR32 Mighty Gecko 1 Software Documentation  efr32mg1-doc-5.1.2
bmp280.c
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  * Copyright (C) 2015 - 2016 Bosch Sensortec GmbH
4  *
5  * File : bmp280.c
6  *
7  * Date : 2016/07/01
8  *
9  * Revision : 2.0.5(Pressure and Temperature compensation code revision is 1.1)
10  *
11  * Usage: Sensor Driver for BMP280 sensor
12  *
13  ****************************************************************************
14 *
15 * \section License
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are met:
19 *
20 * Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 *
23 * Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 *
27 * Neither the name of the copyright holder nor the names of the
28 * contributors may be used to endorse or promote products derived from
29 * this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
32 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
33 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
36 * OR CONTRIBUTORS BE LIABLE FOR ANY
37 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
38 * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
39 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
44 * ANY WAY OUT OF THE USE OF THIS
45 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
46 *
47 * The information provided is believed to be accurate and reliable.
48 * The copyright holder assumes no responsibility
49 * for the consequences of use
50 * of such information nor for any infringement of patents or
51 * other rights of third parties which may result from its use.
52 * No license is granted by implication or otherwise under any patent or
53 * patent rights of the copyright holder.
54 **************************************************************************/
57 #include "bmp280.h"
58 static struct bmp280_t *p_bmp280;
85 BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280)
86 {
87  /* variable used to return communication result*/
88  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
89  u8 v_data_u8 = BMP280_INIT_VALUE;
90  u8 v_chip_id_read_count = BMP280_CHIP_ID_READ_COUNT;
91 
92  p_bmp280 = bmp280;/* assign BMP280 ptr */
93 
94  while (v_chip_id_read_count > 0) {
95  /* read chip id */
96  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
97  BMP280_CHIP_ID_REG, &v_data_u8,
98  BMP280_GEN_READ_WRITE_DATA_LENGTH);
99  /* Check for the correct chip id */
100  if ((v_data_u8 == BMP280_CHIP_ID1)
101  || (v_data_u8 == BMP280_CHIP_ID2)
102  || (v_data_u8 == BMP280_CHIP_ID3))
103  break;
104  v_chip_id_read_count--;
105  /* Delay added concerning the low speed of power up system to
106  facilitate the proper reading of the chip ID */
107  p_bmp280->delay_msec(BMP280_REGISTER_READ_DELAY);
108  }
109 
110  /*assign chip ID to the global structure*/
111  p_bmp280->chip_id = v_data_u8;
112  /*com_rslt status of chip ID read*/
113  com_rslt = (v_chip_id_read_count == BMP280_INIT_VALUE) ?
114  BMP280_CHIP_ID_READ_FAIL : BMP280_CHIP_ID_READ_SUCCESS;
115 
116  if (com_rslt == BMP280_CHIP_ID_READ_SUCCESS) {
117  /* readout bmp280 calibration parameter structure */
118  com_rslt += bmp280_get_calib_param();
119  }
120  return com_rslt;
121 }
139 BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_temperature(
140  s32 *v_uncomp_temperature_s32)
141 {
142  /* variable used to return communication result*/
143  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
144  /* Array holding the MSB and LSb value
145  a_data_u8r[0] - Temperature MSB
146  a_data_u8r[1] - Temperature LSB
147  a_data_u8r[2] - Temperature LSB
148  */
149  u8 a_data_u8r[BMP280_TEMPERATURE_DATA_SIZE] = {BMP280_INIT_VALUE,
150  BMP280_INIT_VALUE, BMP280_INIT_VALUE};
151  /* check the p_bmp280 structure pointer as NULL*/
152  if (p_bmp280 == BMP280_NULL) {
153  com_rslt = E_BMP280_NULL_PTR;
154  } else {
155  /* read temperature data */
156  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
157  BMP280_TEMPERATURE_MSB_REG, a_data_u8r,
158  BMP280_TEMPERATURE_DATA_LENGTH);
159  *v_uncomp_temperature_s32 = (s32)((((u32)(
160  a_data_u8r[BMP280_TEMPERATURE_MSB_DATA]))
161  << BMP280_SHIFT_BIT_POSITION_BY_12_BITS)
162  | (((u32)(
163  a_data_u8r[BMP280_TEMPERATURE_LSB_DATA]))
164  << BMP280_SHIFT_BIT_POSITION_BY_04_BITS)
165  | ((u32)a_data_u8r[BMP280_TEMPERATURE_XLSB_DATA]
166  >> BMP280_SHIFT_BIT_POSITION_BY_04_BITS));
167  }
168  return com_rslt;
169 }
185 s32 bmp280_compensate_temperature_int32(s32 v_uncomp_temperature_s32)
186 {
187  s32 v_x1_u32r = BMP280_INIT_VALUE;
188  s32 v_x2_u32r = BMP280_INIT_VALUE;
189  s32 temperature = BMP280_INIT_VALUE;
190  /* calculate true temperature*/
191  /*calculate x1*/
192  v_x1_u32r = ((((v_uncomp_temperature_s32
193  >> BMP280_SHIFT_BIT_POSITION_BY_03_BITS)
194  - ((s32)p_bmp280->calib_param.dig_T1
195  << BMP280_SHIFT_BIT_POSITION_BY_01_BIT)))
196  * ((s32)p_bmp280->calib_param.dig_T2))
197  >> BMP280_SHIFT_BIT_POSITION_BY_11_BITS;
198  /*calculate x2*/
199  v_x2_u32r = (((((v_uncomp_temperature_s32
200  >> BMP280_SHIFT_BIT_POSITION_BY_04_BITS)
201  - ((s32)p_bmp280->calib_param.dig_T1))
202  * ((v_uncomp_temperature_s32
203  >> BMP280_SHIFT_BIT_POSITION_BY_04_BITS)
204  - ((s32)p_bmp280->calib_param.dig_T1)))
205  >> BMP280_SHIFT_BIT_POSITION_BY_12_BITS)
206  * ((s32)p_bmp280->calib_param.dig_T3))
207  >> BMP280_SHIFT_BIT_POSITION_BY_14_BITS;
208  /*calculate t_fine*/
209  p_bmp280->calib_param.t_fine = v_x1_u32r + v_x2_u32r;
210  /*calculate temperature*/
211  temperature = (p_bmp280->calib_param.t_fine * 5 + 128)
212  >> BMP280_SHIFT_BIT_POSITION_BY_08_BITS;
213 
214  return temperature;
215 }
235 BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure(
236  s32 *v_uncomp_pressure_s32)
237 {
238  /* variable used to return communication result*/
239  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
240  /* Array holding the MSB and LSb value
241  a_data_u8[0] - Pressure MSB
242  a_data_u8[1] - Pressure LSB
243  a_data_u8[2] - Pressure LSB
244  */
245  u8 a_data_u8[BMP280_PRESSURE_DATA_SIZE] = {BMP280_INIT_VALUE,
246  BMP280_INIT_VALUE, BMP280_INIT_VALUE};
247  /* check the p_bmp280 structure pointer as NULL*/
248  if (p_bmp280 == BMP280_NULL) {
249  com_rslt = E_BMP280_NULL_PTR;
250  } else {
251  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
252  BMP280_PRESSURE_MSB_REG, a_data_u8,
253  BMP280_PRESSURE_DATA_LENGTH);
254  *v_uncomp_pressure_s32 = (s32)((((u32)(
255  a_data_u8[BMP280_PRESSURE_MSB_DATA]))
256  << BMP280_SHIFT_BIT_POSITION_BY_12_BITS)
257  | (((u32)(a_data_u8[BMP280_PRESSURE_LSB_DATA]))
258  << BMP280_SHIFT_BIT_POSITION_BY_04_BITS)
259  | ((u32)a_data_u8[BMP280_PRESSURE_XLSB_DATA]
260  >> BMP280_SHIFT_BIT_POSITION_BY_04_BITS));
261  }
262  return com_rslt;
263 }
281 {
282  s32 v_x1_u32r = BMP280_INIT_VALUE;
283  s32 v_x2_u32r = BMP280_INIT_VALUE;
284  u32 v_pressure_u32 = BMP280_INIT_VALUE;
285  /* calculate x1*/
286  v_x1_u32r = (((s32)p_bmp280->calib_param.t_fine)
287  >> BMP280_SHIFT_BIT_POSITION_BY_01_BIT) - (s32)64000;
288  /* calculate x2*/
289  v_x2_u32r = (((v_x1_u32r >> BMP280_SHIFT_BIT_POSITION_BY_02_BITS)
290  * (v_x1_u32r >> BMP280_SHIFT_BIT_POSITION_BY_02_BITS))
291  >> BMP280_SHIFT_BIT_POSITION_BY_11_BITS)
292  * ((s32)p_bmp280->calib_param.dig_P6);
293  v_x2_u32r = v_x2_u32r + ((v_x1_u32r *
294  ((s32)p_bmp280->calib_param.dig_P5))
295  << BMP280_SHIFT_BIT_POSITION_BY_01_BIT);
296  v_x2_u32r = (v_x2_u32r >> BMP280_SHIFT_BIT_POSITION_BY_02_BITS)
297  + (((s32)p_bmp280->calib_param.dig_P4)
298  << BMP280_SHIFT_BIT_POSITION_BY_16_BITS);
299  /* calculate x1*/
300  v_x1_u32r = (((p_bmp280->calib_param.dig_P3
301  * (((v_x1_u32r
302  >> BMP280_SHIFT_BIT_POSITION_BY_02_BITS) * (v_x1_u32r
303  >> BMP280_SHIFT_BIT_POSITION_BY_02_BITS))
304  >> BMP280_SHIFT_BIT_POSITION_BY_13_BITS))
305  >> BMP280_SHIFT_BIT_POSITION_BY_03_BITS)
306  + ((((s32)p_bmp280->calib_param.dig_P2)
307  * v_x1_u32r)
308  >> BMP280_SHIFT_BIT_POSITION_BY_01_BIT))
309  >> BMP280_SHIFT_BIT_POSITION_BY_18_BITS;
310  v_x1_u32r = ((((32768 + v_x1_u32r))
311  * ((s32)p_bmp280->calib_param.dig_P1))
312  >> BMP280_SHIFT_BIT_POSITION_BY_15_BITS);
313  /* calculate pressure*/
314  v_pressure_u32 = (((u32)(((s32)1048576) - v_uncomp_pressure_s32)
315  - (v_x2_u32r >> BMP280_SHIFT_BIT_POSITION_BY_12_BITS)))
316  * 3125;
317  /* check overflow*/
318  if (v_pressure_u32 < 0x80000000)
319  /* Avoid exception caused by division by zero */
320  if (v_x1_u32r != BMP280_INIT_VALUE)
321  v_pressure_u32 = (v_pressure_u32
322  << BMP280_SHIFT_BIT_POSITION_BY_01_BIT)
323  / ((u32)v_x1_u32r);
324  else
325  return BMP280_INVALID_DATA;
326  else
327  /* Avoid exception caused by division by zero */
328  if (v_x1_u32r != BMP280_INIT_VALUE)
329  v_pressure_u32 = (v_pressure_u32 / (u32)v_x1_u32r) * 2;
330  else
331  return BMP280_INVALID_DATA;
332  /* calculate x1*/
333  v_x1_u32r = (((s32)p_bmp280->calib_param.dig_P9) * ((s32)(
334  ((v_pressure_u32
335  >> BMP280_SHIFT_BIT_POSITION_BY_03_BITS)
336  * (v_pressure_u32
337  >> BMP280_SHIFT_BIT_POSITION_BY_03_BITS))
338  >> BMP280_SHIFT_BIT_POSITION_BY_13_BITS)))
339  >> BMP280_SHIFT_BIT_POSITION_BY_12_BITS;
340  /* calculate x2*/
341  v_x2_u32r = (((s32)(v_pressure_u32 >>
342  BMP280_SHIFT_BIT_POSITION_BY_02_BITS))
343  * ((s32)p_bmp280->calib_param.dig_P8))
344  >> BMP280_SHIFT_BIT_POSITION_BY_13_BITS;
345  /* calculate true pressure*/
346  v_pressure_u32 = (u32)((s32)v_pressure_u32 + ((v_x1_u32r + v_x2_u32r
347  + p_bmp280->calib_param.dig_P7)
348  >> BMP280_SHIFT_BIT_POSITION_BY_04_BITS));
349 
350  return v_pressure_u32;
351 }
364 BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure_temperature(
365  s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32)
366 {
367  /* variable used to return communication result*/
368  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
369  /* Array holding the temperature and pressure data
370  a_data_u8[0] - Pressure MSB
371  a_data_u8[1] - Pressure LSB
372  a_data_u8[2] - Pressure LSB
373  a_data_u8[3] - Temperature MSB
374  a_data_u8[4] - Temperature LSB
375  a_data_u8[5] - Temperature LSB
376  */
377  u8 a_data_u8[BMP280_ALL_DATA_FRAME_LENGTH] = {BMP280_INIT_VALUE,
378  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
379  BMP280_INIT_VALUE, BMP280_INIT_VALUE};
380  /* check the p_bmp280 structure pointer as NULL*/
381  if (p_bmp280 == BMP280_NULL) {
382  com_rslt = E_BMP280_NULL_PTR;
383  } else {
384  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
385  BMP280_PRESSURE_MSB_REG, a_data_u8,
386  BMP280_DATA_FRAME_SIZE);
387  /*Pressure*/
388  *v_uncomp_pressure_s32 = (s32)((((u32)(
389  a_data_u8[BMP280_DATA_FRAME_PRESSURE_MSB_BYTE]))
390  << BMP280_SHIFT_BIT_POSITION_BY_12_BITS)
391  | (((u32)(
392  a_data_u8[BMP280_DATA_FRAME_PRESSURE_LSB_BYTE]))
393  << BMP280_SHIFT_BIT_POSITION_BY_04_BITS)
394  | ((u32)a_data_u8[
395  BMP280_DATA_FRAME_PRESSURE_XLSB_BYTE]
396  >> BMP280_SHIFT_BIT_POSITION_BY_04_BITS));
397 
398  /* Temperature */
399  *v_uncomp_temperature_s32 = (s32)((((u32)(a_data_u8[
400  BMP280_DATA_FRAME_TEMPERATURE_MSB_BYTE]))
401  << BMP280_SHIFT_BIT_POSITION_BY_12_BITS)
402  | (((u32)(a_data_u8[
403  BMP280_DATA_FRAME_TEMPERATURE_LSB_BYTE]))
404  << BMP280_SHIFT_BIT_POSITION_BY_04_BITS)
405  | ((u32)a_data_u8[
406  BMP280_DATA_FRAME_TEMPERATURE_XLSB_BYTE]
407  >> BMP280_SHIFT_BIT_POSITION_BY_04_BITS));
408  }
409  return com_rslt;
410 }
425 BMP280_RETURN_FUNCTION_TYPE bmp280_read_pressure_temperature(
426  u32 *v_pressure_u32, s32 *v_temperature_s32)
427 {
428  /* variable used to return communication result*/
429  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
430  s32 v_uncomp_pressure_s32 = BMP280_INIT_VALUE;
431  s32 v_uncomp_temperature_s32 = BMP280_INIT_VALUE;
432  /* check the p_bmp280 structure pointer as NULL*/
433  if (p_bmp280 == BMP280_NULL) {
434  com_rslt = E_BMP280_NULL_PTR;
435  } else {
436  /* read uncompensated pressure and temperature*/
438  &v_uncomp_pressure_s32,
439  &v_uncomp_temperature_s32);
440  /* read true pressure and temperature*/
441  *v_temperature_s32 = bmp280_compensate_temperature_int32(
442  v_uncomp_temperature_s32);
443  *v_pressure_u32 = bmp280_compensate_pressure_int32(
444  v_uncomp_pressure_s32);
445  }
446  return com_rslt;
447 }
473 BMP280_RETURN_FUNCTION_TYPE bmp280_get_calib_param(void)
474 {
475  /* variable used to return communication result*/
476  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
477  u8 a_data_u8[BMP280_CALIB_DATA_SIZE] = {BMP280_INIT_VALUE,
478  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
479  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
480  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
481  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
482  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
483  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
484  BMP280_INIT_VALUE, BMP280_INIT_VALUE, BMP280_INIT_VALUE,
485  BMP280_INIT_VALUE, BMP280_INIT_VALUE};
486  /* check the p_bmp280 structure pointer as NULL*/
487  if (p_bmp280 == BMP280_NULL) {
488  com_rslt = E_BMP280_NULL_PTR;
489  } else {
490  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
491  BMP280_TEMPERATURE_CALIB_DIG_T1_LSB_REG,
492  a_data_u8,
493  BMP280_PRESSURE_TEMPERATURE_CALIB_DATA_LENGTH);
494  /* read calibration values*/
495  p_bmp280->calib_param.dig_T1 = (u16)((((u16)((u8)a_data_u8[
496  BMP280_TEMPERATURE_CALIB_DIG_T1_MSB]))
497  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
498  | a_data_u8[
499  BMP280_TEMPERATURE_CALIB_DIG_T1_LSB]);
500  p_bmp280->calib_param.dig_T2 = (s16)((((s16)((s8)a_data_u8[
501  BMP280_TEMPERATURE_CALIB_DIG_T2_MSB]))
502  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
503  | a_data_u8[
504  BMP280_TEMPERATURE_CALIB_DIG_T2_LSB]);
505  p_bmp280->calib_param.dig_T3 = (s16)((((s16)((s8)a_data_u8[
506  BMP280_TEMPERATURE_CALIB_DIG_T3_MSB]))
507  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
508  | a_data_u8[
509  BMP280_TEMPERATURE_CALIB_DIG_T3_LSB]);
510  p_bmp280->calib_param.dig_P1 = (u16)((((u16)((u8)a_data_u8[
511  BMP280_PRESSURE_CALIB_DIG_P1_MSB]))
512  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
513  | a_data_u8[
514  BMP280_PRESSURE_CALIB_DIG_P1_LSB]);
515  p_bmp280->calib_param.dig_P2 = (s16)((((s16)((s8)a_data_u8[
516  BMP280_PRESSURE_CALIB_DIG_P2_MSB]))
517  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
518  | a_data_u8[
519  BMP280_PRESSURE_CALIB_DIG_P2_LSB]);
520  p_bmp280->calib_param.dig_P3 = (s16)((((s16)((s8)a_data_u8[
521  BMP280_PRESSURE_CALIB_DIG_P3_MSB]))
522  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
523  | a_data_u8[
524  BMP280_PRESSURE_CALIB_DIG_P3_LSB]);
525  p_bmp280->calib_param.dig_P4 = (s16)((((s16)((s8)a_data_u8[
526  BMP280_PRESSURE_CALIB_DIG_P4_MSB]))
527  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
528  | a_data_u8[
529  BMP280_PRESSURE_CALIB_DIG_P4_LSB]);
530  p_bmp280->calib_param.dig_P5 = (s16)((((s16)((s8)a_data_u8[
531  BMP280_PRESSURE_CALIB_DIG_P5_MSB]))
532  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
533  | a_data_u8[
534  BMP280_PRESSURE_CALIB_DIG_P5_LSB]);
535  p_bmp280->calib_param.dig_P6 = (s16)((((s16)((s8)a_data_u8[
536  BMP280_PRESSURE_CALIB_DIG_P6_MSB]))
537  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
538  | a_data_u8[
539  BMP280_PRESSURE_CALIB_DIG_P6_LSB]);
540  p_bmp280->calib_param.dig_P7 = (s16)((((s16)((s8)a_data_u8[
541  BMP280_PRESSURE_CALIB_DIG_P7_MSB]))
542  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
543  | a_data_u8[
544  BMP280_PRESSURE_CALIB_DIG_P7_LSB]);
545  p_bmp280->calib_param.dig_P8 = (s16)((((s16)((s8)a_data_u8[
546  BMP280_PRESSURE_CALIB_DIG_P8_MSB]))
547  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
548  | a_data_u8[
549  BMP280_PRESSURE_CALIB_DIG_P8_LSB]);
550  p_bmp280->calib_param.dig_P9 = (s16)((((s16)((s8)a_data_u8[
551  BMP280_PRESSURE_CALIB_DIG_P9_MSB]))
552  << BMP280_SHIFT_BIT_POSITION_BY_08_BITS)
553  | a_data_u8[
554  BMP280_PRESSURE_CALIB_DIG_P9_LSB]);
555  }
556  return com_rslt;
557 }
583 BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_temperature(u8 *v_value_u8)
584 {
585  /* variable used to return communication result*/
586  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
587  u8 v_data_u8 = BMP280_INIT_VALUE;
588  /* check the p_bmp280 structure pointer as NULL*/
589  if (p_bmp280 == BMP280_NULL) {
590  com_rslt = E_BMP280_NULL_PTR;
591  } else {
592  /* read temperature over sampling*/
593  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
594  BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG,
595  &v_data_u8, BMP280_GEN_READ_WRITE_DATA_LENGTH);
596  *v_value_u8 = BMP280_GET_BITSLICE(v_data_u8,
597  BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE);
598  /* assign temperature oversampling*/
599  p_bmp280->oversamp_temperature = *v_value_u8;
600  }
601  return com_rslt;
602 }
628 BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_temperature(u8 v_value_u8)
629 {
630  /* variable used to return communication result*/
631  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
632  u8 v_data_u8 = BMP280_INIT_VALUE;
633  /* check the p_bmp280 structure pointer as NULL*/
634  if (p_bmp280 == BMP280_NULL) {
635  com_rslt = E_BMP280_NULL_PTR;
636  } else {
637  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
638  BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG,
639  &v_data_u8, BMP280_GEN_READ_WRITE_DATA_LENGTH);
640  if (com_rslt == SUCCESS) {
641  /* write over sampling*/
642  v_data_u8 = BMP280_SET_BITSLICE(v_data_u8,
643  BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE,
644  v_value_u8);
645  com_rslt += p_bmp280->BMP280_BUS_WRITE_FUNC(
646  p_bmp280->dev_addr,
647  BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG,
648  &v_data_u8,
649  BMP280_GEN_READ_WRITE_DATA_LENGTH);
650  p_bmp280->oversamp_temperature = v_value_u8;
651  }
652  }
653  return com_rslt;
654 }
680 BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_pressure(u8 *v_value_u8)
681 {
682  /* variable used to return communication result*/
683  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
684  u8 v_data_u8 = BMP280_INIT_VALUE;
685  /* check the p_bmp280 structure pointer as NULL*/
686  if (p_bmp280 == BMP280_NULL) {
687  com_rslt = E_BMP280_NULL_PTR;
688  } else {
689  /* read pressure over sampling */
690  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
691  BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG,
692  &v_data_u8, BMP280_GEN_READ_WRITE_DATA_LENGTH);
693  *v_value_u8 = BMP280_GET_BITSLICE(v_data_u8,
694  BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE);
695 
696  p_bmp280->oversamp_pressure = *v_value_u8;
697  }
698  return com_rslt;
699 }
725 BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_pressure(u8 v_value_u8)
726 {
727  /* variable used to return communication result*/
728  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
729  u8 v_data_u8 = BMP280_INIT_VALUE;
730  /* check the p_bmp280 structure pointer as NULL*/
731  if (p_bmp280 == BMP280_NULL) {
732  com_rslt = E_BMP280_NULL_PTR;
733  } else {
734  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
735  BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG,
736  &v_data_u8, BMP280_GEN_READ_WRITE_DATA_LENGTH);
737  if (com_rslt == SUCCESS) {
738  /* write pressure over sampling */
739  v_data_u8 = BMP280_SET_BITSLICE(v_data_u8,
740  BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE,
741  v_value_u8);
742  com_rslt += p_bmp280->BMP280_BUS_WRITE_FUNC(
743  p_bmp280->dev_addr,
744  BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG,
745  &v_data_u8,
746  BMP280_GEN_READ_WRITE_DATA_LENGTH);
747 
748  p_bmp280->oversamp_pressure = v_value_u8;
749  }
750  }
751  return com_rslt;
752 }
772 BMP280_RETURN_FUNCTION_TYPE bmp280_get_power_mode(u8 *v_power_mode_u8)
773 {
774  /* variable used to return communication result*/
775  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
776  u8 v_mode_u8 = BMP280_INIT_VALUE;
777  /* check the p_bmp280 structure pointer as NULL*/
778  if (p_bmp280 == BMP280_NULL) {
779  com_rslt = E_BMP280_NULL_PTR;
780  } else {
781  /* read the power mode*/
782  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
783  BMP280_CTRL_MEAS_REG_POWER_MODE__REG,
784  &v_mode_u8, BMP280_GEN_READ_WRITE_DATA_LENGTH);
785  *v_power_mode_u8 = BMP280_GET_BITSLICE(v_mode_u8,
786  BMP280_CTRL_MEAS_REG_POWER_MODE);
787  }
788  return com_rslt;
789 }
809 BMP280_RETURN_FUNCTION_TYPE bmp280_set_power_mode(u8 v_power_mode_u8)
810 {
811  /* variable used to return communication result*/
812  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
813  u8 v_mode_u8 = BMP280_INIT_VALUE;
814  /* check the p_bmp280 structure pointer as NULL*/
815  if (p_bmp280 == BMP280_NULL) {
816  com_rslt = E_BMP280_NULL_PTR;
817  } else {
818  if (v_power_mode_u8 <= BMP280_NORMAL_MODE) {
819  /* write the power mode*/
820  v_mode_u8 = (p_bmp280->oversamp_temperature
821  << BMP280_SHIFT_BIT_POSITION_BY_05_BITS)
822  + (p_bmp280->oversamp_pressure
823  << BMP280_SHIFT_BIT_POSITION_BY_02_BITS)
824  + v_power_mode_u8;
825  com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC(
826  p_bmp280->dev_addr,
827  BMP280_CTRL_MEAS_REG_POWER_MODE__REG,
828  &v_mode_u8,
829  BMP280_GEN_READ_WRITE_DATA_LENGTH);
830  } else {
831  com_rslt = E_BMP280_OUT_OF_RANGE;
832  }
833  }
834  return com_rslt;
835 }
852 BMP280_RETURN_FUNCTION_TYPE bmp280_set_soft_rst(void)
853 {
854  /* variable used to return communication result*/
855  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
856  u8 v_data_u8 = BMP280_SOFT_RESET_CODE;
857  /* check the p_bmp280 structure pointer as NULL*/
858  if (p_bmp280 == BMP280_NULL) {
859  com_rslt = E_BMP280_NULL_PTR;
860  } else {
861  /* write soft reset */
862  com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr,
863  BMP280_RST_REG, &v_data_u8,
864  BMP280_GEN_READ_WRITE_DATA_LENGTH);
865  }
866  return com_rslt;
867 }
888 BMP280_RETURN_FUNCTION_TYPE bmp280_get_spi3(u8 *v_enable_disable_u8)
889 {
890  /* variable used to return communication result*/
891  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
892  u8 v_data_u8 = BMP280_INIT_VALUE;
893  /* check the p_bmp280 structure pointer as NULL*/
894  if (p_bmp280 == BMP280_NULL) {
895  com_rslt = E_BMP280_NULL_PTR;
896  } else {
897  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
898  BMP280_CONFIG_REG_SPI3_ENABLE__REG, &v_data_u8,
899  BMP280_GEN_READ_WRITE_DATA_LENGTH);
900  *v_enable_disable_u8 = BMP280_GET_BITSLICE(v_data_u8,
901  BMP280_CONFIG_REG_SPI3_ENABLE);
902  }
903  return com_rslt;
904 }
925 BMP280_RETURN_FUNCTION_TYPE bmp280_set_spi3(u8 v_enable_disable_u8)
926 {
927  /* variable used to return communication result*/
928  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
929  u8 v_data_u8 = BMP280_INIT_VALUE;
930  /* check the p_bmp280 structure pointer as NULL*/
931  if (p_bmp280 == BMP280_NULL) {
932  com_rslt = E_BMP280_NULL_PTR;
933  } else {
934  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
935  BMP280_CONFIG_REG_SPI3_ENABLE__REG, &v_data_u8,
936  BMP280_GEN_READ_WRITE_DATA_LENGTH);
937  if (com_rslt == SUCCESS) {
938  v_data_u8 = BMP280_SET_BITSLICE(v_data_u8,
939  BMP280_CONFIG_REG_SPI3_ENABLE,
940  v_enable_disable_u8);
941  com_rslt += p_bmp280->BMP280_BUS_WRITE_FUNC(
942  p_bmp280->dev_addr,
943  BMP280_CONFIG_REG_SPI3_ENABLE__REG,
944  &v_data_u8,
945  BMP280_GEN_READ_WRITE_DATA_LENGTH);
946  }
947  }
948  return com_rslt;
949 }
971 BMP280_RETURN_FUNCTION_TYPE bmp280_get_filter(u8 *v_value_u8)
972 {
973  /* variable used to return communication result*/
974  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
975  u8 v_data_u8 = BMP280_INIT_VALUE;
976  /* check the p_bmp280 structure pointer as NULL*/
977  if (p_bmp280 == BMP280_NULL) {
978  com_rslt = E_BMP280_NULL_PTR;
979  } else {
980  /* read filter*/
981  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
982  BMP280_CONFIG_REG_FILTER__REG, &v_data_u8,
983  BMP280_GEN_READ_WRITE_DATA_LENGTH);
984  *v_value_u8 = BMP280_GET_BITSLICE(v_data_u8,
985  BMP280_CONFIG_REG_FILTER);
986  }
987  return com_rslt;
988 }
1010 BMP280_RETURN_FUNCTION_TYPE bmp280_set_filter(u8 v_value_u8)
1011 {
1012  BMP280_RETURN_FUNCTION_TYPE com_rslt = SUCCESS;
1013  u8 v_data_u8 = BMP280_INIT_VALUE;
1014  /* check the p_bmp280 structure pointer as NULL*/
1015  if (p_bmp280 == BMP280_NULL) {
1016  com_rslt = E_BMP280_NULL_PTR;
1017  } else {
1018  /* write filter*/
1019  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
1020  BMP280_CONFIG_REG_FILTER__REG, &v_data_u8,
1021  BMP280_GEN_READ_WRITE_DATA_LENGTH);
1022  if (com_rslt == SUCCESS) {
1023  v_data_u8 = BMP280_SET_BITSLICE(v_data_u8,
1024  BMP280_CONFIG_REG_FILTER, v_value_u8);
1025  com_rslt += p_bmp280->BMP280_BUS_WRITE_FUNC(
1026  p_bmp280->dev_addr,
1027  BMP280_CONFIG_REG_FILTER__REG,
1028  &v_data_u8,
1029  BMP280_GEN_READ_WRITE_DATA_LENGTH);
1030  }
1031  }
1032  return com_rslt;
1033 }
1058 BMP280_RETURN_FUNCTION_TYPE bmp280_get_standby_durn(u8 *v_standby_durn_u8)
1059 {
1060  /* variable used to return communication result*/
1061  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
1062  u8 v_data_u8 = BMP280_INIT_VALUE;
1063  /* check the p_bmp280 structure pointer as NULL*/
1064  if (p_bmp280 == BMP280_NULL) {
1065  com_rslt = E_BMP280_NULL_PTR;
1066  } else {
1067  /* read the standby duration*/
1068  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
1069  BMP280_CONFIG_REG_STANDBY_DURN__REG, &v_data_u8,
1070  BMP280_GEN_READ_WRITE_DATA_LENGTH);
1071  *v_standby_durn_u8 = BMP280_GET_BITSLICE(v_data_u8,
1072  BMP280_CONFIG_REG_STANDBY_DURN);
1073  }
1074  return com_rslt;
1075 }
1111 BMP280_RETURN_FUNCTION_TYPE bmp280_set_standby_durn(u8 v_standby_durn_u8)
1112 {
1113  /* variable used to return communication result*/
1114  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
1115  u8 v_data_u8 = BMP280_INIT_VALUE;
1116  /* check the p_bmp280 structure pointer as NULL*/
1117  if (p_bmp280 == BMP280_NULL) {
1118  com_rslt = E_BMP280_NULL_PTR;
1119  } else {
1120  /* write the standby duration*/
1121  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
1122  BMP280_CONFIG_REG_STANDBY_DURN__REG, &v_data_u8,
1123  BMP280_GEN_READ_WRITE_DATA_LENGTH);
1124  if (com_rslt == SUCCESS) {
1125  v_data_u8 = BMP280_SET_BITSLICE(v_data_u8,
1126  BMP280_CONFIG_REG_STANDBY_DURN,
1127  v_standby_durn_u8);
1128  com_rslt += p_bmp280->BMP280_BUS_WRITE_FUNC(
1129  p_bmp280->dev_addr,
1130  BMP280_CONFIG_REG_STANDBY_DURN__REG,
1131  &v_data_u8,
1132  BMP280_GEN_READ_WRITE_DATA_LENGTH);
1133  }
1134  }
1135  return com_rslt;
1136 }
1157 BMP280_RETURN_FUNCTION_TYPE bmp280_set_work_mode(u8 v_work_mode_u8)
1158 {
1159  /* variable used to return communication result*/
1160  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
1161  u8 v_data_u8 = BMP280_INIT_VALUE;
1162  /* check the p_bmp280 structure pointer as NULL*/
1163  if (p_bmp280 == BMP280_NULL) {
1164  com_rslt = E_BMP280_NULL_PTR;
1165  } else {
1166  if (v_work_mode_u8 <= BMP280_ULTRA_HIGH_RESOLUTION_MODE) {
1167  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(
1168  p_bmp280->dev_addr,
1169  BMP280_CTRL_MEAS_REG, &v_data_u8,
1170  BMP280_GEN_READ_WRITE_DATA_LENGTH);
1171  if (com_rslt == SUCCESS) {
1172  switch (v_work_mode_u8) {
1173  /* write work mode*/
1174  case BMP280_ULTRA_LOW_POWER_MODE:
1175  p_bmp280->oversamp_temperature =
1176  BMP280_ULTRALOWPOWER_OVERSAMP_TEMPERATURE;
1177  p_bmp280->oversamp_pressure =
1178  BMP280_ULTRALOWPOWER_OVERSAMP_PRESSURE;
1179  break;
1180  case BMP280_LOW_POWER_MODE:
1181  p_bmp280->oversamp_temperature =
1182  BMP280_LOWPOWER_OVERSAMP_TEMPERATURE;
1183  p_bmp280->oversamp_pressure =
1184  BMP280_LOWPOWER_OVERSAMP_PRESSURE;
1185  break;
1186  case BMP280_STANDARD_RESOLUTION_MODE:
1187  p_bmp280->oversamp_temperature =
1188  BMP280_STANDARDRESOLUTION_OVERSAMP_TEMPERATURE;
1189  p_bmp280->oversamp_pressure =
1190  BMP280_STANDARDRESOLUTION_OVERSAMP_PRESSURE;
1191  break;
1192  case BMP280_HIGH_RESOLUTION_MODE:
1193  p_bmp280->oversamp_temperature =
1194  BMP280_HIGHRESOLUTION_OVERSAMP_TEMPERATURE;
1195  p_bmp280->oversamp_pressure =
1196  BMP280_HIGHRESOLUTION_OVERSAMP_PRESSURE;
1197  break;
1198  case BMP280_ULTRA_HIGH_RESOLUTION_MODE:
1199  p_bmp280->oversamp_temperature =
1200  BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_TEMPERATURE;
1201  p_bmp280->oversamp_pressure =
1202  BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_PRESSURE;
1203  break;
1204  }
1205  v_data_u8 = BMP280_SET_BITSLICE(v_data_u8,
1206  BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE,
1207  p_bmp280->oversamp_temperature);
1208  v_data_u8 = BMP280_SET_BITSLICE(v_data_u8,
1209  BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE,
1210  p_bmp280->oversamp_pressure);
1211  com_rslt += p_bmp280->BMP280_BUS_WRITE_FUNC(
1212  p_bmp280->dev_addr, BMP280_CTRL_MEAS_REG,
1213  &v_data_u8, BMP280_GEN_READ_WRITE_DATA_LENGTH);
1214  }
1215  } else {
1216  com_rslt = E_BMP280_OUT_OF_RANGE;
1217  }
1218  }
1219  return com_rslt;
1220 }
1237  s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32)
1238 {
1239  /* variable used to return communication result*/
1240  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
1241  u8 v_data_u8 = BMP280_INIT_VALUE;
1242  u8 v_waittime_u8 = BMP280_INIT_VALUE;
1243  /* check the p_bmp280 structure pointer as NULL*/
1244  if (p_bmp280 == BMP280_NULL) {
1245  com_rslt = E_BMP280_NULL_PTR;
1246  } else {
1247  /* read pressure and temperature*/
1248  v_data_u8 = (p_bmp280->oversamp_temperature
1249  << BMP280_SHIFT_BIT_POSITION_BY_05_BITS)
1250  + (p_bmp280->oversamp_pressure
1251  << BMP280_SHIFT_BIT_POSITION_BY_02_BITS)
1252  + BMP280_FORCED_MODE;
1253  com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr,
1254  BMP280_CTRL_MEAS_REG, &v_data_u8,
1255  BMP280_GEN_READ_WRITE_DATA_LENGTH);
1256  bmp280_compute_wait_time(&v_waittime_u8);
1257  p_bmp280->delay_msec(v_waittime_u8);
1259  v_uncomp_pressure_s32,
1260  v_uncomp_temperature_s32);
1261  }
1262  return com_rslt;
1263 }
1281 BMP280_RETURN_FUNCTION_TYPE bmp280_write_register(u8 v_addr_u8, u8 *v_data_u8,
1282  u8 v_len_u8)
1283 {
1284  /* variable used to return communication result*/
1285  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
1286  /* check the p_bmp280 structure pointer as NULL*/
1287  if (p_bmp280 == BMP280_NULL) {
1288  com_rslt = E_BMP280_NULL_PTR;
1289  } else {
1290  com_rslt = p_bmp280->BMP280_BUS_WRITE_FUNC(p_bmp280->dev_addr,
1291  v_addr_u8, v_data_u8, v_len_u8);
1292  }
1293  return com_rslt;
1294 }
1312 BMP280_RETURN_FUNCTION_TYPE bmp280_read_register(u8 v_addr_u8, u8 *v_data_u8,
1313  u8 v_len_u8)
1314 {
1315  /* variable used to return communication result*/
1316  BMP280_RETURN_FUNCTION_TYPE com_rslt = ERROR;
1317  /* check the p_bmp280 structure pointer as NULL*/
1318  if (p_bmp280 == BMP280_NULL) {
1319  com_rslt = E_BMP280_NULL_PTR;
1320  } else {
1321  com_rslt = p_bmp280->BMP280_BUS_READ_FUNC(p_bmp280->dev_addr,
1322  v_addr_u8, v_data_u8, v_len_u8);
1323  }
1324  return com_rslt;
1325 }
1326 #ifdef BMP280_ENABLE_FLOAT
1327 
1343 double bmp280_compensate_temperature_double(s32 v_uncomp_temperature_s32)
1344 {
1345  double v_x1_u32r = BMP280_INIT_VALUE;
1346  double v_x2_u32r = BMP280_INIT_VALUE;
1347  double temperature = BMP280_INIT_VALUE;
1348  /* calculate x1*/
1349  v_x1_u32r = (((double)v_uncomp_temperature_s32) / 16384.0 -
1350  ((double)p_bmp280->calib_param.dig_T1) / 1024.0) *
1351  ((double)p_bmp280->calib_param.dig_T2);
1352  /* calculate x2*/
1353  v_x2_u32r = ((((double)v_uncomp_temperature_s32) / 131072.0 -
1354  ((double)p_bmp280->calib_param.dig_T1) / 8192.0) *
1355  (((double)v_uncomp_temperature_s32) / 131072.0 -
1356  ((double)p_bmp280->calib_param.dig_T1) / 8192.0)) *
1357  ((double)p_bmp280->calib_param.dig_T3);
1358  /* calculate t_fine*/
1359  p_bmp280->calib_param.t_fine = (s32)(v_x1_u32r + v_x2_u32r);
1360  /* calculate true pressure*/
1361  temperature = (v_x1_u32r + v_x2_u32r) / 5120.0;
1362 
1363  return temperature;
1364 }
1381 double bmp280_compensate_pressure_double(s32 v_uncomp_pressure_s32)
1382 {
1383  double v_x1_u32r = BMP280_INIT_VALUE;
1384  double v_x2_u32r = BMP280_INIT_VALUE;
1385  double pressure = BMP280_INIT_VALUE;
1386 
1387  v_x1_u32r = ((double)p_bmp280->calib_param.t_fine/2.0) - 64000.0;
1388  v_x2_u32r = v_x1_u32r * v_x1_u32r *
1389  ((double)p_bmp280->calib_param.dig_P6) / 32768.0;
1390  v_x2_u32r = v_x2_u32r + v_x1_u32r *
1391  ((double)p_bmp280->calib_param.dig_P5) * 2.0;
1392  v_x2_u32r = (v_x2_u32r / 4.0) +
1393  (((double)p_bmp280->calib_param.dig_P4) * 65536.0);
1394  v_x1_u32r = (((double)p_bmp280->calib_param.dig_P3) *
1395  v_x1_u32r * v_x1_u32r / 524288.0 +
1396  ((double)p_bmp280->calib_param.dig_P2) * v_x1_u32r) / 524288.0;
1397  v_x1_u32r = (1.0 + v_x1_u32r / 32768.0) *
1398  ((double)p_bmp280->calib_param.dig_P1);
1399  pressure = 1048576.0 - (double)v_uncomp_pressure_s32;
1400  /* Avoid exception caused by division by zero */
1401  if ((v_x1_u32r > 0) || (v_x1_u32r < 0))
1402  pressure = (pressure - (v_x2_u32r / 4096.0)) *
1403  6250.0 / v_x1_u32r;
1404  else
1405  return BMP280_INVALID_DATA;
1406  v_x1_u32r = ((double)p_bmp280->calib_param.dig_P9) *
1407  pressure * pressure / 2147483648.0;
1408  v_x2_u32r = pressure * ((double)p_bmp280->calib_param.dig_P8) / 32768.0;
1409  pressure = pressure + (v_x1_u32r + v_x2_u32r +
1410  ((double)p_bmp280->calib_param.dig_P7)) / 16.0;
1411 
1412  return pressure;
1413 }
1414 #endif
1415 #if defined(BMP280_ENABLE_INT64) && defined(BMP280_64BITSUPPORT_PRESENT)
1416 
1433 {
1434  s64 v_x1_s64r = BMP280_INIT_VALUE;
1435  s64 v_x2_s64r = BMP280_INIT_VALUE;
1436  s64 pressure = BMP280_INIT_VALUE;
1437  /* calculate x1*/
1438  v_x1_s64r = ((s64)p_bmp280->calib_param.t_fine) - 128000;
1439  v_x2_s64r = v_x1_s64r * v_x1_s64r *
1440  (s64)p_bmp280->calib_param.dig_P6;
1441  /* calculate x2*/
1442  v_x2_s64r = v_x2_s64r + ((v_x1_s64r * (s64)p_bmp280->calib_param.dig_P5)
1443  << BMP280_SHIFT_BIT_POSITION_BY_17_BITS);
1444  v_x2_s64r = v_x2_s64r +
1445  (((s64)p_bmp280->calib_param.dig_P4)
1446  << BMP280_SHIFT_BIT_POSITION_BY_35_BITS);
1447  v_x1_s64r = ((v_x1_s64r * v_x1_s64r *
1448  (s64)p_bmp280->calib_param.dig_P3)
1449  >> BMP280_SHIFT_BIT_POSITION_BY_08_BITS) +
1450  ((v_x1_s64r * (s64)p_bmp280->calib_param.dig_P2)
1451  << BMP280_SHIFT_BIT_POSITION_BY_12_BITS);
1452  v_x1_s64r = (((((s64)1) << BMP280_SHIFT_BIT_POSITION_BY_47_BITS)
1453  + v_x1_s64r)) * ((s64)p_bmp280->calib_param.dig_P1) >>
1454  BMP280_SHIFT_BIT_POSITION_BY_33_BITS;
1455  pressure = 1048576 - v_uncomp_pressure_s32;
1456  if (v_x1_s64r != BMP280_INIT_VALUE)
1457 #if defined __KERNEL__
1458  pressure = div64_s64((((pressure
1459  << BMP280_SHIFT_BIT_POSITION_BY_31_BITS)
1460  - v_x2_s64r) * 3125), v_x1_s64r);
1461 #else
1462  pressure = (((pressure
1463  << BMP280_SHIFT_BIT_POSITION_BY_31_BITS)
1464  - v_x2_s64r) * 3125) / v_x1_s64r;
1465 #endif
1466  else
1467  return BMP280_INVALID_DATA;
1468  v_x1_s64r = (((s64)p_bmp280->calib_param.dig_P9) *
1469  (pressure >> BMP280_SHIFT_BIT_POSITION_BY_13_BITS) *
1470  (pressure >> BMP280_SHIFT_BIT_POSITION_BY_13_BITS))
1471  >> BMP280_SHIFT_BIT_POSITION_BY_25_BITS;
1472  v_x2_s64r = (((s64)p_bmp280->calib_param.dig_P8) *
1473  pressure) >> BMP280_SHIFT_BIT_POSITION_BY_19_BITS;
1474  /* calculate pressure*/
1475  pressure = ((pressure + v_x1_s64r + v_x2_s64r)
1476  >> BMP280_SHIFT_BIT_POSITION_BY_08_BITS) +
1477  (((s64)p_bmp280->calib_param.dig_P7)
1478  << BMP280_SHIFT_BIT_POSITION_BY_04_BITS);
1479  return (u32)pressure;
1480 }
1481 #endif
1482 
1495 BMP280_RETURN_FUNCTION_TYPE bmp280_compute_wait_time(u8 *v_delaytime_u8r)
1496 {
1497  /* variable used to return communication result*/
1498  BMP280_RETURN_FUNCTION_TYPE com_rslt = SUCCESS;
1499 
1500  *v_delaytime_u8r = (T_INIT_MAX + T_MEASURE_PER_OSRS_MAX * (((1
1501  << p_bmp280->oversamp_temperature)
1502  >> BMP280_SHIFT_BIT_POSITION_BY_01_BIT)
1503  + ((1 << p_bmp280->oversamp_pressure)
1504  >> BMP280_SHIFT_BIT_POSITION_BY_01_BIT))
1505  + ((p_bmp280->oversamp_pressure > 0) ?
1506  T_SETUP_PRESSURE_MAX : 0) + 15) / 16;
1507  return com_rslt;
1508 }
BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280)
This function is used for initialize the bus read and bus write functions and assign the chip id and ...
Definition: bmp280.c:85
u8 dev_addr
Definition: bmp280.h:771
BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure_temperature(s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32)
reads uncompensated pressure and temperature
Definition: bmp280.c:364
BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_pressure(u8 *v_value_u8)
This API is used to get the pressure oversampling setting in the register 0xF4 bits from 2 to 4...
Definition: bmp280.c:680
BMP280_RETURN_FUNCTION_TYPE bmp280_write_register(u8 v_addr_u8, u8 *v_data_u8, u8 v_len_u8)
This API write the data to the given register.
Definition: bmp280.c:1281
unsigned short int u16
Definition: bmp280.h:283
BMP280_RETURN_FUNCTION_TYPE bmp280_set_power_mode(u8 v_power_mode_u8)
This API used to set the Operational Mode from the sensor in the register 0xF4 bit 0 and 1...
Definition: bmp280.c:809
BMP280_RETURN_FUNCTION_TYPE bmp280_get_standby_durn(u8 *v_standby_durn_u8)
This API used to Read the standby duration time from the sensor in the register 0xF5 bit 5 to 7...
Definition: bmp280.c:1058
BMP280_RETURN_FUNCTION_TYPE bmp280_read_register(u8 v_addr_u8, u8 *v_data_u8, u8 v_len_u8)
This API reads the data from the given register.
Definition: bmp280.c:1312
u32 bmp280_compensate_pressure_int32(s32 v_uncomp_pressure_s32)
Reads actual pressure from uncompensated pressure and returns the value in Pascal(Pa) ...
Definition: bmp280.c:280
u32 bmp280_compensate_pressure_int64(s32 v_uncomp_pressure_s32)
This API used to read actual pressure from uncompensated pressure.
Definition: bmp280.c:1432
BMP280_RETURN_FUNCTION_TYPE bmp280_compute_wait_time(u8 *v_delaytime_u8r)
Computing waiting time for sensor data read.
Definition: bmp280.c:1495
BMP280_RETURN_FUNCTION_TYPE bmp280_get_oversamp_temperature(u8 *v_value_u8)
This API is used to get the temperature oversampling setting in the register 0xF4 bits from 5 to 7...
Definition: bmp280.c:583
static struct bmp280_t * p_bmp280
Definition: bmp280.c:58
unsigned int u32
Definition: bmp280.h:284
BMP280 Sensor Driver Support Header File.
BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_temperature(s32 *v_uncomp_temperature_s32)
This API is used to read uncompensated temperature in the registers 0xFA, 0xFB and 0xFC...
Definition: bmp280.c:139
struct bmp280_calib_param_t calib_param
Definition: bmp280.h:768
void(* delay_msec)(BMP280_MDELAY_DATA_TYPE)
Definition: bmp280.h:778
u8 oversamp_temperature
Definition: bmp280.h:773
signed int s32
Definition: bmp280.h:278
BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure(s32 *v_uncomp_pressure_s32)
This API is used to read uncompensated pressure. in the registers 0xF7, 0xF8 and 0xF9.
Definition: bmp280.c:235
BMP280_RETURN_FUNCTION_TYPE bmp280_read_pressure_temperature(u32 *v_pressure_u32, s32 *v_temperature_s32)
This API reads the true pressure and temperature.
Definition: bmp280.c:425
BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_temperature(u8 v_value_u8)
This API is used to set the temperature oversampling setting in the register 0xF4 bits from 5 to 7...
Definition: bmp280.c:628
BMP280_RETURN_FUNCTION_TYPE bmp280_set_spi3(u8 v_enable_disable_u8)
This API used to set the sensor SPI mode(communication type) in the register 0xF5 bit 0...
Definition: bmp280.c:925
BMP280_RETURN_FUNCTION_TYPE bmp280_set_soft_rst(void)
Used to reset the sensor The value 0xB6 is written to the 0xE0 register the device is reset using the...
Definition: bmp280.c:852
BMP280_RETURN_FUNCTION_TYPE bmp280_get_spi3(u8 *v_enable_disable_u8)
This API used to get the sensor SPI mode(communication type) in the register 0xF5 bit 0...
Definition: bmp280.c:888
signed short int s16
Definition: bmp280.h:277
BMP280_RETURN_FUNCTION_TYPE bmp280_set_work_mode(u8 v_work_mode_u8)
This API is used to write the working mode of the sensor.
Definition: bmp280.c:1157
unsigned char u8
Definition: bmp280.h:282
double bmp280_compensate_temperature_double(s32 v_uncomp_temperature_s32)
This API used to read actual temperature from uncompensated temperature.
Definition: bmp280.c:1343
u8 oversamp_pressure
Definition: bmp280.h:774
BMP280_RETURN_FUNCTION_TYPE bmp280_set_oversamp_pressure(u8 v_value_u8)
This API is used to set the pressure oversampling setting in the register 0xF4 bits from 2 to 4...
Definition: bmp280.c:725
double bmp280_compensate_pressure_double(s32 v_uncomp_pressure_s32)
Reads actual pressure from uncompensated pressure and returns pressure in Pa as double.
Definition: bmp280.c:1381
BMP280_RETURN_FUNCTION_TYPE bmp280_get_filter(u8 *v_value_u8)
This API is used to reads filter setting in the register 0xF5 bit 3 and 4.
Definition: bmp280.c:971
s32 bmp280_compensate_temperature_int32(s32 v_uncomp_temperature_s32)
Reads actual temperature from uncompensated temperature.
Definition: bmp280.c:185
BMP280_RETURN_FUNCTION_TYPE bmp280_get_forced_uncomp_pressure_temperature(s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32)
This API used to read both uncompensated pressure and temperature in forced mode. ...
Definition: bmp280.c:1236
u8 chip_id
Definition: bmp280.h:770
BMP280_RETURN_FUNCTION_TYPE bmp280_set_filter(u8 v_value_u8)
This API is used to write filter setting in the register 0xF5 bit 3 and 4.
Definition: bmp280.c:1010
BMP280_RETURN_FUNCTION_TYPE bmp280_get_calib_param(void)
This API is used to calibration parameters used for calculation in the registers. ...
Definition: bmp280.c:473
signed long long int s64
Definition: bmp280.h:279
BMP280_RETURN_FUNCTION_TYPE bmp280_get_power_mode(u8 *v_power_mode_u8)
This API used to get the Operational Mode from the sensor in the register 0xF4 bit 0 and 1...
Definition: bmp280.c:772
BMP280_RETURN_FUNCTION_TYPE bmp280_set_standby_durn(u8 v_standby_durn_u8)
This API used to Read the standby duration time from the sensor in the register 0xF5 bit 5 to 7...
Definition: bmp280.c:1111
This structure holds BMP280 initialization parameters.
Definition: bmp280.h:767
signed char s8
Definition: bmp280.h:276