LibDriver BMP388
Loading...
Searching...
No Matches
driver_bmp388.c
Go to the documentation of this file.
1
37
38#include "driver_bmp388.h"
39
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
51
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
104
116static uint8_t a_bmp388_iic_spi_read(bmp388_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
117{
118 if (handle->iic_spi == BMP388_INTERFACE_IIC) /* iic interface */
119 {
120 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* iic read */
121 {
122 return 1; /* return error */
123 }
124 else
125 {
126 return 0; /* success return 0 */
127 }
128 }
129 else /* spi interface */
130 {
131 reg |= 1 << 7; /* set read mode */
132 if (handle->spi_read(reg, handle->buf,
133 len > 512 ? (512 + 1) : (len + 1)) != 0) /* spi read */
134 {
135 return 1; /* return error */
136 }
137 memcpy(buf, handle->buf+1, (len > 512) ? 512 : len); /* copy data */
138
139 return 0; /* success return 0 */
140 }
141}
142
154static uint8_t a_bmp388_iic_spi_write(bmp388_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
155{
156 if (handle->iic_spi == BMP388_INTERFACE_IIC) /* iic interface */
157 {
158 uint16_t i;
159
160 for (i = 0; i < len; i++) /* write data one byte by one byte */
161 {
162 if (handle->iic_write(handle->iic_addr,
163 (uint8_t)(reg + i), buf + i, 1) != 0) /* iic write */
164 {
165 return 1; /* return error */
166 }
167 }
168
169 return 0; /* success return 0 */
170 }
171 else
172 {
173 uint16_t i;
174
175 reg &= ~(1 << 7); /* write mode */
176 for (i = 0; i < len; i++) /* write data one byte by one byte */
177 {
178 if (handle->spi_write((uint8_t)(reg + i), buf + i, 1) != 0) /* spi write */
179 {
180 return 1; /* return error */
181 }
182 }
183
184 return 0; /* success return 0 */
185 }
186}
187
196static uint8_t a_bmp388_get_calibration_data(bmp388_handle_t *handle)
197{
198 uint8_t buf[2];
199
200 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_T1_L, (uint8_t *)buf, 2) != 0) /* read t1 */
201 {
202 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
203
204 return 1; /* return error */
205 }
206 handle->t1 = (uint16_t)buf[1] << 8 | buf[0]; /* set t1 */
207 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_T2_L, (uint8_t *)buf, 2) != 0) /* read t2 */
208 {
209 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
210
211 return 1; /* return error */
212 }
213 handle->t2 = (uint16_t)buf[1] << 8 | buf[0]; /* set t2 */
214 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_T3, (uint8_t *)buf, 1) != 0) /* read t3 */
215 {
216 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
217
218 return 1; /* return error */
219 }
220 handle->t3 = (int8_t)(buf[0]); /* set t3 */
221 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P1_L, (uint8_t *)buf, 2) != 0) /* read p1 */
222 {
223 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
224
225 return 1; /* return error */
226 }
227 handle->p1 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p1 */
228 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P2_L, (uint8_t *)buf, 2) != 0) /* read p2 */
229 {
230 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
231
232 return 1; /* return error */
233 }
234 handle->p2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p2 */
235 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P3, (uint8_t *)buf, 1) != 0) /* read p3 */
236 {
237 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
238
239 return 1; /* return error */
240 }
241 handle->p3 = (int8_t)(buf[0]); /* set p3 */
242 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P4, (uint8_t *)buf, 1) != 0) /* read p4 */
243 {
244 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
245
246 return 1; /* return error */
247 }
248 handle->p4 = (int8_t)(buf[0]); /* set p4 */
249 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P5_L, (uint8_t *)buf, 2) != 0) /* read p5 */
250 {
251 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
252
253 return 1; /* return error */
254 }
255 handle->p5 = (uint16_t)buf[1] << 8 | buf[0]; /* set p5 */
256 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P6_L, (uint8_t *)buf, 2) != 0) /* read p6l */
257 {
258 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
259
260 return 1; /* return error */
261 }
262 handle->p6 = (uint16_t)buf[1] << 8 | buf[0]; /* set p6 */
263 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P7, (uint8_t *)buf, 1) != 0) /* read p7 */
264 {
265 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
266
267 return 1; /* return error */
268 }
269 handle->p7 = (int8_t)(buf[0]); /* set p7 */
270 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P8, (uint8_t *)buf, 1) != 0) /* read p8 */
271 {
272 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
273
274 return 1; /* return error */
275 }
276 handle->p8 = (int8_t)(buf[0]); /* set p8 */
277 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P9_L, (uint8_t *)buf, 2) != 0) /* read p9l */
278 {
279 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
280
281 return 1; /* return error */
282 }
283 handle->p9 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p9 */
284 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P10, (uint8_t *)buf, 1) != 0) /* read p10 */
285 {
286 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
287
288 return 1; /* return error */
289 }
290 handle->p10 = (int8_t)(buf[0]); /* set p10 */
291 if (a_bmp388_iic_spi_read(handle, BMP388_REG_NVM_PAR_P11, (uint8_t *)buf, 1) != 0) /* read p11 */
292 {
293 handle->debug_print("bmp388: get calibration data failed.\n"); /* get calibration data failed */
294
295 return 1; /* return error */
296 }
297 handle->p11 = (int8_t)(buf[0]); /* set p11 */
298
299 return 0; /* success return 0 */
300}
301
309static int64_t a_bmp388_compensate_temperature(bmp388_handle_t *handle, uint32_t data)
310{
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;
317 int64_t comp_temp;
318
319 /* calculate compensate temperature */
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);
328
329 return comp_temp;
330}
331
339static int64_t a_bmp388_compensate_pressure(bmp388_handle_t *handle, uint32_t data)
340{
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;
347 int64_t offset;
348 int64_t sensitivity;
349 uint64_t comp_press;
350
351 /* calculate compensate pressure */
352 partial_data1 = handle->t_fine * handle->t_fine;
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);
373
374 return comp_press;
375}
376
388uint8_t bmp388_get_error(bmp388_handle_t *handle, uint8_t *err)
389{
390 uint8_t res;
391
392 if (handle == NULL) /* check handle */
393 {
394 return 2; /* return error */
395 }
396 if (handle->inited != 1) /* check handle initialization */
397 {
398 return 3; /* return error */
399 }
400
401 res = a_bmp388_iic_spi_read(handle, BMP388_REG_ERR_REG, (uint8_t *)err, 1); /* read config */
402 if (res != 0) /* check result */
403 {
404 handle->debug_print("bmp388: get error register failed.\n"); /* get error register failed */
405
406 return 1; /* return error */
407 }
408
409 return 0; /* success return 0 */
410}
411
423uint8_t bmp388_get_status(bmp388_handle_t *handle, uint8_t *status)
424{
425 uint8_t res;
426
427 if (handle == NULL) /* check handle */
428 {
429 return 2; /* return error */
430 }
431 if (handle->inited != 1) /* check handle initialization */
432 {
433 return 3; /* return error */
434 }
435
436 res = a_bmp388_iic_spi_read(handle, BMP388_REG_STATUS, (uint8_t *)status, 1); /* read status */
437 if (res != 0) /* check result */
438 {
439 handle->debug_print("bmp388: get status register failed.\n"); /* get status register failed */
440
441 return 1; /* return error */
442 }
443
444 return 0; /* success return 0 */
445}
446
458uint8_t bmp388_get_sensortime(bmp388_handle_t *handle, uint32_t *t)
459{
460 uint8_t res;
461 uint8_t buf[3];
462
463 if (handle == NULL) /* check handle */
464 {
465 return 2; /* return error */
466 }
467 if (handle->inited != 1) /* check handle initialization */
468 {
469 return 3; /* return error */
470 }
471
472 res = a_bmp388_iic_spi_read(handle, BMP388_REG_SENSORTIME_0, (uint8_t *)buf, 3); /* read config */
473 if (res != 0) /* check result */
474 {
475 handle->debug_print("bmp388: get sensor time register failed.\n"); /* get sensor time register failed */
476
477 return 1; /* return error */
478 }
479 *t = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get time */
480
481 return 0; /* success return 0 */
482}
483
496{
497 uint8_t res;
498 uint8_t prev;
499
500 if (handle == NULL) /* check handle */
501 {
502 return 2; /* return error */
503 }
504 if (handle->inited != 1) /* check handle initialization */
505 {
506 return 3; /* return error */
507 }
508
509 res = a_bmp388_iic_spi_read(handle, BMP388_REG_EVENT, (uint8_t *)&prev, 1); /* read config */
510 if (res != 0) /* check result */
511 {
512 handle->debug_print("bmp388: get event register failed.\n"); /* get event register failed */
513
514 return 1; /* return error */
515 }
516 *event = (bmp388_event_t)(prev & (1 << 0)); /* get event */
517
518 return 0; /* success return 0 */
519}
520
532uint8_t bmp388_get_interrupt_status(bmp388_handle_t *handle, uint8_t *status)
533{
534 uint8_t res;
535
536 if (handle == NULL) /* check handle */
537 {
538 return 2; /* return error */
539 }
540 if (handle->inited != 1) /* check handle initialization */
541 {
542 return 3; /* return error */
543 }
544
545 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_STATUS, (uint8_t *)status, 1); /* read status */
546 if (res != 0) /* check result */
547 {
548 handle->debug_print("bmp388: get interrupt status register failed.\n"); /* get interrupt status register failed */
549
550 return 1; /* return error */
551 }
552
553 return 0; /* success return 0 */
554}
555
567uint8_t bmp388_get_fifo_length(bmp388_handle_t *handle, uint16_t *length)
568{
569 uint8_t res;
570 uint8_t buf[2];
571
572 if (handle == NULL) /* check handle */
573 {
574 return 2; /* return error */
575 }
576 if (handle->inited != 1) /* check handle initialization */
577 {
578 return 3; /* return error */
579 }
580
581 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_LENGTH_0, (uint8_t *)buf, 2); /* read config */
582 if (res != 0) /* check result */
583 {
584 handle->debug_print("bmp388: get fifo length register failed.\n"); /* get fifo length register failed */
585
586 return 1; /* return error */
587 }
588 *length = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0]; /* get data */
589
590 return 0; /* success return 0 */
591}
592
605uint8_t bmp388_get_fifo_data(bmp388_handle_t *handle, uint8_t *data, uint16_t length)
606{
607 uint8_t res;
608
609 if (handle == NULL) /* check handle */
610 {
611 return 2; /* return error */
612 }
613 if (handle->inited != 1) /* check handle initialization */
614 {
615 return 3; /* return error */
616 }
617
618 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_DATA, (uint8_t *)data, length); /* read data */
619 if (res != 0) /* check result */
620 {
621 handle->debug_print("bmp388: get fifo data register failed.\n"); /* get fifo data register failed */
622
623 return 1; /* return error */
624 }
625
626 return 0; /* success return 0 */
627}
628
640uint8_t bmp388_set_fifo_watermark(bmp388_handle_t *handle, uint16_t watermark)
641{
642 uint8_t res;
643 uint8_t buf[2];
644
645 if (handle == NULL) /* check handle */
646 {
647 return 2; /* return error */
648 }
649 if (handle->inited != 1) /* check handle initialization */
650 {
651 return 3; /* return error */
652 }
653
654 buf[0] = watermark & 0xFF; /* set low part */
655 buf[1] = (watermark >> 8) & 0x01; /* set high part */
656 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_WTM_0, (uint8_t *)buf, 2); /* write config */
657 if (res != 0) /* check result */
658 {
659 handle->debug_print("bmp388: set fifo watermark register failed.\n"); /* set fifo watermark register failed */
660
661 return 1; /* return error */
662 }
663
664 return 0; /* success return 0 */
665}
666
678uint8_t bmp388_get_fifo_watermark(bmp388_handle_t *handle, uint16_t *watermark)
679{
680 uint8_t res;
681 uint8_t buf[2];
682
683 if (handle == NULL) /* check handle */
684 {
685 return 2; /* return error */
686 }
687 if (handle->inited != 1) /* check handle initialization */
688 {
689 return 3; /* return error */
690 }
691
692 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_WTM_0, (uint8_t *)buf, 2); /* read config */
693 if (res != 0) /* check result */
694 {
695 handle->debug_print("bmp388: get fifo watermark register failed.\n"); /* get fifo watermark register failed */
696
697 return 1; /* return error */
698 }
699 *watermark = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0]; /* get data */
700
701 return 0; /* success return 0 */
702}
703
716{
717 uint8_t res;
718 uint8_t prev;
719
720 if (handle == NULL) /* check handle */
721 {
722 return 2; /* return error */
723 }
724 if (handle->inited != 1) /* check handle initialization */
725 {
726 return 3; /* return error */
727 }
728
729 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
730 if (res != 0) /* check result */
731 {
732 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
733
734 return 1; /* return error */
735 }
736 prev &= ~(1 << 0); /* clear config */
737 prev |= enable << 0; /* set config */
738 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
739 if (res != 0) /* check result */
740 {
741 handle->debug_print("bmp388: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
742
743 return 1; /* return error */
744 }
745
746 return 0; /* success return 0 */
747}
748
761{
762 uint8_t res;
763 uint8_t prev;
764
765 if (handle == NULL) /* check handle */
766 {
767 return 2; /* return error */
768 }
769 if (handle->inited != 1) /* check handle initialization */
770 {
771 return 3; /* return error */
772 }
773
774 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
775 if (res != 0) /* check result */
776 {
777 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
778
779 return 1; /* return error */
780 }
781 *enable = (bmp388_bool_t)(prev & 0x01); /* get config */
782
783 return 0; /* success return 0 */
784}
785
798{
799 uint8_t res;
800 uint8_t prev;
801
802 if (handle == NULL) /* check handle */
803 {
804 return 2; /* return error */
805 }
806 if (handle->inited != 1) /* check handle initialization */
807 {
808 return 3; /* return error */
809 }
810
811 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
812 if (res != 0) /* check result */
813 {
814 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
815
816 return 1; /* return error */
817 }
818 prev &= ~(1 << 1); /* clear config */
819 prev |= enable << 1; /* set config */
820 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
821 if (res != 0) /* check result */
822 {
823 handle->debug_print("bmp388: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
824
825 return 1; /* return error */
826 }
827
828 return 0; /* success return 0 */
829}
830
843{
844 uint8_t res;
845 uint8_t prev;
846
847 if (handle == NULL) /* check handle */
848 {
849 return 2; /* return error */
850 }
851 if (handle->inited != 1) /* check handle initialization */
852 {
853 return 3; /* return error */
854 }
855
856 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
857 if (res != 0) /* check result */
858 {
859 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
860
861 return 1; /* return error */
862 }
863 *enable = (bmp388_bool_t)((prev >> 1) & 0x01); /* get config */
864
865 return 0; /* success return 0 */
866}
867
880{
881 uint8_t res;
882 uint8_t prev;
883
884 if (handle == NULL) /* check handle */
885 {
886 return 2; /* return error */
887 }
888 if (handle->inited != 1) /* check handle initialization */
889 {
890 return 3; /* return error */
891 }
892
893 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
894 if (res != 0) /* check result */
895 {
896 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
897
898 return 1; /* return error */
899 }
900 prev &= ~(1 << 2); /* clear config */
901 prev |= enable << 2; /* set config */
902 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
903 if (res != 0) /* check result */
904 {
905 handle->debug_print("bmp388: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
906
907 return 1; /* return error */
908 }
909
910 return 0; /* success return 0 */
911}
912
925{
926 uint8_t res;
927 uint8_t prev;
928
929 if (handle == NULL) /* check handle */
930 {
931 return 2; /* return error */
932 }
933 if (handle->inited != 1) /* check handle initialization */
934 {
935 return 3; /* return error */
936 }
937
938 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
939 if (res != 0) /* check result */
940 {
941 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
942
943 return 1; /* return error */
944 }
945 *enable = (bmp388_bool_t)((prev >> 2) & 0x01); /* get config */
946
947 return 0; /* success return 0 */
948}
949
962{
963 uint8_t res;
964 uint8_t prev;
965
966 if (handle == NULL) /* check handle */
967 {
968 return 2; /* return error */
969 }
970 if (handle->inited != 1) /* check handle initialization */
971 {
972 return 3; /* return error */
973 }
974
975 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
976 if (res != 0) /* check result */
977 {
978 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
979
980 return 1; /* return error */
981 }
982 prev &= ~(1 << 3); /* clear config */
983 prev |= enable << 3; /* set config */
984 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
985 if (res != 0) /* check result */
986 {
987 handle->debug_print("bmp388: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
988
989 return 1; /* return error */
990 }
991
992 return 0; /* success return 0 */
993}
994
1007{
1008 uint8_t res;
1009 uint8_t prev;
1010
1011 if (handle == NULL) /* check handle */
1012 {
1013 return 2; /* return error */
1014 }
1015 if (handle->inited != 1) /* check handle initialization */
1016 {
1017 return 3; /* return error */
1018 }
1019
1020 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1021 if (res != 0) /* check result */
1022 {
1023 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1024
1025 return 1; /* return error */
1026 }
1027 *enable = (bmp388_bool_t)((prev >> 3) & 0x01); /* get config */
1028
1029 return 0; /* success return 0 */
1030}
1031
1044{
1045 uint8_t res;
1046 uint8_t prev;
1047
1048 if (handle == NULL) /* check handle */
1049 {
1050 return 2; /* return error */
1051 }
1052 if (handle->inited != 1) /* check handle initialization */
1053 {
1054 return 3; /* return error */
1055 }
1056
1057 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1058 if (res != 0) /* check result */
1059 {
1060 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1061
1062 return 1; /* return error */
1063 }
1064 prev &= ~(1 << 4); /* clear config */
1065 prev |= enable << 4; /* set config */
1066 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
1067 if (res != 0) /* check result */
1068 {
1069 handle->debug_print("bmp388: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
1070
1071 return 1; /* return error */
1072 }
1073
1074 return 0; /* success return 0 */
1075}
1076
1089{
1090 uint8_t res;
1091 uint8_t prev;
1092
1093 if (handle == NULL) /* check handle */
1094 {
1095 return 2; /* return error */
1096 }
1097 if (handle->inited != 1) /* check handle initialization */
1098 {
1099 return 3; /* return error */
1100 }
1101
1102 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1103 if (res != 0) /* check result */
1104 {
1105 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1106
1107 return 1; /* return error */
1108 }
1109 *enable = (bmp388_bool_t)((prev >> 4) & 0x01); /* get config */
1110
1111 return 0; /* success return 0 */
1112}
1113
1125uint8_t bmp388_set_fifo_subsampling(bmp388_handle_t *handle, uint8_t subsample)
1126{
1127 uint8_t res;
1128 uint8_t prev;
1129
1130 if (handle == NULL) /* check handle */
1131 {
1132 return 2; /* return error */
1133 }
1134 if (handle->inited != 1) /* check handle initialization */
1135 {
1136 return 3; /* return error */
1137 }
1138
1139 if (subsample > 7) /* check subsample */
1140 {
1141 handle->debug_print("bmp388: subsample is invalid.\n"); /* subsample is invalid */
1142
1143 return 4; /* return error */
1144 }
1145 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1146 if (res != 0) /* check result */
1147 {
1148 handle->debug_print("bmp388: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1149
1150 return 1; /* return error */
1151 }
1152 prev &= ~(7 << 0); /* clear config */
1153 prev |= subsample << 0; /* set config */
1154 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* write config */
1155 if (res != 0) /* check result */
1156 {
1157 handle->debug_print("bmp388: set fifo config 2 register failed.\n"); /* set fifo config 2 register failed */
1158
1159 return 1; /* return error */
1160 }
1161
1162 return 0; /* success return 0 */
1163}
1164
1176uint8_t bmp388_get_fifo_subsampling(bmp388_handle_t *handle, uint8_t *subsample)
1177{
1178 uint8_t res;
1179 uint8_t prev;
1180
1181 if (handle == NULL) /* check handle */
1182 {
1183 return 2; /* return error */
1184 }
1185 if (handle->inited != 1) /* check handle initialization */
1186 {
1187 return 3; /* return error */
1188 }
1189
1190 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1191 if (res != 0) /* check result */
1192 {
1193 handle->debug_print("bmp388: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1194
1195 return 1; /* return error */
1196 }
1197 *subsample = (bmp388_bool_t)((prev >> 0) & 0x07); /* get config */
1198
1199 return 0; /* success return 0 */
1200}
1201
1214{
1215 uint8_t res;
1216 uint8_t prev;
1217
1218 if (handle == NULL) /* check handle */
1219 {
1220 return 2; /* return error */
1221 }
1222 if (handle->inited != 1) /* check handle initialization */
1223 {
1224 return 3; /* return error */
1225 }
1226
1227 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1228 if (res != 0) /* check result */
1229 {
1230 handle->debug_print("bmp388: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1231
1232 return 1; /* return error */
1233 }
1234 prev &= ~(3 << 3); /* clear config */
1235 prev |= source << 3; /* set config */
1236 res = a_bmp388_iic_spi_write(handle, BMP388_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* write config */
1237 if (res != 0) /* check result */
1238 {
1239 handle->debug_print("bmp388: set fifo config 2 register failed.\n"); /* set fifo config 2 register failed */
1240
1241 return 1; /* return error */
1242 }
1243
1244 return 0; /* success return 0 */
1245}
1246
1259{
1260 uint8_t res;
1261 uint8_t prev;
1262
1263 if (handle == NULL) /* check handle */
1264 {
1265 return 2; /* return error */
1266 }
1267 if (handle->inited != 1) /* check handle initialization */
1268 {
1269 return 3; /* return error */
1270 }
1271
1272 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1273 if (res != 0) /* check result */
1274 {
1275 handle->debug_print("bmp388: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1276
1277 return 1; /* return error */
1278 }
1279 *source = (bmp388_fifo_data_source_t)((prev >> 3) & 0x01); /* get config */
1280
1281 return 0; /* success return 0 */
1282}
1283
1296{
1297 uint8_t res;
1298 uint8_t prev;
1299
1300 if (handle == NULL) /* check handle */
1301 {
1302 return 2; /* return error */
1303 }
1304 if (handle->inited != 1) /* check handle initialization */
1305 {
1306 return 3; /* return error */
1307 }
1308
1309 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1310 if (res != 0) /* check result */
1311 {
1312 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1313
1314 return 1; /* return error */
1315 }
1316 prev &= ~(1 << 0); /* clear config */
1317 prev |= pin_type << 0; /* set config */
1318 res = a_bmp388_iic_spi_write(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1319 if (res != 0) /* check result */
1320 {
1321 handle->debug_print("bmp388: set int ctrl register failed.\n"); /* set int ctrl register failed */
1322
1323 return 1; /* return error */
1324 }
1325
1326 return 0; /* success return 0 */
1327}
1328
1341{
1342 uint8_t res;
1343 uint8_t prev;
1344
1345 if (handle == NULL) /* check handle */
1346 {
1347 return 2; /* return error */
1348 }
1349 if (handle->inited != 1) /* check handle initialization */
1350 {
1351 return 3; /* return error */
1352 }
1353
1354 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1355 if (res != 0) /* check result */
1356 {
1357 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1358
1359 return 1; /* return error */
1360 }
1361 *pin_type = (bmp388_interrupt_pin_type_t)(prev & 0x01); /* get interrupt pin type */
1362
1363 return 0; /* success return 0 */
1364}
1365
1378{
1379 uint8_t res;
1380 uint8_t prev;
1381
1382 if (handle == NULL) /* check handle */
1383 {
1384 return 2; /* return error */
1385 }
1386 if (handle->inited != 1) /* check handle initialization */
1387 {
1388 return 3; /* return error */
1389 }
1390
1391 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1392 if (res != 0) /* check result */
1393 {
1394 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1395
1396 return 1; /* return error */
1397 }
1398 prev &= ~(1 << 1); /* clear config */
1399 prev |= level << 1; /* set config */
1400 res = a_bmp388_iic_spi_write(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1401 if (res != 0) /* check result */
1402 {
1403 handle->debug_print("bmp388: set int ctrl register failed.\n"); /* set int ctrl register failed */
1404
1405 return 1; /* return error */
1406 }
1407
1408 return 0; /* success return 0 */
1409}
1410
1423{
1424 uint8_t res;
1425 uint8_t prev;
1426
1427 if (handle == NULL) /* check handle */
1428 {
1429 return 2; /* return error */
1430 }
1431 if (handle->inited != 1) /* check handle initialization */
1432 {
1433 return 3; /* return error */
1434 }
1435
1436 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1437 if (res != 0) /* check result */
1438 {
1439 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1440
1441 return 1; /* return error */
1442 }
1443 *level = (bmp388_interrupt_active_level_t)((prev >> 1) & 0x01); /* get config */
1444
1445 return 0; /* success return 0 */
1446}
1447
1460{
1461 uint8_t res;
1462 uint8_t prev;
1463
1464 if (handle == NULL) /* check handle */
1465 {
1466 return 2; /* return error */
1467 }
1468 if (handle->inited != 1) /* check handle initialization */
1469 {
1470 return 3; /* return error */
1471 }
1472
1473 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1474 if (res != 0) /* check result */
1475 {
1476 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1477
1478 return 1; /* return error */
1479 }
1480 prev &= ~(1 << 2); /* clear config */
1481 prev |= enable << 2; /* set config */
1482 res = a_bmp388_iic_spi_write(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1483 if (res != 0) /* check result */
1484 {
1485 handle->debug_print("bmp388: set int ctrl register failed.\n"); /* set int ctrl register failed */
1486
1487 return 1; /* return error */
1488 }
1489
1490 return 0; /* success return 0 */
1491}
1492
1505{
1506 uint8_t res;
1507 uint8_t prev;
1508
1509 if (handle == NULL) /* check handle */
1510 {
1511 return 2; /* return error */
1512 }
1513 if (handle->inited != 1) /* check handle initialization */
1514 {
1515 return 3; /* return error */
1516 }
1517
1518 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1519 if (res != 0) /* check result */
1520 {
1521 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1522
1523 return 1; /* return error */
1524 }
1525 *enable = (bmp388_bool_t)((prev >> 2) & 0x01); /* get config */
1526
1527 return 0; /* success return 0 */
1528}
1529
1542{
1543 uint8_t res;
1544 uint8_t prev;
1545
1546 if (handle == NULL) /* check handle */
1547 {
1548 return 2; /* return error */
1549 }
1550 if (handle->inited != 1) /* check handle initialization */
1551 {
1552 return 3; /* return error */
1553 }
1554
1555 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1556 if (res != 0) /* check result */
1557 {
1558 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1559
1560 return 1; /* return error */
1561 }
1562 prev &= ~(1 << 3); /* clear config */
1563 prev |= enable << 3; /* set config */
1564 res = a_bmp388_iic_spi_write(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1565 if (res != 0) /* check result */
1566 {
1567 handle->debug_print("bmp388: set int ctrl register failed.\n"); /* set int ctrl register failed */
1568
1569 return 1; /* return error */
1570 }
1571
1572 return 0; /* success return 0 */
1573}
1574
1587{
1588 uint8_t res;
1589 uint8_t prev;
1590
1591 if (handle == NULL) /* check handle */
1592 {
1593 return 2; /* return error */
1594 }
1595 if (handle->inited != 1) /* check handle initialization */
1596 {
1597 return 3; /* return error */
1598 }
1599
1600 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1601 if (res != 0) /* check result */
1602 {
1603 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1604
1605 return 1; /* return error */
1606 }
1607 *enable = (bmp388_bool_t)((prev >> 3) & 0x01); /* get config */
1608
1609 return 0; /* success return 0 */
1610}
1611
1624{
1625 uint8_t res;
1626 uint8_t prev;
1627
1628 if (handle == NULL) /* check handle */
1629 {
1630 return 2; /* return error */
1631 }
1632 if (handle->inited != 1) /* check handle initialization */
1633 {
1634 return 3; /* return error */
1635 }
1636
1637 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1638 if (res != 0) /* check result */
1639 {
1640 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1641
1642 return 1; /* return error */
1643 }
1644 prev &= ~(1 << 4); /* clear config */
1645 prev |= enable << 4; /* set config */
1646 res = a_bmp388_iic_spi_write(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1647 if (res != 0) /* check result */
1648 {
1649 handle->debug_print("bmp388: set int ctrl register failed.\n"); /* set int ctrl register failed */
1650
1651 return 1; /* return error */
1652 }
1653
1654 return 0; /* success return 0 */
1655}
1656
1669{
1670 uint8_t res;
1671 uint8_t prev;
1672
1673 if (handle == NULL) /* check handle */
1674 {
1675 return 2; /* return error */
1676 }
1677 if (handle->inited != 1) /* check handle initialization */
1678 {
1679 return 3; /* return error */
1680 }
1681
1682 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1683 if (res != 0) /* check result */
1684 {
1685 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1686
1687 return 1; /* return error */
1688 }
1689 *enable = (bmp388_bool_t)((prev >> 4) & 0x01); /* get config */
1690
1691 return 0; /* success return 0 */
1692}
1693
1706{
1707 uint8_t res;
1708 uint8_t prev;
1709
1710 if (handle == NULL) /* check handle */
1711 {
1712 return 2; /* return error */
1713 }
1714 if (handle->inited != 1) /* check handle initialization */
1715 {
1716 return 3; /* return error */
1717 }
1718
1719 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1720 if (res != 0) /* check result */
1721 {
1722 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1723
1724 return 1; /* return error */
1725 }
1726 prev &= ~(1 << 6); /* clear config */
1727 prev |= enable << 6; /* set config */
1728 res = a_bmp388_iic_spi_write(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1729 if (res != 0) /* check result */
1730 {
1731 handle->debug_print("bmp388: set int ctrl register failed.\n"); /* set int ctrl register failed */
1732
1733 return 1; /* return error */
1734 }
1735
1736 return 0; /* success return 0 */
1737}
1738
1751{
1752 uint8_t res;
1753 uint8_t prev;
1754
1755 if (handle == NULL) /* check handle */
1756 {
1757 return 2; /* return error */
1758 }
1759 if (handle->inited != 1) /* check handle initialization */
1760 {
1761 return 3; /* return error */
1762 }
1763
1764 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1765 if (res != 0) /* check result */
1766 {
1767 handle->debug_print("bmp388: get int ctrl register failed.\n"); /* get int ctrl register failed */
1768
1769 return 1; /* return error */
1770 }
1771 *enable = (bmp388_bool_t)((prev >> 6) & 0x01); /* get config */
1772
1773 return 0; /* success return 0 */
1774}
1775
1788{
1789 uint8_t res;
1790 uint8_t prev;
1791
1792 if (handle == NULL) /* check handle */
1793 {
1794 return 2; /* return error */
1795 }
1796 if (handle->inited != 1) /* check handle initialization */
1797 {
1798 return 3; /* return error */
1799 }
1800
1801 res = a_bmp388_iic_spi_read(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1802 if (res != 0) /* check result */
1803 {
1804 handle->debug_print("bmp388: get if conf register failed.\n"); /* get if conf register failed */
1805
1806 return 1; /* return error */
1807 }
1808 prev &= ~(1 << 0); /* clear config */
1809 prev |= wire << 0; /* set config */
1810 res = a_bmp388_iic_spi_write(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1811 if (res != 0) /* check result */
1812 {
1813 handle->debug_print("bmp388: set if conf register failed.\n"); /* set if conf register failed */
1814
1815 return 1; /* return error */
1816 }
1817
1818 return 0; /* success return 0 */
1819}
1820
1833{
1834 uint8_t res;
1835 uint8_t prev;
1836
1837 if (handle == NULL) /* check handle */
1838 {
1839 return 2; /* return error */
1840 }
1841 if (handle->inited != 1) /* check handle initialization */
1842 {
1843 return 3; /* return error */
1844 }
1845
1846 res = a_bmp388_iic_spi_read(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1847 if (res != 0) /* check result */
1848 {
1849 handle->debug_print("bmp388: get if conf register failed.\n"); /* get if conf register failed */
1850
1851 return 1; /* return error */
1852 }
1853 *wire = (bmp388_spi_wire_t)(prev & 0x01); /* get config */
1854
1855 return 0; /* success return 0 */
1856}
1857
1870{
1871 uint8_t res;
1872 uint8_t prev;
1873
1874 if (handle == NULL) /* check handle */
1875 {
1876 return 2; /* return error */
1877 }
1878 if (handle->inited != 1) /* check handle initialization */
1879 {
1880 return 3; /* return error */
1881 }
1882
1883 res = a_bmp388_iic_spi_read(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1884 if (res != 0) /* check result */
1885 {
1886 handle->debug_print("bmp388: get if conf register failed.\n"); /* get if conf register failed */
1887
1888 return 1; /* return error */
1889 }
1890 prev &= ~(1 << 1); /* clear config */
1891 prev |= enable << 1; /* set config */
1892 res = a_bmp388_iic_spi_write(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1893 if (res != 0) /* check result */
1894 {
1895 handle->debug_print("bmp388: set if conf register failed.\n"); /* set if conf register failed */
1896
1897 return 1; /* return error */
1898 }
1899
1900 return 0; /* success return 0 */
1901}
1902
1915{
1916 uint8_t res;
1917 uint8_t prev;
1918
1919 if (handle == NULL) /* check handle */
1920 {
1921 return 2; /* return error */
1922 }
1923 if (handle->inited != 1) /* check handle initialization */
1924 {
1925 return 3; /* return error */
1926 }
1927
1928 res = a_bmp388_iic_spi_read(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1929 if (res != 0) /* check result */
1930 {
1931 handle->debug_print("bmp388: get if conf register failed.\n"); /* get if conf register failed */
1932
1933 return 1; /* return error */
1934 }
1935 *enable = (bmp388_bool_t)((prev >> 1) & 0x01); /* get config */
1936
1937 return 0; /* success return 0 */
1938}
1939
1952{
1953 uint8_t res;
1954 uint8_t prev;
1955
1956 if (handle == NULL) /* check handle */
1957 {
1958 return 2; /* return error */
1959 }
1960 if (handle->inited != 1) /* check handle initialization */
1961 {
1962 return 3; /* return error */
1963 }
1964
1965 res = a_bmp388_iic_spi_read(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1966 if (res != 0) /* check result */
1967 {
1968 handle->debug_print("bmp388: get if conf register failed.\n"); /* get if conf register failed */
1969
1970 return 1; /* return error */
1971 }
1972 prev &= ~(1 << 2); /* clear config */
1973 prev |= period << 2; /* set config */
1974 res = a_bmp388_iic_spi_write(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1975 if (res != 0) /* check result */
1976 {
1977 handle->debug_print("bmp388: set if conf register failed.\n"); /* set if conf register failed */
1978
1979 return 1; /* return error */
1980 }
1981
1982 return 0; /* success return 0 */
1983}
1984
1997{
1998 uint8_t res;
1999 uint8_t prev;
2000
2001 if (handle == NULL) /* check handle */
2002 {
2003 return 2; /* return error */
2004 }
2005 if (handle->inited != 1) /* check handle initialization */
2006 {
2007 return 3; /* return error */
2008 }
2009
2010 res = a_bmp388_iic_spi_read(handle, BMP388_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
2011 if (res != 0) /* check result */
2012 {
2013 handle->debug_print("bmp388: get if conf register failed.\n"); /* get if conf register failed */
2014
2015 return 1; /* return error */
2016 }
2017 *period = (bmp388_iic_watchdog_period_t)((prev >> 2) & 0x01); /* get config */
2018
2019 return 0; /* success return 0 */
2020}
2021
2034{
2035 uint8_t res;
2036 uint8_t prev;
2037
2038 if (handle == NULL) /* check handle */
2039 {
2040 return 2; /* return error */
2041 }
2042 if (handle->inited != 1) /* check handle initialization */
2043 {
2044 return 3; /* return error */
2045 }
2046
2047 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2048 if (res != 0) /* check result */
2049 {
2050 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2051
2052 return 1; /* return error */
2053 }
2054 prev &= ~(1 << 0); /* clear config */
2055 prev |= enable << 0; /* set config */
2056 res = a_bmp388_iic_spi_write(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2057 if (res != 0) /* check result */
2058 {
2059 handle->debug_print("bmp388: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2060
2061 return 1; /* return error */
2062 }
2063
2064 return 0; /* success return 0 */
2065}
2066
2079{
2080 uint8_t res;
2081 uint8_t prev;
2082
2083 if (handle == NULL) /* check handle */
2084 {
2085 return 2; /* return error */
2086 }
2087 if (handle->inited != 1) /* check handle initialization */
2088 {
2089 return 3; /* return error */
2090 }
2091
2092 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2093 if (res != 0) /* check result */
2094 {
2095 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2096
2097 return 1; /* return error */
2098 }
2099 *enable = (bmp388_bool_t)((prev >> 0) & 0x01); /* get config */
2100
2101 return 0; /* success return 0 */
2102}
2103
2116{
2117 uint8_t res;
2118 uint8_t prev;
2119
2120 if (handle == NULL) /* check handle */
2121 {
2122 return 2; /* return error */
2123 }
2124 if (handle->inited != 1) /* check handle initialization */
2125 {
2126 return 3; /* return error */
2127 }
2128
2129 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2130 if (res != 0) /* check result */
2131 {
2132 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2133
2134 return 1; /* return error */
2135 }
2136 prev &= ~(1 << 1); /* clear config */
2137 prev |= enable << 1; /* set config */
2138 res = a_bmp388_iic_spi_write(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2139 if (res != 0) /* check result */
2140 {
2141 handle->debug_print("bmp388: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2142
2143 return 1; /* return error */
2144 }
2145
2146 return 0; /* success return 0 */
2147}
2148
2161{
2162 uint8_t res;
2163 uint8_t prev;
2164
2165 if (handle == NULL) /* check handle */
2166 {
2167 return 2; /* return error */
2168 }
2169 if (handle->inited != 1) /* check handle initialization */
2170 {
2171 return 3; /* return error */
2172 }
2173
2174 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2175 if (res != 0) /* check result */
2176 {
2177 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2178
2179 return 1; /* return error */
2180 }
2181 *enable = (bmp388_bool_t)((prev >> 1) & 0x01); /* get config */
2182
2183 return 0; /* success return 0 */
2184}
2185
2198{
2199 uint8_t res;
2200 uint8_t prev;
2201
2202 if (handle == NULL) /* check handle */
2203 {
2204 return 2; /* return error */
2205 }
2206 if (handle->inited != 1) /* check handle initialization */
2207 {
2208 return 3; /* return error */
2209 }
2210
2211 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2212 if (res != 0) /* check result */
2213 {
2214 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2215
2216 return 1; /* return error */
2217 }
2218 prev &= ~(3 << 4); /* clear config */
2219 prev |= mode << 4; /* set config */
2220 res = a_bmp388_iic_spi_write(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2221 if (res != 0) /* check result */
2222 {
2223 handle->debug_print("bmp388: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2224
2225 return 1; /* return error */
2226 }
2227
2228 return 0; /* success return 0 */
2229}
2230
2243{
2244 uint8_t res;
2245 uint8_t prev;
2246
2247 if (handle == NULL) /* check handle */
2248 {
2249 return 2; /* return error */
2250 }
2251 if (handle->inited != 1) /* check handle initialization */
2252 {
2253 return 3; /* return error */
2254 }
2255
2256 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2257 if (res != 0) /* check result */
2258 {
2259 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2260
2261 return 1; /* return error */
2262 }
2263 *mode = (bmp388_mode_t)((prev >> 4) & 0x03); /* get config */
2264
2265 return 0; /* success return 0 */
2266}
2267
2280{
2281 uint8_t res;
2282 uint8_t prev;
2283
2284 if (handle == NULL) /* check handle */
2285 {
2286 return 2; /* return error */
2287 }
2288 if (handle->inited != 1) /* check handle initialization */
2289 {
2290 return 3; /* return error */
2291 }
2292
2293 res = a_bmp388_iic_spi_read(handle, BMP388_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2294 if (res != 0) /* check result */
2295 {
2296 handle->debug_print("bmp388: get osr register failed.\n"); /* get osr register failed */
2297
2298 return 1; /* return error */
2299 }
2300 prev &= ~(7 << 0); /* clear config */
2301 prev |= oversampling << 0; /* set config */
2302 res = a_bmp388_iic_spi_write(handle, BMP388_REG_OSR, (uint8_t *)&prev, 1); /* write config */
2303 if (res != 0) /* check result */
2304 {
2305 handle->debug_print("bmp388: set osr register failed.\n"); /* set osr register failed */
2306
2307 return 1; /* return error */
2308 }
2309
2310 return 0; /* success return 0 */
2311}
2312
2325{
2326 uint8_t res;
2327 uint8_t prev;
2328
2329 if (handle == NULL) /* check handle */
2330 {
2331 return 2; /* return error */
2332 }
2333 if (handle->inited != 1) /* check handle initialization */
2334 {
2335 return 3; /* return error */
2336 }
2337
2338 res = a_bmp388_iic_spi_read(handle, BMP388_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2339 if (res != 0) /* check result */
2340 {
2341 handle->debug_print("bmp388: get osr register failed.\n"); /* get osr register failed */
2342
2343 return 1; /* return error */
2344 }
2345 *oversampling = (bmp388_oversampling_t)((prev >> 0) & 0x07); /* get config */
2346
2347 return 0; /* success return 0 */
2348}
2349
2362{
2363 uint8_t res;
2364 uint8_t prev;
2365
2366 if (handle == NULL) /* check handle */
2367 {
2368 return 2; /* return error */
2369 }
2370 if (handle->inited != 1) /* check handle initialization */
2371 {
2372 return 3; /* return error */
2373 }
2374
2375 res = a_bmp388_iic_spi_read(handle, BMP388_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2376 if (res != 0) /* check result */
2377 {
2378 handle->debug_print("bmp388: get osr register failed.\n"); /* get osr register failed */
2379
2380 return 1; /* return error */
2381 }
2382 prev &= ~(7 << 3); /* clear config */
2383 prev |= oversampling << 3; /* set config */
2384 res = a_bmp388_iic_spi_write(handle, BMP388_REG_OSR, (uint8_t *)&prev, 1); /* write config */
2385 if (res != 0) /* check result */
2386 {
2387 handle->debug_print("bmp388: set osr register failed.\n"); /* set osr register failed */
2388
2389 return 1; /* return error */
2390 }
2391
2392 return 0; /* success return 0 */
2393}
2394
2407{
2408 uint8_t res;
2409 uint8_t prev;
2410
2411 if (handle == NULL) /* check handle */
2412 {
2413 return 2; /* return error */
2414 }
2415 if (handle->inited != 1) /* check handle initialization */
2416 {
2417 return 3; /* return error */
2418 }
2419
2420 res = a_bmp388_iic_spi_read(handle, BMP388_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2421 if (res != 0) /* check result */
2422 {
2423 handle->debug_print("bmp388: get osr register failed.\n"); /* get osr register failed */
2424
2425 return 1; /* return error */
2426 }
2427 *oversampling = (bmp388_oversampling_t)((prev >> 3) & 0x07); /* get config */
2428
2429 return 0; /* success return 0 */
2430}
2431
2444{
2445 uint8_t res;
2446 uint8_t prev;
2447
2448 if (handle == NULL) /* check handle */
2449 {
2450 return 2; /* return error */
2451 }
2452 if (handle->inited != 1) /* check handle initialization */
2453 {
2454 return 3; /* return error */
2455 }
2456
2457 res = a_bmp388_iic_spi_read(handle, BMP388_REG_ODR, (uint8_t *)&prev, 1); /* read config */
2458 if (res != 0) /* check result */
2459 {
2460 handle->debug_print("bmp388: get odr register failed.\n"); /* get odr register failed */
2461
2462 return 1; /* return error */
2463 }
2464
2465 prev &= ~(31 << 0); /* clear config */
2466 prev |= odr << 0; /* set config */
2467 res = a_bmp388_iic_spi_write(handle, BMP388_REG_ODR, (uint8_t *)&prev, 1); /* write config */
2468 if (res != 0) /* check result */
2469 {
2470 handle->debug_print("bmp388: set odr register failed.\n"); /* set odr register failed */
2471
2472 return 1; /* return error */
2473 }
2474
2475 return 0; /* success return 0 */
2476}
2477
2490{
2491 uint8_t res;
2492 uint8_t prev;
2493
2494 if (handle == NULL) /* check handle */
2495 {
2496 return 2; /* return error */
2497 }
2498 if (handle->inited != 1) /* check handle initialization */
2499 {
2500 return 3; /* return error */
2501 }
2502
2503 res = a_bmp388_iic_spi_read(handle, BMP388_REG_ODR, (uint8_t *)&prev, 1); /* read config */
2504 if (res != 0) /* check result */
2505 {
2506 handle->debug_print("bmp388: get odr register failed.\n"); /* get odr register failed */
2507
2508 return 1; /* return error */
2509 }
2510 *odr = (bmp388_odr_t)((prev >> 0) & 31); /* get config */
2511
2512 return 0; /* success return 0 */
2513}
2514
2527{
2528 uint8_t res;
2529 uint8_t prev;
2530
2531 if (handle == NULL) /* check handle */
2532 {
2533 return 2; /* return error */
2534 }
2535 if (handle->inited != 1) /* check handle initialization */
2536 {
2537 return 3; /* return error */
2538 }
2539
2540 res = a_bmp388_iic_spi_read(handle, BMP388_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
2541 if (res != 0) /* check result */
2542 {
2543 handle->debug_print("bmp388: get config register failed.\n"); /* get config register failed */
2544
2545 return 1; /* return error */
2546 }
2547
2548 prev &= ~(0x7 << 1); /* clear config */
2549 prev |= coefficient << 1; /* set config */
2550 res = a_bmp388_iic_spi_write(handle, BMP388_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
2551 if (res != 0) /* check result */
2552 {
2553 handle->debug_print("bmp388: set config register failed.\n"); /* set config register failed */
2554
2555 return 1; /* return error */
2556 }
2557
2558 return 0; /* success return 0 */
2559}
2560
2573{
2574 uint8_t res;
2575 uint8_t prev;
2576
2577 if (handle == NULL) /* check handle */
2578 {
2579 return 2; /* return error */
2580 }
2581 if (handle->inited != 1) /* check handle initialization */
2582 {
2583 return 3; /* return error */
2584 }
2585
2586 res = a_bmp388_iic_spi_read(handle, BMP388_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
2587 if (res != 0) /* check result */
2588 {
2589 handle->debug_print("bmp388: get config register failed.\n"); /* return error */
2590
2591 return 1; /* return error */
2592 }
2593 *coefficient = (bmp388_filter_coefficient_t)((prev >> 1) & 0x07); /* get coefficient */
2594
2595 return 0; /* success return 0 */
2596}
2597
2609{
2610 uint8_t res;
2611 uint8_t prev;
2612
2613 if (handle == NULL) /* check handle */
2614 {
2615 return 2; /* return error */
2616 }
2617 if (handle->inited != 1) /* check handle initialization */
2618 {
2619 return 3; /* return error */
2620 }
2621
2622 prev = 0xB0; /* command */
2623 res = a_bmp388_iic_spi_write(handle, BMP388_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2624 if (res != 0) /* check result */
2625 {
2626 handle->debug_print("bmp388: set cmd register failed.\n"); /* set cmd register failed */
2627
2628 return 1; /* return error */
2629 }
2630
2631 return 0; /* success return 0 */
2632}
2633
2645{
2646 uint8_t res;
2647 uint8_t prev;
2648
2649 if (handle == NULL) /* check handle */
2650 {
2651 return 2; /* return error */
2652 }
2653 if (handle->inited != 1) /* check handle initialization */
2654 {
2655 return 3; /* return error */
2656 }
2657
2658 prev = 0xB6; /* command */
2659 res = a_bmp388_iic_spi_write(handle, BMP388_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2660 if (res != 0) /* check result */
2661 {
2662 handle->debug_print("bmp388: set cmd register failed.\n"); /* set cmd register failed */
2663
2664 return 1; /* return error */
2665 }
2666
2667 return 0; /* success return 0 */
2668}
2669
2681{
2682 uint8_t res;
2683 uint8_t prev;
2684
2685 if (handle == NULL) /* check handle */
2686 {
2687 return 2; /* return error */
2688 }
2689 if (handle->inited != 1) /* check handle initialization */
2690 {
2691 return 3; /* return error */
2692 }
2693
2694 prev = 0x34; /* command */
2695 res = a_bmp388_iic_spi_write(handle, BMP388_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2696 if (res != 0) /* check result */
2697 {
2698 handle->debug_print("bmp388: set cmd register failed.\n"); /* set cmd register failed */
2699
2700 return 1; /* return error */
2701 }
2702
2703 return 0; /* success return 0 */
2704}
2705
2716static uint8_t a_bmp388_close(bmp388_handle_t *handle)
2717{
2718 if (handle->iic_spi == BMP388_INTERFACE_IIC) /* if iic interface */
2719 {
2720 if (handle->iic_deinit() != 0) /* close iic */
2721 {
2722 handle->debug_print("bmp388: iic deinit failed.\n"); /* iic deinit failed */
2723
2724 return 1; /* return error */
2725 }
2726 else
2727 {
2728 return 0; /* success return 0 */
2729 }
2730 }
2731 else
2732 {
2733 if (handle->spi_deinit() != 0) /* close spi */
2734 {
2735 handle->debug_print("bmp388: spi deinit failed.\n"); /* spi deinit failed */
2736
2737 return 1; /* return error */
2738 }
2739 else
2740 {
2741 return 0; /* success return 0 */
2742 }
2743 }
2744}
2745
2760{
2761 uint8_t id;
2762 uint8_t reg;
2763
2764 if (handle == NULL) /* check handle */
2765 {
2766 return 2; /* return error */
2767 }
2768 if (handle->debug_print == NULL) /* check debug_print */
2769 {
2770 return 3; /* return error */
2771 }
2772 if (handle->iic_init == NULL) /* check iic_init */
2773 {
2774 handle->debug_print("bmp388: iic_init is null.\n"); /* iic_init is null */
2775
2776 return 3; /* return error */
2777 }
2778 if (handle->iic_deinit == NULL) /* check iic_init */
2779 {
2780 handle->debug_print("bmp388: iic_deinit is null.\n"); /* iic_deinit is null */
2781
2782 return 3; /* return error */
2783 }
2784 if (handle->iic_read == NULL) /* check iic_read */
2785 {
2786 handle->debug_print("bmp388: iic_read is null.\n"); /* iic_read is null */
2787
2788 return 3; /* return error */
2789 }
2790 if (handle->iic_write == NULL) /* check iic_write */
2791 {
2792 handle->debug_print("bmp388: iic_write is null.\n"); /* iic_write is null */
2793
2794 return 3; /* return error */
2795 }
2796 if (handle->spi_init == NULL) /* check spi_init */
2797 {
2798 handle->debug_print("bmp388: spi_init is null.\n"); /* spi_init is null */
2799
2800 return 3; /* return error */
2801 }
2802 if (handle->spi_deinit == NULL) /* check spi_deinit */
2803 {
2804 handle->debug_print("bmp388: spi_deinit is null.\n"); /* spi_deinit is null */
2805
2806 return 3; /* return error */
2807 }
2808 if (handle->spi_read == NULL) /* check spi_read */
2809 {
2810 handle->debug_print("bmp388: spi_read is null.\n"); /* spi_read is null */
2811
2812 return 3; /* return error */
2813 }
2814 if (handle->spi_write == NULL) /* check spi_write */
2815 {
2816 handle->debug_print("bmp388: spi_write is null.\n"); /* spi_write is null */
2817
2818 return 3; /* return error */
2819 }
2820 if (handle->delay_ms == NULL) /* check delay_ms */
2821 {
2822 handle->debug_print("bmp388: delay_ms is null.\n"); /* delay_ms is null */
2823
2824 return 3; /* return error */
2825 }
2826
2827 if (handle->iic_spi == BMP388_INTERFACE_IIC) /* if iic interface */
2828 {
2829 if (handle->iic_init() != 0) /* initialize iic bus */
2830 {
2831 handle->debug_print("bmp388: iic init failed.\n"); /* iic init failed */
2832
2833 return 1; /* return error */
2834 }
2835 }
2836 else
2837 {
2838 if (handle->spi_init() != 0) /* initialize spi bus */
2839 {
2840 handle->debug_print("bmp388: spi init failed.\n"); /* spi init failed */
2841
2842 return 1; /* return error */
2843 }
2844 }
2845 if (a_bmp388_iic_spi_read(handle, BMP388_REG_CHIP_ID, (uint8_t *)&id, 1) != 0) /* read chip id */
2846 {
2847 handle->debug_print("bmp388: read chip id failed.\n"); /* read chip id failed */
2848 (void)a_bmp388_close(handle); /* close bmp388 */
2849
2850 return 4; /* return error */
2851 }
2852 if (id != 0x50) /* check chip id */
2853 {
2854 handle->debug_print("bmp388: id is invalid.\n"); /* id is invalid */
2855 (void)a_bmp388_close(handle); /* close bmp388 */
2856
2857 return 4;
2858 } /* return error */
2859 reg = 0xB6; /* set command */
2860 if (a_bmp388_iic_spi_write(handle, BMP388_REG_CMD, (uint8_t *)&reg, 1) != 0) /* write command */
2861 {
2862 handle->debug_print("bmp388: soft rest failed.\n"); /* soft rest failed */
2863 (void)a_bmp388_close(handle); /* close bmp388 */
2864
2865 return 5; /* return error */
2866 }
2867 handle->delay_ms(10); /* delay 10 ms */
2868 if (a_bmp388_iic_spi_read(handle, BMP388_REG_ERR_REG, (uint8_t *)&reg, 1) != 0) /* read reg */
2869 {
2870 handle->debug_print("bmp388: get err reg failed.\n"); /* return error */
2871 (void)a_bmp388_close(handle); /* close bmp388 */
2872
2873 return 5; /* return error */
2874 }
2875 if ((reg & 0x07) != 0) /* check running status */
2876 {
2877 handle->debug_print("bmp388: find running error.\n"); /* find running error */
2878 (void)a_bmp388_close(handle); /* close bmp388 */
2879
2880 return 5; /* return error */
2881 }
2882 if (a_bmp388_get_calibration_data(handle) != 0) /* get calibration data */
2883 {
2884 handle->debug_print("bmp388: get calibration data error.\n"); /* get calibration data error */
2885 (void)a_bmp388_close(handle); /* close bmp388 */
2886
2887 return 6; /* return error */
2888 }
2889 handle->inited = 1; /* flag finish initialization */
2890
2891 return 0; /* success return 0 */
2892}
2893
2906{
2907 uint8_t res;
2908 uint8_t prev;
2909
2910 if (handle == NULL) /* check handle */
2911 {
2912 return 2; /* return error */
2913 }
2914 if (handle->inited != 1) /* check handle initialization */
2915 {
2916 return 3; /* return error */
2917 }
2918
2919 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2920 if (res != 0) /* check result */
2921 {
2922 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2923
2924 return 4; /* return error */
2925 }
2926 prev &= ~(3 << 0); /* clear config */
2927 prev &= ~(3 << 4); /* set config */
2928 res = a_bmp388_iic_spi_write(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2929 if (res != 0) /* check result */
2930 {
2931 handle->debug_print("bmp388: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2932
2933 return 4; /* return error */
2934 }
2935 if (a_bmp388_close(handle) != 0) /* close bmp388 */
2936 {
2937 return 1; /* return error */
2938 }
2939 else
2940 {
2941 handle->inited = 0; /* flag close */
2942
2943 return 0; /* success return 0 */
2944 }
2945}
2946
2959uint8_t bmp388_read_temperature(bmp388_handle_t *handle, uint32_t *raw, float *c)
2960{
2961 uint8_t res;
2962 uint8_t prev;
2963 uint8_t buf[3];
2964
2965 if (handle == NULL) /* check handle */
2966 {
2967 return 2; /* return error */
2968 }
2969 if (handle->inited != 1) /* check handle initialization */
2970 {
2971 return 3; /* return error */
2972 }
2973
2974 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
2975 if (res != 0) /* check result */
2976 {
2977 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
2978
2979 return 1; /* return error */
2980 }
2981 if ((prev & 0x01) != 0) /* check mode */
2982 {
2983 handle->debug_print("bmp388: fifo mode can't use this function.\n"); /* fifo mode can't use this function */
2984
2985 return 1; /* return error */
2986 }
2987 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read pwr ctrl */
2988 if (res != 0) /* check result */
2989 {
2990 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2991
2992 return 1; /* return error */
2993 }
2994 if (((prev >> 4) & 0x03) == 0x03) /* normal mode */
2995 {
2996 res = a_bmp388_iic_spi_read(handle, BMP388_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
2997 if (res != 0) /* check result */
2998 {
2999 handle->debug_print("bmp388: get status register failed.\n"); /* get status register failed */
3000
3001 return 1; /* return error */
3002 }
3003 if ((prev & (1 << 6)) != 0) /* data is ready */
3004 {
3005 int64_t output;
3006
3007 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3008 if (res != 0) /* check result */
3009 {
3010 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3011
3012 return 1; /* return error */
3013 }
3014 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3015 output = a_bmp388_compensate_temperature(handle, *raw); /* compensate temperature */
3016 *c = (float)((double)output / 100.0); /* get converted temperature */
3017
3018 return 0; /* success return 0 */
3019
3020 }
3021 else
3022 {
3023 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3024
3025 return 1; /* return error */
3026 }
3027 }
3028 else if (((prev >> 4) & 0x03) == 0x00) /* force mode */
3029 {
3030 uint16_t cnt = 5000;
3031
3032 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3033 if (res != 0) /* check result */
3034 {
3035 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3036
3037 return 1; /* return error */
3038 }
3039 prev &= ~(0x03 << 4); /* clear 4-5 bits */
3040 prev |= 0x01 << 4; /* set bit 4 */
3041 res = a_bmp388_iic_spi_write(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3042 if (res != 0) /* check result */
3043 {
3044 handle->debug_print("bmp388: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
3045
3046 return 1; /* return error */
3047 }
3048
3049 while (1) /* loop */
3050 {
3051 res = a_bmp388_iic_spi_read(handle, BMP388_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
3052 if (res != 0) /* check result */
3053 {
3054 handle->debug_print("bmp388: get status register failed.\n"); /* get status register failed */
3055
3056 return 1; /* return error */
3057 }
3058 if ((prev & (1 << 6)) != 0) /* data is ready */
3059 {
3060 int64_t output;
3061
3062 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3063 if (res != 0) /* check result */
3064 {
3065 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3066
3067 return 1; /* return error */
3068 }
3069 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3070 output = a_bmp388_compensate_temperature(handle, *raw); /* compensate temperature */
3071 *c = (float)((double)output / 100.0); /* get converted temperature */
3072
3073 return 0; /* success return 0 */
3074
3075 }
3076 else
3077 {
3078 if (cnt != 0) /* check cnt */
3079 {
3080 cnt--; /* cnt-- */
3081 handle->delay_ms(1); /* delay 1 ms */
3082
3083 continue; /* continue */
3084 }
3085 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3086
3087 return 1; /* return error */
3088 }
3089 }
3090 }
3091 else
3092 {
3093 handle->debug_print("bmp388: mode is invalid.\n"); /* mode is invalid */
3094
3095 return 1; /* return error */
3096 }
3097}
3098
3111uint8_t bmp388_read_pressure(bmp388_handle_t *handle, uint32_t *raw, float *pa)
3112{
3113 uint8_t res;
3114 uint8_t prev;
3115 uint8_t buf[3];
3116 uint32_t temperature_raw;
3117
3118 if (handle == NULL) /* check handle */
3119 {
3120 return 2; /* return error */
3121 }
3122 if (handle->inited != 1) /* check handle initialization */
3123 {
3124 return 3; /* return error */
3125 }
3126
3127 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3128 if (res != 0) /* check result */
3129 {
3130 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
3131
3132 return 1; /* return error */
3133 }
3134 if ((prev & 0x01) != 0) /* check mode */
3135 {
3136 handle->debug_print("bmp388: fifo mode can't use this function.\n"); /* fifo mode can't use this function */
3137
3138 return 1; /* return error */
3139 }
3140 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3141 if (res != 0) /* check result */
3142 {
3143 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3144
3145 return 1; /* return error */
3146 }
3147 if (((prev >> 4) & 0x03) == 0x03) /* normal mode */
3148 {
3149 res = a_bmp388_iic_spi_read(handle, BMP388_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
3150 if (res != 0) /* check result */
3151 {
3152 handle->debug_print("bmp388: get status register failed.\n"); /* get status register failed */
3153
3154 return 1; /* return error */
3155 }
3156 if ((prev & (1 << 6)) != 0) /* data is ready */
3157 {
3158 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_3, (uint8_t *)buf, 3); /* read config */
3159 if (res != 0) /* check result */
3160 {
3161 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3162
3163 return 1; /* return error */
3164 }
3165 temperature_raw= (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3166 (void)a_bmp388_compensate_temperature(handle, temperature_raw); /* compensate temperature */
3167 }
3168 else
3169 {
3170 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3171
3172 return 1; /* return error */
3173 }
3174 if ((prev & (1 << 5)) != 0) /* data is ready */
3175 {
3176 int64_t output;
3177
3178 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_0, (uint8_t *)buf, 3); /* read config */
3179 if (res != 0) /* check result */
3180 {
3181 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3182
3183 return 1; /* return error */
3184 }
3185 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3186 output = a_bmp388_compensate_pressure(handle, *raw); /* compensate pressure */
3187 *pa = (float)((double)output / 100.0); /* get converted pressure */
3188
3189 return 0; /* success return 0 */
3190 }
3191 else
3192 {
3193 handle->debug_print("bmp388: pressure data is not ready.\n"); /* pressure data is not ready */
3194
3195 return 1; /* return error */
3196 }
3197 }
3198 else if (((prev >> 4) & 0x03) == 0x00) /* force mode */
3199 {
3200 uint16_t cnt = 5000;
3201
3202 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3203 if (res != 0) /* check result */
3204 {
3205 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3206
3207 return 1; /* return error */
3208 }
3209 prev &= ~(0x03 << 4); /* clear 4-5 bits */
3210 prev |= 0x01 << 4; /* set 4 bit */
3211 res = a_bmp388_iic_spi_write(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3212 if (res != 0) /* check result */
3213 {
3214 handle->debug_print("bmp388: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
3215
3216 return 1; /* return error */
3217 }
3218
3219 while (1) /* loop */
3220 {
3221 res = a_bmp388_iic_spi_read(handle, BMP388_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3222 if (res != 0) /* check result */
3223 {
3224 handle->debug_print("bmp388: get status register failed.\n"); /* get status register failed */
3225
3226 return 1; /* return error */
3227 }
3228 if ((prev & (1 << 6)) != 0) /* data is ready */
3229 {
3230 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3231 if (res != 0) /* check result */
3232 {
3233 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3234
3235 return 1; /* return error */
3236 }
3237 temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3238 (void)a_bmp388_compensate_temperature(handle, temperature_raw); /* compensate temperature */
3239
3240 goto press; /* goto press */
3241 }
3242 else
3243 {
3244 if (cnt != 0) /* check cnt */
3245 {
3246 cnt--; /* cnt-- */
3247 handle->delay_ms(1); /* delay 1 ms */
3248
3249 continue; /* continue */
3250 }
3251 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3252
3253 return 1; /* return error */
3254 }
3255
3256 press:
3257
3258 cnt = 5000; /* set cnt 5000 */
3259 if ((prev & (1 << 5)) != 0) /* data is ready */
3260 {
3261 int64_t output;
3262
3263 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_0, (uint8_t *)buf, 3); /* read config */
3264 if (res != 0) /* check result */
3265 {
3266 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3267
3268 return 1; /* return error */
3269 }
3270 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3271 output = a_bmp388_compensate_pressure(handle, *raw); /* compensate pressure */
3272 *pa = (float)((double)output / 100.0); /* get converted pressure */
3273
3274 return 0; /* success return 0 */
3275 }
3276 else
3277 {
3278 if (cnt != 0) /* check cnt */
3279 {
3280 cnt--; /* cnt-- */
3281 handle->delay_ms(1); /* delay 1 ms */
3282
3283 continue; /* continue */
3284 }
3285 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3286
3287 return 1; /* return error */
3288 }
3289 }
3290 }
3291 else
3292 {
3293 handle->debug_print("bmp388: mode is invalid.\n"); /* mode is invalid */
3294
3295 return 1; /* return error */
3296 }
3297}
3298
3313uint8_t bmp388_read_temperature_pressure(bmp388_handle_t *handle, uint32_t *temperature_raw, float *temperature_c,
3314 uint32_t *pressure_raw, float *pressure_pa)
3315{
3316 uint8_t res;
3317 uint8_t prev;
3318 uint8_t buf[3];
3319
3320 if (handle == NULL) /* check handle */
3321 {
3322 return 2; /* return error */
3323 }
3324 if (handle->inited != 1) /* check handle initialization */
3325 {
3326 return 3; /* return error */
3327 }
3328
3329 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3330 if (res != 0) /* check result */
3331 {
3332 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
3333
3334 return 1; /* return error */
3335 }
3336 if ((prev & 0x01) != 0) /* check fifo mode */
3337 {
3338 handle->debug_print("bmp388: fifo mode can't use this function.\n"); /* fifo mode can't use this function */
3339
3340 return 1; /* return error */
3341 }
3342 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3343 if (res != 0) /* check result */
3344 {
3345 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3346
3347 return 1; /* return error */
3348 }
3349 if (((prev >> 4) & 0x03) == 0x03) /* normal mode */
3350 {
3351 res = a_bmp388_iic_spi_read(handle, BMP388_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3352 if (res != 0) /* check result */
3353 {
3354 handle->debug_print("bmp388: get status register failed.\n"); /* get status register failed */
3355
3356 return 1; /* return error */
3357 }
3358 if ((prev & (1 << 6)) != 0) /* data is ready */
3359 {
3360 int64_t output;
3361
3362 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3363 if (res != 0) /* check result */
3364 {
3365 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3366
3367 return 1; /* return error */
3368 }
3369 *temperature_raw= (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3370 output = a_bmp388_compensate_temperature(handle, *temperature_raw); /* compensate temperature */
3371 *temperature_c = (float)((double)output / 100.0); /* get converted temperature */
3372 }
3373 else
3374 {
3375 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3376
3377 return 1; /* return error */
3378 }
3379 if ((prev & (1 << 5)) != 0) /* data is ready */
3380 {
3381 int64_t output;
3382
3383 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_0, (uint8_t *)buf, 3); /* read data */
3384 if (res != 0) /* check result */
3385 {
3386 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3387
3388 return 1; /* return error */
3389 }
3390 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3391 output = a_bmp388_compensate_pressure(handle, *pressure_raw); /* compensate pressure */
3392 *pressure_pa = (float)((double)output / 100.0); /* get converted pressure */
3393
3394 return 0; /* success return 0 */
3395 }
3396 else
3397 {
3398 handle->debug_print("bmp388: pressure data is not ready.\n"); /* pressure data is not ready */
3399
3400 return 1; /* return error */
3401 }
3402 }
3403 else if (((prev >> 4) & 0x03) == 0x00) /* force mode */
3404 {
3405 uint16_t cnt = 5000;
3406
3407 res = a_bmp388_iic_spi_read(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3408 if (res != 0) /* check result */
3409 {
3410 handle->debug_print("bmp388: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3411
3412 return 1; /* return error */
3413 }
3414 prev &= ~(0x03 << 4); /* clear 4-5 bits */
3415 prev |= 0x01 << 4; /* set bit 4 */
3416 res = a_bmp388_iic_spi_write(handle, BMP388_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
3417 if (res != 0) /* check result */
3418 {
3419 handle->debug_print("bmp388: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
3420
3421 return 1; /* return error */
3422 }
3423
3424 while (1) /* loop */
3425 {
3426 res = a_bmp388_iic_spi_read(handle, BMP388_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3427 if (res != 0) /* check result */
3428 {
3429 handle->debug_print("bmp388: get status register failed.\n"); /* get status register failed */
3430
3431 return 1; /* return error */
3432 }
3433 if ((prev & (1 << 6)) != 0) /* data is ready */
3434 {
3435 int64_t output;
3436
3437 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3438 if (res != 0) /* check result */
3439 {
3440 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3441
3442 return 1; /* return error */
3443 }
3444 *temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3445 output = a_bmp388_compensate_temperature(handle, *temperature_raw); /* compensate temperature */
3446 *temperature_c = (float)((double)output / 100.0); /* get converted temperature */
3447
3448 break; /* break */
3449 }
3450 else
3451 {
3452 if (cnt != 0) /* check cnt */
3453 {
3454 cnt--; /* cnt-- */
3455 handle->delay_ms(1); /* delay 1 ms */
3456
3457 continue; /* continue */
3458 }
3459 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3460
3461 return 1; /* return error */
3462 }
3463 }
3464 cnt = 5000; /* set cnt */
3465
3466 while (1) /* loop */
3467 {
3468 if ((prev & (1 << 5)) != 0) /* data is ready */
3469 {
3470 int64_t output;
3471
3472 res = a_bmp388_iic_spi_read(handle, BMP388_REG_DATA_0, (uint8_t *)buf, 3); /* read raw data */
3473 if (res != 0) /* check result */
3474 {
3475 handle->debug_print("bmp388: get data register failed.\n"); /* get data register failed */
3476
3477 return 1; /* return error */
3478 }
3479 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3480 output = a_bmp388_compensate_pressure(handle, *pressure_raw); /* compensate pressure */
3481 *pressure_pa = (float)((double)output / 100.0); /* get converted pressure */
3482
3483 return 0; /* success return 0 */
3484 }
3485 else
3486 {
3487 if (cnt != 0) /* check cnt */
3488 {
3489 cnt--; /* cnt-- */
3490 handle->delay_ms(1); /* delay 1 ms */
3491
3492 continue; /* continue */
3493 }
3494 handle->debug_print("bmp388: temperature data is not ready.\n"); /* temperature data is not ready */
3495
3496 return 1; /* return error */
3497 }
3498 }
3499 }
3500 else
3501 {
3502 handle->debug_print("bmp388: mode is invalid.\n"); /* mode is invalid */
3503
3504 return 1; /* return error */
3505 }
3506}
3507
3519{
3520 uint8_t res;
3521 uint8_t status;
3522
3523 if (handle == NULL) /* check handle */
3524 {
3525 return 2; /* return error */
3526 }
3527 if (handle->inited != 1) /* check handle initialization */
3528 {
3529 return 3; /* return error */
3530 }
3531
3532 res = a_bmp388_iic_spi_read(handle, BMP388_REG_INT_STATUS, (uint8_t *)&status, 1); /* read config */
3533 if (res != 0) /* check result */
3534 {
3535 handle->debug_print("bmp388: get interrupt status register failed.\n"); /* get interrupt status register failed */
3536
3537 return 1; /* return error */
3538 }
3539 if ((status & (1 << 1)) != 0) /* if fifo full */
3540 {
3541 if(handle->receive_callback != NULL) /* if receive callback is valid */
3542 {
3543 handle->receive_callback(BMP388_INTERRUPT_STATUS_FIFO_FULL); /* run receive callback */
3544 }
3545 }
3546 if ((status & (1 << 0)) != 0) /* if fifo watermark */
3547 {
3548 if(handle->receive_callback != NULL) /* if receive callback is valid */
3549 {
3550 handle->receive_callback(BMP388_INTERRUPT_STATUS_FIFO_WATERMARK); /* run receive callback */
3551 }
3552 }
3553 if ((status & (1 << 3)) != 0) /* if data ready */
3554 {
3555 if (handle->receive_callback != NULL) /* if receive callback is valid */
3556 {
3557 handle->receive_callback(BMP388_INTERRUPT_STATUS_DATA_READY); /* run receive callback */
3558 }
3559 }
3560
3561 return 0; /* success return 0 */
3562}
3563
3574{
3575 if (handle == NULL) /* check handle */
3576 {
3577 return 2; /* return error */
3578 }
3579
3580 handle->iic_addr = (uint8_t)addr_pin; /* set iic address */
3581
3582 return 0; /* success return 0 */
3583}
3584
3595{
3596 if (handle == NULL) /* check handle */
3597 {
3598 return 2; /* return error */
3599 }
3600
3601 *addr_pin = (bmp388_address_t)handle->iic_addr; /* get iic address */
3602
3603 return 0; /* success return 0 */
3604}
3605
3616{
3617 if (handle == NULL) /* check handle */
3618 {
3619 return 2; /* return error */
3620 }
3621
3622 handle->iic_spi = (uint8_t)interface; /* set interface */
3623
3624 return 0; /* success return 0 */
3625}
3626
3637{
3638 if (handle == NULL) /* check handle */
3639 {
3640 return 2; /* return error */
3641 }
3642
3643 *interface = (bmp388_interface_t)(handle->iic_spi); /* get interface */
3644
3645 return 0; /* success return 0 */
3646}
3647
3660uint8_t bmp388_read_fifo(bmp388_handle_t *handle, uint8_t *buf, uint16_t *len)
3661{
3662 uint8_t res;
3663 uint8_t prev;
3664 uint8_t tmp_buf[2];
3665 uint16_t length;
3666
3667 if (handle == NULL) /* check handle */
3668 {
3669 return 2; /* return error */
3670 }
3671 if (handle->inited != 1) /* check handle initialization */
3672 {
3673 return 3; /* return error */
3674 }
3675
3676 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3677 if (res != 0) /* check result */
3678 {
3679 handle->debug_print("bmp388: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
3680
3681 return 1; /* return error */
3682 }
3683 if ((prev & 0x01) != 0) /* check mode */
3684 {
3685 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_LENGTH_0, (uint8_t *)tmp_buf, 2); /* read config */
3686 if (res != 0) /* check result */
3687 {
3688 handle->debug_print("bmp388: get fifo length register failed.\n"); /* get fifo length register failed */
3689
3690 return 1; /* return error */
3691 }
3692 length = ((uint16_t)(tmp_buf[1] & 0x01) << 8) | tmp_buf[0]; /* get data */
3693 if ((prev & (1 << 2)) != 0) /* if include sensor time */
3694 {
3695 length += 4; /* add sensor time length */
3696 }
3697 *len = (*len) < length ? (*len) :length; /* get real length */
3698 res = a_bmp388_iic_spi_read(handle, BMP388_REG_FIFO_DATA, (uint8_t *)buf, *len); /* read config */
3699 if (res != 0) /* check result */
3700 {
3701 handle->debug_print("bmp388: get fifo data failed.\n"); /* get fifo data failed */
3702
3703 return 1; /* return error */
3704 }
3705
3706 return 0; /* success return 0 */
3707 }
3708 else
3709 {
3710 handle->debug_print("bmp388: normal mode or forced mode can't use this function.\n"); /* normal mode or forced mode can't use this function */
3711
3712 return 1; /* return error */
3713 }
3714}
3715
3730uint8_t bmp388_fifo_parse(bmp388_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp388_frame_t *frame, uint16_t *frame_len)
3731{
3732 uint8_t res;
3733 uint16_t i;
3734 uint16_t frame_total;
3735
3736 if (handle == NULL) /* check handle */
3737 {
3738 return 2; /* return error */
3739 }
3740 if (handle->inited != 1) /* check handle initialization */
3741 {
3742 return 3; /* return error */
3743 }
3744
3745 if (buf_len == 0) /* check buffer length */
3746 {
3747 handle->debug_print("bmp388: buffer length is invalid.\n"); /* buffer length is invalid */
3748
3749 return 1; /* return error */
3750 }
3751 frame_total = 0; /* clear total frame */
3752 res = 0; /* set 0 */
3753 i = 0; /* set 0 */
3754 while (i < buf_len) /* loop */
3755 {
3756 switch ((uint8_t)buf[i])
3757 {
3758 case 0x90 :
3759 {
3760 if (frame_total > ((*frame_len)-1)) /* check length */
3761 {
3762 return 0; /* return success */
3763 }
3764 frame[frame_total].type = BMP388_FRAME_TYPE_TEMPERATURE; /* set temperature type */
3765 frame[frame_total].raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1]; /* set raw */
3766 frame[frame_total].data = (float)((double)a_bmp388_compensate_temperature(handle, frame[frame_total].raw) / 100.0); /* set compensate temperature */
3767 frame_total++; /* frame++ */
3768 i += 4; /* index + 4 */
3769
3770 break; /* break */
3771 }
3772 case 0x94 :
3773 {
3774 if ((frame_total) > ((*frame_len)-1)) /* check length */
3775 {
3776 return 0; /* return success */
3777 }
3778 frame[frame_total].type = BMP388_FRAME_TYPE_TEMPERATURE; /* set temperature type */
3779 frame[frame_total].raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1]; /* set raw */
3780 frame[frame_total].data = (float)((double)a_bmp388_compensate_temperature(handle, frame[frame_total].raw) / 100.0); /* set compensate temperature */
3781 frame_total++; /* frame++ */
3782 if (frame_total > ((*frame_len)-1)) /* check length */
3783 {
3784 return 0; /* return success */
3785 }
3786 frame[frame_total].type = BMP388_FRAME_TYPE_PRESSURE; /* set pressure type */
3787 frame[frame_total].raw = (uint32_t)buf[i + 5 + 1] << 16 | (uint32_t)buf[i + 4 + 1] << 8 | buf[i + 3 + 1]; /* set raw */
3788 frame[frame_total].data = (float)((double)a_bmp388_compensate_pressure(handle, frame[frame_total].raw) / 100.0); /* set compensate pressure */
3789 frame_total++; /* frame++ */
3790 i += 7; /* index + 7 */
3791
3792 break; /* break */
3793 }
3794 case 0xA0 :
3795 {
3796 if (frame_total > ((*frame_len)-1)) /* check length */
3797 {
3798 return 0; /* return success */
3799 }
3800 frame[frame_total].type = BMP388_FRAME_TYPE_SENSORTIME; /* set sensor time type */
3801 frame[frame_total].raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1]; /* set raw */
3802 frame[frame_total].data = 0; /* set data */
3803 frame_total++; /* frame++ */
3804 i += 4; /* index+4 */
3805
3806 break; /* break */
3807 }
3808 case 0x80 : /* fifo empty */
3809 {
3810 i += 2; /* index+2 */
3811
3812 break; /* break */
3813 }
3814 case 0x48 : /* fifo input config */
3815 {
3816 i += 2; /* index+2 */
3817
3818 break; /* break */
3819 }
3820 case 0x44 : /* config error */
3821 {
3822 i += 2; /* index+2 */
3823
3824 break; /* break */
3825 }
3826 default :
3827 {
3828 handle->debug_print("bmp388: header is invalid.\n"); /* header is invalid */
3829 res = 1; /* set 1 */
3830
3831 break; /* break */
3832 }
3833 }
3834 if (res == 1) /* check the result */
3835 {
3836 return 1; /* return error */
3837 }
3838 }
3839 *frame_len = frame_total; /* set frame length */
3840
3841 return 0; /* success return 0 */
3842}
3843
3856uint8_t bmp388_set_reg(bmp388_handle_t *handle, uint8_t reg, uint8_t value)
3857{
3858 if (handle == NULL) /* check handle */
3859 {
3860 return 2; /* return error */
3861 }
3862 if (handle->inited != 1) /* check handle initialization */
3863 {
3864 return 3; /* return error */
3865 }
3866
3867 return a_bmp388_iic_spi_write(handle, reg, &value, 1); /* write register */
3868}
3869
3882uint8_t bmp388_get_reg(bmp388_handle_t *handle, uint8_t reg, uint8_t *value)
3883{
3884 if (handle == NULL) /* check handle */
3885 {
3886 return 2; /* return error */
3887 }
3888 if (handle->inited != 1) /* check handle initialization */
3889 {
3890 return 3; /* return error */
3891 }
3892
3893 return a_bmp388_iic_spi_read(handle, reg, value, 1); /* read register */
3894}
3895
3905{
3906 if (info == NULL) /* check handle */
3907 {
3908 return 2; /* return error */
3909 }
3910
3911 memset(info, 0, sizeof(bmp388_info_t)); /* initialize bmp388 info structure */
3912 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
3913 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
3914 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
3915 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
3916 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
3917 info->max_current_ma = MAX_CURRENT; /* set maximum current */
3918 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
3919 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
3920 info->driver_version = DRIVER_VERSION; /* set driver version */
3921
3922 return 0; /* success return 0 */
3923}
#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 MAX_CURRENT
#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 TEMPERATURE_MAX
#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 BMP388_REG_ODR
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define BMP388_REG_NVM_PAR_P11
#define BMP388_REG_FIFO_DATA
#define BMP388_REG_OSR
#define BMP388_REG_NVM_PAR_P7
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define BMP388_REG_CHIP_ID
#define BMP388_REG_EVENT
#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_INTERFACE_IIC
@ 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
bmp388_frame_type_t type
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 buf[512+1]
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
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]