File ns_max86150_driver.c
FileList > neuralSPOT > neuralspot > ns-i2c > src > ns_max86150_driver.c
Go to the source code of this file
Register driver for MAX86150 ECG/PPG IC. More...
#include "ns_max86150_driver.h"
#include <ctype.h>
#include <stdint.h>
#include <string.h>
Public Static Attributes
Type | Name |
---|---|
const uint8_t | MAX86150_ECG_CONFIG1 = = 0x3C |
const uint8_t | MAX86150_ECG_CONFIG3 = = 0x3E |
const uint8_t | MAX86150_FIFO_CONFIG = = 0x08 |
const uint8_t | MAX86150_FIFO_CONTROL1 = = 0x09 |
const uint8_t | MAX86150_FIFO_CONTROL2 = = 0x0A |
const uint8_t | MAX86150_FIFO_DATA = = 0x07 |
const uint8_t | MAX86150_FIFO_OVERFLOW = = 0x05 |
const uint8_t | MAX86150_FIFO_RD_PTR = = 0x06 |
const uint8_t | MAX86150_FIFO_WR_PTR = = 0x04 |
const uint8_t | MAX86150_INT_EN1 = = 0x02 |
const uint8_t | MAX86150_INT_EN2 = = 0x03 |
const uint8_t | MAX86150_INT_STAT1 = = 0x00 |
const uint8_t | MAX86150_INT_STAT2 = = 0x01 |
const uint8_t | MAX86150_LED1_PA = = 0x11 |
const uint8_t | MAX86150_LED2_PA = = 0x12 |
const uint8_t | MAX86150_LEDP_PA = = 0x15 |
const uint8_t | MAX86150_LED_RANGE = = 0x14 |
const uint8_t | MAX86150_PART_ID = = 0xFF |
const uint8_t | MAX86150_PPG_CONFIG1 = = 0x0E |
const uint8_t | MAX86150_PPG_CONFIG2 = = 0x0F |
const uint8_t | MAX86150_PPG_PROX_INT_THRESH = = 0x10 |
const uint8_t | MAX86150_SYS_CONTROL = = 0x0D |
Public Functions
Type | Name |
---|---|
void | max86150_clear_fifo (const max86150_context_t * ctx) Clear FIFO. |
void | max86150_disable_slots (const max86150_context_t * ctx) Disables all FIFO slots data sources. |
uint8_t | max86150_get_fifo_overflow_counter (const max86150_context_t * ctx) Get FIFO overflow counter. |
uint8_t | max86150_get_fifo_rd_pointer (const max86150_context_t * ctx) Get FIFO write pointer. |
uint8_t | max86150_get_fifo_wr_pointer (const max86150_context_t * ctx) Get FIFO write pointer. |
uint8_t | max86150_get_int1 (const max86150_context_t * ctx) Get interrupt 1 register A_FULL[7] PPG_RDY[6] ALC_OVF[5] PROX_INT[4] PWR_RDY[0]. |
uint8_t | max86150_get_int2 (const max86150_context_t * ctx) Get interrupt 2 register VDD_OOR[7] ECG_RDY[2]. |
uint8_t | max86150_get_part_id (const max86150_context_t * ctx) Get part ID. Should be 0x1E for this part. |
uint8_t | max86150_get_register (const max86150_context_t * ctx, uint8_t reg, uint8_t mask) Read register field. |
void | max86150_powerup (const max86150_context_t * ctx) Takes chip out ofpower-save mode. |
uint32_t | max86150_read_fifo_samples (const max86150_context_t * ctx, uint32_t * buffer, max86150_slot_type * slots, uint8_t numSlots) Reads all data available in FIFO. |
void | max86150_reset (const max86150_context_t * ctx) This performs full power-on-reset. All registers are reset. |
void | max86150_set_alc_ovf_int_flag (const max86150_context_t * ctx, uint8_t enable) Set ambient light cancellation (ALC) overflow interrupt enable flag. |
void | max86150_set_alm_full_int_flag (const max86150_context_t * ctx, uint8_t enable) Set FIFO almost full interrupt enable flag. |
void | max86150_set_almost_full_flag_options (const max86150_context_t * ctx, uint8_t options) Set FIFO almost full flag options. |
void | max86150_set_almost_full_int_options (const max86150_context_t * ctx, uint8_t options) Set FIFO almost full interrupt options. |
void | max86150_set_almost_full_rollover (const max86150_context_t * ctx, uint8_t enable) Set whether FIFO rolls over when full. |
void | max86150_set_almost_full_threshold (const max86150_context_t * ctx, uint8_t space) Set FIFO almost full value (i.e. how many samples till interrupt is triggered) |
void | max86150_set_ecg_ia_gain (const max86150_context_t * ctx, uint8_t value) Set ECG instrument amplifier gain. |
void | max86150_set_ecg_pga_gain (const max86150_context_t * ctx, uint8_t value) Set ECG PGA gain. Gain = 2**value (V/V) |
void | max86150_set_ecg_rdy_int_flag (const max86150_context_t * ctx, uint8_t enable) Set new ECG FIFO data ready interrupt enable flag. |
void | max86150_set_ecg_sample_rate (const max86150_context_t * ctx, uint8_t value) |
void | max86150_set_fifo_enable (const max86150_context_t * ctx, uint8_t enable) Set FIFO enable state. |
uint8_t | max86150_set_fifo_overflow_counter (const max86150_context_t * ctx, uint8_t value) Set FIFO overflow counter. |
void | max86150_set_fifo_rd_pointer (const max86150_context_t * ctx, uint8_t value) Set FIFO read pointer. |
void | max86150_set_fifo_slot (const max86150_context_t * ctx, uint8_t slot, max86150_slot_type type) Configure FIFO for given slot (element) |
void | max86150_set_fifo_slots (const max86150_context_t * ctx, max86150_slot_type * slots) Configure all FIFO slots. |
void | max86150_set_fifo_wr_pointer (const max86150_context_t * ctx, uint8_t value) Set FIFO write pointer. |
void | max86150_set_led_current_range (const max86150_context_t * ctx, uint8_t led, uint8_t value) Set LED current range. |
void | max86150_set_led_pulse_amplitude (const max86150_context_t * ctx, uint8_t led, uint8_t value) |
void | max86150_set_ppg_adc_range (const max86150_context_t * ctx, uint8_t range) Set PPG ADC range. |
void | max86150_set_ppg_pulse_width (const max86150_context_t * ctx, uint8_t value) Set PPG pulse width. |
void | max86150_set_ppg_rdy_int_flag (const max86150_context_t * ctx, uint8_t enable) Set new PPG FIFO data ready interrupt enable flag. |
void | max86150_set_ppg_sample_average (const max86150_context_t * ctx, uint8_t value) Set PPG sample averaging. Will average and decimate adjacent samples. |
void | max86150_set_ppg_sample_rate (const max86150_context_t * ctx, uint8_t value) Set PPG sample rate and pulse rate. NOTE: If rate cant be acheived, then highest available will be selected. |
void | max86150_set_prox_int_flag (const max86150_context_t * ctx, uint8_t enable) Set proximity interrupt enable flag. |
void | max86150_set_proximity_threshold (const max86150_context_t * ctx, uint8_t value) Sets the IR ADC count that triggers the beginning of the PPG mode. |
int | max86150_set_register (const max86150_context_t * ctx, uint8_t reg, uint8_t value, uint8_t mask) Set register field. |
void | max86150_set_vdd_oor_int_flag (const max86150_context_t * ctx, uint8_t enable) Set VDD Out-of-Range indicator interrupt flag. |
void | max86150_shutdown (const max86150_context_t * ctx) Put chip into power-save mode. Registers retain their values. |
Detailed Description
Author:
Adam Page (adam.page@ambiq.com)
Version:
0.1
Date:
2022-11-02
Copyright:
Copyright (c) 2022
Public Static Attributes Documentation
variable MAX86150_ECG_CONFIG1
const uint8_t MAX86150_ECG_CONFIG1;
variable MAX86150_ECG_CONFIG3
const uint8_t MAX86150_ECG_CONFIG3;
variable MAX86150_FIFO_CONFIG
const uint8_t MAX86150_FIFO_CONFIG;
variable MAX86150_FIFO_CONTROL1
const uint8_t MAX86150_FIFO_CONTROL1;
variable MAX86150_FIFO_CONTROL2
const uint8_t MAX86150_FIFO_CONTROL2;
variable MAX86150_FIFO_DATA
const uint8_t MAX86150_FIFO_DATA;
variable MAX86150_FIFO_OVERFLOW
const uint8_t MAX86150_FIFO_OVERFLOW;
variable MAX86150_FIFO_RD_PTR
const uint8_t MAX86150_FIFO_RD_PTR;
variable MAX86150_FIFO_WR_PTR
const uint8_t MAX86150_FIFO_WR_PTR;
variable MAX86150_INT_EN1
const uint8_t MAX86150_INT_EN1;
variable MAX86150_INT_EN2
const uint8_t MAX86150_INT_EN2;
variable MAX86150_INT_STAT1
const uint8_t MAX86150_INT_STAT1;
variable MAX86150_INT_STAT2
const uint8_t MAX86150_INT_STAT2;
variable MAX86150_LED1_PA
const uint8_t MAX86150_LED1_PA;
variable MAX86150_LED2_PA
const uint8_t MAX86150_LED2_PA;
variable MAX86150_LEDP_PA
const uint8_t MAX86150_LEDP_PA;
variable MAX86150_LED_RANGE
const uint8_t MAX86150_LED_RANGE;
variable MAX86150_PART_ID
const uint8_t MAX86150_PART_ID;
variable MAX86150_PPG_CONFIG1
const uint8_t MAX86150_PPG_CONFIG1;
variable MAX86150_PPG_CONFIG2
const uint8_t MAX86150_PPG_CONFIG2;
variable MAX86150_PPG_PROX_INT_THRESH
const uint8_t MAX86150_PPG_PROX_INT_THRESH;
variable MAX86150_SYS_CONTROL
const uint8_t MAX86150_SYS_CONTROL;
Public Functions Documentation
function max86150_clear_fifo
Clear FIFO.
void max86150_clear_fifo (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
function max86150_disable_slots
Disables all FIFO slots data sources.
void max86150_disable_slots (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
function max86150_get_fifo_overflow_counter
Get FIFO overflow counter.
uint8_t max86150_get_fifo_overflow_counter (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
Returns:
FIFO overflow counter
function max86150_get_fifo_rd_pointer
Get FIFO write pointer.
uint8_t max86150_get_fifo_rd_pointer (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
Returns:
FIFO write pointer
function max86150_get_fifo_wr_pointer
Get FIFO write pointer.
uint8_t max86150_get_fifo_wr_pointer (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
Returns:
write pointer
function max86150_get_int1
Get interrupt 1 register A_FULL[7] PPG_RDY[6] ALC_OVF[5] PROX_INT[4] PWR_RDY[0].
uint8_t max86150_get_int1 (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
Returns:
register value
function max86150_get_int2
Get interrupt 2 register VDD_OOR[7] ECG_RDY[2].
uint8_t max86150_get_int2 (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
Returns:
register value
function max86150_get_part_id
Get part ID. Should be 0x1E for this part.
uint8_t max86150_get_part_id (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
Returns:
return
function max86150_get_register
Read register field.
uint8_t max86150_get_register (
const max86150_context_t * ctx,
uint8_t reg,
uint8_t mask
)
Returns:
Register value
function max86150_powerup
Takes chip out ofpower-save mode.
void max86150_powerup (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
function max86150_read_fifo_samples
Reads all data available in FIFO.
uint32_t max86150_read_fifo_samples (
const max86150_context_t * ctx,
uint32_t * buffer,
max86150_slot_type * slots,
uint8_t numSlots
)
Parameters:
ctx
Device contextbuffer
Buffer to store FIFO data. Should be at least 32*3*elementsPerSample (max 384 bytes)elementsPerSample
Number of elements per sample. Depends on values written to FD1-FD4
Returns:
Number of samples read
function max86150_reset
This performs full power-on-reset. All registers are reset.
void max86150_reset (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
function max86150_set_alc_ovf_int_flag
Set ambient light cancellation (ALC) overflow interrupt enable flag.
void max86150_set_alc_ovf_int_flag (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device context
function max86150_set_alm_full_int_flag
Set FIFO almost full interrupt enable flag.
void max86150_set_alm_full_int_flag (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device context
function max86150_set_almost_full_flag_options
Set FIFO almost full flag options.
void max86150_set_almost_full_flag_options (
const max86150_context_t * ctx,
uint8_t options
)
Parameters:
ctx
Device contextoptions
1-bit: 0: Assert on a_full condition, clear by status reg read, and re-assert on subsequent samples 1: Assert on a_full condition, clear by status reg read, and not re-assert on subsequent samples
function max86150_set_almost_full_int_options
Set FIFO almost full interrupt options.
void max86150_set_almost_full_int_options (
const max86150_context_t * ctx,
uint8_t options
)
Parameters:
ctx
Device contextoptions
1-bit: 0: A_FULL interrupt does not get cleared by FIFO_DATA register read. It gets cleared by status register read. 1: A_FULL interrupt gets cleared by FIFO_DATA register read or status register read.
function max86150_set_almost_full_rollover
Set whether FIFO rolls over when full.
void max86150_set_almost_full_rollover (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device contextenable
1-bit: 0: No rollover - FIFO stop on full 1: Rollover - FIFO auto rolls over on full
function max86150_set_almost_full_threshold
Set FIFO almost full value (i.e. how many samples till interrupt is triggered)
void max86150_set_almost_full_threshold (
const max86150_context_t * ctx,
uint8_t space
)
Parameters:
ctx
Device contextspace
Remaining FIFO space before intr trigger
function max86150_set_ecg_ia_gain
Set ECG instrument amplifier gain.
void max86150_set_ecg_ia_gain (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device contextvalue
Gain table: 0: 5, 1: 9.5, 2: 20, 3: 50 (V/V)
function max86150_set_ecg_pga_gain
Set ECG PGA gain. Gain = 2**value (V/V)
void max86150_set_ecg_pga_gain (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device contextvalue
2-bit
function max86150_set_ecg_rdy_int_flag
Set new ECG FIFO data ready interrupt enable flag.
void max86150_set_ecg_rdy_int_flag (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device context
function max86150_set_ecg_sample_rate
void max86150_set_ecg_sample_rate (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device contextvalue
3-bit Sample Rate Table (Hz) VALUE FS FBW_70 FBW_90 0 1600 420 232 1 800 210 116 2 400 105 58 3 200 52 29 4 3200 840 464 5 1600 420 232 6 800 210 116 7 400 105 58
function max86150_set_fifo_enable
Set FIFO enable state.
void max86150_set_fifo_enable (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device contextenable
Enable/disable FIFO. Clears on enable
function max86150_set_fifo_overflow_counter
Set FIFO overflow counter.
uint8_t max86150_set_fifo_overflow_counter (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device context
Returns:
FIFO overflow counter
function max86150_set_fifo_rd_pointer
Set FIFO read pointer.
void max86150_set_fifo_rd_pointer (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device context
function max86150_set_fifo_slot
Configure FIFO for given slot (element)
void max86150_set_fifo_slot (
const max86150_context_t * ctx,
uint8_t slot,
max86150_slot_type type
)
Parameters:
ctx
Device contextslot
Element 0-based index corresponding to FD1, FD2, FD3, FD4type
Data source to feed
function max86150_set_fifo_slots
Configure all FIFO slots.
void max86150_set_fifo_slots (
const max86150_context_t * ctx,
max86150_slot_type * slots
)
Parameters:
ctx
Device contextslot0
Element (FD1) data sourceslot1
Element (FD2) data sourceslot2
Element (FD3) data sourceslot3
Element (FD4) data source
function max86150_set_fifo_wr_pointer
Set FIFO write pointer.
void max86150_set_fifo_wr_pointer (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device contextvalue
Write pointer
function max86150_set_led_current_range
Set LED current range.
void max86150_set_led_current_range (
const max86150_context_t * ctx,
uint8_t led,
uint8_t value
)
Parameters:
ctx
Device contextled
0: LED1 (IR), 1: LED2 (RED)value
2-bit | 0: 50, 1: 100 (mA)
function max86150_set_led_pulse_amplitude
void max86150_set_led_pulse_amplitude (
const max86150_context_t * ctx,
uint8_t led,
uint8_t value
)
Parameters:
ctx
Device contextled
0: LED1 (IR), 1: LED2 (RED), 2: LEDP (proximity)value
7-bit | Pulse amplitude = 0.2*value*(LEDn_RANGE+1) (mA)
function max86150_set_ppg_adc_range
Set PPG ADC range.
void max86150_set_ppg_adc_range (
const max86150_context_t * ctx,
uint8_t range
)
Parameters:
ctx
Device contextvalue
2-bit | Full scale = 2**(14+value) nA, LSB = 7.8125 * (2 ** value)
function max86150_set_ppg_pulse_width
Set PPG pulse width.
void max86150_set_ppg_pulse_width (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device contextvalue
2-bit | 0: 50 1: 100 2: 200 3: 400 (us)
function max86150_set_ppg_rdy_int_flag
Set new PPG FIFO data ready interrupt enable flag.
void max86150_set_ppg_rdy_int_flag (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device context
function max86150_set_ppg_sample_average
Set PPG sample averaging. Will average and decimate adjacent samples.
void max86150_set_ppg_sample_average (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device contextvalue
avg = min(2**value, 32)
function max86150_set_ppg_sample_rate
Set PPG sample rate and pulse rate. NOTE: If rate cant be acheived, then highest available will be selected.
void max86150_set_ppg_sample_rate (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device contextvalue
4-bit | Samples/sec: [10, 20, 50, 84, 100, 200, 400, 800, 1000, 1600, 3200, 10, 20, 50, 84, 100] Pulses/sec: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2]
function max86150_set_prox_int_flag
Set proximity interrupt enable flag.
void max86150_set_prox_int_flag (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device context
function max86150_set_proximity_threshold
Sets the IR ADC count that triggers the beginning of the PPG mode.
void max86150_set_proximity_threshold (
const max86150_context_t * ctx,
uint8_t value
)
Parameters:
ctx
Device context
function max86150_set_register
Set register field.
int max86150_set_register (
const max86150_context_t * ctx,
uint8_t reg,
uint8_t value,
uint8_t mask
)
Returns:
0 if successful
function max86150_set_vdd_oor_int_flag
Set VDD Out-of-Range indicator interrupt flag.
void max86150_set_vdd_oor_int_flag (
const max86150_context_t * ctx,
uint8_t enable
)
Parameters:
ctx
Device context
function max86150_shutdown
Put chip into power-save mode. Registers retain their values.
void max86150_shutdown (
const max86150_context_t * ctx
)
Parameters:
ctx
Device context
The documentation for this class was generated from the following file neuralSPOT/neuralspot/ns-i2c/src/ns_max86150_driver.c