Chanel Richardson / Mbed OS vitalsplus-max86150_chanel

Dependencies:   max32630fthr USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max86150.h Source File

max86150.h

00001 /***************************************************
00002   Arduino library written for the Maxim MAX86150 ECG and PPG integrated sensor
00003 
00004     Written by Ashwin Whitchurch, ProtoCentral Electronics (www.protocentral.com)
00005 
00006     https://github.com/protocentral/protocentral_max86150
00007 
00008   Based on code written by Peter Jansen and Nathan Seidle (SparkFun) for the MAX30105 sensor
00009   BSD license, all text above must be included in any redistribution.
00010  *****************************************************/
00011 
00012 #pragma once
00013 #include "mbed.h"
00014 #include "I2C.h"
00015 //#define MAX86150_ADDRESS          0x5E //7-bit I2C Address
00016 //Note that MAX30102 has the same I2C address and Part ID
00017 
00018 #define I2C_SPEED_STANDARD        100000
00019 #define I2C_SPEED_FAST            400000
00020 
00021 //Define the size of the I2C buffer based on the platform the user has
00022 
00023 
00024   //The catch-all default is 32
00025 #define I2C_BUFFER_LENGTH 32
00026 
00027 
00028 class MAX86150 {
00029  public:
00030   MAX86150(void);
00031 
00032   //bool begin(TwoWire &wirePort = Wire, uint32_t i2cSpeed = I2C_SPEED_STANDARD, uint8_t i2caddr = MAX86150_ADDRESS);
00033     bool begin(I2C &wirePort, uint32_t i2cSpeed, uint8_t i2caddr);
00034 
00035   uint32_t getRed(void); //Returns immediate red value
00036   uint32_t getIR(void); //Returns immediate IR value
00037   int32_t getECG(void); //Returns immediate ECG value
00038   bool safeCheck(uint8_t maxTimeToCheck); //Given a max amount of time, check for new data
00039 
00040   // Configuration
00041   void softReset();
00042   void shutDown();
00043   void wakeUp();
00044 
00045   void setLEDMode(uint8_t mode);
00046 
00047   void setADCRange(uint8_t adcRange);
00048   void setSampleRate(uint8_t sampleRate);
00049   void setPulseWidth(uint8_t pulseWidth);
00050 
00051   void setPulseAmplitudeRed(uint8_t value);
00052   void setPulseAmplitudeIR(uint8_t value);
00053   void setPulseAmplitudeProximity(uint8_t value);
00054 
00055   void setProximityThreshold(uint8_t threshMSB);
00056 
00057   //Multi-led configuration mode (page 22)
00058   void enableSlot(uint8_t slotNumber, uint8_t device); //Given slot number, assign a device to slot
00059   void disableSlots(void);
00060 
00061   // Data Collection
00062 
00063   //Interrupts (page 13, 14)
00064   uint8_t getINT1(void); //Returns the main interrupt group
00065   uint8_t getINT2(void); //Returns the temp ready interrupt
00066   void enableAFULL(void); //Enable/disable individual interrupts
00067   void disableAFULL(void);
00068   void enableDATARDY(void);
00069   void disableDATARDY(void);
00070   void enableALCOVF(void);
00071   void disableALCOVF(void);
00072   void enablePROXINT(void);
00073   void disablePROXINT(void);
00074   void enableDIETEMPRDY(void);
00075   void disableDIETEMPRDY(void);
00076 
00077   //FIFO Configuration (page 18)
00078   void setFIFOAverage(uint8_t samples);
00079   void enableFIFORollover();
00080   void disableFIFORollover();
00081   void setFIFOAlmostFull(uint8_t samples);
00082 
00083   //FIFO Reading
00084   uint16_t check(void); //Checks for new data and fills FIFO
00085   uint8_t available(void); //Tells caller how many new samples are available (head - tail)
00086   void nextSample(void); //Advances the tail of the sense array
00087   uint32_t getFIFORed(void); //Returns the FIFO sample pointed to by tail
00088   uint32_t getFIFOIR(void); //Returns the FIFO sample pointed to by tail
00089   int32_t getFIFOECG(void); //Returns the FIFO sample pointed to by tail
00090 
00091   uint8_t getWritePointer(void);
00092   uint8_t getReadPointer(void);
00093   void clearFIFO(void); //Sets the read/write pointers to zero
00094 
00095   //Proximity Mode Interrupt Threshold
00096   void setPROXINTTHRESH(uint8_t val);
00097 
00098   // Die Temperature
00099   float readTemperature();
00100   float readTemperatureF();
00101 
00102   // Detecting ID/Revision
00103   uint8_t getRevisionID();
00104   uint8_t readPartID();
00105     uint8_t readRegLED();
00106 
00107   // Setup the IC with user selectable settings
00108   void setup(uint8_t powerLevel = 0x1F, uint8_t sampleAverage = 4, uint8_t ledMode = 3, int sampleRate = 400, int pulseWidth = 411, int adcRange = 4096);
00109 
00110   // Low-level I2C communication
00111   uint8_t readRegister8(uint8_t address, uint8_t reg);
00112   void writeRegister8(uint8_t address, uint8_t reg, uint8_t value);
00113 
00114  private:
00115   I2C *_i2cPort; //The generic connection to user's chosen I2C hardware
00116   uint8_t _i2caddr;
00117 
00118   //activeLEDs is the number of channels turned on, and can be 1 to 3. 2 is common for Red+IR.
00119   uint8_t activeDevices; //Gets set during setup. Allows check() to calculate how many bytes to read from FIFO
00120 
00121   uint8_t revisionID;
00122 
00123   void readRevisionID();
00124 
00125   void bitMask(uint8_t reg, uint8_t mask, uint8_t thing);
00126 
00127    #define STORAGE_SIZE 4 //Each long is 4 bytes so limit this to fit on your micro
00128   typedef struct Record
00129   {
00130     uint32_t red[STORAGE_SIZE];
00131     uint32_t IR[STORAGE_SIZE];
00132     int32_t ecg[STORAGE_SIZE];
00133     uint8_t head;
00134     uint8_t tail;
00135   } sense_struct; //This is our circular buffer of readings from the sensor
00136 
00137   sense_struct sense;
00138 
00139 };