Commit 132ab9c0 authored by Jakob's avatar Jakob Committed by Arist

fix(max86150): replace Arduino library with a better version

Get samples from FIFO by small junks due to a recommendation from Maxim
not to read the entire FIFO, but rather a fixed number of samples.
See https://os.mbed.com/users/laserdad/code/MAX86150_ECG_PPG//file/3c728f3d1f10/main.cpp/

Additional tuning for particular configuration of max86150 in card10.
Co-Authored-by: Arist's avatarArist <aristkojevnikov@gmail.com>
parent f17417e1
This diff is collapsed.
......@@ -18,86 +18,115 @@
#include <stdint.h>
#include <stdbool.h>
typedef uint8_t byte;
bool max86150_begin(void);
uint32_t max86150_getRed(void); //Returns immediate red value
uint32_t max86150_getIR(void); //Returns immediate IR value
int32_t max86150_getECG(void); //Returns immediate ECG value
bool max86150_safeCheck(uint8_t maxTimeToCheck); //Given a max amount of time, check for new data
// Configuration
void max86150_softReset();
void max86150_shutDown();
void max86150_wakeUp();
static const uint8_t MAX86150_SAMPLEAVG_1 = 0b000;
static const uint8_t MAX86150_SAMPLEAVG_2 = 0b001;
static const uint8_t MAX86150_SAMPLEAVG_4 = 0b010;
static const uint8_t MAX86150_SAMPLEAVG_8 = 0b011;
static const uint8_t MAX86150_SAMPLEAVG_16 = 0b100;
static const uint8_t MAX86150_SAMPLEAVG_32 = 0b101;
static const uint8_t MAX86150_ADCRANGE_4096 = 0b00000000;
static const uint8_t MAX86150_ADCRANGE_8192 = 0b01000000;
static const uint8_t MAX86150_ADCRANGE_16384 = 0b10000000;
static const uint8_t MAX86150_ADCRANGE_32768 = 0b11000000;
static const uint8_t MAX86150_PPG_SAMPLERATE_10 = 0b00000000;
static const uint8_t MAX86150_PPG_SAMPLERATE_20 = 0b00000100;
static const uint8_t MAX86150_PPG_SAMPLERATE_50 = 0b00001000;
static const uint8_t MAX86150_PPG_SAMPLERATE_84 = 0b00001100;
static const uint8_t MAX86150_PPG_SAMPLERATE_100 = 0b00010000;
static const uint8_t MAX86150_PPG_SAMPLERATE_200 = 0b00010100;
static const uint8_t MAX86150_PPG_SAMPLERATE_400 = 0b00011000;
static const uint8_t MAX86150_PPG_SAMPLERATE_800 = 0b00011100;
static const uint8_t MAX86150_PPG_SAMPLERATE_1000 = 0b00100000;
static const uint8_t MAX86150_PPG_SAMPLERATE_1600 = 0b00100100;
static const uint8_t MAX86150_PPG_SAMPLERATE_3200 = 0b00101000;
static const uint8_t MAX86150_PPG_PULSEWIDTH_50 = 0b00;
static const uint8_t MAX86150_PPG_PULSEWIDTH_100 = 0b01;
static const uint8_t MAX86150_PPG_PULSEWIDTH_200 = 0b10;
static const uint8_t MAX86150_PPG_PULSEWIDTH_400 = 0b11;
static const uint8_t MAX86150_SLOT_NONE = 0b0000;
static const uint8_t MAX86150_SLOT_RED_LED = 0b0010;
static const uint8_t MAX86150_SLOT_IR_LED = 0b0001;
static const uint8_t MAX86150_SLOT_RED_PILOT = 0b0110;
static const uint8_t MAX86150_SLOT_IR_PILOT = 0b0101;
static const uint8_t MAX86150_SLOT_ECG = 0b1001;
static const uint8_t MAX86150_LED1_RANGE_50 = 0b00;
static const uint8_t MAX86150_LED1_RANGE_100 = 0b01;
static const uint8_t MAX86150_LED2_RANGE_50 = 0b0000;
static const uint8_t MAX86150_LED2_RANGE_100 = 0b0100;
static const uint8_t MAX86150_ECG_SAMPLERATE_200 = 0b011;
static const uint8_t MAX86150_ECG_SAMPLERATE_400 = 0b010;
static const uint8_t MAX86150_ECG_SAMPLERATE_800 = 0b001;
static const uint8_t MAX86150_ECG_SAMPLERATE_1600 = 0b000;
static const uint8_t MAX86150_ECG_SAMPLERATE_3200 = 0b100;
static const uint8_t MAX86150_ECG_PGA_GAIN_1 = 0b0000;
static const uint8_t MAX86150_ECG_PGA_GAIN_2 = 0b0100;
static const uint8_t MAX86150_ECG_PGA_GAIN_4 = 0b1000;
static const uint8_t MAX86150_ECG_PGA_GAIN_8 = 0b1100;
static const uint8_t MAX86150_ECG_IA_GAIN_5 = 0b00;
static const uint8_t MAX86150_ECG_IA_GAIN_9_5 = 0b01;
static const uint8_t MAX86150_ECG_IA_GAIN_20 = 0b10;
static const uint8_t MAX86150_ECG_IA_GAIN_50 = 0b11;
void max86150_setLEDMode(uint8_t mode);
void max86150_setADCRange(uint8_t adcRange);
void max86150_setSampleRate(uint8_t sampleRate);
void max86150_setPulseWidth(uint8_t pulseWidth);
void max86150_setPulseAmplitudeRed(uint8_t value);
void max86150_setPulseAmplitudeIR(uint8_t value);
void max86150_setPulseAmplitudeProximity(uint8_t value);
void max86150_setProximityThreshold(uint8_t threshMSB);
bool max86150_begin(void);
//Multi-led configuration mode (page 22)
void max86150_enableSlot(uint8_t slotNumber, uint8_t device); //Given slot number, assign a device to slot
uint8_t max86150_get_int1(void);
uint8_t max86150_get_int2(void);
void max86150_set_int_full(bool enabled);
void max86150_set_int_datardy(bool enabled);
void max86150_set_int_ambient_light_overflow(bool enabled);
void max86150_set_int_proximity(bool enabled);
void max86150_soft_reset(void);
void max86150_shut_down(void);
void max86150_wake_up(void);
void max86150_set_ppg_adc_range(uint8_t adcRange);
void max86150_set_ppg_sample_rate(uint8_t sampleRate);
void max86150_set_ppg_pulse_width(uint8_t pulseWidth);
void max86150_set_led_red_amplitude(uint8_t amplitude);
void max86150_set_led_ir_amplitude(uint8_t amplitude);
void max86150_set_led_proximity_amplitude(uint8_t amplitude);
void max86150_set_proximity_threshold(uint8_t threshMSB);
void max86150_fifo_enable_slot(uint8_t slotNumber, uint8_t device);
void max86150_disableSlots(void);
// Data Collection
//Interrupts (page 13, 14)
uint8_t max86150_getINT1(void); //Returns the main interrupt group
uint8_t max86150_getINT2(void); //Returns the temp ready interrupt
void max86150_enableAFULL(void); //Enable/disable individual interrupts
void max86150_disableAFULL(void);
void max86150_enableDATARDY(void);
void max86150_disableDATARDY(void);
void max86150_enableALCOVF(void);
void max86150_disableALCOVF(void);
void max86150_enablePROXINT(void);
void max86150_disablePROXINT(void);
void max86150_enableDIETEMPRDY(void);
void max86150_disableDIETEMPRDY(void);
//FIFO Configuration (page 18)
void max86150_setFIFOAverage(uint8_t samples);
void max86150_enableFIFORollover();
void max86150_disableFIFORollover();
void max86150_setFIFOAlmostFull(uint8_t samples);
//FIFO Reading
uint16_t max86150_check(void); //Checks for new data and fills FIFO
uint8_t max86150_available(void); //Tells caller how many new samples are available (head - tail)
void max86150_nextSample(void); //Advances the tail of the sense array
uint32_t max86150_getFIFORed(void); //Returns the FIFO sample pointed to by tail
uint32_t max86150_getFIFOIR(void); //Returns the FIFO sample pointed to by tail
int32_t max86150_getFIFOECG(void); //Returns the FIFO sample pointed to by tail
uint8_t max86150_getWritePointer(void);
uint8_t max86150_getReadPointer(void);
void max86150_clearFIFO(void); //Sets the read/write pointers to zero
//Proximity Mode Interrupt Threshold
void max86150_setPROXINTTHRESH(uint8_t val);
// Die Temperature
float max86150_readTemperature();
float max86150_readTemperatureF();
// Detecting ID/Revision
uint8_t max86150_getRevisionID();
uint8_t max86150_readPartID();
uint8_t max86150_readRegLED();
// Setup the IC with user selectable settings
//void max86150_setup(byte powerLevel = 0x1F, byte sampleAverage = 4, byte ledMode = 3, int sampleRate = 400, int pulseWidth = 411, int adcRange = 4096);
void max86150_setup(byte powerLevel, byte sampleAverage, byte ledMode, int sampleRate, int pulseWidth, int adcRange);
// Low-level I2C communication
uint8_t max86150_readRegister8(uint8_t address, uint8_t reg);
void max86150_writeRegister8(uint8_t address, uint8_t reg, uint8_t value);
void max86150_set_ppg_averaging(uint8_t numberOfSamples);
void max86150_clear_fifo(void);
void max86150_set_fifo_rollover(bool enabled);
void max86150_set_fifo_almost_full_clear(bool enabled);
void max86150_set_fifo_almost_full_repeat(bool enabled);
void max86150_set_fifo_almost_full(uint8_t numberOfSamples);
uint8_t max86150_get_fifo_write_pointer(void);
uint8_t max86150_get_fifo_read_pointer(void);
uint8_t max86150_read_part_id();
void max86150_set_ecg_sample_rate(uint8_t sampleRate);
void max86150_set_ecg_pga_gain(uint8_t gain);
void max86150_set_ecg_instrumentation_amplifier_gain(uint8_t gain);
void max86150_setup(const uint8_t ppg_sample_rate);
uint8_t max86150_available(void);
uint32_t max86150_get_red(void);
uint32_t max86150_get_ir(void);
int32_t max86150_get_ecg(void);
uint32_t max86150_get_fifo_red(void);
uint32_t max86150_get_fifo_ir(void);
int32_t max86150_get_fifo_ecg(void);
void max86150_next_sample(void);
uint8_t max86150_get_sample(uint32_t *red, uint32_t *ir, int32_t *ecg);
uint16_t max86150_check(void);
bool max86150_safe_check(uint8_t max_tries);
void max86150_bit_mask(uint8_t reg, uint8_t mask, uint8_t thing);
uint8_t max86150_read_register(uint8_t address, uint8_t reg);
void max86150_write_register(uint8_t address, uint8_t reg, uint8_t value);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment