42#define CHIP_NAME "Maxim Integrated MAX30102"
43#define MANUFACTURER_NAME "Maxim Integrated"
44#define SUPPLY_VOLTAGE_MIN 1.7f
45#define SUPPLY_VOLTAGE_MAX 2.0f
46#define MAX_CURRENT 20.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define MAX30102_ADDRESS 0xAE
59#define MAX30102_REG_INTERRUPT_STATUS_1 0x00
60#define MAX30102_REG_INTERRUPT_STATUS_2 0x01
61#define MAX30102_REG_INTERRUPT_ENABLE_1 0x02
62#define MAX30102_REG_INTERRUPT_ENABLE_2 0x03
63#define MAX30102_REG_FIFO_WRITE_POINTER 0x04
64#define MAX30102_REG_OVERFLOW_COUNTER 0x05
65#define MAX30102_REG_FIFO_READ_POINTER 0x06
66#define MAX30102_REG_FIFO_DATA_REGISTER 0x07
67#define MAX30102_REG_FIFO_CONFIG 0x08
68#define MAX30102_REG_MODE_CONFIG 0x09
69#define MAX30102_REG_SPO2_CONFIG 0x0A
70#define MAX30102_REG_LED_PULSE_1 0x0C
71#define MAX30102_REG_LED_PULSE_2 0x0D
72#define MAX30102_REG_MULTI_LED_MODE_CONTROL_1 0x11
73#define MAX30102_REG_MULTI_LED_MODE_CONTROL_2 0x12
74#define MAX30102_REG_DIE_TEMP_INTEGER 0x1F
75#define MAX30102_REG_DIE_TEMP_FRACTION 0x20
76#define MAX30102_REG_DIE_TEMP_CONFIG 0x21
77#define MAX30102_REG_REVISION_ID 0xFE
78#define MAX30102_REG_PART_ID 0xFF
109 handle->
debug_print(
"max30102: iic_init is null.\n");
115 handle->
debug_print(
"max30102: iic_deinit is null.\n");
121 handle->
debug_print(
"max30102: iic_read is null.\n");
127 handle->
debug_print(
"max30102: iic_write is null.\n");
133 handle->
debug_print(
"max30102: receive_callback is null.\n");
139 handle->
debug_print(
"max30102: delay_ms is null.\n");
146 handle->
debug_print(
"max30102: iic init failed.\n");
153 handle->
debug_print(
"max30102: read part id failed.\n");
168 handle->
debug_print(
"max30102: read mode config failed.\n");
178 handle->
debug_print(
"max30102: write mode config failed.\n");
187 handle->
debug_print(
"max30102: read mode config failed.\n");
192 if ((prev & (1 << 6)) != 0)
203 handle->
debug_print(
"max30102: write fifo read pointer failed.\n");
211 handle->
debug_print(
"max30102: write fifo write pointer failed.\n");
219 handle->
debug_print(
"max30102: write overflow counter failed.\n");
257 handle->
debug_print(
"max30102: read mode config failed.\n");
266 handle->
debug_print(
"max30102: write mode config failed.\n");
272 handle->
debug_print(
"max30102: iic deinit failed.\n");
309 handle->
debug_print(
"max30102: read interrupt status1 failed.\n");
344 handle->
debug_print(
"max30102: read interrupt status2 failed.\n");
355 handle->
debug_print(
"max30102: read die temp integer failed.\n");
359 handle->
raw = (uint16_t)prev << 4;
363 handle->
debug_print(
"max30102: read die temp fraction failed.\n");
367 handle->
raw = handle->
raw | prev1;
368 handle->
temperature = (float)(prev) + (float)(prev1) * 0.0625f;
420 handle->
debug_print(
"max30102: read overflow counter failed.\n");
434 handle->
debug_print(
"max30102: read fifo read point failed.\n");
441 handle->
debug_print(
"max30102: read fifo write point failed.\n");
446 if (write_point > read_point)
448 l = write_point - read_point;
452 l = 32 + write_point - read_point;
454 *len = ((*len) > l) ? l : (*len);
458 handle->
debug_print(
"max30102: read mode config failed.\n");
477 handle->
debug_print(
"max30105: mode is invalid.\n");
485 handle->
debug_print(
"max30102: read fifo data register failed.\n");
492 handle->
debug_print(
"max30102: read spo2 config failed.\n");
514 for (i = 0; i < (*len); i++)
518 raw_red[i] = ((uint32_t)handle->
buf[i * 3 + 0] << 16) |
519 ((uint32_t)handle->
buf[i * 3 + 1] << 8) |
520 ((uint32_t)handle->
buf[i * 3 + 2] << 0);
521 raw_red[i] = raw_red[i] >> bit;
525 raw_red[i] = ((uint32_t)handle->
buf[i * 6 + 0] << 16) |
526 ((uint32_t)handle->
buf[i * 6 + 1] << 8) |
527 ((uint32_t)handle->
buf[i * 6 + 2] << 0);
528 raw_red[i] = raw_red[i] >> bit;
529 raw_ir[i] = ((uint32_t)handle->
buf[i * 6 + 3] << 16) |
530 ((uint32_t)handle->
buf[i * 6 + 4] << 8) |
531 ((uint32_t)handle->
buf[i * 6 + 5] << 0);
532 raw_ir[i] = raw_ir[i] >> bit;
569 handle->
debug_print(
"max30102: read interrupt enable2 failed.\n");
573 if ((prev & (1 << 1)) == 0)
580 handle->
debug_print(
"max30102: write interrupt enable2 failed.\n");
589 handle->
debug_print(
"max30102: read die temp config failed.\n");
598 handle->
debug_print(
"max30102: write die temp config failed.\n");
657 handle->
debug_print(
"max30102: read interrupt status2 failed.\n");
670 handle->
debug_print(
"max30102: read interrupt status1 failed.\n");
711 handle->
debug_print(
"max30102: read interrupt enable2 failed.\n");
715 prev &= ~(1 << type);
716 prev |= enable << type;
720 handle->
debug_print(
"max30102: write interrupt enable2 failed.\n");
732 handle->
debug_print(
"max30102: read interrupt enable1 failed.\n");
736 prev &= ~(1 << type);
737 prev |= enable << type;
741 handle->
debug_print(
"max30102: write interrupt enable1 failed.\n");
781 handle->
debug_print(
"max30102: read interrupt enable2 failed.\n");
794 handle->
debug_print(
"max30102: read interrupt enable1 failed.\n");
831 handle->
debug_print(
"max30102: pointer can't be over 0x1F.\n");
836 prev = pointer & 0x1F;
840 handle->
debug_print(
"max30102: write fifo write pointer failed.\n");
876 handle->
debug_print(
"max30102: read fifo write pointer failed.\n");
880 *pointer = prev & 0x1F;
912 handle->
debug_print(
"max30102: counter can't be over 0x1F.\n");
917 prev = counter & 0x1F;
921 handle->
debug_print(
"max30102: set fifo overflow counter failed.\n");
957 handle->
debug_print(
"max30102: get fifo overflow counter failed.\n");
961 *counter = prev & 0x1F;
993 handle->
debug_print(
"max30102: pointer can't be over 0x1F.\n");
998 prev = pointer & 0x1F;
1002 handle->
debug_print(
"max30102: write fifo read pointer failed.\n");
1038 handle->
debug_print(
"max30102: read fifo read pointer failed.\n");
1042 *pointer = prev & 0x1F;
1074 handle->
debug_print(
"max30102: write fifo data register failed.\n");
1109 handle->
debug_print(
"max30102: read fifo data register failed.\n");
1145 handle->
debug_print(
"max30102: read fifo config failed.\n");
1149 prev &= ~(0x7 << 5);
1150 prev |= sample << 5;
1154 handle->
debug_print(
"max30102: write fifo config failed.\n");
1190 handle->
debug_print(
"max30102: read fifo config failed.\n");
1227 handle->
debug_print(
"max30102: read fifo config failed.\n");
1231 prev &= ~(0x1 << 4);
1232 prev |= enable << 4;
1236 handle->
debug_print(
"max30102: write fifo config failed.\n");
1272 handle->
debug_print(
"max30102: read fifo config failed.\n");
1308 handle->
debug_print(
"max30102: value can't be over 0xF.\n");
1316 handle->
debug_print(
"max30102: read fifo config failed.\n");
1320 prev &= ~(0xF << 0);
1325 handle->
debug_print(
"max30102: write fifo config failed.\n");
1361 handle->
debug_print(
"max30102: read fifo config failed.\n");
1365 *value = prev & 0xF;
1398 handle->
debug_print(
"max30102: read mode config failed.\n");
1403 prev |= enable << 7;
1407 handle->
debug_print(
"max30102: write mode config failed.\n");
1443 handle->
debug_print(
"max30102: read mode config failed.\n");
1479 handle->
debug_print(
"max30102: read mode config failed.\n");
1488 handle->
debug_print(
"max30102: write mode config failed.\n");
1524 handle->
debug_print(
"max30102: read mode config failed.\n");
1533 handle->
debug_print(
"max30102: write mode config failed.\n");
1569 handle->
debug_print(
"max30102: read mode config failed.\n");
1606 handle->
debug_print(
"max30102: read spo2 config failed.\n");
1615 handle->
debug_print(
"max30102: write spo2 config failed.\n");
1651 handle->
debug_print(
"max30102: read spo2 config failed.\n");
1688 handle->
debug_print(
"max30102: read spo2 config failed.\n");
1697 handle->
debug_print(
"max30102: write spo2 config failed.\n");
1733 handle->
debug_print(
"max30102: read spo2 config failed.\n");
1770 handle->
debug_print(
"max30102: read spo2 config failed.\n");
1775 prev |= resolution << 0;
1779 handle->
debug_print(
"max30102: write spo2 config failed.\n");
1815 handle->
debug_print(
"max30102: read spo2 config failed.\n");
1851 handle->
debug_print(
"max30102: write led pulse 1 failed.\n");
1886 handle->
debug_print(
"max30102: read led pulse 1 failed.\n");
1921 handle->
debug_print(
"max30102: write led pulse 2 failed.\n");
1956 handle->
debug_print(
"max30102: read led pulse 2 failed.\n");
1995 handle->
debug_print(
"max30102: read led slot failed.\n");
1999 prev &= ~(0x7 << 0);
2004 handle->
debug_print(
"max30102: write led slot failed.\n");
2016 handle->
debug_print(
"max30102: read led slot failed.\n");
2020 prev &= ~(0x7 << 4);
2025 handle->
debug_print(
"max30102: write led slot failed.\n");
2037 handle->
debug_print(
"max30102: read led slot failed.\n");
2041 prev &= ~(0x7 << 0);
2046 handle->
debug_print(
"max30102: write led slot failed.\n");
2058 handle->
debug_print(
"max30102: read led slot failed.\n");
2062 prev &= ~(0x7 << 4);
2067 handle->
debug_print(
"max30102: write led slot failed.\n");
2076 handle->
debug_print(
"max30102: slot is invalid.\n");
2113 handle->
debug_print(
"max30102: read led slot failed.\n");
2126 handle->
debug_print(
"max30102: read led slot failed.\n");
2139 handle->
debug_print(
"max30102: read led slot failed.\n");
2152 handle->
debug_print(
"max30102: read led slot failed.\n");
2162 handle->
debug_print(
"max30102: slot is invalid.\n");
2196 handle->
debug_print(
"max30102: read die temp config failed.\n");
2201 prev |= (enable << 0);
2205 handle->
debug_print(
"max30102: write die temp config failed.\n");
2241 handle->
debug_print(
"max30102: read die temp config failed.\n");
2278 handle->
debug_print(
"max30102: read revision id failed.\n");
2285 handle->
debug_print(
"max30102: read part id failed.\n");
#define MAX30102_REG_LED_PULSE_1
#define MAX30102_REG_INTERRUPT_STATUS_1
chip register definition
#define MAX30102_REG_DIE_TEMP_CONFIG
#define MAX30102_REG_REVISION_ID
#define MAX30102_REG_MODE_CONFIG
#define SUPPLY_VOLTAGE_MAX
#define MAX30102_REG_INTERRUPT_ENABLE_2
#define MAX30102_REG_PART_ID
#define MAX30102_REG_DIE_TEMP_INTEGER
#define MAX30102_REG_MULTI_LED_MODE_CONTROL_2
#define MAX30102_REG_SPO2_CONFIG
#define MAX30102_REG_MULTI_LED_MODE_CONTROL_1
#define MAX30102_REG_LED_PULSE_2
#define MAX30102_REG_FIFO_READ_POINTER
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define MAX30102_REG_OVERFLOW_COUNTER
#define MAX30102_REG_FIFO_CONFIG
#define MAX30102_REG_INTERRUPT_STATUS_2
#define MAX30102_REG_FIFO_WRITE_POINTER
#define MAX30102_REG_DIE_TEMP_FRACTION
#define MAX30102_REG_FIFO_DATA_REGISTER
#define MAX30102_ADDRESS
iic address definition
#define CHIP_NAME
chip information definition
#define MAX30102_REG_INTERRUPT_ENABLE_1
driver max30102 header file
uint8_t max30102_set_slot(max30102_handle_t *handle, max30102_slot_t slot, max30102_led_t led)
set the led slot
uint8_t max30102_get_slot(max30102_handle_t *handle, max30102_slot_t slot, max30102_led_t *led)
get the led slot
uint8_t max30102_set_fifo_read_pointer(max30102_handle_t *handle, uint8_t pointer)
set the fifo read pointer
max30102_slot_t
max30102 slot enumeration definition
uint8_t max30102_set_die_temperature(max30102_handle_t *handle, max30102_bool_t enable)
enable or disable die temperature
max30102_bool_t
max30102 bool enumeration definition
uint8_t max30102_get_fifo_write_pointer(max30102_handle_t *handle, uint8_t *pointer)
get the fifo write pointer
uint8_t max30102_set_fifo_roll(max30102_handle_t *handle, max30102_bool_t enable)
enable or disable the fifo roll
uint8_t max30102_get_interrupt(max30102_handle_t *handle, max30102_interrupt_t type, max30102_bool_t *enable)
get the interrupt bool
uint8_t max30102_reset(max30102_handle_t *handle)
reset the chip
uint8_t max30102_get_mode(max30102_handle_t *handle, max30102_mode_t *mode)
get the mode
uint8_t max30102_get_fifo_roll(max30102_handle_t *handle, max30102_bool_t *enable)
get the fifo roll status
uint8_t max30102_get_fifo_data(max30102_handle_t *handle, uint8_t *data)
get the fifo data
uint8_t max30102_get_interrupt_status(max30102_handle_t *handle, max30102_interrupt_status_t status, max30102_bool_t *enable)
get the interrupt status
uint8_t max30102_set_fifo_almost_full(max30102_handle_t *handle, uint8_t value)
set the fifo almost full value
uint8_t max30102_get_led_red_pulse_amplitude(max30102_handle_t *handle, uint8_t *amp)
get the red led pulse amplitude
uint8_t max30102_info(max30102_info_t *info)
get chip's information
uint8_t max30102_set_fifo_sample_averaging(max30102_handle_t *handle, max30102_sample_averaging_t sample)
set the fifo sample averaging
uint8_t max30102_read_temperature(max30102_handle_t *handle, uint16_t *raw, float *temp)
read the temperature
uint8_t max30102_set_led_red_pulse_amplitude(max30102_handle_t *handle, uint8_t amp)
set the red led pulse amplitude
uint8_t max30102_get_fifo_sample_averaging(max30102_handle_t *handle, max30102_sample_averaging_t *sample)
get the fifo sample averaging
uint8_t max30102_set_mode(max30102_handle_t *handle, max30102_mode_t mode)
set the mode
uint8_t max30102_get_spo2_adc_range(max30102_handle_t *handle, max30102_spo2_adc_range_t *range)
get the spo2 adc range
uint8_t max30102_set_shutdown(max30102_handle_t *handle, max30102_bool_t enable)
set the shutdown
uint8_t max30102_read(max30102_handle_t *handle, uint32_t *raw_red, uint32_t *raw_ir, uint8_t *len)
read the data
uint8_t max30102_get_led_ir_pulse_amplitude(max30102_handle_t *handle, uint8_t *amp)
get the ir led pulse amplitude
uint8_t max30102_deinit(max30102_handle_t *handle)
close the chip
uint8_t max30102_set_spo2_adc_range(max30102_handle_t *handle, max30102_spo2_adc_range_t range)
set the spo2 adc range
uint8_t max30102_get_fifo_read_pointer(max30102_handle_t *handle, uint8_t *pointer)
get the fifo read pointer
max30102_spo2_adc_range_t
max30102 spo2 adc range enumeration definition
uint8_t max30102_set_spo2_sample_rate(max30102_handle_t *handle, max30102_spo2_sample_rate_t rate)
set the spo2 sample rate
uint8_t max30102_get_fifo_overflow_counter(max30102_handle_t *handle, uint8_t *counter)
get the fifo overflow counter
max30102_interrupt_t
max30102 interrupt enumeration definition
uint8_t max30102_set_interrupt(max30102_handle_t *handle, max30102_interrupt_t type, max30102_bool_t enable)
set the interrupt bool
uint8_t max30102_get_die_temperature(max30102_handle_t *handle, max30102_bool_t *enable)
get the die temperature status
uint8_t max30102_set_led_ir_pulse_amplitude(max30102_handle_t *handle, uint8_t amp)
set the ir led pulse amplitude
uint8_t max30102_get_id(max30102_handle_t *handle, uint8_t *revision_id, uint8_t *part_id)
get the chip id
struct max30102_info_s max30102_info_t
max30102 information structure definition
uint8_t max30102_init(max30102_handle_t *handle)
initialize the chip
max30102_spo2_sample_rate_t
max30102 spo2 sample rate enumeration definition
uint8_t max30102_set_fifo_data(max30102_handle_t *handle, uint8_t data)
set the fifo data
uint8_t max30102_get_spo2_sample_rate(max30102_handle_t *handle, max30102_spo2_sample_rate_t *rate)
get the spo2 sample rate
max30102_sample_averaging_t
max30102 sample averaging enumeration definition
struct max30102_handle_s max30102_handle_t
max30102 handle structure definition
uint8_t max30102_irq_handler(max30102_handle_t *handle)
irq handler
uint8_t max30102_set_adc_resolution(max30102_handle_t *handle, max30102_adc_resolution_t resolution)
set the adc resolution
uint8_t max30102_get_fifo_almost_full(max30102_handle_t *handle, uint8_t *value)
get the fifo almost full value
max30102_interrupt_status_t
max30102 interrupt status enumeration definition
uint8_t max30102_set_fifo_write_pointer(max30102_handle_t *handle, uint8_t pointer)
set the fifo write pointer
uint8_t max30102_set_fifo_overflow_counter(max30102_handle_t *handle, uint8_t counter)
set the fifo overflow counter
max30102_led_t
max30102 led enumeration definition
max30102_adc_resolution_t
max30102 adc resolution enumeration definition
uint8_t max30102_get_adc_resolution(max30102_handle_t *handle, max30102_adc_resolution_t *resolution)
get the adc resolution
max30102_mode_t
max30102 mode enumeration definition
uint8_t max30102_get_shutdown(max30102_handle_t *handle, max30102_bool_t *enable)
get the shutdown
@ MAX30102_INTERRUPT_DIE_TEMP_RDY_EN
@ MAX30102_INTERRUPT_STATUS_FIFO_FULL
@ MAX30102_INTERRUPT_STATUS_ALC_OVF
@ MAX30102_INTERRUPT_STATUS_DIE_TEMP_RDY
@ MAX30102_INTERRUPT_STATUS_PPG_RDY
@ MAX30102_INTERRUPT_STATUS_PWR_RDY
@ MAX30102_MODE_HEART_RATE
@ MAX30102_MODE_MULTI_LED
uint8_t max30102_set_reg(max30102_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t max30102_get_reg(max30102_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get 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)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v