Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
bmp3_i2c.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
31 #include "peripherals/bmp3_i2c.h"
32 
36 static void parse_sensor_data(struct Bmp3_I2c *bmp);
37 static void parse_calib_data(struct Bmp3_I2c *bmp);
38 #if BMP3_COMPENSATION == BMP3_DOUBLE_PRECISION_COMPENSATION
39 PRINT_CONFIG_MSG("BMP3 double precision compensation")
40 static double compensate_pressure(struct Bmp3_I2c *bmp);
41 static double compensate_temperature(struct Bmp3_I2c *bmp);
42 static double bmp3_pow(double base, uint8_t power);
43 #elif BMP3_COMPENSATION == BMP3_SINGLE_PRECISION_COMPENSATION
44 PRINT_CONFIG_MSG("BMP3 single precision compensation")
45 static float compensate_pressure(struct Bmp3_I2c *bmp);
46 static float compensate_temperature(struct Bmp3_I2c *bmp);
47 static float bmp3_pow(float base, uint8_t power);
48 #elif BMP3_COMPENSATION == BMP3_INTEGER_COMPENSATION
49 PRINT_CONFIG_MSG("BMP3 integer compensation")
50 static int64_t compensate_temperature(struct Bmp3_I2c *bmp);
51 static uint64_t compensate_pressure(struct Bmp3_I2c *bmp);
52 #else
53 #error "BMP3: Unknown compensation type"
54 #endif
55 
56 
60 void bmp3_i2c_init(struct Bmp3_I2c *bmp, struct i2c_periph *i2c_p, uint8_t addr)
61 {
62  /* set i2c_peripheral */
63  bmp->i2c_p = i2c_p;
64 
65  /* slave address */
66  bmp->i2c_trans.slave_addr = addr;
67  /* set initial status: Done */
69 
70  bmp->data_available = false;
71  bmp->initialized = false;
73 }
74 
78 void bmp3_i2c_periodic(struct Bmp3_I2c *bmp)
79 {
80  if (bmp->i2c_trans.status != I2CTransDone) {
81  return; // transaction not finished
82  }
83 
84  switch (bmp->status) {
85  case BMP3_STATUS_UNINIT:
86  bmp->data_available = false;
87  bmp->initialized = false;
89  break;
90 
92  // request calibration data
95  break;
96 
98  // From datasheet, recommended config for drone usecase:
99  // osrs_p = 8, osrs_t = 1
100  // IIR filter = 2 (note: this one doesn't exist...)
101  // ODR = 50
102  bmp->i2c_trans.buf[0] = BMP3_PWR_CTRL_ADDR;
103  bmp->i2c_trans.buf[1] = BMP3_ALL | BMP3_NORMAL_MODE << 4;
104  bmp->i2c_trans.buf[2] = BMP3_OSR_ADDR;
106  bmp->i2c_trans.buf[4] = BMP3_ODR_ADDR;
107  bmp->i2c_trans.buf[5] = BMP3_ODR_50_HZ;
108  bmp->i2c_trans.buf[6] = BMP3_CONFIG_ADDR;
109  bmp->i2c_trans.buf[7] = BMP3_IIR_FILTER_COEFF_3 << 1;
110  i2c_transmit(bmp->i2c_p, &bmp->i2c_trans, bmp->i2c_trans.slave_addr, 8);
111  break;
112 
114  /* read data */
117  break;
118 
119  default:
120  break;
121  }
122 }
123 
124 
125 void bmp3_i2c_event(struct Bmp3_I2c *bmp)
126 {
127  if (bmp->i2c_trans.status == I2CTransSuccess) {
128  switch (bmp->status) {
130  // compute calib
131  parse_calib_data(bmp);
133  break;
134 
136  // nothing else to do, start reading
138  bmp->initialized = true;
139  break;
140 
142  // check status byte
143  if (bmp->i2c_trans.buf[0] & (BMP3_ALL << 5)) {
144  // parse sensor data, compensate temperature first, then pressure
145  parse_sensor_data(bmp);
147  compensate_pressure(bmp);
148  bmp->data_available = true;
149  }
150  break;
151 
152  default:
153  break;
154  }
156  } else if (bmp->i2c_trans.status == I2CTransFailed) {
157  /* try again */
158  if (!bmp->initialized) {
159  bmp->status = BMP3_STATUS_UNINIT;
160  }
162  }
163 }
164 
165 
166 static void parse_sensor_data(struct Bmp3_I2c *bmp)
167 {
168  /* Temporary variables to store the sensor data */
169  uint32_t data_xlsb;
170  uint32_t data_lsb;
171  uint32_t data_msb;
172 
173  /* Store the parsed register values for pressure data */
174  data_xlsb = (uint32_t)bmp->i2c_trans.buf[1];
175  data_lsb = (uint32_t)bmp->i2c_trans.buf[2] << 8;
176  data_msb = (uint32_t)bmp->i2c_trans.buf[3] << 16;
177  bmp->raw_pressure = data_msb | data_lsb | data_xlsb;
178 
179  /* Store the parsed register values for temperature data */
180  data_xlsb = (uint32_t)bmp->i2c_trans.buf[4];
181  data_lsb = (uint32_t)bmp->i2c_trans.buf[5] << 8;
182  data_msb = (uint32_t)bmp->i2c_trans.buf[6] << 16;
183  bmp->raw_temperature = data_msb | data_lsb | data_xlsb;
184 }
185 
186 
187 #if BMP3_COMPENSATION == BMP3_DOUBLE_PRECISION_COMPENSATION
188 
193 static void parse_calib_data(struct Bmp3_I2c *bmp)
194 {
195  double temp_var;
196  uint8_t *data = (uint8_t *)bmp->i2c_trans.buf; // we know that this buffer will not be modified during this call
197 
198  /* 1 / 2^8 */
199  temp_var = 0.00390625;
200  bmp->calib.par_t1 = BMP3_CONCAT_BYTES(data[1], data[0]);
201  bmp->quant_calib.par_t1 = ((double)bmp->calib.par_t1 / temp_var);
202 
203  bmp->calib.par_t2 = BMP3_CONCAT_BYTES(data[3], data[2]);
204  temp_var = 1073741824.0;
205  bmp->quant_calib.par_t2 = ((double)bmp->calib.par_t2 / temp_var);
206 
207  bmp->calib.par_t3 = (int8_t)data[4];
208  temp_var = 281474976710656.0;
209  bmp->quant_calib.par_t3 = ((double)bmp->calib.par_t3 / temp_var);
210 
211  bmp->calib.par_p1 = (int16_t)BMP3_CONCAT_BYTES(data[6], data[5]);
212  temp_var = 1048576.0;
213  bmp->quant_calib.par_p1 = ((double)(bmp->calib.par_p1 - (16384)) / temp_var);
214 
215  bmp->calib.par_p2 = (int16_t)BMP3_CONCAT_BYTES(data[8], data[7]);
216  temp_var = 536870912.0;
217  bmp->quant_calib.par_p2 = ((double)(bmp->calib.par_p2 - (16384)) / temp_var);
218 
219  bmp->calib.par_p3 = (int8_t)data[9];
220  temp_var = 4294967296.0;
221  bmp->quant_calib.par_p3 = ((double)bmp->calib.par_p3 / temp_var);
222 
223  bmp->calib.par_p4 = (int8_t)data[10];
224  temp_var = 137438953472.0;
225  bmp->quant_calib.par_p4 = ((double)bmp->calib.par_p4 / temp_var);
226 
227  bmp->calib.par_p5 = BMP3_CONCAT_BYTES(data[12], data[11]);
228  /* 1 / 2^3 */
229  temp_var = 0.125;
230  bmp->quant_calib.par_p5 = ((double)bmp->calib.par_p5 / temp_var);
231 
232  bmp->calib.par_p6 = BMP3_CONCAT_BYTES(data[14], data[13]);
233  temp_var = 64.0;
234  bmp->quant_calib.par_p6 = ((double)bmp->calib.par_p6 / temp_var);
235 
236  bmp->calib.par_p7 = (int8_t)data[15];
237  temp_var = 256.0;
238  bmp->quant_calib.par_p7 = ((double)bmp->calib.par_p7 / temp_var);
239 
240  bmp->calib.par_p8 = (int8_t)data[16];
241  temp_var = 32768.0;
242  bmp->quant_calib.par_p8 = ((double)bmp->calib.par_p8 / temp_var);
243 
244  bmp->calib.par_p9 = (int16_t)BMP3_CONCAT_BYTES(data[18], data[17]);
245  temp_var = 281474976710656.0;
246  bmp->quant_calib.par_p9 = ((double)bmp->calib.par_p9 / temp_var);
247 
248  bmp->calib.par_p10 = (int8_t)data[19];
249  temp_var = 281474976710656.0;
250  bmp->quant_calib.par_p10 = ((double)bmp->calib.par_p10 / temp_var);
251 
252  bmp->calib.par_p11 = (int8_t)data[20];
253  temp_var = 36893488147419103232.0;
254  bmp->quant_calib.par_p11 = ((double)bmp->calib.par_p11 / temp_var);
255 }
256 
261 static double compensate_temperature(struct Bmp3_I2c *bmp)
262 {
263  double partial_data1 = (double)(bmp->raw_temperature - bmp->quant_calib.par_t1);
264  double partial_data2 = (double)(partial_data1 * bmp->quant_calib.par_t2);
265  /* Update the compensated temperature in structure since this is
266  needed for pressure calculation */
267  bmp->quant_calib.t_lin = partial_data2 + (partial_data1 * partial_data1)
268  * bmp->quant_calib.par_t3;
269 
270  /* Store compensated temperature in float in structure */
271  bmp->temperature = (float)bmp->quant_calib.t_lin;
272 
273  /* Returns compensated temperature */
274  return bmp->quant_calib.t_lin;
275 }
276 
281 static double compensate_pressure(struct Bmp3_I2c *bmp)
282 {
283  /* Variable to store the compensated pressure */
284  double comp_press;
285  /* Temporary variables used for compensation */
286  double partial_data1;
287  double partial_data2;
288  double partial_data3;
289  double partial_data4;
290  double partial_out1;
291  double partial_out2;
292 
293  partial_data1 = bmp->quant_calib.par_p6 * bmp->quant_calib.t_lin;
294  partial_data2 = bmp->quant_calib.par_p7 * bmp3_pow(bmp->quant_calib.t_lin, 2);
295  partial_data3 = bmp->quant_calib.par_p8 * bmp3_pow(bmp->quant_calib.t_lin, 3);
296  partial_out1 = bmp->quant_calib.par_p5 + partial_data1 + partial_data2 + partial_data3;
297 
298  partial_data1 = bmp->quant_calib.par_p2 * bmp->quant_calib.t_lin;
299  partial_data2 = bmp->quant_calib.par_p3 * bmp3_pow(bmp->quant_calib.t_lin, 2);
300  partial_data3 = bmp->quant_calib.par_p4 * bmp3_pow(bmp->quant_calib.t_lin, 3);
301  partial_out2 = bmp->raw_pressure *
302  (bmp->quant_calib.par_p1 + partial_data1 + partial_data2 + partial_data3);
303 
304  partial_data1 = bmp3_pow((double)bmp->raw_pressure, 2);
305  partial_data2 = bmp->quant_calib.par_p9 + bmp->quant_calib.par_p10 * bmp->quant_calib.t_lin;
306  partial_data3 = partial_data1 * partial_data2;
307  partial_data4 = partial_data3 + bmp3_pow((double)bmp->raw_pressure, 3) * bmp->quant_calib.par_p11;
308  comp_press = partial_out1 + partial_out2 + partial_data4;
309 
310  /* Store compensated temperature in float in structure */
311  bmp->pressure = (float)comp_press;
312 
313  return comp_press;
314 }
315 
320 static double bmp3_pow(double base, uint8_t power)
321 {
322  double pow_output = 1;
323 
324  while (power != 0) {
325  pow_output = base * pow_output;
326  power--;
327  }
328 
329  return pow_output;
330 }
331 
332 #elif BMP3_COMPENSATION == BMP3_SINGLE_PRECISION_COMPENSATION
333 
338 static void parse_calib_data(struct Bmp3_I2c *bmp)
339 {
340  float temp_var;
341  uint8_t *data = (uint8_t *)bmp->i2c_trans.buf; // we know that this buffer will not be modified during this call
342 
343  /* 1 / 2^8 */
344  temp_var = 0.00390625f;
345  bmp->calib.par_t1 = BMP3_CONCAT_BYTES(data[1], data[0]);
346  bmp->quant_calib.par_t1 = ((float)bmp->calib.par_t1 / temp_var);
347 
348  bmp->calib.par_t2 = BMP3_CONCAT_BYTES(data[3], data[2]);
349  temp_var = 1073741824.0f;
350  bmp->quant_calib.par_t2 = ((float)bmp->calib.par_t2 / temp_var);
351 
352  bmp->calib.par_t3 = (int8_t)data[4];
353  temp_var = 281474976710656.0f;
354  bmp->quant_calib.par_t3 = ((float)bmp->calib.par_t3 / temp_var);
355 
356  bmp->calib.par_p1 = (int16_t)BMP3_CONCAT_BYTES(data[6], data[5]);
357  temp_var = 1048576.0f;
358  bmp->quant_calib.par_p1 = ((float)(bmp->calib.par_p1 - (16384)) / temp_var);
359 
360  bmp->calib.par_p2 = (int16_t)BMP3_CONCAT_BYTES(data[8], data[7]);
361  temp_var = 536870912.0f;
362  bmp->quant_calib.par_p2 = ((float)(bmp->calib.par_p2 - (16384)) / temp_var);
363 
364  bmp->calib.par_p3 = (int8_t)data[9];
365  temp_var = 4294967296.0f;
366  bmp->quant_calib.par_p3 = ((float)bmp->calib.par_p3 / temp_var);
367 
368  bmp->calib.par_p4 = (int8_t)data[10];
369  temp_var = 137438953472.0f;
370  bmp->quant_calib.par_p4 = ((float)bmp->calib.par_p4 / temp_var);
371 
372  bmp->calib.par_p5 = BMP3_CONCAT_BYTES(data[12], data[11]);
373  /* 1 / 2^3 */
374  temp_var = 0.125f;
375  bmp->quant_calib.par_p5 = ((float)bmp->calib.par_p5 / temp_var);
376 
377  bmp->calib.par_p6 = BMP3_CONCAT_BYTES(data[14], data[13]);
378  temp_var = 64.0f;
379  bmp->quant_calib.par_p6 = ((float)bmp->calib.par_p6 / temp_var);
380 
381  bmp->calib.par_p7 = (int8_t)data[15];
382  temp_var = 256.0f;
383  bmp->quant_calib.par_p7 = ((float)bmp->calib.par_p7 / temp_var);
384 
385  bmp->calib.par_p8 = (int8_t)data[16];
386  temp_var = 32768.0f;
387  bmp->quant_calib.par_p8 = ((float)bmp->calib.par_p8 / temp_var);
388 
389  bmp->calib.par_p9 = (int16_t)BMP3_CONCAT_BYTES(data[18], data[17]);
390  temp_var = 281474976710656.0f;
391  bmp->quant_calib.par_p9 = ((float)bmp->calib.par_p9 / temp_var);
392 
393  bmp->calib.par_p10 = (int8_t)data[19];
394  temp_var = 281474976710656.0f;
395  bmp->quant_calib.par_p10 = ((float)bmp->calib.par_p10 / temp_var);
396 
397  bmp->calib.par_p11 = (int8_t)data[20];
398  temp_var = 36893488147419103232.0f;
399  bmp->quant_calib.par_p11 = ((float)bmp->calib.par_p11 / temp_var);
400 }
401 
406 static float compensate_temperature(struct Bmp3_I2c *bmp)
407 {
408  float partial_data1 = (float)(bmp->raw_temperature - bmp->quant_calib.par_t1);
409  float partial_data2 = (float)(partial_data1 * bmp->quant_calib.par_t2);
410  /* Update the compensated temperature in structure since this is
411  needed for pressure calculation */
412  bmp->quant_calib.t_lin = partial_data2 + (partial_data1 * partial_data1)
413  * bmp->quant_calib.par_t3;
414 
415  /* Store compensated temperature in float in structure */
416  bmp->temperature = (float)bmp->quant_calib.t_lin;
417 
418  /* Returns compensated temperature */
419  return bmp->quant_calib.t_lin;
420 }
421 
426 static float compensate_pressure(struct Bmp3_I2c *bmp)
427 {
428  /* Variable to store the compensated pressure */
429  float comp_press;
430  /* Temporary variables used for compensation */
431  float partial_data1;
432  float partial_data2;
433  float partial_data3;
434  float partial_data4;
435  float partial_out1;
436  float partial_out2;
437 
438  partial_data1 = bmp->quant_calib.par_p6 * bmp->quant_calib.t_lin;
439  partial_data2 = bmp->quant_calib.par_p7 * bmp3_pow(bmp->quant_calib.t_lin, 2);
440  partial_data3 = bmp->quant_calib.par_p8 * bmp3_pow(bmp->quant_calib.t_lin, 3);
441  partial_out1 = bmp->quant_calib.par_p5 + partial_data1 + partial_data2 + partial_data3;
442 
443  partial_data1 = bmp->quant_calib.par_p2 * bmp->quant_calib.t_lin;
444  partial_data2 = bmp->quant_calib.par_p3 * bmp3_pow(bmp->quant_calib.t_lin, 2);
445  partial_data3 = bmp->quant_calib.par_p4 * bmp3_pow(bmp->quant_calib.t_lin, 3);
446  partial_out2 = bmp->raw_pressure *
447  (bmp->quant_calib.par_p1 + partial_data1 + partial_data2 + partial_data3);
448 
449  partial_data1 = bmp3_pow((float)bmp->raw_pressure, 2);
450  partial_data2 = bmp->quant_calib.par_p9 + bmp->quant_calib.par_p10 * bmp->quant_calib.t_lin;
451  partial_data3 = partial_data1 * partial_data2;
452  partial_data4 = partial_data3 + bmp3_pow((float)bmp->raw_pressure, 3) * bmp->quant_calib.par_p11;
453  comp_press = partial_out1 + partial_out2 + partial_data4;
454 
455  /* Store compensated temperature in float in structure */
456  bmp->pressure = (float)comp_press;
457 
458  return comp_press;
459 }
460 
465 static float bmp3_pow(float base, uint8_t power)
466 {
467  float pow_output = 1;
468 
469  while (power != 0) {
470  pow_output = base * pow_output;
471  power--;
472  }
473 
474  return pow_output;
475 }
476 
477 #elif BMP3_COMPENSATION == BMP3_INTEGER_COMPENSATION
478 
483 static void parse_calib_data(struct Bmp3_I2c *bmp)
484 {
485  uint8_t *data = (uint8_t *)bmp->i2c_trans.buf; // we know that this buffer will not be modified during this call
486 
487  bmp->calib.par_t1 = BMP3_CONCAT_BYTES(data[1], data[0]);
488  bmp->calib.par_t2 = BMP3_CONCAT_BYTES(data[3], data[2]);
489  bmp->calib.par_t3 = (int8_t)data[4];
490  bmp->calib.par_p1 = (int16_t)BMP3_CONCAT_BYTES(data[6], data[5]);
491  bmp->calib.par_p2 = (int16_t)BMP3_CONCAT_BYTES(data[8], data[7]);
492  bmp->calib.par_p3 = (int8_t)data[9];
493  bmp->calib.par_p4 = (int8_t)data[10];
494  bmp->calib.par_p5 = BMP3_CONCAT_BYTES(data[12], data[11]);
495  bmp->calib.par_p6 = BMP3_CONCAT_BYTES(data[14], data[13]);
496  bmp->calib.par_p7 = (int8_t)data[15];
497  bmp->calib.par_p8 = (int8_t)data[16];
498  bmp->calib.par_p9 = (int16_t)BMP3_CONCAT_BYTES(data[18], data[17]);
499  bmp->calib.par_p10 = (int8_t)data[19];
500  bmp->calib.par_p11 = (int8_t)data[20];
501 }
502 
507 static int64_t compensate_temperature(struct Bmp3_I2c *bmp)
508 {
509  uint64_t partial_data1;
510  uint64_t partial_data2;
511  uint64_t partial_data3;
512  int64_t partial_data4;
513  int64_t partial_data5;
514  int64_t partial_data6;
515  int64_t comp_temp;
516 
517  partial_data1 = bmp->raw_temperature - (256 * bmp->calib.par_t1);
518  partial_data2 = bmp->calib.par_t2 * partial_data1;
519  partial_data3 = partial_data1 * partial_data1;
520  partial_data4 = (int64_t)partial_data3 * bmp->calib.par_t3;
521  partial_data5 = ((int64_t)(partial_data2 * 262144) + partial_data4);
522  partial_data6 = partial_data5 / 4294967296;
523  /* Store t_lin in dev. structure for pressure calculation */
524  bmp->calib.t_lin = partial_data6;
525  comp_temp = (int64_t)((partial_data6 * 25) / 16384);
526 
527  /* Store compensated temperature in float in structure */
528  bmp->temperature = ((float)comp_temp) / 100.f;
529 
530  return comp_temp;
531 }
532 
537 static uint64_t compensate_pressure(struct Bmp3_I2c *bmp)
538 {
539  int64_t partial_data1;
540  int64_t partial_data2;
541  int64_t partial_data3;
542  int64_t partial_data4;
543  int64_t partial_data5;
544  int64_t partial_data6;
545  int64_t offset;
546  int64_t sensitivity;
547  uint64_t comp_press;
548 
549  partial_data1 = bmp->calib.t_lin * bmp->calib.t_lin;
550  partial_data2 = partial_data1 / 64;
551  partial_data3 = (partial_data2 * bmp->calib.t_lin) / 256;
552  partial_data4 = (bmp->calib.par_p8 * partial_data3) / 32;
553  partial_data5 = (bmp->calib.par_p7 * partial_data1) * 16;
554  partial_data6 = (bmp->calib.par_p6 * bmp->calib.t_lin) * 4194304;
555  offset = (bmp->calib.par_p5 * 140737488355328) + partial_data4 + partial_data5 + partial_data6;
556 
557  partial_data2 = (bmp->calib.par_p4 * partial_data3) / 32;
558  partial_data4 = (bmp->calib.par_p3 * partial_data1) * 4;
559  partial_data5 = (bmp->calib.par_p2 - 16384) * bmp->calib.t_lin * 2097152;
560  sensitivity = ((bmp->calib.par_p1 - 16384) * 70368744177664) + partial_data2 + partial_data4 + partial_data5;
561 
562  partial_data1 = (sensitivity / 16777216) * bmp->raw_pressure;
563  partial_data2 = bmp->calib.par_p10 * bmp->calib.t_lin;
564  partial_data3 = partial_data2 + (65536 * bmp->calib.par_p9);
565  partial_data4 = (partial_data3 * bmp->raw_pressure) / 8192;
566  partial_data5 = (partial_data4 * bmp->raw_pressure) / 512;
567  partial_data6 = (int64_t)((uint64_t)bmp->raw_pressure * (uint64_t)bmp->raw_pressure);
568  partial_data2 = (bmp->calib.par_p11 * partial_data6) / 65536;
569  partial_data3 = (partial_data2 * bmp->raw_pressure) / 128;
570  partial_data4 = (offset / 4) + partial_data1 + partial_data5 + partial_data3;
571  comp_press = (((uint64_t)partial_data4 * 25) / (uint64_t)1099511627776);
572 
573  /* Store compensated temperature in float in structure */
574  bmp->pressure = ((float)comp_press) / 100.f;
575 
576  return comp_press;
577 }
578 
579 #endif
580 
bmp3_reg_calib_data::par_p3
int8_t par_p3
Definition: bmp3_regs.h:157
Bmp3_I2c::temperature
float temperature
temperature in deg Celcius
Definition: bmp3_i2c.h:51
i2c_transaction::buf
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
bmp3_reg_calib_data::t_lin
int64_t t_lin
Definition: bmp3_regs.h:166
bmp3_i2c_event
void bmp3_i2c_event(struct Bmp3_I2c *bmp)
Definition: bmp3_i2c.c:125
Bmp3_I2c::i2c_trans
struct i2c_transaction i2c_trans
Definition: bmp3_i2c.h:40
bmp3_i2c_init
void bmp3_i2c_init(struct Bmp3_I2c *bmp, struct i2c_periph *i2c_p, uint8_t addr)
init function
Definition: bmp3_i2c.c:60
bmp3_i2c.h
Sensor driver for BMP3 sensor via I2C.
bmp3_reg_calib_data::par_p1
int16_t par_p1
Definition: bmp3_regs.h:155
BMP3_STATUS_CONFIGURE
@ BMP3_STATUS_CONFIGURE
Definition: bmp3_regs.h:144
BMP3_PWR_CTRL_ADDR
#define BMP3_PWR_CTRL_ADDR
Definition: bmp3_regs.h:57
bmp3_reg_calib_data::par_p6
uint16_t par_p6
Definition: bmp3_regs.h:160
parse_calib_data
static void parse_calib_data(struct Bmp3_I2c *bmp)
This internal API is used to parse the calibration data, compensates it and store it in device struct...
Definition: bmp3_i2c.c:193
BMP3_CONCAT_BYTES
#define BMP3_CONCAT_BYTES(msb, lsb)
Definition: bmp3_regs.h:113
I2CTransFailed
@ I2CTransFailed
transaction failed
Definition: i2c.h:58
uint32_t
unsigned long uint32_t
Definition: types.h:18
int64_t
signed long long int64_t
Definition: types.h:21
bmp3_reg_calib_data::par_p9
int16_t par_p9
Definition: bmp3_regs.h:163
bmp3_reg_calib_data::par_p5
uint16_t par_p5
Definition: bmp3_regs.h:159
bmp3_reg_calib_data::par_p7
int8_t par_p7
Definition: bmp3_regs.h:161
Bmp3_I2c::status
enum Bmp3Status status
state machine status
Definition: bmp3_i2c.h:41
BMP3_ODR_50_HZ
#define BMP3_ODR_50_HZ
Definition: bmp3_regs.h:90
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
BMP3_IIR_FILTER_COEFF_3
#define BMP3_IIR_FILTER_COEFF_3
Definition: bmp3_regs.h:80
Bmp3_I2c::i2c_p
struct i2c_periph * i2c_p
Definition: bmp3_i2c.h:39
bmp3_reg_calib_data::par_t3
int8_t par_t3
Definition: bmp3_regs.h:154
i2c_transmit
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:324
BMP3_ODR_ADDR
#define BMP3_ODR_ADDR
Definition: bmp3_regs.h:59
BMP3_NO_OVERSAMPLING
#define BMP3_NO_OVERSAMPLING
Definition: bmp3_regs.h:70
BMP3_NORMAL_MODE
#define BMP3_NORMAL_MODE
Definition: bmp3_regs.h:67
Bmp3_I2c::calib
struct bmp3_reg_calib_data calib
calibration data
Definition: bmp3_i2c.h:44
i2c_transceive
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition: i2c.c:344
bmp3_reg_calib_data::par_p11
int8_t par_p11
Definition: bmp3_regs.h:165
int16_t
signed short int16_t
Definition: types.h:17
uint8_t
unsigned char uint8_t
Definition: types.h:14
bmp3_reg_calib_data::par_t2
uint16_t par_t2
Definition: bmp3_regs.h:153
bmp3_reg_calib_data::par_p8
int8_t par_p8
Definition: bmp3_regs.h:162
Bmp3_I2c::data_available
volatile bool data_available
data ready flag
Definition: bmp3_i2c.h:43
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
compensate_temperature
static double compensate_temperature(struct Bmp3_I2c *bmp)
This internal API is used to compensate the raw temperature data and return the compensated temperatu...
Definition: bmp3_i2c.c:261
Bmp3_I2c::raw_pressure
uint32_t raw_pressure
uncompensated pressure
Definition: bmp3_i2c.h:48
BMP3_SENS_STATUS_REG_ADDR
#define BMP3_SENS_STATUS_REG_ADDR
Definition: bmp3_regs.h:46
compensate_pressure
static double compensate_pressure(struct Bmp3_I2c *bmp)
This internal API is used to compensate the raw pressure data and return the compensated pressure dat...
Definition: bmp3_i2c.c:281
i2c_transaction::slave_addr
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
BMP3_P_AND_T_HEADER_DATA_LEN
#define BMP3_P_AND_T_HEADER_DATA_LEN
Definition: bmp3_regs.h:117
BMP3_ALL
#define BMP3_ALL
Definition: bmp3_regs.h:110
PRINT_CONFIG_MSG
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
BMP3_OSR_ADDR
#define BMP3_OSR_ADDR
Definition: bmp3_regs.h:58
offset
static const float offset[]
Definition: dw1000_arduino.c:199
int8_t
signed char int8_t
Definition: types.h:15
bmp3_reg_calib_data::par_t1
uint16_t par_t1
Definition: bmp3_regs.h:152
bmp3_pow
static double bmp3_pow(double base, uint8_t power)
This internal API is used to calculate the power functionality for double precision floating point va...
Definition: bmp3_i2c.c:320
BMP3_STATUS_READ_DATA
@ BMP3_STATUS_READ_DATA
Definition: bmp3_regs.h:145
bmp3_reg_calib_data::par_p4
int8_t par_p4
Definition: bmp3_regs.h:158
BMP3_CALIB_DATA_ADDR
#define BMP3_CALIB_DATA_ADDR
Definition: bmp3_regs.h:61
BMP3_OVERSAMPLING_8X
#define BMP3_OVERSAMPLING_8X
Definition: bmp3_regs.h:73
bmp3_i2c_periodic
void bmp3_i2c_periodic(struct Bmp3_I2c *bmp)
Start new measurement if sensor ready.
Definition: bmp3_i2c.c:78
bmp3_reg_calib_data::par_p10
int8_t par_p10
Definition: bmp3_regs.h:164
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
Bmp3_I2c::raw_temperature
uint32_t raw_temperature
uncompensated temperature
Definition: bmp3_i2c.h:49
BMP3_CONFIG_ADDR
#define BMP3_CONFIG_ADDR
Definition: bmp3_regs.h:60
Bmp3_I2c
Definition: bmp3_i2c.h:38
i2c_periph
Definition: i2c.h:144
BMP3_STATUS_GET_CALIB
@ BMP3_STATUS_GET_CALIB
Definition: bmp3_regs.h:143
parse_sensor_data
static void parse_sensor_data(struct Bmp3_I2c *bmp)
local function to extract raw data from i2c buffer and compute compensation with selected precision
Definition: bmp3_i2c.c:166
bmp3_reg_calib_data::par_p2
int16_t par_p2
Definition: bmp3_regs.h:156
Bmp3_I2c::quant_calib
struct bmp3_quantized_calib_data quant_calib
quantized calibration data
Definition: bmp3_i2c.h:46
Bmp3_I2c::initialized
bool initialized
config done flag
Definition: bmp3_i2c.h:42
BMP3_CALIB_DATA_LEN
#define BMP3_CALIB_DATA_LEN
Definition: bmp3_regs.h:116
uint64_t
unsigned long long uint64_t
Definition: types.h:20
BMP3_STATUS_UNINIT
@ BMP3_STATUS_UNINIT
Definition: bmp3_regs.h:142
Bmp3_I2c::pressure
float pressure
pressure in Pascal
Definition: bmp3_i2c.h:50