no-OS
Loading...
Searching...
No Matches
maxm86161.h File Reference

Header file for MAXM86161 optical pulse oximeter driver. More...

#include <stdint.h>
#include <stdbool.h>
#include "no_os_i2c.h"
#include "no_os_gpio.h"
#include "no_os_irq.h"
#include "no_os_util.h"
Include dependency graph for maxm86161.h:

Classes

struct  maxm86161_int_handler
 
struct  maxm86161_dev
 
struct  maxm86161_init_param
 

Macros

#define MAXM86161_I2C_ADDR   0x62
 
#define MAXM86161_PART_ID_VAL   0x36
 
#define MAXM86161_FIFO_DEPTH   128
 
#define MAXM86161_FIFO_DATA_SIZE   3
 
#define MAXM86161_NUM_LED_SEQ   6
 
#define MAXM86161_NUM_LEDS   3
 
#define MAXM86161_RESET_DELAY_MS   10
 
#define MAXM86161_REG_INT_STATUS_1   0x00
 
#define MAXM86161_INT1_A_FULL   NO_OS_BIT(7)
 
#define MAXM86161_INT1_DATA_RDY   NO_OS_BIT(6)
 
#define MAXM86161_INT1_ALC_OVF   NO_OS_BIT(5)
 
#define MAXM86161_INT1_PROX_INT   NO_OS_BIT(4)
 
#define MAXM86161_INT1_LED_COMPB   NO_OS_BIT(3)
 
#define MAXM86161_INT1_DIE_TEMP_RDY   NO_OS_BIT(2)
 
#define MAXM86161_INT1_PWR_RDY   NO_OS_BIT(0)
 
#define MAXM86161_REG_INT_STATUS_2   0x01
 
#define MAXM86161_INT2_SHA_DONE   NO_OS_BIT(0)
 
#define MAXM86161_REG_INT_EN_1   0x02
 
#define MAXM86161_INT1_A_FULL_EN   NO_OS_BIT(7)
 
#define MAXM86161_INT1_DATA_RDY_EN   NO_OS_BIT(6)
 
#define MAXM86161_INT1_ALC_OVF_EN   NO_OS_BIT(5)
 
#define MAXM86161_INT1_PROX_INT_EN   NO_OS_BIT(4)
 
#define MAXM86161_INT1_LED_COMPB_EN   NO_OS_BIT(3)
 
#define MAXM86161_INT1_DIE_TEMP_RDY_EN   NO_OS_BIT(2)
 
#define MAXM86161_REG_INT_EN_2   0x03
 
#define MAXM86161_INT2_SHA_DONE_EN   NO_OS_BIT(0)
 
#define MAXM86161_REG_FIFO_WR_PTR   0x04
 
#define MAXM86161_REG_FIFO_RD_PTR   0x05
 
#define MAXM86161_REG_OVF_COUNTER   0x06
 
#define MAXM86161_FIFO_OVF_COUNTER_MSK   NO_OS_GENMASK(6, 0)
 
#define MAXM86161_REG_FIFO_DATA_COUNT   0x07
 
#define MAXM86161_REG_FIFO_DATA   0x08
 
#define MAXM86161_REG_FIFO_CFG_1   0x09
 
#define MAXM86161_FIFO_A_FULL_MSK   NO_OS_GENMASK(6, 0)
 
#define MAXM86161_FIFO_A_FULL_MAX   127
 
#define MAXM86161_REG_FIFO_CFG_2   0x0A
 
#define MAXM86161_FIFO_CFG2_FLUSH   NO_OS_BIT(4)
 
#define MAXM86161_FIFO_CFG2_STAT_CLR   NO_OS_BIT(3)
 
#define MAXM86161_FIFO_CFG2_A_FULL_TYPE   NO_OS_BIT(2)
 
#define MAXM86161_FIFO_CFG2_FIFO_RO   NO_OS_BIT(1)
 
#define MAXM86161_REG_SYS_CTRL   0x0D
 
#define MAXM86161_SYS_CTRL_SINGLE_PPG   NO_OS_BIT(3)
 
#define MAXM86161_SYS_CTRL_LP_MODE   NO_OS_BIT(2)
 
#define MAXM86161_SYS_CTRL_SHDN   NO_OS_BIT(1)
 
#define MAXM86161_SYS_CTRL_RESET   NO_OS_BIT(0)
 
#define MAXM86161_REG_PPG_SYNC_CTRL   0x10
 
#define MAXM86161_PPG_SYNC_TIMESTAMP_EN   NO_OS_BIT(7)
 
#define MAXM86161_PPG_SYNC_DAC_CODE_TAG   NO_OS_BIT(6)
 
#define MAXM86161_PPG_SYNC_SW_FORCE   NO_OS_BIT(4)
 
#define MAXM86161_PPG_SYNC_GPIO_CTRL_MSK   NO_OS_GENMASK(3, 0)
 
#define MAXM86161_REG_PPG_CFG_1   0x11
 
#define MAXM86161_PPG_CFG1_ALC_DISABLE   NO_OS_BIT(7)
 
#define MAXM86161_PPG_CFG1_ADD_OFFSET   NO_OS_BIT(6)
 
#define MAXM86161_PPG_CFG1_ADC_RGE_MSK   NO_OS_GENMASK(3, 2)
 
#define MAXM86161_PPG_CFG1_PPG_TINT_MSK   NO_OS_GENMASK(1, 0)
 
#define MAXM86161_REG_PPG_CFG_2   0x12
 
#define MAXM86161_PPG_CFG2_PPG_SR_MSK   NO_OS_GENMASK(7, 3)
 
#define MAXM86161_PPG_CFG2_SMP_AVE_MSK   NO_OS_GENMASK(2, 0)
 
#define MAXM86161_REG_PPG_CFG_3   0x13
 
#define MAXM86161_PPG_CFG3_LED_SETLNG_MSK   NO_OS_GENMASK(7, 6)
 
#define MAXM86161_PPG_CFG3_DIG_FILT_MSK   NO_OS_BIT(5)
 
#define MAXM86161_PPG_CFG3_BURST_RATE_MSK   NO_OS_GENMASK(2, 1)
 
#define MAXM86161_PPG_CFG3_BURST_EN   NO_OS_BIT(0)
 
#define MAXM86161_PPG_SR_MAX   0x13
 
#define MAXM86161_REG_PROX_INT_THRESH   0x14
 
#define MAXM86161_REG_PD_BIAS   0x15
 
#define MAXM86161_PD_BIAS_MSK   NO_OS_GENMASK(2, 0)
 
#define MAXM86161_REG_PICKET_FENCE   0x16
 
#define MAXM86161_PF_ENABLE   NO_OS_BIT(7)
 
#define MAXM86161_PF_ORDER   NO_OS_BIT(6)
 
#define MAXM86161_PF_IIR_TC_MSK   NO_OS_GENMASK(5, 4)
 
#define MAXM86161_PF_IIR_INIT_MSK   NO_OS_GENMASK(3, 2)
 
#define MAXM86161_PF_THRESH_SIGMA_MSK   NO_OS_GENMASK(1, 0)
 
#define MAXM86161_REG_LED_SEQ_1   0x20
 
#define MAXM86161_REG_LED_SEQ_2   0x21
 
#define MAXM86161_REG_LED_SEQ_3   0x22
 
#define MAXM86161_LED_SEQ_ODD_MSK   NO_OS_GENMASK(3, 0)
 
#define MAXM86161_LED_SEQ_EVEN_MSK   NO_OS_GENMASK(7, 4)
 
#define MAXM86161_REG_LED1_PA   0x23
 
#define MAXM86161_REG_LED2_PA   0x24
 
#define MAXM86161_REG_LED3_PA   0x25
 
#define MAXM86161_REG_LED_PILOT_PA   0x29
 
#define MAXM86161_REG_LED_RANGE_1   0x2A
 
#define MAXM86161_LED1_RGE_MSK   NO_OS_GENMASK(1, 0)
 
#define MAXM86161_LED2_RGE_MSK   NO_OS_GENMASK(3, 2)
 
#define MAXM86161_LED3_RGE_MSK   NO_OS_GENMASK(5, 4)
 
#define MAXM86161_REG_S1_HIRES_DAC   0x2C
 
#define MAXM86161_REG_S2_HIRES_DAC   0x2D
 
#define MAXM86161_REG_S3_HIRES_DAC   0x2E
 
#define MAXM86161_REG_S4_HIRES_DAC   0x2F
 
#define MAXM86161_REG_S5_HIRES_DAC   0x30
 
#define MAXM86161_REG_S6_HIRES_DAC   0x31
 
#define MAXM86161_HIRES_DAC_OVR   NO_OS_BIT(7)
 
#define MAXM86161_HIRES_DAC_VAL_MSK   NO_OS_GENMASK(5, 0)
 
#define MAXM86161_REG_DIE_TEMP_CFG   0x40
 
#define MAXM86161_TEMP_EN   NO_OS_BIT(0)
 
#define MAXM86161_TEMP_MEAS_WAIT_TRIES   10
 
#define MAXM86161_TEMP_MEAS_DELAY_MS   10
 
#define MAXM86161_REG_DIE_TEMP_INT   0x41
 
#define MAXM86161_REG_DIE_TEMP_FRAC   0x42
 
#define MAXM86161_REG_DIE_TEMP_FRAC_MASK   NO_OS_GENMASK(3, 0)
 
#define MAXM86161_REG_DIE_TEMP_INT_MASK   NO_OS_GENMASK(7, 0) /* Temp should be read in a burst */
 
#define MAXM86161_DIE_TEMP_FRAC_OFFSET   8
 
#define MAXM86161_DIE_TEMP_SCALE_UC   1000000
 
#define MAXM86161_DIE_TEMP_FRAC_SCALE_UC   62500
 
#define MAXM86161_REG_DAC_CAL_EN   0x50
 
#define MAXM86161_CAL_DAC_COMPLETE   NO_OS_BIT(6)
 
#define MAXM86161_CAL_DAC1_OOR   NO_OS_BIT(4)
 
#define MAXM86161_START_CAL   NO_OS_BIT(2)
 
#define MAXM86161_REG_SHA_CMD   0xF0
 
#define MAXM86161_REG_SHA_CFG   0xF1
 
#define MAXM86161_SHA_EN   NO_OS_BIT(1)
 
#define MAXM86161_SHA_START   NO_OS_BIT(0)
 
#define MAXM86161_SHA_CHALLENGE_LEN   20
 
#define MAXM86161_REG_MEM_CTRL   0xF2
 
#define MAXM86161_MEM_WR_EN   NO_OS_BIT(1)
 
#define MAXM86161_MEM_BANK_SEL   NO_OS_BIT(0)
 
#define MAXM86161_REG_MEM_IDX   0xF3
 
#define MAXM86161_MEM_IDX_MAX   0x17F
 
#define MAXM86161_MEM_IDX_BANK0_MSK   0xFF
 
#define MAXM86161_REG_MEM_DATA   0xF4
 
#define MAXM86161_REG_REV_ID   0xFE
 
#define MAXM86161_REG_PART_ID   0xFF
 
#define MAXM86161_FIFO_TAG_MSK   NO_OS_GENMASK(23, 19)
 
#define MAXM86161_FIFO_DATA_MSK   NO_OS_GENMASK(18, 0)
 
#define MAXM86161_FIFO_TAG_SHIFT   19
 
#define MAXM86161_FIFO_PACK(tag, data)
 
#define MAXM86161_SHA_CMD_MAC_W_ROM   0x35
 
#define MAXM86161_SHA_CMD_MAC_WO_ROM   0x36
 
#define MAXM86161_SHA_MEM_START   0x00
 
#define MAXM86161_SHA_MEM_END   0x09
 
#define MAXM86161_FIFO_SAMPLE_SIZE   3
 
#define MAXM86161_FIFO_BURST_RD_CAP   (255U - (255U % MAXM86161_FIFO_SAMPLE_SIZE))
 

Typedefs

typedef void(* maxm86161_int_cb_t) (void *ctx)
 

Enumerations

enum  maxm86161_fifo_tag {
  MAXM86161_TAG_PPG1_LEDC1 = 0x01 ,
  MAXM86161_TAG_PPG1_LEDC2 ,
  MAXM86161_TAG_PPG1_LEDC3 ,
  MAXM86161_TAG_PPG1_LEDC4 ,
  MAXM86161_TAG_PPG1_LEDC5 ,
  MAXM86161_TAG_PPG1_LEDC6 ,
  MAXM86161_TAG_PROX1 = 0x19 ,
  MAXM86161_TAG_SUB_DAC_UPDATE = 0x1D ,
  MAXM86161_TAG_INVALID ,
  MAXM86161_TAG_TIME_STAMP
}
 
enum  maxm86161_led_num {
  MAXM86161_LED_NUM_GREEN = 1 ,
  MAXM86161_LED_NUM_IR ,
  MAXM86161_LED_NUM_RED ,
  MAXM86161_LED_NUM_PILOT_GREEN
}
 
enum  maxm86161_led_src {
  MAXM86161_LED_SRC_NONE = 0 ,
  MAXM86161_LED_SRC_GREEN ,
  MAXM86161_LED_SRC_IR ,
  MAXM86161_LED_SRC_RED ,
  MAXM86161_LED_SRC_PILOT_GREEN = 8 ,
  MAXM86161_LED_SRC_DIRECT_AMB
}
 
enum  maxm86161_ppg_tint {
  MAXM86161_TINT_14_8_US = 0 ,
  MAXM86161_TINT_29_4_US ,
  MAXM86161_TINT_58_7_US ,
  MAXM86161_TINT_117_3_US
}
 
enum  maxm86161_adc_range {
  MAXM86161_ADC_RGE_4UA = 0 ,
  MAXM86161_ADC_RGE_8UA ,
  MAXM86161_ADC_RGE_16UA ,
  MAXM86161_ADC_RGE_32UA
}
 
enum  maxm86161_smp_ave {
  MAXM86161_SMP_AVE_1 = 0 ,
  MAXM86161_SMP_AVE_2 ,
  MAXM86161_SMP_AVE_4 ,
  MAXM86161_SMP_AVE_8 ,
  MAXM86161_SMP_AVE_16 ,
  MAXM86161_SMP_AVE_32 ,
  MAXM86161_SMP_AVE_64 ,
  MAXM86161_SMP_AVE_128
}
 
enum  maxm86161_led_range {
  MAXM86161_LED_RGE_31MA = 0 ,
  MAXM86161_LED_RGE_62MA ,
  MAXM86161_LED_RGE_93MA ,
  MAXM86161_LED_RGE_124MA
}
 
enum  maxm86161_led_settling {
  MAXM86161_LED_SETLNG_4_US = 0 ,
  MAXM86161_LED_SETLNG_6_US ,
  MAXM86161_LED_SETLNG_8_US ,
  MAXM86161_LED_SETLNG_12_US
}
 
enum  maxm86161_dig_filt_sel {
  MAXM86161_DIG_FILT_CDM = 0 ,
  MAXM86161_DIG_FILT_FDM
}
 
enum  maxm86161_burst_rate {
  MAXM86161_BURST_RATE_8HZ = 0 ,
  MAXM86161_BURST_RATE_32HZ ,
  MAXM86161_BURST_RATE_84HZ ,
  MAXM86161_BURST_RATE_256HZ
}
 
enum  maxm86161_pf_iir_tc {
  MAXM86161_PF_IIR_TC_1_64 = 0 ,
  MAXM86161_PF_IIR_TC_1_32 ,
  MAXM86161_PF_IIR_TC_1_16 ,
  MAXM86161_PF_IIR_TC_1_8
}
 
enum  maxm86161_pf_iir_init {
  MAXM86161_PF_IIR_INIT_64 = 0 ,
  MAXM86161_PF_IIR_INIT_48 ,
  MAXM86161_PF_IIR_INIT_32 ,
  MAXM86161_PF_IIR_INIT_24
}
 
enum  maxm86161_pf_threshold_sigma_mult {
  MAXM86161_PF_TH_GAIN_4 = 0 ,
  MAXM86161_PF_TH_GAIN_8 ,
  MAXM86161_PF_TH_GAIN_16 ,
  MAXM86161_PF_TH_GAIN_32
}
 
enum  maxm86161_pd_bias {
  MAXM86161_PD_BIAS_0_65PF = 1 ,
  MAXM86161_PD_BIAS_65_130PF = 5 ,
  MAXM86161_PD_BIAS_130_260PF ,
  MAXM86161_PD_BIAS_260_520PF
}
 
enum  maxm86161_gpio_ctrl {
  MAXM86161_GPIO_TRISTATE = 0 ,
  MAXM86161_GPIO_SAMPLE_TRIGGER = 2 ,
  MAXM86161_GPIO_EXPOSURE_TRIGGER = 6 ,
  MAXM86161_GPIO_HW_FORCE_SYNC = 9 ,
  MAXM86161_GPIO_SAMPLE_SYNC_ONESHOT
}
 
enum  maxm86161_irq_sources {
  MAXM86161_INT_PWR_RDY = 0 ,
  MAXM86161_INT_DIE_TEMP_RDY ,
  MAXM86161_INT_LED_COMPB ,
  MAXM86161_INT_PROX_INT ,
  MAXM86161_INT_ALC_OVF ,
  MAXM86161_INT_DATA_RDY ,
  MAXM86161_INT_A_FULL ,
  MAXM86161_INT_SHA_DONE ,
  MAXM86161_INT_COUNT
}
 

Functions

int maxm86161_init (struct maxm86161_dev **device, struct maxm86161_init_param *init_param)
 Initialize the MAXM86161 device driver.
 
int maxm86161_remove (struct maxm86161_dev *dev)
 Free resources allocated by maxm86161_init().
 
int maxm86161_reset (struct maxm86161_dev *dev)
 Perform a software reset of the MAXM86161.
 
int maxm86161_verify_id (struct maxm86161_dev *dev)
 Verify the MAXM86161 part identity and cache revision info.
 
int maxm86161_reg_read (struct maxm86161_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
 Read a single register from the MAXM86161.
 
int maxm86161_reg_write (struct maxm86161_dev *dev, uint8_t reg_addr, uint8_t reg_data)
 Write a single register on the MAXM86161.
 
int maxm86161_reg_update_bits (struct maxm86161_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t data)
 Read-modify-write the bits selected by a mask in a register.
 
int maxm86161_burst_reg_read (struct maxm86161_dev *dev, uint8_t reg_addr, uint8_t *reg_data, uint16_t count)
 Burst-read multiple bytes starting at a register address.
 
int maxm86161_burst_reg_write (struct maxm86161_dev *dev, uint8_t reg_addr, uint8_t *reg_data, uint16_t count)
 Burst-write multiple bytes starting at a register address.
 
int maxm86161_shutdown (struct maxm86161_dev *dev)
 Put the MAXM86161 into shutdown (power-down) mode.
 
int maxm86161_set_shutdown (struct maxm86161_dev *dev, bool enable)
 Enable or disable shutdown mode of the MAXM86161.
 
int maxm86161_set_low_power_mode (struct maxm86161_dev *dev, bool enable)
 Enable or disable low-power mode of the MAXM86161.
 
int maxm86161_set_sample_rate (struct maxm86161_dev *dev, uint8_t ppg_sr)
 Set the PPG sample rate.
 
int maxm86161_get_sample_rate (struct maxm86161_dev *dev, uint8_t *ppg_sr)
 Get the currently configured PPG sample rate.
 
int maxm86161_set_integration_time (struct maxm86161_dev *dev, enum maxm86161_ppg_tint tint)
 Set the PPG ADC integration time.
 
int maxm86161_get_integration_time (struct maxm86161_dev *dev, enum maxm86161_ppg_tint *tint)
 Get the currently configured PPG ADC integration time.
 
int maxm86161_set_adc_range (struct maxm86161_dev *dev, enum maxm86161_adc_range range)
 Set the PPG ADC full-scale range.
 
int maxm86161_get_adc_range (struct maxm86161_dev *dev, enum maxm86161_adc_range *range)
 Get the currently configured PPG ADC full-scale range.
 
int maxm86161_set_sample_averaging (struct maxm86161_dev *dev, enum maxm86161_smp_ave avg)
 Set the number of samples averaged per FIFO data point.
 
int maxm86161_get_sample_averaging (struct maxm86161_dev *dev, enum maxm86161_smp_ave *avg)
 Get the currently configured sample averaging.
 
int maxm86161_set_alc_disable (struct maxm86161_dev *dev, bool disable)
 Enable or disable the Ambient Light Cancellation (ALC) circuit.
 
int maxm86161_get_alc_disable (struct maxm86161_dev *dev, bool *disable)
 Get the current Ambient Light Cancellation (ALC) disable state.
 
int maxm86161_set_add_offset (struct maxm86161_dev *dev, bool enable)
 Enable or disable the ADC add-offset feature.
 
int maxm86161_get_add_offset (struct maxm86161_dev *dev, bool *enable)
 Get the current ADC add-offset enable state.
 
int maxm86161_set_led_settling (struct maxm86161_dev *dev, enum maxm86161_led_settling settling)
 Set the LED settling time.
 
int maxm86161_get_led_settling (struct maxm86161_dev *dev, enum maxm86161_led_settling *settling)
 Get the currently configured LED settling time.
 
int maxm86161_set_digital_filter (struct maxm86161_dev *dev, enum maxm86161_dig_filt_sel filter)
 Select the PPG digital filter (CDM or FDM).
 
int maxm86161_get_digital_filter (struct maxm86161_dev *dev, enum maxm86161_dig_filt_sel *filter)
 Get the currently selected PPG digital filter.
 
int maxm86161_set_pd_bias (struct maxm86161_dev *dev, enum maxm86161_pd_bias bias)
 Set the photodiode bias (based on PD capacitance).
 
int maxm86161_get_pd_bias (struct maxm86161_dev *dev, enum maxm86161_pd_bias *bias)
 Get the currently configured photodiode bias.
 
int maxm86161_set_led_sequence (struct maxm86161_dev *dev, uint8_t slot, enum maxm86161_led_src src)
 Set the LED/measurement source for a single sequence slot.
 
int maxm86161_get_led_sequence (struct maxm86161_dev *dev, uint8_t slot, enum maxm86161_led_src *src)
 Get the LED/measurement source configured for a sequence slot.
 
int maxm86161_set_led_pulse_amplitude (struct maxm86161_dev *dev, enum maxm86161_led_num led_num, uint8_t amplitude)
 Set the pulse amplitude (drive current) of an LED.
 
int maxm86161_get_led_pulse_amplitude (struct maxm86161_dev *dev, enum maxm86161_led_num led_num, uint8_t *amplitude)
 Get the pulse amplitude (drive current) of an LED.
 
int maxm86161_set_led_range (struct maxm86161_dev *dev, enum maxm86161_led_num led_num, enum maxm86161_led_range range)
 Set the full-scale current range of an LED driver.
 
int maxm86161_get_led_range (struct maxm86161_dev *dev, enum maxm86161_led_num led_num, enum maxm86161_led_range *range)
 Get the full-scale current range of an LED driver.
 
int maxm86161_set_led_cfg (struct maxm86161_dev *dev, enum maxm86161_led_num led_num, enum maxm86161_led_range range, uint8_t led_seq_num, uint8_t amplitude)
 Get the full-scale current range of an LED driver.
 
int maxm86161_set_hires_dac (struct maxm86161_dev *dev, uint8_t slot, bool override, uint8_t dac_val)
 Configure the high-resolution DAC override for a sequence slot.
 
int maxm86161_get_hires_dac (struct maxm86161_dev *dev, uint8_t slot, bool *override, uint8_t *dac_val)
 Read back the high-resolution DAC configuration for a slot.
 
int maxm86161_set_fifo_watermark (struct maxm86161_dev *dev, uint8_t watermark)
 Set the FIFO almost-full watermark threshold.
 
int maxm86161_get_fifo_watermark (struct maxm86161_dev *dev, uint8_t *watermark)
 Get the FIFO almost-full watermark threshold.
 
int maxm86161_fifo_flush (struct maxm86161_dev *dev)
 Flush (clear) the FIFO contents.
 
int maxm86161_set_fifo_rollover (struct maxm86161_dev *dev, bool enable)
 Enable or disable FIFO roll-over on full.
 
int maxm86161_get_fifo_rollover (struct maxm86161_dev *dev, bool *enable)
 Get the FIFO roll-over enable state.
 
int maxm86161_set_fifo_a_full_type (struct maxm86161_dev *dev, bool type)
 Set the FIFO almost-full interrupt assertion behavior.
 
int maxm86161_get_fifo_a_full_type (struct maxm86161_dev *dev, bool *type)
 Get the FIFO almost-full interrupt assertion behavior.
 
int maxm86161_set_fifo_stat_clr (struct maxm86161_dev *dev, bool enable)
 Configure whether reading FIFO data clears the status bit.
 
int maxm86161_get_fifo_count (struct maxm86161_dev *dev, uint8_t *count)
 Get the number of samples currently stored in the FIFO.
 
int maxm86161_fifo_overflow_check (struct maxm86161_dev *dev, uint8_t *overflow_count)
 Read the FIFO overflow counter.
 
int maxm86161_read_fifo_data (struct maxm86161_dev *dev, uint8_t *data, uint16_t num_samples)
 Burst-read raw sample data from the FIFO.
 
int maxm86161_decode_fifo_sample (uint8_t *raw, uint8_t *tag, uint32_t *data)
 Decode a raw 3-byte FIFO sample into its tag and data fields.
 
int maxm86161_get_interrupt_status (struct maxm86161_dev *dev, uint16_t *status)
 Read the combined interrupt status of the MAXM86161.
 
int maxm86161_clear_interrupt_status (struct maxm86161_dev *dev)
 Clear pending interrupt status flags.
 
int maxm86161_set_irq_handler (struct maxm86161_dev *dev, enum maxm86161_irq_sources int_source, bool enable, maxm86161_int_cb_t callback, void *cb_args)
 Register a callback for an interrupt source and enable/disable it.
 
void maxm86161_irq_handler (void *ctx)
 Top-level interrupt dispatcher for the MAXM86161.
 
int maxm86161_set_prox_threshold (struct maxm86161_dev *dev, uint8_t threshold)
 Set the proximity mode entry threshold.
 
int maxm86161_get_prox_threshold (struct maxm86161_dev *dev, uint8_t *threshold)
 Get the proximity mode entry threshold.
 
int maxm86161_set_pf_enable (struct maxm86161_dev *dev, bool enable)
 Enable or disable the picket-fence detect-and-replace feature.
 
int maxm86161_get_pf_enable (struct maxm86161_dev *dev, bool *enable)
 Get the picket-fence enable state.
 
int maxm86161_set_pf_order (struct maxm86161_dev *dev, bool order)
 Set the picket-fence detect/replace ordering.
 
int maxm86161_get_pf_order (struct maxm86161_dev *dev, bool *order)
 Get the picket-fence detect/replace ordering.
 
int maxm86161_set_pf_iir_tc (struct maxm86161_dev *dev, enum maxm86161_pf_iir_tc iir_tc)
 Set the picket-fence IIR time constant.
 
int maxm86161_get_pf_iir_tc (struct maxm86161_dev *dev, enum maxm86161_pf_iir_tc *iir_tc)
 Get the picket-fence IIR time constant.
 
int maxm86161_set_pf_iir_init (struct maxm86161_dev *dev, enum maxm86161_pf_iir_init iir_init_value)
 Set the picket-fence IIR initialization value.
 
int maxm86161_get_pf_iir_init (struct maxm86161_dev *dev, enum maxm86161_pf_iir_init *iir_init_value)
 Get the picket-fence IIR initialization value.
 
int maxm86161_set_pf_threshold_sigma (struct maxm86161_dev *dev, enum maxm86161_pf_threshold_sigma_mult threshold_sigma_mult)
 Set the picket-fence threshold sigma multiplier.
 
int maxm86161_get_pf_threshold_sigma (struct maxm86161_dev *dev, enum maxm86161_pf_threshold_sigma_mult *threshold_sigma_mult)
 Get the picket-fence threshold sigma multiplier.
 
int maxm86161_read_die_temperature (struct maxm86161_dev *dev, int32_t *temperature)
 Read and convert the die temperature.
 
int maxm86161_start_calibration (struct maxm86161_dev *dev)
 Start the DAC (offset) calibration procedure.
 
int maxm86161_get_calibration_status (struct maxm86161_dev *dev, bool *complete, bool *oor)
 Query the DAC calibration status.
 
int maxm86161_set_burst_enable (struct maxm86161_dev *dev, bool enable)
 Enable or disable burst sampling mode and set its rate.
 
int maxm86161_set_burst_rate (struct maxm86161_dev *dev, enum maxm86161_burst_rate rate)
 Enable or disable burst sampling mode and set its rate.
 
int maxm86161_set_burst_mode (struct maxm86161_dev *dev, bool enable, enum maxm86161_burst_rate rate)
 Enable or disable burst sampling mode and set its rate.
 
int maxm86161_set_timestamp_enable (struct maxm86161_dev *dev, bool enable)
 Enable or disable timestamp tagging of PPG samples.
 
int maxm86161_set_dac_code_tag (struct maxm86161_dev *dev, bool enable)
 Enable or disable DAC-code tagging of PPG samples.
 
int maxm86161_set_gpio_ctrl (struct maxm86161_dev *dev, enum maxm86161_gpio_ctrl ctrl)
 Configure the behavior of the GPIO/sync pin.
 
int maxm86161_force_sync (struct maxm86161_dev *dev)
 Issue a software-forced PPG synchronization event.
 
int maxm86161_sha_enable (struct maxm86161_dev *dev, bool enable)
 Enable or disable the SHA-256 authentication engine.
 
int maxm86161_sha_start (struct maxm86161_dev *dev, uint8_t cmd)
 Issue a SHA command and start the SHA-256 operation.
 
int maxm86161_sha_write_challenge (struct maxm86161_dev *dev, uint8_t *challenge, uint8_t len)
 Write a SHA-256 challenge into the device memory.
 
int maxm86161_sha_read_response (struct maxm86161_dev *dev, uint8_t *response, uint8_t len)
 Read the SHA-256 response from the device memory.
 
int maxm86161_memory_read (struct maxm86161_dev *dev, uint16_t addr, uint8_t *data)
 Read a single byte from the device memory.
 
int maxm86161_memory_write (struct maxm86161_dev *dev, uint16_t addr, uint8_t data)
 Write a single byte to the device memory.
 

Detailed Description

Header file for MAXM86161 optical pulse oximeter driver.

Author
Jan Carlo Roleda (janca.nosp@m.rlo..nosp@m.roled.nosp@m.a@an.nosp@m.alog..nosp@m.com)

Copyright 2026(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Macro Definition Documentation

◆ MAXM86161_CAL_DAC1_OOR

#define MAXM86161_CAL_DAC1_OOR   NO_OS_BIT(4)

◆ MAXM86161_CAL_DAC_COMPLETE

#define MAXM86161_CAL_DAC_COMPLETE   NO_OS_BIT(6)

◆ MAXM86161_DIE_TEMP_FRAC_OFFSET

#define MAXM86161_DIE_TEMP_FRAC_OFFSET   8

◆ MAXM86161_DIE_TEMP_FRAC_SCALE_UC

#define MAXM86161_DIE_TEMP_FRAC_SCALE_UC   62500

◆ MAXM86161_DIE_TEMP_SCALE_UC

#define MAXM86161_DIE_TEMP_SCALE_UC   1000000

◆ MAXM86161_FIFO_A_FULL_MAX

#define MAXM86161_FIFO_A_FULL_MAX   127

◆ MAXM86161_FIFO_A_FULL_MSK

#define MAXM86161_FIFO_A_FULL_MSK   NO_OS_GENMASK(6, 0)

◆ MAXM86161_FIFO_BURST_RD_CAP

#define MAXM86161_FIFO_BURST_RD_CAP   (255U - (255U % MAXM86161_FIFO_SAMPLE_SIZE))

◆ MAXM86161_FIFO_CFG2_A_FULL_TYPE

#define MAXM86161_FIFO_CFG2_A_FULL_TYPE   NO_OS_BIT(2)

◆ MAXM86161_FIFO_CFG2_FIFO_RO

#define MAXM86161_FIFO_CFG2_FIFO_RO   NO_OS_BIT(1)

◆ MAXM86161_FIFO_CFG2_FLUSH

#define MAXM86161_FIFO_CFG2_FLUSH   NO_OS_BIT(4)

◆ MAXM86161_FIFO_CFG2_STAT_CLR

#define MAXM86161_FIFO_CFG2_STAT_CLR   NO_OS_BIT(3)

◆ MAXM86161_FIFO_DATA_MSK

#define MAXM86161_FIFO_DATA_MSK   NO_OS_GENMASK(18, 0)

◆ MAXM86161_FIFO_DATA_SIZE

#define MAXM86161_FIFO_DATA_SIZE   3

◆ MAXM86161_FIFO_DEPTH

#define MAXM86161_FIFO_DEPTH   128

◆ MAXM86161_FIFO_OVF_COUNTER_MSK

#define MAXM86161_FIFO_OVF_COUNTER_MSK   NO_OS_GENMASK(6, 0)

◆ MAXM86161_FIFO_PACK

#define MAXM86161_FIFO_PACK ( tag,
data )
Value:
((((uint32_t)(tag) << MAXM86161_FIFO_TAG_SHIFT) & MAXM86161_FIFO_TAG_MSK) | \
((uint32_t)(data) & MAXM86161_FIFO_DATA_MSK))
#define MAXM86161_FIFO_TAG_SHIFT
Definition maxm86161.h:192
#define MAXM86161_FIFO_TAG_MSK
Definition maxm86161.h:190
#define MAXM86161_FIFO_DATA_MSK
Definition maxm86161.h:191

◆ MAXM86161_FIFO_SAMPLE_SIZE

#define MAXM86161_FIFO_SAMPLE_SIZE   3

◆ MAXM86161_FIFO_TAG_MSK

#define MAXM86161_FIFO_TAG_MSK   NO_OS_GENMASK(23, 19)

◆ MAXM86161_FIFO_TAG_SHIFT

#define MAXM86161_FIFO_TAG_SHIFT   19

◆ MAXM86161_HIRES_DAC_OVR

#define MAXM86161_HIRES_DAC_OVR   NO_OS_BIT(7)

◆ MAXM86161_HIRES_DAC_VAL_MSK

#define MAXM86161_HIRES_DAC_VAL_MSK   NO_OS_GENMASK(5, 0)

◆ MAXM86161_I2C_ADDR

#define MAXM86161_I2C_ADDR   0x62

◆ MAXM86161_INT1_A_FULL

#define MAXM86161_INT1_A_FULL   NO_OS_BIT(7)

◆ MAXM86161_INT1_A_FULL_EN

#define MAXM86161_INT1_A_FULL_EN   NO_OS_BIT(7)

◆ MAXM86161_INT1_ALC_OVF

#define MAXM86161_INT1_ALC_OVF   NO_OS_BIT(5)

◆ MAXM86161_INT1_ALC_OVF_EN

#define MAXM86161_INT1_ALC_OVF_EN   NO_OS_BIT(5)

◆ MAXM86161_INT1_DATA_RDY

#define MAXM86161_INT1_DATA_RDY   NO_OS_BIT(6)

◆ MAXM86161_INT1_DATA_RDY_EN

#define MAXM86161_INT1_DATA_RDY_EN   NO_OS_BIT(6)

◆ MAXM86161_INT1_DIE_TEMP_RDY

#define MAXM86161_INT1_DIE_TEMP_RDY   NO_OS_BIT(2)

◆ MAXM86161_INT1_DIE_TEMP_RDY_EN

#define MAXM86161_INT1_DIE_TEMP_RDY_EN   NO_OS_BIT(2)

◆ MAXM86161_INT1_LED_COMPB

#define MAXM86161_INT1_LED_COMPB   NO_OS_BIT(3)

◆ MAXM86161_INT1_LED_COMPB_EN

#define MAXM86161_INT1_LED_COMPB_EN   NO_OS_BIT(3)

◆ MAXM86161_INT1_PROX_INT

#define MAXM86161_INT1_PROX_INT   NO_OS_BIT(4)

◆ MAXM86161_INT1_PROX_INT_EN

#define MAXM86161_INT1_PROX_INT_EN   NO_OS_BIT(4)

◆ MAXM86161_INT1_PWR_RDY

#define MAXM86161_INT1_PWR_RDY   NO_OS_BIT(0)

◆ MAXM86161_INT2_SHA_DONE

#define MAXM86161_INT2_SHA_DONE   NO_OS_BIT(0)

◆ MAXM86161_INT2_SHA_DONE_EN

#define MAXM86161_INT2_SHA_DONE_EN   NO_OS_BIT(0)

◆ MAXM86161_LED1_RGE_MSK

#define MAXM86161_LED1_RGE_MSK   NO_OS_GENMASK(1, 0)

◆ MAXM86161_LED2_RGE_MSK

#define MAXM86161_LED2_RGE_MSK   NO_OS_GENMASK(3, 2)

◆ MAXM86161_LED3_RGE_MSK

#define MAXM86161_LED3_RGE_MSK   NO_OS_GENMASK(5, 4)

◆ MAXM86161_LED_SEQ_EVEN_MSK

#define MAXM86161_LED_SEQ_EVEN_MSK   NO_OS_GENMASK(7, 4)

◆ MAXM86161_LED_SEQ_ODD_MSK

#define MAXM86161_LED_SEQ_ODD_MSK   NO_OS_GENMASK(3, 0)

◆ MAXM86161_MEM_BANK_SEL

#define MAXM86161_MEM_BANK_SEL   NO_OS_BIT(0)

◆ MAXM86161_MEM_IDX_BANK0_MSK

#define MAXM86161_MEM_IDX_BANK0_MSK   0xFF

◆ MAXM86161_MEM_IDX_MAX

#define MAXM86161_MEM_IDX_MAX   0x17F

◆ MAXM86161_MEM_WR_EN

#define MAXM86161_MEM_WR_EN   NO_OS_BIT(1)

◆ MAXM86161_NUM_LED_SEQ

#define MAXM86161_NUM_LED_SEQ   6

◆ MAXM86161_NUM_LEDS

#define MAXM86161_NUM_LEDS   3

◆ MAXM86161_PART_ID_VAL

#define MAXM86161_PART_ID_VAL   0x36

◆ MAXM86161_PD_BIAS_MSK

#define MAXM86161_PD_BIAS_MSK   NO_OS_GENMASK(2, 0)

◆ MAXM86161_PF_ENABLE

#define MAXM86161_PF_ENABLE   NO_OS_BIT(7)

◆ MAXM86161_PF_IIR_INIT_MSK

#define MAXM86161_PF_IIR_INIT_MSK   NO_OS_GENMASK(3, 2)

◆ MAXM86161_PF_IIR_TC_MSK

#define MAXM86161_PF_IIR_TC_MSK   NO_OS_GENMASK(5, 4)

◆ MAXM86161_PF_ORDER

#define MAXM86161_PF_ORDER   NO_OS_BIT(6)

◆ MAXM86161_PF_THRESH_SIGMA_MSK

#define MAXM86161_PF_THRESH_SIGMA_MSK   NO_OS_GENMASK(1, 0)

◆ MAXM86161_PPG_CFG1_ADC_RGE_MSK

#define MAXM86161_PPG_CFG1_ADC_RGE_MSK   NO_OS_GENMASK(3, 2)

◆ MAXM86161_PPG_CFG1_ADD_OFFSET

#define MAXM86161_PPG_CFG1_ADD_OFFSET   NO_OS_BIT(6)

◆ MAXM86161_PPG_CFG1_ALC_DISABLE

#define MAXM86161_PPG_CFG1_ALC_DISABLE   NO_OS_BIT(7)

◆ MAXM86161_PPG_CFG1_PPG_TINT_MSK

#define MAXM86161_PPG_CFG1_PPG_TINT_MSK   NO_OS_GENMASK(1, 0)

◆ MAXM86161_PPG_CFG2_PPG_SR_MSK

#define MAXM86161_PPG_CFG2_PPG_SR_MSK   NO_OS_GENMASK(7, 3)

◆ MAXM86161_PPG_CFG2_SMP_AVE_MSK

#define MAXM86161_PPG_CFG2_SMP_AVE_MSK   NO_OS_GENMASK(2, 0)

◆ MAXM86161_PPG_CFG3_BURST_EN

#define MAXM86161_PPG_CFG3_BURST_EN   NO_OS_BIT(0)

◆ MAXM86161_PPG_CFG3_BURST_RATE_MSK

#define MAXM86161_PPG_CFG3_BURST_RATE_MSK   NO_OS_GENMASK(2, 1)

◆ MAXM86161_PPG_CFG3_DIG_FILT_MSK

#define MAXM86161_PPG_CFG3_DIG_FILT_MSK   NO_OS_BIT(5)

◆ MAXM86161_PPG_CFG3_LED_SETLNG_MSK

#define MAXM86161_PPG_CFG3_LED_SETLNG_MSK   NO_OS_GENMASK(7, 6)

◆ MAXM86161_PPG_SR_MAX

#define MAXM86161_PPG_SR_MAX   0x13

◆ MAXM86161_PPG_SYNC_DAC_CODE_TAG

#define MAXM86161_PPG_SYNC_DAC_CODE_TAG   NO_OS_BIT(6)

◆ MAXM86161_PPG_SYNC_GPIO_CTRL_MSK

#define MAXM86161_PPG_SYNC_GPIO_CTRL_MSK   NO_OS_GENMASK(3, 0)

◆ MAXM86161_PPG_SYNC_SW_FORCE

#define MAXM86161_PPG_SYNC_SW_FORCE   NO_OS_BIT(4)

◆ MAXM86161_PPG_SYNC_TIMESTAMP_EN

#define MAXM86161_PPG_SYNC_TIMESTAMP_EN   NO_OS_BIT(7)

◆ MAXM86161_REG_DAC_CAL_EN

#define MAXM86161_REG_DAC_CAL_EN   0x50

◆ MAXM86161_REG_DIE_TEMP_CFG

#define MAXM86161_REG_DIE_TEMP_CFG   0x40

◆ MAXM86161_REG_DIE_TEMP_FRAC

#define MAXM86161_REG_DIE_TEMP_FRAC   0x42

◆ MAXM86161_REG_DIE_TEMP_FRAC_MASK

#define MAXM86161_REG_DIE_TEMP_FRAC_MASK   NO_OS_GENMASK(3, 0)

◆ MAXM86161_REG_DIE_TEMP_INT

#define MAXM86161_REG_DIE_TEMP_INT   0x41

◆ MAXM86161_REG_DIE_TEMP_INT_MASK

#define MAXM86161_REG_DIE_TEMP_INT_MASK   NO_OS_GENMASK(7, 0) /* Temp should be read in a burst */

◆ MAXM86161_REG_FIFO_CFG_1

#define MAXM86161_REG_FIFO_CFG_1   0x09

◆ MAXM86161_REG_FIFO_CFG_2

#define MAXM86161_REG_FIFO_CFG_2   0x0A

◆ MAXM86161_REG_FIFO_DATA

#define MAXM86161_REG_FIFO_DATA   0x08

◆ MAXM86161_REG_FIFO_DATA_COUNT

#define MAXM86161_REG_FIFO_DATA_COUNT   0x07

◆ MAXM86161_REG_FIFO_RD_PTR

#define MAXM86161_REG_FIFO_RD_PTR   0x05

◆ MAXM86161_REG_FIFO_WR_PTR

#define MAXM86161_REG_FIFO_WR_PTR   0x04

◆ MAXM86161_REG_INT_EN_1

#define MAXM86161_REG_INT_EN_1   0x02

◆ MAXM86161_REG_INT_EN_2

#define MAXM86161_REG_INT_EN_2   0x03

◆ MAXM86161_REG_INT_STATUS_1

#define MAXM86161_REG_INT_STATUS_1   0x00

◆ MAXM86161_REG_INT_STATUS_2

#define MAXM86161_REG_INT_STATUS_2   0x01

◆ MAXM86161_REG_LED1_PA

#define MAXM86161_REG_LED1_PA   0x23

◆ MAXM86161_REG_LED2_PA

#define MAXM86161_REG_LED2_PA   0x24

◆ MAXM86161_REG_LED3_PA

#define MAXM86161_REG_LED3_PA   0x25

◆ MAXM86161_REG_LED_PILOT_PA

#define MAXM86161_REG_LED_PILOT_PA   0x29

◆ MAXM86161_REG_LED_RANGE_1

#define MAXM86161_REG_LED_RANGE_1   0x2A

◆ MAXM86161_REG_LED_SEQ_1

#define MAXM86161_REG_LED_SEQ_1   0x20

◆ MAXM86161_REG_LED_SEQ_2

#define MAXM86161_REG_LED_SEQ_2   0x21

◆ MAXM86161_REG_LED_SEQ_3

#define MAXM86161_REG_LED_SEQ_3   0x22

◆ MAXM86161_REG_MEM_CTRL

#define MAXM86161_REG_MEM_CTRL   0xF2

◆ MAXM86161_REG_MEM_DATA

#define MAXM86161_REG_MEM_DATA   0xF4

◆ MAXM86161_REG_MEM_IDX

#define MAXM86161_REG_MEM_IDX   0xF3

◆ MAXM86161_REG_OVF_COUNTER

#define MAXM86161_REG_OVF_COUNTER   0x06

◆ MAXM86161_REG_PART_ID

#define MAXM86161_REG_PART_ID   0xFF

◆ MAXM86161_REG_PD_BIAS

#define MAXM86161_REG_PD_BIAS   0x15

◆ MAXM86161_REG_PICKET_FENCE

#define MAXM86161_REG_PICKET_FENCE   0x16

◆ MAXM86161_REG_PPG_CFG_1

#define MAXM86161_REG_PPG_CFG_1   0x11

◆ MAXM86161_REG_PPG_CFG_2

#define MAXM86161_REG_PPG_CFG_2   0x12

◆ MAXM86161_REG_PPG_CFG_3

#define MAXM86161_REG_PPG_CFG_3   0x13

◆ MAXM86161_REG_PPG_SYNC_CTRL

#define MAXM86161_REG_PPG_SYNC_CTRL   0x10

◆ MAXM86161_REG_PROX_INT_THRESH

#define MAXM86161_REG_PROX_INT_THRESH   0x14

◆ MAXM86161_REG_REV_ID

#define MAXM86161_REG_REV_ID   0xFE

◆ MAXM86161_REG_S1_HIRES_DAC

#define MAXM86161_REG_S1_HIRES_DAC   0x2C

◆ MAXM86161_REG_S2_HIRES_DAC

#define MAXM86161_REG_S2_HIRES_DAC   0x2D

◆ MAXM86161_REG_S3_HIRES_DAC

#define MAXM86161_REG_S3_HIRES_DAC   0x2E

◆ MAXM86161_REG_S4_HIRES_DAC

#define MAXM86161_REG_S4_HIRES_DAC   0x2F

◆ MAXM86161_REG_S5_HIRES_DAC

#define MAXM86161_REG_S5_HIRES_DAC   0x30

◆ MAXM86161_REG_S6_HIRES_DAC

#define MAXM86161_REG_S6_HIRES_DAC   0x31

◆ MAXM86161_REG_SHA_CFG

#define MAXM86161_REG_SHA_CFG   0xF1

◆ MAXM86161_REG_SHA_CMD

#define MAXM86161_REG_SHA_CMD   0xF0

◆ MAXM86161_REG_SYS_CTRL

#define MAXM86161_REG_SYS_CTRL   0x0D

◆ MAXM86161_RESET_DELAY_MS

#define MAXM86161_RESET_DELAY_MS   10

◆ MAXM86161_SHA_CHALLENGE_LEN

#define MAXM86161_SHA_CHALLENGE_LEN   20

◆ MAXM86161_SHA_CMD_MAC_W_ROM

#define MAXM86161_SHA_CMD_MAC_W_ROM   0x35

◆ MAXM86161_SHA_CMD_MAC_WO_ROM

#define MAXM86161_SHA_CMD_MAC_WO_ROM   0x36

◆ MAXM86161_SHA_EN

#define MAXM86161_SHA_EN   NO_OS_BIT(1)

◆ MAXM86161_SHA_MEM_END

#define MAXM86161_SHA_MEM_END   0x09

◆ MAXM86161_SHA_MEM_START

#define MAXM86161_SHA_MEM_START   0x00

◆ MAXM86161_SHA_START

#define MAXM86161_SHA_START   NO_OS_BIT(0)

◆ MAXM86161_START_CAL

#define MAXM86161_START_CAL   NO_OS_BIT(2)

◆ MAXM86161_SYS_CTRL_LP_MODE

#define MAXM86161_SYS_CTRL_LP_MODE   NO_OS_BIT(2)

◆ MAXM86161_SYS_CTRL_RESET

#define MAXM86161_SYS_CTRL_RESET   NO_OS_BIT(0)

◆ MAXM86161_SYS_CTRL_SHDN

#define MAXM86161_SYS_CTRL_SHDN   NO_OS_BIT(1)

◆ MAXM86161_SYS_CTRL_SINGLE_PPG

#define MAXM86161_SYS_CTRL_SINGLE_PPG   NO_OS_BIT(3)

◆ MAXM86161_TEMP_EN

#define MAXM86161_TEMP_EN   NO_OS_BIT(0)

◆ MAXM86161_TEMP_MEAS_DELAY_MS

#define MAXM86161_TEMP_MEAS_DELAY_MS   10

◆ MAXM86161_TEMP_MEAS_WAIT_TRIES

#define MAXM86161_TEMP_MEAS_WAIT_TRIES   10

Typedef Documentation

◆ maxm86161_int_cb_t

typedef void(* maxm86161_int_cb_t) (void *ctx)

Enumeration Type Documentation

◆ maxm86161_adc_range

Enumerator
MAXM86161_ADC_RGE_4UA 
MAXM86161_ADC_RGE_8UA 
MAXM86161_ADC_RGE_16UA 
MAXM86161_ADC_RGE_32UA 

◆ maxm86161_burst_rate

Enumerator
MAXM86161_BURST_RATE_8HZ 
MAXM86161_BURST_RATE_32HZ 
MAXM86161_BURST_RATE_84HZ 
MAXM86161_BURST_RATE_256HZ 

◆ maxm86161_dig_filt_sel

Enumerator
MAXM86161_DIG_FILT_CDM 
MAXM86161_DIG_FILT_FDM 

◆ maxm86161_fifo_tag

Enumerator
MAXM86161_TAG_PPG1_LEDC1 
MAXM86161_TAG_PPG1_LEDC2 
MAXM86161_TAG_PPG1_LEDC3 
MAXM86161_TAG_PPG1_LEDC4 
MAXM86161_TAG_PPG1_LEDC5 
MAXM86161_TAG_PPG1_LEDC6 
MAXM86161_TAG_PROX1 
MAXM86161_TAG_SUB_DAC_UPDATE 
MAXM86161_TAG_INVALID 
MAXM86161_TAG_TIME_STAMP 

◆ maxm86161_gpio_ctrl

Enumerator
MAXM86161_GPIO_TRISTATE 
MAXM86161_GPIO_SAMPLE_TRIGGER 
MAXM86161_GPIO_EXPOSURE_TRIGGER 
MAXM86161_GPIO_HW_FORCE_SYNC 
MAXM86161_GPIO_SAMPLE_SYNC_ONESHOT 

◆ maxm86161_irq_sources

Enumerator
MAXM86161_INT_PWR_RDY 
MAXM86161_INT_DIE_TEMP_RDY 
MAXM86161_INT_LED_COMPB 
MAXM86161_INT_PROX_INT 
MAXM86161_INT_ALC_OVF 
MAXM86161_INT_DATA_RDY 
MAXM86161_INT_A_FULL 
MAXM86161_INT_SHA_DONE 
MAXM86161_INT_COUNT 

◆ maxm86161_led_num

Enumerator
MAXM86161_LED_NUM_GREEN 
MAXM86161_LED_NUM_IR 
MAXM86161_LED_NUM_RED 
MAXM86161_LED_NUM_PILOT_GREEN 

◆ maxm86161_led_range

Enumerator
MAXM86161_LED_RGE_31MA 
MAXM86161_LED_RGE_62MA 
MAXM86161_LED_RGE_93MA 
MAXM86161_LED_RGE_124MA 

◆ maxm86161_led_settling

Enumerator
MAXM86161_LED_SETLNG_4_US 
MAXM86161_LED_SETLNG_6_US 
MAXM86161_LED_SETLNG_8_US 
MAXM86161_LED_SETLNG_12_US 

◆ maxm86161_led_src

Enumerator
MAXM86161_LED_SRC_NONE 
MAXM86161_LED_SRC_GREEN 
MAXM86161_LED_SRC_IR 
MAXM86161_LED_SRC_RED 
MAXM86161_LED_SRC_PILOT_GREEN 
MAXM86161_LED_SRC_DIRECT_AMB 

◆ maxm86161_pd_bias

Enumerator
MAXM86161_PD_BIAS_0_65PF 
MAXM86161_PD_BIAS_65_130PF 
MAXM86161_PD_BIAS_130_260PF 
MAXM86161_PD_BIAS_260_520PF 

◆ maxm86161_pf_iir_init

Enumerator
MAXM86161_PF_IIR_INIT_64 
MAXM86161_PF_IIR_INIT_48 
MAXM86161_PF_IIR_INIT_32 
MAXM86161_PF_IIR_INIT_24 

◆ maxm86161_pf_iir_tc

Enumerator
MAXM86161_PF_IIR_TC_1_64 
MAXM86161_PF_IIR_TC_1_32 
MAXM86161_PF_IIR_TC_1_16 
MAXM86161_PF_IIR_TC_1_8 

◆ maxm86161_pf_threshold_sigma_mult

Enumerator
MAXM86161_PF_TH_GAIN_4 
MAXM86161_PF_TH_GAIN_8 
MAXM86161_PF_TH_GAIN_16 
MAXM86161_PF_TH_GAIN_32 

◆ maxm86161_ppg_tint

Enumerator
MAXM86161_TINT_14_8_US 
MAXM86161_TINT_29_4_US 
MAXM86161_TINT_58_7_US 
MAXM86161_TINT_117_3_US 

◆ maxm86161_smp_ave

Enumerator
MAXM86161_SMP_AVE_1 
MAXM86161_SMP_AVE_2 
MAXM86161_SMP_AVE_4 
MAXM86161_SMP_AVE_8 
MAXM86161_SMP_AVE_16 
MAXM86161_SMP_AVE_32 
MAXM86161_SMP_AVE_64 
MAXM86161_SMP_AVE_128 

Function Documentation

◆ maxm86161_burst_reg_read()

int maxm86161_burst_reg_read ( struct maxm86161_dev * dev,
uint8_t reg_addr,
uint8_t * reg_data,
uint16_t count )

Burst-read multiple bytes starting at a register address.

Parameters
dev- Device descriptor.
reg_addr- Starting register address for the burst read.
reg_data- Buffer where the read bytes are stored.
count- Number of bytes to read.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_burst_reg_write()

int maxm86161_burst_reg_write ( struct maxm86161_dev * dev,
uint8_t reg_addr,
uint8_t * reg_data,
uint16_t count )

Burst-write multiple bytes starting at a register address.

Parameters
dev- Device descriptor.
reg_addr- Starting register address for the burst write.
reg_data- Buffer holding the bytes to write.
count- Number of bytes to write.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_clear_interrupt_status()

int maxm86161_clear_interrupt_status ( struct maxm86161_dev * dev)

Clear pending interrupt status flags.

Reads INT_STATUS_1 and INT_STATUS_2 (which are cleared on read) to acknowledge and clear any pending interrupt flags.

Parameters
dev- Device descriptor.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_decode_fifo_sample()

int maxm86161_decode_fifo_sample ( uint8_t * raw,
uint8_t * tag,
uint32_t * data )

Decode a raw 3-byte FIFO sample into its tag and data fields.

Combines the three raw bytes (big-endian) into a 24-bit value and extracts the sample tag and the measurement data.

Parameters
raw- Pointer to the 3 raw sample bytes.
tag- Pointer where the decoded sample tag is stored.
data- Pointer where the decoded measurement data is stored.
Returns
0 on success, -EINVAL if any pointer is NULL.

◆ maxm86161_fifo_flush()

int maxm86161_fifo_flush ( struct maxm86161_dev * dev)

Flush (clear) the FIFO contents.

Sets the FLUSH bit in FIFO_CFG_2 to discard all currently buffered samples.

Parameters
dev- Device descriptor.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_fifo_overflow_check()

int maxm86161_fifo_overflow_check ( struct maxm86161_dev * dev,
uint8_t * overflow_count )

Read the FIFO overflow counter.

Reads the OVF_COUNTER register and returns the number of samples lost due to FIFO overflow (lower 7 bits).

Parameters
dev- Device descriptor.
overflow_count- Pointer where the overflow sample count is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_force_sync()

int maxm86161_force_sync ( struct maxm86161_dev * dev)

Issue a software-forced PPG synchronization event.

Sets the SW_FORCE bit in the PPG sync control register to trigger a sync.

Parameters
dev- Device descriptor.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_adc_range()

int maxm86161_get_adc_range ( struct maxm86161_dev * dev,
enum maxm86161_adc_range * range )

Get the currently configured PPG ADC full-scale range.

Parameters
dev- Device descriptor.
range- Pointer where the ADC range selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_add_offset()

int maxm86161_get_add_offset ( struct maxm86161_dev * dev,
bool * enable )

Get the current ADC add-offset enable state.

Parameters
dev- Device descriptor.
enable- Pointer set to true if the offset is enabled, false otherwise.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_alc_disable()

int maxm86161_get_alc_disable ( struct maxm86161_dev * dev,
bool * disable )

Get the current Ambient Light Cancellation (ALC) disable state.

Parameters
dev- Device descriptor.
disable- Pointer set to true if ALC is disabled, false otherwise.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_calibration_status()

int maxm86161_get_calibration_status ( struct maxm86161_dev * dev,
bool * complete,
bool * oor )

Query the DAC calibration status.

Reads the DAC calibration register and reports whether calibration has completed and whether the result is out of range.

Parameters
dev- Device descriptor.
complete- Pointer set to true when calibration has completed.
oor- Pointer set to true when the calibration result is out of range.
Returns
0 on success, -EINVAL if any pointer is NULL, or another negative error code on failure.

◆ maxm86161_get_digital_filter()

int maxm86161_get_digital_filter ( struct maxm86161_dev * dev,
enum maxm86161_dig_filt_sel * filter )

Get the currently selected PPG digital filter.

Parameters
dev- Device descriptor.
filter- Pointer where the digital filter selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_fifo_a_full_type()

int maxm86161_get_fifo_a_full_type ( struct maxm86161_dev * dev,
bool * type )

Get the FIFO almost-full interrupt assertion behavior.

Parameters
dev- Device descriptor.
type- Pointer where the almost-full interrupt type is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_fifo_count()

int maxm86161_get_fifo_count ( struct maxm86161_dev * dev,
uint8_t * count )

Get the number of samples currently stored in the FIFO.

Parameters
dev- Device descriptor.
count- Pointer where the FIFO sample count is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_fifo_rollover()

int maxm86161_get_fifo_rollover ( struct maxm86161_dev * dev,
bool * enable )

Get the FIFO roll-over enable state.

Parameters
dev- Device descriptor.
enable- Pointer set to true if roll-over is enabled, false otherwise.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_fifo_watermark()

int maxm86161_get_fifo_watermark ( struct maxm86161_dev * dev,
uint8_t * watermark )

Get the FIFO almost-full watermark threshold.

Parameters
dev- Device descriptor.
watermark- Pointer where the almost-full threshold is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_hires_dac()

int maxm86161_get_hires_dac ( struct maxm86161_dev * dev,
uint8_t slot,
bool * override,
uint8_t * dac_val )

Read back the high-resolution DAC configuration for a slot.

Parameters
dev- Device descriptor.
slot- Sequence slot index (1 to MAXM86161_NUM_LED_SEQ).
override- Pointer set to true if the DAC override is active.
dac_val- Pointer where the 6-bit DAC value is stored.
Returns
0 on success, -EINVAL for an invalid slot, or another negative error code on failure.

◆ maxm86161_get_integration_time()

int maxm86161_get_integration_time ( struct maxm86161_dev * dev,
enum maxm86161_ppg_tint * tint )

Get the currently configured PPG ADC integration time.

Parameters
dev- Device descriptor.
tint- Pointer where the integration time selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_interrupt_status()

int maxm86161_get_interrupt_status ( struct maxm86161_dev * dev,
uint16_t * status )

Read the combined interrupt status of the MAXM86161.

Reads both INT_STATUS_1 and INT_STATUS_2 and packs them into a single 16-bit value (STATUS_2 in the high byte, STATUS_1 in the low byte).

Parameters
dev- Device descriptor.
status- Pointer where the packed interrupt status is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_led_pulse_amplitude()

int maxm86161_get_led_pulse_amplitude ( struct maxm86161_dev * dev,
enum maxm86161_led_num led_num,
uint8_t * amplitude )

Get the pulse amplitude (drive current) of an LED.

Parameters
dev- Device descriptor.
led_num- LED index (1 to MAXM86161_NUM_LEDS).
amplitude- Pointer where the 8-bit pulse amplitude code is stored.
Returns
0 on success, -EINVAL for an invalid LED number, or another negative error code on failure.

◆ maxm86161_get_led_range()

int maxm86161_get_led_range ( struct maxm86161_dev * dev,
enum maxm86161_led_num led_num,
enum maxm86161_led_range * range )

Get the full-scale current range of an LED driver.

Parameters
dev- Device descriptor.
led_num- LED index (1 to MAXM86161_NUM_LEDS).
range- Pointer where the LED current range selection is stored.
Returns
0 on success, -EINVAL for an invalid LED number, or another negative error code on failure.

◆ maxm86161_get_led_sequence()

int maxm86161_get_led_sequence ( struct maxm86161_dev * dev,
uint8_t slot,
enum maxm86161_led_src * src )

Get the LED/measurement source configured for a sequence slot.

Parameters
dev- Device descriptor.
slot- Sequence slot index (0 to MAXM86161_NUM_LED_SEQ - 1).
src- Pointer where the slot's source is stored.
Returns
0 on success, -EINVAL for an invalid slot, or another negative error code on failure.

◆ maxm86161_get_led_settling()

int maxm86161_get_led_settling ( struct maxm86161_dev * dev,
enum maxm86161_led_settling * settling )

Get the currently configured LED settling time.

Parameters
dev- Device descriptor.
settling- Pointer where the LED settling time selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_pd_bias()

int maxm86161_get_pd_bias ( struct maxm86161_dev * dev,
enum maxm86161_pd_bias * bias )

Get the currently configured photodiode bias.

Parameters
dev- Device descriptor.
bias- Pointer where the photodiode bias selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_pf_enable()

int maxm86161_get_pf_enable ( struct maxm86161_dev * dev,
bool * enable )

Get the picket-fence enable state.

Parameters
dev- Device descriptor.
enable- Pointer set to true if picket-fence is enabled, false otherwise.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_pf_iir_init()

int maxm86161_get_pf_iir_init ( struct maxm86161_dev * dev,
enum maxm86161_pf_iir_init * iir_init_value )

Get the picket-fence IIR initialization value.

Parameters
dev- Device descriptor.
iir_init_value- Pointer where the IIR initialization value is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_pf_iir_tc()

int maxm86161_get_pf_iir_tc ( struct maxm86161_dev * dev,
enum maxm86161_pf_iir_tc * iir_tc )

Get the picket-fence IIR time constant.

Parameters
dev- Device descriptor.
iir_tc- Pointer where the IIR time constant selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_pf_order()

int maxm86161_get_pf_order ( struct maxm86161_dev * dev,
bool * order )

Get the picket-fence detect/replace ordering.

Parameters
dev- Device descriptor.
order- Pointer where the ordering selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_pf_threshold_sigma()

int maxm86161_get_pf_threshold_sigma ( struct maxm86161_dev * dev,
enum maxm86161_pf_threshold_sigma_mult * threshold_sigma_mult )

Get the picket-fence threshold sigma multiplier.

Parameters
dev- Device descriptor.
threshold_sigma_mult- Pointer where the threshold sigma multiplier is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_prox_threshold()

int maxm86161_get_prox_threshold ( struct maxm86161_dev * dev,
uint8_t * threshold )

Get the proximity mode entry threshold.

Parameters
dev- Device descriptor.
threshold- Pointer where the proximity threshold value is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_sample_averaging()

int maxm86161_get_sample_averaging ( struct maxm86161_dev * dev,
enum maxm86161_smp_ave * avg )

Get the currently configured sample averaging.

Parameters
dev- Device descriptor.
avg- Pointer where the sample averaging selection is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_get_sample_rate()

int maxm86161_get_sample_rate ( struct maxm86161_dev * dev,
uint8_t * ppg_sr )

Get the currently configured PPG sample rate.

Parameters
dev- Device descriptor.
ppg_sr- Pointer where the sample rate selection code is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_init()

int maxm86161_init ( struct maxm86161_dev ** device,
struct maxm86161_init_param * init_param )

Initialize the MAXM86161 device driver.

Allocates the device descriptor, initializes the I2C Bus, verifies the part ID, resets the device, places it into shutdown, clears the interrupt status and selects single-PPG mode. Optionally configures the INTB GPIO and registers a falling-edge interrupt callback when the corresponding init parameters are supplied. On any failure all acquired resources are released.

Parameters
device- Pointer that receives the allocated device descriptor.
init_param- Initialization parameters.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_irq_handler()

void maxm86161_irq_handler ( void * ctx)

Top-level interrupt dispatcher for the MAXM86161.

Intended to be registered as the GPIO/INTB interrupt callback. Reads the combined interrupt status and, for every asserted source, invokes the registered per-source callback (if any). Does nothing if the context is NULL or the status read fails.

Parameters
ctx- Opaque context, expected to be a struct maxm86161_dev pointer.

◆ maxm86161_memory_read()

int maxm86161_memory_read ( struct maxm86161_dev * dev,
uint16_t addr,
uint8_t * data )

Read a single byte from the device memory.

Selects the memory bank based on the address (bank 1 for addresses above 0xFF), sets the memory index to the low byte of the address and reads the memory data register.

Parameters
dev- Device descriptor.
addr- Memory address to read (valid range 0x000 to 0x17F).
data- Pointer where the read byte is stored.
Returns
0 on success, -EINVAL for invalid arguments or an out-of-range address, or another negative error code on failure.

◆ maxm86161_memory_write()

int maxm86161_memory_write ( struct maxm86161_dev * dev,
uint16_t addr,
uint8_t data )

Write a single byte to the device memory.

Enables memory writes and selects the memory bank based on the address (bank 1 for addresses above 0xFF), sets the memory index to the low byte of the address and writes the memory data register.

Parameters
dev- Device descriptor.
addr- Memory address to write (valid range 0x000 to 0x17F).
data- Byte value to write.
Returns
0 on success, -EINVAL for invalid arguments or an out-of-range address, or another negative error code on failure.

◆ maxm86161_read_die_temperature()

int maxm86161_read_die_temperature ( struct maxm86161_dev * dev,
int32_t * temperature )

Read and convert the die temperature.

Reads the integer and fractional die-temperature registers and combines them into a signed temperature in degrees Celsius (fractional LSB = 0.0625 degC).

Parameters
dev- Device descriptor.
temperature- Pointer where the temperature in micro-degrees Celsius (1 degC = 1000000) is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_read_fifo_data()

int maxm86161_read_fifo_data ( struct maxm86161_dev * dev,
uint8_t * data,
uint16_t num_samples )

Burst-read raw sample data from the FIFO.

Reads num_samples samples from the FIFO_DATA register, each sample being MAXM86161_FIFO_DATA_SIZE bytes wide.

Parameters
dev- Device descriptor.
data- Buffer receiving the raw sample bytes; must hold at least num_samples * MAXM86161_FIFO_DATA_SIZE bytes.
num_samples- Number of samples to read (must be non-zero).
Returns
0 on success, -EINVAL for invalid arguments, or another negative error code on failure.

◆ maxm86161_reg_read()

int maxm86161_reg_read ( struct maxm86161_dev * dev,
uint8_t reg_addr,
uint8_t * reg_data )

Read a single register from the MAXM86161.

Parameters
dev- Device descriptor.
reg_addr- Address of the register to read.
reg_data- Pointer where the read register value is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_reg_update_bits()

int maxm86161_reg_update_bits ( struct maxm86161_dev * dev,
uint8_t reg_addr,
uint8_t mask,
uint8_t data )

Read-modify-write the bits selected by a mask in a register.

Reads the register, clears the bits covered by mask and writes data into that bit field (aligned to the mask) before writing the register back.

Parameters
dev- Device descriptor.
reg_addr- Address of the register to update.
mask- Bit mask selecting the field to modify.
data- New value for the masked field (right-aligned).
Returns
0 on success, negative error code otherwise.

◆ maxm86161_reg_write()

int maxm86161_reg_write ( struct maxm86161_dev * dev,
uint8_t reg_addr,
uint8_t reg_data )

Write a single register on the MAXM86161.

Parameters
dev- Device descriptor.
reg_addr- Address of the register to write.
reg_data- Value to write into the register.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_remove()

int maxm86161_remove ( struct maxm86161_dev * dev)

Free resources allocated by maxm86161_init().

Puts the device into shutdown, disables and unregisters the interrupt callback and removes the IRQ controller (if used), removes the INTB GPIO (if used), tears down the bus backend and frees the device descriptor. The first error encountered while releasing GPIO/bus resources is returned.

Parameters
dev- Device descriptor.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_reset()

int maxm86161_reset ( struct maxm86161_dev * dev)

Perform a software reset of the MAXM86161.

Sets the RESET bit in the system control register and waits for the reset settling delay before returning.

Parameters
dev- Device descriptor.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_adc_range()

int maxm86161_set_adc_range ( struct maxm86161_dev * dev,
enum maxm86161_adc_range range )

Set the PPG ADC full-scale range.

Updates the ADC_RGE field of PPG_CFG_1 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
range- ADC range selection.
Returns
0 on success, -EINVAL for an out-of-range value, or another negative error code on failure.

◆ maxm86161_set_add_offset()

int maxm86161_set_add_offset ( struct maxm86161_dev * dev,
bool enable )

Enable or disable the ADC add-offset feature.

Updates the ADD_OFFSET bit of PPG_CFG_1 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
enable- true to enable the added offset, false to disable it.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_alc_disable()

int maxm86161_set_alc_disable ( struct maxm86161_dev * dev,
bool disable )

Enable or disable the Ambient Light Cancellation (ALC) circuit.

Updates the ALC_DISABLE bit of PPG_CFG_1 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
disable- true to disable ALC, false to enable it.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_burst_enable()

int maxm86161_set_burst_enable ( struct maxm86161_dev * dev,
bool enable )

Enable or disable burst sampling mode and set its rate.

Updates the BURST_EN bit and, on success, the BURST_RATE field of PPG_CFG_3.

Parameters
dev- Device descriptor.
enable- true to enable burst mode, false to disable it.
Returns
0 on success, -EINVAL for a negative error code on failure.

◆ maxm86161_set_burst_mode()

int maxm86161_set_burst_mode ( struct maxm86161_dev * dev,
bool enable,
enum maxm86161_burst_rate rate )

Enable or disable burst sampling mode and set its rate.

Updates the BURST_EN bit and, on success, the BURST_RATE field of PPG_CFG_3.

Parameters
dev- Device descriptor.
enable- true to enable burst mode, false to disable it.
rate- Burst sampling rate selection.
Returns
0 on success, -EINVAL for an out-of-range rate, or another negative error code on failure.

◆ maxm86161_set_burst_rate()

int maxm86161_set_burst_rate ( struct maxm86161_dev * dev,
enum maxm86161_burst_rate rate )

Enable or disable burst sampling mode and set its rate.

Updates the BURST_EN bit and, on success, the BURST_RATE field of PPG_CFG_3.

Parameters
dev- Device descriptor.
rate- Burst sampling rate selection.
Returns
0 on success, -EINVAL for an out-of-range rate, or another negative error code on failure.

◆ maxm86161_set_dac_code_tag()

int maxm86161_set_dac_code_tag ( struct maxm86161_dev * dev,
bool enable )

Enable or disable DAC-code tagging of PPG samples.

Updates the DAC_CODE_TAG bit of the PPG sync control register.

Parameters
dev- Device descriptor.
enable- true to enable DAC-code tagging, false to disable it.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_digital_filter()

int maxm86161_set_digital_filter ( struct maxm86161_dev * dev,
enum maxm86161_dig_filt_sel filter )

Select the PPG digital filter (CDM or FDM).

Updates the DIG_FILT field of PPG_CFG_3 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
filter- Digital filter selection.
Returns
0 on success, -EINVAL for an out-of-range value, or another negative error code on failure.

◆ maxm86161_set_fifo_a_full_type()

int maxm86161_set_fifo_a_full_type ( struct maxm86161_dev * dev,
bool type )

Set the FIFO almost-full interrupt assertion behavior.

Updates the A_FULL_TYPE bit of FIFO_CFG_2 and caches the value in the device configuration, selecting whether the almost-full interrupt is repeated for each new sample or asserted only once.

Parameters
dev- Device descriptor.
type- Almost-full interrupt type selection.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_fifo_rollover()

int maxm86161_set_fifo_rollover ( struct maxm86161_dev * dev,
bool enable )

Enable or disable FIFO roll-over on full.

Updates the FIFO_RO bit of FIFO_CFG_2 and caches the value in the device configuration. When enabled, new samples overwrite the oldest once the FIFO is full.

Parameters
dev- Device descriptor.
enable- true to enable roll-over, false to disable it.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_fifo_stat_clr()

int maxm86161_set_fifo_stat_clr ( struct maxm86161_dev * dev,
bool enable )

Configure whether reading FIFO data clears the status bit.

Updates the STAT_CLR bit of FIFO_CFG_2 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
enable- true to clear the FIFO status on data read, false otherwise.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_fifo_watermark()

int maxm86161_set_fifo_watermark ( struct maxm86161_dev * dev,
uint8_t watermark )

Set the FIFO almost-full watermark threshold.

Updates the A_FULL field of FIFO_CFG_1 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
watermark- Almost-full threshold (valid range 0 to 127).
Returns
0 on success, -EINVAL for an out-of-range value, or another negative error code on failure.

◆ maxm86161_set_gpio_ctrl()

int maxm86161_set_gpio_ctrl ( struct maxm86161_dev * dev,
enum maxm86161_gpio_ctrl ctrl )

Configure the behavior of the GPIO/sync pin.

Updates the GPIO_CTRL field of the PPG sync control register.

Parameters
dev- Device descriptor.
ctrl- GPIO control mode selection.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_hires_dac()

int maxm86161_set_hires_dac ( struct maxm86161_dev * dev,
uint8_t slot,
bool override,
uint8_t dac_val )

Configure the high-resolution DAC override for a sequence slot.

Writes the per-slot HIRES_DAC register, optionally setting the override bit together with the 6-bit DAC value.

Parameters
dev- Device descriptor.
slot- Sequence slot index (1 to MAXM86161_NUM_LED_SEQ).
override- true to force the DAC value, false to use auto-calibration.
dac_val- 6-bit DAC value (only the lower 6 bits are used).
Returns
0 on success, -EINVAL for an invalid slot, or another negative error code on failure.

◆ maxm86161_set_integration_time()

int maxm86161_set_integration_time ( struct maxm86161_dev * dev,
enum maxm86161_ppg_tint tint )

Set the PPG ADC integration time.

Updates the PPG_TINT field of PPG_CFG_1 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
tint- Integration time selection.
Returns
0 on success, -EINVAL for an out-of-range value, or another negative error code on failure.

◆ maxm86161_set_irq_handler()

int maxm86161_set_irq_handler ( struct maxm86161_dev * dev,
enum maxm86161_irq_sources int_source,
bool enable,
maxm86161_int_cb_t callback,
void * cb_args )

Register a callback for an interrupt source and enable/disable it.

Enables or disables the enable bit for the requested interrupt source in the appropriate INT_EN register and stores the callback and its argument in the device's handler table. The PWR_RDY source has no enable bit, so only the callback is registered for it.

Parameters
dev- Device descriptor.
int_source- Interrupt source to configure.
enable- true to enable the interrupt, false to disable it.
callback- Callback invoked when the interrupt fires.
cb_args- Opaque argument passed to the callback.
Returns
0 on success, -EINVAL for an invalid interrupt source, or another negative error code on failure.

◆ maxm86161_set_led_cfg()

int maxm86161_set_led_cfg ( struct maxm86161_dev * dev,
enum maxm86161_led_num led_num,
enum maxm86161_led_range range,
uint8_t led_seq_num,
uint8_t amplitude )

Get the full-scale current range of an LED driver.

Parameters
dev- Device descriptor.
led_num- LED index (1 to MAXM86161_NUM_LEDS).
range- LED current range selection.
led_seq_num- LED/measurement source assigned to the slot.
amplitude- Pointer where the 8-bit pilot pulse amplitude is stored.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_led_pulse_amplitude()

int maxm86161_set_led_pulse_amplitude ( struct maxm86161_dev * dev,
enum maxm86161_led_num led_num,
uint8_t amplitude )

Set the pulse amplitude (drive current) of an LED.

Writes the LEDn_PA register for the selected LED and caches the value in the device descriptor.

Parameters
dev- Device descriptor.
led_num- LED index (1 to MAXM86161_NUM_LEDS).
amplitude- 8-bit pulse amplitude code.
Returns
0 on success, -EINVAL for an invalid LED number, or another negative error code on failure.

◆ maxm86161_set_led_range()

int maxm86161_set_led_range ( struct maxm86161_dev * dev,
enum maxm86161_led_num led_num,
enum maxm86161_led_range range )

Set the full-scale current range of an LED driver.

Selects the appropriate mask in the LED_RANGE_1 register for the given LED, caches the range in the device descriptor and updates the field.

Parameters
dev- Device descriptor.
led_num- LED index (1 to MAXM86161_NUM_LEDS).
range- LED current range selection.
Returns
0 on success, -EINVAL for an invalid LED number or range, or another negative error code on failure.

◆ maxm86161_set_led_sequence()

int maxm86161_set_led_sequence ( struct maxm86161_dev * dev,
uint8_t slot,
enum maxm86161_led_src src )

Set the LED/measurement source for a single sequence slot.

Selects the target LED_SEQ register and nibble (even/odd) based on the slot index, caches the source in the device descriptor and writes the field.

Parameters
dev- Device descriptor.
slot- Sequence slot index (0 to MAXM86161_NUM_LED_SEQ - 1).
src- LED/measurement source assigned to the slot.
Returns
0 on success, -EINVAL for an invalid slot, or another negative error code on failure.

◆ maxm86161_set_led_settling()

int maxm86161_set_led_settling ( struct maxm86161_dev * dev,
enum maxm86161_led_settling settling )

Set the LED settling time.

Updates the LED_SETLNG field of PPG_CFG_3 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
settling- LED settling time selection.
Returns
0 on success, -EINVAL for an out-of-range value, or another negative error code on failure.

◆ maxm86161_set_low_power_mode()

int maxm86161_set_low_power_mode ( struct maxm86161_dev * dev,
bool enable )

Enable or disable low-power mode of the MAXM86161.

Parameters
dev- Device descriptor.
enable- true to enable low-power mode, false to disable it.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_pd_bias()

int maxm86161_set_pd_bias ( struct maxm86161_dev * dev,
enum maxm86161_pd_bias bias )

Set the photodiode bias (based on PD capacitance).

Parameters
dev- Device descriptor.
bias- Photodiode bias selection.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_pf_enable()

int maxm86161_set_pf_enable ( struct maxm86161_dev * dev,
bool enable )

Enable or disable the picket-fence detect-and-replace feature.

Updates the ENABLE bit of the PICKET_FENCE register.

Parameters
dev- Device descriptor.
enable- true to enable picket-fence, false to disable it.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_pf_iir_init()

int maxm86161_set_pf_iir_init ( struct maxm86161_dev * dev,
enum maxm86161_pf_iir_init iir_init_value )

Set the picket-fence IIR initialization value.

Updates the IIR_INIT field of the PICKET_FENCE register.

Parameters
dev- Device descriptor.
iir_init_value- IIR initialization value selection.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_pf_iir_tc()

int maxm86161_set_pf_iir_tc ( struct maxm86161_dev * dev,
enum maxm86161_pf_iir_tc iir_tc )

Set the picket-fence IIR time constant.

Updates the IIR_TC field of the PICKET_FENCE register.

Parameters
dev- Device descriptor.
iir_tc- IIR time constant selection.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_pf_order()

int maxm86161_set_pf_order ( struct maxm86161_dev * dev,
bool order )

Set the picket-fence detect/replace ordering.

Updates the ORDER bit of the PICKET_FENCE register.

Parameters
dev- Device descriptor.
order- Ordering selection (false or true).
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_pf_threshold_sigma()

int maxm86161_set_pf_threshold_sigma ( struct maxm86161_dev * dev,
enum maxm86161_pf_threshold_sigma_mult threshold_sigma_mult )

Set the picket-fence threshold sigma multiplier.

Updates the THRESH_SIGMA field of the PICKET_FENCE register.

Parameters
dev- Device descriptor.
threshold_sigma_mult- Threshold sigma multiplier selection.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_prox_threshold()

int maxm86161_set_prox_threshold ( struct maxm86161_dev * dev,
uint8_t threshold )

Set the proximity mode entry threshold.

Writes the PROX_INT_THRESH register that determines the ADC count at which the device transitions from proximity to normal PPG mode.

Parameters
dev- Device descriptor.
threshold- Proximity interrupt threshold value.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_sample_averaging()

int maxm86161_set_sample_averaging ( struct maxm86161_dev * dev,
enum maxm86161_smp_ave avg )

Set the number of samples averaged per FIFO data point.

Updates the SMP_AVE field of PPG_CFG_2 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
avg- Sample averaging selection.
Returns
0 on success, -EINVAL for an out-of-range value, or another negative error code on failure.

◆ maxm86161_set_sample_rate()

int maxm86161_set_sample_rate ( struct maxm86161_dev * dev,
uint8_t ppg_sr )

Set the PPG sample rate.

Updates the PPG_SR field of PPG_CFG_2 and caches the value in the device configuration.

Parameters
dev- Device descriptor.
ppg_sr- Sample rate selection code (valid range 0x00 to 0x13).
Returns
0 on success, -EINVAL for an out-of-range value, or another negative error code on failure.

◆ maxm86161_set_shutdown()

int maxm86161_set_shutdown ( struct maxm86161_dev * dev,
bool enable )

Enable or disable shutdown mode of the MAXM86161.

Parameters
dev- Device descriptor.
enable- true to enter shutdown, false to resume normal operation.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_set_timestamp_enable()

int maxm86161_set_timestamp_enable ( struct maxm86161_dev * dev,
bool enable )

Enable or disable timestamp tagging of PPG samples.

Updates the TIMESTAMP_EN bit of the PPG sync control register.

Parameters
dev- Device descriptor.
enable- true to enable timestamps, false to disable them.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_sha_enable()

int maxm86161_sha_enable ( struct maxm86161_dev * dev,
bool enable )

Enable or disable the SHA-256 authentication engine.

Updates the SHA_EN bit of the SHA configuration register.

Parameters
dev- Device descriptor.
enable- true to enable the SHA engine, false to disable it.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_sha_read_response()

int maxm86161_sha_read_response ( struct maxm86161_dev * dev,
uint8_t * response,
uint8_t len )

Read the SHA-256 response from the device memory.

Sets the memory index to the SHA memory start and burst-reads the response from the memory data register.

Parameters
dev- Device descriptor.
response- Buffer receiving the response bytes.
len- Number of bytes to read (must be non-zero).
Returns
0 on success, -EINVAL for invalid arguments, or another negative error code on failure.

◆ maxm86161_sha_start()

int maxm86161_sha_start ( struct maxm86161_dev * dev,
uint8_t cmd )

Issue a SHA command and start the SHA-256 operation.

Writes the command to the SHA command register and then sets the SHA_START bit in the SHA configuration register to begin the operation.

Parameters
dev- Device descriptor.
cmd- SHA command code to execute.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_sha_write_challenge()

int maxm86161_sha_write_challenge ( struct maxm86161_dev * dev,
uint8_t * challenge,
uint8_t len )

Write a SHA-256 challenge into the device memory.

Enables memory writes, sets the memory index to the SHA memory start and burst-writes the challenge into the memory data register. The challenge must be exactly 20 bytes (a 160-bit value).

Parameters
dev- Device descriptor.
challenge- Buffer holding the challenge bytes.
len- Length of the challenge in bytes (must be 20).
Returns
0 on success, -EINVAL for invalid arguments or an incorrect length, or another negative error code on failure.

◆ maxm86161_shutdown()

int maxm86161_shutdown ( struct maxm86161_dev * dev)

Put the MAXM86161 into shutdown (power-down) mode.

Convenience wrapper around maxm86161_set_shutdown() that always enables shutdown.

Parameters
dev- Device descriptor.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_start_calibration()

int maxm86161_start_calibration ( struct maxm86161_dev * dev)

Start the DAC (offset) calibration procedure.

Sets the START_CAL bit in the DAC calibration enable register to begin calibration. Completion should be polled via maxm86161_get_calibration_status().

Parameters
dev- Device descriptor.
Returns
0 on success, negative error code otherwise.

◆ maxm86161_verify_id()

int maxm86161_verify_id ( struct maxm86161_dev * dev)

Verify the MAXM86161 part identity and cache revision info.

Reads the part ID register and checks it against the expected value; on mismatch -ENODEV is returned. On success the part ID and revision ID are stored in the device descriptor.

Parameters
dev- Device descriptor.
Returns
0 on success, -ENODEV if the part ID does not match, or another negative error code on communication failure.