2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
23 #include "drivers/barometer/barometer.h"
24 #include "drivers/bus.h"
26 int8_t ms5611CRC(uint16_t *prom
);
27 void ms5611Calculate(int32_t *pressure
, int32_t *temperature
);
29 extern uint16_t ms5611_c
[8];
30 extern uint32_t ms5611_up
;
31 extern uint32_t ms5611_ut
;
36 #include "unittest_macros.h"
37 #include "gtest/gtest.h"
40 TEST(baroMS5611Test
, TestValidMs5611Crc
)
43 uint16_t ms5611Prom
[] = {0x3132,0x3334,0x3536,0x3738,0x3940,0x4142,0x4344,0x450B};
46 int8_t result
= ms5611CRC(ms5611Prom
);
52 TEST(baroMS5611Test
, TestInvalidMs5611Crc
)
55 uint16_t ms5611Prom
[] = {0x3132,0x3334,0x3536,0x3738,0x3940,0x4142,0x4344,0x4500};
58 int8_t result
= ms5611CRC(ms5611Prom
);
61 EXPECT_EQ(-1, result
);
64 TEST(baroMS5611Test
, TestMs5611AllZeroProm
)
67 uint16_t ms5611Prom
[] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
70 int8_t result
= ms5611CRC(ms5611Prom
);
73 EXPECT_EQ(-1, result
);
76 TEST(baroMS5611Test
, TestMs5611AllOnesProm
)
79 uint16_t ms5611Prom
[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
82 int8_t result
= ms5611CRC(ms5611Prom
);
85 EXPECT_EQ(-1, result
);
88 TEST(baroMS5611Test
, TestMs5611CalculatePressureGT20Deg
)
91 int32_t pressure
, temperature
;
92 uint16_t ms5611_c_test
[] = {0x0000, 40127, 36924, 23317, 23282, 33464, 28312, 0x0000}; // calibration data from MS5611 datasheet
93 memcpy(&ms5611_c
, &ms5611_c_test
, sizeof(ms5611_c_test
));
95 ms5611_up
= 9085466; // Digital pressure value from MS5611 datasheet
96 ms5611_ut
= 8569150; // Digital temperature value from MS5611 datasheet
99 ms5611Calculate(&pressure
, &temperature
);
102 EXPECT_EQ(2007, temperature
); // 20.07 deg C
103 EXPECT_EQ(100009, pressure
); // 1000.09 mbar
106 TEST(baroMS5611Test
, TestMs5611CalculatePressureLT20Deg
)
109 int32_t pressure
, temperature
;
110 uint16_t ms5611_c_test
[] = {0x0000, 40127, 36924, 23317, 23282, 33464, 28312, 0x0000}; // calibration data from MS5611 datasheet
111 memcpy(&ms5611_c
, &ms5611_c_test
, sizeof(ms5611_c_test
));
113 ms5611_up
= 9085466; // Digital pressure value from MS5611 datasheet
114 ms5611_ut
= 8069150; // Digital temperature value
117 ms5611Calculate(&pressure
, &temperature
);
120 EXPECT_EQ(205, temperature
); // 2.05 deg C
121 EXPECT_EQ(96512, pressure
); // 965.12 mbar
124 TEST(baroMS5611Test
, TestMs5611CalculatePressureLTMinus15Deg
)
127 int32_t pressure
, temperature
;
128 uint16_t ms5611_c_test
[] = {0x0000, 40127, 36924, 23317, 23282, 33464, 28312, 0x0000}; // calibration data from MS5611 datasheet
129 memcpy(&ms5611_c
, &ms5611_c_test
, sizeof(ms5611_c_test
));
131 ms5611_up
= 9085466; // Digital pressure value from MS5611 datasheet
132 ms5611_ut
= 7369150; // Digital temperature value
135 ms5611Calculate(&pressure
, &temperature
);
138 EXPECT_EQ(-2710, temperature
); // -27.10 deg C
139 EXPECT_EQ(90613, pressure
); // 906.13 mbar
146 void delay(uint32_t) {}
147 void delayMicroseconds(uint32_t) {}
149 bool busBusy(const extDevice_t
*, bool*) {return false;}
150 bool busRawReadRegisterBuffer(const extDevice_t
*, uint8_t, uint8_t*, uint8_t) {return true;}
151 bool busRawReadRegisterBufferStart(const extDevice_t
*, uint8_t, uint8_t*, uint8_t) {return true;}
152 bool busRawWriteRegister(const extDevice_t
*, uint8_t, uint8_t) {return true;}
153 bool busRawWriteRegisterStart(const extDevice_t
*, uint8_t, uint8_t) {return true;}
154 void busDeviceRegister(const extDevice_t
*) {}
156 uint16_t spiCalculateDivider() {
160 void spiSetClkDivisor() {
163 void spiPreinitByIO() {
166 void IOConfigGPIO() {