1
1
use cramium_api:: { I2cApi , I2cResult } ;
2
2
3
3
pub const BMP180_ADDR : u8 = 0x77 ;
4
+ #[ cfg( feature = "std" ) ]
4
5
const REG_CALIB_START : u8 = 0xAA ;
5
6
const REG_CTRL : u8 = 0xF4 ;
6
7
const REG_DATA_START : u8 = 0xF6 ;
7
8
const CMD_READ_TEMP : u8 = 0x2E ;
8
9
9
10
#[ derive( Debug , Clone , Copy ) ]
10
11
12
+ #[ allow( dead_code) ]
11
13
struct Bmp180Calibration {
12
- ac1 : i16 , ac2 : i16 , ac3 : i16 ,
13
- ac4 : u16 , ac5 : u16 , ac6 : u16 ,
14
- b1 : i16 , b2 : i16 ,
15
- mb : i16 , mc : i16 , md : i16 ,
14
+ ac1 : i16 ,
15
+ ac2 : i16 ,
16
+ ac3 : i16 ,
17
+ ac4 : u16 ,
18
+ ac5 : u16 ,
19
+ ac6 : u16 ,
20
+ b1 : i16 ,
21
+ b2 : i16 ,
22
+ mb : i16 ,
23
+ mc : i16 ,
24
+ md : i16 ,
16
25
}
17
26
18
27
pub struct Bmp180 {
@@ -32,26 +41,34 @@ impl Bmp180 {
32
41
Err ( _) => return Err ( I2cResult :: InternalError ) ,
33
42
}
34
43
44
+ // note: calibration data is Big Endian, hence the from_be_bytes
35
45
let calibration = Bmp180Calibration {
36
46
ac1 : i16:: from_be_bytes ( [ cal_buf[ 0 ] , cal_buf[ 1 ] ] ) ,
37
47
ac2 : i16:: from_be_bytes ( [ cal_buf[ 2 ] , cal_buf[ 3 ] ] ) ,
38
48
ac3 : i16:: from_be_bytes ( [ cal_buf[ 4 ] , cal_buf[ 5 ] ] ) ,
39
49
ac4 : u16:: from_be_bytes ( [ cal_buf[ 6 ] , cal_buf[ 7 ] ] ) ,
40
50
ac5 : u16:: from_be_bytes ( [ cal_buf[ 8 ] , cal_buf[ 9 ] ] ) ,
41
51
ac6 : u16:: from_be_bytes ( [ cal_buf[ 10 ] , cal_buf[ 11 ] ] ) ,
42
- b1 : i16:: from_be_bytes ( [ cal_buf[ 12 ] , cal_buf[ 13 ] ] ) ,
43
- b2 : i16:: from_be_bytes ( [ cal_buf[ 14 ] , cal_buf[ 15 ] ] ) ,
44
- mb : i16:: from_be_bytes ( [ cal_buf[ 16 ] , cal_buf[ 17 ] ] ) ,
45
- mc : i16:: from_be_bytes ( [ cal_buf[ 18 ] , cal_buf[ 19 ] ] ) ,
46
- md : i16:: from_be_bytes ( [ cal_buf[ 20 ] , cal_buf[ 21 ] ] ) ,
52
+ b1 : i16:: from_be_bytes ( [ cal_buf[ 12 ] , cal_buf[ 13 ] ] ) ,
53
+ b2 : i16:: from_be_bytes ( [ cal_buf[ 14 ] , cal_buf[ 15 ] ] ) ,
54
+ mb : i16:: from_be_bytes ( [ cal_buf[ 16 ] , cal_buf[ 17 ] ] ) ,
55
+ mc : i16:: from_be_bytes ( [ cal_buf[ 18 ] , cal_buf[ 19 ] ] ) ,
56
+ md : i16:: from_be_bytes ( [ cal_buf[ 20 ] , cal_buf[ 21 ] ] ) ,
47
57
} ;
48
58
49
- if calibration. ac1 == 0 || calibration. ac2 == 0 || calibration. ac3 == 0 ||
50
- calibration. ac4 == 0 || calibration. ac5 == 0 || calibration. ac6 == 0 ||
51
- calibration. b1 == 0 || calibration. b2 == 0 ||
52
- calibration. mb == 0 || calibration. mc == 0 || calibration. md == 0 ||
53
- calibration. ac1 == -1 {
54
- // Return an error indicating the data from the sensor is invalid.
59
+ if calibration. ac1 == 0
60
+ || calibration. ac2 == 0
61
+ || calibration. ac3 == 0
62
+ || calibration. ac4 == 0
63
+ || calibration. ac5 == 0
64
+ || calibration. ac6 == 0
65
+ || calibration. b1 == 0
66
+ || calibration. b2 == 0
67
+ || calibration. mb == 0
68
+ || calibration. mc == 0
69
+ || calibration. md == 0
70
+ || calibration. ac1 == -1
71
+ {
55
72
return Err ( I2cResult :: InternalError ) ;
56
73
}
57
74
0 commit comments