no-OS
Loading...
Searching...
No Matches
max30009.c File Reference

Implementation of MAX30009 driver. More...

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "max30009.h"
#include "no_os_alloc.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_print_log.h"
Include dependency graph for max30009.c:

Macros

#define MAX30009_SPI_READ   0x80
 
#define MAX30009_SPI_WRITE   0x00
 

Functions

int max30009_reg_read_multiple (struct max30009_dev *device, uint8_t reg_addr, uint8_t *data, uint32_t len)
 Read multiple bytes from register.
 
int max30009_reg_read (struct max30009_dev *device, uint8_t reg_addr, uint8_t *data)
 Read a single byte from register.
 
int max30009_reg_write_multiple (struct max30009_dev *device, uint8_t reg_addr, uint8_t *data, uint32_t len)
 Write multiple bytes to register.
 
int max30009_reg_write (struct max30009_dev *device, uint8_t reg_addr, uint8_t data)
 Write a single byte to register.
 
int max30009_reg_update (struct max30009_dev *device, uint8_t reg_addr, uint8_t mask, uint8_t value)
 Update specific bits in a register.
 
int max30009_soft_reset (struct max30009_dev *device)
 Perform software reset.
 
int max30009_verify_part_id (struct max30009_dev *device)
 Read device part ID.
 
int max30009_set_power_mode (struct max30009_dev *device, bool shutdown)
 Set power mode (shutdown or active)
 
int max30009_init (struct max30009_dev **device, struct max30009_init_param *init_param)
 Initialize the MAX30009 device.
 
int max30009_remove (struct max30009_dev *device)
 Remove the MAX30009 device and free resources.
 
int max30009_get_status (struct max30009_dev *device, struct max30009_status *status)
 Get device status.
 
int max30009_check_lead_off (struct max30009_dev *device, bool *leads_on)
 Check lead-off detection status.
 
int max30009_fifo_flush (struct max30009_dev *device)
 Flush FIFO contents.
 
int max30009_fifo_get_count (struct max30009_dev *device, uint16_t *count)
 Get FIFO data count.
 
int max30009_fifo_get_ovf_count (struct max30009_dev *device, uint16_t *count)
 Get FIFO overflow data count.
 
int max30009_read_fifo_data (struct max30009_dev *device, uint8_t *data, uint32_t len)
 Read data from FIFO.
 
int max30009_fifo_decode_sample (uint8_t *raw_data, struct max30009_fifo_sample *sample)
 Decode a 3-byte FIFO sample into type and data.
 
int max30009_get_fifo_pointers (struct max30009_dev *device, uint8_t *write_ptr, uint8_t *read_ptr)
 Get FIFO read and write pointers.
 
int max30009_set_fifo_watermark (struct max30009_dev *device, uint8_t watermark)
 Set FIFO watermark level.
 
int max30009_get_fifo_watermark (struct max30009_dev *device, uint8_t *watermark)
 Gets the FIFO watermark level of the device.
 
int max30009_set_fifo_rollover (struct max30009_dev *device, bool rollover)
 Set FIFO rollover mode.
 
int max30009_set_a_full_type (struct max30009_dev *device, bool type)
 Set almost-full interrupt type.
 
int max30009_insert_fifo_marker (struct max30009_dev *device)
 Insert marker into FIFO data stream.
 
int max30009_clear_fifo_status (struct max30009_dev *device)
 Clear FIFO status flags.
 
int max30009_timing_system_reset (struct max30009_dev *device)
 Trigger timing system reset for PLL synchronization.
 
int max30009_set_master_mode (struct max30009_dev *device, bool is_master)
 Set master/slave mode for PLL synchronization.
 
int max30009_configure_int_pin (struct max30009_dev *device, uint8_t func_cfg, uint8_t out_cfg)
 Configure INT pin function and output.
 
int max30009_configure_trig_pin (struct max30009_dev *device, uint8_t input_cfg, uint8_t output_cfg)
 Configure TRIG pin input and output.
 
int max30009_configure_i2c_broadcast (struct max30009_dev *device, bool enable, uint8_t broadcast_addr)
 Configure I2C broadcast address.
 
int max30009_disable_i2c (struct max30009_dev *device)
 Disable I2C interface (SPI only mode)
 
int max30009_pll_set_dividers (struct max30009_dev *device, uint16_t mdiv, enum max30009_pll_ndiv ndiv, enum max30009_pll_kdiv kdiv)
 Configure PLL dividers.
 
int max30009_pll_enable (struct max30009_dev *device, bool enable)
 Enable or disable PLL.
 
int max30009_pll_set_lock_window (struct max30009_dev *device, bool lock_window)
 Set PLL lock window.
 
int max30009_set_clock_source (struct max30009_dev *device, bool use_external, bool use_32768_hz)
 Configure clock source.
 
int max30009_clock_fine_tune (struct max30009_dev *device, uint8_t tune_val)
 Fine tune internal clock frequency.
 
int max30009_bioz_enable (struct max30009_dev *device, bool enable)
 Enable or disable BioZ measurement.
 
int max30009_bioz_i_enable (struct max30009_dev *device, bool enable)
 Enable or disable BioZ I channel.
 
int max30009_bioz_q_enable (struct max30009_dev *device, bool enable)
 Enable or disable BioZ Q channel.
 
int max30009_bioz_bg_enable (struct max30009_dev *device, bool enable)
 Enable or disable BioZ bandgap.
 
int max30009_set_dac_osr (struct max30009_dev *device, enum max30009_dac_osr osr)
 Set DAC oversampling ratio.
 
int max30009_set_adc_osr (struct max30009_dev *device, enum max30009_adc_osr osr)
 Set ADC oversampling ratio.
 
int max30009_set_digital_hpf (struct max30009_dev *device, enum max30009_dhpf dhpf)
 Set digital high-pass filter.
 
int max30009_set_digital_lpf (struct max30009_dev *device, enum max30009_dlpf dlpf)
 Set digital low-pass filter.
 
int max30009_set_analog_hpf (struct max30009_dev *device, enum max30009_ahpf ahpf)
 Set analog high-pass filter.
 
int max30009_set_drive_mode (struct max30009_dev *device, enum max30009_drive_mode mode)
 Set drive mode (current, voltage, H-bridge, or standby)
 
int max30009_set_drive_current_detailed (struct max30009_dev *device, uint8_t idrv_range, uint8_t vdrv_mag)
 Set drive current with detailed control.
 
int max30009_enable_external_resistor (struct max30009_dev *device, bool enable)
 Enable or disable external resistor for current drive.
 
int max30009_enable_rapid_lead_off (struct max30009_dev *device, bool enable)
 Enable or disable rapid lead-off detection.
 
int max30009_enable_fast_start (struct max30009_dev *device, bool enable, bool manual)
 Enable or disable fast start mode.
 
int max30009_set_ina_mode (struct max30009_dev *device, bool low_power)
 Set INA (Instrumentation Amplifier) mode.
 
int max30009_disable_differential_mode (struct max30009_dev *device, bool disable)
 Disable differential mode (enable single-ended)
 
int max30009_set_amp_range (struct max30009_dev *device, uint8_t amp_range)
 Set amplifier range.
 
int max30009_set_amp_bandwidth (struct max30009_dev *device, uint8_t amp_bw)
 Set amplifier bandwidth.
 
int max30009_enable_external_cap (struct max30009_dev *device, bool enable)
 Enable or disable external capacitor.
 
int max30009_enable_dc_restore (struct max30009_dev *device, bool enable)
 Enable or disable DC restore circuit.
 
int max30009_enable_drive_reset (struct max30009_dev *device, bool enable)
 Enable or disable drive reset.
 
int max30009_enable_dac_reset (struct max30009_dev *device, bool enable)
 Enable or disable DAC reset.
 
int max30009_set_comparison_mode (struct max30009_dev *device, uint8_t cmp_mode)
 Set comparison mode for threshold detection.
 
int max30009_enable_bioz_threshold (struct max30009_dev *device, bool enable)
 Enable or disable BioZ threshold detection.
 
int max30009_set_bioz_thresholds (struct max30009_dev *device, uint8_t low_thresh, uint8_t high_thresh)
 Set BioZ threshold values.
 
int max30009_set_demod_clk_phases (struct max30009_dev *device, bool i_clk_phase, bool q_clk_phase)
 Set demodulation clock phases.
 
int max30009_enable_ina_chopping (struct max30009_dev *device, bool enable)
 Enable or disable INA chopping.
 
int max30009_set_channel_freq_select (struct max30009_dev *device, bool fsel)
 Set channel frequency select.
 
int max30009_enable_standby_mode (struct max30009_dev *device, bool keep_rx_on)
 Enable or disable standby mode.
 
int max30009_enable_calibration (struct max30009_dev *device, bool enable)
 Enable or disable calibration mode.
 
int max30009_enable_calibration_mux (struct max30009_dev *device, bool enable)
 Enable or disable calibration MUX.
 
int max30009_calibration_connect_only (struct max30009_dev *device, bool cal_only)
 Set calibration connect-only mode.
 
int max30009_set_bia_load_resistor (struct max30009_dev *device, enum max30009_bia_rsel rsel)
 Set BIA (Body Impedance Analysis) load resistor.
 
int max30009_enable_bia_bist (struct max30009_dev *device, bool enable)
 Enable or disable BIA BIST (Built-In Self Test)
 
int max30009_set_gsr_load_resistor (struct max30009_dev *device, enum max30009_gsr_rsel rsel)
 Set GSR (Galvanic Skin Response) load resistor.
 
int max30009_enable_gsr_load (struct max30009_dev *device, bool enable)
 Enable or disable GSR load resistor.
 
int max30009_enable_internal_load (struct max30009_dev *device, bool enable)
 Enable or disable internal load resistor.
 
int max30009_enable_external_load (struct max30009_dev *device, bool enable)
 Enable or disable external load connection.
 
int max30009_assign_electrodes (struct max30009_dev *device, uint8_t bip_assign, uint8_t bin_assign, uint8_t drvp_assign, uint8_t drvn_assign)
 Assign electrodes to measurement channels.
 
int max30009_read_bist_error (struct max30009_dev *device, uint8_t *error)
 Read BIST error value.
 
int max30009_lead_off_config (struct max30009_dev *device, bool enable, uint8_t threshold)
 Configure lead-off detection.
 
int max30009_set_lead_off_current (struct max30009_dev *device, enum max30009_loff_current current)
 Set lead-off detection current magnitude.
 
int max30009_set_lead_off_polarity (struct max30009_dev *device, bool positive)
 Set lead-off detection current polarity.
 
int max30009_enable_external_lead_off (struct max30009_dev *device, bool enable)
 Enable or disable external lead-off detection.
 
int max30009_enable_drive_oor_detect (struct max30009_dev *device, bool enable)
 Enable or disable drive out-of-range detection.
 
int max30009_enable_ultra_low_power_lead_on (struct max30009_dev *device, bool enable)
 Enable or disable ultra-low-power lead-on detection.
 
int max30009_get_detailed_lead_status (struct max30009_dev *device, struct max30009_lead_status *status)
 Get detailed lead detection status.
 
int max30009_set_lead_bias (struct max30009_dev *device, enum max30009_rbias_val rbias_value, bool enable_bip, bool enable_bin)
 Configure lead bias resistor and enable for receive electrodes.
 
int max30009_set_pll_config (struct max30009_dev *device, struct max30009_pll_config *pll_config)
 Set complete PLL configuration.
 
int max30009_get_pll_config (struct max30009_dev *device, struct max30009_pll_config *pll_config)
 Get complete PLL configuration.
 
int max30009_set_fifo_config (struct max30009_dev *device, struct max30009_fifo_config *fifo_config)
 Set complete FIFO configuration.
 
int max30009_get_fifo_config (struct max30009_dev *device, struct max30009_fifo_config *fifo_config)
 Get complete FIFO configuration.
 
int max30009_set_bioz_config (struct max30009_dev *device, struct max30009_bioz_config *bioz_config)
 Set complete BioZ configuration.
 
int max30009_get_bioz_config (struct max30009_dev *device, struct max30009_bioz_config *bioz_config)
 Get complete BioZ configuration.
 
int max30009_set_bioz_mux_config (struct max30009_dev *device, struct max30009_bioz_mux_config *mux_config)
 Set complete BioZ MUX configuration.
 
int max30009_get_bioz_mux_config (struct max30009_dev *device, struct max30009_bioz_mux_config *mux_config)
 Get complete BioZ MUX configuration.
 
int max30009_set_lead_detect_config (struct max30009_dev *device, struct max30009_lead_detect_config *lead_config)
 Set complete lead detection configuration.
 
int max30009_get_lead_detect_config (struct max30009_dev *device, struct max30009_lead_detect_config *lead_config)
 Get complete lead detection configuration.
 
int max30009_interrupt_config (struct max30009_dev *device, uint8_t int1_mask, uint8_t int2_mask)
 Configure interrupt enables.
 
int max30009_enable_interrupt (struct max30009_dev *device, enum max30009_interrupt interrupt, bool enable)
 Enable or disable a specific interrupt.
 
int max30009_clear_status (struct max30009_dev *device)
 Clear interrupt status registers.
 

Detailed Description

Implementation of MAX30009 driver.

Author
Edelweise Escala (edelw.nosp@m.eise.nosp@m..esca.nosp@m.la@a.nosp@m.nalog.nosp@m..com)

Copyright 2026(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ MAX30009_SPI_READ

#define MAX30009_SPI_READ   0x80

◆ MAX30009_SPI_WRITE

#define MAX30009_SPI_WRITE   0x00

Function Documentation

◆ max30009_assign_electrodes()

int max30009_assign_electrodes ( struct max30009_dev * device,
uint8_t bip_assign,
uint8_t bin_assign,
uint8_t drvp_assign,
uint8_t drvn_assign )

Assign electrodes to measurement channels.

Parameters
device- Device descriptor
bip_assign- BIP (positive receive) electrode assignment
bin_assign- BIN (negative receive) electrode assignment
drvp_assign- DRVP (positive drive) electrode assignment
drvn_assign- DRVN (negative drive) electrode assignment
Returns
0 in case of success, negative error code otherwise

◆ max30009_bioz_bg_enable()

int max30009_bioz_bg_enable ( struct max30009_dev * device,
bool enable )

Enable or disable BioZ bandgap.

Parameters
device- MAX30009 device descriptor
enable- True to enable bandgap, false to disable
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_bioz_enable()

int max30009_bioz_enable ( struct max30009_dev * device,
bool enable )

Enable or disable BioZ measurement.

Parameters
device- MAX30009 device descriptor
enable- True to enable BioZ, false to disable
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_bioz_i_enable()

int max30009_bioz_i_enable ( struct max30009_dev * device,
bool enable )

Enable or disable BioZ I channel.

Parameters
device- MAX30009 device descriptor
enable- True to enable I channel, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_bioz_q_enable()

int max30009_bioz_q_enable ( struct max30009_dev * device,
bool enable )

Enable or disable BioZ Q channel.

Parameters
device- MAX30009 device descriptor
enable- True to enable Q channel, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_calibration_connect_only()

int max30009_calibration_connect_only ( struct max30009_dev * device,
bool cal_only )

Set calibration connect-only mode.

Parameters
device- Device descriptor
cal_only- True for connect-only mode, false for normal
Returns
0 in case of success, negative error code otherwise

◆ max30009_check_lead_off()

int max30009_check_lead_off ( struct max30009_dev * device,
bool * leads_on )

Check lead-off detection status.

Parameters
device- MAX30009 device descriptor
leads_on- True if leads connected
Returns
0 in case of success, negative error code otherwise

◆ max30009_clear_fifo_status()

int max30009_clear_fifo_status ( struct max30009_dev * device)

Clear FIFO status flags.

Parameters
device- Device descriptor
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_clear_status()

int max30009_clear_status ( struct max30009_dev * device)

Clear interrupt status registers.

Parameters
device- MAX30009 device descriptor
Returns
0 in case of success, negative error code otherwise
Note
Reading the status registers clears them
Here is the caller graph for this function:

◆ max30009_clock_fine_tune()

int max30009_clock_fine_tune ( struct max30009_dev * device,
uint8_t tune_val )

Fine tune internal clock frequency.

Parameters
device- Device descriptor
tune_val- Fine tune value (0-31, ±0.78% adjustment range)
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_configure_i2c_broadcast()

int max30009_configure_i2c_broadcast ( struct max30009_dev * device,
bool enable,
uint8_t broadcast_addr )

Configure I2C broadcast address.

Parameters
device- Device descriptor
enable- True to enable broadcast, false to disable
broadcast_addr- Broadcast address (7-bit, shifted left by 1)
Returns
0 in case of success, negative error code otherwise
Note
Allows multiple devices to respond to broadcast address

◆ max30009_configure_int_pin()

int max30009_configure_int_pin ( struct max30009_dev * device,
uint8_t func_cfg,
uint8_t out_cfg )

Configure INT pin function and output.

Parameters
device- Device descriptor
func_cfg- Function configuration (0-3)
out_cfg- Output configuration (0-3)
Returns
0 in case of success, negative error code otherwise

◆ max30009_configure_trig_pin()

int max30009_configure_trig_pin ( struct max30009_dev * device,
uint8_t input_cfg,
uint8_t output_cfg )

Configure TRIG pin input and output.

Parameters
device- Device descriptor
input_cfg- Input configuration (0 or 1)
output_cfg- Output configuration (0-3)
Returns
0 in case of success, negative error code otherwise

◆ max30009_disable_differential_mode()

int max30009_disable_differential_mode ( struct max30009_dev * device,
bool disable )

Disable differential mode (enable single-ended)

Parameters
device- Device descriptor
disable- True to disable differential mode, false for differential
Returns
0 in case of success, negative error code otherwise

◆ max30009_disable_i2c()

int max30009_disable_i2c ( struct max30009_dev * device)

Disable I2C interface (SPI only mode)

Parameters
device- Device descriptor
Returns
0 in case of success, negative error code otherwise
Note
After disabling I2C, device only responds to SPI

◆ max30009_enable_bia_bist()

int max30009_enable_bia_bist ( struct max30009_dev * device,
bool enable )

Enable or disable BIA BIST (Built-In Self Test)

Parameters
device- Device descriptor
enable- True to enable BIST, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_bioz_threshold()

int max30009_enable_bioz_threshold ( struct max30009_dev * device,
bool enable )

Enable or disable BioZ threshold detection.

Parameters
device- Device descriptor
enable- True to enable threshold detection, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_calibration()

int max30009_enable_calibration ( struct max30009_dev * device,
bool enable )

Enable or disable calibration mode.

Parameters
device- Device descriptor
enable- True to enable calibration, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_calibration_mux()

int max30009_enable_calibration_mux ( struct max30009_dev * device,
bool enable )

Enable or disable calibration MUX.

Parameters
device- Device descriptor
enable- True to enable calibration MUX, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_dac_reset()

int max30009_enable_dac_reset ( struct max30009_dev * device,
bool enable )

Enable or disable DAC reset.

Parameters
device- Device descriptor
enable- True to enable DAC reset, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_dc_restore()

int max30009_enable_dc_restore ( struct max30009_dev * device,
bool enable )

Enable or disable DC restore circuit.

Parameters
device- Device descriptor
enable- True to enable DC restore, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_drive_oor_detect()

int max30009_enable_drive_oor_detect ( struct max30009_dev * device,
bool enable )

Enable or disable drive out-of-range detection.

Parameters
device- Device descriptor
enable- True to enable drive OOR detection, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_drive_reset()

int max30009_enable_drive_reset ( struct max30009_dev * device,
bool enable )

Enable or disable drive reset.

Parameters
device- Device descriptor
enable- True to enable drive reset, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_external_cap()

int max30009_enable_external_cap ( struct max30009_dev * device,
bool enable )

Enable or disable external capacitor.

Parameters
device- Device descriptor
enable- True to enable external capacitor, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_external_lead_off()

int max30009_enable_external_lead_off ( struct max30009_dev * device,
bool enable )

Enable or disable external lead-off detection.

Parameters
device- Device descriptor
enable- True to enable external lead-off detection, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_external_load()

int max30009_enable_external_load ( struct max30009_dev * device,
bool enable )

Enable or disable external load connection.

Parameters
device- Device descriptor
enable- True to enable external load connection, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_external_resistor()

int max30009_enable_external_resistor ( struct max30009_dev * device,
bool enable )

Enable or disable external resistor for current drive.

Parameters
device- Device descriptor
enable- True to enable external resistor, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_fast_start()

int max30009_enable_fast_start ( struct max30009_dev * device,
bool enable,
bool manual )

Enable or disable fast start mode.

Parameters
device- Device descriptor
enable- True to enable fast start, false to disable
manual- True for manual trigger, false for automatic
Returns
0 in case of success, negative error code otherwise
Note
Fast start reduces settling time for faster measurements

◆ max30009_enable_gsr_load()

int max30009_enable_gsr_load ( struct max30009_dev * device,
bool enable )

Enable or disable GSR load resistor.

Parameters
device- Device descriptor
enable- True to enable GSR load, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_ina_chopping()

int max30009_enable_ina_chopping ( struct max30009_dev * device,
bool enable )

Enable or disable INA chopping.

Parameters
device- Device descriptor
enable- True to enable chopping (improves CMRR), false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_internal_load()

int max30009_enable_internal_load ( struct max30009_dev * device,
bool enable )

Enable or disable internal load resistor.

Parameters
device- Device descriptor
enable- True to enable internal load, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_enable_interrupt()

int max30009_enable_interrupt ( struct max30009_dev * device,
enum max30009_interrupt interrupt,
bool enable )

Enable or disable a specific interrupt.

Parameters
device- MAX30009 device descriptor
interrupt- Interrupt type from max30009_interrupt enum
enable- True to enable, false to disable
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_enable_rapid_lead_off()

int max30009_enable_rapid_lead_off ( struct max30009_dev * device,
bool enable )

Enable or disable rapid lead-off detection.

Parameters
device- Device descriptor
enable- True to enable rapid mode, false for normal
Returns
0 in case of success, negative error code otherwise
Note
Rapid mode detects lead-off faster but with higher current consumption

◆ max30009_enable_standby_mode()

int max30009_enable_standby_mode ( struct max30009_dev * device,
bool keep_rx_on )

Enable or disable standby mode.

Parameters
device- Device descriptor
keep_rx_on- True to keep receive path on in standby, false to power down completely
Returns
0 in case of success, negative error code otherwise
Note
Standby mode reduces power consumption while maintaining quick wake-up

◆ max30009_enable_ultra_low_power_lead_on()

int max30009_enable_ultra_low_power_lead_on ( struct max30009_dev * device,
bool enable )

Enable or disable ultra-low-power lead-on detection.

Parameters
device- Device descriptor
enable- True to enable ULP lead-on detection, false to disable
Returns
0 in case of success, negative error code otherwise

◆ max30009_fifo_decode_sample()

int max30009_fifo_decode_sample ( uint8_t * raw_data,
struct max30009_fifo_sample * sample )

Decode a 3-byte FIFO sample into type and data.

Parameters
raw_data- 3-byte raw FIFO data
sample- Pointer to store decoded sample (type and data)
Returns
0 in case of success, negative error code otherwise

FIFO Data Format (24 bits total):

  • Bits 23-20: TAG[3:0] - Sample type identifier
  • Bits 19-0: DATA[19:0] - 20-bit signed measurement data

TAG Values:

  • 0x1: BioZ In-Phase sample
  • 0x2: BioZ Quadrature sample
  • 0xE: Marker (0xFFFFFE - all 1s except bit 0)
  • 0xF: Invalid sample (0xFFFFFF - all 1s)
Here is the caller graph for this function:

◆ max30009_fifo_flush()

int max30009_fifo_flush ( struct max30009_dev * device)

Flush FIFO contents.

Parameters
device- MAX30009 device descriptor
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_fifo_get_count()

int max30009_fifo_get_count ( struct max30009_dev * device,
uint16_t * count )

Get FIFO data count.

Parameters
device- MAX30009 device descriptor
count- Pointer to store FIFO data count (0-256)
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_fifo_get_ovf_count()

int max30009_fifo_get_ovf_count ( struct max30009_dev * device,
uint16_t * count )

Get FIFO overflow data count.

Parameters
device- MAX30009 device descriptor
count- Pointer to store FIFO overflow data count (0-128)
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_bioz_config()

int max30009_get_bioz_config ( struct max30009_dev * device,
struct max30009_bioz_config * bioz_config )

Get complete BioZ configuration.

Parameters
device- Device descriptor
bioz_config- Pointer to store BioZ configuration
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_bioz_mux_config()

int max30009_get_bioz_mux_config ( struct max30009_dev * device,
struct max30009_bioz_mux_config * mux_config )

Get complete BioZ MUX configuration.

Parameters
device- Device descriptor
mux_config- Pointer to store BioZ MUX configuration
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_detailed_lead_status()

int max30009_get_detailed_lead_status ( struct max30009_dev * device,
struct max30009_lead_status * status )

Get detailed lead detection status.

Parameters
device- Device descriptor
status- Pointer to store detailed lead status information
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_fifo_config()

int max30009_get_fifo_config ( struct max30009_dev * device,
struct max30009_fifo_config * fifo_config )

Get complete FIFO configuration.

Parameters
device- Device descriptor
fifo_config- Pointer to store FIFO configuration
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_fifo_pointers()

int max30009_get_fifo_pointers ( struct max30009_dev * device,
uint8_t * write_ptr,
uint8_t * read_ptr )

Get FIFO read and write pointers.

Parameters
device- Device descriptor
write_ptr- Pointer to store write pointer value (0-255)
read_ptr- Pointer to store read pointer value (0-255)
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_fifo_watermark()

int max30009_get_fifo_watermark ( struct max30009_dev * device,
uint8_t * watermark )

Gets the FIFO watermark level of the device.

Parameters
device- Device descriptor.
watermark- Pointer to a variable where the current FIFO watermark level
Returns
0 in case of success, negative error code otherwise.

◆ max30009_get_lead_detect_config()

int max30009_get_lead_detect_config ( struct max30009_dev * device,
struct max30009_lead_detect_config * lead_config )

Get complete lead detection configuration.

Parameters
device- Device descriptor
lead_config- Pointer to store lead detection configuration
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_pll_config()

int max30009_get_pll_config ( struct max30009_dev * device,
struct max30009_pll_config * pll_config )

Get complete PLL configuration.

Parameters
device- Device descriptor
pll_config- Pointer to store PLL configuration
Returns
0 in case of success, negative error code otherwise

◆ max30009_get_status()

int max30009_get_status ( struct max30009_dev * device,
struct max30009_status * status )

Get device status.

Parameters
device- MAX30009 device descriptor
status- Pointer to store device status information
Returns
0 in case of success, negative error code otherwise

◆ max30009_init()

int max30009_init ( struct max30009_dev ** device,
struct max30009_init_param * init_param )

Initialize the MAX30009 device.

Parameters
device- Pointer to the device descriptor pointer
init_param- Initialization parameters
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_insert_fifo_marker()

int max30009_insert_fifo_marker ( struct max30009_dev * device)

Insert marker into FIFO data stream.

Parameters
device- Device descriptor
Returns
0 in case of success, negative error code otherwise
Note
Marker is used to identify specific data points in FIFO stream

◆ max30009_interrupt_config()

int max30009_interrupt_config ( struct max30009_dev * device,
uint8_t int1_mask,
uint8_t int2_mask )

Configure interrupt enables.

Parameters
device- MAX30009 device descriptor
int1_mask- Interrupt enable mask for INTERRUPT_ENABLE1 register
int2_mask- Interrupt enable mask for INTERRUPT_ENABLE2 register
Returns
0 in case of success, negative error code otherwise

◆ max30009_lead_off_config()

int max30009_lead_off_config ( struct max30009_dev * device,
bool enable,
uint8_t threshold )

Configure lead-off detection.

Parameters
device- MAX30009 device descriptor
enable- True to enable lead-off detection, false to disable
threshold- Lead-off detection threshold (0-15)
Returns
0 in case of success, negative error code otherwise

◆ max30009_pll_enable()

int max30009_pll_enable ( struct max30009_dev * device,
bool enable )

Enable or disable PLL.

Parameters
device- Device descriptor
enable- True to enable PLL, false to disable
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_pll_set_dividers()

int max30009_pll_set_dividers ( struct max30009_dev * device,
uint16_t mdiv,
enum max30009_pll_ndiv ndiv,
enum max30009_pll_kdiv kdiv )

Configure PLL dividers.

Parameters
device- Device descriptor
mdiv- M divider value (0-1023, PLL_CLK = (MDIV+1) × REF_CLK)
ndiv- N divider value (MAX30009_NDIV_512 or MAX30009_NDIV_1024)
kdiv- K divider value (MAX30009_KDIV_1 to MAX30009_KDIV_8192)
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_pll_set_lock_window()

int max30009_pll_set_lock_window ( struct max30009_dev * device,
bool lock_window )

Set PLL lock window.

Parameters
device- Device descriptor
lock_window- True to enable extended lock window, false for normal
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_read_bist_error()

int max30009_read_bist_error ( struct max30009_dev * device,
uint8_t * error )

Read BIST error value.

Parameters
device- Device descriptor
error- Pointer to store BIST error value
Returns
0 in case of success, negative error code otherwise

◆ max30009_read_fifo_data()

int max30009_read_fifo_data ( struct max30009_dev * device,
uint8_t * data,
uint32_t len )

Read data from FIFO.

Parameters
device- MAX30009 device descriptor
data- Buffer to store FIFO data
lenNumber of bytes to read from the FIFO.
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_reg_read()

int max30009_reg_read ( struct max30009_dev * device,
uint8_t reg_addr,
uint8_t * data )

Read a single byte from register.

Parameters
device- MAX30009 device descriptor
reg_addr- Register address to read from
data- Pointer to variable where read byte will be stored
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_reg_read_multiple()

int max30009_reg_read_multiple ( struct max30009_dev * device,
uint8_t reg_addr,
uint8_t * data,
uint32_t len )

Read multiple bytes from register.

Parameters
device- MAX30009 device descriptor
reg_addr- Register address to read from
data- Pointer to buffer where read data will be stored
len- Number of bytes to read
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_reg_update()

int max30009_reg_update ( struct max30009_dev * device,
uint8_t reg_addr,
uint8_t mask,
uint8_t value )

Update specific bits in a register.

Parameters
device- MAX30009 device descriptor
reg_addr- Register address to update
mask- Bit mask indicating which bits to update
value- New value for the field, given in raw (unshifted) form. It is shifted into the mask position internally via no_os_field_prep, so callers must NOT pre-shift with no_os_field_prep.
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_reg_write()

int max30009_reg_write ( struct max30009_dev * device,
uint8_t reg_addr,
uint8_t data )

Write a single byte to register.

Parameters
device- MAX30009 device descriptor
reg_addr- Register address to write to
data- Byte value to be written
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_reg_write_multiple()

int max30009_reg_write_multiple ( struct max30009_dev * device,
uint8_t reg_addr,
uint8_t * data,
uint32_t len )

Write multiple bytes to register.

Parameters
device- MAX30009 device descriptor
reg_addr- Register address to write to
data- Pointer to buffer containing data to be written
len- Number of bytes to write
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_remove()

int max30009_remove ( struct max30009_dev * device)

Remove the MAX30009 device and free resources.

Parameters
device- MAX30009 device descriptor
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_a_full_type()

int max30009_set_a_full_type ( struct max30009_dev * device,
bool type )

Set almost-full interrupt type.

Parameters
device- Device descriptor
type- True for asserted when count >= threshold, False for count > threshold
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_adc_osr()

int max30009_set_adc_osr ( struct max30009_dev * device,
enum max30009_adc_osr osr )

Set ADC oversampling ratio.

Parameters
device- Device descriptor
osr- ADC OSR value (MAX30009_ADC_OSR_8 through _1024)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_amp_bandwidth()

int max30009_set_amp_bandwidth ( struct max30009_dev * device,
uint8_t amp_bw )

Set amplifier bandwidth.

Parameters
device- Device descriptor
amp_bw- Amplifier bandwidth setting (0-3)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_amp_range()

int max30009_set_amp_range ( struct max30009_dev * device,
uint8_t amp_range )

Set amplifier range.

Parameters
device- Device descriptor
amp_range- Amplifier range setting (0-3)
Returns
0 in case of success, negative error code otherwise
Note
Optimizes ADC dynamic range for different electrode impedances

◆ max30009_set_analog_hpf()

int max30009_set_analog_hpf ( struct max30009_dev * device,
enum max30009_ahpf ahpf )

Set analog high-pass filter.

Parameters
device- Device descriptor
ahpf- Analog HPF setting (BYPASS, or 100Hz-10kHz)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_bia_load_resistor()

int max30009_set_bia_load_resistor ( struct max30009_dev * device,
enum max30009_bia_rsel rsel )

Set BIA (Body Impedance Analysis) load resistor.

Parameters
device- Device descriptor
rsel- Resistor selection (280, 600, 900, or 5100 ohms)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_bioz_config()

int max30009_set_bioz_config ( struct max30009_dev * device,
struct max30009_bioz_config * bioz_config )

Set complete BioZ configuration.

Parameters
device- Device descriptor
bioz_config- BioZ configuration structure
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_bioz_mux_config()

int max30009_set_bioz_mux_config ( struct max30009_dev * device,
struct max30009_bioz_mux_config * mux_config )

Set complete BioZ MUX configuration.

Parameters
device- Device descriptor
mux_config- BioZ MUX configuration structure
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_bioz_thresholds()

int max30009_set_bioz_thresholds ( struct max30009_dev * device,
uint8_t low_thresh,
uint8_t high_thresh )

Set BioZ threshold values.

Parameters
device- Device descriptor
low_thresh- Low threshold value (0-255)
high_thresh- High threshold value (0-255)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_channel_freq_select()

int max30009_set_channel_freq_select ( struct max30009_dev * device,
bool fsel )

Set channel frequency select.

Parameters
device- Device descriptor
fsel- Frequency select bit
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_clock_source()

int max30009_set_clock_source ( struct max30009_dev * device,
bool use_external,
bool use_32768_hz )

Configure clock source.

Parameters
device- Device descriptor
use_external- True for external clock, false for internal oscillator
use_32768_hz- True for 32.768 kHz, false for 32.0 kHz
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_comparison_mode()

int max30009_set_comparison_mode ( struct max30009_dev * device,
uint8_t cmp_mode )

Set comparison mode for threshold detection.

Parameters
device- Device descriptor
cmp_mode- Comparison mode (0-3)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_dac_osr()

int max30009_set_dac_osr ( struct max30009_dev * device,
enum max30009_dac_osr osr )

Set DAC oversampling ratio.

Parameters
device- Device descriptor
osr- DAC OSR value (MAX30009_DAC_OSR_32, _64, _128, or _256)
Returns
0 in case of success, negative error code otherwise
Note
Affects stimulus frequency: F_BIOZ = PLL_CLK / (KDIV × DAC_OSR)

◆ max30009_set_demod_clk_phases()

int max30009_set_demod_clk_phases ( struct max30009_dev * device,
bool i_clk_phase,
bool q_clk_phase )

Set demodulation clock phases.

Parameters
device- Device descriptor
i_clk_phase- I channel clock phase (true for inverted)
q_clk_phase- Q channel clock phase (true for inverted)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_digital_hpf()

int max30009_set_digital_hpf ( struct max30009_dev * device,
enum max30009_dhpf dhpf )

Set digital high-pass filter.

Parameters
device- Device descriptor
dhpf- Digital HPF setting
Returns
0 in case of success, negative error code otherwise
Note
Used to remove DC offset from bioimpedance signal

◆ max30009_set_digital_lpf()

int max30009_set_digital_lpf ( struct max30009_dev * device,
enum max30009_dlpf dlpf )

Set digital low-pass filter.

Parameters
device- Device descriptor
dlpf- Digital LPF setting
Returns
0 in case of success, negative error code otherwise
Note
Used for anti-aliasing and noise reduction

◆ max30009_set_drive_current_detailed()

int max30009_set_drive_current_detailed ( struct max30009_dev * device,
uint8_t idrv_range,
uint8_t vdrv_mag )

Set drive current with detailed control.

Parameters
device- Device descriptor
idrv_range- Current range setting (0-3)
vdrv_mag- Voltage magnitude setting (0-3)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_drive_mode()

int max30009_set_drive_mode ( struct max30009_dev * device,
enum max30009_drive_mode mode )

Set drive mode (current, voltage, H-bridge, or standby)

Parameters
device- Device descriptor
mode- Drive mode (SINE_CURRENT, SINE_VOLTAGE, H_BRIDGE, or STANDBY)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_fifo_config()

int max30009_set_fifo_config ( struct max30009_dev * device,
struct max30009_fifo_config * fifo_config )

Set complete FIFO configuration.

Parameters
device- Device descriptor
fifo_config- FIFO configuration structure
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_fifo_rollover()

int max30009_set_fifo_rollover ( struct max30009_dev * device,
bool rollover )

Set FIFO rollover mode.

Parameters
device- Device descriptor
rollover- True to enable rollover mode, false to stop when full
Returns
0 in case of success, negative error code otherwise
Note
In rollover mode, new data overwrites oldest data when FIFO is full
Here is the caller graph for this function:

◆ max30009_set_fifo_watermark()

int max30009_set_fifo_watermark ( struct max30009_dev * device,
uint8_t watermark )

Set FIFO watermark level.

Parameters
device- Device descriptor
watermark- Watermark level (number of samples before FIFO generates an interrupt).
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_gsr_load_resistor()

int max30009_set_gsr_load_resistor ( struct max30009_dev * device,
enum max30009_gsr_rsel rsel )

Set GSR (Galvanic Skin Response) load resistor.

Parameters
device- Device descriptor
rsel- Resistor selection (25.7k, 101k, 505k, or 1M ohms)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_ina_mode()

int max30009_set_ina_mode ( struct max30009_dev * device,
bool low_power )

Set INA (Instrumentation Amplifier) mode.

Parameters
device- Device descriptor
low_power- True for low-power mode, false for low-noise mode
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_lead_bias()

int max30009_set_lead_bias ( struct max30009_dev * device,
enum max30009_rbias_val rbias_value,
bool enable_bip,
bool enable_bin )

Configure lead bias resistor and enable for receive electrodes.

Parameters
device- Device descriptor
rbias_value- Bias resistor value (50M, 100M, 200M ohms)
enable_bip- True to enable bias on BIP (positive receive) electrode
enable_bin- True to enable bias on BIN (negative receive) electrode
Returns
0 in case of success, negative error code otherwise
Note
Lead bias pulls electrodes to mid-supply for proper DC operating point
Here is the caller graph for this function:

◆ max30009_set_lead_detect_config()

int max30009_set_lead_detect_config ( struct max30009_dev * device,
struct max30009_lead_detect_config * lead_config )

Set complete lead detection configuration.

Parameters
device- Device descriptor
lead_config- Lead detection configuration structure
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_lead_off_current()

int max30009_set_lead_off_current ( struct max30009_dev * device,
enum max30009_loff_current current )

Set lead-off detection current magnitude.

Parameters
device- Device descriptor
current- Lead-off current setting (5nA, 11nA, 22nA, 55nA, or 110nA)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_lead_off_polarity()

int max30009_set_lead_off_polarity ( struct max30009_dev * device,
bool positive )

Set lead-off detection current polarity.

Parameters
device- Device descriptor
positive- True for positive polarity, false for negative polarity
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_master_mode()

int max30009_set_master_mode ( struct max30009_dev * device,
bool is_master )

Set master/slave mode for PLL synchronization.

Parameters
device- Device descriptor
is_master- True for master mode (generates FCLK_SYS), False for slave mode (uses external FCLK_SYS)
Returns
0 in case of success, negative error code otherwise

◆ max30009_set_pll_config()

int max30009_set_pll_config ( struct max30009_dev * device,
struct max30009_pll_config * pll_config )

Set complete PLL configuration.

Parameters
device- Device descriptor
pll_config- PLL configuration structure
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_set_power_mode()

int max30009_set_power_mode ( struct max30009_dev * device,
bool shutdown )

Set power mode (shutdown or active)

Parameters
device- MAX30009 device descriptor
shutdown- True to enter shutdown mode, false for active mode
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function:

◆ max30009_soft_reset()

int max30009_soft_reset ( struct max30009_dev * device)

Perform software reset.

Parameters
device- MAX30009 device descriptor
Returns
0 in case of success, negative error code otherwise
Note
Follows the datasheet-required soft-reset sequence: BIOZ_BG_EN=1, SHDN=0, REF_CLK_SEL=0, PLL_EN=0, wait >=1ms, RESET=1. Re-enable the PLL after soft reset via max30009_pll_enable().
Here is the caller graph for this function:

◆ max30009_timing_system_reset()

int max30009_timing_system_reset ( struct max30009_dev * device)

Trigger timing system reset for PLL synchronization.

Parameters
device- Device descriptor
Returns
0 in case of success, negative error code otherwise
Note
Use this after PLL configuration changes to synchronize timing system

◆ max30009_verify_part_id()

int max30009_verify_part_id ( struct max30009_dev * device)

Read device part ID.

Parameters
device- MAX30009 device descriptor
Returns
0 in case of success, negative error code otherwise
Here is the caller graph for this function: