upm  0.6.2
Sensor/Actuator repository for libmraa (v0.10.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bme280driver.h
Go to the documentation of this file.
1 
59 #ifndef __BME280DRIVER_H__
60 #define __BME280DRIVER_H__
61 
62 
75 #ifdef __KERNEL__
76 
77 #include <linux/types.h>
78 #include <linux/math64.h>
79 #define BME280_64BITSUPPORT_PRESENT
80 /* singed integer type*/
81 typedef int8_t s8;
82 typedef int16_t s16;
83 typedef int32_t s32;
84 typedef int64_t s64;
86 typedef u_int8_t u8;
87 typedef u_int16_t u16;
88 typedef u_int32_t u32;
89 typedef u_int64_t u64;
93 #else /* ! __KERNEL__ */
94 /**********************************************************
95 * These definition uses for define the C
96 * standard version data types
97 ***********************************************************/
98 # if !defined(__STDC_VERSION__)
99 
100 /************************************************
101  * compiler is C11 C standard
102 ************************************************/
103 #if (__STDC_VERSION__ == 201112L)
104 
105 /************************************************/
106 #include <stdint.h>
107 /************************************************/
108 
109 /*unsigned integer types*/
110 typedef uint8_t u8;
111 typedef uint16_t u16;
112 typedef uint32_t u32;
113 typedef uint64_t u64;
115 /*signed integer types*/
116 typedef int8_t s8;
117 typedef int16_t s16;
118 typedef int32_t s32;
119 typedef int64_t s64;
120 #define BME280_64BITSUPPORT_PRESENT
121 /************************************************
122  * compiler is C99 C standard
123 ************************************************/
124 
125 #elif (__STDC_VERSION__ == 199901L)
126 
127 /* stdint.h is a C99 supported c library.
128 which is used to fixed the integer size*/
129 /************************************************/
130 #include <stdint.h>
131 /************************************************/
132 
133 /*unsigned integer types*/
134 typedef uint8_t u8;
135 typedef uint16_t u16;
136 typedef uint32_t u32;
137 typedef uint64_t u64;
139 /*signed integer types*/
140 typedef int8_t s8;
141 typedef int16_t s16;
142 typedef int32_t s32;
143 typedef int64_t s64;
144 #define BME280_64BITSUPPORT_PRESENT
145 /************************************************
146  * compiler is C89 or other C standard
147 ************************************************/
148 
149 #else /* !defined(__STDC_VERSION__) */
150 
155 #define MACHINE_32_BIT
156 
161 #ifdef MACHINE_16_BIT
162 #include <limits.h>
163 /*signed integer types*/
164 typedef signed char s8;
165 typedef signed short int s16;
166 typedef signed long int s32;
168 #if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL
169 typedef long int s64;
170 typedef unsigned long int u64;
171 #define BME280_64BITSUPPORT_PRESENT
172 #elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL)
173 typedef long long int s64;
174 typedef unsigned long long int u64;
175 #define BME280_64BITSUPPORT_PRESENT
176 #else
177 #warning Either the correct data type for signed 64 bit integer \
178 could not be found, or 64 bit integers are not supported in your environment.
179 #warning The API will only offer 32 bit pressure calculation.This will \
180 slightly impede accuracy(noise of ~1 pascal RMS will be added to output).
181 #warning If 64 bit integers are supported on your platform, \
182 please set s64 manually and "#define(BMPE80_64BITSUPPORT_PRESENT)" manually.
183 #endif
184 
185 /*unsigned integer types*/
186 typedef unsigned char u8;
187 typedef unsigned short int u16;
188 typedef unsigned long int u32;
190 /* If your machine support 32 bit
191 define the MACHINE_32_BIT*/
192 #elif defined MACHINE_32_BIT
193 /*signed integer types*/
194 typedef signed char s8;
195 typedef signed short int s16;
196 typedef signed int s32;
197 typedef signed long long int s64;
199 /*unsigned integer types*/
200 typedef unsigned char u8;
201 typedef unsigned short int u16;
202 typedef unsigned int u32;
203 typedef unsigned long long int u64;
208 #define BME280_64BITSUPPORT_PRESENT
209 
210 /* If your machine support 64 bit
211 define the MACHINE_64_BIT*/
212 #elif defined MACHINE_64_BIT
213 /*signed integer types*/
214 typedef signed char s8;
215 typedef signed short int s16;
216 typedef signed int s32;
217 typedef signed long int s64;
219 /*unsigned integer types*/
220 typedef unsigned char u8;
221 typedef unsigned short int u16;
222 typedef unsigned int u32;
223 typedef unsigned long int u64;
224 #define BME280_64BITSUPPORT_PRESENT
225 
226 #else
227 #warning The data types defined above which not supported \
228 define the data types manually
229 #endif
230 #endif
231 
232 /*** This else will execute for the compilers
233  * which are not supported the C standards
234  * Like C89/C99/C11***/
235 #else
236 
241 #define MACHINE_32_BIT
242 
243 /* If your machine support 16 bit
244 define the MACHINE_16_BIT*/
245 #ifdef MACHINE_16_BIT
246 #include <limits.h>
247 /*signed integer types*/
248 typedef signed char s8;
249 typedef signed short int s16;
250 typedef signed long int s32;
252 #if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL
253 typedef long int s64;
254 typedef unsigned long int u64;
255 #define BME280_64BITSUPPORT_PRESENT
256 #elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL)
257 typedef long long int s64;
258 typedef unsigned long long int u64;
259 #define BME280_64BITSUPPORT_PRESENT
260 #else
261 #warning Either the correct data type for signed 64 bit integer \
262 could not be found, or 64 bit integers are not supported in your environment.
263 #warning The API will only offer 32 bit pressure calculation.This will \
264 slightly impede accuracy(noise of ~1 pascal RMS will be added to output).
265 #warning If 64 bit integers are supported on your platform, \
266 please set s64 manually and "#define(BME280_64BITSUPPORT_PRESENT)" manually.
267 #endif
268 
269 /*unsigned integer types*/
270 typedef unsigned char u8;
271 typedef unsigned short int u16;
272 typedef unsigned long int u32;
276 #elif defined MACHINE_32_BIT
277 /*signed integer types*/
278 typedef signed char s8;
279 typedef signed short int s16;
280 typedef signed int s32;
281 typedef signed long long int s64;
283 /*unsigned integer types*/
284 typedef unsigned char u8;
285 typedef unsigned short int u16;
286 typedef unsigned int u32;
287 typedef unsigned long long int u64;
288 #define BME280_64BITSUPPORT_PRESENT
289 
290 /* If your machine support 64 bit
291 define the MACHINE_64_BIT*/
292 #elif defined MACHINE_64_BIT
293 /*signed integer types*/
294 typedef signed char s8;
295 typedef signed short int s16;
296 typedef signed int s32;
297 typedef signed long int s64;
299 /*unsigned integer types*/
300 typedef unsigned char u8;
301 typedef unsigned short int u16;
302 typedef unsigned int u32;
303 typedef unsigned long int u64;
304 #define BME280_64BITSUPPORT_PRESENT
305 
306 #else
307 #warning The data types defined above which not supported \
308 define the data types manually
309 #endif
310 #endif
311 #endif
312 /********************************************/
314 /**************************************/
320 #define BME280_ENABLE_FLOAT
321 
327 #define BME280_ENABLE_INT64
328 /***************************************************************/
330 /***************************************************************/
352 #define BME280_BUS_WR_RETURN_TYPE s8
353 
354 /* links the order of parameters defined in
355 BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
356 #define BME280_BUS_WR_PARAM_TYPES u8, u8,\
357  u8 *, u8
358 
359 /* links the order of parameters defined in
360 BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
361 #define BME280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\
362  register_data, wr_len)
363 
364 /* never change this line */
365 #define BME280_BUS_WRITE_FUNC(device_addr, register_addr,\
366 register_data, wr_len) bus_write(device_addr, register_addr,\
367  register_data, wr_len)
368 
392 /*defines the return parameter type of the BME280_RD_FUNCTION
393 */
394 #define BME280_BUS_RD_RETURN_TYPE s8
395 
398 #define BME280_BUS_RD_PARAM_TYPES (u8, u8,\
399  u8 *, u8)
400 
401 /* links the order of parameters defined in \
402 BME280_BUS_RD_PARAM_TYPE to function calls used inside the API
403 */
404 #define BME280_BUS_RD_PARAM_ORDER (device_addr, register_addr,\
405  register_data)
406 
407 /* never change this line */
408 #define BME280_BUS_READ_FUNC(device_addr, register_addr,\
409  register_data, rd_len)bus_read(device_addr, register_addr,\
410  register_data, rd_len)
411 /****************************************/
413 /****************************************/
414 /* defines the return parameter type of the BME280_DELAY_FUNCTION
415 */
416 #define BME280_DELAY_RETURN_TYPE void
417 
418 /* defines the calling parameter types of the BME280_DELAY_FUNCTION
419 */
420 #define BME280_DELAY_PARAM_TYPES u16
421 /***************************************************************/
423 /***************************************************************/
424 /* never change this line */
425 #define BME280_DELAY_FUNC(delay_in_msec)\
426  delay_func(delay_in_msec)
427 
428 #define BME280_GET_BITSLICE(regvar, bitname)\
429  ((regvar & bitname##__MSK) >> bitname##__POS)
430 
431 #define BME280_SET_BITSLICE(regvar, bitname, val)\
432 ((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
433 
434 /***************************************************************/
436 /***************************************************************/
437 /* Constants */
438 #define BME280_NULL (0)
439 #define BME280_RETURN_FUNCTION_TYPE s8
440 /* shift definitions*/
441 #define BME280_SHIFT_BIT_POSITION_BY_01_BIT (1)
442 #define BME280_SHIFT_BIT_POSITION_BY_02_BITS (2)
443 #define BME280_SHIFT_BIT_POSITION_BY_03_BITS (3)
444 #define BME280_SHIFT_BIT_POSITION_BY_04_BITS (4)
445 #define BME280_SHIFT_BIT_POSITION_BY_07_BITS (7)
446 #define BME280_SHIFT_BIT_POSITION_BY_08_BITS (8)
447 #define BME280_SHIFT_BIT_POSITION_BY_10_BITS (10)
448 #define BME280_SHIFT_BIT_POSITION_BY_11_BITS (11)
449 #define BME280_SHIFT_BIT_POSITION_BY_12_BITS (12)
450 #define BME280_SHIFT_BIT_POSITION_BY_13_BITS (13)
451 #define BME280_SHIFT_BIT_POSITION_BY_14_BITS (14)
452 #define BME280_SHIFT_BIT_POSITION_BY_15_BITS (15)
453 #define BME280_SHIFT_BIT_POSITION_BY_16_BITS (16)
454 #define BME280_SHIFT_BIT_POSITION_BY_17_BITS (17)
455 #define BME280_SHIFT_BIT_POSITION_BY_18_BITS (18)
456 #define BME280_SHIFT_BIT_POSITION_BY_19_BITS (19)
457 #define BME280_SHIFT_BIT_POSITION_BY_20_BITS (20)
458 #define BME280_SHIFT_BIT_POSITION_BY_25_BITS (25)
459 #define BME280_SHIFT_BIT_POSITION_BY_31_BITS (31)
460 #define BME280_SHIFT_BIT_POSITION_BY_33_BITS (33)
461 #define BME280_SHIFT_BIT_POSITION_BY_35_BITS (35)
462 #define BME280_SHIFT_BIT_POSITION_BY_47_BITS (47)
463 
464 /* numeric definitions */
465 #define BME280_PRESSURE_TEMPERATURE_CALIB_DATA_LENGTH (26)
466 #define BME280_HUMIDITY_CALIB_DATA_LENGTH (7)
467 #define BME280_GEN_READ_WRITE_DATA_LENGTH (1)
468 #define BME280_HUMIDITY_DATA_LENGTH (2)
469 #define BME280_TEMPERATURE_DATA_LENGTH (3)
470 #define BME280_PRESSURE_DATA_LENGTH (3)
471 #define BME280_ALL_DATA_FRAME_LENGTH (8)
472 #define BME280_INIT_VALUE (0)
473 #define BME280_INVALID_DATA (0)
474 
475 /****************************************************/
477 /***************************************************/
478 #define SUCCESS ((u8)0)
479 #define E_BME280_NULL_PTR ((s8)-127)
480 #define E_BME280_COMM_RES ((s8)-1)
481 #define E_BME280_OUT_OF_RANGE ((s8)-2)
482 #define ERROR ((s8)-1)
483 /****************************************************/
485 /***************************************************/
486 #define BME280_I2C_ADDRESS1 (0x76)
487 #define BME280_I2C_ADDRESS2 (0x77)
488 /****************************************************/
490 /***************************************************/
491 /* Sensor Specific constants */
492 #define BME280_SLEEP_MODE (0x00)
493 #define BME280_FORCED_MODE (0x01)
494 #define BME280_NORMAL_MODE (0x03)
495 #define BME280_SOFT_RESET_CODE (0xB6)
496 /****************************************************/
498 /***************************************************/
499 #define BME280_STANDBY_TIME_1_MS (0x00)
500 #define BME280_STANDBY_TIME_63_MS (0x01)
501 #define BME280_STANDBY_TIME_125_MS (0x02)
502 #define BME280_STANDBY_TIME_250_MS (0x03)
503 #define BME280_STANDBY_TIME_500_MS (0x04)
504 #define BME280_STANDBY_TIME_1000_MS (0x05)
505 #define BME280_STANDBY_TIME_10_MS (0x06)
506 #define BME280_STANDBY_TIME_20_MS (0x07)
507 /****************************************************/
509 /***************************************************/
510 #define BME280_OVERSAMP_SKIPPED (0x00)
511 #define BME280_OVERSAMP_1X (0x01)
512 #define BME280_OVERSAMP_2X (0x02)
513 #define BME280_OVERSAMP_4X (0x03)
514 #define BME280_OVERSAMP_8X (0x04)
515 #define BME280_OVERSAMP_16X (0x05)
516 /****************************************************/
518 /***************************************************/
519 /*#define BME280_ULTRALOWPOWER_MODE (0x00)
520 #define BME280_LOWPOWER_MODE (0x01)
521 #define BME280_STANDARDRESOLUTION_MODE (0x02)
522 #define BME280_HIGHRESOLUTION_MODE (0x03)
523 #define BME280_ULTRAHIGHRESOLUTION_MODE (0x04)
524 
525 #define BME280_ULTRALOWPOWER_OSRS_P BME280_OVERSAMP_1X
526 #define BME280_ULTRALOWPOWER_OSRS_T BME280_OVERSAMP_1X
527 
528 #define BME280_LOWPOWER_OSRS_P BME280_OVERSAMP_2X
529 #define BME280_LOWPOWER_OSRS_T BME280_OVERSAMP_1X
530 
531 #define BME280_STANDARDRESOLUTION_OSRS_P BME280_OVERSAMP_4X
532 #define BME280_STANDARDRESOLUTION_OSRS_T BME280_OVERSAMP_1X
533 
534 #define BME280_HIGHRESOLUTION_OSRS_P BME280_OVERSAMP_8X
535 #define BME280_HIGHRESOLUTION_OSRS_T BME280_OVERSAMP_1X
536 
537 #define BME280_ULTRAHIGHRESOLUTION_OSRS_P BME280_OVERSAMP_16X
538 #define BME280_ULTRAHIGHRESOLUTION_OSRS_T BME280_OVERSAMP_2X */
539 
540 #define BME280_STANDARD_OVERSAMP_HUMIDITY BME280_OVERSAMP_1X
541 /****************************************************/
543 /***************************************************/
544 #define BME280_FILTER_COEFF_OFF (0x00)
545 #define BME280_FILTER_COEFF_2 (0x01)
546 #define BME280_FILTER_COEFF_4 (0x02)
547 #define BME280_FILTER_COEFF_8 (0x03)
548 #define BME280_FILTER_COEFF_16 (0x04)
549 /****************************************************/
551 /***************************************************/
552 #define T_INIT_MAX (20)
553  /* 20/16 = 1.25 ms */
554 #define T_MEASURE_PER_OSRS_MAX (37)
555  /* 37/16 = 2.3125 ms*/
556 
557 #define T_SETUP_PRESSURE_MAX (10)
558  /* 10/16 = 0.625 ms */
559 
560 #define T_SETUP_HUMIDITY_MAX (10)
561  /* 10/16 = 0.625 ms */
562 /****************************************************/
564 /***************************************************/
565 #define BME280_HUMIDITY_DATA_SIZE (2)
566 #define BME280_TEMPERATURE_DATA_SIZE (3)
567 #define BME280_PRESSURE_DATA_SIZE (3)
568 #define BME280_DATA_FRAME_SIZE (8)
569 
571 #define BME280_CALIB_DATA_SIZE (26)
572 
573 #define BME280_TEMPERATURE_MSB_DATA (0)
574 #define BME280_TEMPERATURE_LSB_DATA (1)
575 #define BME280_TEMPERATURE_XLSB_DATA (2)
576 #define BME280_PRESSURE_MSB_DATA (0)
577 #define BME280_PRESSURE_LSB_DATA (1)
578 #define BME280_PRESSURE_XLSB_DATA (2)
579 #define BME280_HUMIDITY_MSB_DATA (0)
580 #define BME280_HUMIDITY_LSB_DATA (1)
581 
582 #define BME280_DATA_FRAME_PRESSURE_MSB_BYTE (0)
583 #define BME280_DATA_FRAME_PRESSURE_LSB_BYTE (1)
584 #define BME280_DATA_FRAME_PRESSURE_XLSB_BYTE (2)
585 #define BME280_DATA_FRAME_TEMPERATURE_MSB_BYTE (3)
586 #define BME280_DATA_FRAME_TEMPERATURE_LSB_BYTE (4)
587 #define BME280_DATA_FRAME_TEMPERATURE_XLSB_BYTE (5)
588 #define BME280_DATA_FRAME_HUMIDITY_MSB_BYTE (6)
589 #define BME280_DATA_FRAME_HUMIDITY_LSB_BYTE (7)
590 /****************************************************/
592 /***************************************************/
593 #define BME280_TEMPERATURE_CALIB_DIG_T1_LSB (0)
594 #define BME280_TEMPERATURE_CALIB_DIG_T1_MSB (1)
595 #define BME280_TEMPERATURE_CALIB_DIG_T2_LSB (2)
596 #define BME280_TEMPERATURE_CALIB_DIG_T2_MSB (3)
597 #define BME280_TEMPERATURE_CALIB_DIG_T3_LSB (4)
598 #define BME280_TEMPERATURE_CALIB_DIG_T3_MSB (5)
599 #define BME280_PRESSURE_CALIB_DIG_P1_LSB (6)
600 #define BME280_PRESSURE_CALIB_DIG_P1_MSB (7)
601 #define BME280_PRESSURE_CALIB_DIG_P2_LSB (8)
602 #define BME280_PRESSURE_CALIB_DIG_P2_MSB (9)
603 #define BME280_PRESSURE_CALIB_DIG_P3_LSB (10)
604 #define BME280_PRESSURE_CALIB_DIG_P3_MSB (11)
605 #define BME280_PRESSURE_CALIB_DIG_P4_LSB (12)
606 #define BME280_PRESSURE_CALIB_DIG_P4_MSB (13)
607 #define BME280_PRESSURE_CALIB_DIG_P5_LSB (14)
608 #define BME280_PRESSURE_CALIB_DIG_P5_MSB (15)
609 #define BME280_PRESSURE_CALIB_DIG_P6_LSB (16)
610 #define BME280_PRESSURE_CALIB_DIG_P6_MSB (17)
611 #define BME280_PRESSURE_CALIB_DIG_P7_LSB (18)
612 #define BME280_PRESSURE_CALIB_DIG_P7_MSB (19)
613 #define BME280_PRESSURE_CALIB_DIG_P8_LSB (20)
614 #define BME280_PRESSURE_CALIB_DIG_P8_MSB (21)
615 #define BME280_PRESSURE_CALIB_DIG_P9_LSB (22)
616 #define BME280_PRESSURE_CALIB_DIG_P9_MSB (23)
617 #define BME280_HUMIDITY_CALIB_DIG_H1 (25)
618 #define BME280_HUMIDITY_CALIB_DIG_H2_LSB (0)
619 #define BME280_HUMIDITY_CALIB_DIG_H2_MSB (1)
620 #define BME280_HUMIDITY_CALIB_DIG_H3 (2)
621 #define BME280_HUMIDITY_CALIB_DIG_H4_MSB (3)
622 #define BME280_HUMIDITY_CALIB_DIG_H4_LSB (4)
623 #define BME280_HUMIDITY_CALIB_DIG_H5_MSB (5)
624 #define BME280_HUMIDITY_CALIB_DIG_H6 (6)
625 #define BME280_MASK_DIG_H4 (0x0F)
626 /****************************************************/
628 /***************************************************/
629 /*calibration parameters */
630 #define BME280_TEMPERATURE_CALIB_DIG_T1_LSB_REG (0x88)
631 #define BME280_TEMPERATURE_CALIB_DIG_T1_MSB_REG (0x89)
632 #define BME280_TEMPERATURE_CALIB_DIG_T2_LSB_REG (0x8A)
633 #define BME280_TEMPERATURE_CALIB_DIG_T2_MSB_REG (0x8B)
634 #define BME280_TEMPERATURE_CALIB_DIG_T3_LSB_REG (0x8C)
635 #define BME280_TEMPERATURE_CALIB_DIG_T3_MSB_REG (0x8D)
636 #define BME280_PRESSURE_CALIB_DIG_P1_LSB_REG (0x8E)
637 #define BME280_PRESSURE_CALIB_DIG_P1_MSB_REG (0x8F)
638 #define BME280_PRESSURE_CALIB_DIG_P2_LSB_REG (0x90)
639 #define BME280_PRESSURE_CALIB_DIG_P2_MSB_REG (0x91)
640 #define BME280_PRESSURE_CALIB_DIG_P3_LSB_REG (0x92)
641 #define BME280_PRESSURE_CALIB_DIG_P3_MSB_REG (0x93)
642 #define BME280_PRESSURE_CALIB_DIG_P4_LSB_REG (0x94)
643 #define BME280_PRESSURE_CALIB_DIG_P4_MSB_REG (0x95)
644 #define BME280_PRESSURE_CALIB_DIG_P5_LSB_REG (0x96)
645 #define BME280_PRESSURE_CALIB_DIG_P5_MSB_REG (0x97)
646 #define BME280_PRESSURE_CALIB_DIG_P6_LSB_REG (0x98)
647 #define BME280_PRESSURE_CALIB_DIG_P6_MSB_REG (0x99)
648 #define BME280_PRESSURE_CALIB_DIG_P7_LSB_REG (0x9A)
649 #define BME280_PRESSURE_CALIB_DIG_P7_MSB_REG (0x9B)
650 #define BME280_PRESSURE_CALIB_DIG_P8_LSB_REG (0x9C)
651 #define BME280_PRESSURE_CALIB_DIG_P8_MSB_REG (0x9D)
652 #define BME280_PRESSURE_CALIB_DIG_P9_LSB_REG (0x9E)
653 #define BME280_PRESSURE_CALIB_DIG_P9_MSB_REG (0x9F)
654 
655 #define BME280_HUMIDITY_CALIB_DIG_H1_REG (0xA1)
656 
657 #define BME280_HUMIDITY_CALIB_DIG_H2_LSB_REG (0xE1)
658 #define BME280_HUMIDITY_CALIB_DIG_H2_MSB_REG (0xE2)
659 #define BME280_HUMIDITY_CALIB_DIG_H3_REG (0xE3)
660 #define BME280_HUMIDITY_CALIB_DIG_H4_MSB_REG (0xE4)
661 #define BME280_HUMIDITY_CALIB_DIG_H4_LSB_REG (0xE5)
662 #define BME280_HUMIDITY_CALIB_DIG_H5_MSB_REG (0xE6)
663 #define BME280_HUMIDITY_CALIB_DIG_H6_REG (0xE7)
664 /****************************************************/
666 /***************************************************/
667 #define BME280_CHIP_ID_REG (0xD0) /*Chip ID Register */
668 #define BME280_RST_REG (0xE0) /*Softreset Register */
669 #define BME280_STAT_REG (0xF3) /*Status Register */
670 #define BME280_CTRL_MEAS_REG (0xF4) /*Ctrl Measure Register */
671 #define BME280_CTRL_HUMIDITY_REG (0xF2) /*Ctrl Humidity Register*/
672 #define BME280_CONFIG_REG (0xF5) /*Configuration Register */
673 #define BME280_PRESSURE_MSB_REG (0xF7) /*Pressure MSB Register */
674 #define BME280_PRESSURE_LSB_REG (0xF8) /*Pressure LSB Register */
675 #define BME280_PRESSURE_XLSB_REG (0xF9) /*Pressure XLSB Register */
676 #define BME280_TEMPERATURE_MSB_REG (0xFA) /*Temperature MSB Reg */
677 #define BME280_TEMPERATURE_LSB_REG (0xFB) /*Temperature LSB Reg */
678 #define BME280_TEMPERATURE_XLSB_REG (0xFC) /*Temperature XLSB Reg */
679 #define BME280_HUMIDITY_MSB_REG (0xFD) /*Humidity MSB Reg */
680 #define BME280_HUMIDITY_LSB_REG (0xFE) /*Humidity LSB Reg */
681 /****************************************************/
683 /***************************************************/
684 /* Status Register */
685 #define BME280_STAT_REG_MEASURING__POS (3)
686 #define BME280_STAT_REG_MEASURING__MSK (0x08)
687 #define BME280_STAT_REG_MEASURING__LEN (1)
688 #define BME280_STAT_REG_MEASURING__REG (BME280_STAT_REG)
689 
690 #define BME280_STAT_REG_IM_UPDATE__POS (0)
691 #define BME280_STAT_REG_IM_UPDATE__MSK (0x01)
692 #define BME280_STAT_REG_IM_UPDATE__LEN (1)
693 #define BME280_STAT_REG_IM_UPDATE__REG (BME280_STAT_REG)
694 /****************************************************/
697 /***************************************************/
698 /* Control Measurement Register */
699 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__POS (5)
700 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__MSK (0xE0)
701 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__LEN (3)
702 #define BME280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG \
703 (BME280_CTRL_MEAS_REG)
704 /****************************************************/
707 /***************************************************/
708 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__POS (2)
709 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__MSK (0x1C)
710 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__LEN (3)
711 #define BME280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG \
712 (BME280_CTRL_MEAS_REG)
713 /****************************************************/
716 /***************************************************/
717 #define BME280_CTRL_MEAS_REG_POWER_MODE__POS (0)
718 #define BME280_CTRL_MEAS_REG_POWER_MODE__MSK (0x03)
719 #define BME280_CTRL_MEAS_REG_POWER_MODE__LEN (2)
720 #define BME280_CTRL_MEAS_REG_POWER_MODE__REG \
721 (BME280_CTRL_MEAS_REG)
722 /****************************************************/
725 /***************************************************/
726 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__POS (0)
727 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__MSK (0x07)
728 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__LEN (3)
729 #define BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY__REG \
730 (BME280_CTRL_HUMIDITY_REG)
731 /****************************************************/
734 /***************************************************/
735 /* Configuration Register */
736 #define BME280_CONFIG_REG_TSB__POS (5)
737 #define BME280_CONFIG_REG_TSB__MSK (0xE0)
738 #define BME280_CONFIG_REG_TSB__LEN (3)
739 #define BME280_CONFIG_REG_TSB__REG (BME280_CONFIG_REG)
740 /****************************************************/
743 /***************************************************/
744 #define BME280_CONFIG_REG_FILTER__POS (2)
745 #define BME280_CONFIG_REG_FILTER__MSK (0x1C)
746 #define BME280_CONFIG_REG_FILTER__LEN (3)
747 #define BME280_CONFIG_REG_FILTER__REG (BME280_CONFIG_REG)
748 /****************************************************/
751 /***************************************************/
752 #define BME280_CONFIG_REG_SPI3_ENABLE__POS (0)
753 #define BME280_CONFIG_REG_SPI3_ENABLE__MSK (0x01)
754 #define BME280_CONFIG_REG_SPI3_ENABLE__LEN (1)
755 #define BME280_CONFIG_REG_SPI3_ENABLE__REG (BME280_CONFIG_REG)
756 /****************************************************/
759 /***************************************************/
760 /* Data Register */
761 #define BME280_PRESSURE_XLSB_REG_DATA__POS (4)
762 #define BME280_PRESSURE_XLSB_REG_DATA__MSK (0xF0)
763 #define BME280_PRESSURE_XLSB_REG_DATA__LEN (4)
764 #define BME280_PRESSURE_XLSB_REG_DATA__REG (BME280_PRESSURE_XLSB_REG)
765 
766 #define BME280_TEMPERATURE_XLSB_REG_DATA__POS (4)
767 #define BME280_TEMPERATURE_XLSB_REG_DATA__MSK (0xF0)
768 #define BME280_TEMPERATURE_XLSB_REG_DATA__LEN (4)
769 #define BME280_TEMPERATURE_XLSB_REG_DATA__REG (BME280_TEMPERATURE_XLSB_REG)
770 /****************************************************/
772 /***************************************************/
773 #define BME280_WR_FUNC_PTR\
774  s8 (*bus_write)(u8, u8,\
775  u8 *, u8)
776 
777 #define BME280_RD_FUNC_PTR\
778  s8 (*bus_read)(u8, u8,\
779  u8 *, u8)
780 
781 #define BME280_MDELAY_DATA_TYPE u16
782 
783 #define BME280_3MS_DELAY 3
784 /**************************************************************/
786 /**************************************************************/
812 };
816 struct bme280_t {
832  void (*delay_msec)(BME280_MDELAY_DATA_TYPE);
833 };
834 /**************************************************************/
836 /**************************************************************/
837 /**************************************************************/
839 /**************************************************************/
865 BME280_RETURN_FUNCTION_TYPE bme280_init(struct bme280_t *bme280);
866 /**************************************************************/
868 /**************************************************************/
886 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_temperature(
887 s32 *v_uncomp_temperature_s32);
888 /**************************************************************/
890 /**************************************************************/
904 s32 bme280_compensate_temperature_int32(s32 v_uncomp_temperature_s32);
919 s32 v_uncomp_temperature_s32);
920 /**************************************************************/
922 /**************************************************************/
942 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure(
943 s32 *v_uncomp_pressure_s32);
944 /**************************************************************/
946 /**************************************************************/
962 u32 bme280_compensate_pressure_int32(s32 v_uncomp_pressure_s32);
963 /**************************************************************/
965 /**************************************************************/
984 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_humidity(
985 s32 *v_uncomp_humidity_s32);
986 /**************************************************************/
988 /**************************************************************/
1003 u32 bme280_compensate_humidity_int32(s32 v_uncomp_humidity_s32);
1019 s32 v_uncomp_humidity_s32);
1020 /**************************************************************/
1023 /**************************************************************/
1043 BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure_temperature_humidity(
1044 s32 *v_uncomp_pressure_s32,
1045 s32 *v_uncomp_temperature_s32, s32 *v_uncomp_humidity_s32);
1046 /**************************************************************/
1049 /**************************************************************/
1067 BME280_RETURN_FUNCTION_TYPE bme280_read_pressure_temperature_humidity(
1068 u32 *v_pressure_u32, s32 *v_temperature_s32, u32 *v_humidity_u32);
1069 /**************************************************************/
1071 /**************************************************************/
1100 BME280_RETURN_FUNCTION_TYPE bme280_get_calib_param(void);
1101 /**************************************************************/
1103 /**************************************************************/
1129 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_temperature(
1130 u8 *v_value_u8);
1156 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_temperature(
1157 u8 v_value_u8);
1158 /**************************************************************/
1160 /**************************************************************/
1186 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_pressure(
1187 u8 *v_value_u8);
1213 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_pressure(
1214 u8 v_value_u8);
1215 /**************************************************************/
1217 /**************************************************************/
1243 BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_humidity(u8 *v_value_u8);
1283 BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_humidity(
1284 u8 v_value_u8);
1285 /**************************************************************/
1287 /**************************************************************/
1307 BME280_RETURN_FUNCTION_TYPE bme280_get_power_mode(u8 *v_power_mode_u8);
1327 BME280_RETURN_FUNCTION_TYPE bme280_set_power_mode(u8 v_power_mode_u8);
1328 /**************************************************************/
1330 /**************************************************************/
1346 BME280_RETURN_FUNCTION_TYPE bme280_set_soft_rst(void);
1347 /**************************************************************/
1349 /**************************************************************/
1370 BME280_RETURN_FUNCTION_TYPE bme280_get_spi3(u8 *v_enable_disable_u8);
1391 BME280_RETURN_FUNCTION_TYPE bme280_set_spi3(u8 v_enable_disable_u8);
1392 /**************************************************************/
1394 /**************************************************************/
1417 BME280_RETURN_FUNCTION_TYPE bme280_get_filter(u8 *v_value_u8);
1440 BME280_RETURN_FUNCTION_TYPE bme280_set_filter(u8 v_value_u8);
1441 /**************************************************************/
1443 /**************************************************************/
1467 BME280_RETURN_FUNCTION_TYPE bme280_get_standby_durn(u8 *v_standby_durn_u8);
1501 BME280_RETURN_FUNCTION_TYPE bme280_set_standby_durn(u8 v_standby_durn_u8);
1502 /**************************************************************/
1504 /**************************************************************/
1505 /*
1506  * @brief Writes the working mode to the sensor
1507  *
1508  *
1509  *
1510  *
1511  * @param v_work_mode_u8 : Mode to be set
1512  * value | Working mode
1513  * ----------|--------------------
1514  * 0 | BME280_ULTRALOWPOWER_MODE
1515  * 1 | BME280_LOWPOWER_MODE
1516  * 2 | BME280_STANDARDRESOLUTION_MODE
1517  * 3 | BME280_HIGHRESOLUTION_MODE
1518  * 4 | BME280_ULTRAHIGHRESOLUTION_MODE
1519  *
1520  * @return results of bus communication function
1521  * @retval 0 -> Success
1522  * @retval -1 -> Error
1523  *
1524  *
1525 */
1526 /*BME280_RETURN_FUNCTION_TYPE bme280_set_work_mode(u8 v_work_mode_u8);*/
1527 /**************************************************************/
1529 /**************************************************************/
1546 BME280_RETURN_FUNCTION_TYPE
1548 s32 *v_uncom_pressure_s32,
1549 s32 *v_uncom_temperature_s32, s32 *v_uncom_humidity_s32);
1550 /**************************************************************/
1552 /**************************************************************/
1570 BME280_RETURN_FUNCTION_TYPE bme280_write_register(u8 v_addr_u8,
1571 u8 *v_data_u8, u8 v_len_u8);
1589 BME280_RETURN_FUNCTION_TYPE bme280_read_register(u8 v_addr_u8,
1590 u8 *v_data_u8, u8 v_len_u8);
1591 /**************************************************************/
1593 /**************************************************************/
1594 #ifdef BME280_ENABLE_FLOAT
1595 
1610 s32 v_uncom_temperature_s32);
1611 /**************************************************************/
1613 /**************************************************************/
1627 double bme280_compensate_pressure_double(s32 v_uncom_pressure_s32);
1628 /**************************************************************/
1630 /**************************************************************/
1643 double bme280_compensate_humidity_double(s32 v_uncom_humidity_s32);
1644 #endif
1645 /**************************************************************/
1647 /**************************************************************/
1648 #if defined(BME280_ENABLE_INT64) && defined(BME280_64BITSUPPORT_PRESENT)
1649 
1665 u32 bme280_compensate_pressure_int64(s32 v_uncom_pressure_s32);
1666 /**************************************************************/
1668 /**************************************************************/
1684 s32 v_uncom_pressure_s32);
1685 #endif
1686 /**************************************************************/
1688 /**************************************************************/
1702 BME280_RETURN_FUNCTION_TYPE bme280_compute_wait_time(u8
1703 *v_delaytime_u8r);
1704 #endif
BME280_RETURN_FUNCTION_TYPE bme280_set_filter(u8 v_value_u8)
This API is used to write filter setting in the register 0xF5 bit 3 and 4.
Definition: bme280driver.cxx:1522
BME280_RETURN_FUNCTION_TYPE bme280_init(struct bme280_t *bme280)
This function is used for initialize the bus read and bus write functions and assign the chip id and ...
Definition: bme280driver.cxx:82
u8 ctrl_hum_reg
Definition: bme280driver.h:826
BME280_RETURN_FUNCTION_TYPE bme280_get_forced_uncomp_pressure_temperature_humidity(s32 *v_uncom_pressure_s32, s32 *v_uncom_temperature_s32, s32 *v_uncom_humidity_s32)
This API used to read uncompensated temperature,pressure and humidity in forced mode.
Definition: bme280driver.cxx:1820
BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_humidity(u8 *v_value_u8)
This API is used to get the humidity oversampling setting in the register 0xF2 bits from 0 to 2...
Definition: bme280driver.cxx:1039
BME280_RD_FUNC_PTR
Definition: bme280driver.h:831
BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure(s32 *v_uncomp_pressure_s32)
This API is used to read uncompensated pressure. in the registers 0xF7, 0xF8 and 0xF9.
Definition: bme280driver.cxx:236
s16 dig_P9
Definition: bme280driver.h:802
double bme280_compensate_pressure_double(s32 v_uncom_pressure_s32)
Reads actual pressure from uncompensated pressure.
Definition: bme280driver.cxx:2015
s16 dig_P3
Definition: bme280driver.h:796
s16 dig_P7
Definition: bme280driver.h:800
s32 t_fine
Definition: bme280driver.h:811
s16 dig_P4
Definition: bme280driver.h:797
s16 dig_P8
Definition: bme280driver.h:801
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:1355
u8 oversamp_temperature
Definition: bme280driver.h:823
u8 chip_id
Definition: bme280driver.h:820
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:1319
u8 dev_addr
Definition: bme280driver.h:821
u16 bme280_compensate_humidity_int32_sixteen_bit_output(s32 v_uncomp_humidity_s32)
Reads actual humidity from uncompensated humidity.
Definition: bme280driver.cxx:456
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:1229
s16 dig_T2
Definition: bme280driver.h:792
signed short int s16
Definition: bme280driver.h:195
BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_temperature(s32 *v_uncomp_temperature_s32)
This API is used to read uncompensated temperature in the registers 0xFA, 0xFB and 0xFC...
Definition: bme280driver.cxx:117
s16 dig_P2
Definition: bme280driver.h:795
u8 ctrl_meas_reg
Definition: bme280driver.h:827
s16 bme280_compensate_temperature_int32_sixteen_bit_output(s32 v_uncomp_temperature_s32)
Reads actual temperature from uncompensated temperature.
Definition: bme280driver.cxx:204
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:947
BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_humidity(s32 *v_uncomp_humidity_s32)
This API is used to read uncompensated humidity. in the registers 0xF7, 0xF8 and 0xF9.
Definition: bme280driver.cxx:371
BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_humidity(u8 v_value_u8)
This API is used to set the humidity oversampling setting in the register 0xF2 bits from 0 to 2...
Definition: bme280driver.cxx:1100
u32 bme280_compensate_pressure_int64_twentyfour_bit_output(s32 v_uncom_pressure_s32)
Reads actual pressure from uncompensated pressure.
Definition: bme280driver.cxx:2168
BME280_RETURN_FUNCTION_TYPE bme280_set_standby_durn(u8 v_standby_durn_u8)
This API used to write the standby duration time from the sensor in the register 0xF5 bit 5 to 7...
Definition: bme280driver.cxx:1660
BME280_RETURN_FUNCTION_TYPE bme280_write_register(u8 v_addr_u8, u8 *v_data_u8, u8 v_len_u8)
This API write the data to the given register.
Definition: bme280driver.cxx:1920
s16 dig_P6
Definition: bme280driver.h:799
signed long long int s64
Definition: bme280driver.h:197
unsigned char u8
Definition: bme280driver.h:200
void(* delay_msec)(BME280_MDELAY_DATA_TYPE)
Definition: bme280driver.h:832
u16 dig_P1
Definition: bme280driver.h:794
double bme280_compensate_humidity_double(s32 v_uncom_humidity_s32)
Reads actual humidity from uncompensated humidity.
Definition: bme280driver.cxx:2060
BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure_temperature_humidity(s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32, s32 *v_uncomp_humidity_s32)
This API used to read uncompensated pressure,temperature and humidity.
Definition: bme280driver.cxx:485
BME280_RETURN_FUNCTION_TYPE bme280_read_register(u8 v_addr_u8, u8 *v_data_u8, u8 v_len_u8)
This API reads the data from the given register.
Definition: bme280driver.cxx:1952
This structure holds all device specific calibration parameters.
Definition: bme280driver.h:790
unsigned long long int u64
Definition: bme280driver.h:203
u8 oversamp_pressure
Definition: bme280driver.h:824
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:808
u8 config_reg
Definition: bme280driver.h:828
BME280_RETURN_FUNCTION_TYPE bme280_get_filter(u8 *v_value_u8)
This API is used to reads filter setting in the register 0xF5 bit 3 and 4.
Definition: bme280driver.cxx:1482
u16 dig_T1
Definition: bme280driver.h:791
u32 bme280_compensate_pressure_int64(s32 v_uncom_pressure_s32)
Reads actual pressure from uncompensated pressure.
Definition: bme280driver.cxx:2102
BME280_RETURN_FUNCTION_TYPE bme280_read_pressure_temperature_humidity(u32 *v_pressure_u32, s32 *v_temperature_s32, u32 *v_humidity_u32)
This API used to read true pressure, temperature and humidity.
Definition: bme280driver.cxx:565
This structure holds BME280 initialization parameters.
Definition: bme280driver.h:816
s16 dig_H5
Definition: bme280driver.h:808
signed int s32
Definition: bme280driver.h:196
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:900
unsigned int u32
Definition: bme280driver.h:202
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:1609
u32 bme280_compensate_humidity_int32(s32 v_uncomp_humidity_s32)
Reads actual humidity from uncompensated humidity.
Definition: bme280driver.cxx:411
s16 dig_T3
Definition: bme280driver.h:793
BME280_RETURN_FUNCTION_TYPE bme280_get_calib_param(void)
This API is used to calibration parameters used for calculation in the registers. ...
Definition: bme280driver.cxx:622
signed char s8
If your machine support 16 bit define the MACHINE_16_BIT.
Definition: bme280driver.h:194
s16 dig_P5
Definition: bme280driver.h:798
s32 bme280_compensate_temperature_int32(s32 v_uncomp_temperature_s32)
Reads actual temperature from uncompensated temperature.
Definition: bme280driver.cxx:161
u8 oversamp_humidity
Definition: bme280driver.h:825
BME280_RETURN_FUNCTION_TYPE bme280_compute_wait_time(u8 *v_delaytime_u8r)
Computing waiting time for sensor data read.
Definition: bme280driver.cxx:2192
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:1394
s16 dig_H4
Definition: bme280driver.h:807
s16 dig_H2
Definition: bme280driver.h:805
s8 dig_H6
Definition: bme280driver.h:809
double bme280_compensate_temperature_double(s32 v_uncom_temperature_s32)
Reads actual temperature from uncompensated temperature.
Definition: bme280driver.cxx:1982
struct bme280_calibration_param_t cal_param
Definition: bme280driver.h:817
u32 bme280_compensate_pressure_int32(s32 v_uncomp_pressure_s32)
Reads actual pressure from uncompensated pressure.
Definition: bme280driver.cxx:281
unsigned short int u16
Definition: bme280driver.h:201
u8 dig_H3
Definition: bme280driver.h:806
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:1192
BME280_WR_FUNC_PTR
Definition: bme280driver.h:830
BME280_RETURN_FUNCTION_TYPE bme280_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: bme280driver.cxx:762
u8 dig_H1
Definition: bme280driver.h:804