![]() |
no-OS
|
Implementation of MAXM86161 optical pulse oximeter driver. More...
#include <stdlib.h>#include <string.h>#include "maxm86161.h"#include "no_os_alloc.h"#include "no_os_delay.h"#include "no_os_error.h"#include "no_os_irq.h"#include "no_os_print_log.h"Functions | |
| 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_verify_id (struct maxm86161_dev *dev) |
| Verify the MAXM86161 part identity and cache revision info. | |
| int | maxm86161_reset (struct maxm86161_dev *dev) |
| Perform a software reset of the MAXM86161. | |
| 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_set_pf_order (struct maxm86161_dev *dev, bool order) |
| Set 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_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_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_enable (struct maxm86161_dev *dev, bool *enable) |
| Get the picket-fence enable state. | |
| int | maxm86161_get_pf_order (struct maxm86161_dev *dev, bool *order) |
| Get the picket-fence detect/replace ordering. | |
| 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_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_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. | |
| int | maxm86161_memory_bank_set (struct maxm86161_dev *dev, bool enable) |
| int | maxm86161_memory_bank_get (struct maxm86161_dev *dev, bool *enable) |
| 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(). | |
Implementation of MAXM86161 optical pulse oximeter driver.
Copyright 2026(c) Analog Devices, Inc.
SPDX-License-Identifier: BSD-3-Clause
| 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.
| 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. |
| 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.
| 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. |
| 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.
| dev | - Device descriptor. |
| 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.
| 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. |
| 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.
| dev | - Device descriptor. |
| 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).
| dev | - Device descriptor. |
| overflow_count | - Pointer where the overflow sample count is stored. |
| 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.
| dev | - Device descriptor. |
| int maxm86161_get_adc_range | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_adc_range * | range ) |
Get the currently configured PPG ADC full-scale range.
| dev | - Device descriptor. |
| range | - Pointer where the ADC range selection is stored. |
| int maxm86161_get_add_offset | ( | struct maxm86161_dev * | dev, |
| bool * | enable ) |
Get the current ADC add-offset enable state.
| dev | - Device descriptor. |
| enable | - Pointer set to true if the offset is enabled, false otherwise. |
| int maxm86161_get_alc_disable | ( | struct maxm86161_dev * | dev, |
| bool * | disable ) |
Get the current Ambient Light Cancellation (ALC) disable state.
| dev | - Device descriptor. |
| disable | - Pointer set to true if ALC is disabled, false otherwise. |
| 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.
| 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. |
| int maxm86161_get_digital_filter | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_dig_filt_sel * | filter ) |
Get the currently selected PPG digital filter.
| dev | - Device descriptor. |
| filter | - Pointer where the digital filter selection is stored. |
| int maxm86161_get_fifo_a_full_type | ( | struct maxm86161_dev * | dev, |
| bool * | type ) |
Get the FIFO almost-full interrupt assertion behavior.
| dev | - Device descriptor. |
| type | - Pointer where the almost-full interrupt type is stored. |
| int maxm86161_get_fifo_count | ( | struct maxm86161_dev * | dev, |
| uint8_t * | count ) |
Get the number of samples currently stored in the FIFO.
| dev | - Device descriptor. |
| count | - Pointer where the FIFO sample count is stored. |
| int maxm86161_get_fifo_rollover | ( | struct maxm86161_dev * | dev, |
| bool * | enable ) |
Get the FIFO roll-over enable state.
| dev | - Device descriptor. |
| enable | - Pointer set to true if roll-over is enabled, false otherwise. |
| int maxm86161_get_fifo_watermark | ( | struct maxm86161_dev * | dev, |
| uint8_t * | watermark ) |
Get the FIFO almost-full watermark threshold.
| dev | - Device descriptor. |
| watermark | - Pointer where the almost-full threshold is stored. |
| 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.
| 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. |
| int maxm86161_get_integration_time | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_ppg_tint * | tint ) |
Get the currently configured PPG ADC integration time.
| dev | - Device descriptor. |
| tint | - Pointer where the integration time selection is stored. |
| 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).
| dev | - Device descriptor. |
| status | - Pointer where the packed interrupt status is stored. |
| 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.
| dev | - Device descriptor. |
| led_num | - LED index (1 to MAXM86161_NUM_LEDS). |
| amplitude | - Pointer where the 8-bit pulse amplitude code is stored. |
| 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.
| dev | - Device descriptor. |
| led_num | - LED index (1 to MAXM86161_NUM_LEDS). |
| range | - Pointer where the LED current range selection is stored. |
| 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.
| dev | - Device descriptor. |
| slot | - Sequence slot index (0 to MAXM86161_NUM_LED_SEQ - 1). |
| src | - Pointer where the slot's source is stored. |
| int maxm86161_get_led_settling | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_led_settling * | settling ) |
Get the currently configured LED settling time.
| dev | - Device descriptor. |
| settling | - Pointer where the LED settling time selection is stored. |
| int maxm86161_get_pd_bias | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_pd_bias * | bias ) |
Get the currently configured photodiode bias.
| dev | - Device descriptor. |
| bias | - Pointer where the photodiode bias selection is stored. |
| int maxm86161_get_pf_enable | ( | struct maxm86161_dev * | dev, |
| bool * | enable ) |
Get the picket-fence enable state.
| dev | - Device descriptor. |
| enable | - Pointer set to true if picket-fence is enabled, false otherwise. |
| 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.
| dev | - Device descriptor. |
| iir_init_value | - Pointer where the IIR initialization value is stored. |
| int maxm86161_get_pf_iir_tc | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_pf_iir_tc * | iir_tc ) |
Get the picket-fence IIR time constant.
| dev | - Device descriptor. |
| iir_tc | - Pointer where the IIR time constant selection is stored. |
| int maxm86161_get_pf_order | ( | struct maxm86161_dev * | dev, |
| bool * | order ) |
Get the picket-fence detect/replace ordering.
| dev | - Device descriptor. |
| order | - Pointer where the ordering selection is stored. |
| 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.
| dev | - Device descriptor. |
| threshold_sigma_mult | - Pointer where the threshold sigma multiplier is stored. |
| int maxm86161_get_prox_threshold | ( | struct maxm86161_dev * | dev, |
| uint8_t * | threshold ) |
Get the proximity mode entry threshold.
| dev | - Device descriptor. |
| threshold | - Pointer where the proximity threshold value is stored. |
| int maxm86161_get_sample_averaging | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_smp_ave * | avg ) |
Get the currently configured sample averaging.
| dev | - Device descriptor. |
| avg | - Pointer where the sample averaging selection is stored. |
| int maxm86161_get_sample_rate | ( | struct maxm86161_dev * | dev, |
| uint8_t * | ppg_sr ) |
Get the currently configured PPG sample rate.
| dev | - Device descriptor. |
| ppg_sr | - Pointer where the sample rate selection code is stored. |
| 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.
| device | - Pointer that receives the allocated device descriptor. |
| init_param | - Initialization parameters. |
| 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.
| ctx | - Opaque context, expected to be a struct maxm86161_dev pointer. |
| int maxm86161_memory_bank_get | ( | struct maxm86161_dev * | dev, |
| bool * | enable ) |
| int maxm86161_memory_bank_set | ( | struct maxm86161_dev * | dev, |
| bool | enable ) |
| 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.
| dev | - Device descriptor. |
| addr | - Memory address to read (valid range 0x000 to 0x17F). |
| data | - Pointer where the read byte is stored. |
| 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.
| dev | - Device descriptor. |
| addr | - Memory address to write (valid range 0x000 to 0x17F). |
| data | - Byte value to write. |
| 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).
| dev | - Device descriptor. |
| temperature | - Pointer where the temperature in micro-degrees Celsius (1 degC = 1000000) is stored. |
| 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.
| 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). |
| int maxm86161_reg_read | ( | struct maxm86161_dev * | dev, |
| uint8_t | reg_addr, | ||
| uint8_t * | reg_data ) |
Read a single register from the MAXM86161.
| dev | - Device descriptor. |
| reg_addr | - Address of the register to read. |
| reg_data | - Pointer where the read register value is stored. |
| 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.
| 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). |
| int maxm86161_reg_write | ( | struct maxm86161_dev * | dev, |
| uint8_t | reg_addr, | ||
| uint8_t | reg_data ) |
Write a single register on the MAXM86161.
| dev | - Device descriptor. |
| reg_addr | - Address of the register to write. |
| reg_data | - Value to write into the register. |
| 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.
| dev | - Device descriptor. |
| 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.
| dev | - Device descriptor. |
| 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.
| dev | - Device descriptor. |
| range | - ADC range selection. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable the added offset, false to disable it. |
| 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.
| dev | - Device descriptor. |
| disable | - true to disable ALC, false to enable it. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable burst mode, false to disable it. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable burst mode, false to disable it. |
| rate | - Burst sampling rate selection. |
| 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.
| dev | - Device descriptor. |
| rate | - Burst sampling rate selection. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable DAC-code tagging, false to disable it. |
| 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.
| dev | - Device descriptor. |
| filter | - Digital filter selection. |
| 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.
| dev | - Device descriptor. |
| type | - Almost-full interrupt type selection. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable roll-over, false to disable it. |
| 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.
| dev | - Device descriptor. |
| enable | - true to clear the FIFO status on data read, false otherwise. |
| 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.
| dev | - Device descriptor. |
| watermark | - Almost-full threshold (valid range 0 to 127). |
| 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.
| dev | - Device descriptor. |
| ctrl | - GPIO control mode selection. |
| 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.
| 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). |
| 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.
| dev | - Device descriptor. |
| tint | - Integration time selection. |
| 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.
| 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. |
| 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.
| 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. |
| 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.
| dev | - Device descriptor. |
| led_num | - LED index (1 to MAXM86161_NUM_LEDS). |
| amplitude | - 8-bit pulse amplitude code. |
| 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.
| dev | - Device descriptor. |
| led_num | - LED index (1 to MAXM86161_NUM_LEDS). |
| range | - LED current range selection. |
| 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.
| dev | - Device descriptor. |
| slot | - Sequence slot index (0 to MAXM86161_NUM_LED_SEQ - 1). |
| src | - LED/measurement source assigned to the slot. |
| 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.
| dev | - Device descriptor. |
| settling | - LED settling time selection. |
| int maxm86161_set_low_power_mode | ( | struct maxm86161_dev * | dev, |
| bool | enable ) |
Enable or disable low-power mode of the MAXM86161.
| dev | - Device descriptor. |
| enable | - true to enable low-power mode, false to disable it. |
| int maxm86161_set_pd_bias | ( | struct maxm86161_dev * | dev, |
| enum maxm86161_pd_bias | bias ) |
Set the photodiode bias (based on PD capacitance).
| dev | - Device descriptor. |
| bias | - Photodiode bias selection. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable picket-fence, false to disable it. |
| 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.
| dev | - Device descriptor. |
| iir_init_value | - IIR initialization value selection. |
| 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.
| dev | - Device descriptor. |
| iir_tc | - IIR time constant selection. |
| 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.
| dev | - Device descriptor. |
| order | - Ordering selection (false or true). |
| 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.
| dev | - Device descriptor. |
| threshold_sigma_mult | - Threshold sigma multiplier selection. |
| 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.
| dev | - Device descriptor. |
| threshold | - Proximity interrupt threshold value. |
| 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.
| dev | - Device descriptor. |
| avg | - Sample averaging selection. |
| 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.
| dev | - Device descriptor. |
| ppg_sr | - Sample rate selection code (valid range 0x00 to 0x13). |
| int maxm86161_set_shutdown | ( | struct maxm86161_dev * | dev, |
| bool | enable ) |
Enable or disable shutdown mode of the MAXM86161.
| dev | - Device descriptor. |
| enable | - true to enter shutdown, false to resume normal operation. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable timestamps, false to disable them. |
| 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.
| dev | - Device descriptor. |
| enable | - true to enable the SHA engine, false to disable it. |
| 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.
| dev | - Device descriptor. |
| response | - Buffer receiving the response bytes. |
| len | - Number of bytes to read (must be non-zero). |
| 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.
| dev | - Device descriptor. |
| cmd | - SHA command code to execute. |
| 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).
| dev | - Device descriptor. |
| challenge | - Buffer holding the challenge bytes. |
| len | - Length of the challenge in bytes (must be 20). |
| 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.
| dev | - Device descriptor. |
| 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().
| dev | - Device descriptor. |
| 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.
| dev | - Device descriptor. |