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
54#define MAX30105_ADDRESS 0xAE
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
112 handle->
debug_print(
"max30105: iic_init is null.\n");
118 handle->
debug_print(
"max30105: iic_deinit is null.\n");
124 handle->
debug_print(
"max30105: iic_read is null.\n");
130 handle->
debug_print(
"max30105: iic_write is null.\n");
136 handle->
debug_print(
"max30105: receive_callback is null.\n");
142 handle->
debug_print(
"max30105: delay_ms is null.\n");
149 handle->
debug_print(
"max30105: iic init failed.\n");
156 handle->
debug_print(
"max30105: read part id failed.\n");
171 handle->
debug_print(
"max30105: read mode config failed.\n");
181 handle->
debug_print(
"max30105: write mode config failed.\n");
190 handle->
debug_print(
"max30105: read mode config failed.\n");
195 if ((prev & (1 << 6)) != 0)
206 handle->
debug_print(
"max30105: write fifo read pointer failed.\n");
214 handle->
debug_print(
"max30105: write fifo write pointer failed.\n");
222 handle->
debug_print(
"max30105: write overflow counter failed.\n");
260 handle->
debug_print(
"max30105: read mode config failed.\n");
269 handle->
debug_print(
"max30105: write mode config failed.\n");
275 handle->
debug_print(
"max30105: iic deinit failed.\n");
312 handle->
debug_print(
"max30105: read interrupt status1 failed.\n");
354 handle->
debug_print(
"max30105: read interrupt status2 failed.\n");
365 handle->
debug_print(
"max30105: read die temp integer failed.\n");
369 handle->
raw = (uint16_t)prev << 4;
373 handle->
debug_print(
"max30105: read die temp fraction failed.\n");
377 handle->
raw = handle->
raw | prev1;
378 handle->
temperature = (float)(prev) + (float)(prev1) * 0.0625f;
431 handle->
debug_print(
"max30105: read overflow counter failed.\n");
445 handle->
debug_print(
"max30105: read fifo read point failed.\n");
452 handle->
debug_print(
"max30105: read fifo write point failed.\n");
457 if (write_point > read_point)
459 l = write_point - read_point;
463 l = 32 + write_point - read_point;
465 *len = ((*len) > l) ? l : (*len);
469 handle->
debug_print(
"max30105: read mode config failed.\n");
488 handle->
debug_print(
"max30105: mode is invalid.\n");
496 handle->
debug_print(
"max30105: read fifo data register failed.\n");
503 handle->
debug_print(
"max30105: read spo2 config failed.\n");
524 for (i = 0; i < (*len); i++)
528 raw_red[i] = ((uint32_t)handle->
buf[i * 3 + 0] << 16) |
529 ((uint32_t)handle->
buf[i * 3 + 1] << 8) |
530 ((uint32_t)handle->
buf[i * 3 + 2] << 0);
531 raw_red[i] = raw_red[i] >> bit;
535 raw_red[i] = ((uint32_t)handle->
buf[i * 6 + 0] << 16) |
536 ((uint32_t)handle->
buf[i * 6 + 1] << 8) |
537 ((uint32_t)handle->
buf[i * 6 + 2] << 0);
538 raw_red[i] = raw_red[i] >> bit;
539 raw_ir[i] = ((uint32_t)handle->
buf[i * 6 + 3] << 16) |
540 ((uint32_t)handle->
buf[i * 6 + 4] << 8) |
541 ((uint32_t)handle->
buf[i * 6 + 5] << 0);
542 raw_ir[i] = raw_ir[i] >> bit;
546 raw_red[i] = ((uint32_t)handle->
buf[i * 9 + 0] << 16) |
547 ((uint32_t)handle->
buf[i * 9 + 1] << 8) |
548 ((uint32_t)handle->
buf[i * 9 + 2] << 0);
549 raw_red[i] = raw_red[i] >> bit;
550 raw_ir[i] = ((uint32_t)handle->
buf[i * 9 + 3] << 16) |
551 ((uint32_t)handle->
buf[i * 9 + 4] << 8) |
552 ((uint32_t)handle->
buf[i * 9 + 5] << 0);
553 raw_ir[i] = raw_ir[i] >> bit;
554 raw_green[i] = ((uint32_t)handle->
buf[i * 9 + 6] << 16) |
555 ((uint32_t)handle->
buf[i * 9 + 7] << 8) |
556 ((uint32_t)handle->
buf[i * 9 + 8] << 0);
557 raw_green[i] = raw_green[i] >> bit;
594 handle->
debug_print(
"max30105: read interrupt enable2 failed.\n");
598 if ((prev & (1 << 1)) == 0)
605 handle->
debug_print(
"max30105: write interrupt enable2 failed.\n");
614 handle->
debug_print(
"max30105: read die temp config failed.\n");
623 handle->
debug_print(
"max30105: write die temp config failed.\n");
682 handle->
debug_print(
"max30105: read interrupt status2 failed.\n");
695 handle->
debug_print(
"max30105: read interrupt status1 failed.\n");
736 handle->
debug_print(
"max30105: read interrupt enable2 failed.\n");
740 prev &= ~(1 << type);
741 prev |= enable << type;
745 handle->
debug_print(
"max30105: write interrupt enable2 failed.\n");
757 handle->
debug_print(
"max30105: read interrupt enable1 failed.\n");
761 prev &= ~(1 << type);
762 prev |= enable << type;
766 handle->
debug_print(
"max30105: write interrupt enable1 failed.\n");
806 handle->
debug_print(
"max30105: read interrupt enable2 failed.\n");
819 handle->
debug_print(
"max30105: read interrupt enable1 failed.\n");
856 handle->
debug_print(
"max30105: pointer can't be over 0x1F.\n");
861 prev = pointer & 0x1F;
865 handle->
debug_print(
"max30105: write fifo write pointer failed.\n");
901 handle->
debug_print(
"max30105: read fifo write pointer failed.\n");
905 *pointer = prev & 0x1F;
937 handle->
debug_print(
"max30105: counter can't be over 0x1F.\n");
942 prev = counter & 0x1F;
946 handle->
debug_print(
"max30105: set fifo overflow counter failed.\n");
982 handle->
debug_print(
"max30105: get fifo overflow counter failed.\n");
986 *counter = prev & 0x1F;
1018 handle->
debug_print(
"max30105: pointer can't be over 0x1F.\n");
1023 prev = pointer & 0x1F;
1027 handle->
debug_print(
"max30105: write fifo read pointer failed.\n");
1063 handle->
debug_print(
"max30105: read fifo read pointer failed.\n");
1067 *pointer = prev & 0x1F;
1099 handle->
debug_print(
"max30105: write fifo data register failed.\n");
1134 handle->
debug_print(
"max30105: read fifo data register failed.\n");
1170 handle->
debug_print(
"max30105: read fifo config failed.\n");
1174 prev &= ~(0x7 << 5);
1175 prev |= sample << 5;
1179 handle->
debug_print(
"max30105: write fifo config failed.\n");
1215 handle->
debug_print(
"max30105: read fifo config failed.\n");
1252 handle->
debug_print(
"max30105: read fifo config failed.\n");
1256 prev &= ~(0x1 << 4);
1257 prev |= enable << 4;
1261 handle->
debug_print(
"max30105: write fifo config failed.\n");
1297 handle->
debug_print(
"max30105: read fifo config failed.\n");
1333 handle->
debug_print(
"max30105: value can't be over 0xF.\n");
1341 handle->
debug_print(
"max30105: read fifo config failed.\n");
1345 prev &= ~(0xF << 0);
1350 handle->
debug_print(
"max30105: write fifo config failed.\n");
1386 handle->
debug_print(
"max30105: read fifo config failed.\n");
1390 *value = prev & 0xF;
1423 handle->
debug_print(
"max30105: read mode config failed.\n");
1428 prev |= enable << 7;
1432 handle->
debug_print(
"max30105: write mode config failed.\n");
1468 handle->
debug_print(
"max30105: read mode config failed.\n");
1504 handle->
debug_print(
"max30105: read mode config failed.\n");
1513 handle->
debug_print(
"max30105: write mode config failed.\n");
1549 handle->
debug_print(
"max30105: read mode config failed.\n");
1558 handle->
debug_print(
"max30105: write mode config failed.\n");
1594 handle->
debug_print(
"max30105: read mode config failed.\n");
1631 handle->
debug_print(
"max30105: read spo2 config failed.\n");
1640 handle->
debug_print(
"max30105: write spo2 config failed.\n");
1676 handle->
debug_print(
"max30105: read spo2 config failed.\n");
1713 handle->
debug_print(
"max30105: read spo2 config failed.\n");
1722 handle->
debug_print(
"max30105: write spo2 config failed.\n");
1758 handle->
debug_print(
"max30105: read spo2 config failed.\n");
1795 handle->
debug_print(
"max30105: read spo2 config failed.\n");
1800 prev |= resolution << 0;
1804 handle->
debug_print(
"max30105: write spo2 config failed.\n");
1840 handle->
debug_print(
"max30105: read spo2 config failed.\n");
1876 handle->
debug_print(
"max30105: write led 1 pa failed.\n");
1911 handle->
debug_print(
"max30105: read led 1 pa failed.\n");
1946 handle->
debug_print(
"max30105: write led 2 pa failed.\n");
1981 handle->
debug_print(
"max30105: read led 2 pa failed.\n");
2016 handle->
debug_print(
"max30105: write led 3 pa failed.\n");
2051 handle->
debug_print(
"max30105: read led 3 pa failed.\n");
2086 handle->
debug_print(
"max30105: write led proximity pa failed.\n");
2121 handle->
debug_print(
"max30105: read led proximity pa failed.\n");
2160 handle->
debug_print(
"max30105: read led slot failed.\n");
2164 prev &= ~(0x7 << 0);
2169 handle->
debug_print(
"max30105: write led slot failed.\n");
2181 handle->
debug_print(
"max30105: read led slot failed.\n");
2185 prev &= ~(0x7 << 4);
2190 handle->
debug_print(
"max30105: write led slot failed.\n");
2202 handle->
debug_print(
"max30105: read led slot failed.\n");
2206 prev &= ~(0x7 << 0);
2211 handle->
debug_print(
"max30105: write led slot failed.\n");
2223 handle->
debug_print(
"max30105: read led slot failed.\n");
2227 prev &= ~(0x7 << 4);
2232 handle->
debug_print(
"max30105: write led slot failed.\n");
2241 handle->
debug_print(
"max30105: slot is invalid.\n");
2278 handle->
debug_print(
"max30105: read led slot failed.\n");
2291 handle->
debug_print(
"max30105: read led slot failed.\n");
2304 handle->
debug_print(
"max30105: read led slot failed.\n");
2317 handle->
debug_print(
"max30105: read led slot failed.\n");
2327 handle->
debug_print(
"max30105: slot is invalid.\n");
2361 handle->
debug_print(
"max30105: read die temp config failed.\n");
2366 prev |= (enable << 0);
2370 handle->
debug_print(
"max30105: write die temp config failed.\n");
2406 handle->
debug_print(
"max30105: read die temp config failed.\n");
2442 handle->
debug_print(
"max30105: write proximity interrupt threshold failed.\n");
2477 handle->
debug_print(
"max30105: read proximity interrupt threshold failed.\n");
2507 *reg = (uint8_t)(adc / 1023);
2534 *adc = (uint32_t)(reg * 1023);
2567 handle->
debug_print(
"max30105: read revision id failed.\n");
2574 handle->
debug_print(
"max30105: read part id failed.\n");
#define MAX30105_REG_OVERFLOW_COUNTER
#define MAX30105_REG_LED_2_PA
#define MAX30105_REG_INTERRUPT_ENABLE_1
#define MAX30105_REG_DIE_TEMP_CONFIG
#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 MAX30105_REG_LED_1_PA
#define MAX30105_REG_PILOT_PA
#define MANUFACTURER_NAME
#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 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_GREEN_RED_IR
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)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v