LibDriver BMP384
Loading...
Searching...
No Matches
driver_bmp384.c
Go to the documentation of this file.
1
36
37#include "driver_bmp384.h"
38
42#define CHIP_NAME "Bosch BMP384"
43#define MANUFACTURER_NAME "Bosch"
44#define SUPPLY_VOLTAGE_MIN 1.65f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.8f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define BMP384_REG_CMD 0x7E
55#define BMP384_REG_NVM_PAR_T1_L 0x31
56#define BMP384_REG_NVM_PAR_T1_H 0x32
57#define BMP384_REG_NVM_PAR_T2_L 0x33
58#define BMP384_REG_NVM_PAR_T2_H 0x34
59#define BMP384_REG_NVM_PAR_T3 0x35
60#define BMP384_REG_NVM_PAR_P1_L 0x36
61#define BMP384_REG_NVM_PAR_P1_H 0x37
62#define BMP384_REG_NVM_PAR_P2_L 0x38
63#define BMP384_REG_NVM_PAR_P2_H 0x39
64#define BMP384_REG_NVM_PAR_P3 0x3A
65#define BMP384_REG_NVM_PAR_P4 0x3B
66#define BMP384_REG_NVM_PAR_P5_L 0x3C
67#define BMP384_REG_NVM_PAR_P5_H 0x3D
68#define BMP384_REG_NVM_PAR_P6_L 0x3E
69#define BMP384_REG_NVM_PAR_P6_H 0x3F
70#define BMP384_REG_NVM_PAR_P7 0x40
71#define BMP384_REG_NVM_PAR_P8 0x41
72#define BMP384_REG_NVM_PAR_P9_L 0x42
73#define BMP384_REG_NVM_PAR_P9_H 0x43
74#define BMP384_REG_NVM_PAR_P10 0x44
75#define BMP384_REG_NVM_PAR_P11 0x45
76#define BMP384_REG_CONFIG 0x1F
77#define BMP384_REG_ODR 0x1D
78#define BMP384_REG_OSR 0x1C
79#define BMP384_REG_PWR_CTRL 0x1B
80#define BMP384_REG_IF_CONF 0x1A
81#define BMP384_REG_INT_CTRL 0x19
82#define BMP384_REG_FIFO_CONFIG_2 0x18
83#define BMP384_REG_FIFO_CONFIG_1 0x17
84#define BMP384_REG_FIFO_WTM_1 0x16
85#define BMP384_REG_FIFO_WTM_0 0x15
86#define BMP384_REG_FIFO_DATA 0x14
87#define BMP384_REG_FIFO_LENGTH_1 0x13
88#define BMP384_REG_FIFO_LENGTH_0 0x12
89#define BMP384_REG_INT_STATUS 0x11
90#define BMP384_REG_EVENT 0x10
91#define BMP384_REG_SENSORTIME_2 0x0E
92#define BMP384_REG_SENSORTIME_1 0x0D
93#define BMP384_REG_SENSORTIME_0 0x0C
94#define BMP384_REG_DATA_5 0x09
95#define BMP384_REG_DATA_4 0x08
96#define BMP384_REG_DATA_3 0x07
97#define BMP384_REG_DATA_2 0x06
98#define BMP384_REG_DATA_1 0x05
99#define BMP384_REG_DATA_0 0x04
100#define BMP384_REG_STATUS 0x03
101#define BMP384_REG_ERR_REG 0x02
102#define BMP384_REG_CHIP_ID 0x00
103
115static uint8_t a_bmp384_iic_spi_read(bmp384_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
116{
117 if (handle->iic_spi == BMP384_INTERFACE_IIC) /* iic interface */
118 {
119 if (handle->iic_read(handle->iic_addr, reg, buf, len) != 0) /* iic read */
120 {
121 return 1; /* return error */
122 }
123 else
124 {
125 return 0; /* success return 0 */
126 }
127 }
128 else /* spi interface */
129 {
130 reg |= 1 << 7; /* set read mode */
131 if (handle->spi_read(reg, handle->buf,
132 len > 512 ? (512 + 1) : (len + 1)) != 0) /* spi read */
133 {
134 return 1; /* return error */
135 }
136 memcpy(buf, handle->buf+1, (len > 512) ? 512 : len); /* copy data */
137
138 return 0; /* success return 0 */
139 }
140}
141
153static uint8_t a_bmp384_iic_spi_write(bmp384_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
154{
155 if (handle->iic_spi == BMP384_INTERFACE_IIC) /* iic interface */
156 {
157 uint16_t i;
158
159 for (i = 0; i < len; i++) /* write data one byte by one byte */
160 {
161 if (handle->iic_write(handle->iic_addr,
162 (uint8_t)(reg + i), buf + i, 1) != 0) /* iic write */
163 {
164 return 1; /* return error */
165 }
166 }
167
168 return 0; /* success return 0 */
169 }
170 else
171 {
172 uint16_t i;
173
174 reg &= ~(1 << 7); /* write mode */
175 for (i = 0; i < len; i++) /* write data one byte by one byte */
176 {
177 if (handle->spi_write((uint8_t)(reg + i), buf + i, 1) != 0) /* spi write */
178 {
179 return 1; /* return error */
180 }
181 }
182
183 return 0; /* success return 0 */
184 }
185}
186
195static uint8_t a_bmp384_get_calibration_data(bmp384_handle_t *handle)
196{
197 uint8_t buf[2];
198
199 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_T1_L, (uint8_t *)buf, 2) != 0) /* read t1 */
200 {
201 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
202
203 return 1; /* return error */
204 }
205 handle->t1 = (uint16_t)buf[1] << 8 | buf[0]; /* set t1 */
206 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_T2_L, (uint8_t *)buf, 2) != 0) /* read t2 */
207 {
208 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
209
210 return 1; /* return error */
211 }
212 handle->t2 = (uint16_t)buf[1] << 8 | buf[0]; /* set t2 */
213 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_T3, (uint8_t *)buf, 1) != 0) /* read t3 */
214 {
215 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
216
217 return 1; /* return error */
218 }
219 handle->t3 = (int8_t)(buf[0]); /* set t3 */
220 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P1_L, (uint8_t *)buf, 2) != 0) /* read p1 */
221 {
222 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
223
224 return 1; /* return error */
225 }
226 handle->p1 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p1 */
227 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P2_L, (uint8_t *)buf, 2) != 0) /* read p2 */
228 {
229 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
230
231 return 1; /* return error */
232 }
233 handle->p2 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p2 */
234 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P3, (uint8_t *)buf, 1) != 0) /* read p3 */
235 {
236 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
237
238 return 1; /* return error */
239 }
240 handle->p3 = (int8_t)(buf[0]); /* set p3 */
241 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P4, (uint8_t *)buf, 1) != 0) /* read p4 */
242 {
243 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
244
245 return 1; /* return error */
246 }
247 handle->p4 = (int8_t)(buf[0]); /* set p4 */
248 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P5_L, (uint8_t *)buf, 2) != 0) /* read p5 */
249 {
250 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
251
252 return 1; /* return error */
253 }
254 handle->p5 = (uint16_t)buf[1] << 8 | buf[0]; /* set p5 */
255 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P6_L, (uint8_t *)buf, 2) != 0) /* read p6l */
256 {
257 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
258
259 return 1; /* return error */
260 }
261 handle->p6 = (uint16_t)buf[1] << 8 | buf[0]; /* set p6 */
262 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P7, (uint8_t *)buf, 1) != 0) /* read p7 */
263 {
264 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
265
266 return 1; /* return error */
267 }
268 handle->p7 = (int8_t)(buf[0]); /* set p7 */
269 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P8, (uint8_t *)buf, 1) != 0) /* read p8 */
270 {
271 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
272
273 return 1; /* return error */
274 }
275 handle->p8 = (int8_t)(buf[0]); /* set p8 */
276 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P9_L, (uint8_t *)buf, 2) != 0) /* read p9l */
277 {
278 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
279
280 return 1; /* return error */
281 }
282 handle->p9 = (int16_t)((uint16_t)buf[1] << 8 | buf[0]); /* set p9 */
283 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P10, (uint8_t *)buf, 1) != 0) /* read p10 */
284 {
285 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
286
287 return 1; /* return error */
288 }
289 handle->p10 = (int8_t)(buf[0]); /* set p10 */
290 if (a_bmp384_iic_spi_read(handle, BMP384_REG_NVM_PAR_P11, (uint8_t *)buf, 1) != 0) /* read p11 */
291 {
292 handle->debug_print("bmp384: get calibration data failed.\n"); /* get calibration data failed */
293
294 return 1; /* return error */
295 }
296 handle->p11 = (int8_t)(buf[0]); /* set p11 */
297
298 return 0; /* success return 0 */
299}
300
308static int64_t a_bmp384_compensate_temperature(bmp384_handle_t *handle, uint32_t data)
309{
310 uint64_t partial_data1;
311 uint64_t partial_data2;
312 uint64_t partial_data3;
313 int64_t partial_data4;
314 int64_t partial_data5;
315 int64_t partial_data6;
316 int64_t comp_temp;
317
318 /* calculate compensate temperature */
319 partial_data1 = (uint64_t)(data - (256 * (uint64_t)(handle->t1)));
320 partial_data2 = (uint64_t)(handle->t2 * partial_data1);
321 partial_data3 = (uint64_t)(partial_data1 * partial_data1);
322 partial_data4 = (int64_t)(((int64_t)partial_data3) * ((int64_t)handle->t3));
323 partial_data5 = ((int64_t)(((int64_t)partial_data2) * 262144) + (int64_t)partial_data4);
324 partial_data6 = (int64_t)(((int64_t)partial_data5) / 4294967296U);
325 handle->t_fine = partial_data6;
326 comp_temp = (int64_t)((partial_data6 * 25) / 16384);
327
328 return comp_temp;
329}
330
338static int64_t a_bmp384_compensate_pressure(bmp384_handle_t *handle, uint32_t data)
339{
340 int64_t partial_data1;
341 int64_t partial_data2;
342 int64_t partial_data3;
343 int64_t partial_data4;
344 int64_t partial_data5;
345 int64_t partial_data6;
346 int64_t offset;
347 int64_t sensitivity;
348 uint64_t comp_press;
349
350 /* calculate compensate pressure */
351 partial_data1 = handle->t_fine * handle->t_fine;
352 partial_data2 = partial_data1 / 64;
353 partial_data3 = (partial_data2 * handle->t_fine) / 256;
354 partial_data4 = (handle->p8 * partial_data3) / 32;
355 partial_data5 = (handle->p7 * partial_data1) * 16;
356 partial_data6 = (handle->p6 * handle->t_fine) * 4194304;
357 offset = (int64_t)((int64_t)(handle->p5) * (int64_t)140737488355328U) + partial_data4 + partial_data5 + partial_data6;
358 partial_data2 = (((int64_t)handle->p4) * partial_data3) / 32;
359 partial_data4 = (handle->p3 * partial_data1) * 4;
360 partial_data5 = ((int64_t)(handle->p2) - 16384) * ((int64_t)handle->t_fine) * 2097152;
361 sensitivity = (((int64_t)(handle->p1) - 16384) * (int64_t)70368744177664U) + partial_data2 + partial_data4 + partial_data5;
362 partial_data1 = (sensitivity / 16777216) * data;
363 partial_data2 = (int64_t)(handle->p10) * (int64_t)(handle->t_fine);
364 partial_data3 = partial_data2 + (65536 * (int64_t)(handle->p9));
365 partial_data4 = (partial_data3 * data) / 8192;
366 partial_data5 = (partial_data4 * data) / 512;
367 partial_data6 = (int64_t)((uint64_t)data * (uint64_t)data);
368 partial_data2 = ((int64_t)(handle->p11) * (int64_t)(partial_data6)) / 65536;
369 partial_data3 = (partial_data2 * data) / 128;
370 partial_data4 = (offset / 4) + partial_data1 + partial_data5 + partial_data3;
371 comp_press = (((uint64_t)partial_data4 * 25) / (uint64_t)1099511627776U);
372
373 return comp_press;
374}
375
387uint8_t bmp384_get_error(bmp384_handle_t *handle, uint8_t *err)
388{
389 uint8_t res;
390
391 if (handle == NULL) /* check handle */
392 {
393 return 2; /* return error */
394 }
395 if (handle->inited != 1) /* check handle initialization */
396 {
397 return 3; /* return error */
398 }
399
400 res = a_bmp384_iic_spi_read(handle, BMP384_REG_ERR_REG, (uint8_t *)err, 1); /* read config */
401 if (res != 0) /* check result */
402 {
403 handle->debug_print("bmp384: get error register failed.\n"); /* get error register failed */
404
405 return 1; /* return error */
406 }
407
408 return 0; /* success return 0 */
409}
410
422uint8_t bmp384_get_status(bmp384_handle_t *handle, uint8_t *status)
423{
424 uint8_t res;
425
426 if (handle == NULL) /* check handle */
427 {
428 return 2; /* return error */
429 }
430 if (handle->inited != 1) /* check handle initialization */
431 {
432 return 3; /* return error */
433 }
434
435 res = a_bmp384_iic_spi_read(handle, BMP384_REG_STATUS, (uint8_t *)status, 1); /* read status */
436 if (res != 0) /* check result */
437 {
438 handle->debug_print("bmp384: get status register failed.\n"); /* get status register failed */
439
440 return 1; /* return error */
441 }
442
443 return 0; /* success return 0 */
444}
445
457uint8_t bmp384_get_sensortime(bmp384_handle_t *handle, uint32_t *t)
458{
459 uint8_t res;
460 uint8_t buf[3];
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_bmp384_iic_spi_read(handle, BMP384_REG_SENSORTIME_0, (uint8_t *)buf, 3); /* read config */
472 if (res != 0) /* check result */
473 {
474 handle->debug_print("bmp384: get sensor time register failed.\n"); /* get sensor time register failed */
475
476 return 1; /* return error */
477 }
478 *t = (uint32_t)buf[2] << 16 | (uint32_t)buf[1] << 8 | buf[0]; /* get time */
479
480 return 0; /* success return 0 */
481}
482
495{
496 uint8_t res;
497 uint8_t prev;
498
499 if (handle == NULL) /* check handle */
500 {
501 return 2; /* return error */
502 }
503 if (handle->inited != 1) /* check handle initialization */
504 {
505 return 3; /* return error */
506 }
507
508 res = a_bmp384_iic_spi_read(handle, BMP384_REG_EVENT, (uint8_t *)&prev, 1); /* read config */
509 if (res != 0) /* check result */
510 {
511 handle->debug_print("bmp384: get event register failed.\n"); /* get event register failed */
512
513 return 1; /* return error */
514 }
515 *event = (bmp384_event_t)(prev & (1 << 0)); /* get event */
516
517 return 0; /* success return 0 */
518}
519
531uint8_t bmp384_get_interrupt_status(bmp384_handle_t *handle, uint8_t *status)
532{
533 uint8_t res;
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_bmp384_iic_spi_read(handle, BMP384_REG_INT_STATUS, (uint8_t *)status, 1); /* read status */
545 if (res != 0) /* check result */
546 {
547 handle->debug_print("bmp384: get interrupt status register failed.\n"); /* get interrupt status register failed */
548
549 return 1; /* return error */
550 }
551
552 return 0; /* success return 0 */
553}
554
566uint8_t bmp384_get_fifo_length(bmp384_handle_t *handle, uint16_t *length)
567{
568 uint8_t res;
569 uint8_t buf[2];
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_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_LENGTH_0, (uint8_t *)buf, 2); /* read config */
581 if (res != 0) /* check result */
582 {
583 handle->debug_print("bmp384: get fifo length register failed.\n"); /* get fifo length register failed */
584
585 return 1; /* return error */
586 }
587 *length = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0]; /* get data */
588
589 return 0; /* success return 0 */
590}
591
604uint8_t bmp384_get_fifo_data(bmp384_handle_t *handle, uint8_t *data, uint16_t length)
605{
606 uint8_t res;
607
608 if (handle == NULL) /* check handle */
609 {
610 return 2; /* return error */
611 }
612 if (handle->inited != 1) /* check handle initialization */
613 {
614 return 3; /* return error */
615 }
616
617 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_DATA, (uint8_t *)data, length); /* read data */
618 if (res != 0) /* check result */
619 {
620 handle->debug_print("bmp384: get fifo data register failed.\n"); /* get fifo data register failed */
621
622 return 1; /* return error */
623 }
624
625 return 0; /* success return 0 */
626}
627
639uint8_t bmp384_set_fifo_watermark(bmp384_handle_t *handle, uint16_t watermark)
640{
641 uint8_t res;
642 uint8_t buf[2];
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 buf[0] = watermark & 0xFF; /* set low part */
654 buf[1] = (watermark >> 8) & 0x01; /* set high part */
655 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_WTM_0, (uint8_t *)buf, 2); /* write config */
656 if (res != 0) /* check result */
657 {
658 handle->debug_print("bmp384: set fifo watermark register failed.\n"); /* set fifo watermark register failed */
659
660 return 1; /* return error */
661 }
662
663 return 0; /* success return 0 */
664}
665
677uint8_t bmp384_get_fifo_watermark(bmp384_handle_t *handle, uint16_t *watermark)
678{
679 uint8_t res;
680 uint8_t buf[2];
681
682 if (handle == NULL) /* check handle */
683 {
684 return 2; /* return error */
685 }
686 if (handle->inited != 1) /* check handle initialization */
687 {
688 return 3; /* return error */
689 }
690
691 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_WTM_0, (uint8_t *)buf, 2); /* read config */
692 if (res != 0) /* check result */
693 {
694 handle->debug_print("bmp384: get fifo watermark register failed.\n"); /* get fifo watermark register failed */
695
696 return 1; /* return error */
697 }
698 *watermark = ((uint16_t)(buf[1] & 0x01) << 8) | buf[0]; /* get data */
699
700 return 0; /* success return 0 */
701}
702
715{
716 uint8_t res;
717 uint8_t prev;
718
719 if (handle == NULL) /* check handle */
720 {
721 return 2; /* return error */
722 }
723 if (handle->inited != 1) /* check handle initialization */
724 {
725 return 3; /* return error */
726 }
727
728 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
729 if (res != 0) /* check result */
730 {
731 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
732
733 return 1; /* return error */
734 }
735 prev &= ~(1 << 0); /* clear config */
736 prev |= enable << 0; /* set config */
737 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
738 if (res != 0) /* check result */
739 {
740 handle->debug_print("bmp384: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
741
742 return 1; /* return error */
743 }
744
745 return 0; /* success return 0 */
746}
747
760{
761 uint8_t res;
762 uint8_t prev;
763
764 if (handle == NULL) /* check handle */
765 {
766 return 2; /* return error */
767 }
768 if (handle->inited != 1) /* check handle initialization */
769 {
770 return 3; /* return error */
771 }
772
773 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
774 if (res != 0) /* check result */
775 {
776 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
777
778 return 1; /* return error */
779 }
780 *enable = (bmp384_bool_t)(prev & 0x01); /* get config */
781
782 return 0; /* success return 0 */
783}
784
797{
798 uint8_t res;
799 uint8_t prev;
800
801 if (handle == NULL) /* check handle */
802 {
803 return 2; /* return error */
804 }
805 if (handle->inited != 1) /* check handle initialization */
806 {
807 return 3; /* return error */
808 }
809
810 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
811 if (res != 0) /* check result */
812 {
813 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
814
815 return 1; /* return error */
816 }
817 prev &= ~(1 << 1); /* clear config */
818 prev |= enable << 1; /* set config */
819 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
820 if (res != 0) /* check result */
821 {
822 handle->debug_print("bmp384: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
823
824 return 1; /* return error */
825 }
826
827 return 0; /* success return 0 */
828}
829
842{
843 uint8_t res;
844 uint8_t prev;
845
846 if (handle == NULL) /* check handle */
847 {
848 return 2; /* return error */
849 }
850 if (handle->inited != 1) /* check handle initialization */
851 {
852 return 3; /* return error */
853 }
854
855 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
856 if (res != 0) /* check result */
857 {
858 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
859
860 return 1; /* return error */
861 }
862 *enable = (bmp384_bool_t)((prev >> 1) & 0x01); /* get config */
863
864 return 0; /* success return 0 */
865}
866
879{
880 uint8_t res;
881 uint8_t prev;
882
883 if (handle == NULL) /* check handle */
884 {
885 return 2; /* return error */
886 }
887 if (handle->inited != 1) /* check handle initialization */
888 {
889 return 3; /* return error */
890 }
891
892 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
893 if (res != 0) /* check result */
894 {
895 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
896
897 return 1; /* return error */
898 }
899 prev &= ~(1 << 2); /* clear config */
900 prev |= enable << 2; /* set config */
901 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
902 if (res != 0) /* check result */
903 {
904 handle->debug_print("bmp384: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
905
906 return 1; /* return error */
907 }
908
909 return 0; /* success return 0 */
910}
911
924{
925 uint8_t res;
926 uint8_t prev;
927
928 if (handle == NULL) /* check handle */
929 {
930 return 2; /* return error */
931 }
932 if (handle->inited != 1) /* check handle initialization */
933 {
934 return 3; /* return error */
935 }
936
937 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
938 if (res != 0) /* check result */
939 {
940 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
941
942 return 1; /* return error */
943 }
944 *enable = (bmp384_bool_t)((prev >> 2) & 0x01); /* get config */
945
946 return 0; /* success return 0 */
947}
948
961{
962 uint8_t res;
963 uint8_t prev;
964
965 if (handle == NULL) /* check handle */
966 {
967 return 2; /* return error */
968 }
969 if (handle->inited != 1) /* check handle initialization */
970 {
971 return 3; /* return error */
972 }
973
974 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
975 if (res != 0) /* check result */
976 {
977 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
978
979 return 1; /* return error */
980 }
981 prev &= ~(1 << 3); /* clear config */
982 prev |= enable << 3; /* set config */
983 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
984 if (res != 0) /* check result */
985 {
986 handle->debug_print("bmp384: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
987
988 return 1; /* return error */
989 }
990
991 return 0; /* success return 0 */
992}
993
1006{
1007 uint8_t res;
1008 uint8_t prev;
1009
1010 if (handle == NULL) /* check handle */
1011 {
1012 return 2; /* return error */
1013 }
1014 if (handle->inited != 1) /* check handle initialization */
1015 {
1016 return 3; /* return error */
1017 }
1018
1019 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1020 if (res != 0) /* check result */
1021 {
1022 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1023
1024 return 1; /* return error */
1025 }
1026 *enable = (bmp384_bool_t)((prev >> 3) & 0x01); /* get config */
1027
1028 return 0; /* success return 0 */
1029}
1030
1043{
1044 uint8_t res;
1045 uint8_t prev;
1046
1047 if (handle == NULL) /* check handle */
1048 {
1049 return 2; /* return error */
1050 }
1051 if (handle->inited != 1) /* check handle initialization */
1052 {
1053 return 3; /* return error */
1054 }
1055
1056 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1057 if (res != 0) /* check result */
1058 {
1059 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1060
1061 return 1; /* return error */
1062 }
1063 prev &= ~(1 << 4); /* clear config */
1064 prev |= enable << 4; /* set config */
1065 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* write config */
1066 if (res != 0) /* check result */
1067 {
1068 handle->debug_print("bmp384: set fifo config 1 register failed.\n"); /* set fifo config 1 register failed */
1069
1070 return 1; /* return error */
1071 }
1072
1073 return 0; /* success return 0 */
1074}
1075
1088{
1089 uint8_t res;
1090 uint8_t prev;
1091
1092 if (handle == NULL) /* check handle */
1093 {
1094 return 2; /* return error */
1095 }
1096 if (handle->inited != 1) /* check handle initialization */
1097 {
1098 return 3; /* return error */
1099 }
1100
1101 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
1102 if (res != 0) /* check result */
1103 {
1104 handle->debug_print("bmp384: get fifo config 1 register failed.\n"); /* get fifo config 1 register failed */
1105
1106 return 1; /* return error */
1107 }
1108 *enable = (bmp384_bool_t)((prev >> 4) & 0x01); /* get config */
1109
1110 return 0; /* success return 0 */
1111}
1112
1124uint8_t bmp384_set_fifo_subsampling(bmp384_handle_t *handle, uint8_t subsample)
1125{
1126 uint8_t res;
1127 uint8_t prev;
1128
1129 if (handle == NULL) /* check handle */
1130 {
1131 return 2; /* return error */
1132 }
1133 if (handle->inited != 1) /* check handle initialization */
1134 {
1135 return 3; /* return error */
1136 }
1137
1138 if (subsample > 7) /* check subsample */
1139 {
1140 handle->debug_print("bmp384: subsample is invalid.\n"); /* subsample is invalid */
1141
1142 return 4; /* return error */
1143 }
1144 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1145 if (res != 0) /* check result */
1146 {
1147 handle->debug_print("bmp384: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1148
1149 return 1; /* return error */
1150 }
1151 prev &= ~(7 << 0); /* clear config */
1152 prev |= subsample << 0; /* set config */
1153 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* write config */
1154 if (res != 0) /* check result */
1155 {
1156 handle->debug_print("bmp384: set fifo config 2 register failed.\n"); /* set fifo config 2 register failed */
1157
1158 return 1; /* return error */
1159 }
1160
1161 return 0; /* success return 0 */
1162}
1163
1175uint8_t bmp384_get_fifo_subsampling(bmp384_handle_t *handle, uint8_t *subsample)
1176{
1177 uint8_t res;
1178 uint8_t prev;
1179
1180 if (handle == NULL) /* check handle */
1181 {
1182 return 2; /* return error */
1183 }
1184 if (handle->inited != 1) /* check handle initialization */
1185 {
1186 return 3; /* return error */
1187 }
1188
1189 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1190 if (res != 0) /* check result */
1191 {
1192 handle->debug_print("bmp384: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1193
1194 return 1; /* return error */
1195 }
1196 *subsample = (bmp384_bool_t)((prev >> 0) & 0x07); /* get config */
1197
1198 return 0; /* success return 0 */
1199}
1200
1213{
1214 uint8_t res;
1215 uint8_t prev;
1216
1217 if (handle == NULL) /* check handle */
1218 {
1219 return 2; /* return error */
1220 }
1221 if (handle->inited != 1) /* check handle initialization */
1222 {
1223 return 3; /* return error */
1224 }
1225
1226 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1227 if (res != 0) /* check result */
1228 {
1229 handle->debug_print("bmp384: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1230
1231 return 1; /* return error */
1232 }
1233 prev &= ~(3 << 3); /* clear config */
1234 prev |= source << 3; /* set config */
1235 res = a_bmp384_iic_spi_write(handle, BMP384_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* write config */
1236 if (res != 0) /* check result */
1237 {
1238 handle->debug_print("bmp384: set fifo config 2 register failed.\n"); /* set fifo config 2 register failed */
1239
1240 return 1; /* return error */
1241 }
1242
1243 return 0; /* success return 0 */
1244}
1245
1258{
1259 uint8_t res;
1260 uint8_t prev;
1261
1262 if (handle == NULL) /* check handle */
1263 {
1264 return 2; /* return error */
1265 }
1266 if (handle->inited != 1) /* check handle initialization */
1267 {
1268 return 3; /* return error */
1269 }
1270
1271 res = a_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_2, (uint8_t *)&prev, 1); /* read config */
1272 if (res != 0) /* check result */
1273 {
1274 handle->debug_print("bmp384: get fifo config 2 register failed.\n"); /* get fifo config 2 register failed */
1275
1276 return 1; /* return error */
1277 }
1278 *source = (bmp384_fifo_data_source_t)((prev >> 3) & 0x01); /* get config */
1279
1280 return 0; /* success return 0 */
1281}
1282
1295{
1296 uint8_t res;
1297 uint8_t prev;
1298
1299 if (handle == NULL) /* check handle */
1300 {
1301 return 2; /* return error */
1302 }
1303 if (handle->inited != 1) /* check handle initialization */
1304 {
1305 return 3; /* return error */
1306 }
1307
1308 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1309 if (res != 0) /* check result */
1310 {
1311 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1312
1313 return 1; /* return error */
1314 }
1315 prev &= ~(1 << 0); /* clear config */
1316 prev |= pin_type << 0; /* set config */
1317 res = a_bmp384_iic_spi_write(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1318 if (res != 0) /* check result */
1319 {
1320 handle->debug_print("bmp384: set int ctrl register failed.\n"); /* set int ctrl register failed */
1321
1322 return 1; /* return error */
1323 }
1324
1325 return 0; /* success return 0 */
1326}
1327
1340{
1341 uint8_t res;
1342 uint8_t prev;
1343
1344 if (handle == NULL) /* check handle */
1345 {
1346 return 2; /* return error */
1347 }
1348 if (handle->inited != 1) /* check handle initialization */
1349 {
1350 return 3; /* return error */
1351 }
1352
1353 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1354 if (res != 0) /* check result */
1355 {
1356 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1357
1358 return 1; /* return error */
1359 }
1360 *pin_type = (bmp384_interrupt_pin_type_t)(prev & 0x01); /* get interrupt pin type */
1361
1362 return 0; /* success return 0 */
1363}
1364
1377{
1378 uint8_t res;
1379 uint8_t prev;
1380
1381 if (handle == NULL) /* check handle */
1382 {
1383 return 2; /* return error */
1384 }
1385 if (handle->inited != 1) /* check handle initialization */
1386 {
1387 return 3; /* return error */
1388 }
1389
1390 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1391 if (res != 0) /* check result */
1392 {
1393 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1394
1395 return 1; /* return error */
1396 }
1397 prev &= ~(1 << 1); /* clear config */
1398 prev |= level << 1; /* set config */
1399 res = a_bmp384_iic_spi_write(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1400 if (res != 0) /* check result */
1401 {
1402 handle->debug_print("bmp384: set int ctrl register failed.\n"); /* set int ctrl register failed */
1403
1404 return 1; /* return error */
1405 }
1406
1407 return 0; /* success return 0 */
1408}
1409
1422{
1423 uint8_t res;
1424 uint8_t prev;
1425
1426 if (handle == NULL) /* check handle */
1427 {
1428 return 2; /* return error */
1429 }
1430 if (handle->inited != 1) /* check handle initialization */
1431 {
1432 return 3; /* return error */
1433 }
1434
1435 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1436 if (res != 0) /* check result */
1437 {
1438 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1439
1440 return 1; /* return error */
1441 }
1442 *level = (bmp384_interrupt_active_level_t)((prev >> 1) & 0x01); /* get config */
1443
1444 return 0; /* success return 0 */
1445}
1446
1459{
1460 uint8_t res;
1461 uint8_t prev;
1462
1463 if (handle == NULL) /* check handle */
1464 {
1465 return 2; /* return error */
1466 }
1467 if (handle->inited != 1) /* check handle initialization */
1468 {
1469 return 3; /* return error */
1470 }
1471
1472 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1473 if (res != 0) /* check result */
1474 {
1475 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1476
1477 return 1; /* return error */
1478 }
1479 prev &= ~(1 << 2); /* clear config */
1480 prev |= enable << 2; /* set config */
1481 res = a_bmp384_iic_spi_write(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1482 if (res != 0) /* check result */
1483 {
1484 handle->debug_print("bmp384: set int ctrl register failed.\n"); /* set int ctrl register failed */
1485
1486 return 1; /* return error */
1487 }
1488
1489 return 0; /* success return 0 */
1490}
1491
1504{
1505 uint8_t res;
1506 uint8_t prev;
1507
1508 if (handle == NULL) /* check handle */
1509 {
1510 return 2; /* return error */
1511 }
1512 if (handle->inited != 1) /* check handle initialization */
1513 {
1514 return 3; /* return error */
1515 }
1516
1517 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1518 if (res != 0) /* check result */
1519 {
1520 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1521
1522 return 1; /* return error */
1523 }
1524 *enable = (bmp384_bool_t)((prev >> 2) & 0x01); /* get config */
1525
1526 return 0; /* success return 0 */
1527}
1528
1541{
1542 uint8_t res;
1543 uint8_t prev;
1544
1545 if (handle == NULL) /* check handle */
1546 {
1547 return 2; /* return error */
1548 }
1549 if (handle->inited != 1) /* check handle initialization */
1550 {
1551 return 3; /* return error */
1552 }
1553
1554 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1555 if (res != 0) /* check result */
1556 {
1557 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1558
1559 return 1; /* return error */
1560 }
1561 prev &= ~(1 << 3); /* clear config */
1562 prev |= enable << 3; /* set config */
1563 res = a_bmp384_iic_spi_write(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1564 if (res != 0) /* check result */
1565 {
1566 handle->debug_print("bmp384: set int ctrl register failed.\n"); /* set int ctrl register failed */
1567
1568 return 1; /* return error */
1569 }
1570
1571 return 0; /* success return 0 */
1572}
1573
1586{
1587 uint8_t res;
1588 uint8_t prev;
1589
1590 if (handle == NULL) /* check handle */
1591 {
1592 return 2; /* return error */
1593 }
1594 if (handle->inited != 1) /* check handle initialization */
1595 {
1596 return 3; /* return error */
1597 }
1598
1599 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1600 if (res != 0) /* check result */
1601 {
1602 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1603
1604 return 1; /* return error */
1605 }
1606 *enable = (bmp384_bool_t)((prev >> 3) & 0x01); /* get config */
1607
1608 return 0; /* success return 0 */
1609}
1610
1623{
1624 uint8_t res;
1625 uint8_t prev;
1626
1627 if (handle == NULL) /* check handle */
1628 {
1629 return 2; /* return error */
1630 }
1631 if (handle->inited != 1) /* check handle initialization */
1632 {
1633 return 3; /* return error */
1634 }
1635
1636 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1637 if (res != 0) /* check result */
1638 {
1639 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1640
1641 return 1; /* return error */
1642 }
1643 prev &= ~(1 << 4); /* clear config */
1644 prev |= enable << 4; /* set config */
1645 res = a_bmp384_iic_spi_write(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1646 if (res != 0) /* check result */
1647 {
1648 handle->debug_print("bmp384: set int ctrl register failed.\n"); /* set int ctrl register failed */
1649
1650 return 1; /* return error */
1651 }
1652
1653 return 0; /* success return 0 */
1654}
1655
1668{
1669 uint8_t res;
1670 uint8_t prev;
1671
1672 if (handle == NULL) /* check handle */
1673 {
1674 return 2; /* return error */
1675 }
1676 if (handle->inited != 1) /* check handle initialization */
1677 {
1678 return 3; /* return error */
1679 }
1680
1681 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1682 if (res != 0) /* check result */
1683 {
1684 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1685
1686 return 1; /* return error */
1687 }
1688 *enable = (bmp384_bool_t)((prev >> 4) & 0x01); /* get config */
1689
1690 return 0; /* success return 0 */
1691}
1692
1705{
1706 uint8_t res;
1707 uint8_t prev;
1708
1709 if (handle == NULL) /* check handle */
1710 {
1711 return 2; /* return error */
1712 }
1713 if (handle->inited != 1) /* check handle initialization */
1714 {
1715 return 3; /* return error */
1716 }
1717
1718 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1719 if (res != 0) /* check result */
1720 {
1721 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1722
1723 return 1; /* return error */
1724 }
1725 prev &= ~(1 << 6); /* clear config */
1726 prev |= enable << 6; /* set config */
1727 res = a_bmp384_iic_spi_write(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* write config */
1728 if (res != 0) /* check result */
1729 {
1730 handle->debug_print("bmp384: set int ctrl register failed.\n"); /* set int ctrl register failed */
1731
1732 return 1; /* return error */
1733 }
1734
1735 return 0; /* success return 0 */
1736}
1737
1750{
1751 uint8_t res;
1752 uint8_t prev;
1753
1754 if (handle == NULL) /* check handle */
1755 {
1756 return 2; /* return error */
1757 }
1758 if (handle->inited != 1) /* check handle initialization */
1759 {
1760 return 3; /* return error */
1761 }
1762
1763 res = a_bmp384_iic_spi_read(handle, BMP384_REG_INT_CTRL, (uint8_t *)&prev, 1); /* read config */
1764 if (res != 0) /* check result */
1765 {
1766 handle->debug_print("bmp384: get int ctrl register failed.\n"); /* get int ctrl register failed */
1767
1768 return 1; /* return error */
1769 }
1770 *enable = (bmp384_bool_t)((prev >> 6) & 0x01); /* get config */
1771
1772 return 0; /* success return 0 */
1773}
1774
1787{
1788 uint8_t res;
1789 uint8_t prev;
1790
1791 if (handle == NULL) /* check handle */
1792 {
1793 return 2; /* return error */
1794 }
1795 if (handle->inited != 1) /* check handle initialization */
1796 {
1797 return 3; /* return error */
1798 }
1799
1800 res = a_bmp384_iic_spi_read(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1801 if (res != 0) /* check result */
1802 {
1803 handle->debug_print("bmp384: get if conf register failed.\n"); /* get if conf register failed */
1804
1805 return 1; /* return error */
1806 }
1807 prev &= ~(1 << 0); /* clear config */
1808 prev |= wire << 0; /* set config */
1809 res = a_bmp384_iic_spi_write(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1810 if (res != 0) /* check result */
1811 {
1812 handle->debug_print("bmp384: set if conf register failed.\n"); /* set if conf register failed */
1813
1814 return 1; /* return error */
1815 }
1816
1817 return 0; /* success return 0 */
1818}
1819
1832{
1833 uint8_t res;
1834 uint8_t prev;
1835
1836 if (handle == NULL) /* check handle */
1837 {
1838 return 2; /* return error */
1839 }
1840 if (handle->inited != 1) /* check handle initialization */
1841 {
1842 return 3; /* return error */
1843 }
1844
1845 res = a_bmp384_iic_spi_read(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1846 if (res != 0) /* check result */
1847 {
1848 handle->debug_print("bmp384: get if conf register failed.\n"); /* get if conf register failed */
1849
1850 return 1; /* return error */
1851 }
1852 *wire = (bmp384_spi_wire_t)(prev & 0x01); /* get config */
1853
1854 return 0; /* success return 0 */
1855}
1856
1869{
1870 uint8_t res;
1871 uint8_t prev;
1872
1873 if (handle == NULL) /* check handle */
1874 {
1875 return 2; /* return error */
1876 }
1877 if (handle->inited != 1) /* check handle initialization */
1878 {
1879 return 3; /* return error */
1880 }
1881
1882 res = a_bmp384_iic_spi_read(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1883 if (res != 0) /* check result */
1884 {
1885 handle->debug_print("bmp384: get if conf register failed.\n"); /* get if conf register failed */
1886
1887 return 1; /* return error */
1888 }
1889 prev &= ~(1 << 1); /* clear config */
1890 prev |= enable << 1; /* set config */
1891 res = a_bmp384_iic_spi_write(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1892 if (res != 0) /* check result */
1893 {
1894 handle->debug_print("bmp384: set if conf register failed.\n"); /* set if conf register failed */
1895
1896 return 1; /* return error */
1897 }
1898
1899 return 0; /* success return 0 */
1900}
1901
1914{
1915 uint8_t res;
1916 uint8_t prev;
1917
1918 if (handle == NULL) /* check handle */
1919 {
1920 return 2; /* return error */
1921 }
1922 if (handle->inited != 1) /* check handle initialization */
1923 {
1924 return 3; /* return error */
1925 }
1926
1927 res = a_bmp384_iic_spi_read(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1928 if (res != 0) /* check result */
1929 {
1930 handle->debug_print("bmp384: get if conf register failed.\n"); /* get if conf register failed */
1931
1932 return 1; /* return error */
1933 }
1934 *enable = (bmp384_bool_t)((prev >> 1) & 0x01); /* get config */
1935
1936 return 0; /* success return 0 */
1937}
1938
1951{
1952 uint8_t res;
1953 uint8_t prev;
1954
1955 if (handle == NULL) /* check handle */
1956 {
1957 return 2; /* return error */
1958 }
1959 if (handle->inited != 1) /* check handle initialization */
1960 {
1961 return 3; /* return error */
1962 }
1963
1964 res = a_bmp384_iic_spi_read(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
1965 if (res != 0) /* check result */
1966 {
1967 handle->debug_print("bmp384: get if conf register failed.\n"); /* get if conf register failed */
1968
1969 return 1; /* return error */
1970 }
1971 prev &= ~(1 << 2); /* clear config */
1972 prev |= period << 2; /* set config */
1973 res = a_bmp384_iic_spi_write(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* write config */
1974 if (res != 0) /* check result */
1975 {
1976 handle->debug_print("bmp384: set if conf register failed.\n"); /* set if conf register failed */
1977
1978 return 1; /* return error */
1979 }
1980
1981 return 0; /* success return 0 */
1982}
1983
1996{
1997 uint8_t res;
1998 uint8_t prev;
1999
2000 if (handle == NULL) /* check handle */
2001 {
2002 return 2; /* return error */
2003 }
2004 if (handle->inited != 1) /* check handle initialization */
2005 {
2006 return 3; /* return error */
2007 }
2008
2009 res = a_bmp384_iic_spi_read(handle, BMP384_REG_IF_CONF, (uint8_t *)&prev, 1); /* read config */
2010 if (res != 0) /* check result */
2011 {
2012 handle->debug_print("bmp384: get if conf register failed.\n"); /* get if conf register failed */
2013
2014 return 1; /* return error */
2015 }
2016 *period = (bmp384_iic_watchdog_period_t)((prev >> 2) & 0x01); /* get config */
2017
2018 return 0; /* success return 0 */
2019}
2020
2033{
2034 uint8_t res;
2035 uint8_t prev;
2036
2037 if (handle == NULL) /* check handle */
2038 {
2039 return 2; /* return error */
2040 }
2041 if (handle->inited != 1) /* check handle initialization */
2042 {
2043 return 3; /* return error */
2044 }
2045
2046 res = a_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2047 if (res != 0) /* check result */
2048 {
2049 handle->debug_print("bmp384: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2050
2051 return 1; /* return error */
2052 }
2053 prev &= ~(1 << 0); /* clear config */
2054 prev |= enable << 0; /* set config */
2055 res = a_bmp384_iic_spi_write(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2056 if (res != 0) /* check result */
2057 {
2058 handle->debug_print("bmp384: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2059
2060 return 1; /* return error */
2061 }
2062
2063 return 0; /* success return 0 */
2064}
2065
2078{
2079 uint8_t res;
2080 uint8_t prev;
2081
2082 if (handle == NULL) /* check handle */
2083 {
2084 return 2; /* return error */
2085 }
2086 if (handle->inited != 1) /* check handle initialization */
2087 {
2088 return 3; /* return error */
2089 }
2090
2091 res = a_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2092 if (res != 0) /* check result */
2093 {
2094 handle->debug_print("bmp384: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2095
2096 return 1; /* return error */
2097 }
2098 *enable = (bmp384_bool_t)((prev >> 0) & 0x01); /* get config */
2099
2100 return 0; /* success return 0 */
2101}
2102
2115{
2116 uint8_t res;
2117 uint8_t prev;
2118
2119 if (handle == NULL) /* check handle */
2120 {
2121 return 2; /* return error */
2122 }
2123 if (handle->inited != 1) /* check handle initialization */
2124 {
2125 return 3; /* return error */
2126 }
2127
2128 res = a_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2129 if (res != 0) /* check result */
2130 {
2131 handle->debug_print("bmp384: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2132
2133 return 1; /* return error */
2134 }
2135 prev &= ~(1 << 1); /* clear config */
2136 prev |= enable << 1; /* set config */
2137 res = a_bmp384_iic_spi_write(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2138 if (res != 0) /* check result */
2139 {
2140 handle->debug_print("bmp384: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2141
2142 return 1; /* return error */
2143 }
2144
2145 return 0; /* success return 0 */
2146}
2147
2160{
2161 uint8_t res;
2162 uint8_t prev;
2163
2164 if (handle == NULL) /* check handle */
2165 {
2166 return 2; /* return error */
2167 }
2168 if (handle->inited != 1) /* check handle initialization */
2169 {
2170 return 3; /* return error */
2171 }
2172
2173 res = a_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2174 if (res != 0) /* check result */
2175 {
2176 handle->debug_print("bmp384: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2177
2178 return 1; /* return error */
2179 }
2180 *enable = (bmp384_bool_t)((prev >> 1) & 0x01); /* get config */
2181
2182 return 0; /* success return 0 */
2183}
2184
2197{
2198 uint8_t res;
2199 uint8_t prev;
2200
2201 if (handle == NULL) /* check handle */
2202 {
2203 return 2; /* return error */
2204 }
2205 if (handle->inited != 1) /* check handle initialization */
2206 {
2207 return 3; /* return error */
2208 }
2209
2210 res = a_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2211 if (res != 0) /* check result */
2212 {
2213 handle->debug_print("bmp384: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2214
2215 return 1; /* return error */
2216 }
2217 prev &= ~(3 << 4); /* clear config */
2218 prev |= mode << 4; /* set config */
2219 res = a_bmp384_iic_spi_write(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2220 if (res != 0) /* check result */
2221 {
2222 handle->debug_print("bmp384: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2223
2224 return 1; /* return error */
2225 }
2226
2227 return 0; /* success return 0 */
2228}
2229
2242{
2243 uint8_t res;
2244 uint8_t prev;
2245
2246 if (handle == NULL) /* check handle */
2247 {
2248 return 2; /* return error */
2249 }
2250 if (handle->inited != 1) /* check handle initialization */
2251 {
2252 return 3; /* return error */
2253 }
2254
2255 res = a_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2256 if (res != 0) /* check result */
2257 {
2258 handle->debug_print("bmp384: get pwr ctrl register failed.\n"); /* get pwr ctrl register failed */
2259
2260 return 1; /* return error */
2261 }
2262 *mode = (bmp384_mode_t)((prev >> 4) & 0x03); /* get config */
2263
2264 return 0; /* success return 0 */
2265}
2266
2279{
2280 uint8_t res;
2281 uint8_t prev;
2282
2283 if (handle == NULL) /* check handle */
2284 {
2285 return 2; /* return error */
2286 }
2287 if (handle->inited != 1) /* check handle initialization */
2288 {
2289 return 3; /* return error */
2290 }
2291
2292 res = a_bmp384_iic_spi_read(handle, BMP384_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2293 if (res != 0) /* check result */
2294 {
2295 handle->debug_print("bmp384: get osr register failed.\n"); /* get osr register failed */
2296
2297 return 1; /* return error */
2298 }
2299 prev &= ~(7 << 0); /* clear config */
2300 prev |= oversampling << 0; /* set config */
2301 res = a_bmp384_iic_spi_write(handle, BMP384_REG_OSR, (uint8_t *)&prev, 1); /* write config */
2302 if (res != 0) /* check result */
2303 {
2304 handle->debug_print("bmp384: set osr register failed.\n"); /* set osr register failed */
2305
2306 return 1; /* return error */
2307 }
2308
2309 return 0; /* success return 0 */
2310}
2311
2324{
2325 uint8_t res;
2326 uint8_t prev;
2327
2328 if (handle == NULL) /* check handle */
2329 {
2330 return 2; /* return error */
2331 }
2332 if (handle->inited != 1) /* check handle initialization */
2333 {
2334 return 3; /* return error */
2335 }
2336
2337 res = a_bmp384_iic_spi_read(handle, BMP384_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2338 if (res != 0) /* check result */
2339 {
2340 handle->debug_print("bmp384: get osr register failed.\n"); /* get osr register failed */
2341
2342 return 1; /* return error */
2343 }
2344 *oversampling = (bmp384_oversampling_t)((prev >> 0) & 0x07); /* get config */
2345
2346 return 0; /* success return 0 */
2347}
2348
2361{
2362 uint8_t res;
2363 uint8_t prev;
2364
2365 if (handle == NULL) /* check handle */
2366 {
2367 return 2; /* return error */
2368 }
2369 if (handle->inited != 1) /* check handle initialization */
2370 {
2371 return 3; /* return error */
2372 }
2373
2374 res = a_bmp384_iic_spi_read(handle, BMP384_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2375 if (res != 0) /* check result */
2376 {
2377 handle->debug_print("bmp384: get osr register failed.\n"); /* get osr register failed */
2378
2379 return 1; /* return error */
2380 }
2381 prev &= ~(7 << 3); /* clear config */
2382 prev |= oversampling << 3; /* set config */
2383 res = a_bmp384_iic_spi_write(handle, BMP384_REG_OSR, (uint8_t *)&prev, 1); /* write config */
2384 if (res != 0) /* check result */
2385 {
2386 handle->debug_print("bmp384: set osr register failed.\n"); /* set osr register failed */
2387
2388 return 1; /* return error */
2389 }
2390
2391 return 0; /* success return 0 */
2392}
2393
2406{
2407 uint8_t res;
2408 uint8_t prev;
2409
2410 if (handle == NULL) /* check handle */
2411 {
2412 return 2; /* return error */
2413 }
2414 if (handle->inited != 1) /* check handle initialization */
2415 {
2416 return 3; /* return error */
2417 }
2418
2419 res = a_bmp384_iic_spi_read(handle, BMP384_REG_OSR, (uint8_t *)&prev, 1); /* read config */
2420 if (res != 0) /* check result */
2421 {
2422 handle->debug_print("bmp384: get osr register failed.\n"); /* get osr register failed */
2423
2424 return 1; /* return error */
2425 }
2426 *oversampling = (bmp384_oversampling_t)((prev >> 3) & 0x07); /* get config */
2427
2428 return 0; /* success return 0 */
2429}
2430
2443{
2444 uint8_t res;
2445 uint8_t prev;
2446
2447 if (handle == NULL) /* check handle */
2448 {
2449 return 2; /* return error */
2450 }
2451 if (handle->inited != 1) /* check handle initialization */
2452 {
2453 return 3; /* return error */
2454 }
2455
2456 res = a_bmp384_iic_spi_read(handle, BMP384_REG_ODR, (uint8_t *)&prev, 1); /* read config */
2457 if (res != 0) /* check result */
2458 {
2459 handle->debug_print("bmp384: get odr register failed.\n"); /* get odr register failed */
2460
2461 return 1; /* return error */
2462 }
2463
2464 prev &= ~(31 << 0); /* clear config */
2465 prev |= odr << 0; /* set config */
2466 res = a_bmp384_iic_spi_write(handle, BMP384_REG_ODR, (uint8_t *)&prev, 1); /* write config */
2467 if (res != 0) /* check result */
2468 {
2469 handle->debug_print("bmp384: set odr register failed.\n"); /* set odr register failed */
2470
2471 return 1; /* return error */
2472 }
2473
2474 return 0; /* success return 0 */
2475}
2476
2489{
2490 uint8_t res;
2491 uint8_t prev;
2492
2493 if (handle == NULL) /* check handle */
2494 {
2495 return 2; /* return error */
2496 }
2497 if (handle->inited != 1) /* check handle initialization */
2498 {
2499 return 3; /* return error */
2500 }
2501
2502 res = a_bmp384_iic_spi_read(handle, BMP384_REG_ODR, (uint8_t *)&prev, 1); /* read config */
2503 if (res != 0) /* check result */
2504 {
2505 handle->debug_print("bmp384: get odr register failed.\n"); /* get odr register failed */
2506
2507 return 1; /* return error */
2508 }
2509 *odr = (bmp384_odr_t)((prev >> 0) & 31); /* get config */
2510
2511 return 0; /* success return 0 */
2512}
2513
2526{
2527 uint8_t res;
2528 uint8_t prev;
2529
2530 if (handle == NULL) /* check handle */
2531 {
2532 return 2; /* return error */
2533 }
2534 if (handle->inited != 1) /* check handle initialization */
2535 {
2536 return 3; /* return error */
2537 }
2538
2539 res = a_bmp384_iic_spi_read(handle, BMP384_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
2540 if (res != 0) /* check result */
2541 {
2542 handle->debug_print("bmp384: get config register failed.\n"); /* get config register failed */
2543
2544 return 1; /* return error */
2545 }
2546
2547 prev &= ~(0x7 << 1); /* clear config */
2548 prev |= coefficient << 1; /* set config */
2549 res = a_bmp384_iic_spi_write(handle, BMP384_REG_CONFIG, (uint8_t *)&prev, 1); /* write config */
2550 if (res != 0) /* check result */
2551 {
2552 handle->debug_print("bmp384: set config register failed.\n"); /* set config register failed */
2553
2554 return 1; /* return error */
2555 }
2556
2557 return 0; /* success return 0 */
2558}
2559
2572{
2573 uint8_t res;
2574 uint8_t prev;
2575
2576 if (handle == NULL) /* check handle */
2577 {
2578 return 2; /* return error */
2579 }
2580 if (handle->inited != 1) /* check handle initialization */
2581 {
2582 return 3; /* return error */
2583 }
2584
2585 res = a_bmp384_iic_spi_read(handle, BMP384_REG_CONFIG, (uint8_t *)&prev, 1); /* read config */
2586 if (res != 0) /* check result */
2587 {
2588 handle->debug_print("bmp384: get config register failed.\n"); /* return error */
2589
2590 return 1; /* return error */
2591 }
2592 *coefficient = (bmp384_filter_coefficient_t)((prev >> 1) & 0x07); /* get coefficient */
2593
2594 return 0; /* success return 0 */
2595}
2596
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 prev = 0xB0; /* command */
2622 res = a_bmp384_iic_spi_write(handle, BMP384_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2623 if (res != 0) /* check result */
2624 {
2625 handle->debug_print("bmp384: set cmd register failed.\n"); /* set cmd register failed */
2626
2627 return 1; /* return error */
2628 }
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 = 0xB6; /* command */
2658 res = a_bmp384_iic_spi_write(handle, BMP384_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2659 if (res != 0) /* check result */
2660 {
2661 handle->debug_print("bmp384: 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 = 0x34; /* command */
2694 res = a_bmp384_iic_spi_write(handle, BMP384_REG_CMD, (uint8_t *)&prev, 1); /* write config */
2695 if (res != 0) /* check result */
2696 {
2697 handle->debug_print("bmp384: 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_bmp384_close(bmp384_handle_t *handle)
2716{
2717 if (handle->iic_spi == BMP384_INTERFACE_IIC) /* if iic interface */
2718 {
2719 if (handle->iic_deinit() != 0) /* close iic */
2720 {
2721 handle->debug_print("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: 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("bmp384: delay_ms is null.\n"); /* delay_ms is null */
2822
2823 return 3; /* return error */
2824 }
2825
2826 if (handle->iic_spi == BMP384_INTERFACE_IIC) /* if iic interface */
2827 {
2828 if (handle->iic_init() != 0) /* initialize iic bus */
2829 {
2830 handle->debug_print("bmp384: 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("bmp384: spi init failed.\n"); /* spi init failed */
2840
2841 return 1; /* return error */
2842 }
2843 }
2844 if (a_bmp384_iic_spi_read(handle, BMP384_REG_CHIP_ID, (uint8_t *)&id, 1) != 0) /* read chip id */
2845 {
2846 handle->debug_print("bmp384: read chip id failed.\n"); /* read chip id failed */
2847 (void)a_bmp384_close(handle); /* close bmp384 */
2848
2849 return 4; /* return error */
2850 }
2851 if (id != 0x50) /* check chip id */
2852 {
2853 handle->debug_print("bmp384: id is invalid.\n"); /* id is invalid */
2854 (void)a_bmp384_close(handle); /* close bmp384 */
2855
2856 return 4;
2857 } /* return error */
2858 reg = 0xB6; /* set command */
2859 if (a_bmp384_iic_spi_write(handle, BMP384_REG_CMD, (uint8_t *)&reg, 1) != 0) /* write command */
2860 {
2861 handle->debug_print("bmp384: soft rest failed.\n"); /* soft rest failed */
2862 (void)a_bmp384_close(handle); /* close bmp384 */
2863
2864 return 5; /* return error */
2865 }
2866 handle->delay_ms(10); /* delay 10 ms */
2867 if (a_bmp384_iic_spi_read(handle, BMP384_REG_ERR_REG, (uint8_t *)&reg, 1) != 0) /* read reg */
2868 {
2869 handle->debug_print("bmp384: get err reg failed.\n"); /* return error */
2870 (void)a_bmp384_close(handle); /* close bmp384 */
2871
2872 return 5; /* return error */
2873 }
2874 if ((reg & 0x07) != 0) /* check running status */
2875 {
2876 handle->debug_print("bmp384: find running error.\n"); /* find running error */
2877 (void)a_bmp384_close(handle); /* close bmp384 */
2878
2879 return 5; /* return error */
2880 }
2881 if (a_bmp384_get_calibration_data(handle) != 0) /* get calibration data */
2882 {
2883 handle->debug_print("bmp384: get calibration data error.\n"); /* get calibration data error */
2884 (void)a_bmp384_close(handle); /* close bmp384 */
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_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
2919 if (res != 0) /* check result */
2920 {
2921 handle->debug_print("bmp384: 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_bmp384_iic_spi_write(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
2928 if (res != 0) /* check result */
2929 {
2930 handle->debug_print("bmp384: set pwr ctrl register failed.\n"); /* set pwr ctrl register failed */
2931
2932 return 4; /* return error */
2933 }
2934 if (a_bmp384_close(handle) != 0) /* close bmp384 */
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 bmp384_read_temperature(bmp384_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_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
2974 if (res != 0) /* check result */
2975 {
2976 handle->debug_print("bmp384: 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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read pwr ctrl */
2987 if (res != 0) /* check result */
2988 {
2989 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
2996 if (res != 0) /* check result */
2997 {
2998 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3007 if (res != 0) /* check result */
3008 {
3009 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3032 if (res != 0) /* check result */
3033 {
3034 handle->debug_print("bmp384: 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_bmp384_iic_spi_write(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3041 if (res != 0) /* check result */
3042 {
3043 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
3051 if (res != 0) /* check result */
3052 {
3053 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3062 if (res != 0) /* check result */
3063 {
3064 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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("bmp384: mode is invalid.\n"); /* mode is invalid */
3093
3094 return 1; /* return error */
3095 }
3096}
3097
3110uint8_t bmp384_read_pressure(bmp384_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_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3127 if (res != 0) /* check result */
3128 {
3129 handle->debug_print("bmp384: 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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3140 if (res != 0) /* check result */
3141 {
3142 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_STATUS, (uint8_t *)&prev, 1); /* read status */
3149 if (res != 0) /* check result */
3150 {
3151 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_3, (uint8_t *)buf, 3); /* read config */
3158 if (res != 0) /* check result */
3159 {
3160 handle->debug_print("bmp384: 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_bmp384_compensate_temperature(handle, temperature_raw); /* compensate temperature */
3166 }
3167 else
3168 {
3169 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_0, (uint8_t *)buf, 3); /* read config */
3178 if (res != 0) /* check result */
3179 {
3180 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3202 if (res != 0) /* check result */
3203 {
3204 handle->debug_print("bmp384: 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_bmp384_iic_spi_write(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3211 if (res != 0) /* check result */
3212 {
3213 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3221 if (res != 0) /* check result */
3222 {
3223 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3230 if (res != 0) /* check result */
3231 {
3232 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_0, (uint8_t *)buf, 3); /* read config */
3263 if (res != 0) /* check result */
3264 {
3265 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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("bmp384: mode is invalid.\n"); /* mode is invalid */
3293
3294 return 1; /* return error */
3295 }
3296}
3297
3312uint8_t bmp384_read_temperature_pressure(bmp384_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_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3329 if (res != 0) /* check result */
3330 {
3331 handle->debug_print("bmp384: 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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3342 if (res != 0) /* check result */
3343 {
3344 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3351 if (res != 0) /* check result */
3352 {
3353 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3362 if (res != 0) /* check result */
3363 {
3364 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_0, (uint8_t *)buf, 3); /* read data */
3383 if (res != 0) /* check result */
3384 {
3385 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* read config */
3407 if (res != 0) /* check result */
3408 {
3409 handle->debug_print("bmp384: 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_bmp384_iic_spi_write(handle, BMP384_REG_PWR_CTRL, (uint8_t *)&prev, 1); /* write config */
3416 if (res != 0) /* check result */
3417 {
3418 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_STATUS, (uint8_t *)&prev, 1); /* read config */
3426 if (res != 0) /* check result */
3427 {
3428 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_3, (uint8_t *)buf, 3); /* read raw data */
3437 if (res != 0) /* check result */
3438 {
3439 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_DATA_0, (uint8_t *)buf, 3); /* read raw data */
3472 if (res != 0) /* check result */
3473 {
3474 handle->debug_print("bmp384: 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_bmp384_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("bmp384: 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("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_INT_STATUS, (uint8_t *)&status, 1); /* read config */
3532 if (res != 0) /* check result */
3533 {
3534 handle->debug_print("bmp384: 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(BMP384_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(BMP384_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(BMP384_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 = (bmp384_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 = (bmp384_interface_t)(handle->iic_spi); /* get interface */
3643
3644 return 0; /* success return 0 */
3645}
3646
3659uint8_t bmp384_read_fifo(bmp384_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_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_CONFIG_1, (uint8_t *)&prev, 1); /* read config */
3676 if (res != 0) /* check result */
3677 {
3678 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_LENGTH_0, (uint8_t *)tmp_buf, 2); /* read config */
3685 if (res != 0) /* check result */
3686 {
3687 handle->debug_print("bmp384: 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_bmp384_iic_spi_read(handle, BMP384_REG_FIFO_DATA, (uint8_t *)buf, *len); /* read config */
3698 if (res != 0) /* check result */
3699 {
3700 handle->debug_print("bmp384: 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("bmp384: 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 bmp384_fifo_parse(bmp384_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp384_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("bmp384: 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 = BMP384_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_bmp384_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 = BMP384_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_bmp384_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 = BMP384_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_bmp384_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 = BMP384_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("bmp384: 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 bmp384_set_reg(bmp384_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_bmp384_iic_spi_write(handle, reg, &value, 1); /* write register */
3867}
3868
3881uint8_t bmp384_get_reg(bmp384_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_bmp384_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(bmp384_info_t)); /* initialize bmp384 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 BMP384_REG_NVM_PAR_T3
#define BMP384_REG_NVM_PAR_T1_L
#define BMP384_REG_IF_CONF
#define BMP384_REG_DATA_3
#define MAX_CURRENT
#define BMP384_REG_FIFO_CONFIG_2
#define BMP384_REG_NVM_PAR_P10
#define BMP384_REG_FIFO_WTM_0
#define BMP384_REG_FIFO_CONFIG_1
#define BMP384_REG_NVM_PAR_P3
#define BMP384_REG_NVM_PAR_P7
#define BMP384_REG_NVM_PAR_P11
#define BMP384_REG_FIFO_LENGTH_0
#define BMP384_REG_INT_CTRL
#define BMP384_REG_NVM_PAR_P8
#define SUPPLY_VOLTAGE_MAX
#define BMP384_REG_FIFO_DATA
#define BMP384_REG_CHIP_ID
#define BMP384_REG_NVM_PAR_T2_L
#define BMP384_REG_NVM_PAR_P2_L
#define TEMPERATURE_MAX
#define BMP384_REG_NVM_PAR_P6_L
#define BMP384_REG_EVENT
#define BMP384_REG_ERR_REG
#define BMP384_REG_SENSORTIME_0
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define BMP384_REG_STATUS
#define BMP384_REG_NVM_PAR_P5_L
#define BMP384_REG_ODR
#define BMP384_REG_NVM_PAR_P4
#define CHIP_NAME
chip information definition
#define BMP384_REG_NVM_PAR_P9_L
#define BMP384_REG_CMD
chip register definition
#define DRIVER_VERSION
#define BMP384_REG_DATA_0
#define BMP384_REG_CONFIG
#define BMP384_REG_OSR
#define BMP384_REG_NVM_PAR_P1_L
#define BMP384_REG_PWR_CTRL
#define BMP384_REG_INT_STATUS
driver bmp384 header file
uint8_t bmp384_read_temperature_pressure(bmp384_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure
uint8_t bmp384_get_iic_watchdog_timer(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the iic watchdog timer status
uint8_t bmp384_deinit(bmp384_handle_t *handle)
close the chip
bmp384_event_t
bmp384 event enumeration definition
uint8_t bmp384_get_addr_pin(bmp384_handle_t *handle, bmp384_address_t *addr_pin)
get the iic address pin
uint8_t bmp384_get_spi_wire(bmp384_handle_t *handle, bmp384_spi_wire_t *wire)
get the spi wire
bmp384_mode_t
bmp384 mode enumeration definition
uint8_t bmp384_set_addr_pin(bmp384_handle_t *handle, bmp384_address_t addr_pin)
set the iic address pin
bmp384_interface_t
bmp384 interface enumeration definition
uint8_t bmp384_softreset(bmp384_handle_t *handle)
soft reset
uint8_t bmp384_get_filter_coefficient(bmp384_handle_t *handle, bmp384_filter_coefficient_t *coefficient)
get the filter coefficient
uint8_t bmp384_extmode_en_middle(bmp384_handle_t *handle)
extmode enable middle
uint8_t bmp384_get_pressure_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t *oversampling)
get the pressure oversampling
bmp384_fifo_data_source_t
bmp384 fifo data source enumeration definition
uint8_t bmp384_get_pressure(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the pressure status
uint8_t bmp384_read_pressure(bmp384_handle_t *handle, uint32_t *raw, float *pa)
read the pressure
uint8_t bmp384_get_status(bmp384_handle_t *handle, uint8_t *status)
get the status
uint8_t bmp384_set_interface(bmp384_handle_t *handle, bmp384_interface_t interface)
set the interface
uint8_t bmp384_set_pressure(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the pressure
uint8_t bmp384_set_temperature(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the temperature
bmp384_spi_wire_t
bmp384 spi wire enumeration definition
bmp384_bool_t
bmp384 bool enumeration definition
uint8_t bmp384_get_sensortime(bmp384_handle_t *handle, uint32_t *t)
get the sensor time
struct bmp384_frame_s bmp384_frame_t
bmp384 frame structure definition
uint8_t bmp384_read_temperature(bmp384_handle_t *handle, uint32_t *raw, float *c)
read the temperature
bmp384_interrupt_pin_type_t
bmp384 interrupt pin type enumeration definition
uint8_t bmp384_get_temperature_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t *oversampling)
get the temperature oversampling
uint8_t bmp384_set_pressure_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the pressure oversampling
uint8_t bmp384_get_interface(bmp384_handle_t *handle, bmp384_interface_t *interface)
get the interface
uint8_t bmp384_set_iic_watchdog_timer(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the iic watchdog timer
uint8_t bmp384_get_event(bmp384_handle_t *handle, bmp384_event_t *event)
get the event
bmp384_odr_t
bmp384 output data rate enumeration definition
bmp384_address_t
bmp384 address enumeration definition
uint8_t bmp384_set_filter_coefficient(bmp384_handle_t *handle, bmp384_filter_coefficient_t coefficient)
set the filter coefficient
uint8_t bmp384_info(bmp384_info_t *info)
get chip's information
bmp384_filter_coefficient_t
bmp384 filter coefficient enumeration definition
uint8_t bmp384_get_mode(bmp384_handle_t *handle, bmp384_mode_t *mode)
get the chip mode
struct bmp384_info_s bmp384_info_t
bmp384 information structure definition
uint8_t bmp384_set_spi_wire(bmp384_handle_t *handle, bmp384_spi_wire_t wire)
set the spi wire
uint8_t bmp384_set_mode(bmp384_handle_t *handle, bmp384_mode_t mode)
set the chip mode
uint8_t bmp384_init(bmp384_handle_t *handle)
initialize the chip
bmp384_iic_watchdog_period_t
bmp384 iic watchdog period enumeration definition
uint8_t bmp384_set_iic_watchdog_period(bmp384_handle_t *handle, bmp384_iic_watchdog_period_t period)
set the iic watchdog period
uint8_t bmp384_get_iic_watchdog_period(bmp384_handle_t *handle, bmp384_iic_watchdog_period_t *period)
get the iic watchdog period
uint8_t bmp384_get_odr(bmp384_handle_t *handle, bmp384_odr_t *odr)
get the output data rate
bmp384_oversampling_t
bmp384 oversampling enumeration definition
uint8_t bmp384_irq_handler(bmp384_handle_t *handle)
irq handler
uint8_t bmp384_set_temperature_oversampling(bmp384_handle_t *handle, bmp384_oversampling_t oversampling)
set the temperature oversampling
struct bmp384_handle_s bmp384_handle_t
bmp384 handle structure definition
uint8_t bmp384_set_odr(bmp384_handle_t *handle, bmp384_odr_t odr)
set the output data rate
uint8_t bmp384_get_temperature(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the temperature status
uint8_t bmp384_get_error(bmp384_handle_t *handle, uint8_t *err)
get the error
bmp384_interrupt_active_level_t
bmp384 interrupt active level enumeration definition
@ BMP384_INTERFACE_IIC
@ BMP384_FRAME_TYPE_SENSORTIME
@ BMP384_FRAME_TYPE_PRESSURE
@ BMP384_FRAME_TYPE_TEMPERATURE
@ BMP384_INTERRUPT_STATUS_FIFO_WATERMARK
@ BMP384_INTERRUPT_STATUS_FIFO_FULL
@ BMP384_INTERRUPT_STATUS_DATA_READY
uint8_t bmp384_set_reg(bmp384_handle_t *handle, uint8_t reg, uint8_t value)
set the chip register
uint8_t bmp384_get_reg(bmp384_handle_t *handle, uint8_t reg, uint8_t *value)
get the chip register
uint8_t bmp384_fifo_parse(bmp384_handle_t *handle, uint8_t *buf, uint16_t buf_len, bmp384_frame_t *frame, uint16_t *frame_len)
parse the fifo data
uint8_t bmp384_get_fifo_pressure_on(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo pressure on status
uint8_t bmp384_set_fifo_pressure_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo pressure on
uint8_t bmp384_set_fifo_data_source(bmp384_handle_t *handle, bmp384_fifo_data_source_t source)
set the fifo data source
uint8_t bmp384_get_fifo_length(bmp384_handle_t *handle, uint16_t *length)
get the fifo length
uint8_t bmp384_set_fifo_stop_on_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo stopping on full
uint8_t bmp384_set_fifo_sensortime_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo sensor time on
uint8_t bmp384_get_fifo_temperature_on(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo temperature on status
uint8_t bmp384_read_fifo(bmp384_handle_t *handle, uint8_t *buf, uint16_t *len)
read the fifo
uint8_t bmp384_set_fifo(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo
uint8_t bmp384_get_fifo(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo status
uint8_t bmp384_get_fifo_stop_on_full(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo stopping on full status
uint8_t bmp384_get_fifo_sensortime_on(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the fifo sensor time on status
uint8_t bmp384_flush_fifo(bmp384_handle_t *handle)
flush the fifo
uint8_t bmp384_set_fifo_temperature_on(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo temperature on
uint8_t bmp384_get_fifo_data_source(bmp384_handle_t *handle, bmp384_fifo_data_source_t *source)
get the fifo data source
uint8_t bmp384_get_fifo_watermark(bmp384_handle_t *handle, uint16_t *watermark)
get the fifo watermark
uint8_t bmp384_set_fifo_watermark(bmp384_handle_t *handle, uint16_t watermark)
set the fifo watermark
uint8_t bmp384_get_fifo_data(bmp384_handle_t *handle, uint8_t *data, uint16_t length)
get the fifo data
uint8_t bmp384_set_fifo_subsampling(bmp384_handle_t *handle, uint8_t subsample)
set the fifo subsampling
uint8_t bmp384_get_fifo_subsampling(bmp384_handle_t *handle, uint8_t *subsample)
get the fifo subsampling
uint8_t bmp384_set_interrupt_pin_type(bmp384_handle_t *handle, bmp384_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t bmp384_get_interrupt_active_level(bmp384_handle_t *handle, bmp384_interrupt_active_level_t *level)
get the interrupt active level
uint8_t bmp384_set_interrupt_active_level(bmp384_handle_t *handle, bmp384_interrupt_active_level_t level)
set the interrupt active level
uint8_t bmp384_get_interrupt_fifo_full(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the interrupt fifo full
uint8_t bmp384_get_interrupt_status(bmp384_handle_t *handle, uint8_t *status)
get the interrupt status
uint8_t bmp384_set_interrupt_data_ready(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the data ready interrupt
uint8_t bmp384_get_interrupt_pin_type(bmp384_handle_t *handle, bmp384_interrupt_pin_type_t *pin_type)
get the interrupt pin type
uint8_t bmp384_get_interrupt_fifo_watermark(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the interrupt fifo watermark
uint8_t bmp384_set_interrupt_fifo_full(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo full interrupt
uint8_t bmp384_get_latch_interrupt_pin_and_interrupt_status(bmp384_handle_t *handle, bmp384_bool_t *enable)
get latching interrupt pin and interrupt status
uint8_t bmp384_set_interrupt_fifo_watermark(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable the fifo watermark interrupt
uint8_t bmp384_set_latch_interrupt_pin_and_interrupt_status(bmp384_handle_t *handle, bmp384_bool_t enable)
enable or disable latching interrupt pin and interrupt status
uint8_t bmp384_get_interrupt_data_ready(bmp384_handle_t *handle, bmp384_bool_t *enable)
get the interrupt data ready status
bmp384_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]