43#define CHIP_NAME "Bosch BMP388"
44#define MANUFACTURER_NAME "Bosch"
45#define SUPPLY_VOLTAGE_MIN 1.65f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 0.8f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
55#define BMP388_REG_CMD 0x7E
56#define BMP388_REG_NVM_PAR_T1_L 0x31
57#define BMP388_REG_NVM_PAR_T1_H 0x32
58#define BMP388_REG_NVM_PAR_T2_L 0x33
59#define BMP388_REG_NVM_PAR_T2_H 0x34
60#define BMP388_REG_NVM_PAR_T3 0x35
61#define BMP388_REG_NVM_PAR_P1_L 0x36
62#define BMP388_REG_NVM_PAR_P1_H 0x37
63#define BMP388_REG_NVM_PAR_P2_L 0x38
64#define BMP388_REG_NVM_PAR_P2_H 0x39
65#define BMP388_REG_NVM_PAR_P3 0x3A
66#define BMP388_REG_NVM_PAR_P4 0x3B
67#define BMP388_REG_NVM_PAR_P5_L 0x3C
68#define BMP388_REG_NVM_PAR_P5_H 0x3D
69#define BMP388_REG_NVM_PAR_P6_L 0x3E
70#define BMP388_REG_NVM_PAR_P6_H 0x3F
71#define BMP388_REG_NVM_PAR_P7 0x40
72#define BMP388_REG_NVM_PAR_P8 0x41
73#define BMP388_REG_NVM_PAR_P9_L 0x42
74#define BMP388_REG_NVM_PAR_P9_H 0x43
75#define BMP388_REG_NVM_PAR_P10 0x44
76#define BMP388_REG_NVM_PAR_P11 0x45
77#define BMP388_REG_CONFIG 0x1F
78#define BMP388_REG_ODR 0x1D
79#define BMP388_REG_OSR 0x1C
80#define BMP388_REG_PWR_CTRL 0x1B
81#define BMP388_REG_IF_CONF 0x1A
82#define BMP388_REG_INT_CTRL 0x19
83#define BMP388_REG_FIFO_CONFIG_2 0x18
84#define BMP388_REG_FIFO_CONFIG_1 0x17
85#define BMP388_REG_FIFO_WTM_1 0x16
86#define BMP388_REG_FIFO_WTM_0 0x15
87#define BMP388_REG_FIFO_DATA 0x14
88#define BMP388_REG_FIFO_LENGTH_1 0x13
89#define BMP388_REG_FIFO_LENGTH_0 0x12
90#define BMP388_REG_INT_STATUS 0x11
91#define BMP388_REG_EVENT 0x10
92#define BMP388_REG_SENSORTIME_2 0x0E
93#define BMP388_REG_SENSORTIME_1 0x0D
94#define BMP388_REG_SENSORTIME_0 0x0C
95#define BMP388_REG_DATA_5 0x09
96#define BMP388_REG_DATA_4 0x08
97#define BMP388_REG_DATA_3 0x07
98#define BMP388_REG_DATA_2 0x06
99#define BMP388_REG_DATA_1 0x05
100#define BMP388_REG_DATA_0 0x04
101#define BMP388_REG_STATUS 0x03
102#define BMP388_REG_ERR_REG 0x02
103#define BMP388_REG_CHIP_ID 0x00
116static uint8_t a_bmp388_iic_spi_read(
bmp388_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_bmp388_iic_spi_write(
bmp388_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(
"bmp388: get calibration data failed.\n");
206 handle->
t1 = (uint16_t)buf[1] << 8 | buf[0];
209 handle->
debug_print(
"bmp388: get calibration data failed.\n");
213 handle->
t2 = (uint16_t)buf[1] << 8 | buf[0];
216 handle->
debug_print(
"bmp388: get calibration data failed.\n");
220 handle->
t3 = (int8_t)(buf[0]);
223 handle->
debug_print(
"bmp388: get calibration data failed.\n");
227 handle->
p1 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
230 handle->
debug_print(
"bmp388: get calibration data failed.\n");
234 handle->
p2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
237 handle->
debug_print(
"bmp388: get calibration data failed.\n");
241 handle->
p3 = (int8_t)(buf[0]);
244 handle->
debug_print(
"bmp388: get calibration data failed.\n");
248 handle->
p4 = (int8_t)(buf[0]);
251 handle->
debug_print(
"bmp388: get calibration data failed.\n");
255 handle->
p5 = (uint16_t)buf[1] << 8 | buf[0];
258 handle->
debug_print(
"bmp388: get calibration data failed.\n");
262 handle->
p6 = (uint16_t)buf[1] << 8 | buf[0];
265 handle->
debug_print(
"bmp388: get calibration data failed.\n");
269 handle->
p7 = (int8_t)(buf[0]);
272 handle->
debug_print(
"bmp388: get calibration data failed.\n");
276 handle->
p8 = (int8_t)(buf[0]);
279 handle->
debug_print(
"bmp388: get calibration data failed.\n");
283 handle->
p9 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]);
286 handle->
debug_print(
"bmp388: get calibration data failed.\n");
290 handle->
p10 = (int8_t)(buf[0]);
293 handle->
debug_print(
"bmp388: get calibration data failed.\n");
297 handle->
p11 = (int8_t)(buf[0]);
309static int64_t a_bmp388_compensate_temperature(
bmp388_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_bmp388_compensate_pressure(
bmp388_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(
"bmp388: get error register failed.\n");
439 handle->
debug_print(
"bmp388: get status register failed.\n");
475 handle->
debug_print(
"bmp388: get sensor time register failed.\n");
479 *t = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
512 handle->
debug_print(
"bmp388: get event register failed.\n");
548 handle->
debug_print(
"bmp388: get interrupt status register failed.\n");
584 handle->
debug_print(
"bmp388: get fifo length register failed.\n");
588 *length = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0];
621 handle->
debug_print(
"bmp388: get fifo data register failed.\n");
654 buf[0] = watermark & 0xFF;
655 buf[1] = (watermark >> 8) & 0x01;
659 handle->
debug_print(
"bmp388: set fifo watermark register failed.\n");
695 handle->
debug_print(
"bmp388: get fifo watermark register failed.\n");
699 *watermark = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0];
732 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
741 handle->
debug_print(
"bmp388: set fifo config 1 register failed.\n");
777 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
814 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
823 handle->
debug_print(
"bmp388: set fifo config 1 register failed.\n");
859 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
896 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
905 handle->
debug_print(
"bmp388: set fifo config 1 register failed.\n");
941 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
978 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
987 handle->
debug_print(
"bmp388: set fifo config 1 register failed.\n");
1023 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
1060 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
1065 prev |= enable << 4;
1069 handle->
debug_print(
"bmp388: set fifo config 1 register failed.\n");
1105 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
1141 handle->
debug_print(
"bmp388: subsample is invalid.\n");
1148 handle->
debug_print(
"bmp388: get fifo config 2 register failed.\n");
1153 prev |= subsample << 0;
1157 handle->
debug_print(
"bmp388: set fifo config 2 register failed.\n");
1193 handle->
debug_print(
"bmp388: get fifo config 2 register failed.\n");
1230 handle->
debug_print(
"bmp388: get fifo config 2 register failed.\n");
1235 prev |= source << 3;
1239 handle->
debug_print(
"bmp388: set fifo config 2 register failed.\n");
1275 handle->
debug_print(
"bmp388: get fifo config 2 register failed.\n");
1312 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1317 prev |= pin_type << 0;
1321 handle->
debug_print(
"bmp388: set int ctrl register failed.\n");
1357 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1394 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1403 handle->
debug_print(
"bmp388: set int ctrl register failed.\n");
1439 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1476 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1481 prev |= enable << 2;
1485 handle->
debug_print(
"bmp388: set int ctrl register failed.\n");
1521 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1558 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1563 prev |= enable << 3;
1567 handle->
debug_print(
"bmp388: set int ctrl register failed.\n");
1603 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1640 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1645 prev |= enable << 4;
1649 handle->
debug_print(
"bmp388: set int ctrl register failed.\n");
1685 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1722 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1727 prev |= enable << 6;
1731 handle->
debug_print(
"bmp388: set int ctrl register failed.\n");
1767 handle->
debug_print(
"bmp388: get int ctrl register failed.\n");
1804 handle->
debug_print(
"bmp388: get if conf register failed.\n");
1813 handle->
debug_print(
"bmp388: set if conf register failed.\n");
1849 handle->
debug_print(
"bmp388: get if conf register failed.\n");
1886 handle->
debug_print(
"bmp388: get if conf register failed.\n");
1891 prev |= enable << 1;
1895 handle->
debug_print(
"bmp388: set if conf register failed.\n");
1931 handle->
debug_print(
"bmp388: get if conf register failed.\n");
1968 handle->
debug_print(
"bmp388: get if conf register failed.\n");
1973 prev |= period << 2;
1977 handle->
debug_print(
"bmp388: set if conf register failed.\n");
2013 handle->
debug_print(
"bmp388: get if conf register failed.\n");
2050 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2055 prev |= enable << 0;
2059 handle->
debug_print(
"bmp388: set pwr ctrl register failed.\n");
2095 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2132 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2137 prev |= enable << 1;
2141 handle->
debug_print(
"bmp388: set pwr ctrl register failed.\n");
2177 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2214 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2223 handle->
debug_print(
"bmp388: set pwr ctrl register failed.\n");
2259 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2293 res = a_bmp388_iic_spi_read(handle,
BMP388_REG_OSR, (uint8_t *)&prev, 1);
2296 handle->
debug_print(
"bmp388: get osr register failed.\n");
2301 prev |= oversampling << 0;
2302 res = a_bmp388_iic_spi_write(handle,
BMP388_REG_OSR, (uint8_t *)&prev, 1);
2305 handle->
debug_print(
"bmp388: set osr register failed.\n");
2338 res = a_bmp388_iic_spi_read(handle,
BMP388_REG_OSR, (uint8_t *)&prev, 1);
2341 handle->
debug_print(
"bmp388: get osr register failed.\n");
2375 res = a_bmp388_iic_spi_read(handle,
BMP388_REG_OSR, (uint8_t *)&prev, 1);
2378 handle->
debug_print(
"bmp388: get osr register failed.\n");
2383 prev |= oversampling << 3;
2384 res = a_bmp388_iic_spi_write(handle,
BMP388_REG_OSR, (uint8_t *)&prev, 1);
2387 handle->
debug_print(
"bmp388: set osr register failed.\n");
2420 res = a_bmp388_iic_spi_read(handle,
BMP388_REG_OSR, (uint8_t *)&prev, 1);
2423 handle->
debug_print(
"bmp388: get osr register failed.\n");
2457 res = a_bmp388_iic_spi_read(handle,
BMP388_REG_ODR, (uint8_t *)&prev, 1);
2460 handle->
debug_print(
"bmp388: get odr register failed.\n");
2467 res = a_bmp388_iic_spi_write(handle,
BMP388_REG_ODR, (uint8_t *)&prev, 1);
2470 handle->
debug_print(
"bmp388: set odr register failed.\n");
2503 res = a_bmp388_iic_spi_read(handle,
BMP388_REG_ODR, (uint8_t *)&prev, 1);
2506 handle->
debug_print(
"bmp388: get odr register failed.\n");
2543 handle->
debug_print(
"bmp388: get config register failed.\n");
2548 prev &= ~(0x7 << 1);
2549 prev |= coefficient << 1;
2553 handle->
debug_print(
"bmp388: set config register failed.\n");
2589 handle->
debug_print(
"bmp388: get config register failed.\n");
2623 res = a_bmp388_iic_spi_write(handle,
BMP388_REG_CMD, (uint8_t *)&prev, 1);
2626 handle->
debug_print(
"bmp388: set cmd register failed.\n");
2659 res = a_bmp388_iic_spi_write(handle,
BMP388_REG_CMD, (uint8_t *)&prev, 1);
2662 handle->
debug_print(
"bmp388: set cmd register failed.\n");
2695 res = a_bmp388_iic_spi_write(handle,
BMP388_REG_CMD, (uint8_t *)&prev, 1);
2698 handle->
debug_print(
"bmp388: set cmd register failed.\n");
2722 handle->
debug_print(
"bmp388: iic deinit failed.\n");
2735 handle->
debug_print(
"bmp388: spi deinit failed.\n");
2774 handle->
debug_print(
"bmp388: iic_init is null.\n");
2780 handle->
debug_print(
"bmp388: iic_deinit is null.\n");
2786 handle->
debug_print(
"bmp388: iic_read is null.\n");
2792 handle->
debug_print(
"bmp388: iic_write is null.\n");
2798 handle->
debug_print(
"bmp388: spi_init is null.\n");
2804 handle->
debug_print(
"bmp388: spi_deinit is null.\n");
2810 handle->
debug_print(
"bmp388: spi_read is null.\n");
2816 handle->
debug_print(
"bmp388: spi_write is null.\n");
2822 handle->
debug_print(
"bmp388: delay_ms is null.\n");
2831 handle->
debug_print(
"bmp388: iic init failed.\n");
2840 handle->
debug_print(
"bmp388: spi init failed.\n");
2847 handle->
debug_print(
"bmp388: read chip id failed.\n");
2848 (void)a_bmp388_close(handle);
2855 (void)a_bmp388_close(handle);
2860 if (a_bmp388_iic_spi_write(handle,
BMP388_REG_CMD, (uint8_t *)®, 1) != 0)
2862 handle->
debug_print(
"bmp388: soft rest failed.\n");
2863 (void)a_bmp388_close(handle);
2870 handle->
debug_print(
"bmp388: get err reg failed.\n");
2871 (void)a_bmp388_close(handle);
2875 if ((reg & 0x07) != 0)
2877 handle->
debug_print(
"bmp388: find running error.\n");
2878 (void)a_bmp388_close(handle);
2882 if (a_bmp388_get_calibration_data(handle) != 0)
2884 handle->
debug_print(
"bmp388: get calibration data error.\n");
2885 (void)a_bmp388_close(handle);
2922 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2931 handle->
debug_print(
"bmp388: set pwr ctrl register failed.\n");
2935 if (a_bmp388_close(handle) != 0)
2977 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
2981 if ((prev & 0x01) != 0)
2983 handle->
debug_print(
"bmp388: fifo mode can't use this function.\n");
2990 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
2994 if (((prev >> 4) & 0x03) == 0x03)
2999 handle->
debug_print(
"bmp388: get status register failed.\n");
3003 if ((prev & (1 << 6)) != 0)
3010 handle->
debug_print(
"bmp388: get data register failed.\n");
3014 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3015 output = a_bmp388_compensate_temperature(handle, *raw);
3016 *c = (float)((
double)output / 100.0);
3023 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3028 else if (((prev >> 4) & 0x03) == 0x00)
3030 uint16_t cnt = 5000;
3035 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
3039 prev &= ~(0x03 << 4);
3044 handle->
debug_print(
"bmp388: set pwr ctrl register failed.\n");
3054 handle->
debug_print(
"bmp388: get status register failed.\n");
3058 if ((prev & (1 << 6)) != 0)
3065 handle->
debug_print(
"bmp388: get data register failed.\n");
3069 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3070 output = a_bmp388_compensate_temperature(handle, *raw);
3071 *c = (float)((
double)output / 100.0);
3085 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3093 handle->
debug_print(
"bmp388: mode is invalid.\n");
3116 uint32_t temperature_raw;
3130 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
3134 if ((prev & 0x01) != 0)
3136 handle->
debug_print(
"bmp388: fifo mode can't use this function.\n");
3143 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
3147 if (((prev >> 4) & 0x03) == 0x03)
3152 handle->
debug_print(
"bmp388: get status register failed.\n");
3156 if ((prev & (1 << 6)) != 0)
3161 handle->
debug_print(
"bmp388: get data register failed.\n");
3165 temperature_raw= (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3166 (void)a_bmp388_compensate_temperature(handle, temperature_raw);
3170 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3174 if ((prev & (1 << 5)) != 0)
3181 handle->
debug_print(
"bmp388: get data register failed.\n");
3185 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3186 output = a_bmp388_compensate_pressure(handle, *raw);
3187 *pa = (float)((
double)output / 100.0);
3193 handle->
debug_print(
"bmp388: pressure data is not ready.\n");
3198 else if (((prev >> 4) & 0x03) == 0x00)
3200 uint16_t cnt = 5000;
3205 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
3209 prev &= ~(0x03 << 4);
3214 handle->
debug_print(
"bmp388: set pwr ctrl register failed.\n");
3224 handle->
debug_print(
"bmp388: get status register failed.\n");
3228 if ((prev & (1 << 6)) != 0)
3233 handle->
debug_print(
"bmp388: get data register failed.\n");
3237 temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3238 (void)a_bmp388_compensate_temperature(handle, temperature_raw);
3251 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3259 if ((prev & (1 << 5)) != 0)
3266 handle->
debug_print(
"bmp388: get data register failed.\n");
3270 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3271 output = a_bmp388_compensate_pressure(handle, *raw);
3272 *pa = (float)((
double)output / 100.0);
3285 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3293 handle->
debug_print(
"bmp388: mode is invalid.\n");
3314 uint32_t *pressure_raw,
float *pressure_pa)
3332 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
3336 if ((prev & 0x01) != 0)
3338 handle->
debug_print(
"bmp388: fifo mode can't use this function.\n");
3345 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
3349 if (((prev >> 4) & 0x03) == 0x03)
3354 handle->
debug_print(
"bmp388: get status register failed.\n");
3358 if ((prev & (1 << 6)) != 0)
3365 handle->
debug_print(
"bmp388: get data register failed.\n");
3369 *temperature_raw= (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3370 output = a_bmp388_compensate_temperature(handle, *temperature_raw);
3371 *temperature_c = (float)((
double)output / 100.0);
3375 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3379 if ((prev & (1 << 5)) != 0)
3386 handle->
debug_print(
"bmp388: get data register failed.\n");
3390 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3391 output = a_bmp388_compensate_pressure(handle, *pressure_raw);
3392 *pressure_pa = (float)((
double)output / 100.0);
3398 handle->
debug_print(
"bmp388: pressure data is not ready.\n");
3403 else if (((prev >> 4) & 0x03) == 0x00)
3405 uint16_t cnt = 5000;
3410 handle->
debug_print(
"bmp388: get pwr ctrl register failed.\n");
3414 prev &= ~(0x03 << 4);
3419 handle->
debug_print(
"bmp388: set pwr ctrl register failed.\n");
3429 handle->
debug_print(
"bmp388: get status register failed.\n");
3433 if ((prev & (1 << 6)) != 0)
3440 handle->
debug_print(
"bmp388: get data register failed.\n");
3444 *temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3445 output = a_bmp388_compensate_temperature(handle, *temperature_raw);
3446 *temperature_c = (float)((
double)output / 100.0);
3459 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3468 if ((prev & (1 << 5)) != 0)
3475 handle->
debug_print(
"bmp388: get data register failed.\n");
3479 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0];
3480 output = a_bmp388_compensate_pressure(handle, *pressure_raw);
3481 *pressure_pa = (float)((
double)output / 100.0);
3494 handle->
debug_print(
"bmp388: temperature data is not ready.\n");
3502 handle->
debug_print(
"bmp388: mode is invalid.\n");
3535 handle->
debug_print(
"bmp388: get interrupt status register failed.\n");
3539 if ((status & (1 << 1)) != 0)
3546 if ((status & (1 << 0)) != 0)
3553 if ((status & (1 << 3)) != 0)
3580 handle->
iic_addr = (uint8_t)addr_pin;
3622 handle->
iic_spi = (uint8_t)interface;
3679 handle->
debug_print(
"bmp388: get fifo config 1 register failed.\n");
3683 if ((prev & 0x01) != 0)
3688 handle->
debug_print(
"bmp388: get fifo length register failed.\n");
3692 length = ((uint16_t)(tmp_buf[1] & 0x01) << 8) | tmp_buf[0];
3693 if ((prev & (1 << 2)) != 0)
3697 *len = (*len) < length ? (*len) :length;
3701 handle->
debug_print(
"bmp388: get fifo data failed.\n");
3710 handle->
debug_print(
"bmp388: normal mode or forced mode can't use this function.\n");
3734 uint16_t frame_total;
3747 handle->
debug_print(
"bmp388: buffer length is invalid.\n");
3756 switch ((uint8_t)buf[i])
3760 if (frame_total > ((*frame_len)-1))
3765 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3766 frame[frame_total].
data = (float)((
double)a_bmp388_compensate_temperature(handle, frame[frame_total].raw) / 100.0);
3774 if ((frame_total) > ((*frame_len)-1))
3779 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3780 frame[frame_total].
data = (float)((
double)a_bmp388_compensate_temperature(handle, frame[frame_total].raw) / 100.0);
3782 if (frame_total > ((*frame_len)-1))
3787 frame[frame_total].
raw = (uint32_t)buf[i + 5 + 1] << 16 | (uint32_t)buf[i + 4 + 1] << 8 | buf[i + 3 + 1];
3788 frame[frame_total].
data = (float)((
double)a_bmp388_compensate_pressure(handle, frame[frame_total].raw) / 100.0);
3796 if (frame_total > ((*frame_len)-1))
3801 frame[frame_total].
raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1];
3802 frame[frame_total].
data = 0;
3828 handle->
debug_print(
"bmp388: header is invalid.\n");
3839 *frame_len = frame_total;
3867 return a_bmp388_iic_spi_write(handle, reg, &value, 1);
3893 return a_bmp388_iic_spi_read(handle, reg, value, 1);
#define BMP388_REG_DATA_3
#define BMP388_REG_FIFO_LENGTH_0
#define BMP388_REG_NVM_PAR_P9_L
#define BMP388_REG_IF_CONF
#define BMP388_REG_CONFIG
#define BMP388_REG_NVM_PAR_P5_L
#define BMP388_REG_NVM_PAR_P1_L
#define BMP388_REG_NVM_PAR_P8
#define BMP388_REG_NVM_PAR_T3
#define BMP388_REG_SENSORTIME_0
#define BMP388_REG_FIFO_WTM_0
#define BMP388_REG_FIFO_CONFIG_2
#define BMP388_REG_NVM_PAR_T1_L
#define BMP388_REG_NVM_PAR_P3
#define BMP388_REG_INT_CTRL
#define BMP388_REG_NVM_PAR_P6_L
#define SUPPLY_VOLTAGE_MAX
#define BMP388_REG_DATA_0
#define BMP388_REG_STATUS
#define BMP388_REG_NVM_PAR_T2_L
#define BMP388_REG_ERR_REG
#define BMP388_REG_FIFO_CONFIG_1
#define BMP388_REG_NVM_PAR_P4
#define BMP388_REG_PWR_CTRL
#define BMP388_REG_NVM_PAR_P10
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BMP388_REG_NVM_PAR_P11
#define BMP388_REG_FIFO_DATA
#define BMP388_REG_NVM_PAR_P7
#define CHIP_NAME
chip information definition
#define BMP388_REG_CHIP_ID
#define BMP388_REG_NVM_PAR_P2_L
#define BMP388_REG_INT_STATUS
#define BMP388_REG_CMD
chip register definition
driver bmp388 header file
bmp388_oversampling_t
bmp388 oversampling enumeration definition
uint8_t bmp388_get_error(bmp388_handle_t *handle, uint8_t *err)
get the error
uint8_t bmp388_set_odr(bmp388_handle_t *handle, bmp388_odr_t odr)
set the output data rate
uint8_t bmp388_set_pressure(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the pressure
bmp388_interface_t
bmp388 interface enumeration definition
uint8_t bmp388_init(bmp388_handle_t *handle)
initialize the chip
uint8_t bmp388_set_spi_wire(bmp388_handle_t *handle, bmp388_spi_wire_t wire)
set the spi wire
uint8_t bmp388_read_pressure(bmp388_handle_t *handle, uint32_t *raw, float *pa)
read the pressure
bmp388_spi_wire_t
bmp388 spi wire enumeration definition
uint8_t bmp388_get_temperature_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t *oversampling)
get the temperature oversampling
uint8_t bmp388_get_interface(bmp388_handle_t *handle, bmp388_interface_t *interface)
get the interface
uint8_t bmp388_set_iic_watchdog_timer(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the iic watchdog timer
uint8_t bmp388_read_temperature(bmp388_handle_t *handle, uint32_t *raw, float *c)
read the temperature
uint8_t bmp388_get_pressure(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the pressure status
uint8_t bmp388_get_event(bmp388_handle_t *handle, bmp388_event_t *event)
get the event
struct bmp388_handle_s bmp388_handle_t
bmp388 handle structure definition
uint8_t bmp388_set_pressure_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the pressure oversampling
struct bmp388_frame_s bmp388_frame_t
bmp388 frame structure definition
uint8_t bmp388_get_iic_watchdog_period(bmp388_handle_t *handle, bmp388_iic_watchdog_period_t *period)
get the iic watchdog period
uint8_t bmp388_get_pressure_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t *oversampling)
get the pressure oversampling
uint8_t bmp388_set_temperature(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the temperature
uint8_t bmp388_set_filter_coefficient(bmp388_handle_t *handle, bmp388_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp388_irq_handler(bmp388_handle_t *handle)
irq handler
uint8_t bmp388_deinit(bmp388_handle_t *handle)
close the chip
uint8_t bmp388_set_interface(bmp388_handle_t *handle, bmp388_interface_t interface)
set the interface
uint8_t bmp388_get_mode(bmp388_handle_t *handle, bmp388_mode_t *mode)
get the chip mode
uint8_t bmp388_get_status(bmp388_handle_t *handle, uint8_t *status)
get the status
uint8_t bmp388_get_addr_pin(bmp388_handle_t *handle, bmp388_address_t *addr_pin)
get the iic address pin
bmp388_filter_coefficient_t
bmp388 filter coefficient enumeration definition
uint8_t bmp388_get_sensortime(bmp388_handle_t *handle, uint32_t *t)
get the sensor time
uint8_t bmp388_set_iic_watchdog_period(bmp388_handle_t *handle, bmp388_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp388_read_temperature_pressure(bmp388_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
bmp388_event_t
bmp388 event enumeration definition
uint8_t bmp388_set_mode(bmp388_handle_t *handle, bmp388_mode_t mode)
set the chip mode
uint8_t bmp388_softreset(bmp388_handle_t *handle)
soft reset
bmp388_odr_t
bmp388 output data rate enumeration definition
uint8_t bmp388_set_temperature_oversampling(bmp388_handle_t *handle, bmp388_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp388_get_temperature(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the temperature status
uint8_t bmp388_extmode_en_middle(bmp388_handle_t *handle)
extmode enable middle
bmp388_interrupt_active_level_t
bmp388 interrupt active level enumeration definition
uint8_t bmp388_get_iic_watchdog_timer(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the iic watchdog timer status
uint8_t bmp388_set_addr_pin(bmp388_handle_t *handle, bmp388_address_t addr_pin)
set the iic address pin
bmp388_bool_t
bmp388 bool enumeration definition
bmp388_fifo_data_source_t
bmp388 fifo data source enumeration definition
bmp388_mode_t
bmp388 mode enumeration definition
struct bmp388_info_s bmp388_info_t
bmp388 information structure definition
uint8_t bmp388_info(bmp388_info_t *info)
get chip's information
bmp388_interrupt_pin_type_t
bmp388 interrupt pin type enumeration definition
bmp388_address_t
bmp388 address enumeration definition
uint8_t bmp388_get_spi_wire(bmp388_handle_t *handle, bmp388_spi_wire_t *wire)
get the spi wire
uint8_t bmp388_get_odr(bmp388_handle_t *handle, bmp388_odr_t *odr)
get the output data rate
bmp388_iic_watchdog_period_t
bmp388 iic watchdog period enumeration definition
uint8_t bmp388_get_filter_coefficient(bmp388_handle_t *handle, bmp388_filter_coefficient_t *coefficient)
get the filter coefficient
@ BMP388_FRAME_TYPE_SENSORTIME
@ BMP388_FRAME_TYPE_TEMPERATURE
@ BMP388_FRAME_TYPE_PRESSURE
@ BMP388_INTERRUPT_STATUS_FIFO_FULL
@ BMP388_INTERRUPT_STATUS_DATA_READY
@ BMP388_INTERRUPT_STATUS_FIFO_WATERMARK
uint8_t bmp388_get_reg(bmp388_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
uint8_t bmp388_set_reg(bmp388_handle_t *handle, uint8_t reg, uint8_t value)
set the chip register
uint8_t bmp388_get_fifo_data(bmp388_handle_t *handle, uint8_t *data, uint16_t length)
get the fifo data
uint8_t bmp388_get_fifo_subsampling(bmp388_handle_t *handle, uint8_t *subsample)
get the fifo subsampling
uint8_t bmp388_get_fifo_sensortime_on(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the fifo sensor time on status
uint8_t bmp388_read_fifo(bmp388_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp388_set_fifo_temperature_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp388_fifo_parse(bmp388_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp388_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp388_get_fifo_length(bmp388_handle_t *handle, uint16_t *length)
get the fifo length
uint8_t bmp388_set_fifo_watermark(bmp388_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp388_set_fifo_subsampling(bmp388_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp388_get_fifo_stop_on_full(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the fifo stopping on full status
uint8_t bmp388_get_fifo_pressure_on(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the fifo pressure on status
uint8_t bmp388_get_fifo_data_source(bmp388_handle_t *handle, bmp388_fifo_data_source_t *source)
get the fifo data source
uint8_t bmp388_set_fifo_data_source(bmp388_handle_t *handle, bmp388_fifo_data_source_t source)
set the fifo data source
uint8_t bmp388_get_fifo_watermark(bmp388_handle_t *handle, uint16_t *watermark)
get the fifo watermark
uint8_t bmp388_set_fifo_stop_on_full(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp388_set_fifo_sensortime_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp388_get_fifo_temperature_on(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the fifo temperature on status
uint8_t bmp388_set_fifo_pressure_on(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp388_set_fifo(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo
uint8_t bmp388_get_fifo(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the fifo status
uint8_t bmp388_flush_fifo(bmp388_handle_t *handle)
flush the fifo
uint8_t bmp388_get_interrupt_fifo_watermark(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the interrupt fifo watermark
uint8_t bmp388_get_interrupt_data_ready(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the interrupt data ready status
uint8_t bmp388_get_interrupt_active_level(bmp388_handle_t *handle, bmp388_interrupt_active_level_t *level)
get the interrupt active level
uint8_t bmp388_get_latch_interrupt_pin_and_interrupt_status(bmp388_handle_t *handle, bmp388_bool_t *enable)
get latching interrupt pin and interrupt status
uint8_t bmp388_set_interrupt_fifo_full(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp388_get_interrupt_fifo_full(bmp388_handle_t *handle, bmp388_bool_t *enable)
get the interrupt fifo full
uint8_t bmp388_set_interrupt_fifo_watermark(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp388_get_interrupt_status(bmp388_handle_t *handle, uint8_t *status)
get the interrupt status
uint8_t bmp388_get_interrupt_pin_type(bmp388_handle_t *handle, bmp388_interrupt_pin_type_t *pin_type)
get the interrupt pin type
uint8_t bmp388_set_interrupt_data_ready(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp388_set_interrupt_active_level(bmp388_handle_t *handle, bmp388_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp388_set_interrupt_pin_type(bmp388_handle_t *handle, bmp388_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp388_set_latch_interrupt_pin_and_interrupt_status(bmp388_handle_t *handle, bmp388_bool_t enable)
enable or disable latching interrupt pin and interrupt status
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