LibDriver BMP390
Loading...
Searching...
No Matches
driver_bmp390.c
Go to the documentation of this file.
1
36
37#include "driver_bmp390.h"
38
42#define CHIP_NAME "Bosch BMP390"
43#define MANUFACTURER_NAME "Bosch"
44#define SUPPLY_VOLTAGE_MIN 1.65f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.73f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define BMP390_REG_CMD 0x7E
55#define BMP390_REG_NVM_PAR_T1_L 0x31
56#define BMP390_REG_NVM_PAR_T1_H 0x32
57#define BMP390_REG_NVM_PAR_T2_L 0x33
58#define BMP390_REG_NVM_PAR_T2_H 0x34
59#define BMP390_REG_NVM_PAR_T3 0x35
60#define BMP390_REG_NVM_PAR_P1_L 0x36
61#define BMP390_REG_NVM_PAR_P1_H 0x37
62#define BMP390_REG_NVM_PAR_P2_L 0x38
63#define BMP390_REG_NVM_PAR_P2_H 0x39
64#define BMP390_REG_NVM_PAR_P3 0x3A
65#define BMP390_REG_NVM_PAR_P4 0x3B
66#define BMP390_REG_NVM_PAR_P5_L 0x3C
67#define BMP390_REG_NVM_PAR_P5_H 0x3D
68#define BMP390_REG_NVM_PAR_P6_L 0x3E
69#define BMP390_REG_NVM_PAR_P6_H 0x3F
70#define BMP390_REG_NVM_PAR_P7 0x40
71#define BMP390_REG_NVM_PAR_P8 0x41
72#define BMP390_REG_NVM_PAR_P9_L 0x42
73#define BMP390_REG_NVM_PAR_P9_H 0x43
74#define BMP390_REG_NVM_PAR_P10 0x44
75#define BMP390_REG_NVM_PAR_P11 0x45
76#define BMP390_REG_CONFIG 0x1F
77#define BMP390_REG_ODR 0x1D
78#define BMP390_REG_OSR 0x1C
79#define BMP390_REG_PWR_CTRL 0x1B
80#define BMP390_REG_IF_CONF 0x1A
81#define BMP390_REG_INT_CTRL 0x19
82#define BMP390_REG_FIFO_CONFIG_2 0x18
83#define BMP390_REG_FIFO_CONFIG_1 0x17
84#define BMP390_REG_FIFO_WTM_1 0x16
85#define BMP390_REG_FIFO_WTM_0 0x15
86#define BMP390_REG_FIFO_DATA 0x14
87#define BMP390_REG_FIFO_LENGTH_1 0x13
88#define BMP390_REG_FIFO_LENGTH_0 0x12
89#define BMP390_REG_INT_STATUS 0x11
90#define BMP390_REG_EVENT 0x10
91#define BMP390_REG_SENSORTIME_2 0x0E
92#define BMP390_REG_SENSORTIME_1 0x0D
93#define BMP390_REG_SENSORTIME_0 0x0C
94#define BMP390_REG_DATA_5 0x09
95#define BMP390_REG_DATA_4 0x08
96#define BMP390_REG_DATA_3 0x07
97#define BMP390_REG_DATA_2 0x06
98#define BMP390_REG_DATA_1 0x05
99#define BMP390_REG_DATA_0 0x04
100#define BMP390_REG_STATUS 0x03
101#define BMP390_REG_ERR_REG 0x02
102#define BMP390_REG_REV_ID 0x01
103#define BMP390_REG_CHIP_ID 0x00
104
116static uint8_t a_bmp390_iic_spi_read(bmp390_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
117{
118 if (handle->iic_spi == BMP390_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_bmp390_iic_spi_write(bmp390_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
155{
156 if (handle->iic_spi == BMP390_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_bmp390_get_calibration_data(bmp390_handle_t *handle)
197{
198 uint8_t buf[2];
199
200 if (a_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_T1_L, (uint8_t *)buf, 2) != 0) /* read t1 */
201 {
202 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_T2_L, (uint8_t *)buf, 2) != 0) /* read t2 */
208 {
209 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_T3, (uint8_t *)buf, 1) != 0) /* read t3 */
215 {
216 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P1_L, (uint8_t *)buf, 2) != 0) /* read p1 */
222 {
223 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P2_L, (uint8_t *)buf, 2) != 0) /* read p2 */
229 {
230 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P3, (uint8_t *)buf, 1) != 0) /* read p3 */
236 {
237 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P4, (uint8_t *)buf, 1) != 0) /* read p4 */
243 {
244 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P5_L, (uint8_t *)buf, 2) != 0) /* read p5 */
250 {
251 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P6_L, (uint8_t *)buf, 2) != 0) /* read p6l */
257 {
258 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P7, (uint8_t *)buf, 1) != 0) /* read p7 */
264 {
265 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P8, (uint8_t *)buf, 1) != 0) /* read p8 */
271 {
272 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P9_L, (uint8_t *)buf, 2) != 0) /* read p9l */
278 {
279 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P10, (uint8_t *)buf, 1) != 0) /* read p10 */
285 {
286 handle->debug_print("bmp390: 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_bmp390_iic_spi_read(handle, BMP390_REG_NVM_PAR_P11, (uint8_t *)buf, 1) != 0) /* read p11 */
292 {
293 handle->debug_print("bmp390: 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_bmp390_compensate_temperature(bmp390_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_bmp390_compensate_pressure(bmp390_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 bmp390_get_revision_id(bmp390_handle_t *handle, uint8_t *id)
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_bmp390_iic_spi_read(handle, BMP390_REG_REV_ID, (uint8_t *)id, 1); /* read config */
402 if (res != 0) /* check result */
403 {
404 handle->debug_print("bmp390: get revision id register failed.\n"); /* get revision id register failed */
405
406 return 1; /* return error */
407 }
408
409 return 0; /* success return 0 */
410}
411
423uint8_t bmp390_get_error(bmp390_handle_t *handle, uint8_t *err)
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_bmp390_iic_spi_read(handle, BMP390_REG_ERR_REG, (uint8_t *)err, 1); /* read config */
437 if (res != 0) /* check result */
438 {
439 handle->debug_print("bmp390: get error register failed.\n"); /* get error register failed */
440
441 return 1; /* return error */
442 }
443
444 return 0; /* success return 0 */
445}
446
458uint8_t bmp390_get_status(bmp390_handle_t *handle, uint8_t *status)
459{
460 uint8_t res;
461
462 if (handle == NULL) /* check handle */
463 {
464 return 2; /* return error */
465 }
466 if (handle->inited != 1) /* check handle initialization */
467 {
468 return 3; /* return error */
469 }
470
471 res = a_bmp390_iic_spi_read(handle, BMP390_REG_STATUS, (uint8_t *)status, 1); /* read status */
472 if (res != 0) /* check result */
473 {
474 handle->debug_print("bmp390: get status register failed.\n"); /* get status register failed */
475
476 return 1; /* return error */
477 }
478
479 return 0; /* success return 0 */
480}
481
493uint8_t bmp390_get_sensortime(bmp390_handle_t *handle, uint32_t *t)
494{
495 uint8_t res;
496 uint8_t buf[3];
497
498 if (handle == NULL) /* check handle */
499 {
500 return 2; /* return error */
501 }
502 if (handle->inited != 1) /* check handle initialization */
503 {
504 return 3; /* return error */
505 }
506
507 res = a_bmp390_iic_spi_read(handle, BMP390_REG_SENSORTIME_0, (uint8_t *)buf, 3); /* read config */
508 if (res != 0) /* check result */
509 {
510 handle->debug_print("bmp390: get sensor time register failed.\n"); /* get sensor time register failed */
511
512 return 1; /* return error */
513 }
514 *t = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get time */
515
516 return 0; /* success return 0 */
517}
518
531{
532 uint8_t res;
533 uint8_t prev;
534
535 if (handle == NULL) /* check handle */
536 {
537 return 2; /* return error */
538 }
539 if (handle->inited != 1) /* check handle initialization */
540 {
541 return 3; /* return error */
542 }
543
544 res = a_bmp390_iic_spi_read(handle, BMP390_REG_EVENT, (uint8_t *)&prev, 1); /* read config */
545 if (res != 0) /* check result */
546 {
547 handle->debug_print("bmp390: get event register failed.\n"); /* get event register failed */
548
549 return 1; /* return error */
550 }
551 *event = (bmp390_event_t)(prev & (3 << 0)); /* get event */
552
553 return 0; /* success return 0 */
554}
555
567uint8_t bmp390_get_interrupt_status(bmp390_handle_t *handle, uint8_t *status)
568{
569 uint8_t res;
570
571 if (handle == NULL) /* check handle */
572 {
573 return 2; /* return error */
574 }
575 if (handle->inited != 1) /* check handle initialization */
576 {
577 return 3; /* return error */
578 }
579
580 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_STATUS, (uint8_t *)status, 1); /* read status */
581 if (res != 0) /* check result */
582 {
583 handle->debug_print("bmp390: get interrupt status register failed.\n"); /* get interrupt status register failed */
584
585 return 1; /* return error */
586 }
587
588 return 0; /* success return 0 */
589}
590
602uint8_t bmp390_get_fifo_length(bmp390_handle_t *handle, uint16_t *length)
603{
604 uint8_t res;
605 uint8_t buf[2];
606
607 if (handle == NULL) /* check handle */
608 {
609 return 2; /* return error */
610 }
611 if (handle->inited != 1) /* check handle initialization */
612 {
613 return 3; /* return error */
614 }
615
616 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_LENGTH_0, (uint8_t *)buf, 2); /* read config */
617 if (res != 0) /* check result */
618 {
619 handle->debug_print("bmp390: get fifo length register failed.\n"); /* get fifo length register failed */
620
621 return 1; /* return error */
622 }
623 *length = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0]; /* get data */
624
625 return 0; /* success return 0 */
626}
627
640uint8_t bmp390_get_fifo_data(bmp390_handle_t *handle, uint8_t *data, uint16_t length)
641{
642 uint8_t res;
643
644 if (handle == NULL) /* check handle */
645 {
646 return 2; /* return error */
647 }
648 if (handle->inited != 1) /* check handle initialization */
649 {
650 return 3; /* return error */
651 }
652
653 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_DATA, (uint8_t *)data, length); /* read data */
654 if (res != 0) /* check result */
655 {
656 handle->debug_print("bmp390: get fifo data register failed.\n"); /* get fifo data register failed */
657
658 return 1; /* return error */
659 }
660
661 return 0; /* success return 0 */
662}
663
675uint8_t bmp390_set_fifo_watermark(bmp390_handle_t *handle, uint16_t watermark)
676{
677 uint8_t res;
678 uint8_t buf[2];
679
680 if (handle == NULL) /* check handle */
681 {
682 return 2; /* return error */
683 }
684 if (handle->inited != 1) /* check handle initialization */
685 {
686 return 3; /* return error */
687 }
688
689 buf[0] = watermark & 0xFF; /* set low part */
690 buf[1] = (watermark >> 8) & 0x01; /* set high part */
691 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_WTM_0, (uint8_t *)buf, 2); /* write config */
692 if (res != 0) /* check result */
693 {
694 handle->debug_print("bmp390: set fifo watermark register failed.\n"); /* set fifo watermark register failed */
695
696 return 1; /* return error */
697 }
698
699 return 0; /* success return 0 */
700}
701
713uint8_t bmp390_get_fifo_watermark(bmp390_handle_t *handle, uint16_t *watermark)
714{
715 uint8_t res;
716 uint8_t buf[2];
717
718 if (handle == NULL) /* check handle */
719 {
720 return 2; /* return error */
721 }
722 if (handle->inited != 1) /* check handle initialization */
723 {
724 return 3; /* return error */
725 }
726
727 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_WTM_0, (uint8_t *)buf, 2); /* read config */
728 if (res != 0) /* check result */
729 {
730 handle->debug_print("bmp390: get fifo watermark register failed.\n"); /* get fifo watermark register failed */
731
732 return 1; /* return error */
733 }
734 *watermark = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0]; /* get data */
735
736 return 0; /* success return 0 */
737}
738
751{
752 uint8_t res;
753 uint8_t prev;
754
755 if (handle == NULL) /* check handle */
756 {
757 return 2; /* return error */
758 }
759 if (handle->inited != 1) /* check handle initialization */
760 {
761 return 3; /* return error */
762 }
763
764 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
765 if (res != 0) /* check result */
766 {
767 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
768
769 return 1; /* return error */
770 }
771 prev &= ~(1 << 0); /* clear config */
772 prev |= enable << 0; /* set config */
773 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
774 if (res != 0) /* check result */
775 {
776 handle->debug_print("bmp390: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
777
778 return 1; /* return error */
779 }
780
781 return 0; /* success return 0 */
782}
783
796{
797 uint8_t res;
798 uint8_t prev;
799
800 if (handle == NULL) /* check handle */
801 {
802 return 2; /* return error */
803 }
804 if (handle->inited != 1) /* check handle initialization */
805 {
806 return 3; /* return error */
807 }
808
809 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
810 if (res != 0) /* check result */
811 {
812 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
813
814 return 1; /* return error */
815 }
816 *enable = (bmp390_bool_t)(prev & 0x01); /* get config */
817
818 return 0; /* success return 0 */
819}
820
833{
834 uint8_t res;
835 uint8_t prev;
836
837 if (handle == NULL) /* check handle */
838 {
839 return 2; /* return error */
840 }
841 if (handle->inited != 1) /* check handle initialization */
842 {
843 return 3; /* return error */
844 }
845
846 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
847 if (res != 0) /* check result */
848 {
849 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
850
851 return 1; /* return error */
852 }
853 prev &= ~(1 << 1); /* clear config */
854 prev |= enable << 1; /* set config */
855 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
856 if (res != 0) /* check result */
857 {
858 handle->debug_print("bmp390: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
859
860 return 1; /* return error */
861 }
862
863 return 0; /* success return 0 */
864}
865
878{
879 uint8_t res;
880 uint8_t prev;
881
882 if (handle == NULL) /* check handle */
883 {
884 return 2; /* return error */
885 }
886 if (handle->inited != 1) /* check handle initialization */
887 {
888 return 3; /* return error */
889 }
890
891 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
892 if (res != 0) /* check result */
893 {
894 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
895
896 return 1; /* return error */
897 }
898 *enable = (bmp390_bool_t)((prev >> 1) & 0x01); /* get config */
899
900 return 0; /* success return 0 */
901}
902
915{
916 uint8_t res;
917 uint8_t prev;
918
919 if (handle == NULL) /* check handle */
920 {
921 return 2; /* return error */
922 }
923 if (handle->inited != 1) /* check handle initialization */
924 {
925 return 3; /* return error */
926 }
927
928 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
929 if (res != 0) /* check result */
930 {
931 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
932
933 return 1; /* return error */
934 }
935 prev &= ~(1 << 2); /* clear config */
936 prev |= enable << 2; /* set config */
937 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
938 if (res != 0) /* check result */
939 {
940 handle->debug_print("bmp390: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
941
942 return 1; /* return error */
943 }
944
945 return 0; /* success return 0 */
946}
947
960{
961 uint8_t res;
962 uint8_t prev;
963
964 if (handle == NULL) /* check handle */
965 {
966 return 2; /* return error */
967 }
968 if (handle->inited != 1) /* check handle initialization */
969 {
970 return 3; /* return error */
971 }
972
973 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
974 if (res != 0) /* check result */
975 {
976 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
977
978 return 1; /* return error */
979 }
980 *enable = (bmp390_bool_t)((prev >> 2) & 0x01); /* get config */
981
982 return 0; /* success return 0 */
983}
984
997{
998 uint8_t res;
999 uint8_t prev;
1000
1001 if (handle == NULL) /* check handle */
1002 {
1003 return 2; /* return error */
1004 }
1005 if (handle->inited != 1) /* check handle initialization */
1006 {
1007 return 3; /* return error */
1008 }
1009
1010 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1011 if (res != 0) /* check result */
1012 {
1013 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1014
1015 return 1; /* return error */
1016 }
1017 prev &= ~(1 << 3); /* clear config */
1018 prev |= enable << 3; /* set config */
1019 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
1020 if (res != 0) /* check result */
1021 {
1022 handle->debug_print("bmp390: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
1023
1024 return 1; /* return error */
1025 }
1026
1027 return 0; /* success return 0 */
1028}
1029
1042{
1043 uint8_t res;
1044 uint8_t prev;
1045
1046 if (handle == NULL) /* check handle */
1047 {
1048 return 2; /* return error */
1049 }
1050 if (handle->inited != 1) /* check handle initialization */
1051 {
1052 return 3; /* return error */
1053 }
1054
1055 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1056 if (res != 0) /* check result */
1057 {
1058 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1059
1060 return 1; /* return error */
1061 }
1062 *enable = (bmp390_bool_t)((prev >> 3) & 0x01); /* get config */
1063
1064 return 0; /* success return 0 */
1065}
1066
1079{
1080 uint8_t res;
1081 uint8_t prev;
1082
1083 if (handle == NULL) /* check handle */
1084 {
1085 return 2; /* return error */
1086 }
1087 if (handle->inited != 1) /* check handle initialization */
1088 {
1089 return 3; /* return error */
1090 }
1091
1092 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1093 if (res != 0) /* check result */
1094 {
1095 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1096
1097 return 1; /* return error */
1098 }
1099 prev &= ~(1 << 4); /* clear config */
1100 prev |= enable << 4; /* set config */
1101 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
1102 if (res != 0) /* check result */
1103 {
1104 handle->debug_print("bmp390: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
1105
1106 return 1; /* return error */
1107 }
1108
1109 return 0; /* success return 0 */
1110}
1111
1124{
1125 uint8_t res;
1126 uint8_t prev;
1127
1128 if (handle == NULL) /* check handle */
1129 {
1130 return 2; /* return error */
1131 }
1132 if (handle->inited != 1) /* check handle initialization */
1133 {
1134 return 3; /* return error */
1135 }
1136
1137 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1138 if (res != 0) /* check result */
1139 {
1140 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1141
1142 return 1; /* return error */
1143 }
1144 *enable = (bmp390_bool_t)((prev >> 4) & 0x01); /* get config */
1145
1146 return 0; /* success return 0 */
1147}
1148
1160uint8_t bmp390_set_fifo_subsampling(bmp390_handle_t *handle, uint8_t subsample)
1161{
1162 uint8_t res;
1163 uint8_t prev;
1164
1165 if (handle == NULL) /* check handle */
1166 {
1167 return 2; /* return error */
1168 }
1169 if (handle->inited != 1) /* check handle initialization */
1170 {
1171 return 3; /* return error */
1172 }
1173
1174 if (subsample > 7) /* check subsample */
1175 {
1176 handle->debug_print("bmp390: subsample is invalid.\n"); /* subsample is invalid */
1177
1178 return 4; /* return error */
1179 }
1180 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1181 if (res != 0) /* check result */
1182 {
1183 handle->debug_print("bmp390: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1184
1185 return 1; /* return error */
1186 }
1187 prev &= ~(7 << 0); /* clear config */
1188 prev |= subsample << 0; /* set config */
1189 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* write config */
1190 if (res != 0) /* check result */
1191 {
1192 handle->debug_print("bmp390: set fifo config 2 register failed.\n"); /* set fifo config 2 register failed */
1193
1194 return 1; /* return error */
1195 }
1196
1197 return 0; /* success return 0 */
1198}
1199
1211uint8_t bmp390_get_fifo_subsampling(bmp390_handle_t *handle, uint8_t *subsample)
1212{
1213 uint8_t res;
1214 uint8_t prev;
1215
1216 if (handle == NULL) /* check handle */
1217 {
1218 return 2; /* return error */
1219 }
1220 if (handle->inited != 1) /* check handle initialization */
1221 {
1222 return 3; /* return error */
1223 }
1224
1225 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1226 if (res != 0) /* check result */
1227 {
1228 handle->debug_print("bmp390: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1229
1230 return 1; /* return error */
1231 }
1232 *subsample = (bmp390_bool_t)((prev >> 0) & 0x07); /* get config */
1233
1234 return 0; /* success return 0 */
1235}
1236
1249{
1250 uint8_t res;
1251 uint8_t prev;
1252
1253 if (handle == NULL) /* check handle */
1254 {
1255 return 2; /* return error */
1256 }
1257 if (handle->inited != 1) /* check handle initialization */
1258 {
1259 return 3; /* return error */
1260 }
1261
1262 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1263 if (res != 0) /* check result */
1264 {
1265 handle->debug_print("bmp390: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1266
1267 return 1; /* return error */
1268 }
1269 prev &= ~(3 << 3); /* clear config */
1270 prev |= source << 3; /* set config */
1271 res = a_bmp390_iic_spi_write(handle, BMP390_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* write config */
1272 if (res != 0) /* check result */
1273 {
1274 handle->debug_print("bmp390: set fifo config 2 register failed.\n"); /* set fifo config 2 register failed */
1275
1276 return 1; /* return error */
1277 }
1278
1279 return 0; /* success return 0 */
1280}
1281
1294{
1295 uint8_t res;
1296 uint8_t prev;
1297
1298 if (handle == NULL) /* check handle */
1299 {
1300 return 2; /* return error */
1301 }
1302 if (handle->inited != 1) /* check handle initialization */
1303 {
1304 return 3; /* return error */
1305 }
1306
1307 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1308 if (res != 0) /* check result */
1309 {
1310 handle->debug_print("bmp390: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1311
1312 return 1; /* return error */
1313 }
1314 *source = (bmp390_fifo_data_source_t)((prev >> 3) & 0x01); /* get config */
1315
1316 return 0; /* success return 0 */
1317}
1318
1331{
1332 uint8_t res;
1333 uint8_t prev;
1334
1335 if (handle == NULL) /* check handle */
1336 {
1337 return 2; /* return error */
1338 }
1339 if (handle->inited != 1) /* check handle initialization */
1340 {
1341 return 3; /* return error */
1342 }
1343
1344 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1345 if (res != 0) /* check result */
1346 {
1347 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1348
1349 return 1; /* return error */
1350 }
1351 prev &= ~(1 << 0); /* clear config */
1352 prev |= pin_type << 0; /* set config */
1353 res = a_bmp390_iic_spi_write(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1354 if (res != 0) /* check result */
1355 {
1356 handle->debug_print("bmp390: set int ctrl register failed.\n"); /* set int ctrl register failed */
1357
1358 return 1; /* return error */
1359 }
1360
1361 return 0; /* success return 0 */
1362}
1363
1376{
1377 uint8_t res;
1378 uint8_t prev;
1379
1380 if (handle == NULL) /* check handle */
1381 {
1382 return 2; /* return error */
1383 }
1384 if (handle->inited != 1) /* check handle initialization */
1385 {
1386 return 3; /* return error */
1387 }
1388
1389 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1390 if (res != 0) /* check result */
1391 {
1392 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1393
1394 return 1; /* return error */
1395 }
1396 *pin_type = (bmp390_interrupt_pin_type_t)(prev & 0x01); /* get interrupt pin type */
1397
1398 return 0; /* success return 0 */
1399}
1400
1413{
1414 uint8_t res;
1415 uint8_t prev;
1416
1417 if (handle == NULL) /* check handle */
1418 {
1419 return 2; /* return error */
1420 }
1421 if (handle->inited != 1) /* check handle initialization */
1422 {
1423 return 3; /* return error */
1424 }
1425
1426 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1427 if (res != 0) /* check result */
1428 {
1429 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1430
1431 return 1; /* return error */
1432 }
1433 prev &= ~(1 << 1); /* clear config */
1434 prev |= level << 1; /* set config */
1435 res = a_bmp390_iic_spi_write(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1436 if (res != 0) /* check result */
1437 {
1438 handle->debug_print("bmp390: set int ctrl register failed.\n"); /* set int ctrl register failed */
1439
1440 return 1; /* return error */
1441 }
1442
1443 return 0; /* success return 0 */
1444}
1445
1458{
1459 uint8_t res;
1460 uint8_t prev;
1461
1462 if (handle == NULL) /* check handle */
1463 {
1464 return 2; /* return error */
1465 }
1466 if (handle->inited != 1) /* check handle initialization */
1467 {
1468 return 3; /* return error */
1469 }
1470
1471 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1472 if (res != 0) /* check result */
1473 {
1474 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1475
1476 return 1; /* return error */
1477 }
1478 *level = (bmp390_interrupt_active_level_t)((prev >> 1) & 0x01); /* get config */
1479
1480 return 0; /* success return 0 */
1481}
1482
1495{
1496 uint8_t res;
1497 uint8_t prev;
1498
1499 if (handle == NULL) /* check handle */
1500 {
1501 return 2; /* return error */
1502 }
1503 if (handle->inited != 1) /* check handle initialization */
1504 {
1505 return 3; /* return error */
1506 }
1507
1508 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1509 if (res != 0) /* check result */
1510 {
1511 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1512
1513 return 1; /* return error */
1514 }
1515 prev &= ~(1 << 2); /* clear config */
1516 prev |= enable << 2; /* set config */
1517 res = a_bmp390_iic_spi_write(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1518 if (res != 0) /* check result */
1519 {
1520 handle->debug_print("bmp390: set int ctrl register failed.\n"); /* set int ctrl register failed */
1521
1522 return 1; /* return error */
1523 }
1524
1525 return 0; /* success return 0 */
1526}
1527
1540{
1541 uint8_t res;
1542 uint8_t prev;
1543
1544 if (handle == NULL) /* check handle */
1545 {
1546 return 2; /* return error */
1547 }
1548 if (handle->inited != 1) /* check handle initialization */
1549 {
1550 return 3; /* return error */
1551 }
1552
1553 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1554 if (res != 0) /* check result */
1555 {
1556 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1557
1558 return 1; /* return error */
1559 }
1560 *enable = (bmp390_bool_t)((prev >> 2) & 0x01); /* get config */
1561
1562 return 0; /* success return 0 */
1563}
1564
1577{
1578 uint8_t res;
1579 uint8_t prev;
1580
1581 if (handle == NULL) /* check handle */
1582 {
1583 return 2; /* return error */
1584 }
1585 if (handle->inited != 1) /* check handle initialization */
1586 {
1587 return 3; /* return error */
1588 }
1589
1590 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1591 if (res != 0) /* check result */
1592 {
1593 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1594
1595 return 1; /* return error */
1596 }
1597 prev &= ~(1 << 3); /* clear config */
1598 prev |= enable << 3; /* set config */
1599 res = a_bmp390_iic_spi_write(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1600 if (res != 0) /* check result */
1601 {
1602 handle->debug_print("bmp390: set int ctrl register failed.\n"); /* set int ctrl register failed */
1603
1604 return 1; /* return error */
1605 }
1606
1607 return 0; /* success return 0 */
1608}
1609
1622{
1623 uint8_t res;
1624 uint8_t prev;
1625
1626 if (handle == NULL) /* check handle */
1627 {
1628 return 2; /* return error */
1629 }
1630 if (handle->inited != 1) /* check handle initialization */
1631 {
1632 return 3; /* return error */
1633 }
1634
1635 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1636 if (res != 0) /* check result */
1637 {
1638 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1639
1640 return 1; /* return error */
1641 }
1642 *enable = (bmp390_bool_t)((prev >> 3) & 0x01); /* get config */
1643
1644 return 0; /* success return 0 */
1645}
1646
1659{
1660 uint8_t res;
1661 uint8_t prev;
1662
1663 if (handle == NULL) /* check handle */
1664 {
1665 return 2; /* return error */
1666 }
1667 if (handle->inited != 1) /* check handle initialization */
1668 {
1669 return 3; /* return error */
1670 }
1671
1672 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1673 if (res != 0) /* check result */
1674 {
1675 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1676
1677 return 1; /* return error */
1678 }
1679 prev &= ~(1 << 4); /* clear config */
1680 prev |= enable << 4; /* set config */
1681 res = a_bmp390_iic_spi_write(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1682 if (res != 0) /* check result */
1683 {
1684 handle->debug_print("bmp390: set int ctrl register failed.\n"); /* set int ctrl register failed */
1685
1686 return 1; /* return error */
1687 }
1688
1689 return 0; /* success return 0 */
1690}
1691
1704{
1705 uint8_t res;
1706 uint8_t prev;
1707
1708 if (handle == NULL) /* check handle */
1709 {
1710 return 2; /* return error */
1711 }
1712 if (handle->inited != 1) /* check handle initialization */
1713 {
1714 return 3; /* return error */
1715 }
1716
1717 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1718 if (res != 0) /* check result */
1719 {
1720 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1721
1722 return 1; /* return error */
1723 }
1724 *enable = (bmp390_bool_t)((prev >> 4) & 0x01); /* get config */
1725
1726 return 0; /* success return 0 */
1727}
1728
1741{
1742 uint8_t res;
1743 uint8_t prev;
1744
1745 if (handle == NULL) /* check handle */
1746 {
1747 return 2; /* return error */
1748 }
1749 if (handle->inited != 1) /* check handle initialization */
1750 {
1751 return 3; /* return error */
1752 }
1753
1754 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1755 if (res != 0) /* check result */
1756 {
1757 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1758
1759 return 1; /* return error */
1760 }
1761 prev &= ~(1 << 6); /* clear config */
1762 prev |= enable << 6; /* set config */
1763 res = a_bmp390_iic_spi_write(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1764 if (res != 0) /* check result */
1765 {
1766 handle->debug_print("bmp390: set int ctrl register failed.\n"); /* set int ctrl register failed */
1767
1768 return 1; /* return error */
1769 }
1770
1771 return 0; /* success return 0 */
1772}
1773
1786{
1787 uint8_t res;
1788 uint8_t prev;
1789
1790 if (handle == NULL) /* check handle */
1791 {
1792 return 2; /* return error */
1793 }
1794 if (handle->inited != 1) /* check handle initialization */
1795 {
1796 return 3; /* return error */
1797 }
1798
1799 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1800 if (res != 0) /* check result */
1801 {
1802 handle->debug_print("bmp390: get int ctrl register failed.\n"); /* get int ctrl register failed */
1803
1804 return 1; /* return error */
1805 }
1806 *enable = (bmp390_bool_t)((prev >> 6) & 0x01); /* get config */
1807
1808 return 0; /* success return 0 */
1809}
1810
1823{
1824 uint8_t res;
1825 uint8_t prev;
1826
1827 if (handle == NULL) /* check handle */
1828 {
1829 return 2; /* return error */
1830 }
1831 if (handle->inited != 1) /* check handle initialization */
1832 {
1833 return 3; /* return error */
1834 }
1835
1836 res = a_bmp390_iic_spi_read(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1837 if (res != 0) /* check result */
1838 {
1839 handle->debug_print("bmp390: get if conf register failed.\n"); /* get if conf register failed */
1840
1841 return 1; /* return error */
1842 }
1843 prev &= ~(1 << 0); /* clear config */
1844 prev |= wire << 0; /* set config */
1845 res = a_bmp390_iic_spi_write(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1846 if (res != 0) /* check result */
1847 {
1848 handle->debug_print("bmp390: set if conf register failed.\n"); /* set if conf register failed */
1849
1850 return 1; /* return error */
1851 }
1852
1853 return 0; /* success return 0 */
1854}
1855
1868{
1869 uint8_t res;
1870 uint8_t prev;
1871
1872 if (handle == NULL) /* check handle */
1873 {
1874 return 2; /* return error */
1875 }
1876 if (handle->inited != 1) /* check handle initialization */
1877 {
1878 return 3; /* return error */
1879 }
1880
1881 res = a_bmp390_iic_spi_read(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1882 if (res != 0) /* check result */
1883 {
1884 handle->debug_print("bmp390: get if conf register failed.\n"); /* get if conf register failed */
1885
1886 return 1; /* return error */
1887 }
1888 *wire = (bmp390_spi_wire_t)(prev & 0x01); /* get config */
1889
1890 return 0; /* success return 0 */
1891}
1892
1905{
1906 uint8_t res;
1907 uint8_t prev;
1908
1909 if (handle == NULL) /* check handle */
1910 {
1911 return 2; /* return error */
1912 }
1913 if (handle->inited != 1) /* check handle initialization */
1914 {
1915 return 3; /* return error */
1916 }
1917
1918 res = a_bmp390_iic_spi_read(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1919 if (res != 0) /* check result */
1920 {
1921 handle->debug_print("bmp390: get if conf register failed.\n"); /* get if conf register failed */
1922
1923 return 1; /* return error */
1924 }
1925 prev &= ~(1 << 1); /* clear config */
1926 prev |= enable << 1; /* set config */
1927 res = a_bmp390_iic_spi_write(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1928 if (res != 0) /* check result */
1929 {
1930 handle->debug_print("bmp390: set if conf register failed.\n"); /* set if conf register failed */
1931
1932 return 1; /* return error */
1933 }
1934
1935 return 0; /* success return 0 */
1936}
1937
1950{
1951 uint8_t res;
1952 uint8_t prev;
1953
1954 if (handle == NULL) /* check handle */
1955 {
1956 return 2; /* return error */
1957 }
1958 if (handle->inited != 1) /* check handle initialization */
1959 {
1960 return 3; /* return error */
1961 }
1962
1963 res = a_bmp390_iic_spi_read(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1964 if (res != 0) /* check result */
1965 {
1966 handle->debug_print("bmp390: get if conf register failed.\n"); /* get if conf register failed */
1967
1968 return 1; /* return error */
1969 }
1970 *enable = (bmp390_bool_t)((prev >> 1) & 0x01); /* get config */
1971
1972 return 0; /* success return 0 */
1973}
1974
1987{
1988 uint8_t res;
1989 uint8_t prev;
1990
1991 if (handle == NULL) /* check handle */
1992 {
1993 return 2; /* return error */
1994 }
1995 if (handle->inited != 1) /* check handle initialization */
1996 {
1997 return 3; /* return error */
1998 }
1999
2000 res = a_bmp390_iic_spi_read(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
2001 if (res != 0) /* check result */
2002 {
2003 handle->debug_print("bmp390: get if conf register failed.\n"); /* get if conf register failed */
2004
2005 return 1; /* return error */
2006 }
2007 prev &= ~(1 << 2); /* clear config */
2008 prev |= period << 2; /* set config */
2009 res = a_bmp390_iic_spi_write(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
2010 if (res != 0) /* check result */
2011 {
2012 handle->debug_print("bmp390: set if conf register failed.\n"); /* set if conf register failed */
2013
2014 return 1; /* return error */
2015 }
2016
2017 return 0; /* success return 0 */
2018}
2019
2032{
2033 uint8_t res;
2034 uint8_t prev;
2035
2036 if (handle == NULL) /* check handle */
2037 {
2038 return 2; /* return error */
2039 }
2040 if (handle->inited != 1) /* check handle initialization */
2041 {
2042 return 3; /* return error */
2043 }
2044
2045 res = a_bmp390_iic_spi_read(handle, BMP390_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
2046 if (res != 0) /* check result */
2047 {
2048 handle->debug_print("bmp390: get if conf register failed.\n"); /* get if conf register failed */
2049
2050 return 1; /* return error */
2051 }
2052 *period = (bmp390_iic_watchdog_period_t)((prev >> 2) & 0x01); /* get config */
2053
2054 return 0; /* success return 0 */
2055}
2056
2069{
2070 uint8_t res;
2071 uint8_t prev;
2072
2073 if (handle == NULL) /* check handle */
2074 {
2075 return 2; /* return error */
2076 }
2077 if (handle->inited != 1) /* check handle initialization */
2078 {
2079 return 3; /* return error */
2080 }
2081
2082 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2083 if (res != 0) /* check result */
2084 {
2085 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2086
2087 return 1; /* return error */
2088 }
2089 prev &= ~(1 << 0); /* clear config */
2090 prev |= enable << 0; /* set config */
2091 res = a_bmp390_iic_spi_write(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2092 if (res != 0) /* check result */
2093 {
2094 handle->debug_print("bmp390: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2095
2096 return 1; /* return error */
2097 }
2098
2099 return 0; /* success return 0 */
2100}
2101
2114{
2115 uint8_t res;
2116 uint8_t prev;
2117
2118 if (handle == NULL) /* check handle */
2119 {
2120 return 2; /* return error */
2121 }
2122 if (handle->inited != 1) /* check handle initialization */
2123 {
2124 return 3; /* return error */
2125 }
2126
2127 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2128 if (res != 0) /* check result */
2129 {
2130 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2131
2132 return 1; /* return error */
2133 }
2134 *enable = (bmp390_bool_t)((prev >> 0) & 0x01); /* get config */
2135
2136 return 0; /* success return 0 */
2137}
2138
2151{
2152 uint8_t res;
2153 uint8_t prev;
2154
2155 if (handle == NULL) /* check handle */
2156 {
2157 return 2; /* return error */
2158 }
2159 if (handle->inited != 1) /* check handle initialization */
2160 {
2161 return 3; /* return error */
2162 }
2163
2164 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2165 if (res != 0) /* check result */
2166 {
2167 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2168
2169 return 1; /* return error */
2170 }
2171 prev &= ~(1 << 1); /* clear config */
2172 prev |= enable << 1; /* set config */
2173 res = a_bmp390_iic_spi_write(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2174 if (res != 0) /* check result */
2175 {
2176 handle->debug_print("bmp390: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2177
2178 return 1; /* return error */
2179 }
2180
2181 return 0; /* success return 0 */
2182}
2183
2196{
2197 uint8_t res;
2198 uint8_t prev;
2199
2200 if (handle == NULL) /* check handle */
2201 {
2202 return 2; /* return error */
2203 }
2204 if (handle->inited != 1) /* check handle initialization */
2205 {
2206 return 3; /* return error */
2207 }
2208
2209 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2210 if (res != 0) /* check result */
2211 {
2212 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2213
2214 return 1; /* return error */
2215 }
2216 *enable = (bmp390_bool_t)((prev >> 1) & 0x01); /* get config */
2217
2218 return 0; /* success return 0 */
2219}
2220
2233{
2234 uint8_t res;
2235 uint8_t prev;
2236
2237 if (handle == NULL) /* check handle */
2238 {
2239 return 2; /* return error */
2240 }
2241 if (handle->inited != 1) /* check handle initialization */
2242 {
2243 return 3; /* return error */
2244 }
2245
2246 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2247 if (res != 0) /* check result */
2248 {
2249 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2250
2251 return 1; /* return error */
2252 }
2253 prev &= ~(3 << 4); /* clear config */
2254 prev |= mode << 4; /* set config */
2255 res = a_bmp390_iic_spi_write(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2256 if (res != 0) /* check result */
2257 {
2258 handle->debug_print("bmp390: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2259
2260 return 1; /* return error */
2261 }
2262
2263 return 0; /* success return 0 */
2264}
2265
2278{
2279 uint8_t res;
2280 uint8_t prev;
2281
2282 if (handle == NULL) /* check handle */
2283 {
2284 return 2; /* return error */
2285 }
2286 if (handle->inited != 1) /* check handle initialization */
2287 {
2288 return 3; /* return error */
2289 }
2290
2291 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2292 if (res != 0) /* check result */
2293 {
2294 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2295
2296 return 1; /* return error */
2297 }
2298 *mode = (bmp390_mode_t)((prev >> 4) & 0x03); /* get config */
2299
2300 return 0; /* success return 0 */
2301}
2302
2315{
2316 uint8_t res;
2317 uint8_t prev;
2318
2319 if (handle == NULL) /* check handle */
2320 {
2321 return 2; /* return error */
2322 }
2323 if (handle->inited != 1) /* check handle initialization */
2324 {
2325 return 3; /* return error */
2326 }
2327
2328 res = a_bmp390_iic_spi_read(handle, BMP390_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2329 if (res != 0) /* check result */
2330 {
2331 handle->debug_print("bmp390: get osr register failed.\n"); /* get osr register failed */
2332
2333 return 1; /* return error */
2334 }
2335 prev &= ~(7 << 0); /* clear config */
2336 prev |= oversampling << 0; /* set config */
2337 res = a_bmp390_iic_spi_write(handle, BMP390_REG_OSR, (uint8_t *)&prev, 1); /* write config */
2338 if (res != 0) /* check result */
2339 {
2340 handle->debug_print("bmp390: set osr register failed.\n"); /* set osr register failed */
2341
2342 return 1; /* return error */
2343 }
2344
2345 return 0; /* success return 0 */
2346}
2347
2360{
2361 uint8_t res;
2362 uint8_t prev;
2363
2364 if (handle == NULL) /* check handle */
2365 {
2366 return 2; /* return error */
2367 }
2368 if (handle->inited != 1) /* check handle initialization */
2369 {
2370 return 3; /* return error */
2371 }
2372
2373 res = a_bmp390_iic_spi_read(handle, BMP390_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2374 if (res != 0) /* check result */
2375 {
2376 handle->debug_print("bmp390: get osr register failed.\n"); /* get osr register failed */
2377
2378 return 1; /* return error */
2379 }
2380 *oversampling = (bmp390_oversampling_t)((prev >> 0) & 0x07); /* get config */
2381
2382 return 0; /* success return 0 */
2383}
2384
2397{
2398 uint8_t res;
2399 uint8_t prev;
2400
2401 if (handle == NULL) /* check handle */
2402 {
2403 return 2; /* return error */
2404 }
2405 if (handle->inited != 1) /* check handle initialization */
2406 {
2407 return 3; /* return error */
2408 }
2409
2410 res = a_bmp390_iic_spi_read(handle, BMP390_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2411 if (res != 0) /* check result */
2412 {
2413 handle->debug_print("bmp390: get osr register failed.\n"); /* get osr register failed */
2414
2415 return 1; /* return error */
2416 }
2417 prev &= ~(7 << 3); /* clear config */
2418 prev |= oversampling << 3; /* set config */
2419 res = a_bmp390_iic_spi_write(handle, BMP390_REG_OSR, (uint8_t *)&prev, 1); /* write config */
2420 if (res != 0) /* check result */
2421 {
2422 handle->debug_print("bmp390: set osr register failed.\n"); /* set osr register failed */
2423
2424 return 1; /* return error */
2425 }
2426
2427 return 0; /* success return 0 */
2428}
2429
2442{
2443 uint8_t res;
2444 uint8_t prev;
2445
2446 if (handle == NULL) /* check handle */
2447 {
2448 return 2; /* return error */
2449 }
2450 if (handle->inited != 1) /* check handle initialization */
2451 {
2452 return 3; /* return error */
2453 }
2454
2455 res = a_bmp390_iic_spi_read(handle, BMP390_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2456 if (res != 0) /* check result */
2457 {
2458 handle->debug_print("bmp390: get osr register failed.\n"); /* get osr register failed */
2459
2460 return 1; /* return error */
2461 }
2462 *oversampling = (bmp390_oversampling_t)((prev >> 3) & 0x07); /* get config */
2463
2464 return 0; /* success return 0 */
2465}
2466
2479{
2480 uint8_t res;
2481 uint8_t prev;
2482
2483 if (handle == NULL) /* check handle */
2484 {
2485 return 2; /* return error */
2486 }
2487 if (handle->inited != 1) /* check handle initialization */
2488 {
2489 return 3; /* return error */
2490 }
2491
2492 res = a_bmp390_iic_spi_read(handle, BMP390_REG_ODR, (uint8_t *)&prev, 1); /* read config */
2493 if (res != 0) /* check result */
2494 {
2495 handle->debug_print("bmp390: get odr register failed.\n"); /* get odr register failed */
2496
2497 return 1; /* return error */
2498 }
2499
2500 prev &= ~(31 << 0); /* clear config */
2501 prev |= odr << 0; /* set config */
2502 res = a_bmp390_iic_spi_write(handle, BMP390_REG_ODR, (uint8_t *)&prev, 1); /* write config */
2503 if (res != 0) /* check result */
2504 {
2505 handle->debug_print("bmp390: set odr register failed.\n"); /* set odr register failed */
2506
2507 return 1; /* return error */
2508 }
2509
2510 return 0; /* success return 0 */
2511}
2512
2525{
2526 uint8_t res;
2527 uint8_t prev;
2528
2529 if (handle == NULL) /* check handle */
2530 {
2531 return 2; /* return error */
2532 }
2533 if (handle->inited != 1) /* check handle initialization */
2534 {
2535 return 3; /* return error */
2536 }
2537
2538 res = a_bmp390_iic_spi_read(handle, BMP390_REG_ODR, (uint8_t *)&prev, 1); /* read config */
2539 if (res != 0) /* check result */
2540 {
2541 handle->debug_print("bmp390: get odr register failed.\n"); /* get odr register failed */
2542
2543 return 1; /* return error */
2544 }
2545 *odr = (bmp390_odr_t)((prev >> 0) & 31); /* get config */
2546
2547 return 0; /* success return 0 */
2548}
2549
2562{
2563 uint8_t res;
2564 uint8_t prev;
2565
2566 if (handle == NULL) /* check handle */
2567 {
2568 return 2; /* return error */
2569 }
2570 if (handle->inited != 1) /* check handle initialization */
2571 {
2572 return 3; /* return error */
2573 }
2574
2575 res = a_bmp390_iic_spi_read(handle, BMP390_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
2576 if (res != 0) /* check result */
2577 {
2578 handle->debug_print("bmp390: get config register failed.\n"); /* get config register failed */
2579
2580 return 1; /* return error */
2581 }
2582
2583 prev &= ~(0x7 << 1); /* clear config */
2584 prev |= coefficient << 1; /* set config */
2585 res = a_bmp390_iic_spi_write(handle, BMP390_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
2586 if (res != 0) /* check result */
2587 {
2588 handle->debug_print("bmp390: set config register failed.\n"); /* set config register failed */
2589
2590 return 1; /* return error */
2591 }
2592
2593 return 0; /* success return 0 */
2594}
2595
2608{
2609 uint8_t res;
2610 uint8_t prev;
2611
2612 if (handle == NULL) /* check handle */
2613 {
2614 return 2; /* return error */
2615 }
2616 if (handle->inited != 1) /* check handle initialization */
2617 {
2618 return 3; /* return error */
2619 }
2620
2621 res = a_bmp390_iic_spi_read(handle, BMP390_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
2622 if (res != 0) /* check result */
2623 {
2624 handle->debug_print("bmp390: get config register failed.\n"); /* return error */
2625
2626 return 1; /* return error */
2627 }
2628 *coefficient = (bmp390_filter_coefficient_t)((prev >> 1) & 0x07); /* get coefficient */
2629
2630 return 0; /* success return 0 */
2631}
2632
2644{
2645 uint8_t res;
2646 uint8_t prev;
2647
2648 if (handle == NULL) /* check handle */
2649 {
2650 return 2; /* return error */
2651 }
2652 if (handle->inited != 1) /* check handle initialization */
2653 {
2654 return 3; /* return error */
2655 }
2656
2657 prev = 0xB0; /* command */
2658 res = a_bmp390_iic_spi_write(handle, BMP390_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2659 if (res != 0) /* check result */
2660 {
2661 handle->debug_print("bmp390: set cmd register failed.\n"); /* set cmd register failed */
2662
2663 return 1; /* return error */
2664 }
2665
2666 return 0; /* success return 0 */
2667}
2668
2680{
2681 uint8_t res;
2682 uint8_t prev;
2683
2684 if (handle == NULL) /* check handle */
2685 {
2686 return 2; /* return error */
2687 }
2688 if (handle->inited != 1) /* check handle initialization */
2689 {
2690 return 3; /* return error */
2691 }
2692
2693 prev = 0xB6; /* command */
2694 res = a_bmp390_iic_spi_write(handle, BMP390_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2695 if (res != 0) /* check result */
2696 {
2697 handle->debug_print("bmp390: set cmd register failed.\n"); /* set cmd register failed */
2698
2699 return 1; /* return error */
2700 }
2701
2702 return 0; /* success return 0 */
2703}
2704
2715static uint8_t a_bmp390_close(bmp390_handle_t *handle)
2716{
2717 if (handle->iic_spi == BMP390_INTERFACE_IIC) /* if iic interface */
2718 {
2719 if (handle->iic_deinit() != 0) /* close iic */
2720 {
2721 handle->debug_print("bmp390: iic deinit failed.\n"); /* iic deinit failed */
2722
2723 return 1; /* return error */
2724 }
2725 else
2726 {
2727 return 0; /* success return 0 */
2728 }
2729 }
2730 else
2731 {
2732 if (handle->spi_deinit() != 0) /* close spi */
2733 {
2734 handle->debug_print("bmp390: spi deinit failed.\n"); /* spi deinit failed */
2735
2736 return 1; /* return error */
2737 }
2738 else
2739 {
2740 return 0; /* success return 0 */
2741 }
2742 }
2743}
2744
2759{
2760 uint8_t id;
2761 uint8_t reg;
2762
2763 if (handle == NULL) /* check handle */
2764 {
2765 return 2; /* return error */
2766 }
2767 if (handle->debug_print == NULL) /* check debug_print */
2768 {
2769 return 3; /* return error */
2770 }
2771 if (handle->iic_init == NULL) /* check iic_init */
2772 {
2773 handle->debug_print("bmp390: iic_init is null.\n"); /* iic_init is null */
2774
2775 return 3; /* return error */
2776 }
2777 if (handle->iic_deinit == NULL) /* check iic_init */
2778 {
2779 handle->debug_print("bmp390: iic_deinit is null.\n"); /* iic_deinit is null */
2780
2781 return 3; /* return error */
2782 }
2783 if (handle->iic_read == NULL) /* check iic_read */
2784 {
2785 handle->debug_print("bmp390: iic_read is null.\n"); /* iic_read is null */
2786
2787 return 3; /* return error */
2788 }
2789 if (handle->iic_write == NULL) /* check iic_write */
2790 {
2791 handle->debug_print("bmp390: iic_write is null.\n"); /* iic_write is null */
2792
2793 return 3; /* return error */
2794 }
2795 if (handle->spi_init == NULL) /* check spi_init */
2796 {
2797 handle->debug_print("bmp390: spi_init is null.\n"); /* spi_init is null */
2798
2799 return 3; /* return error */
2800 }
2801 if (handle->spi_deinit == NULL) /* check spi_deinit */
2802 {
2803 handle->debug_print("bmp390: spi_deinit is null.\n"); /* spi_deinit is null */
2804
2805 return 3; /* return error */
2806 }
2807 if (handle->spi_read == NULL) /* check spi_read */
2808 {
2809 handle->debug_print("bmp390: spi_read is null.\n"); /* spi_read is null */
2810
2811 return 3; /* return error */
2812 }
2813 if (handle->spi_write == NULL) /* check spi_write */
2814 {
2815 handle->debug_print("bmp390: spi_write is null.\n"); /* spi_write is null */
2816
2817 return 3; /* return error */
2818 }
2819 if (handle->delay_ms == NULL) /* check delay_ms */
2820 {
2821 handle->debug_print("bmp390: delay_ms is null.\n"); /* delay_ms is null */
2822
2823 return 3; /* return error */
2824 }
2825
2826 if (handle->iic_spi == BMP390_INTERFACE_IIC) /* if iic interface */
2827 {
2828 if (handle->iic_init() != 0) /* initialize iic bus */
2829 {
2830 handle->debug_print("bmp390: iic init failed.\n"); /* iic init failed */
2831
2832 return 1; /* return error */
2833 }
2834 }
2835 else
2836 {
2837 if (handle->spi_init() != 0) /* initialize spi bus */
2838 {
2839 handle->debug_print("bmp390: spi init failed.\n"); /* spi init failed */
2840
2841 return 1; /* return error */
2842 }
2843 }
2844 if (a_bmp390_iic_spi_read(handle, BMP390_REG_CHIP_ID, (uint8_t *)&id, 1) != 0) /* read chip id */
2845 {
2846 handle->debug_print("bmp390: read chip id failed.\n"); /* read chip id failed */
2847 (void)a_bmp390_close(handle); /* close bmp390 */
2848
2849 return 4; /* return error */
2850 }
2851 if (id != 0x60) /* check chip id */
2852 {
2853 handle->debug_print("bmp390: id is invalid.\n"); /* id is invalid */
2854 (void)a_bmp390_close(handle); /* close bmp390 */
2855
2856 return 4;
2857 } /* return error */
2858 reg = 0xB6; /* set command */
2859 if (a_bmp390_iic_spi_write(handle, BMP390_REG_CMD, (uint8_t *)&reg, 1) != 0) /* write command */
2860 {
2861 handle->debug_print("bmp390: soft rest failed.\n"); /* soft rest failed */
2862 (void)a_bmp390_close(handle); /* close bmp390 */
2863
2864 return 5; /* return error */
2865 }
2866 handle->delay_ms(10); /* delay 10 ms */
2867 if (a_bmp390_iic_spi_read(handle, BMP390_REG_ERR_REG, (uint8_t *)&reg, 1) != 0) /* read reg */
2868 {
2869 handle->debug_print("bmp390: get err reg failed.\n"); /* return error */
2870 (void)a_bmp390_close(handle); /* close bmp390 */
2871
2872 return 5; /* return error */
2873 }
2874 if ((reg & 0x07) != 0) /* check running status */
2875 {
2876 handle->debug_print("bmp390: find running error.\n"); /* find running error */
2877 (void)a_bmp390_close(handle); /* close bmp390 */
2878
2879 return 5; /* return error */
2880 }
2881 if (a_bmp390_get_calibration_data(handle) != 0) /* get calibration data */
2882 {
2883 handle->debug_print("bmp390: get calibration data error.\n"); /* get calibration data error */
2884 (void)a_bmp390_close(handle); /* close bmp390 */
2885
2886 return 6; /* return error */
2887 }
2888 handle->inited = 1; /* flag finish initialization */
2889
2890 return 0; /* success return 0 */
2891}
2892
2905{
2906 uint8_t res;
2907 uint8_t prev;
2908
2909 if (handle == NULL) /* check handle */
2910 {
2911 return 2; /* return error */
2912 }
2913 if (handle->inited != 1) /* check handle initialization */
2914 {
2915 return 3; /* return error */
2916 }
2917
2918 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2919 if (res != 0) /* check result */
2920 {
2921 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2922
2923 return 4; /* return error */
2924 }
2925 prev &= ~(3 << 0); /* clear config */
2926 prev &= ~(3 << 4); /* set config */
2927 res = a_bmp390_iic_spi_write(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2928 if (res != 0) /* check result */
2929 {
2930 handle->debug_print("bmp390: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2931
2932 return 4; /* return error */
2933 }
2934 if (a_bmp390_close(handle) != 0) /* close bmp390 */
2935 {
2936 return 1; /* return error */
2937 }
2938 else
2939 {
2940 handle->inited = 0; /* flag close */
2941
2942 return 0; /* success return 0 */
2943 }
2944}
2945
2958uint8_t bmp390_read_temperature(bmp390_handle_t *handle, uint32_t *raw, float *c)
2959{
2960 uint8_t res;
2961 uint8_t prev;
2962 uint8_t buf[3];
2963
2964 if (handle == NULL) /* check handle */
2965 {
2966 return 2; /* return error */
2967 }
2968 if (handle->inited != 1) /* check handle initialization */
2969 {
2970 return 3; /* return error */
2971 }
2972
2973 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
2974 if (res != 0) /* check result */
2975 {
2976 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
2977
2978 return 1; /* return error */
2979 }
2980 if ((prev & 0x01) != 0) /* check mode */
2981 {
2982 handle->debug_print("bmp390: fifo mode can't use this function.\n"); /* fifo mode can't use this function */
2983
2984 return 1; /* return error */
2985 }
2986 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read pwr ctrl */
2987 if (res != 0) /* check result */
2988 {
2989 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2990
2991 return 1; /* return error */
2992 }
2993 if (((prev >> 4) & 0x03) == 0x03) /* normal mode */
2994 {
2995 res = a_bmp390_iic_spi_read(handle, BMP390_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
2996 if (res != 0) /* check result */
2997 {
2998 handle->debug_print("bmp390: get status register failed.\n"); /* get status register failed */
2999
3000 return 1; /* return error */
3001 }
3002 if ((prev & (1 << 6)) != 0) /* data is ready */
3003 {
3004 int64_t output;
3005
3006 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3007 if (res != 0) /* check result */
3008 {
3009 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3010
3011 return 1; /* return error */
3012 }
3013 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3014 output = a_bmp390_compensate_temperature(handle, *raw); /* compensate temperature */
3015 *c = (float)((double)output / 100.0); /* get converted temperature */
3016
3017 return 0; /* success return 0 */
3018
3019 }
3020 else
3021 {
3022 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3023
3024 return 1; /* return error */
3025 }
3026 }
3027 else if (((prev >> 4) & 0x03) == 0x00) /* force mode */
3028 {
3029 uint16_t cnt = 5000;
3030
3031 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3032 if (res != 0) /* check result */
3033 {
3034 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3035
3036 return 1; /* return error */
3037 }
3038 prev &= ~(0x03 << 4); /* clear 4-5 bits */
3039 prev |= 0x01 << 4; /* set bit 4 */
3040 res = a_bmp390_iic_spi_write(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3041 if (res != 0) /* check result */
3042 {
3043 handle->debug_print("bmp390: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
3044
3045 return 1; /* return error */
3046 }
3047
3048 while (1) /* loop */
3049 {
3050 res = a_bmp390_iic_spi_read(handle, BMP390_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
3051 if (res != 0) /* check result */
3052 {
3053 handle->debug_print("bmp390: get status register failed.\n"); /* get status register failed */
3054
3055 return 1; /* return error */
3056 }
3057 if ((prev & (1 << 6)) != 0) /* data is ready */
3058 {
3059 int64_t output;
3060
3061 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3062 if (res != 0) /* check result */
3063 {
3064 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3065
3066 return 1; /* return error */
3067 }
3068 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3069 output = a_bmp390_compensate_temperature(handle, *raw); /* compensate temperature */
3070 *c = (float)((double)output / 100.0); /* get converted temperature */
3071
3072 return 0; /* success return 0 */
3073
3074 }
3075 else
3076 {
3077 if (cnt != 0) /* check cnt */
3078 {
3079 cnt--; /* cnt-- */
3080 handle->delay_ms(1); /* delay 1 ms */
3081
3082 continue; /* continue */
3083 }
3084 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3085
3086 return 1; /* return error */
3087 }
3088 }
3089 }
3090 else
3091 {
3092 handle->debug_print("bmp390: mode is invalid.\n"); /* mode is invalid */
3093
3094 return 1; /* return error */
3095 }
3096}
3097
3110uint8_t bmp390_read_pressure(bmp390_handle_t *handle, uint32_t *raw, float *pa)
3111{
3112 uint8_t res;
3113 uint8_t prev;
3114 uint8_t buf[3];
3115 uint32_t temperature_raw;
3116
3117 if (handle == NULL) /* check handle */
3118 {
3119 return 2; /* return error */
3120 }
3121 if (handle->inited != 1) /* check handle initialization */
3122 {
3123 return 3; /* return error */
3124 }
3125
3126 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3127 if (res != 0) /* check result */
3128 {
3129 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
3130
3131 return 1; /* return error */
3132 }
3133 if ((prev & 0x01) != 0) /* check mode */
3134 {
3135 handle->debug_print("bmp390: fifo mode can't use this function.\n"); /* fifo mode can't use this function */
3136
3137 return 1; /* return error */
3138 }
3139 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3140 if (res != 0) /* check result */
3141 {
3142 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3143
3144 return 1; /* return error */
3145 }
3146 if (((prev >> 4) & 0x03) == 0x03) /* normal mode */
3147 {
3148 res = a_bmp390_iic_spi_read(handle, BMP390_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
3149 if (res != 0) /* check result */
3150 {
3151 handle->debug_print("bmp390: get status register failed.\n"); /* get status register failed */
3152
3153 return 1; /* return error */
3154 }
3155 if ((prev & (1 << 6)) != 0) /* data is ready */
3156 {
3157 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_3, (uint8_t *)buf, 3); /* read config */
3158 if (res != 0) /* check result */
3159 {
3160 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3161
3162 return 1; /* return error */
3163 }
3164 temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3165 (void)a_bmp390_compensate_temperature(handle, temperature_raw); /* compensate temperature */
3166 }
3167 else
3168 {
3169 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3170
3171 return 1; /* return error */
3172 }
3173 if ((prev & (1 << 5)) != 0) /* data is ready */
3174 {
3175 int64_t output;
3176
3177 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_0, (uint8_t *)buf, 3); /* read config */
3178 if (res != 0) /* check result */
3179 {
3180 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3181
3182 return 1; /* return error */
3183 }
3184 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3185 output = a_bmp390_compensate_pressure(handle, *raw); /* compensate pressure */
3186 *pa = (float)((double)output / 100.0); /* get converted pressure */
3187
3188 return 0; /* success return 0 */
3189 }
3190 else
3191 {
3192 handle->debug_print("bmp390: pressure data is not ready.\n"); /* pressure data is not ready */
3193
3194 return 1; /* return error */
3195 }
3196 }
3197 else if (((prev >> 4) & 0x03) == 0x00) /* force mode */
3198 {
3199 uint16_t cnt = 5000;
3200
3201 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3202 if (res != 0) /* check result */
3203 {
3204 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3205
3206 return 1; /* return error */
3207 }
3208 prev &= ~(0x03 << 4); /* clear 4-5 bits */
3209 prev |= 0x01 << 4; /* set 4 bit */
3210 res = a_bmp390_iic_spi_write(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3211 if (res != 0) /* check result */
3212 {
3213 handle->debug_print("bmp390: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
3214
3215 return 1; /* return error */
3216 }
3217
3218 while (1) /* loop */
3219 {
3220 res = a_bmp390_iic_spi_read(handle, BMP390_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3221 if (res != 0) /* check result */
3222 {
3223 handle->debug_print("bmp390: get status register failed.\n"); /* get status register failed */
3224
3225 return 1; /* return error */
3226 }
3227 if ((prev & (1 << 6)) != 0) /* data is ready */
3228 {
3229 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3230 if (res != 0) /* check result */
3231 {
3232 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3233
3234 return 1; /* return error */
3235 }
3236 temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3237 (void)a_bmp390_compensate_temperature(handle, temperature_raw); /* compensate temperature */
3238
3239 goto press; /* goto press */
3240 }
3241 else
3242 {
3243 if (cnt != 0) /* check cnt */
3244 {
3245 cnt--; /* cnt-- */
3246 handle->delay_ms(1); /* delay 1 ms */
3247
3248 continue; /* continue */
3249 }
3250 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3251
3252 return 1; /* return error */
3253 }
3254
3255 press:
3256
3257 cnt = 5000; /* set cnt 5000 */
3258 if ((prev & (1 << 5)) != 0) /* data is ready */
3259 {
3260 int64_t output;
3261
3262 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_0, (uint8_t *)buf, 3); /* read config */
3263 if (res != 0) /* check result */
3264 {
3265 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3266
3267 return 1; /* return error */
3268 }
3269 *raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3270 output = a_bmp390_compensate_pressure(handle, *raw); /* compensate pressure */
3271 *pa = (float)((double)output / 100.0); /* get converted pressure */
3272
3273 return 0; /* success return 0 */
3274 }
3275 else
3276 {
3277 if (cnt != 0) /* check cnt */
3278 {
3279 cnt--; /* cnt-- */
3280 handle->delay_ms(1); /* delay 1 ms */
3281
3282 continue; /* continue */
3283 }
3284 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3285
3286 return 1; /* return error */
3287 }
3288 }
3289 }
3290 else
3291 {
3292 handle->debug_print("bmp390: mode is invalid.\n"); /* mode is invalid */
3293
3294 return 1; /* return error */
3295 }
3296}
3297
3312uint8_t bmp390_read_temperature_pressure(bmp390_handle_t *handle, uint32_t *temperature_raw, float *temperature_c,
3313 uint32_t *pressure_raw, float *pressure_pa)
3314{
3315 uint8_t res;
3316 uint8_t prev;
3317 uint8_t buf[3];
3318
3319 if (handle == NULL) /* check handle */
3320 {
3321 return 2; /* return error */
3322 }
3323 if (handle->inited != 1) /* check handle initialization */
3324 {
3325 return 3; /* return error */
3326 }
3327
3328 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3329 if (res != 0) /* check result */
3330 {
3331 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
3332
3333 return 1; /* return error */
3334 }
3335 if ((prev & 0x01) != 0) /* check fifo mode */
3336 {
3337 handle->debug_print("bmp390: fifo mode can't use this function.\n"); /* fifo mode can't use this function */
3338
3339 return 1; /* return error */
3340 }
3341 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3342 if (res != 0) /* check result */
3343 {
3344 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3345
3346 return 1; /* return error */
3347 }
3348 if (((prev >> 4) & 0x03) == 0x03) /* normal mode */
3349 {
3350 res = a_bmp390_iic_spi_read(handle, BMP390_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3351 if (res != 0) /* check result */
3352 {
3353 handle->debug_print("bmp390: get status register failed.\n"); /* get status register failed */
3354
3355 return 1; /* return error */
3356 }
3357 if ((prev & (1 << 6)) != 0) /* data is ready */
3358 {
3359 int64_t output;
3360
3361 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3362 if (res != 0) /* check result */
3363 {
3364 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3365
3366 return 1; /* return error */
3367 }
3368 *temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3369 output = a_bmp390_compensate_temperature(handle, *temperature_raw); /* compensate temperature */
3370 *temperature_c = (float)((double)output / 100.0); /* get converted temperature */
3371 }
3372 else
3373 {
3374 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3375
3376 return 1; /* return error */
3377 }
3378 if ((prev & (1 << 5)) != 0) /* data is ready */
3379 {
3380 int64_t output;
3381
3382 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_0, (uint8_t *)buf, 3); /* read data */
3383 if (res != 0) /* check result */
3384 {
3385 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3386
3387 return 1; /* return error */
3388 }
3389 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3390 output = a_bmp390_compensate_pressure(handle, *pressure_raw); /* compensate pressure */
3391 *pressure_pa = (float)((double)output / 100.0); /* get converted pressure */
3392
3393 return 0; /* success return 0 */
3394 }
3395 else
3396 {
3397 handle->debug_print("bmp390: pressure data is not ready.\n"); /* pressure data is not ready */
3398
3399 return 1; /* return error */
3400 }
3401 }
3402 else if (((prev >> 4) & 0x03) == 0x00) /* force mode */
3403 {
3404 uint16_t cnt = 5000;
3405
3406 res = a_bmp390_iic_spi_read(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3407 if (res != 0) /* check result */
3408 {
3409 handle->debug_print("bmp390: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
3410
3411 return 1; /* return error */
3412 }
3413 prev &= ~(0x03 << 4); /* clear 4-5 bits */
3414 prev |= 0x01 << 4; /* set bit 4 */
3415 res = a_bmp390_iic_spi_write(handle, BMP390_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
3416 if (res != 0) /* check result */
3417 {
3418 handle->debug_print("bmp390: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
3419
3420 return 1; /* return error */
3421 }
3422
3423 while (1) /* loop */
3424 {
3425 res = a_bmp390_iic_spi_read(handle, BMP390_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3426 if (res != 0) /* check result */
3427 {
3428 handle->debug_print("bmp390: get status register failed.\n"); /* get status register failed */
3429
3430 return 1; /* return error */
3431 }
3432 if ((prev & (1 << 6)) != 0) /* data is ready */
3433 {
3434 int64_t output;
3435
3436 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3437 if (res != 0) /* check result */
3438 {
3439 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3440
3441 return 1; /* return error */
3442 }
3443 *temperature_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3444 output = a_bmp390_compensate_temperature(handle, *temperature_raw); /* compensate temperature */
3445 *temperature_c = (float)((double)output / 100.0); /* get converted temperature */
3446
3447 break; /* break */
3448 }
3449 else
3450 {
3451 if (cnt != 0) /* check cnt */
3452 {
3453 cnt--; /* cnt-- */
3454 handle->delay_ms(1); /* delay 1 ms */
3455
3456 continue; /* continue */
3457 }
3458 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3459
3460 return 1; /* return error */
3461 }
3462 }
3463 cnt = 5000; /* set cnt */
3464
3465 while (1) /* loop */
3466 {
3467 if ((prev & (1 << 5)) != 0) /* data is ready */
3468 {
3469 int64_t output;
3470
3471 res = a_bmp390_iic_spi_read(handle, BMP390_REG_DATA_0, (uint8_t *)buf, 3); /* read raw data */
3472 if (res != 0) /* check result */
3473 {
3474 handle->debug_print("bmp390: get data register failed.\n"); /* get data register failed */
3475
3476 return 1; /* return error */
3477 }
3478 *pressure_raw = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get data */
3479 output = a_bmp390_compensate_pressure(handle, *pressure_raw); /* compensate pressure */
3480 *pressure_pa = (float)((double)output / 100.0); /* get converted pressure */
3481
3482 return 0; /* success return 0 */
3483 }
3484 else
3485 {
3486 if (cnt != 0) /* check cnt */
3487 {
3488 cnt--; /* cnt-- */
3489 handle->delay_ms(1); /* delay 1 ms */
3490
3491 continue; /* continue */
3492 }
3493 handle->debug_print("bmp390: temperature data is not ready.\n"); /* temperature data is not ready */
3494
3495 return 1; /* return error */
3496 }
3497 }
3498 }
3499 else
3500 {
3501 handle->debug_print("bmp390: mode is invalid.\n"); /* mode is invalid */
3502
3503 return 1; /* return error */
3504 }
3505}
3506
3518{
3519 uint8_t res;
3520 uint8_t status;
3521
3522 if (handle == NULL) /* check handle */
3523 {
3524 return 2; /* return error */
3525 }
3526 if (handle->inited != 1) /* check handle initialization */
3527 {
3528 return 3; /* return error */
3529 }
3530
3531 res = a_bmp390_iic_spi_read(handle, BMP390_REG_INT_STATUS, (uint8_t *)&status, 1); /* read config */
3532 if (res != 0) /* check result */
3533 {
3534 handle->debug_print("bmp390: get interrupt status register failed.\n"); /* get interrupt status register failed */
3535
3536 return 1; /* return error */
3537 }
3538 if ((status & (1 << 1)) != 0) /* if fifo full */
3539 {
3540 if(handle->receive_callback != NULL) /* if receive callback is valid */
3541 {
3542 handle->receive_callback(BMP390_INTERRUPT_STATUS_FIFO_FULL); /* run receive callback */
3543 }
3544 }
3545 if ((status & (1 << 0)) != 0) /* if fifo watermark */
3546 {
3547 if(handle->receive_callback != NULL) /* if receive callback is valid */
3548 {
3549 handle->receive_callback(BMP390_INTERRUPT_STATUS_FIFO_WATERMARK); /* run receive callback */
3550 }
3551 }
3552 if ((status & (1 << 3)) != 0) /* if data ready */
3553 {
3554 if (handle->receive_callback != NULL) /* if receive callback is valid */
3555 {
3556 handle->receive_callback(BMP390_INTERRUPT_STATUS_DATA_READY); /* run receive callback */
3557 }
3558 }
3559
3560 return 0; /* success return 0 */
3561}
3562
3573{
3574 if (handle == NULL) /* check handle */
3575 {
3576 return 2; /* return error */
3577 }
3578
3579 handle->iic_addr = (uint8_t)addr_pin; /* set iic address */
3580
3581 return 0; /* success return 0 */
3582}
3583
3594{
3595 if (handle == NULL) /* check handle */
3596 {
3597 return 2; /* return error */
3598 }
3599
3600 *addr_pin = (bmp390_address_t)handle->iic_addr; /* get iic address */
3601
3602 return 0; /* success return 0 */
3603}
3604
3615{
3616 if (handle == NULL) /* check handle */
3617 {
3618 return 2; /* return error */
3619 }
3620
3621 handle->iic_spi = (uint8_t)interface; /* set interface */
3622
3623 return 0; /* success return 0 */
3624}
3625
3636{
3637 if (handle == NULL) /* check handle */
3638 {
3639 return 2; /* return error */
3640 }
3641
3642 *interface = (bmp390_interface_t)(handle->iic_spi); /* get interface */
3643
3644 return 0; /* success return 0 */
3645}
3646
3659uint8_t bmp390_read_fifo(bmp390_handle_t *handle, uint8_t *buf, uint16_t *len)
3660{
3661 uint8_t res;
3662 uint8_t prev;
3663 uint8_t tmp_buf[2];
3664 uint16_t length;
3665
3666 if (handle == NULL) /* check handle */
3667 {
3668 return 2; /* return error */
3669 }
3670 if (handle->inited != 1) /* check handle initialization */
3671 {
3672 return 3; /* return error */
3673 }
3674
3675 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3676 if (res != 0) /* check result */
3677 {
3678 handle->debug_print("bmp390: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
3679
3680 return 1; /* return error */
3681 }
3682 if ((prev & 0x01) != 0) /* check mode */
3683 {
3684 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_LENGTH_0, (uint8_t *)tmp_buf, 2); /* read config */
3685 if (res != 0) /* check result */
3686 {
3687 handle->debug_print("bmp390: get fifo length register failed.\n"); /* get fifo length register failed */
3688
3689 return 1; /* return error */
3690 }
3691 length = ((uint16_t)(tmp_buf[1] & 0x01) << 8) | tmp_buf[0]; /* get data */
3692 if ((prev & (1 << 2)) != 0) /* if include sensor time */
3693 {
3694 length += 4; /* add sensor time length */
3695 }
3696 *len = (*len) < length ? (*len) :length; /* get real length */
3697 res = a_bmp390_iic_spi_read(handle, BMP390_REG_FIFO_DATA, (uint8_t *)buf, *len); /* read config */
3698 if (res != 0) /* check result */
3699 {
3700 handle->debug_print("bmp390: get fifo data failed.\n"); /* get fifo data failed */
3701
3702 return 1; /* return error */
3703 }
3704
3705 return 0; /* success return 0 */
3706 }
3707 else
3708 {
3709 handle->debug_print("bmp390: normal mode or forced mode can't use this function.\n"); /* normal mode or forced mode can't use this function */
3710
3711 return 1; /* return error */
3712 }
3713}
3714
3729uint8_t bmp390_fifo_parse(bmp390_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp390_frame_t *frame, uint16_t *frame_len)
3730{
3731 uint8_t res;
3732 uint16_t i;
3733 uint16_t frame_total;
3734
3735 if (handle == NULL) /* check handle */
3736 {
3737 return 2; /* return error */
3738 }
3739 if (handle->inited != 1) /* check handle initialization */
3740 {
3741 return 3; /* return error */
3742 }
3743
3744 if (buf_len == 0) /* check buffer length */
3745 {
3746 handle->debug_print("bmp390: buffer length is invalid.\n"); /* buffer length is invalid */
3747
3748 return 1; /* return error */
3749 }
3750 frame_total = 0; /* clear total frame */
3751 res = 0; /* set 0 */
3752 i = 0; /* set 0 */
3753 while (i < buf_len) /* loop */
3754 {
3755 switch ((uint8_t)buf[i])
3756 {
3757 case 0x90 :
3758 {
3759 if (frame_total > ((*frame_len)-1)) /* check length */
3760 {
3761 return 0; /* return success */
3762 }
3763 frame[frame_total].type = BMP390_FRAME_TYPE_TEMPERATURE; /* set temperature type */
3764 frame[frame_total].raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1]; /* set raw */
3765 frame[frame_total].data = (float)((double)a_bmp390_compensate_temperature(handle, frame[frame_total].raw) / 100.0); /* set compensate temperature */
3766 frame_total++; /* frame++ */
3767 i += 4; /* index + 4 */
3768
3769 break; /* break */
3770 }
3771 case 0x94 :
3772 {
3773 if ((frame_total) > ((*frame_len)-1)) /* check length */
3774 {
3775 return 0; /* return success */
3776 }
3777 frame[frame_total].type = BMP390_FRAME_TYPE_TEMPERATURE; /* set temperature type */
3778 frame[frame_total].raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1]; /* set raw */
3779 frame[frame_total].data = (float)((double)a_bmp390_compensate_temperature(handle, frame[frame_total].raw) / 100.0); /* set compensate temperature */
3780 frame_total++; /* frame++ */
3781 if (frame_total > ((*frame_len)-1)) /* check length */
3782 {
3783 return 0; /* return success */
3784 }
3785 frame[frame_total].type = BMP390_FRAME_TYPE_PRESSURE; /* set pressure type */
3786 frame[frame_total].raw = (uint32_t)buf[i + 5 + 1] << 16 | (uint32_t)buf[i + 4 + 1] << 8 | buf[i + 3 + 1]; /* set raw */
3787 frame[frame_total].data = (float)((double)a_bmp390_compensate_pressure(handle, frame[frame_total].raw) / 100.0); /* set compensate pressure */
3788 frame_total++; /* frame++ */
3789 i += 7; /* index + 7 */
3790
3791 break; /* break */
3792 }
3793 case 0xA0 :
3794 {
3795 if (frame_total > ((*frame_len)-1)) /* check length */
3796 {
3797 return 0; /* return success */
3798 }
3799 frame[frame_total].type = BMP390_FRAME_TYPE_SENSORTIME; /* set sensor time type */
3800 frame[frame_total].raw = (uint32_t)buf[i + 2 + 1] << 16 | (uint32_t)buf[i + 1 + 1] << 8 | buf[i + 0 + 1]; /* set raw */
3801 frame[frame_total].data = 0; /* set data */
3802 frame_total++; /* frame++ */
3803 i += 4; /* index+4 */
3804
3805 break; /* break */
3806 }
3807 case 0x80 : /* fifo empty */
3808 {
3809 i += 2; /* index+2 */
3810
3811 break; /* break */
3812 }
3813 case 0x48 : /* fifo input config */
3814 {
3815 i += 2; /* index+2 */
3816
3817 break; /* break */
3818 }
3819 case 0x44 : /* config error */
3820 {
3821 i += 2; /* index+2 */
3822
3823 break; /* break */
3824 }
3825 default :
3826 {
3827 handle->debug_print("bmp390: header is invalid.\n"); /* header is invalid */
3828 res = 1; /* set 1 */
3829
3830 break; /* break */
3831 }
3832 }
3833 if (res == 1) /* check the result */
3834 {
3835 return 1; /* return error */
3836 }
3837 }
3838 *frame_len = frame_total; /* set frame length */
3839
3840 return 0; /* success return 0 */
3841}
3842
3855uint8_t bmp390_set_reg(bmp390_handle_t *handle, uint8_t reg, uint8_t value)
3856{
3857 if (handle == NULL) /* check handle */
3858 {
3859 return 2; /* return error */
3860 }
3861 if (handle->inited != 1) /* check handle initialization */
3862 {
3863 return 3; /* return error */
3864 }
3865
3866 return a_bmp390_iic_spi_write(handle, reg, &value, 1); /* write register */
3867}
3868
3881uint8_t bmp390_get_reg(bmp390_handle_t *handle, uint8_t reg, uint8_t *value)
3882{
3883 if (handle == NULL) /* check handle */
3884 {
3885 return 2; /* return error */
3886 }
3887 if (handle->inited != 1) /* check handle initialization */
3888 {
3889 return 3; /* return error */
3890 }
3891
3892 return a_bmp390_iic_spi_read(handle, reg, value, 1); /* read register */
3893}
3894
3904{
3905 if (info == NULL) /* check handle */
3906 {
3907 return 2; /* return error */
3908 }
3909
3910 memset(info, 0, sizeof(bmp390_info_t)); /* initialize bmp390 info structure */
3911 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
3912 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
3913 strncpy(info->interface, "IIC SPI", 8); /* copy interface name */
3914 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
3915 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
3916 info->max_current_ma = MAX_CURRENT; /* set maximum current */
3917 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
3918 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
3919 info->driver_version = DRIVER_VERSION; /* set driver version */
3920
3921 return 0; /* success return 0 */
3922}
#define BMP390_REG_NVM_PAR_T1_L
#define BMP390_REG_FIFO_CONFIG_1
#define MAX_CURRENT
#define BMP390_REG_NVM_PAR_P4
#define BMP390_REG_NVM_PAR_P5_L
#define BMP390_REG_OSR
#define BMP390_REG_FIFO_CONFIG_2
#define BMP390_REG_DATA_0
#define BMP390_REG_NVM_PAR_P8
#define BMP390_REG_NVM_PAR_P1_L
#define BMP390_REG_STATUS
#define BMP390_REG_NVM_PAR_P3
#define SUPPLY_VOLTAGE_MAX
#define BMP390_REG_SENSORTIME_0
#define BMP390_REG_NVM_PAR_P7
#define BMP390_REG_NVM_PAR_P10
#define BMP390_REG_NVM_PAR_P11
#define BMP390_REG_IF_CONF
#define TEMPERATURE_MAX
#define BMP390_REG_NVM_PAR_T3
#define BMP390_REG_NVM_PAR_T2_L
#define BMP390_REG_FIFO_DATA
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define BMP390_REG_INT_STATUS
#define BMP390_REG_NVM_PAR_P6_L
#define BMP390_REG_PWR_CTRL
#define BMP390_REG_ODR
#define BMP390_REG_EVENT
#define BMP390_REG_INT_CTRL
#define BMP390_REG_CONFIG
#define CHIP_NAME
chip information definition
#define BMP390_REG_NVM_PAR_P2_L
#define BMP390_REG_ERR_REG
#define DRIVER_VERSION
#define BMP390_REG_FIFO_LENGTH_0
#define BMP390_REG_CHIP_ID
#define BMP390_REG_NVM_PAR_P9_L
#define BMP390_REG_REV_ID
#define BMP390_REG_FIFO_WTM_0
#define BMP390_REG_CMD
chip register definition
#define BMP390_REG_DATA_3
driver bmp390 header file
uint8_t bmp390_set_temperature_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the temperature oversampling
uint8_t bmp390_get_pressure_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t *oversampling)
get the pressure oversampling
uint8_t bmp390_get_pressure(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the pressure status
uint8_t bmp390_set_pressure(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the pressure
uint8_t bmp390_set_mode(bmp390_handle_t *handle, bmp390_mode_t mode)
set the chip mode
bmp390_interface_t
bmp390 interface enumeration definition
bmp390_event_t
bmp390 event enumeration definition
uint8_t bmp390_get_odr(bmp390_handle_t *handle, bmp390_odr_t *odr)
get the output data rate
uint8_t bmp390_set_temperature(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the temperature
uint8_t bmp390_get_temperature_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t *oversampling)
get the temperature oversampling
uint8_t bmp390_read_temperature(bmp390_handle_t *handle, uint32_t *raw, float *c)
read the temperature
bmp390_interrupt_active_level_t
bmp390 interrupt active level enumeration definition
uint8_t bmp390_read_pressure(bmp390_handle_t *handle, uint32_t *raw, float *pa)
read the pressure
bmp390_fifo_data_source_t
bmp390 fifo data source enumeration definition
uint8_t bmp390_info(bmp390_info_t *info)
get chip's information
uint8_t bmp390_get_addr_pin(bmp390_handle_t *handle, bmp390_address_t *addr_pin)
get the iic address pin
bmp390_oversampling_t
bmp390 oversampling enumeration definition
uint8_t bmp390_get_status(bmp390_handle_t *handle, uint8_t *status)
get the status
uint8_t bmp390_get_spi_wire(bmp390_handle_t *handle, bmp390_spi_wire_t *wire)
get the spi wire
uint8_t bmp390_get_mode(bmp390_handle_t *handle, bmp390_mode_t *mode)
get the chip mode
uint8_t bmp390_get_error(bmp390_handle_t *handle, uint8_t *err)
get the error
bmp390_interrupt_pin_type_t
bmp390 interrupt pin type enumeration definition
uint8_t bmp390_set_addr_pin(bmp390_handle_t *handle, bmp390_address_t addr_pin)
set the iic address pin
uint8_t bmp390_get_revision_id(bmp390_handle_t *handle, uint8_t *id)
get the revision id
uint8_t bmp390_get_iic_watchdog_period(bmp390_handle_t *handle, bmp390_iic_watchdog_period_t *period)
get the iic watchdog period
struct bmp390_frame_s bmp390_frame_t
bmp390 frame structure definition
uint8_t bmp390_read_temperature_pressure(bmp390_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
bmp390_bool_t
bmp390 bool enumeration definition
bmp390_filter_coefficient_t
bmp390 filter coefficient enumeration definition
uint8_t bmp390_set_odr(bmp390_handle_t *handle, bmp390_odr_t odr)
set the output data rate
uint8_t bmp390_init(bmp390_handle_t *handle)
initialize the chip
bmp390_odr_t
bmp390 output data rate enumeration definition
uint8_t bmp390_set_iic_watchdog_timer(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the iic watchdog timer
bmp390_iic_watchdog_period_t
bmp390 iic watchdog period enumeration definition
uint8_t bmp390_irq_handler(bmp390_handle_t *handle)
irq handler
bmp390_spi_wire_t
bmp390 spi wire enumeration definition
uint8_t bmp390_set_pressure_oversampling(bmp390_handle_t *handle, bmp390_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp390_set_iic_watchdog_period(bmp390_handle_t *handle, bmp390_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp390_get_filter_coefficient(bmp390_handle_t *handle, bmp390_filter_coefficient_t *coefficient)
get the filter coefficient
uint8_t bmp390_get_event(bmp390_handle_t *handle, bmp390_event_t *event)
get the event
uint8_t bmp390_deinit(bmp390_handle_t *handle)
close the chip
uint8_t bmp390_get_interface(bmp390_handle_t *handle, bmp390_interface_t *interface)
get the interface
uint8_t bmp390_get_temperature(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the temperature status
uint8_t bmp390_get_sensortime(bmp390_handle_t *handle, uint32_t *t)
get the sensor time
uint8_t bmp390_set_interface(bmp390_handle_t *handle, bmp390_interface_t interface)
set the interface
bmp390_address_t
bmp390 address enumeration definition
uint8_t bmp390_get_iic_watchdog_timer(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the iic watchdog timer status
uint8_t bmp390_softreset(bmp390_handle_t *handle)
soft reset
uint8_t bmp390_set_spi_wire(bmp390_handle_t *handle, bmp390_spi_wire_t wire)
set the spi wire
uint8_t bmp390_set_filter_coefficient(bmp390_handle_t *handle, bmp390_filter_coefficient_t coefficient)
set the filter coefficient
struct bmp390_info_s bmp390_info_t
bmp390 information structure definition
struct bmp390_handle_s bmp390_handle_t
bmp390 handle structure definition
bmp390_mode_t
bmp390 mode enumeration definition
@ BMP390_INTERRUPT_STATUS_FIFO_FULL
@ BMP390_INTERRUPT_STATUS_DATA_READY
@ BMP390_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP390_INTERFACE_IIC
@ BMP390_FRAME_TYPE_TEMPERATURE
@ BMP390_FRAME_TYPE_PRESSURE
@ BMP390_FRAME_TYPE_SENSORTIME
uint8_t bmp390_set_reg(bmp390_handle_t *handle, uint8_t reg, uint8_t value)
set the chip register
uint8_t bmp390_get_reg(bmp390_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
uint8_t bmp390_fifo_parse(bmp390_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp390_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp390_set_fifo_data_source(bmp390_handle_t *handle, bmp390_fifo_data_source_t source)
set the fifo data source
uint8_t bmp390_get_fifo(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo status
uint8_t bmp390_set_fifo_pressure_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp390_get_fifo_pressure_on(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo pressure on status
uint8_t bmp390_set_fifo_temperature_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp390_get_fifo_stop_on_full(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo stopping on full status
uint8_t bmp390_set_fifo(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo
uint8_t bmp390_get_fifo_data_source(bmp390_handle_t *handle, bmp390_fifo_data_source_t *source)
get the fifo data source
uint8_t bmp390_read_fifo(bmp390_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp390_get_fifo_watermark(bmp390_handle_t *handle, uint16_t *watermark)
get the fifo watermark
uint8_t bmp390_get_fifo_subsampling(bmp390_handle_t *handle, uint8_t *subsample)
get the fifo subsampling
uint8_t bmp390_set_fifo_sensortime_on(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp390_set_fifo_subsampling(bmp390_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp390_flush_fifo(bmp390_handle_t *handle)
flush the fifo
uint8_t bmp390_set_fifo_stop_on_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp390_set_fifo_watermark(bmp390_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp390_get_fifo_data(bmp390_handle_t *handle, uint8_t *data, uint16_t length)
get the fifo data
uint8_t bmp390_get_fifo_sensortime_on(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo sensor time on status
uint8_t bmp390_get_fifo_temperature_on(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the fifo temperature on status
uint8_t bmp390_get_fifo_length(bmp390_handle_t *handle, uint16_t *length)
get the fifo length
uint8_t bmp390_get_interrupt_fifo_watermark(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the interrupt fifo watermark
uint8_t bmp390_get_interrupt_fifo_full(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the interrupt fifo full
uint8_t bmp390_set_interrupt_fifo_watermark(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp390_get_interrupt_active_level(bmp390_handle_t *handle, bmp390_interrupt_active_level_t *level)
get the interrupt active level
uint8_t bmp390_get_interrupt_data_ready(bmp390_handle_t *handle, bmp390_bool_t *enable)
get the interrupt data ready status
uint8_t bmp390_set_interrupt_data_ready(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp390_get_latch_interrupt_pin_and_interrupt_status(bmp390_handle_t *handle, bmp390_bool_t *enable)
get latching interrupt pin and interrupt status
uint8_t bmp390_get_interrupt_status(bmp390_handle_t *handle, uint8_t *status)
get the interrupt status
uint8_t bmp390_get_interrupt_pin_type(bmp390_handle_t *handle, bmp390_interrupt_pin_type_t *pin_type)
get the interrupt pin type
uint8_t bmp390_set_latch_interrupt_pin_and_interrupt_status(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp390_set_interrupt_pin_type(bmp390_handle_t *handle, bmp390_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp390_set_interrupt_fifo_full(bmp390_handle_t *handle, bmp390_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp390_set_interrupt_active_level(bmp390_handle_t *handle, bmp390_interrupt_active_level_t level)
set the interrupt active level
bmp390_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]