LibDriver MAX30105
Loading...
Searching...
No Matches
driver_max30105.c
Go to the documentation of this file.
1
36
37#include "driver_max30105.h"
38
42#define CHIP_NAME "Maxim Integrated MAX30105"
43#define MANUFACTURER_NAME "Maxim Integrated"
44#define SUPPLY_VOLTAGE_MIN 1.7f
45#define SUPPLY_VOLTAGE_MAX 2.0f
46#define MAX_CURRENT 50.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
54#define MAX30105_ADDRESS 0xAE
55
59#define MAX30105_REG_INTERRUPT_STATUS_1 0x00
60#define MAX30105_REG_INTERRUPT_STATUS_2 0x01
61#define MAX30105_REG_INTERRUPT_ENABLE_1 0x02
62#define MAX30105_REG_INTERRUPT_ENABLE_2 0x03
63#define MAX30105_REG_FIFO_WRITE_POINTER 0x04
64#define MAX30105_REG_OVERFLOW_COUNTER 0x05
65#define MAX30105_REG_FIFO_READ_POINTER 0x06
66#define MAX30105_REG_FIFO_DATA_REGISTER 0x07
67#define MAX30105_REG_FIFO_CONFIG 0x08
68#define MAX30105_REG_MODE_CONFIG 0x09
69#define MAX30105_REG_SPO2_CONFIG 0x0A
70#define MAX30105_REG_LED_1_PA 0x0C
71#define MAX30105_REG_LED_2_PA 0x0D
72#define MAX30105_REG_LED_3_PA 0x0E
73#define MAX30105_REG_PILOT_PA 0x10
74#define MAX30105_REG_MULTI_LED_MODE_CONTROL_1 0x11
75#define MAX30105_REG_MULTI_LED_MODE_CONTROL_2 0x12
76#define MAX30105_REG_DIE_TEMP_INTEGER 0x1F
77#define MAX30105_REG_DIE_TEMP_FRACTION 0x20
78#define MAX30105_REG_DIE_TEMP_CONFIG 0x21
79#define MAX30105_REG_PROX_INT_THRESH 0x30
80#define MAX30105_REG_REVISION_ID 0xFE
81#define MAX30105_REG_PART_ID 0xFF
82
97{
98 uint8_t res;
99 uint8_t prev;
100 uint8_t part_id;
101
102 if (handle == NULL) /* check handle */
103 {
104 return 2; /* return error */
105 }
106 if (handle->debug_print == NULL) /* check debug_print */
107 {
108 return 3; /* return error */
109 }
110 if (handle->iic_init == NULL) /* check iic_init */
111 {
112 handle->debug_print("max30105: iic_init is null.\n"); /* iic_init is null */
113
114 return 3; /* return error */
115 }
116 if (handle->iic_deinit == NULL) /* check iic_deinit */
117 {
118 handle->debug_print("max30105: iic_deinit is null.\n"); /* iic_deinit is null */
119
120 return 3; /* return error */
121 }
122 if (handle->iic_read == NULL) /* check iic_read */
123 {
124 handle->debug_print("max30105: iic_read is null.\n"); /* iic_read is null */
125
126 return 3; /* return error */
127 }
128 if (handle->iic_write == NULL) /* check iic_write */
129 {
130 handle->debug_print("max30105: iic_write is null.\n"); /* iic_write is null */
131
132 return 3; /* return error */
133 }
134 if (handle->receive_callback == NULL) /* check receive_callback */
135 {
136 handle->debug_print("max30105: receive_callback is null.\n"); /* receive_callback is null */
137
138 return 3; /* return error */
139 }
140 if (handle->delay_ms == NULL) /* check delay_ms */
141 {
142 handle->debug_print("max30105: delay_ms is null.\n"); /* delay_ms is null */
143
144 return 3; /* return error */
145 }
146
147 if (handle->iic_init() != 0) /* init iic */
148 {
149 handle->debug_print("max30105: iic init failed.\n"); /* iic init failed */
150
151 return 1; /* return error */
152 }
153 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_PART_ID, (uint8_t *)&part_id, 1); /* read part id */
154 if (res != 0) /* check result */
155 {
156 handle->debug_print("max30105: read part id failed.\n"); /* read part id failed */
157 (void)handle->iic_deinit(); /* iic deinit */
158
159 return 4; /* return error */
160 }
161 if (part_id != 0x15) /* check part id */
162 {
163 handle->debug_print("max30105: id is invalid.\n"); /* id is invalid */
164 (void)handle->iic_deinit(); /* iic deinit */
165
166 return 4; /* return error */
167 }
168 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
169 if (res != 0) /* check result */
170 {
171 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
172 (void)handle->iic_deinit(); /* iic deinit */
173
174 return 5; /* return error */
175 }
176 prev &= ~(1 << 6); /* clear config */
177 prev |= 1 << 6; /* set 1 */
178 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* write mode config */
179 if (res != 0) /* check result */
180 {
181 handle->debug_print("max30105: write mode config failed.\n"); /* write mode config failed */
182 (void)handle->iic_deinit(); /* iic deinit */
183
184 return 5; /* return error */
185 }
186 handle->delay_ms(10); /* delay 10 ms */
187 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
188 if (res != 0) /* check result */
189 {
190 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
191 (void)handle->iic_deinit(); /* iic deinit */
192
193 return 5; /* return error */
194 }
195 if ((prev & (1 << 6)) != 0) /* check result */
196 {
197 handle->debug_print("max30105: reset failed.\n"); /* reset failed */
198 (void)handle->iic_deinit(); /* iic deinit */
199
200 return 5; /* return error */
201 }
202 prev = 0; /* set zero */
203 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_READ_POINTER, (uint8_t *)&prev, 1); /* write fifo read pointer */
204 if (res != 0) /* check result */
205 {
206 handle->debug_print("max30105: write fifo read pointer failed.\n"); /* write fifo read pointer failed */
207 (void)handle->iic_deinit(); /* iic deinit */
208
209 return 6; /* return error */
210 }
211 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_WRITE_POINTER, (uint8_t *)&prev, 1); /* write fifo write pointer */
212 if (res != 0) /* check result */
213 {
214 handle->debug_print("max30105: write fifo write pointer failed.\n"); /* write fifo write pointer failed */
215 (void)handle->iic_deinit(); /* iic deinit */
216
217 return 6; /* return error */
218 }
219 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_OVERFLOW_COUNTER, (uint8_t *)&prev, 1); /* write overflow counter */
220 if (res != 0) /* check result */
221 {
222 handle->debug_print("max30105: write overflow counter failed.\n"); /* write overflow counter failed */
223 (void)handle->iic_deinit(); /* iic deinit */
224
225 return 6; /* return error */
226 }
227 handle->inited = 1; /* flag finish initialization */
228
229 return 0; /* success return 0 */
230}
231
244{
245 uint8_t res;
246 uint8_t prev;
247
248 if (handle == NULL) /* check handle */
249 {
250 return 2; /* return error */
251 }
252 if (handle->inited != 1) /* check handle initialization */
253 {
254 return 3; /* return error */
255 }
256
257 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
258 if (res != 0) /* check result */
259 {
260 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
261
262 return 4; /* return error */
263 }
264 prev &= ~(1 << 7); /* clear config */
265 prev |= 1 << 7; /* set bool */
266 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* write mode config */
267 if (res != 0) /* check result */
268 {
269 handle->debug_print("max30105: write mode config failed.\n"); /* write mode config failed */
270
271 return 4; /* return error */
272 }
273 if (handle->iic_deinit() != 0) /* iic deinit */
274 {
275 handle->debug_print("max30105: iic deinit failed.\n"); /* iic deinit failed */
276
277 return 1; /* return error */
278 }
279
280 handle->inited = 0; /* flag close */
281
282 return 0; /* success return 0 */
283}
284
296{
297 uint8_t res;
298 uint8_t prev;
299
300 if (handle == NULL) /* check handle */
301 {
302 return 2; /* return error */
303 }
304 if (handle->inited != 1) /* check handle initialization */
305 {
306 return 3; /* return error */
307 }
308
309 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_STATUS_1, (uint8_t *)&prev, 1); /* read interrupt status1 */
310 if (res != 0) /* check result */
311 {
312 handle->debug_print("max30105: read interrupt status1 failed.\n"); /* read interrupt status1 failed */
313
314 return 1; /* return error */
315 }
316 if ((prev & (1 << MAX30105_INTERRUPT_STATUS_FIFO_FULL)) != 0) /* check fifo full */
317 {
318 if (handle->receive_callback != NULL) /* if receive callback */
319 {
320 handle->receive_callback(MAX30105_INTERRUPT_STATUS_FIFO_FULL); /* run callback */
321 }
322 }
323 if ((prev & (1 << MAX30105_INTERRUPT_STATUS_DATA_RDY)) != 0) /* check data ready */
324 {
325 if (handle->receive_callback != NULL) /* if receive callback */
326 {
327 handle->receive_callback(MAX30105_INTERRUPT_STATUS_DATA_RDY); /* run callback */
328 }
329 }
330 if ((prev & (1 << MAX30105_INTERRUPT_STATUS_ALC_OVF)) != 0) /* check alc ovf */
331 {
332 if (handle->receive_callback != NULL) /* if receive callback */
333 {
334 handle->receive_callback(MAX30105_INTERRUPT_STATUS_ALC_OVF); /* run callback */
335 }
336 }
337 if ((prev & (1 << MAX30105_INTERRUPT_STATUS_PROX_INT)) != 0) /* check proxy int */
338 {
339 if (handle->receive_callback != NULL) /* if receive callback */
340 {
341 handle->receive_callback(MAX30105_INTERRUPT_STATUS_PROX_INT); /* run callback */
342 }
343 }
344 if ((prev & (1 << MAX30105_INTERRUPT_STATUS_PWR_RDY)) != 0) /* check pwr ready */
345 {
346 if (handle->receive_callback != NULL) /* if receive callback */
347 {
348 handle->receive_callback(MAX30105_INTERRUPT_STATUS_PWR_RDY); /* run callback */
349 }
350 }
351 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_STATUS_2, (uint8_t *)&prev, 1); /* read interrupt status2 */
352 if (res != 0) /* check result */
353 {
354 handle->debug_print("max30105: read interrupt status2 failed.\n"); /* read interrupt status2 failed */
355
356 return 1; /* return error */
357 }
358 if ((prev & (1 << MAX30105_INTERRUPT_STATUS_DIE_TEMP_RDY)) != 0) /* check die temp ready */
359 {
360 uint8_t prev1;
361
362 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_DIE_TEMP_INTEGER, (uint8_t *)&prev, 1); /* read die temp integer */
363 if (res != 0) /* check result */
364 {
365 handle->debug_print("max30105: read die temp integer failed.\n"); /* read die temp integer failed */
366
367 return 1; /* return error */
368 }
369 handle->raw = (uint16_t)prev << 4; /* set integer part */
370 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_DIE_TEMP_FRACTION, (uint8_t *)&prev1, 1); /* read die temp fraction */
371 if (res != 0) /* check result */
372 {
373 handle->debug_print("max30105: read die temp fraction failed.\n"); /* read die temp fraction failed */
374
375 return 1; /* return error */
376 }
377 handle->raw = handle->raw | prev1; /* set fraction part */
378 handle->temperature = (float)(prev) + (float)(prev1) * 0.0625f; /* set the temperature */
379 handle->finished_flag = 1; /* set flag */
380
381 if (handle->receive_callback != NULL) /* if receive callback */
382 {
384 }
385 }
386
387 return 0; /* success return 0 */
388}
389
406uint8_t max30105_read(max30105_handle_t *handle, uint32_t *raw_red, uint32_t *raw_ir, uint32_t *raw_green, uint8_t *len)
407{
408 uint8_t res;
409 uint8_t prev;
410 uint8_t mode;
411 uint8_t k;
412 uint8_t read_point;
413 uint8_t write_point;
414 uint8_t l;
415 uint8_t bit;
416 uint8_t i;
417 uint8_t r;
418
419 if (handle == NULL) /* check handle */
420 {
421 return 2; /* return error */
422 }
423 if (handle->inited != 1) /* check handle initialization */
424 {
425 return 3; /* return error */
426 }
427
428 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_OVERFLOW_COUNTER, (uint8_t *)&prev, 1); /* read overflow counter */
429 if (res != 0) /* check result */
430 {
431 handle->debug_print("max30105: read overflow counter failed.\n"); /* read overflow counter failed */
432
433 return 1; /* return error */
434 }
435 r = 0; /* set 0 */
436 if (prev != 0) /* check overflow */
437 {
438 r = 4; /* set 4 */
439
440 handle->debug_print("max30105: fifo overrun.\n"); /* fifo overrun*/
441 }
442 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_READ_POINTER, (uint8_t *)&read_point, 1); /* read fifo read point */
443 if (res != 0) /* check result */
444 {
445 handle->debug_print("max30105: read fifo read point failed.\n"); /* read fifo read point failed */
446
447 return 1; /* return error */
448 }
449 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_WRITE_POINTER, (uint8_t *)&write_point, 1); /* read fifo write point */
450 if (res != 0) /* check result */
451 {
452 handle->debug_print("max30105: read fifo write point failed.\n"); /* read fifo write point failed */
453
454 return 1; /* return error */
455 }
456
457 if (write_point > read_point) /* check point */
458 {
459 l = write_point - read_point; /* get length */
460 }
461 else
462 {
463 l = 32 + write_point - read_point; /* get length */
464 }
465 *len = ((*len) > l) ? l : (*len); /* set read length */
466 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
467 if (res != 0) /* check result */
468 {
469 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
470
471 return 1; /* return error */
472 }
473 mode = (max30105_mode_t)(prev & 0x7); /* get mode */
474 if (mode == MAX30105_MODE_RED) /* check red mode */
475 {
476 k = 3; /* 3 */
477 }
478 else if (mode == MAX30105_MODE_RED_IR) /* check red && ir mode*/
479 {
480 k = 6; /* 6 */
481 }
482 else if (mode == MAX30105_MODE_GREEN_RED_IR) /* check red && ir && green mode */
483 {
484 k = 9; /* 9 */
485 }
486 else
487 {
488 handle->debug_print("max30105: mode is invalid.\n"); /* mode is invalid */
489
490 return 5; /* return error */
491 }
492
493 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_DATA_REGISTER, handle->buf, (*len) * k); /* read fifo read point */
494 if (res != 0) /* check result */
495 {
496 handle->debug_print("max30105: read fifo data register failed.\n"); /* read fifo data register failed */
497
498 return 1; /* return error */
499 }
500 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* read spo2 config */
501 if (res != 0) /* check result */
502 {
503 handle->debug_print("max30105: read spo2 config failed.\n"); /* read spo2 config failed */
504
505 return 1; /* return error */
506 }
507 prev = prev & 0x3; /* get config */
508 if (prev == 0) /* if 0 */
509 {
510 bit = 3; /* 15 bits */
511 }
512 else if (prev == 1) /* if 1 */
513 {
514 bit = 2; /* 16 bits */
515 }
516 else if (prev == 2) /* if 2 */
517 {
518 bit = 1; /* 17 bits */
519 }
520 else /* if 3 */
521 {
522 bit = 0; /* 18 bits */
523 }
524 for (i = 0; i < (*len); i++) /* copy data */
525 {
526 if (mode == MAX30105_MODE_RED) /* check red mode */
527 {
528 raw_red[i] = ((uint32_t)handle->buf[i * 3 + 0] << 16) | /* get raw red data */
529 ((uint32_t)handle->buf[i * 3 + 1] << 8) | /* get raw red data */
530 ((uint32_t)handle->buf[i * 3 + 2] << 0); /* get raw red data */
531 raw_red[i] = raw_red[i] >> bit; /* right shift bit */
532 }
533 else if (mode == MAX30105_MODE_RED_IR) /* check red && ir mode*/
534 {
535 raw_red[i] = ((uint32_t)handle->buf[i * 6 + 0] << 16) | /* get raw red data */
536 ((uint32_t)handle->buf[i * 6 + 1] << 8) | /* get raw red data */
537 ((uint32_t)handle->buf[i * 6 + 2] << 0); /* get raw red data */
538 raw_red[i] = raw_red[i] >> bit; /* right shift bit */
539 raw_ir[i] = ((uint32_t)handle->buf[i * 6 + 3] << 16) | /* get raw ir data */
540 ((uint32_t)handle->buf[i * 6 + 4] << 8) | /* get raw ir data */
541 ((uint32_t)handle->buf[i * 6 + 5] << 0); /* get raw ir data */
542 raw_ir[i] = raw_ir[i] >> bit; /* right shift bit */
543 }
544 else
545 {
546 raw_red[i] = ((uint32_t)handle->buf[i * 9 + 0] << 16) | /* get raw red data */
547 ((uint32_t)handle->buf[i * 9 + 1] << 8) | /* get raw red data */
548 ((uint32_t)handle->buf[i * 9 + 2] << 0); /* get raw red data */
549 raw_red[i] = raw_red[i] >> bit; /* right shift bit */
550 raw_ir[i] = ((uint32_t)handle->buf[i * 9 + 3] << 16) | /* get raw ir data */
551 ((uint32_t)handle->buf[i * 9 + 4] << 8) | /* get raw ir data */
552 ((uint32_t)handle->buf[i * 9 + 5] << 0); /* get raw ir data */
553 raw_ir[i] = raw_ir[i] >> bit; /* right shift bit */
554 raw_green[i] = ((uint32_t)handle->buf[i * 9 + 6] << 16) | /* get raw green data */
555 ((uint32_t)handle->buf[i * 9 + 7] << 8) | /* get raw green data */
556 ((uint32_t)handle->buf[i * 9 + 8] << 0); /* get raw green data */
557 raw_green[i] = raw_green[i] >> bit; /* right shift bit */
558 }
559 }
560
561 return r; /* success return 0 */
562}
563
576uint8_t max30105_read_temperature(max30105_handle_t *handle, uint16_t *raw, float *temp)
577{
578 uint8_t res;
579 uint8_t prev;
580 uint16_t timeout;
581
582 if (handle == NULL) /* check handle */
583 {
584 return 2; /* return error */
585 }
586 if (handle->inited != 1) /* check handle initialization */
587 {
588 return 3; /* return error */
589 }
590
591 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_2, (uint8_t *)&prev, 1); /* read interrupt enable2 */
592 if (res != 0) /* check result */
593 {
594 handle->debug_print("max30105: read interrupt enable2 failed.\n"); /* read interrupt enable2 failed */
595
596 return 1; /* return error */
597 }
598 if ((prev & (1 << 1)) == 0) /* check config */
599 {
600 prev &= ~(1 << 1); /* clear interrupt */
601 prev |= 1 << 1; /* set interrupt */
602 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_2, (uint8_t *)&prev, 1); /* write interrupt enable2 */
603 if (res != 0) /* check result */
604 {
605 handle->debug_print("max30105: write interrupt enable2 failed.\n"); /* write interrupt enable2 failed */
606
607 return 1; /* return error */
608 }
609 }
610
611 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_DIE_TEMP_CONFIG, (uint8_t *)&prev, 1); /* read die temp config */
612 if (res != 0) /* check result */
613 {
614 handle->debug_print("max30105: read die temp config failed.\n"); /* read die temp config failed */
615
616 return 1; /* return error */
617 }
618 prev &= ~(1 << 0); /* clear config */
619 prev |= (1 << 0); /* set bool */
620 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_DIE_TEMP_CONFIG, (uint8_t *)&prev, 1); /* write die temp config */
621 if (res != 0) /* check result */
622 {
623 handle->debug_print("max30105: write die temp config failed.\n"); /* write die temp config failed */
624
625 return 1; /* return error */
626 }
627
628 timeout = 5000; /* set 5000 ms */
629 handle->finished_flag = 0; /* clear finished flag */
630 while (timeout != 0) /* timeout */
631 {
632 handle->delay_ms(1); /* delay 1 ms */
633 timeout--; /* timeout */
634 if (handle->finished_flag != 0) /* check finished flag */
635 {
636 break; /* break */
637 }
638 }
639 if (timeout == 0) /* check timeout */
640 {
641 handle->debug_print("max30105: read timeout.\n"); /* read timeout */
642
643 return 1; /* return error */
644 }
645 *raw = handle->raw; /* get raw */
646 *temp = handle->temperature; /* get temperature */
647
648 return 0; /* success return 0 */
649}
650
664{
665 uint8_t res;
666 uint8_t prev;
667
668 if (handle == NULL) /* check handle */
669 {
670 return 2; /* return error */
671 }
672 if (handle->inited != 1) /* check handle initialization */
673 {
674 return 3; /* return error */
675 }
676
677 if (status == MAX30105_INTERRUPT_STATUS_DIE_TEMP_RDY) /* if die temp ready status */
678 {
679 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_STATUS_2, (uint8_t *)&prev, 1); /* read interrupt status2 */
680 if (res != 0) /* check result */
681 {
682 handle->debug_print("max30105: read interrupt status2 failed.\n"); /* read interrupt status2 failed */
683
684 return 1; /* return error */
685 }
686 *enable = (max30105_bool_t)((prev >> status) & 0x01); /* get bool */
687
688 return 0; /* success return 0 */
689 }
690 else
691 {
692 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_STATUS_1, (uint8_t *)&prev, 1); /* read interrupt status1 */
693 if (res != 0) /* check result */
694 {
695 handle->debug_print("max30105: read interrupt status1 failed.\n"); /* read interrupt status1 failed */
696
697 return 1; /* return error */
698 }
699 *enable = (max30105_bool_t)((prev >> status) & 0x01); /* get bool */
700
701 return 0; /* success return 0 */
702 }
703}
704
718{
719 uint8_t res;
720 uint8_t prev;
721
722 if (handle == NULL) /* check handle */
723 {
724 return 2; /* return error */
725 }
726 if (handle->inited != 1) /* check handle initialization */
727 {
728 return 3; /* return error */
729 }
730
731 if (type == MAX30105_INTERRUPT_DIE_TEMP_RDY_EN) /* if internal temperature enable */
732 {
733 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_2, (uint8_t *)&prev, 1); /* read interrupt enable2 */
734 if (res != 0) /* check result */
735 {
736 handle->debug_print("max30105: read interrupt enable2 failed.\n"); /* read interrupt enable2 failed */
737
738 return 1; /* return error */
739 }
740 prev &= ~(1 << type); /* clear interrupt */
741 prev |= enable << type; /* set interrupt */
742 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_2, (uint8_t *)&prev, 1); /* write interrupt enable2 */
743 if (res != 0) /* check result */
744 {
745 handle->debug_print("max30105: write interrupt enable2 failed.\n"); /* write interrupt enable2 failed */
746
747 return 1; /* return error */
748 }
749
750 return 0; /* success return 0 */
751 }
752 else
753 {
754 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_1, (uint8_t *)&prev, 1); /* read interrupt enable1 */
755 if (res != 0) /* check result */
756 {
757 handle->debug_print("max30105: read interrupt enable1 failed.\n"); /* read interrupt enable1 failed */
758
759 return 1; /* return error */
760 }
761 prev &= ~(1 << type); /* clear interrupt */
762 prev |= enable << type; /* set interrupt */
763 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_1, (uint8_t *)&prev, 1); /* write interrupt enable1 */
764 if (res != 0) /* check result */
765 {
766 handle->debug_print("max30105: write interrupt enable1 failed.\n"); /* write interrupt enable1 failed */
767
768 return 1; /* return error */
769 }
770
771 return 0; /* success return 0 */
772 }
773}
774
788{
789 uint8_t res;
790 uint8_t prev;
791
792 if (handle == NULL) /* check handle */
793 {
794 return 2; /* return error */
795 }
796 if (handle->inited != 1) /* check handle initialization */
797 {
798 return 3; /* return error */
799 }
800
801 if (type == MAX30105_INTERRUPT_DIE_TEMP_RDY_EN) /* if internal temperature enable */
802 {
803 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_2, (uint8_t *)&prev, 1); /* read interrupt enable2 */
804 if (res != 0) /* check result */
805 {
806 handle->debug_print("max30105: read interrupt enable2 failed.\n"); /* read interrupt enable2 failed */
807
808 return 1; /* return error */
809 }
810 *enable = (max30105_bool_t)((prev >> type) & 0x01); /* get bool */
811
812 return 0; /* success return 0 */
813 }
814 else
815 {
816 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_INTERRUPT_ENABLE_1, (uint8_t *)&prev, 1); /* read interrupt enable1 */
817 if (res != 0) /* check result */
818 {
819 handle->debug_print("max30105: read interrupt enable1 failed.\n"); /* read interrupt enable1 failed */
820
821 return 1; /* return error */
822 }
823 *enable = (max30105_bool_t)((prev >> type) & 0x01); /* get bool */
824
825 return 0; /* success return 0 */
826 }
827}
828
841uint8_t max30105_set_fifo_write_pointer(max30105_handle_t *handle, uint8_t pointer)
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 if (pointer > 0x1F) /* check pointer */
855 {
856 handle->debug_print("max30105: pointer can't be over 0x1F.\n"); /* pointer can't be over 0x1F */
857
858 return 4; /* return error */
859 }
860
861 prev = pointer & 0x1F; /* set pointer */
862 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_WRITE_POINTER, (uint8_t *)&prev, 1); /* write fifo write pointer */
863 if (res != 0) /* check result */
864 {
865 handle->debug_print("max30105: write fifo write pointer failed.\n"); /* write fifo write pointer failed */
866
867 return 1; /* return error */
868 }
869
870 return 0; /* success return 0 */
871}
872
884uint8_t max30105_get_fifo_write_pointer(max30105_handle_t *handle, uint8_t *pointer)
885{
886 uint8_t res;
887 uint8_t prev;
888
889 if (handle == NULL) /* check handle */
890 {
891 return 2; /* return error */
892 }
893 if (handle->inited != 1) /* check handle initialization */
894 {
895 return 3; /* return error */
896 }
897
898 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_WRITE_POINTER, (uint8_t *)&prev, 1); /* read fifo write pointer */
899 if (res != 0) /* check result */
900 {
901 handle->debug_print("max30105: read fifo write pointer failed.\n"); /* read fifo write pointer failed */
902
903 return 1; /* return error */
904 }
905 *pointer = prev & 0x1F; /* get pointer */
906
907 return 0; /* success return 0 */
908}
909
923{
924 uint8_t res;
925 uint8_t prev;
926
927 if (handle == NULL) /* check handle */
928 {
929 return 2; /* return error */
930 }
931 if (handle->inited != 1) /* check handle initialization */
932 {
933 return 3; /* return error */
934 }
935 if (counter > 0x1F) /* check counter */
936 {
937 handle->debug_print("max30105: counter can't be over 0x1F.\n"); /* counter can't be over 0x1F */
938
939 return 4; /* return error */
940 }
941
942 prev = counter & 0x1F; /* set counter */
943 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_OVERFLOW_COUNTER, (uint8_t *)&prev, 1); /* set fifo overflow counter */
944 if (res != 0) /* check result */
945 {
946 handle->debug_print("max30105: set fifo overflow counter failed.\n"); /* set fifo overflow counter failed */
947
948 return 1; /* return error */
949 }
950
951 return 0; /* success return 0 */
952}
953
966{
967 uint8_t res;
968 uint8_t prev;
969
970 if (handle == NULL) /* check handle */
971 {
972 return 2; /* return error */
973 }
974 if (handle->inited != 1) /* check handle initialization */
975 {
976 return 3; /* return error */
977 }
978
979 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_OVERFLOW_COUNTER, (uint8_t *)&prev, 1); /* get fifo overflow counter */
980 if (res != 0) /* check result */
981 {
982 handle->debug_print("max30105: get fifo overflow counter failed.\n"); /* get fifo overflow counter failed */
983
984 return 1; /* return error */
985 }
986 *counter = prev & 0x1F; /* get pointer */
987
988 return 0; /* success return 0 */
989}
990
1003uint8_t max30105_set_fifo_read_pointer(max30105_handle_t *handle, uint8_t pointer)
1004{
1005 uint8_t res;
1006 uint8_t prev;
1007
1008 if (handle == NULL) /* check handle */
1009 {
1010 return 2; /* return error */
1011 }
1012 if (handle->inited != 1) /* check handle initialization */
1013 {
1014 return 3; /* return error */
1015 }
1016 if (pointer > 0x1F) /* check pointer */
1017 {
1018 handle->debug_print("max30105: pointer can't be over 0x1F.\n"); /* pointer can't be over 0x1F */
1019
1020 return 4; /* return error */
1021 }
1022
1023 prev = pointer & 0x1F; /* set pointer */
1024 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_READ_POINTER, (uint8_t *)&prev, 1); /* write fifo read pointer */
1025 if (res != 0) /* check result */
1026 {
1027 handle->debug_print("max30105: write fifo read pointer failed.\n"); /* write fifo read pointer failed */
1028
1029 return 1; /* return error */
1030 }
1031
1032 return 0; /* success return 0 */
1033}
1034
1046uint8_t max30105_get_fifo_read_pointer(max30105_handle_t *handle, uint8_t *pointer)
1047{
1048 uint8_t res;
1049 uint8_t prev;
1050
1051 if (handle == NULL) /* check handle */
1052 {
1053 return 2; /* return error */
1054 }
1055 if (handle->inited != 1) /* check handle initialization */
1056 {
1057 return 3; /* return error */
1058 }
1059
1060 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_READ_POINTER, (uint8_t *)&prev, 1); /* read fifo read pointer */
1061 if (res != 0) /* check result */
1062 {
1063 handle->debug_print("max30105: read fifo read pointer failed.\n"); /* read fifo read pointer failed */
1064
1065 return 1; /* return error */
1066 }
1067 *pointer = prev & 0x1F; /* get pointer */
1068
1069 return 0; /* success return 0 */
1070}
1071
1083uint8_t max30105_set_fifo_data(max30105_handle_t *handle, uint8_t data)
1084{
1085 uint8_t res;
1086
1087 if (handle == NULL) /* check handle */
1088 {
1089 return 2; /* return error */
1090 }
1091 if (handle->inited != 1) /* check handle initialization */
1092 {
1093 return 3; /* return error */
1094 }
1095
1096 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_DATA_REGISTER, (uint8_t *)&data, 1); /* write fifo data register */
1097 if (res != 0) /* check result */
1098 {
1099 handle->debug_print("max30105: write fifo data register failed.\n"); /* write fifo data register failed */
1100
1101 return 1; /* return error */
1102 }
1103
1104 return 0; /* success return 0 */
1105}
1106
1118uint8_t max30105_get_fifo_data(max30105_handle_t *handle, uint8_t *data)
1119{
1120 uint8_t res;
1121
1122 if (handle == NULL) /* check handle */
1123 {
1124 return 2; /* return error */
1125 }
1126 if (handle->inited != 1) /* check handle initialization */
1127 {
1128 return 3; /* return error */
1129 }
1130
1131 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_DATA_REGISTER, (uint8_t *)data, 1); /* read fifo data register */
1132 if (res != 0) /* check result */
1133 {
1134 handle->debug_print("max30105: read fifo data register failed.\n"); /* read fifo data register failed */
1135
1136 return 1; /* return error */
1137 }
1138
1139 return 0; /* success return 0 */
1140}
1141
1154{
1155 uint8_t res;
1156 uint8_t prev;
1157
1158 if (handle == NULL) /* check handle */
1159 {
1160 return 2; /* return error */
1161 }
1162 if (handle->inited != 1) /* check handle initialization */
1163 {
1164 return 3; /* return error */
1165 }
1166
1167 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* read fifo config */
1168 if (res != 0) /* check result */
1169 {
1170 handle->debug_print("max30105: read fifo config failed.\n"); /* read fifo config failed */
1171
1172 return 1; /* return error */
1173 }
1174 prev &= ~(0x7 << 5); /* clear config */
1175 prev |= sample << 5; /* set sample */
1176 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* write fifo config */
1177 if (res != 0) /* check result */
1178 {
1179 handle->debug_print("max30105: write fifo config failed.\n"); /* write fifo config failed */
1180
1181 return 1; /* return error */
1182 }
1183
1184 return 0; /* success return 0 */
1185}
1186
1199{
1200 uint8_t res;
1201 uint8_t prev;
1202
1203 if (handle == NULL) /* check handle */
1204 {
1205 return 2; /* return error */
1206 }
1207 if (handle->inited != 1) /* check handle initialization */
1208 {
1209 return 3; /* return error */
1210 }
1211
1212 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* read fifo config */
1213 if (res != 0) /* check result */
1214 {
1215 handle->debug_print("max30105: read fifo config failed.\n"); /* read fifo config failed */
1216
1217 return 1; /* return error */
1218 }
1219 *sample = (max30105_sample_averaging_t)(0x7 & (prev >> 5)); /* get sample averaging */
1220
1221 return 0; /* success return 0 */
1222}
1223
1236{
1237 uint8_t res;
1238 uint8_t prev;
1239
1240 if (handle == NULL) /* check handle */
1241 {
1242 return 2; /* return error */
1243 }
1244 if (handle->inited != 1) /* check handle initialization */
1245 {
1246 return 3; /* return error */
1247 }
1248
1249 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* read fifo config */
1250 if (res != 0) /* check result */
1251 {
1252 handle->debug_print("max30105: read fifo config failed.\n"); /* read fifo config failed */
1253
1254 return 1; /* return error */
1255 }
1256 prev &= ~(0x1 << 4); /* clear config */
1257 prev |= enable << 4; /* set enable */
1258 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* write fifo config */
1259 if (res != 0) /* check result */
1260 {
1261 handle->debug_print("max30105: write fifo config failed.\n"); /* write fifo config failed */
1262
1263 return 1; /* return error */
1264 }
1265
1266 return 0; /* success return 0 */
1267}
1268
1281{
1282 uint8_t res;
1283 uint8_t prev;
1284
1285 if (handle == NULL) /* check handle */
1286 {
1287 return 2; /* return error */
1288 }
1289 if (handle->inited != 1) /* check handle initialization */
1290 {
1291 return 3; /* return error */
1292 }
1293
1294 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* read fifo config */
1295 if (res != 0) /* check result */
1296 {
1297 handle->debug_print("max30105: read fifo config failed.\n"); /* read fifo config failed */
1298
1299 return 1; /* return error */
1300 }
1301 *enable = (max30105_bool_t)(0x1 & (prev >> 4)); /* get bool */
1302
1303 return 0; /* success return 0 */
1304}
1305
1319{
1320 uint8_t res;
1321 uint8_t prev;
1322
1323 if (handle == NULL) /* check handle */
1324 {
1325 return 2; /* return error */
1326 }
1327 if (handle->inited != 1) /* check handle initialization */
1328 {
1329 return 3; /* return error */
1330 }
1331 if (value > 0xF) /* check value */
1332 {
1333 handle->debug_print("max30105: value can't be over 0xF.\n"); /* value can't be over 0xF */
1334
1335 return 4; /* return error */
1336 }
1337
1338 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* read fifo config */
1339 if (res != 0) /* check result */
1340 {
1341 handle->debug_print("max30105: read fifo config failed.\n"); /* read fifo config failed */
1342
1343 return 1; /* return error */
1344 }
1345 prev &= ~(0xF << 0); /* clear config */
1346 prev |= value << 0; /* set value */
1347 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* write fifo config */
1348 if (res != 0) /* check result */
1349 {
1350 handle->debug_print("max30105: write fifo config failed.\n"); /* write fifo config failed */
1351
1352 return 1; /* return error */
1353 }
1354
1355 return 0; /* success return 0 */
1356}
1357
1369uint8_t max30105_get_fifo_almost_full(max30105_handle_t *handle, uint8_t *value)
1370{
1371 uint8_t res;
1372 uint8_t prev;
1373
1374 if (handle == NULL) /* check handle */
1375 {
1376 return 2; /* return error */
1377 }
1378 if (handle->inited != 1) /* check handle initialization */
1379 {
1380 return 3; /* return error */
1381 }
1382
1383 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_FIFO_CONFIG, (uint8_t *)&prev, 1); /* read fifo config */
1384 if (res != 0) /* check result */
1385 {
1386 handle->debug_print("max30105: read fifo config failed.\n"); /* read fifo config failed */
1387
1388 return 1; /* return error */
1389 }
1390 *value = prev & 0xF; /* get value */
1391
1392 return 0; /* success return 0 */
1393}
1394
1407{
1408 uint8_t res;
1409 uint8_t prev;
1410
1411 if (handle == NULL) /* check handle */
1412 {
1413 return 2; /* return error */
1414 }
1415 if (handle->inited != 1) /* check handle initialization */
1416 {
1417 return 3; /* return error */
1418 }
1419
1420 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
1421 if (res != 0) /* check result */
1422 {
1423 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
1424
1425 return 1; /* return error */
1426 }
1427 prev &= ~(1 << 7); /* clear config */
1428 prev |= enable << 7; /* set bool */
1429 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* write mode config */
1430 if (res != 0) /* check result */
1431 {
1432 handle->debug_print("max30105: write mode config failed.\n"); /* write mode config failed */
1433
1434 return 1; /* return error */
1435 }
1436
1437 return 0; /* success return 0 */
1438}
1439
1452{
1453 uint8_t res;
1454 uint8_t prev;
1455
1456 if (handle == NULL) /* check handle */
1457 {
1458 return 2; /* return error */
1459 }
1460 if (handle->inited != 1) /* check handle initialization */
1461 {
1462 return 3; /* return error */
1463 }
1464
1465 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
1466 if (res != 0) /* check result */
1467 {
1468 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
1469
1470 return 1; /* return error */
1471 }
1472 *enable = (max30105_bool_t)((prev >> 7) & 0x01); /* get bool */
1473
1474 return 0; /* success return 0 */
1475}
1476
1488{
1489 uint8_t res;
1490 uint8_t prev;
1491
1492 if (handle == NULL) /* check handle */
1493 {
1494 return 2; /* return error */
1495 }
1496 if (handle->inited != 1) /* check handle initialization */
1497 {
1498 return 3; /* return error */
1499 }
1500
1501 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
1502 if (res != 0) /* check result */
1503 {
1504 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
1505
1506 return 1; /* return error */
1507 }
1508 prev &= ~(1 << 6); /* clear config */
1509 prev |= 1 << 6; /* set 1 */
1510 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* write mode config */
1511 if (res != 0) /* check result */
1512 {
1513 handle->debug_print("max30105: write mode config failed.\n"); /* write mode config failed */
1514
1515 return 1; /* return error */
1516 }
1517
1518 return 0; /* success return 0 */
1519}
1520
1533{
1534 uint8_t res;
1535 uint8_t prev;
1536
1537 if (handle == NULL) /* check handle */
1538 {
1539 return 2; /* return error */
1540 }
1541 if (handle->inited != 1) /* check handle initialization */
1542 {
1543 return 3; /* return error */
1544 }
1545
1546 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
1547 if (res != 0) /* check result */
1548 {
1549 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
1550
1551 return 1; /* return error */
1552 }
1553 prev &= ~(7 << 0); /* clear config */
1554 prev |= mode << 0; /* set mode */
1555 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* write mode config */
1556 if (res != 0) /* check result */
1557 {
1558 handle->debug_print("max30105: write mode config failed.\n"); /* write mode config failed */
1559
1560 return 1; /* return error */
1561 }
1562
1563 return 0; /* success return 0 */
1564}
1565
1578{
1579 uint8_t res;
1580 uint8_t prev;
1581
1582 if (handle == NULL) /* check handle */
1583 {
1584 return 2; /* return error */
1585 }
1586 if (handle->inited != 1) /* check handle initialization */
1587 {
1588 return 3; /* return error */
1589 }
1590
1591 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MODE_CONFIG, (uint8_t *)&prev, 1); /* read mode config */
1592 if (res != 0) /* check result */
1593 {
1594 handle->debug_print("max30105: read mode config failed.\n"); /* read mode config failed */
1595
1596 return 1; /* return error */
1597 }
1598 *mode = (max30105_mode_t)(prev & 0x7); /* get mode */
1599
1600 return 0; /* success return 0 */
1601}
1602
1615{
1616 uint8_t res;
1617 uint8_t prev;
1618
1619 if (handle == NULL) /* check handle */
1620 {
1621 return 2; /* return error */
1622 }
1623 if (handle->inited != 1) /* check handle initialization */
1624 {
1625 return 3; /* return error */
1626 }
1627
1628 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* read spo2 config */
1629 if (res != 0) /* check result */
1630 {
1631 handle->debug_print("max30105: read spo2 config failed.\n"); /* read spo2 config failed */
1632
1633 return 1; /* return error */
1634 }
1635 prev &= ~(3 << 5); /* clear config */
1636 prev |= range << 5; /* set range */
1637 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* write spo2 config */
1638 if (res != 0) /* check result */
1639 {
1640 handle->debug_print("max30105: write spo2 config failed.\n"); /* write spo2 config failed */
1641
1642 return 1; /* return error */
1643 }
1644
1645 return 0; /* success return 0 */
1646}
1647
1660{
1661 uint8_t res;
1662 uint8_t prev;
1663
1664 if (handle == NULL) /* check handle */
1665 {
1666 return 2; /* return error */
1667 }
1668 if (handle->inited != 1) /* check handle initialization */
1669 {
1670 return 3; /* return error */
1671 }
1672
1673 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* read spo2 config */
1674 if (res != 0) /* check result */
1675 {
1676 handle->debug_print("max30105: read spo2 config failed.\n"); /* read spo2 config failed */
1677
1678 return 1; /* return error */
1679 }
1680 *range = (max30105_particle_sensing_adc_range_t)((prev >> 5) & 0x3); /* get range */
1681
1682 return 0; /* success return 0 */
1683}
1684
1697{
1698 uint8_t res;
1699 uint8_t prev;
1700
1701 if (handle == NULL) /* check handle */
1702 {
1703 return 2; /* return error */
1704 }
1705 if (handle->inited != 1) /* check handle initialization */
1706 {
1707 return 3; /* return error */
1708 }
1709
1710 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* read spo2 config */
1711 if (res != 0) /* check result */
1712 {
1713 handle->debug_print("max30105: read spo2 config failed.\n"); /* read spo2 config failed */
1714
1715 return 1; /* return error */
1716 }
1717 prev &= ~(7 << 2); /* clear config */
1718 prev |= rate << 2; /* set sample rate */
1719 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* write spo2 config */
1720 if (res != 0) /* check result */
1721 {
1722 handle->debug_print("max30105: write spo2 config failed.\n"); /* write spo2 config failed */
1723
1724 return 1; /* return error */
1725 }
1726
1727 return 0; /* success return 0 */
1728}
1729
1742{
1743 uint8_t res;
1744 uint8_t prev;
1745
1746 if (handle == NULL) /* check handle */
1747 {
1748 return 2; /* return error */
1749 }
1750 if (handle->inited != 1) /* check handle initialization */
1751 {
1752 return 3; /* return error */
1753 }
1754
1755 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* read spo2 config */
1756 if (res != 0) /* check result */
1757 {
1758 handle->debug_print("max30105: read spo2 config failed.\n"); /* read spo2 config failed */
1759
1760 return 1; /* return error */
1761 }
1762 *rate = (max30105_particle_sensing_sample_rate_t)((prev >> 2) & 0x7); /* get sample rate */
1763
1764 return 0; /* success return 0 */
1765}
1766
1779{
1780 uint8_t res;
1781 uint8_t prev;
1782
1783 if (handle == NULL) /* check handle */
1784 {
1785 return 2; /* return error */
1786 }
1787 if (handle->inited != 1) /* check handle initialization */
1788 {
1789 return 3; /* return error */
1790 }
1791
1792 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* read spo2 config */
1793 if (res != 0) /* check result */
1794 {
1795 handle->debug_print("max30105: read spo2 config failed.\n"); /* read spo2 config failed */
1796
1797 return 1; /* return error */
1798 }
1799 prev &= ~(3 << 0); /* clear config */
1800 prev |= resolution << 0; /* set adc resolution */
1801 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* write spo2 config */
1802 if (res != 0) /* check result */
1803 {
1804 handle->debug_print("max30105: write spo2 config failed.\n"); /* write spo2 config failed */
1805
1806 return 1; /* return error */
1807 }
1808
1809 return 0; /* success return 0 */
1810}
1811
1824{
1825 uint8_t res;
1826 uint8_t prev;
1827
1828 if (handle == NULL) /* check handle */
1829 {
1830 return 2; /* return error */
1831 }
1832 if (handle->inited != 1) /* check handle initialization */
1833 {
1834 return 3; /* return error */
1835 }
1836
1837 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_SPO2_CONFIG, (uint8_t *)&prev, 1); /* read spo2 config */
1838 if (res != 0) /* check result */
1839 {
1840 handle->debug_print("max30105: read spo2 config failed.\n"); /* read spo2 config failed */
1841
1842 return 1; /* return error */
1843 }
1844 *resolution = (max30105_adc_resolution_t)((prev >> 0) & 0x3); /* set adc resolution */
1845
1846 return 0; /* success return 0 */
1847}
1848
1861{
1862 uint8_t res;
1863
1864 if (handle == NULL) /* check handle */
1865 {
1866 return 2; /* return error */
1867 }
1868 if (handle->inited != 1) /* check handle initialization */
1869 {
1870 return 3; /* return error */
1871 }
1872
1873 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_LED_1_PA, (uint8_t *)&amp, 1); /* write led 1 pa*/
1874 if (res != 0) /* check result */
1875 {
1876 handle->debug_print("max30105: write led 1 pa failed.\n"); /* write led 1 pa failed */
1877
1878 return 1; /* return error */
1879 }
1880
1881 return 0; /* success return 0 */
1882}
1883
1896{
1897 uint8_t res;
1898
1899 if (handle == NULL) /* check handle */
1900 {
1901 return 2; /* return error */
1902 }
1903 if (handle->inited != 1) /* check handle initialization */
1904 {
1905 return 3; /* return error */
1906 }
1907
1908 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_LED_1_PA, (uint8_t *)amp, 1); /* read led 1 pa */
1909 if (res != 0) /* check result */
1910 {
1911 handle->debug_print("max30105: read led 1 pa failed.\n"); /* read led 1 pa failed */
1912
1913 return 1; /* return error */
1914 }
1915
1916 return 0; /* success return 0 */
1917}
1918
1931{
1932 uint8_t res;
1933
1934 if (handle == NULL) /* check handle */
1935 {
1936 return 2; /* return error */
1937 }
1938 if (handle->inited != 1) /* check handle initialization */
1939 {
1940 return 3; /* return error */
1941 }
1942
1943 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_LED_2_PA, (uint8_t *)&amp, 1); /* write led 2 pa */
1944 if (res != 0) /* check result */
1945 {
1946 handle->debug_print("max30105: write led 2 pa failed.\n"); /* write led 2 pa failed */
1947
1948 return 1; /* return error */
1949 }
1950
1951 return 0; /* success return 0 */
1952}
1953
1966{
1967 uint8_t res;
1968
1969 if (handle == NULL) /* check handle */
1970 {
1971 return 2; /* return error */
1972 }
1973 if (handle->inited != 1) /* check handle initialization */
1974 {
1975 return 3; /* return error */
1976 }
1977
1978 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_LED_2_PA, (uint8_t *)amp, 1); /* read led 2 pa */
1979 if (res != 0) /* check result */
1980 {
1981 handle->debug_print("max30105: read led 2 pa failed.\n"); /* read led 2 pa failed */
1982
1983 return 1; /* return error */
1984 }
1985
1986 return 0; /* success return 0 */
1987}
1988
2001{
2002 uint8_t res;
2003
2004 if (handle == NULL) /* check handle */
2005 {
2006 return 2; /* return error */
2007 }
2008 if (handle->inited != 1) /* check handle initialization */
2009 {
2010 return 3; /* return error */
2011 }
2012
2013 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_LED_3_PA, (uint8_t *)&amp, 1); /* write led 3 pa */
2014 if (res != 0) /* check result */
2015 {
2016 handle->debug_print("max30105: write led 3 pa failed.\n"); /* write led 3 pa failed */
2017
2018 return 1; /* return error */
2019 }
2020
2021 return 0; /* success return 0 */
2022}
2023
2036{
2037 uint8_t res;
2038
2039 if (handle == NULL) /* check handle */
2040 {
2041 return 2; /* return error */
2042 }
2043 if (handle->inited != 1) /* check handle initialization */
2044 {
2045 return 3; /* return error */
2046 }
2047
2048 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_LED_3_PA, (uint8_t *)amp, 1); /* read led 3 pa */
2049 if (res != 0) /* check result */
2050 {
2051 handle->debug_print("max30105: read led 3 pa failed.\n"); /* read led 3 pa failed */
2052
2053 return 1; /* return error */
2054 }
2055
2056 return 0; /* success return 0 */
2057}
2058
2071{
2072 uint8_t res;
2073
2074 if (handle == NULL) /* check handle */
2075 {
2076 return 2; /* return error */
2077 }
2078 if (handle->inited != 1) /* check handle initialization */
2079 {
2080 return 3; /* return error */
2081 }
2082
2083 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_PILOT_PA, (uint8_t *)&amp, 1); /* write led proximity pa */
2084 if (res != 0) /* check result */
2085 {
2086 handle->debug_print("max30105: write led proximity pa failed.\n"); /* write led proximity pa failed */
2087
2088 return 1; /* return error */
2089 }
2090
2091 return 0; /* success return 0 */
2092}
2093
2106{
2107 uint8_t res;
2108
2109 if (handle == NULL) /* check handle */
2110 {
2111 return 2; /* return error */
2112 }
2113 if (handle->inited != 1) /* check handle initialization */
2114 {
2115 return 3; /* return error */
2116 }
2117
2118 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_PILOT_PA, (uint8_t *)amp, 1); /* read led proximity pa */
2119 if (res != 0) /* check result */
2120 {
2121 handle->debug_print("max30105: read led proximity pa failed.\n"); /* read led proximity pa failed */
2122
2123 return 1; /* return error */
2124 }
2125
2126 return 0; /* success return 0 */
2127}
2128
2142{
2143 uint8_t res;
2144 uint8_t prev;
2145
2146 if (handle == NULL) /* check handle */
2147 {
2148 return 2; /* return error */
2149 }
2150 if (handle->inited != 1) /* check handle initialization */
2151 {
2152 return 3; /* return error */
2153 }
2154
2155 if (slot == MAX30105_SLOT_1) /* slot 1 */
2156 {
2157 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_1, (uint8_t *)&prev, 1); /* read led slot */
2158 if (res != 0) /* check result */
2159 {
2160 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2161
2162 return 1; /* return error */
2163 }
2164 prev &= ~(0x7 << 0); /* clear config */
2165 prev |= led << 0; /* set led */
2166 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_1, (uint8_t *)&prev, 1); /* write led slot */
2167 if (res != 0) /* check result */
2168 {
2169 handle->debug_print("max30105: write led slot failed.\n"); /* write led slot failed */
2170
2171 return 1; /* return error */
2172 }
2173
2174 return 0; /* success return 0 */
2175 }
2176 else if (slot == MAX30105_SLOT_2) /* slot 2 */
2177 {
2178 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_1, (uint8_t *)&prev, 1); /* read led slot */
2179 if (res != 0) /* check result */
2180 {
2181 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2182
2183 return 1; /* return error */
2184 }
2185 prev &= ~(0x7 << 4); /* clear config */
2186 prev |= led << 4; /* set led */
2187 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_1, (uint8_t *)&prev, 1); /* write led slot */
2188 if (res != 0) /* check result */
2189 {
2190 handle->debug_print("max30105: write led slot failed.\n"); /* write led slot failed */
2191
2192 return 1; /* return error */
2193 }
2194
2195 return 0; /* success return 0 */
2196 }
2197 else if (slot == MAX30105_SLOT_3) /* slot 3 */
2198 {
2199 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_2, (uint8_t *)&prev, 1); /* read led slot */
2200 if (res != 0) /* check result */
2201 {
2202 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2203
2204 return 1; /* return error */
2205 }
2206 prev &= ~(0x7 << 0); /* clear config */
2207 prev |= led << 0; /* set led */
2208 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_2, (uint8_t *)&prev, 1); /* write led slot */
2209 if (res != 0) /* check result */
2210 {
2211 handle->debug_print("max30105: write led slot failed.\n"); /* write led slot failed */
2212
2213 return 1; /* return error */
2214 }
2215
2216 return 0; /* success return 0 */
2217 }
2218 else if (slot == MAX30105_SLOT_4) /* slot 4 */
2219 {
2220 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_2, (uint8_t *)&prev, 1); /* read led slot */
2221 if (res != 0) /* check result */
2222 {
2223 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2224
2225 return 1; /* return error */
2226 }
2227 prev &= ~(0x7 << 4); /* clear config */
2228 prev |= led << 4; /* set led */
2229 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_2, (uint8_t *)&prev, 1); /* write led slot */
2230 if (res != 0) /* check result */
2231 {
2232 handle->debug_print("max30105: write led slot failed.\n"); /* write led slot failed */
2233
2234 return 1; /* return error */
2235 }
2236
2237 return 0; /* success return 0 */
2238 }
2239 else /* unknown */
2240 {
2241 handle->debug_print("max30105: slot is invalid.\n"); /* slot is invalid */
2242
2243 return 1; /* return error */
2244 }
2245}
2246
2260{
2261 uint8_t res;
2262 uint8_t prev;
2263
2264 if (handle == NULL) /* check handle */
2265 {
2266 return 2; /* return error */
2267 }
2268 if (handle->inited != 1) /* check handle initialization */
2269 {
2270 return 3; /* return error */
2271 }
2272
2273 if (slot == MAX30105_SLOT_1) /* slot 1 */
2274 {
2275 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_1, (uint8_t *)&prev, 1); /* read led slot */
2276 if (res != 0) /* check result */
2277 {
2278 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2279
2280 return 1; /* return error */
2281 }
2282 *led = (max30105_led_t)((prev >> 0) & 0x7); /* get led */
2283
2284 return 0; /* success return 0 */
2285 }
2286 else if (slot == MAX30105_SLOT_2) /* slot 2 */
2287 {
2288 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_1, (uint8_t *)&prev, 1); /* read led slot */
2289 if (res != 0) /* check result */
2290 {
2291 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2292
2293 return 1; /* return error */
2294 }
2295 *led = (max30105_led_t)((prev >> 4) & 0x7); /* get led */
2296
2297 return 0; /* success return 0 */
2298 }
2299 else if (slot == MAX30105_SLOT_3) /* slot 3 */
2300 {
2301 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_2, (uint8_t *)&prev, 1); /* read led slot */
2302 if (res != 0) /* check result */
2303 {
2304 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2305
2306 return 1; /* return error */
2307 }
2308 *led = (max30105_led_t)((prev >> 0) & 0x7); /* get led */
2309
2310 return 0; /* success return 0 */
2311 }
2312 else if (slot == MAX30105_SLOT_4) /* slot 4 */
2313 {
2314 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_MULTI_LED_MODE_CONTROL_2, (uint8_t *)&prev, 1); /* read led slot */
2315 if (res != 0) /* check result */
2316 {
2317 handle->debug_print("max30105: read led slot failed.\n"); /* read led slot failed */
2318
2319 return 1; /* return error */
2320 }
2321 *led = (max30105_led_t)((prev >> 4) & 0x7); /* get led */
2322
2323 return 0; /* success return 0 */
2324 }
2325 else /* unknown */
2326 {
2327 handle->debug_print("max30105: slot is invalid.\n"); /* slot is invalid */
2328
2329 return 1; /* return error */
2330 }
2331}
2332
2345{
2346 uint8_t res;
2347 uint8_t prev;
2348
2349 if (handle == NULL) /* check handle */
2350 {
2351 return 2; /* return error */
2352 }
2353 if (handle->inited != 1) /* check handle initialization */
2354 {
2355 return 3; /* return error */
2356 }
2357
2358 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_DIE_TEMP_CONFIG, (uint8_t *)&prev, 1); /* read die temp config */
2359 if (res != 0) /* check result */
2360 {
2361 handle->debug_print("max30105: read die temp config failed.\n"); /* read die temp config failed */
2362
2363 return 1; /* return error */
2364 }
2365 prev &= ~(1 << 0); /* clear config */
2366 prev |= (enable << 0); /* set bool */
2367 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_DIE_TEMP_CONFIG, (uint8_t *)&prev, 1); /* write die temp config */
2368 if (res != 0) /* check result */
2369 {
2370 handle->debug_print("max30105: write die temp config failed.\n"); /* write die temp config failed */
2371
2372 return 1; /* return error */
2373 }
2374
2375 return 0; /* success return 0 */
2376}
2377
2390{
2391 uint8_t res;
2392 uint8_t prev;
2393
2394 if (handle == NULL) /* check handle */
2395 {
2396 return 2; /* return error */
2397 }
2398 if (handle->inited != 1) /* check handle initialization */
2399 {
2400 return 3; /* return error */
2401 }
2402
2403 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_DIE_TEMP_CONFIG, (uint8_t *)&prev, 1); /* read die temp config */
2404 if (res != 0) /* check result */
2405 {
2406 handle->debug_print("max30105: read die temp config failed.\n"); /* read die temp config failed */
2407
2408 return 1; /* return error */
2409 }
2410 *enable = (max30105_bool_t)((prev >> 0) & 0x1); /* get bool */
2411
2412 return 0; /* success return 0 */
2413}
2414
2427{
2428 uint8_t res;
2429
2430 if (handle == NULL) /* check handle */
2431 {
2432 return 2; /* return error */
2433 }
2434 if (handle->inited != 1) /* check handle initialization */
2435 {
2436 return 3; /* return error */
2437 }
2438
2439 res = handle->iic_write(MAX30105_ADDRESS, MAX30105_REG_PROX_INT_THRESH, (uint8_t *)&threshold, 1); /* write proximity interrupt threshold */
2440 if (res != 0) /* check result */
2441 {
2442 handle->debug_print("max30105: write proximity interrupt threshold failed.\n"); /* write read proximity interrupt threshold failed */
2443
2444 return 1; /* return error */
2445 }
2446
2447 return 0; /* success return 0 */
2448}
2449
2462{
2463 uint8_t res;
2464
2465 if (handle == NULL) /* check handle */
2466 {
2467 return 2; /* return error */
2468 }
2469 if (handle->inited != 1) /* check handle initialization */
2470 {
2471 return 3; /* return error */
2472 }
2473
2474 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_PROX_INT_THRESH, (uint8_t *)threshold, 1); /* read proximity interrupt threshold */
2475 if (res != 0) /* check result */
2476 {
2477 handle->debug_print("max30105: read proximity interrupt threshold failed.\n"); /* read read proximity interrupt threshold failed */
2478
2479 return 1; /* return error */
2480 }
2481
2482 return 0; /* success return 0 */
2483}
2484
2497{
2498 if (handle == NULL) /* check handle */
2499 {
2500 return 2; /* return error */
2501 }
2502 if (handle->inited != 1) /* check handle initialization */
2503 {
2504 return 3; /* return error */
2505 }
2506
2507 *reg = (uint8_t)(adc / 1023); /* convert real data to register data */
2508
2509 return 0; /* success return 0 */
2510}
2511
2523uint8_t max30105_proximity_threshold_convert_to_data(max30105_handle_t *handle, uint8_t reg, uint32_t *adc)
2524{
2525 if (handle == NULL) /* check handle */
2526 {
2527 return 2; /* return error */
2528 }
2529 if (handle->inited != 1) /* check handle initialization */
2530 {
2531 return 3; /* return error */
2532 }
2533
2534 *adc = (uint32_t)(reg * 1023); /* convert raw data to real data */
2535
2536 return 0; /* success return 0 */
2537}
2538
2551uint8_t max30105_get_id(max30105_handle_t *handle, uint8_t *revision_id, uint8_t *part_id)
2552{
2553 uint8_t res;
2554
2555 if (handle == NULL) /* check handle */
2556 {
2557 return 2; /* return error */
2558 }
2559 if (handle->inited != 1) /* check handle initialization */
2560 {
2561 return 3; /* return error */
2562 }
2563
2564 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_REVISION_ID, (uint8_t *)revision_id, 1); /* read revision id */
2565 if (res != 0) /* check result */
2566 {
2567 handle->debug_print("max30105: read revision id failed.\n"); /* read revision id failed */
2568
2569 return 1; /* return error */
2570 }
2571 res = handle->iic_read(MAX30105_ADDRESS, MAX30105_REG_PART_ID, (uint8_t *)part_id, 1); /* read part id */
2572 if (res != 0) /* check result */
2573 {
2574 handle->debug_print("max30105: read part id failed.\n"); /* read part id failed */
2575
2576 return 1; /* return error */
2577 }
2578
2579 return 0; /* success return 0 */
2580}
2581
2595uint8_t max30105_set_reg(max30105_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2596{
2597 if (handle == NULL) /* check handle */
2598 {
2599 return 2; /* return error */
2600 }
2601 if (handle->inited != 1) /* check handle initialization */
2602 {
2603 return 3; /* return error */
2604 }
2605
2606 if (handle->iic_write(MAX30105_ADDRESS, reg, buf, len) != 0) /* write data */
2607 {
2608 return 1; /* return error */
2609 }
2610 else
2611 {
2612 return 0; /* success return 0 */
2613 }
2614}
2615
2629uint8_t max30105_get_reg(max30105_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
2630{
2631 if (handle == NULL) /* check handle */
2632 {
2633 return 2; /* return error */
2634 }
2635 if (handle->inited != 1) /* check handle initialization */
2636 {
2637 return 3; /* return error */
2638 }
2639
2640 if (handle->iic_read(MAX30105_ADDRESS, reg, buf, len) != 0) /* read data */
2641 {
2642 return 1; /* return error */
2643 }
2644 else
2645 {
2646 return 0; /* success return 0 */
2647 }
2648}
2649
2659{
2660 if (info == NULL) /* check handle */
2661 {
2662 return 2; /* return error */
2663 }
2664
2665 memset(info, 0, sizeof(max30105_info_t)); /* initialize max30105 info structure */
2666 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2667 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2668 strncpy(info->interface, "IIC", 8); /* copy interface name */
2669 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2670 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2671 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2672 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2673 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2674 info->driver_version = DRIVER_VERSION; /* set driver version */
2675
2676 return 0; /* success return 0 */
2677}
#define MAX30105_REG_OVERFLOW_COUNTER
#define MAX30105_REG_LED_2_PA
#define MAX30105_REG_INTERRUPT_ENABLE_1
#define MAX30105_REG_DIE_TEMP_CONFIG
#define MAX_CURRENT
#define MAX30105_REG_INTERRUPT_STATUS_2
#define MAX30105_REG_SPO2_CONFIG
#define MAX30105_REG_REVISION_ID
#define MAX30105_REG_INTERRUPT_ENABLE_2
#define MAX30105_REG_MULTI_LED_MODE_CONTROL_2
#define MAX30105_REG_FIFO_READ_POINTER
#define SUPPLY_VOLTAGE_MAX
#define MAX30105_REG_FIFO_CONFIG
#define MAX30105_REG_FIFO_DATA_REGISTER
#define MAX30105_REG_MODE_CONFIG
#define MAX30105_REG_PROX_INT_THRESH
#define MAX30105_REG_MULTI_LED_MODE_CONTROL_1
#define TEMPERATURE_MAX
#define MAX30105_REG_LED_1_PA
#define MAX30105_REG_PILOT_PA
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define MAX30105_REG_INTERRUPT_STATUS_1
chip register definition
#define SUPPLY_VOLTAGE_MIN
#define MAX30105_REG_LED_3_PA
#define MAX30105_ADDRESS
iic address definition
#define MAX30105_REG_PART_ID
#define CHIP_NAME
chip information definition
#define MAX30105_REG_FIFO_WRITE_POINTER
#define DRIVER_VERSION
#define MAX30105_REG_DIE_TEMP_FRACTION
#define MAX30105_REG_DIE_TEMP_INTEGER
driver max30105 header file
uint8_t max30105_set_fifo_data(max30105_handle_t *handle, uint8_t data)
set the fifo data
uint8_t max30105_init(max30105_handle_t *handle)
initialize the chip
uint8_t max30105_read(max30105_handle_t *handle, uint32_t *raw_red, uint32_t *raw_ir, uint32_t *raw_green, uint8_t *len)
read the data
uint8_t max30105_proximity_threshold_convert_to_data(max30105_handle_t *handle, uint8_t reg, uint32_t *adc)
convert the register raw data to the proximity threshold
uint8_t max30105_get_fifo_roll(max30105_handle_t *handle, max30105_bool_t *enable)
get the fifo roll status
max30105_interrupt_t
max30105 interrupt enumeration definition
uint8_t max30105_irq_handler(max30105_handle_t *handle)
irq handler
uint8_t max30105_get_led_red_pulse_amplitude(max30105_handle_t *handle, uint8_t *amp)
get the red led pulse amplitude
uint8_t max30105_get_adc_resolution(max30105_handle_t *handle, max30105_adc_resolution_t *resolution)
get the adc resolution
uint8_t max30105_get_id(max30105_handle_t *handle, uint8_t *revision_id, uint8_t *part_id)
get the chip id
uint8_t max30105_get_interrupt(max30105_handle_t *handle, max30105_interrupt_t type, max30105_bool_t *enable)
get the interrupt bool
uint8_t max30105_set_fifo_sample_averaging(max30105_handle_t *handle, max30105_sample_averaging_t sample)
set the fifo sample averaging
uint8_t max30105_get_fifo_sample_averaging(max30105_handle_t *handle, max30105_sample_averaging_t *sample)
get the fifo sample averaging
uint8_t max30105_set_fifo_almost_full(max30105_handle_t *handle, uint8_t value)
set the fifo almost full value
uint8_t max30105_get_led_ir_pulse_amplitude(max30105_handle_t *handle, uint8_t *amp)
get the ir led pulse amplitude
uint8_t max30105_info(max30105_info_t *info)
get chip's information
uint8_t max30105_set_led_red_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the red led pulse amplitude
uint8_t max30105_get_die_temperature(max30105_handle_t *handle, max30105_bool_t *enable)
get the die temperature status
uint8_t max30105_get_particle_sensing_adc_range(max30105_handle_t *handle, max30105_particle_sensing_adc_range_t *range)
get the particle sensing adc range
uint8_t max30105_set_shutdown(max30105_handle_t *handle, max30105_bool_t enable)
set the shutdown
uint8_t max30105_get_fifo_data(max30105_handle_t *handle, uint8_t *data)
get the fifo data
uint8_t max30105_get_mode(max30105_handle_t *handle, max30105_mode_t *mode)
get the mode
uint8_t max30105_get_fifo_write_pointer(max30105_handle_t *handle, uint8_t *pointer)
get the fifo write pointer
uint8_t max30105_set_fifo_overflow_counter(max30105_handle_t *handle, uint8_t counter)
set the fifo overflow counter
max30105_interrupt_status_t
max30105 interrupt status enumeration definition
struct max30105_handle_s max30105_handle_t
max30105 handle structure definition
uint8_t max30105_reset(max30105_handle_t *handle)
reset the chip
uint8_t max30105_proximity_threshold_convert_to_register(max30105_handle_t *handle, uint32_t adc, uint8_t *reg)
convert the proximity threshold to the register raw data
uint8_t max30105_get_fifo_read_pointer(max30105_handle_t *handle, uint8_t *pointer)
get the fifo read pointer
max30105_particle_sensing_sample_rate_t
max30105 particle sensing sample rate enumeration definition
uint8_t max30105_set_mode(max30105_handle_t *handle, max30105_mode_t mode)
set the mode
uint8_t max30105_get_shutdown(max30105_handle_t *handle, max30105_bool_t *enable)
get the shutdown
uint8_t max30105_get_proximity_interrupt_threshold(max30105_handle_t *handle, uint8_t *threshold)
get the proximity interrupt threshold
uint8_t max30105_set_fifo_roll(max30105_handle_t *handle, max30105_bool_t enable)
enable or disable the fifo roll
max30105_bool_t
max30105 bool enumeration definition
max30105_sample_averaging_t
max30105 sample averaging enumeration definition
uint8_t max30105_get_slot(max30105_handle_t *handle, max30105_slot_t slot, max30105_led_t *led)
get the led slot
max30105_adc_resolution_t
max30105 adc resolution enumeration definition
uint8_t max30105_get_led_proximity_pulse_amplitude(max30105_handle_t *handle, uint8_t *amp)
get the proximity led pulse amplitude
uint8_t max30105_set_led_proximity_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the proximity led pulse amplitude
uint8_t max30105_get_particle_sensing_sample_rate(max30105_handle_t *handle, max30105_particle_sensing_sample_rate_t *rate)
get the particle sensing sample rate
uint8_t max30105_get_fifo_almost_full(max30105_handle_t *handle, uint8_t *value)
get the fifo almost full value
uint8_t max30105_set_interrupt(max30105_handle_t *handle, max30105_interrupt_t type, max30105_bool_t enable)
set the interrupt bool
max30105_mode_t
max30105 mode enumeration definition
uint8_t max30105_set_fifo_read_pointer(max30105_handle_t *handle, uint8_t pointer)
set the fifo read pointer
max30105_slot_t
max30105 slot enumeration definition
uint8_t max30105_set_led_green_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the green led pulse amplitude
max30105_particle_sensing_adc_range_t
max30105 particle sensing adc range enumeration definition
uint8_t max30105_set_adc_resolution(max30105_handle_t *handle, max30105_adc_resolution_t resolution)
set the adc resolution
uint8_t max30105_set_particle_sensing_adc_range(max30105_handle_t *handle, max30105_particle_sensing_adc_range_t range)
set the particle sensing adc range
uint8_t max30105_set_proximity_interrupt_threshold(max30105_handle_t *handle, uint8_t threshold)
set the proximity interrupt threshold
uint8_t max30105_set_particle_sensing_sample_rate(max30105_handle_t *handle, max30105_particle_sensing_sample_rate_t rate)
set the particle sensing sample rate
max30105_led_t
max30105 led enumeration definition
struct max30105_info_s max30105_info_t
max30105 information structure definition
uint8_t max30105_get_led_green_pulse_amplitude(max30105_handle_t *handle, uint8_t *amp)
get the green led pulse amplitude
uint8_t max30105_get_fifo_overflow_counter(max30105_handle_t *handle, uint8_t *counter)
get the fifo overflow counter
uint8_t max30105_read_temperature(max30105_handle_t *handle, uint16_t *raw, float *temp)
read the temperature
uint8_t max30105_get_interrupt_status(max30105_handle_t *handle, max30105_interrupt_status_t status, max30105_bool_t *enable)
get the interrupt status
uint8_t max30105_deinit(max30105_handle_t *handle)
close the chip
uint8_t max30105_set_fifo_write_pointer(max30105_handle_t *handle, uint8_t pointer)
set the fifo write pointer
uint8_t max30105_set_led_ir_pulse_amplitude(max30105_handle_t *handle, uint8_t amp)
set the ir led pulse amplitude
uint8_t max30105_set_die_temperature(max30105_handle_t *handle, max30105_bool_t enable)
enable or disable die temperature
uint8_t max30105_set_slot(max30105_handle_t *handle, max30105_slot_t slot, max30105_led_t led)
set the led slot
@ MAX30105_INTERRUPT_DIE_TEMP_RDY_EN
@ MAX30105_INTERRUPT_STATUS_ALC_OVF
@ MAX30105_INTERRUPT_STATUS_DIE_TEMP_RDY
@ MAX30105_INTERRUPT_STATUS_FIFO_FULL
@ MAX30105_INTERRUPT_STATUS_DATA_RDY
@ MAX30105_INTERRUPT_STATUS_PWR_RDY
@ MAX30105_INTERRUPT_STATUS_PROX_INT
@ MAX30105_MODE_RED_IR
@ MAX30105_MODE_RED
@ MAX30105_MODE_GREEN_RED_IR
@ MAX30105_SLOT_2
@ MAX30105_SLOT_4
@ MAX30105_SLOT_1
@ MAX30105_SLOT_3
uint8_t max30105_get_reg(max30105_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t max30105_set_reg(max30105_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(uint8_t type)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(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)
char manufacturer_name[32]