42#define CHIP_NAME "Bosch BMP390"
43#define MANUFACTURER_NAME "Bosch"
44#define SUPPLY_VOLTAGE_MIN 1.65f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.73f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define BMP390_REG_CMD 0x7E
55#define BMP390_REG_NVM_PAR_T1_L 0x31
56#define BMP390_REG_NVM_PAR_T1_H 0x32
57#define BMP390_REG_NVM_PAR_T2_L 0x33
58#define BMP390_REG_NVM_PAR_T2_H 0x34
59#define BMP390_REG_NVM_PAR_T3 0x35
60#define BMP390_REG_NVM_PAR_P1_L 0x36
61#define BMP390_REG_NVM_PAR_P1_H 0x37
62#define BMP390_REG_NVM_PAR_P2_L 0x38
63#define BMP390_REG_NVM_PAR_P2_H 0x39
64#define BMP390_REG_NVM_PAR_P3 0x3A
65#define BMP390_REG_NVM_PAR_P4 0x3B
66#define BMP390_REG_NVM_PAR_P5_L 0x3C
67#define BMP390_REG_NVM_PAR_P5_H 0x3D
68#define BMP390_REG_NVM_PAR_P6_L 0x3E
69#define BMP390_REG_NVM_PAR_P6_H 0x3F
70#define BMP390_REG_NVM_PAR_P7 0x40
71#define BMP390_REG_NVM_PAR_P8 0x41
72#define BMP390_REG_NVM_PAR_P9_L 0x42
73#define BMP390_REG_NVM_PAR_P9_H 0x43
74#define BMP390_REG_NVM_PAR_P10 0x44
75#define BMP390_REG_NVM_PAR_P11 0x45
76#define BMP390_REG_CONFIG 0x1F
77#define BMP390_REG_ODR 0x1D
78#define BMP390_REG_OSR 0x1C
79#define BMP390_REG_PWR_CTRL 0x1B
80#define BMP390_REG_IF_CONF 0x1A
81#define BMP390_REG_INT_CTRL 0x19
82#define BMP390_REG_FIFO_CONFIG_2 0x18
83#define BMP390_REG_FIFO_CONFIG_1 0x17
84#define BMP390_REG_FIFO_WTM_1 0x16
85#define BMP390_REG_FIFO_WTM_0 0x15
86#define BMP390_REG_FIFO_DATA 0x14
87#define BMP390_REG_FIFO_LENGTH_1 0x13
88#define BMP390_REG_FIFO_LENGTH_0 0x12
89#define BMP390_REG_INT_STATUS 0x11
90#define BMP390_REG_EVENT 0x10
91#define BMP390_REG_SENSORTIME_2 0x0E
92#define BMP390_REG_SENSORTIME_1 0x0D
93#define BMP390_REG_SENSORTIME_0 0x0C
94#define BMP390_REG_DATA_5 0x09
95#define BMP390_REG_DATA_4 0x08
96#define BMP390_REG_DATA_3 0x07
97#define BMP390_REG_DATA_2 0x06
98#define BMP390_REG_DATA_1 0x05
99#define BMP390_REG_DATA_0 0x04
100#define BMP390_REG_STATUS 0x03
101#define BMP390_REG_ERR_REG 0x02
102#define BMP390_REG_REV_ID 0x01
103#define BMP390_REG_CHIP_ID 0x00
116static uint8_t a_bmp390_iic_spi_read(
bmp390_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
133 len > 512 ? (512 + 1) : (len + 1)) != 0)
137 memcpy(buf, handle->
buf+1, (len > 512) ? 512 : len);
154static uint8_t a_bmp390_iic_spi_write(
bmp390_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
160 for (i = 0; i < len; i++)
163 (uint8_t)(reg + i), buf + i, 1) != 0)
176 for (i = 0; i < len; i++)
178 if (handle->
spi_write((uint8_t)(reg + i), buf + i, 1) != 0)
202 handle->
debug_print(
"bmp390: get calibration data failed.\n");
206 handle->
t1 = (uint16_t)buf[1] << 8 | buf[0];
209 handle->
debug_print(
"bmp390: get calibration data failed.\n");
213 handle->
t2 = (uint16_t)buf[1] << 8 | buf[0];
216 handle->
debug_print(
"bmp390: get calibration data failed.\n");
220 handle->
t3 = (int8_t)(buf[0]);
223 handle->
debug_print(
"bmp390: get calibration data failed.\n");
227 handle->
p1 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
230 handle->
debug_print(
"bmp390: get calibration data failed.\n");
234 handle->
p2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
237 handle->
debug_print(
"bmp390: get calibration data failed.\n");
241 handle->
p3 = (int8_t)(buf[0]);
244 handle->
debug_print(
"bmp390: get calibration data failed.\n");
248 handle->
p4 = (int8_t)(buf[0]);
251 handle->
debug_print(
"bmp390: get calibration data failed.\n");
255 handle->
p5 = (uint16_t)buf[1] << 8 | buf[0];
258 handle->
debug_print(
"bmp390: get calibration data failed.\n");
262 handle->
p6 = (uint16_t)buf[1] << 8 | buf[0];
265 handle->
debug_print(
"bmp390: get calibration data failed.\n");
269 handle->
p7 = (int8_t)(buf[0]);
272 handle->
debug_print(
"bmp390: get calibration data failed.\n");
276 handle->
p8 = (int8_t)(buf[0]);
279 handle->
debug_print(
"bmp390: get calibration data failed.\n");
283 handle->
p9 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
286 handle->
debug_print(
"bmp390: get calibration data failed.\n");
290 handle->
p10 = (int8_t)(buf[0]);
293 handle->
debug_print(
"bmp390: get calibration data failed.\n");
297 handle->
p11 = (int8_t)(buf[0]);
309static int64_t a_bmp390_compensate_temperature(
bmp390_handle_t *handle, uint32_t data)
311 uint64_t partial_data1;
312 uint64_t partial_data2;
313 uint64_t partial_data3;
314 int64_t partial_data4;
315 int64_t partial_data5;
316 int64_t partial_data6;
320 partial_data1 = (uint64_t)(data - (256 * (uint64_t)(handle->
t1)));
321 partial_data2 = (uint64_t)(handle->
t2 * partial_data1);
322 partial_data3 = (uint64_t)(partial_data1 * partial_data1);
323 partial_data4 = (int64_t)(((int64_t)partial_data3) * ((int64_t)handle->
t3));
324 partial_data5 = ((int64_t)(((int64_t)partial_data2) * 262144) + (int64_t)partial_data4);
325 partial_data6 = (int64_t)(((int64_t)partial_data5) / 4294967296U);
326 handle->
t_fine = partial_data6;
327 comp_temp = (int64_t)((partial_data6 * 25) / 16384);
339static int64_t a_bmp390_compensate_pressure(
bmp390_handle_t *handle, uint32_t data)
341 int64_t partial_data1;
342 int64_t partial_data2;
343 int64_t partial_data3;
344 int64_t partial_data4;
345 int64_t partial_data5;
346 int64_t partial_data6;
353 partial_data2 = partial_data1 / 64;
354 partial_data3 = (partial_data2 * handle->
t_fine) / 256;
355 partial_data4 = (handle->
p8 * partial_data3) / 32;
356 partial_data5 = (handle->
p7 * partial_data1) * 16;
357 partial_data6 = (handle->
p6 * handle->
t_fine) * 4194304;
358 offset = (int64_t)((int64_t)(handle->
p5) * (int64_t)140737488355328U) + partial_data4 + partial_data5 + partial_data6;
359 partial_data2 = (((int64_t)handle->
p4) * partial_data3) / 32;
360 partial_data4 = (handle->
p3 * partial_data1) * 4;
361 partial_data5 = ((int64_t)(handle->
p2) - 16384) * ((int64_t)handle->
t_fine) * 2097152;
362 sensitivity = (((int64_t)(handle->
p1) - 16384) * (int64_t)70368744177664U) + partial_data2 + partial_data4 + partial_data5;
363 partial_data1 = (sensitivity / 16777216) * data;
364 partial_data2 = (int64_t)(handle->
p10) * (int64_t)(handle->
t_fine);
365 partial_data3 = partial_data2 + (65536 * (int64_t)(handle->
p9));
366 partial_data4 = (partial_data3 * data) / 8192;
367 partial_data5 = (partial_data4 * data) / 512;
368 partial_data6 = (int64_t)((uint64_t)data * (uint64_t)data);
369 partial_data2 = ((int64_t)(handle->
p11) * (int64_t)(partial_data6)) / 65536;
370 partial_data3 = (partial_data2 * data) / 128;
371 partial_data4 = (offset / 4) + partial_data1 + partial_data5 + partial_data3;
372 comp_press = (((uint64_t)partial_data4 * 25) / (uint64_t)1099511627776U);
404 handle->
debug_print(
"bmp390: get revision id register failed.\n");
439 handle->
debug_print(
"bmp390: get error register failed.\n");
474 handle->
debug_print(
"bmp390: get status register failed.\n");
510 handle->
debug_print(
"bmp390: get sensor time register failed.\n");
514 *t = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
547 handle->
debug_print(
"bmp390: get event register failed.\n");
583 handle->
debug_print(
"bmp390: get interrupt status register failed.\n");
619 handle->
debug_print(
"bmp390: get fifo length register failed.\n");
623 *length = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0];
656 handle->
debug_print(
"bmp390: get fifo data register failed.\n");
689 buf[0] = watermark & 0xFF;
690 buf[1] = (watermark >> 8) & 0x01;
694 handle->
debug_print(
"bmp390: set fifo watermark register failed.\n");
730 handle->
debug_print(
"bmp390: get fifo watermark register failed.\n");
734 *watermark = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0];
767 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
776 handle->
debug_print(
"bmp390: set fifo config 1 register failed.\n");
812 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
849 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
858 handle->
debug_print(
"bmp390: set fifo config 1 register failed.\n");
894 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
931 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
940 handle->
debug_print(
"bmp390: set fifo config 1 register failed.\n");
976 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
1013 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
1018 prev |= enable << 3;
1022 handle->
debug_print(
"bmp390: set fifo config 1 register failed.\n");
1058 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
1095 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
1100 prev |= enable << 4;
1104 handle->
debug_print(
"bmp390: set fifo config 1 register failed.\n");
1140 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
1176 handle->
debug_print(
"bmp390: subsample is invalid.\n");
1183 handle->
debug_print(
"bmp390: get fifo config 2 register failed.\n");
1188 prev |= subsample << 0;
1192 handle->
debug_print(
"bmp390: set fifo config 2 register failed.\n");
1228 handle->
debug_print(
"bmp390: get fifo config 2 register failed.\n");
1265 handle->
debug_print(
"bmp390: get fifo config 2 register failed.\n");
1270 prev |= source << 3;
1274 handle->
debug_print(
"bmp390: set fifo config 2 register failed.\n");
1310 handle->
debug_print(
"bmp390: get fifo config 2 register failed.\n");
1347 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1352 prev |= pin_type << 0;
1356 handle->
debug_print(
"bmp390: set int ctrl register failed.\n");
1392 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1429 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1438 handle->
debug_print(
"bmp390: set int ctrl register failed.\n");
1474 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1511 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1516 prev |= enable << 2;
1520 handle->
debug_print(
"bmp390: set int ctrl register failed.\n");
1556 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1593 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1598 prev |= enable << 3;
1602 handle->
debug_print(
"bmp390: set int ctrl register failed.\n");
1638 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1675 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1680 prev |= enable << 4;
1684 handle->
debug_print(
"bmp390: set int ctrl register failed.\n");
1720 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1757 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1762 prev |= enable << 6;
1766 handle->
debug_print(
"bmp390: set int ctrl register failed.\n");
1802 handle->
debug_print(
"bmp390: get int ctrl register failed.\n");
1839 handle->
debug_print(
"bmp390: get if conf register failed.\n");
1848 handle->
debug_print(
"bmp390: set if conf register failed.\n");
1884 handle->
debug_print(
"bmp390: get if conf register failed.\n");
1921 handle->
debug_print(
"bmp390: get if conf register failed.\n");
1926 prev |= enable << 1;
1930 handle->
debug_print(
"bmp390: set if conf register failed.\n");
1966 handle->
debug_print(
"bmp390: get if conf register failed.\n");
2003 handle->
debug_print(
"bmp390: get if conf register failed.\n");
2008 prev |= period << 2;
2012 handle->
debug_print(
"bmp390: set if conf register failed.\n");
2048 handle->
debug_print(
"bmp390: get if conf register failed.\n");
2085 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2090 prev |= enable << 0;
2094 handle->
debug_print(
"bmp390: set pwr ctrl register failed.\n");
2130 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2167 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2172 prev |= enable << 1;
2176 handle->
debug_print(
"bmp390: set pwr ctrl register failed.\n");
2212 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2249 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2258 handle->
debug_print(
"bmp390: set pwr ctrl register failed.\n");
2294 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2328 res = a_bmp390_iic_spi_read(handle,
BMP390_REG_OSR, (uint8_t *)&prev, 1);
2331 handle->
debug_print(
"bmp390: get osr register failed.\n");
2336 prev |= oversampling << 0;
2337 res = a_bmp390_iic_spi_write(handle,
BMP390_REG_OSR, (uint8_t *)&prev, 1);
2340 handle->
debug_print(
"bmp390: set osr register failed.\n");
2373 res = a_bmp390_iic_spi_read(handle,
BMP390_REG_OSR, (uint8_t *)&prev, 1);
2376 handle->
debug_print(
"bmp390: get osr register failed.\n");
2410 res = a_bmp390_iic_spi_read(handle,
BMP390_REG_OSR, (uint8_t *)&prev, 1);
2413 handle->
debug_print(
"bmp390: get osr register failed.\n");
2418 prev |= oversampling << 3;
2419 res = a_bmp390_iic_spi_write(handle,
BMP390_REG_OSR, (uint8_t *)&prev, 1);
2422 handle->
debug_print(
"bmp390: set osr register failed.\n");
2455 res = a_bmp390_iic_spi_read(handle,
BMP390_REG_OSR, (uint8_t *)&prev, 1);
2458 handle->
debug_print(
"bmp390: get osr register failed.\n");
2492 res = a_bmp390_iic_spi_read(handle,
BMP390_REG_ODR, (uint8_t *)&prev, 1);
2495 handle->
debug_print(
"bmp390: get odr register failed.\n");
2502 res = a_bmp390_iic_spi_write(handle,
BMP390_REG_ODR, (uint8_t *)&prev, 1);
2505 handle->
debug_print(
"bmp390: set odr register failed.\n");
2538 res = a_bmp390_iic_spi_read(handle,
BMP390_REG_ODR, (uint8_t *)&prev, 1);
2541 handle->
debug_print(
"bmp390: get odr register failed.\n");
2578 handle->
debug_print(
"bmp390: get config register failed.\n");
2583 prev &= ~(0x7 << 1);
2584 prev |= coefficient << 1;
2588 handle->
debug_print(
"bmp390: set config register failed.\n");
2624 handle->
debug_print(
"bmp390: get config register failed.\n");
2658 res = a_bmp390_iic_spi_write(handle,
BMP390_REG_CMD, (uint8_t *)&prev, 1);
2661 handle->
debug_print(
"bmp390: set cmd register failed.\n");
2694 res = a_bmp390_iic_spi_write(handle,
BMP390_REG_CMD, (uint8_t *)&prev, 1);
2697 handle->
debug_print(
"bmp390: set cmd register failed.\n");
2721 handle->
debug_print(
"bmp390: iic deinit failed.\n");
2734 handle->
debug_print(
"bmp390: spi deinit failed.\n");
2773 handle->
debug_print(
"bmp390: iic_init is null.\n");
2779 handle->
debug_print(
"bmp390: iic_deinit is null.\n");
2785 handle->
debug_print(
"bmp390: iic_read is null.\n");
2791 handle->
debug_print(
"bmp390: iic_write is null.\n");
2797 handle->
debug_print(
"bmp390: spi_init is null.\n");
2803 handle->
debug_print(
"bmp390: spi_deinit is null.\n");
2809 handle->
debug_print(
"bmp390: spi_read is null.\n");
2815 handle->
debug_print(
"bmp390: spi_write is null.\n");
2821 handle->
debug_print(
"bmp390: delay_ms is null.\n");
2830 handle->
debug_print(
"bmp390: iic init failed.\n");
2839 handle->
debug_print(
"bmp390: spi init failed.\n");
2846 handle->
debug_print(
"bmp390: read chip id failed.\n");
2847 (void)a_bmp390_close(handle);
2854 (void)a_bmp390_close(handle);
2859 if (a_bmp390_iic_spi_write(handle,
BMP390_REG_CMD, (uint8_t *)®, 1) != 0)
2861 handle->
debug_print(
"bmp390: soft rest failed.\n");
2862 (void)a_bmp390_close(handle);
2869 handle->
debug_print(
"bmp390: get err reg failed.\n");
2870 (void)a_bmp390_close(handle);
2874 if ((reg & 0x07) != 0)
2876 handle->
debug_print(
"bmp390: find running error.\n");
2877 (void)a_bmp390_close(handle);
2881 if (a_bmp390_get_calibration_data(handle) != 0)
2883 handle->
debug_print(
"bmp390: get calibration data error.\n");
2884 (void)a_bmp390_close(handle);
2921 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2930 handle->
debug_print(
"bmp390: set pwr ctrl register failed.\n");
2934 if (a_bmp390_close(handle) != 0)
2976 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
2980 if ((prev & 0x01) != 0)
2982 handle->
debug_print(
"bmp390: fifo mode can't use this function.\n");
2989 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
2993 if (((prev >> 4) & 0x03) == 0x03)
2998 handle->
debug_print(
"bmp390: get status register failed.\n");
3002 if ((prev & (1 << 6)) != 0)
3009 handle->
debug_print(
"bmp390: get data register failed.\n");
3013 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3014 output = a_bmp390_compensate_temperature(handle, *raw);
3015 *c = (float)((
double)output / 100.0);
3022 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3027 else if (((prev >> 4) & 0x03) == 0x00)
3029 uint16_t cnt = 5000;
3034 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
3038 prev &= ~(0x03 << 4);
3043 handle->
debug_print(
"bmp390: set pwr ctrl register failed.\n");
3053 handle->
debug_print(
"bmp390: get status register failed.\n");
3057 if ((prev & (1 << 6)) != 0)
3064 handle->
debug_print(
"bmp390: get data register failed.\n");
3068 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3069 output = a_bmp390_compensate_temperature(handle, *raw);
3070 *c = (float)((
double)output / 100.0);
3084 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3092 handle->
debug_print(
"bmp390: mode is invalid.\n");
3115 uint32_t temperature_raw;
3129 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
3133 if ((prev & 0x01) != 0)
3135 handle->
debug_print(
"bmp390: fifo mode can't use this function.\n");
3142 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
3146 if (((prev >> 4) & 0x03) == 0x03)
3151 handle->
debug_print(
"bmp390: get status register failed.\n");
3155 if ((prev & (1 << 6)) != 0)
3160 handle->
debug_print(
"bmp390: get data register failed.\n");
3164 temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3165 (void)a_bmp390_compensate_temperature(handle, temperature_raw);
3169 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3173 if ((prev & (1 << 5)) != 0)
3180 handle->
debug_print(
"bmp390: get data register failed.\n");
3184 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3185 output = a_bmp390_compensate_pressure(handle, *raw);
3186 *pa = (float)((
double)output / 100.0);
3192 handle->
debug_print(
"bmp390: pressure data is not ready.\n");
3197 else if (((prev >> 4) & 0x03) == 0x00)
3199 uint16_t cnt = 5000;
3204 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
3208 prev &= ~(0x03 << 4);
3213 handle->
debug_print(
"bmp390: set pwr ctrl register failed.\n");
3223 handle->
debug_print(
"bmp390: get status register failed.\n");
3227 if ((prev & (1 << 6)) != 0)
3232 handle->
debug_print(
"bmp390: get data register failed.\n");
3236 temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3237 (void)a_bmp390_compensate_temperature(handle, temperature_raw);
3250 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3258 if ((prev & (1 << 5)) != 0)
3265 handle->
debug_print(
"bmp390: get data register failed.\n");
3269 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3270 output = a_bmp390_compensate_pressure(handle, *raw);
3271 *pa = (float)((
double)output / 100.0);
3284 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3292 handle->
debug_print(
"bmp390: mode is invalid.\n");
3313 uint32_t *pressure_raw,
float *pressure_pa)
3331 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
3335 if ((prev & 0x01) != 0)
3337 handle->
debug_print(
"bmp390: fifo mode can't use this function.\n");
3344 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
3348 if (((prev >> 4) & 0x03) == 0x03)
3353 handle->
debug_print(
"bmp390: get status register failed.\n");
3357 if ((prev & (1 << 6)) != 0)
3364 handle->
debug_print(
"bmp390: get data register failed.\n");
3368 *temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3369 output = a_bmp390_compensate_temperature(handle, *temperature_raw);
3370 *temperature_c = (float)((
double)output / 100.0);
3374 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3378 if ((prev & (1 << 5)) != 0)
3385 handle->
debug_print(
"bmp390: get data register failed.\n");
3389 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3390 output = a_bmp390_compensate_pressure(handle, *pressure_raw);
3391 *pressure_pa = (float)((
double)output / 100.0);
3397 handle->
debug_print(
"bmp390: pressure data is not ready.\n");
3402 else if (((prev >> 4) & 0x03) == 0x00)
3404 uint16_t cnt = 5000;
3409 handle->
debug_print(
"bmp390: get pwr ctrl register failed.\n");
3413 prev &= ~(0x03 << 4);
3418 handle->
debug_print(
"bmp390: set pwr ctrl register failed.\n");
3428 handle->
debug_print(
"bmp390: get status register failed.\n");
3432 if ((prev & (1 << 6)) != 0)
3439 handle->
debug_print(
"bmp390: get data register failed.\n");
3443 *temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3444 output = a_bmp390_compensate_temperature(handle, *temperature_raw);
3445 *temperature_c = (float)((
double)output / 100.0);
3458 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3467 if ((prev & (1 << 5)) != 0)
3474 handle->
debug_print(
"bmp390: get data register failed.\n");
3478 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3479 output = a_bmp390_compensate_pressure(handle, *pressure_raw);
3480 *pressure_pa = (float)((
double)output / 100.0);
3493 handle->
debug_print(
"bmp390: temperature data is not ready.\n");
3501 handle->
debug_print(
"bmp390: mode is invalid.\n");
3534 handle->
debug_print(
"bmp390: get interrupt status register failed.\n");
3538 if ((status & (1 << 1)) != 0)
3545 if ((status & (1 << 0)) != 0)
3552 if ((status & (1 << 3)) != 0)
3579 handle->
iic_addr = (uint8_t)addr_pin;
3621 handle->
iic_spi = (uint8_t)interface;
3678 handle->
debug_print(
"bmp390: get fifo config 1 register failed.\n");
3682 if ((prev & 0x01) != 0)
3687 handle->
debug_print(
"bmp390: get fifo length register failed.\n");
3691 length = ((uint16_t)(tmp_buf[1] & 0x01) << 8) | tmp_buf[0];
3692 if ((prev & (1 << 2)) != 0)
3696 *len = (*len) < length ? (*len) :length;
3700 handle->
debug_print(
"bmp390: get fifo data failed.\n");
3709 handle->
debug_print(
"bmp390: normal mode or forced mode can't use this function.\n");
3733 uint16_t frame_total;
3746 handle->
debug_print(
"bmp390: buffer length is invalid.\n");
3755 switch ((uint8_t)buf[i])
3759 if (frame_total > ((*frame_len)-1))
3764 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3765 frame[frame_total].
data = (float)((
double)a_bmp390_compensate_temperature(handle, frame[frame_total].raw) / 100.0);
3773 if ((frame_total) > ((*frame_len)-1))
3778 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3779 frame[frame_total].
data = (float)((
double)a_bmp390_compensate_temperature(handle, frame[frame_total].raw) / 100.0);
3781 if (frame_total > ((*frame_len)-1))
3786 frame[frame_total].
raw = (uint32_t)buf[i + 5 + 1] << 16 | (uint32_t)buf[i + 4 + 1] << 8 | buf[i + 3 + 1];
3787 frame[frame_total].
data = (float)((
double)a_bmp390_compensate_pressure(handle, frame[frame_total].raw) / 100.0);
3795 if (frame_total > ((*frame_len)-1))
3800 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3801 frame[frame_total].
data = 0;
3827 handle->
debug_print(
"bmp390: header is invalid.\n");
3838 *frame_len = frame_total;
3866 return a_bmp390_iic_spi_write(handle, reg, &value, 1);
3892 return a_bmp390_iic_spi_read(handle, reg, value, 1);
#define BMP390_REG_NVM_PAR_T1_L
#define BMP390_REG_FIFO_CONFIG_1
#define BMP390_REG_NVM_PAR_P4
#define BMP390_REG_NVM_PAR_P5_L
#define BMP390_REG_FIFO_CONFIG_2
#define BMP390_REG_DATA_0
#define BMP390_REG_NVM_PAR_P8
#define BMP390_REG_NVM_PAR_P1_L
#define BMP390_REG_STATUS
#define BMP390_REG_NVM_PAR_P3
#define SUPPLY_VOLTAGE_MAX
#define BMP390_REG_SENSORTIME_0
#define BMP390_REG_NVM_PAR_P7
#define BMP390_REG_NVM_PAR_P10
#define BMP390_REG_NVM_PAR_P11
#define BMP390_REG_IF_CONF
#define BMP390_REG_NVM_PAR_T3
#define BMP390_REG_NVM_PAR_T2_L
#define BMP390_REG_FIFO_DATA
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BMP390_REG_INT_STATUS
#define BMP390_REG_NVM_PAR_P6_L
#define BMP390_REG_PWR_CTRL
#define BMP390_REG_INT_CTRL
#define BMP390_REG_CONFIG
#define CHIP_NAME
chip information definition
#define BMP390_REG_NVM_PAR_P2_L
#define BMP390_REG_ERR_REG
#define BMP390_REG_FIFO_LENGTH_0
#define BMP390_REG_CHIP_ID
#define BMP390_REG_NVM_PAR_P9_L
#define BMP390_REG_REV_ID
#define BMP390_REG_FIFO_WTM_0
#define BMP390_REG_CMD
chip register definition
#define BMP390_REG_DATA_3
driver bmp390 header file
uint8_t bmp390_set_temperature_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp390_get_pressure_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t *oversampling)
get the pressure oversampling
uint8_t bmp390_get_pressure(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the pressure status
uint8_t bmp390_set_pressure(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the pressure
uint8_t bmp390_set_mode(bmp390_handle_t *handle, bmp390_mode_t mode)
set the chip mode
bmp390_interface_t
bmp390 interface enumeration definition
bmp390_event_t
bmp390 event enumeration definition
uint8_t bmp390_get_odr(bmp390_handle_t *handle, bmp390_odr_t *odr)
get the output data rate
uint8_t bmp390_set_temperature(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the temperature
uint8_t bmp390_get_temperature_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t *oversampling)
get the temperature oversampling
uint8_t bmp390_read_temperature(bmp390_handle_t *handle, uint32_t *raw, float *c)
read the temperature
bmp390_interrupt_active_level_t
bmp390 interrupt active level enumeration definition
uint8_t bmp390_read_pressure(bmp390_handle_t *handle, uint32_t *raw, float *pa)
read the pressure
bmp390_fifo_data_source_t
bmp390 fifo data source enumeration definition
uint8_t bmp390_info(bmp390_info_t *info)
get chip's information
uint8_t bmp390_get_addr_pin(bmp390_handle_t *handle, bmp390_address_t *addr_pin)
get the iic address pin
bmp390_oversampling_t
bmp390 oversampling enumeration definition
uint8_t bmp390_get_status(bmp390_handle_t *handle, uint8_t *status)
get the status
uint8_t bmp390_get_spi_wire(bmp390_handle_t *handle, bmp390_spi_wire_t *wire)
get the spi wire
uint8_t bmp390_get_mode(bmp390_handle_t *handle, bmp390_mode_t *mode)
get the chip mode
uint8_t bmp390_get_error(bmp390_handle_t *handle, uint8_t *err)
get the error
bmp390_interrupt_pin_type_t
bmp390 interrupt pin type enumeration definition
uint8_t bmp390_set_addr_pin(bmp390_handle_t *handle, bmp390_address_t addr_pin)
set the iic address pin
uint8_t bmp390_get_revision_id(bmp390_handle_t *handle, uint8_t *id)
get the revision id
uint8_t bmp390_get_iic_watchdog_period(bmp390_handle_t *handle, bmp390_iic_watchdog_period_t *period)
get the iic watchdog period
struct bmp390_frame_s bmp390_frame_t
bmp390 frame structure definition
uint8_t bmp390_read_temperature_pressure(bmp390_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
bmp390_bool_t
bmp390 bool enumeration definition
bmp390_filter_coefficient_t
bmp390 filter coefficient enumeration definition
uint8_t bmp390_set_odr(bmp390_handle_t *handle, bmp390_odr_t odr)
set the output data rate
uint8_t bmp390_init(bmp390_handle_t *handle)
initialize the chip
bmp390_odr_t
bmp390 output data rate enumeration definition
uint8_t bmp390_set_iic_watchdog_timer(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the iic watchdog timer
bmp390_iic_watchdog_period_t
bmp390 iic watchdog period enumeration definition
uint8_t bmp390_irq_handler(bmp390_handle_t *handle)
irq handler
bmp390_spi_wire_t
bmp390 spi wire enumeration definition
uint8_t bmp390_set_pressure_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp390_set_iic_watchdog_period(bmp390_handle_t *handle, bmp390_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp390_get_filter_coefficient(bmp390_handle_t *handle, bmp390_filter_coefficient_t *coefficient)
get the filter coefficient
uint8_t bmp390_get_event(bmp390_handle_t *handle, bmp390_event_t *event)
get the event
uint8_t bmp390_deinit(bmp390_handle_t *handle)
close the chip
uint8_t bmp390_get_interface(bmp390_handle_t *handle, bmp390_interface_t *interface)
get the interface
uint8_t bmp390_get_temperature(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the temperature status
uint8_t bmp390_get_sensortime(bmp390_handle_t *handle, uint32_t *t)
get the sensor time
uint8_t bmp390_set_interface(bmp390_handle_t *handle, bmp390_interface_t interface)
set the interface
bmp390_address_t
bmp390 address enumeration definition
uint8_t bmp390_get_iic_watchdog_timer(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the iic watchdog timer status
uint8_t bmp390_softreset(bmp390_handle_t *handle)
soft reset
uint8_t bmp390_set_spi_wire(bmp390_handle_t *handle, bmp390_spi_wire_t wire)
set the spi wire
uint8_t bmp390_set_filter_coefficient(bmp390_handle_t *handle, bmp390_filter_coefficient_t coefficient)
set the filter coefficient
struct bmp390_info_s bmp390_info_t
bmp390 information structure definition
struct bmp390_handle_s bmp390_handle_t
bmp390 handle structure definition
bmp390_mode_t
bmp390 mode enumeration definition
@ BMP390_INTERRUPT_STATUS_FIFO_FULL
@ BMP390_INTERRUPT_STATUS_DATA_READY
@ BMP390_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP390_FRAME_TYPE_TEMPERATURE
@ BMP390_FRAME_TYPE_PRESSURE
@ BMP390_FRAME_TYPE_SENSORTIME
uint8_t bmp390_set_reg(bmp390_handle_t *handle, uint8_t reg, uint8_t value)
set the chip register
uint8_t bmp390_get_reg(bmp390_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
uint8_t bmp390_fifo_parse(bmp390_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp390_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp390_set_fifo_data_source(bmp390_handle_t *handle, bmp390_fifo_data_source_t source)
set the fifo data source
uint8_t bmp390_get_fifo(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo status
uint8_t bmp390_set_fifo_pressure_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp390_get_fifo_pressure_on(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo pressure on status
uint8_t bmp390_set_fifo_temperature_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp390_get_fifo_stop_on_full(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo stopping on full status
uint8_t bmp390_set_fifo(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo
uint8_t bmp390_get_fifo_data_source(bmp390_handle_t *handle, bmp390_fifo_data_source_t *source)
get the fifo data source
uint8_t bmp390_read_fifo(bmp390_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp390_get_fifo_watermark(bmp390_handle_t *handle, uint16_t *watermark)
get the fifo watermark
uint8_t bmp390_get_fifo_subsampling(bmp390_handle_t *handle, uint8_t *subsample)
get the fifo subsampling
uint8_t bmp390_set_fifo_sensortime_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp390_set_fifo_subsampling(bmp390_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp390_flush_fifo(bmp390_handle_t *handle)
flush the fifo
uint8_t bmp390_set_fifo_stop_on_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp390_set_fifo_watermark(bmp390_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp390_get_fifo_data(bmp390_handle_t *handle, uint8_t *data, uint16_t length)
get the fifo data
uint8_t bmp390_get_fifo_sensortime_on(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo sensor time on status
uint8_t bmp390_get_fifo_temperature_on(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo temperature on status
uint8_t bmp390_get_fifo_length(bmp390_handle_t *handle, uint16_t *length)
get the fifo length
uint8_t bmp390_get_interrupt_fifo_watermark(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the interrupt fifo watermark
uint8_t bmp390_get_interrupt_fifo_full(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the interrupt fifo full
uint8_t bmp390_set_interrupt_fifo_watermark(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp390_get_interrupt_active_level(bmp390_handle_t *handle, bmp390_interrupt_active_level_t *level)
get the interrupt active level
uint8_t bmp390_get_interrupt_data_ready(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the interrupt data ready status
uint8_t bmp390_set_interrupt_data_ready(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp390_get_latch_interrupt_pin_and_interrupt_status(bmp390_handle_t *handle, bmp390_bool_t *enable)
get latching interrupt pin and interrupt status
uint8_t bmp390_get_interrupt_status(bmp390_handle_t *handle, uint8_t *status)
get the interrupt status
uint8_t bmp390_get_interrupt_pin_type(bmp390_handle_t *handle, bmp390_interrupt_pin_type_t *pin_type)
get the interrupt pin type
uint8_t bmp390_set_latch_interrupt_pin_and_interrupt_status(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp390_set_interrupt_pin_type(bmp390_handle_t *handle, bmp390_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp390_set_interrupt_fifo_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp390_set_interrupt_active_level(bmp390_handle_t *handle, bmp390_interrupt_active_level_t level)
set the interrupt active level
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v