-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathbmp280.h
1491 lines (1415 loc) · 52.4 KB
/
bmp280.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** \mainpage
*
****************************************************************************
* Copyright (C) 2012 - 2014 Bosch Sensortec GmbH
*
* File : bmp280.h
*
* Date : 2014/12/12
*
* Revision : 2.0.3(Pressure and Temperature compensation code revision is 1.1)
*
* Usage: Sensor Driver for BMP280 sensor
*
****************************************************************************
*
* \section License
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
* The information provided is believed to be accurate and reliable.
* The copyright holder assumes no responsibility
* for the consequences of use
* of such information nor for any infringement of patents or
* other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or
* patent rights of the copyright holder.
**************************************************************************/
/*! \file bmp280.h
\brief BMP280 Sensor Driver Support Header File */
#ifndef __BMP280_H__
#define __BMP280_H__
/*!
* @brief The following definition uses for define the data types
*
* @note While porting the API please consider the following
* @note Please check the version of C standard
* @note Are you using Linux platform
*/
/*!
* @brief For the Linux platform support
* Please use the types.h for your data types definitions
*/
#ifdef __KERNEL__
#include <linux/types.h>
#include <linux/math64.h>
#define BMP280_64BITSUPPORT_PRESENT
/* singed integer type*/
typedef int8_t s8;/**< used for signed 8bit */
typedef int16_t s16;/**< used for signed 16bit */
typedef int32_t s32;/**< used for signed 32bit */
typedef int64_t s64;/**< used for signed 64bit */
typedef u_int8_t u8;/**< used for unsigned 8bit */
typedef u_int16_t u16;/**< used for unsigned 16bit */
typedef u_int32_t u32;/**< used for unsigned 32bit */
typedef u_int64_t u64;/**< used for unsigned 64bit */
#else /* ! __KERNEL__ */
/**********************************************************
* These definition uses for define the C
* standard version data types
***********************************************************/
# if !defined(__STDC_VERSION__)
/************************************************
* compiler is C11 C standard
************************************************/
#if (__STDC_VERSION__ == 201112L)
/************************************************/
#include <stdint.h>
/************************************************/
/*unsigned integer types*/
typedef uint8_t u8;/**< used for unsigned 8bit */
typedef uint16_t u16;/**< used for unsigned 16bit */
typedef uint32_t u32;/**< used for unsigned 32bit */
typedef uint64_t u64;/**< used for unsigned 64bit */
/*signed integer types*/
typedef int8_t s8;/**< used for signed 8bit */
typedef int16_t s16;/**< used for signed 16bit */
typedef int32_t s32;/**< used for signed 32bit */
typedef int64_t s64;/**< used for signed 64bit */
#define BMP280_64BITSUPPORT_PRESENT
/************************************************
* compiler is C99 C standard
************************************************/
#elif (__STDC_VERSION__ == 199901L)
/* stdint.h is a C99 supported c library.
which is used to fixed the integer size*/
/************************************************/
#include <stdint.h>
/************************************************/
/*unsigned integer types*/
typedef uint8_t u8;/**< used for unsigned 8bit */
typedef uint16_t u16;/**< used for unsigned 16bit */
typedef uint32_t u32;/**< used for unsigned 32bit */
typedef uint64_t u64;/**< used for unsigned 64bit */
/*signed integer types*/
typedef int8_t s8;/**< used for signed 8bit */
typedef int16_t s16;/**< used for signed 16bit */
typedef int32_t s32;/**< used for signed 32bit */
typedef int64_t s64;/**< used for signed 64bit */
#define BMP280_64BITSUPPORT_PRESENT
/************************************************
* compiler is C89 or other C standard
************************************************/
#else /* !defined(__STDC_VERSION__) */
/*!
* @brief By default it is defined as 32 bit machine configuration
* define your data types based on your
* machine/compiler/controller configuration
*/
#define MACHINE_32_BIT
/*! @brief
* If your machine support 16 bit
* define the MACHINE_16_BIT
*/
#ifdef MACHINE_16_BIT
#include <limits.h>
/*signed integer types*/
typedef signed char s8;/**< used for signed 8bit */
typedef signed short int s16;/**< used for signed 16bit */
typedef signed long int s32;/**< used for signed 32bit */
#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL
typedef long int s64;/**< used for signed 64bit */
typedef unsigned long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL)
typedef long long int s64;/**< used for signed 64bit */
typedef unsigned long long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
#else
#warning Either the correct data type for signed 64 bit integer \
could not be found, or 64 bit integers are not supported in your environment.
#warning The API will only offer 32 bit pressure calculation.This will \
slightly impede accuracy(noise of ~1 pascal RMS will be added to output).
#warning If 64 bit integers are supported on your platform, \
please set s64 manually and "#define(BMP280_64BITSUPPORT_PRESENT)" manually.
#endif
/*unsigned integer types*/
typedef unsigned char u8;/**< used for unsigned 8bit */
typedef unsigned short int u16;/**< used for unsigned 16bit */
typedef unsigned long int u32;/**< used for unsigned 32bit */
/* If your machine support 32 bit
define the MACHINE_32_BIT*/
#elif defined MACHINE_32_BIT
/*signed integer types*/
typedef signed char s8;/**< used for signed 8bit */
typedef signed short int s16;/**< used for signed 16bit */
typedef signed int s32;/**< used for signed 32bit */
typedef signed long long int s64;/**< used for signed 64bit */
/*unsigned integer types*/
typedef unsigned char u8;/**< used for unsigned 8bit */
typedef unsigned short int u16;/**< used for unsigned 16bit */
typedef unsigned int u32;/**< used for unsigned 32bit */
typedef unsigned long long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
/* If your machine support 64 bit
define the MACHINE_64_BIT*/
#elif defined MACHINE_64_BIT
/*signed integer types*/
typedef signed char s8;/**< used for signed 8bit */
typedef signed short int s16;/**< used for signed 16bit */
typedef signed int s32;/**< used for signed 32bit */
typedef signed long int s64;/**< used for signed 64bit */
/*unsigned integer types*/
typedef unsigned char u8;/**< used for unsigned 8bit */
typedef unsigned short int u16;/**< used for unsigned 16bit */
typedef unsigned int u32;/**< used for unsigned 32bit */
typedef unsigned long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
#else
#warning The data types defined above which not supported \
define the data types manually
#endif
#endif
/*** This else will execute for the compilers
* which are not supported the C standards
* Like C89/C99/C11***/
#else
/*!
* @brief By default it is defined as 32 bit machine configuration
* define your data types based on your
* machine/compiler/controller configuration
*/
#define MACHINE_32_BIT
/* If your machine support 16 bit
define the MACHINE_16_BIT*/
#ifdef MACHINE_16_BIT
#include <limits.h>
/*signed integer types*/
typedef signed char s8;/**< used for signed 8bit */
typedef signed short int s16;/**< used for signed 16bit */
typedef signed long int s32;/**< used for signed 32bit */
#if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL
typedef long int s64;/**< used for signed 64bit */
typedef unsigned long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
#elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL)
typedef long long int s64;/**< used for signed 64bit */
typedef unsigned long long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
#else
#warning Either the correct data type for signed 64 bit integer \
could not be found, or 64 bit integers are not supported in your environment.
#warning The API will only offer 32 bit pressure calculation.This will \
slightly impede accuracy(noise of ~1 pascal RMS will be added to output).
#warning If 64 bit integers are supported on your platform, \
please set s64 manually and "#define(BMP280_64BITSUPPORT_PRESENT)" manually.
#endif
/*unsigned integer types*/
typedef unsigned char u8;/**< used for unsigned 8bit */
typedef unsigned short int u16;/**< used for unsigned 16bit */
typedef unsigned long int u32;/**< used for unsigned 32bit */
/*! @brief If your machine support 32 bit
define the MACHINE_32_BIT*/
#elif defined MACHINE_32_BIT
/*signed integer types*/
typedef signed char s8;/**< used for signed 8bit */
typedef signed short int s16;/**< used for signed 16bit */
typedef signed int s32;/**< used for signed 32bit */
typedef signed long long int s64;/**< used for signed 64bit */
/*unsigned integer types*/
typedef unsigned char u8;/**< used for unsigned 8bit */
typedef unsigned short int u16;/**< used for unsigned 16bit */
typedef unsigned int u32;/**< used for unsigned 32bit */
typedef unsigned long long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
/* If your machine support 64 bit
define the MACHINE_64_BIT*/
#elif defined MACHINE_64_BIT
/*signed integer types*/
typedef signed char s8;/**< used for signed 8bit */
typedef signed short int s16;/**< used for signed 16bit */
typedef signed int s32;/**< used for signed 32bit */
typedef signed long int s64;/**< used for signed 64bit */
/*unsigned integer types*/
typedef unsigned char u8;/**< used for unsigned 8bit */
typedef unsigned short int u16;/**< used for unsigned 16bit */
typedef unsigned int u32;/**< used for unsigned 32bit */
typedef unsigned long int u64;/**< used for unsigned 64bit */
#define BMP280_64BITSUPPORT_PRESENT
#else
#warning The data types defined above which not supported \
define the data types manually
#endif
#endif
#endif
/********************************************/
/**\name ENABLE FLATING OUTPUT */
/**************************************/
/*!
* @brief If the user wants to support floating point calculations, please set
* the following define. If floating point calculation is not wanted
* or allowed (e.g. in Linux kernel), please do not set the definition.
*/
#define BMP280_ENABLE_FLOAT
/*!
* @brief If the user wants to support 64 bit integer calculation (needed for
* optimal pressure accuracy) please set the following definition. If
* int64 calculation is not wanted (e.g. because it would include
* large libraries), please do not set the definition.
*/
#define BMP280_ENABLE_INT64
/***************************************************************/
/**\name BUS READ AND WRITE FUNCTION POINTERS */
/***************************************************************/
/*!
@brief Define the calling convention of YOUR bus communication routine.
@note This includes types of parameters. This example shows the
configuration for an SPI bus link.
If your communication function looks like this:
write_my_bus_xy(u8 device_addr, u8 register_addr,
u8 * data, u8 length);
The BMP280_WR_FUNC_PTR would equal:
BMP280_WR_FUNC_PTR s8 (* bus_write)(u8,
u8, u8 *, u8)
Parameters can be mixed as needed refer to the
refer BMP280_BUS_WRITE_FUNC macro.
*/
/* defines the return parameter type of the BMP280_WR_FUNCTION */
#define BMP280_BUS_WR_RETURN_TYPE s8
/* links the order of parameters defined in
BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
#define BMP280_BUS_WR_PARAM_TYPES u8, u8,\
u8 *, u8
/* links the order of parameters defined in
BMP280_BUS_WR_PARAM_TYPE to function calls used inside the API*/
#define BMP280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\
register_data, wr_len)
/* never change this line */
#define BMP280_BUS_WRITE_FUNC(device_addr, register_addr,\
register_data, wr_len) bus_write(device_addr, register_addr,\
register_data, wr_len)
/*!
@brief link macro between API function calls and bus read function
@note The bus write function can change since this is a
system dependant issue.
If the bus_read parameter calling order is like: reg_addr,
reg_data, wr_len it would be as it is here.
If the parameters are differently ordered or your communication
function like I2C need to know the device address,
you can change this macro accordingly.
BMP280_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\
bus_read(dev_addr, reg_addr, reg_data, wr_len)
This macro lets all API functions call YOUR communication routine in a
way that equals your definition in the
refer BMP280_WR_FUNC_PTR definition.
@note: this macro also includes the "MSB='1'
for reading BMP280 addresses.
*/
/* defines the return parameter type of the BMP280_RD_FUNCTION
*/
#define BMP280_BUS_RD_RETURN_TYPE s8
/* defines the calling parameter types of the BMP280_RD_FUNCTION
*/
#define BMP280_BUS_RD_PARAM_TYPES (u8, u8,\
u8 *, u8)
/* links the order of parameters defined in \
BMP280_BUS_RD_PARAM_TYPE to function calls used inside the API
*/
#define BMP280_BUS_RD_PARAM_ORDER (device_addr, register_addr,\
register_data)
/* never change this line */
#define BMP280_BUS_READ_FUNC(device_addr, register_addr,\
register_data, rd_len)bus_read(device_addr, register_addr,\
register_data, rd_len)
/****************************************/
/**\name DELAY */
/****************************************/
/*!
* @brief defines the return parameter type of the BMP280_DELAY_FUNCTION
*/
#define BMP280_DELAY_RETURN_TYPE void
/*!
* @brief defines the calling parameter types of the BMP280_DELAY_FUNCTION
*/
#define BMP280_DELAY_PARAM_TYPES u16
/***************************************************************/
/**\name GET AND SET BITSLICE FUNCTIONS */
/***************************************************************/
/* never change this line */
#define BMP280_DELAY_FUNC(delay_in_msec)\
delay_func(delay_in_msec)
#define BMP280_GET_BITSLICE(regvar, bitname)\
((regvar & bitname##__MSK) >> bitname##__POS)
#define BMP280_SET_BITSLICE(regvar, bitname, val)\
((regvar & ~bitname##__MSK) | ((val<<bitname##__POS)&bitname##__MSK))
/***************************************************************/
/**\name COMMON USED CONSTANTS */
/***************************************************************/
/* Constants */
#define BMP280_NULL 0
#define BMP280_RETURN_FUNCTION_TYPE s8
/* right shift definitions*/
#define SHIFT_RIGHT_1_POSITION 1
#define SHIFT_RIGHT_2_POSITION 2
#define SHIFT_RIGHT_3_POSITION 3
#define SHIFT_RIGHT_4_POSITION 4
#define SHIFT_RIGHT_8_POSITION 8
#define SHIFT_RIGHT_11_POSITION 11
#define SHIFT_RIGHT_12_POSITION 12
#define SHIFT_RIGHT_13_POSITION 13
#define SHIFT_RIGHT_14_POSITION 14
#define SHIFT_RIGHT_15_POSITION 15
#define SHIFT_RIGHT_18_POSITION 18
#define SHIFT_RIGHT_19_POSITION 19
#define SHIFT_RIGHT_25_POSITION 25
#define SHIFT_RIGHT_33_POSITION 33
/* left shift definitions*/
#define SHIFT_LEFT_1_POSITION 1
#define SHIFT_LEFT_2_POSITION 2
#define SHIFT_LEFT_4_POSITION 4
#define SHIFT_LEFT_5_POSITION 5
#define SHIFT_LEFT_8_POSITION 8
#define SHIFT_LEFT_12_POSITION 12
#define SHIFT_LEFT_16_POSITION 16
#define SHIFT_LEFT_17_POSITION 17
#define SHIFT_LEFT_31_POSITION 31
#define SHIFT_LEFT_35_POSITION 35
#define SHIFT_LEFT_47_POSITION 47
/* numeric definitions*/
#define BMP280_ZERO_U8X 0
#define BMP280_ONE_U8X 1
#define BMP280_THREE_U8X 3
#define BMP280_FOUR_U8X 4
#define BMP280_SIX_U8X 6
#define BMP280_EIGHT_U8X 8
#define BMP280_FIVETEEN_U8X 15
#define BMP280_SIXTEEN_U8X 16
#define BMP280_TWENTY_FOUR_U8X 24
/************************************************/
/**\name ERROR CODES */
/************************************************/
#define SUCCESS ((u8)0)
#define E_BMP280_NULL_PTR ((s8)-127)
#define E_BMP280_COMM_RES ((s8)-1)
#define E_BMP280_OUT_OF_RANGE ((s8)-2)
#define ERROR ((s8)-1)
/************************************************/
/**\name I2C ADDRESS DEFINITION */
/***********************************************/
#define BMP280_I2C_ADDRESS1 0x76
#define BMP280_I2C_ADDRESS2 0x77
/************************************************/
/**\name POWER MODE DEFINITION */
/***********************************************/
/* Sensor Specific constants */
#define BMP280_SLEEP_MODE 0x00
#define BMP280_FORCED_MODE 0x01
#define BMP280_NORMAL_MODE 0x03
#define BMP280_SOFT_RESET_CODE 0xB6
/************************************************/
/**\name STANDBY TIME DEFINITION */
/***********************************************/
#define BMP280_STANDBY_TIME_1_MS 0x00
#define BMP280_STANDBY_TIME_63_MS 0x01
#define BMP280_STANDBY_TIME_125_MS 0x02
#define BMP280_STANDBY_TIME_250_MS 0x03
#define BMP280_STANDBY_TIME_500_MS 0x04
#define BMP280_STANDBY_TIME_1000_MS 0x05
#define BMP280_STANDBY_TIME_2000_MS 0x06
#define BMP280_STANDBY_TIME_4000_MS 0x07
/************************************************/
/**\name OVERSAMPLING DEFINITION */
/***********************************************/
#define BMP280_OVERSAMPLING_SKIPPED 0x00
#define BMP280_OVERSAMP_1X 0x01
#define BMP280_OVERSAMP_2X 0x02
#define BMP280_OVERSAMP_4X 0x03
#define BMP280_OVERSAMP_8X 0x04
#define BMP280_OVERSAMP_16X 0x05
/************************************************/
/**\name WORKING MODE DEFINITION */
/***********************************************/
#define BMP280_ULTRA_LOW_POWER_MODE 0x00
#define BMP280_LOW_POWER_MODE 0x01
#define BMP280_STANDARD_RESOLUTION_MODE 0x02
#define BMP280_HIGH_RESOLUTION_MODE 0x03
#define BMP280_ULTRA_HIGH_RESOLUTION_MODE 0x04
#define BMP280_ULTRALOWPOWER_OVERSAMP_PRESSURE BMP280_OVERSAMP_1X
#define BMP280_ULTRALOWPOWER_OVERSAMP_TEMPERATURE BMP280_OVERSAMP_1X
#define BMP280_LOWPOWER_OVERSAMP_PRESSURE BMP280_OVERSAMP_2X
#define BMP280_LOWPOWER_OVERSAMP_TEMPERATURE BMP280_OVERSAMP_1X
#define BMP280_STANDARDRESOLUTION_OVERSAMP_PRESSURE BMP280_OVERSAMP_4X
#define BMP280_STANDARDRESOLUTION_OVERSAMP_TEMPERATURE BMP280_OVERSAMP_1X
#define BMP280_HIGHRESOLUTION_OVERSAMP_PRESSURE BMP280_OVERSAMP_8X
#define BMP280_HIGHRESOLUTION_OVERSAMP_TEMPERATURE BMP280_OVERSAMP_1X
#define BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_PRESSURE BMP280_OVERSAMP_16X
#define BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_TEMPERATURE BMP280_OVERSAMP_2X
/************************************************/
/**\name FILTER DEFINITION */
/***********************************************/
#define BMP280_FILTER_COEFF_OFF 0x00
#define BMP280_FILTER_COEFF_2 0x01
#define BMP280_FILTER_COEFF_4 0x02
#define BMP280_FILTER_COEFF_8 0x03
#define BMP280_FILTER_COEFF_16 0x04
/************************************************/
/**\name DELAY TIME DEFINITION */
/***********************************************/
#define T_INIT_MAX 20
/* 20/16 = 1.25 ms */
#define T_MEASURE_PER_OSRS_MAX 37
/* 37/16 = 2.3125 ms*/
#define T_SETUP_PRESSURE_MAX 10
/* 10/16 = 0.625 ms */
/************************************************/
/**\name CALIBRATION PARAMETERS DEFINITION */
/***********************************************/
/*calibration parameters */
#define BMP280_DIG_T1_LSB_REG 0x88
#define BMP280_DIG_T1_MSB_REG 0x89
#define BMP280_DIG_T2_LSB_REG 0x8A
#define BMP280_DIG_T2_MSB_REG 0x8B
#define BMP280_DIG_T3_LSB_REG 0x8C
#define BMP280_DIG_T3_MSB_REG 0x8D
#define BMP280_DIG_P1_LSB_REG 0x8E
#define BMP280_DIG_P1_MSB_REG 0x8F
#define BMP280_DIG_P2_LSB_REG 0x90
#define BMP280_DIG_P2_MSB_REG 0x91
#define BMP280_DIG_P3_LSB_REG 0x92
#define BMP280_DIG_P3_MSB_REG 0x93
#define BMP280_DIG_P4_LSB_REG 0x94
#define BMP280_DIG_P4_MSB_REG 0x95
#define BMP280_DIG_P5_LSB_REG 0x96
#define BMP280_DIG_P5_MSB_REG 0x97
#define BMP280_DIG_P6_LSB_REG 0x98
#define BMP280_DIG_P6_MSB_REG 0x99
#define BMP280_DIG_P7_LSB_REG 0x9A
#define BMP280_DIG_P7_MSB_REG 0x9B
#define BMP280_DIG_P8_LSB_REG 0x9C
#define BMP280_DIG_P8_MSB_REG 0x9D
#define BMP280_DIG_P9_LSB_REG 0x9E
#define BMP280_DIG_P9_MSB_REG 0x9F
/************************************************/
/**\name REGISTER ADDRESS DEFINITION */
/***********************************************/
#define BMP280_CHIP_ID_REG 0xD0 /*Chip ID Register */
#define BMP280_RST_REG 0xE0 /*Softreset Register */
#define BMP280_STAT_REG 0xF3 /*Status Register */
#define BMP280_CTRL_MEAS_REG 0xF4 /*Ctrl Measure Register */
#define BMP280_CONFIG_REG 0xF5 /*Configuration Register */
#define BMP280_PRESSURE_MSB_REG 0xF7 /*Pressure MSB Register */
#define BMP280_PRESSURE_LSB_REG 0xF8 /*Pressure LSB Register */
#define BMP280_PRESSURE_XLSB_REG 0xF9 /*Pressure XLSB Register */
#define BMP280_TEMPERATURE_MSB_REG 0xFA /*Temperature MSB Reg */
#define BMP280_TEMPERATURE_LSB_REG 0xFB /*Temperature LSB Reg */
#define BMP280_TEMPERATURE_XLSB_REG 0xFC /*Temperature XLSB Reg */
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION */
/***********************************************/
/* Status Register */
#define BMP280_STATUS_REG_MEASURING__POS 3
#define BMP280_STATUS_REG_MEASURING__MSK 0x08
#define BMP280_STATUS_REG_MEASURING__LEN 1
#define BMP280_STATUS_REG_MEASURING__REG BMP280_STAT_REG
#define BMP280_STATUS_REG_IM_UPDATE__POS 0
#define BMP280_STATUS_REG_IM_UPDATE__MSK 0x01
#define BMP280_STATUS_REG_IM_UPDATE__LEN 1
#define BMP280_STATUS_REG_IM_UPDATE__REG BMP280_STAT_REG
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION
FOR TEMPERATURE OVERSAMPLING */
/***********************************************/
/* Control Measurement Register */
#define BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__POS 5
#define BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__MSK 0xE0
#define BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__LEN 3
#define BMP280_CTRL_MEAS_REG_OVERSAMP_TEMPERATURE__REG \
BMP280_CTRL_MEAS_REG
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION
FOR PRESSURE OVERSAMPLING */
/***********************************************/
#define BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__POS 2
#define BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__MSK 0x1C
#define BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__LEN 3
#define BMP280_CTRL_MEAS_REG_OVERSAMP_PRESSURE__REG \
BMP280_CTRL_MEAS_REG
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION
FOR POWER MODE */
/***********************************************/
#define BMP280_CTRL_MEAS_REG_POWER_MODE__POS 0
#define BMP280_CTRL_MEAS_REG_POWER_MODE__MSK 0x03
#define BMP280_CTRL_MEAS_REG_POWER_MODE__LEN 2
#define BMP280_CTRL_MEAS_REG_POWER_MODE__REG BMP280_CTRL_MEAS_REG
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION
FOR STANDBY DURATION */
/***********************************************/
/* Configuration Register */
#define BMP280_CONFIG_REG_STANDBY_DURN__POS 5
#define BMP280_CONFIG_REG_STANDBY_DURN__MSK 0xE0
#define BMP280_CONFIG_REG_STANDBY_DURN__LEN 3
#define BMP280_CONFIG_REG_STANDBY_DURN__REG BMP280_CONFIG_REG
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION
FOR IIR FILTER */
/***********************************************/
#define BMP280_CONFIG_REG_FILTER__POS 2
#define BMP280_CONFIG_REG_FILTER__MSK 0x1C
#define BMP280_CONFIG_REG_FILTER__LEN 3
#define BMP280_CONFIG_REG_FILTER__REG BMP280_CONFIG_REG
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION
FOR SPI ENABLE*/
/***********************************************/
#define BMP280_CONFIG_REG_SPI3_ENABLE__POS 0
#define BMP280_CONFIG_REG_SPI3_ENABLE__MSK 0x01
#define BMP280_CONFIG_REG_SPI3_ENABLE__LEN 1
#define BMP280_CONFIG_REG_SPI3_ENABLE__REG BMP280_CONFIG_REG
/************************************************/
/**\name BIT LENGTH,POSITION AND MASK DEFINITION
FOR PRESSURE AND TEMPERATURE DATA REGISTERS */
/***********************************************/
/* Data Register */
#define BMP280_PRESSURE_XLSB_REG_DATA__POS 4
#define BMP280_PRESSURE_XLSB_REG_DATA__MSK 0xF0
#define BMP280_PRESSURE_XLSB_REG_DATA__LEN 4
#define BMP280_PRESSURE_XLSB_REG_DATA__REG BMP280_PRESSURE_XLSB_REG
#define BMP280_TEMPERATURE_XLSB_REG_DATA__POS 4
#define BMP280_TEMPERATURE_XLSB_REG_DATA__MSK 0xF0
#define BMP280_TEMPERATURE_XLSB_REG_DATA__LEN 4
#define BMP280_TEMPERATURE_XLSB_REG_DATA__REG BMP280_TEMPERATURE_XLSB_REG
/************************************************/
/**\name BUS READ AND WRITE FUNCTION POINTERS */
/***********************************************/
#define BMP280_WR_FUNC_PTR\
s8 (*bus_write)(u8, u8,\
u8 *, u8)
#define BMP280_RD_FUNC_PTR\
s8 (*bus_read)(u8, u8,\
u8 *, u8)
#define BMP280_MDELAY_DATA_TYPE u16
/****************************************************/
/**\name ARRAY SIZE DEFINITIONS */
/***************************************************/
#define ARRAY_SIZE_TWO 2
#define ARRAY_SIZE_THREE 3
#define ARRAY_SIZE_SIX 6
#define ARRAY_SIZE_FIVE 5
#define ARRAY_SIZE_EIGHT 8
#define ARRAY_SIZE_TWELVE 12
#define ARRAY_SIZE_FOURTEEN 14
#define ARRAY_SIZE_TWENTY_SIX 26
#define INDEX_ZERO 0
#define INDEX_ONE 1
#define INDEX_TWO 2
#define INDEX_THREE 3
#define INDEX_FOUR 4
#define INDEX_FIVE 5
#define INDEX_SIX 6
#define INDEX_SEVEN 7
#define INDEX_EIGHT 8
#define INDEX_NINE 9
#define INDEX_TEN 10
#define INDEX_ELEVEN 11
#define INDEX_TWELVE 12
#define INDEX_THIRTEEN 13
#define INDEX_FOURTEEN 14
#define INDEX_FIVETEEN 15
#define INDEX_SIXTEEN 16
#define INDEX_SEVENTEEN 17
#define INDEX_EIGHTEEN 18
#define INDEX_NINETEEN 19
#define INDEX_TWENTY 20
#define INDEX_TWENTY_ONE 21
#define INDEX_TWENTY_TWO 22
#define INDEX_TWENTY_THREE 23
/****************************************************/
/**\name ARRAY PARAMETERS */
/***************************************************/
#define LSB_ZERO 0
#define MSB_ONE 1
#define LSB_TWO 2
#define MSB_THREE 3
#define LSB_FOUR 4
#define MSB_FIVE 5
#define LSB_SIX 6
#define MSB_SEVEN 7
/****************************************************/
/**\name TRUE TEMPERATURE CALUCULATION PARAMETERS */
/***************************************************/
#define BMP20_DEC_TRUE_TEMP_FIVE_DATA 5
#define BMP20_DEC_TRUE_TEMP_ONE_TWO_EIGHT_DATA 128
/****************************************************/
/**\name TRUE PRESSURE CALUCULATION PARAMETERS */
/***************************************************/
#define BMP20_DEC_TRUE_PRESSURE_6_4_0_0_0_DATA 64000
#define BMP20_DEC_TRUE_PRESSURE_TWO_DATA 2
#define BMP20_DEC_TRUE_PRESSURE_3_2_7_6_8_DATA 32768
#define BMP20_DEC_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA 1048576
#define BMP20_DEC_TRUE_PRESSURE_3_1_2_5_DATA 3125
#define BMP20_HEX_TRUE_PRESSURE_8_0_0_0_0_0_0_0_DATA 0x80000000
/****************************************************/
/**\name TRUE TEMPERATURE CALUCULATION FLOAT RETURN */
/***************************************************/
#define BMP280_FLOAT_TRUE_TEMP_1_6_3_8_4_DATA 16384.0
#define BMP280_FLOAT_TRUE_TEMP_1_0_2_4_DATA 1024.0
#define BMP280_FLOAT_TRUE_TEMP_1_3_1_0_7_2_DATA 131072.0
#define BMP280_FLOAT_TRUE_TEMP_8_1_9_2_DATA 8192.0
#define BMP280_FLOAT_TRUE_TEMP_5_1_2_0_DATA 5120.0
/****************************************************/
/**\name TRUE PRESSURE CALUCULATION FLOAT RETURN */
/***************************************************/
#define BMP280_FLAOT_TRUE_PRESSURE_1_DATA 1.0
#define BMP280_FLAOT_TRUE_PRESSURE_0_DATA 0.0
#define BMP280_FLAOT_TRUE_PRESSURE_2_DATA 2.0
#define BMP280_FLAOT_TRUE_PRESSURE_4_DATA 4.0
#define BMP280_FLAOT_TRUE_PRESSURE_1_6_DATA 16.0
#define BMP280_FLAOT_TRUE_PRESSURE_6_4_0_0_0_DATA 64000.0
#define BMP280_FLAOT_TRUE_PRESSURE_3_2_7_6_8_DATA 32768.0
#define BMP280_FLAOT_TRUE_PRESSURE_6_5_5_3_6_DATA 65536.0
#define BMP280_FLAOT_TRUE_PRESSURE_5_2_4_2_8_8_DATA 524288.0
#define BMP280_FLAOT_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA 1048576.0
#define BMP280_FLAOT_TRUE_PRESSURE_4_0_9_6_DATA 4096.0
#define BMP280_FLAOT_TRUE_PRESSURE_6_2_5_0_DATA 6250.0
#define BMP280_FLAOT_TRUE_PRESSURE_2_1_4_7_4_8_3_6_4_8_DATA \
2147483648.0
/****************************************************/
/**\name TRUE PRESSURE CALUCULATION 64BIT RETURN */
/***************************************************/
#define BMP280_TRUE_PRESSURE_1_2_8_0_0_0_DATA 128000
#define BMP280_TRUE_PRESSURE_1_0_4_8_5_7_6_DATA 1048576
#define BMP280_TRUE_PRESSURE_3_1_2_5_DATA 3125
#define BMP280_TRUE_PRESSURE_1_DATA 1
/**************************************************************/
/**\name STRUCTURE DEFINITIONS */
/**************************************************************/
/*!
* @brief This structure holds all device specific calibration parameters
*/
struct bmp280_calib_param_t {
u16 dig_T1;/**<calibration T1 data*/
s16 dig_T2;/**<calibration T2 data*/
s16 dig_T3;/**<calibration T3 data*/
u16 dig_P1;/**<calibration P1 data*/
s16 dig_P2;/**<calibration P2 data*/
s16 dig_P3;/**<calibration P3 data*/
s16 dig_P4;/**<calibration P4 data*/
s16 dig_P5;/**<calibration P5 data*/
s16 dig_P6;/**<calibration P6 data*/
s16 dig_P7;/**<calibration P7 data*/
s16 dig_P8;/**<calibration P8 data*/
s16 dig_P9;/**<calibration P9 data*/
s32 t_fine;/**<calibration t_fine data*/
};
/*!
* @brief This structure holds BMP280 initialization parameters
*/
struct bmp280_t {
struct bmp280_calib_param_t calib_param;/**<calibration data*/
u8 chip_id;/**< chip id of the sensor*/
u8 dev_addr;/**< device address of the sensor*/
u8 oversamp_temperature;/**< temperature over sampling*/
u8 oversamp_pressure;/**< pressure over sampling*/
BMP280_WR_FUNC_PTR;/**< bus write function pointer*/
BMP280_RD_FUNC_PTR;/**< bus read function pointer*/
void(*delay_msec)(BMP280_MDELAY_DATA_TYPE);/**< delay function pointer*/
};
/**************************************************************/
/**\name FUNCTION DECLARATIONS */
/**************************************************************/
/**************************************************************/
/**\name FUNCTION FOR INTIALIZATION */
/**************************************************************/
/*!
* @brief This function is used for initialize
* the bus read and bus write functions
* and assign the chip id and I2C address of the BMP280 sensor
* chip id is read in the register 0xD0 bit from 0 to 7
*
* @param *bmp280 structure pointer.
*
* @note While changing the parameter of the p_bmp280
* @note consider the following point:
* Changing the reference value of the parameter
* will changes the local copy or local reference
* make sure your changes will not
* affect the reference value of the parameter
* (Better case don't change the reference value of the parameter)
*
*
*
*
* @return results of bus communication function
* @retval 0 -> Success
* @retval -1 -> Error
*
*
*/
BMP280_RETURN_FUNCTION_TYPE bmp280_init(struct bmp280_t *bmp280);
/**************************************************************/
/**\name FUNCTION FOR READ UNCOMPENSATED TEMPERATURE */
/**************************************************************/
/*!
* @brief This API is used to read uncompensated temperature
* in the registers 0xFA, 0xFB and 0xFC
* @note 0xFA -> MSB -> bit from 0 to 7
* @note 0xFB -> LSB -> bit from 0 to 7
* @note 0xFC -> LSB -> bit from 4 to 7
*
* @param v_uncomp_temperature_s32 : The uncompensated temperature.
*
*
*
* @return results of bus communication function
* @retval 0 -> Success
* @retval -1 -> Error
*
*
*/
BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_temperature(
s32 *v_uncomp_temperature_s32);
/**************************************************************/
/**\name FUNCTION FOR READ TRUE TEMPERATURE S32 OUTPUT */
/**************************************************************/
/*!
* @brief Reads actual temperature
* from uncompensated temperature
* @note Returns the value in 0.01 degree Centigrade
* @note Output value of "5123" equals 51.23 DegC.
*
*
*
* @param v_uncomp_temperature_s32 : value of uncompensated temperature
*
*
*
* @return Actual temperature output as s32
*
*/
s32 bmp280_compensate_T_int32(s32 v_uncomp_temperature_s32);
/**************************************************************/
/**\name FUNCTION FOR READ UNCOMPENSATED PRESSURE */
/**************************************************************/
/*!
* @brief This API is used to read uncompensated pressure.
* in the registers 0xF7, 0xF8 and 0xF9
* @note 0xF7 -> MSB -> bit from 0 to 7
* @note 0xF8 -> LSB -> bit from 0 to 7
* @note 0xF9 -> LSB -> bit from 4 to 7
*
*
*
* @param v_uncomp_pressure_s32 : The value of uncompensated pressure
*
*
*
* @return results of bus communication function
* @retval 0 -> Success
* @retval -1 -> Error
*
*
*/
BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure(
s32 *v_uncomp_pressure_s32);
/**************************************************************/
/**\name FUNCTION FOR READ TRUE PRESSURE S32 OUTPUT */
/**************************************************************/
/*!
* @brief Reads actual pressure from uncompensated pressure
* and returns the value in Pascal(Pa)
* @note Output value of "96386" equals 96386 Pa =
* 963.86 hPa = 963.86 millibar
*
*
*
*
* @param v_uncomp_pressure_s32: value of uncompensated pressure
*
*
*
* @return Returns the Actual pressure out put as s32
*
*/
u32 bmp280_compensate_P_int32(s32 v_uncomp_pressure_s32);
/**************************************************************/
/**\name FUNCTION FOR READ UNCOMPENSATED TEMPERATURE AND PRESSURE */
/**************************************************************/
/*!
* @brief reads uncompensated pressure and temperature
*
*
* @param v_uncomp_pressure_s32: The value of uncompensated pressure.
* @param v_uncomp_temperature_s32: The value of uncompensated temperature.
*
* @return results of bus communication function
* @retval 0 -> Success
* @retval -1 -> Error
*
*/
BMP280_RETURN_FUNCTION_TYPE bmp280_read_uncomp_pressure_temperature(
s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32);
/**************************************************************/
/**\name FUNCTION FOR READ TRUE TEMPERATURE AND PRESSURE */
/**************************************************************/
/*!
* @brief This API reads the true pressure and temperature
*
*
* @param v_pressure_u32 : The value of compensated pressure.
* @param v_temperature_s32 : The value of compensated temperature.
*
*
* @return results of bus communication function
* @retval 0 -> Success
* @retval -1 -> Error
*
*
*/
BMP280_RETURN_FUNCTION_TYPE bmp280_read_pressure_temperature(
u32 *v_pressure_u32, s32 *v_pressure_s32);
/**************************************************************/
/**\name FUNCTION FOR READ CALIBRATION DATA */
/**************************************************************/
/*!
* @brief This API is used to
* calibration parameters used for calculation in the registers
*
* parameter | Register address | bit
*------------|------------------|----------------
* dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15
* dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15
* dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15
* dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15
* dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15
* dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15
* dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15
* dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15
* dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15
* dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15
* dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15
* dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15
*
* @return results of bus communication function
* @retval 0 -> Success
* @retval -1 -> Error