Linnéa Edström / MAX30102

Fork of MAX30100 by StepOne

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers max30102.h Source File

max30102.h

00001 /*
00002  * Library for the Maxim MAX30102 pulse oximetry system, I modified a copy of the MAX30100 library in May 2016
00003  */
00004 
00005 /* Define to prevent recursive inclusion -------------------------------------*/
00006 #ifndef __MAX30102_H
00007 #define __MAX30102_H
00008 
00009 #include "mbed.h"
00010 
00011 
00012 /******************************************************************************/
00013 /*********** PULSE OXIMETER AND HEART RATE REGISTER MAPPING  **************/
00014 /******************************************************************************/
00015 
00016 // status registers
00017 #define MAX30102_INT_STATUS          0x00
00018 #define MAX30102_INT_ENABLE          0x02
00019 
00020 // FIFO registers
00021 #define MAX30102_FIFO_W_POINTER      0x04
00022 #define MAX30102_OVR_COUNTER         0x05
00023 #define MAX30102_FIFO_R_POINTER      0x06
00024 #define MAX30102_FIFO_DATA_REG       0x07
00025 
00026 // configuration registers
00027 #define MAX30102_FIFO_CONFIG         0x08
00028 #define MAX30102_CONFIG              0x09
00029 #define MAX30102_SPO2_CONFIG         0x0A
00030 #define MAX30102_LED_CONFIG_1        0x0C 
00031 #define MAX30102_LED_CONFIG_2        0x0D  
00032 
00033 // temperature registers
00034 #define MAX30102_TEMP_INTEGER        0x1F
00035 #define MAX30102_TEMP_FRACTION       0x20
00036 #define MAX30102_TEMP_CONFIG         0x21
00037 
00038 // PART ID registers
00039 #define MAX30102_REVISION_ID         0xFE
00040 #define MAX30102_PART_ID             0xFF
00041 
00042 #define I_AM_MAX30102                0x15
00043 
00044 /************************************** REGISTERS VALUE *******************************************/
00045 
00046 // I2C address
00047 #define MAX30102_ADDRESS             0xAE
00048 
00049 //Enable interrupts
00050 #define MAX30102_INT_ENB_A_FULL      ((uint8_t)0x80)
00051 #define MAX30102_INT_ENB_TEMP_RDY    ((uint8_t)0x40)
00052 #define MAX30102_INT_ENB_HR_RDY      ((uint8_t)0x20)
00053 #define MAX30102_INT_ENB_SO2_RDY     ((uint8_t)0x10)
00054 
00055 //Mode configuration
00056 #define MAX30102_MODE_SHDN           ((uint8_t)0x80)      // Bit 7 high
00057 #define MAX30102_MODE_RESET          ((uint8_t)0x40)      // Bit 6 high
00058 #define MAX30102_MODE_TEMP_EN        ((uint8_t)0x01)
00059 #define MAX30102_MODE_HR             ((uint8_t)0x02)
00060 #define MAX30102_MODE_SPO2           ((uint8_t)0x03)
00061 
00062 //SPO2 configuration
00063 #define MAX30102_SPO2_HI_RES_EN           ((uint8_t)0x40)
00064 
00065 typedef enum{ // This is the same for both LEDs
00066     pw68,     // 68us pulse, ADC 15
00067     pw118,    // 118us pulse, ADC 16
00068     pw215,    // 215us pulse, ADC 17
00069     pw411     // 411us pulse, ADC 18
00070 }pulseWidth;
00071 
00072 typedef enum{
00073     sr50,    // 50 samples per second
00074     sr100,   // 100 samples per second
00075     sr200,   // 200 samples per second
00076     sr400,   // 400 samples per second
00077     sr800,   // 800 samples per second
00078     sr1000   // 1000 samples per second
00079 }sampleRate;
00080 
00081 typedef enum{
00082     i0,    // No current
00083     i4,    // 4.4mA
00084     i8,    // 7.6mA
00085     i11,   // 11.0mA
00086     i14,   // 14.2mA
00087     i17,   // 17.4mA
00088     i21,   // 20.8mA
00089     i27,   // 27.1mA
00090     i31,   // 30.6mA
00091     i34,   // 33.8mA
00092     i37,   // 37.0mA
00093     i40,   // 40.2mA
00094     i44,   // 43.6mA
00095     i47,   // 46.8mA
00096     i50    // 50.0mA
00097 }ledCurrent;
00098 
00099 typedef enum{
00100     low,    // low resolution SPO2
00101     high    // high resolution SPO2 (18 bit with 411us LED pulse width)
00102 }high_resolution;
00103 
00104 typedef enum
00105 {
00106     OXIMETER_OK = 0,
00107     OXIMETER_ERROR = 1,
00108     OXIMETER_TIMEOUT = 2,
00109     OXIMETER_NOT_IMPLEMENTED = 3
00110 } OXIMETER_StatusTypeDef;
00111 
00112 /**
00113  * @brief  MAX30102 driver extended internal structure definition
00114  */
00115 typedef struct
00116 {
00117     OXIMETER_StatusTypeDef (*Enable_Free_Fall_Detection) (void);
00118     OXIMETER_StatusTypeDef (*Disable_Free_Fall_Detection) (void);
00119     OXIMETER_StatusTypeDef (*Get_Status_Free_Fall_Detection) (uint8_t *);
00120 } MAX30102_DrvExtTypeDef;
00121 
00122 class MAX30102 {
00123 public:
00124         
00125     /* Public Methods */
00126     
00127     uint32_t HR;      // Last heart rate datapoint
00128     uint32_t SPO2;    // Last oximetry datapoint
00129     
00130     void  setLEDs(pulseWidth pw, ledCurrent red, ledCurrent ir);  // Sets the LED state
00131     void  setSPO2(sampleRate sr, high_resolution hi_res); // Setup the SPO2 sensor, disabled by default
00132     int   getNumSamp(void);       // Get number of samples
00133     void  readSensor(void);       // Updates the values
00134     void  shutdown(void);   // Instructs device to power-save
00135     void  reset(void);      // Resets the device
00136     void  startup(void);    // Leaves power-save
00137     char  getRevID(void);   // Gets revision ID
00138     char  getPartID(void);  // Gets part ID
00139     void  begin(pulseWidth pw = pw411,  // Longest pulseWidth
00140                 ledCurrent ir = i50,    // Highest current
00141                 sampleRate sr = sr100); // 2nd lowest sampleRate
00142     void  init(pulseWidth pw, sampleRate sr, high_resolution hi_res, ledCurrent red, ledCurrent ir);
00143     void  setTemp(void);
00144     int   readTemp(void);
00145     void  setSPO2mode(void);
00146     void  setInterruptSPO2(void);
00147     void  printRegisters(void); // Dumps contents of registers for debug
00148 };
00149 
00150 #endif /* __MAX30102_H */