
none
max30102.h@1:02f411fefe6f, 2016-06-21 (annotated)
- Committer:
- Filea
- Date:
- Tue Jun 21 09:43:15 2016 +0000
- Revision:
- 1:02f411fefe6f
- Parent:
- max30100.h@0:e1e1947a9882
Modified the code from the library MAX30100 to work with MAX30102 pulse oximeter.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajeje41 | 0:e1e1947a9882 | 1 | /* |
Filea | 1:02f411fefe6f | 2 | * Library for the Maxim MAX30102 pulse oximetry system, I modified a copy of the MAX30100 library in May 2016 |
ajeje41 | 0:e1e1947a9882 | 3 | */ |
ajeje41 | 0:e1e1947a9882 | 4 | |
ajeje41 | 0:e1e1947a9882 | 5 | /* Define to prevent recursive inclusion -------------------------------------*/ |
Filea | 1:02f411fefe6f | 6 | #ifndef __MAX30102_H |
Filea | 1:02f411fefe6f | 7 | #define __MAX30102_H |
ajeje41 | 0:e1e1947a9882 | 8 | |
ajeje41 | 0:e1e1947a9882 | 9 | #include "mbed.h" |
ajeje41 | 0:e1e1947a9882 | 10 | |
ajeje41 | 0:e1e1947a9882 | 11 | |
ajeje41 | 0:e1e1947a9882 | 12 | /******************************************************************************/ |
ajeje41 | 0:e1e1947a9882 | 13 | /*********** PULSE OXIMETER AND HEART RATE REGISTER MAPPING **************/ |
ajeje41 | 0:e1e1947a9882 | 14 | /******************************************************************************/ |
ajeje41 | 0:e1e1947a9882 | 15 | |
ajeje41 | 0:e1e1947a9882 | 16 | // status registers |
Filea | 1:02f411fefe6f | 17 | #define MAX30102_INT_STATUS 0x00 |
Filea | 1:02f411fefe6f | 18 | #define MAX30102_INT_ENABLE 0x02 |
ajeje41 | 0:e1e1947a9882 | 19 | |
ajeje41 | 0:e1e1947a9882 | 20 | // FIFO registers |
Filea | 1:02f411fefe6f | 21 | #define MAX30102_FIFO_W_POINTER 0x04 |
Filea | 1:02f411fefe6f | 22 | #define MAX30102_OVR_COUNTER 0x05 |
Filea | 1:02f411fefe6f | 23 | #define MAX30102_FIFO_R_POINTER 0x06 |
Filea | 1:02f411fefe6f | 24 | #define MAX30102_FIFO_DATA_REG 0x07 |
ajeje41 | 0:e1e1947a9882 | 25 | |
ajeje41 | 0:e1e1947a9882 | 26 | // configuration registers |
Filea | 1:02f411fefe6f | 27 | #define MAX30102_FIFO_CONFIG 0x08 |
Filea | 1:02f411fefe6f | 28 | #define MAX30102_CONFIG 0x09 |
Filea | 1:02f411fefe6f | 29 | #define MAX30102_SPO2_CONFIG 0x0A |
Filea | 1:02f411fefe6f | 30 | #define MAX30102_LED_CONFIG_1 0x0C |
Filea | 1:02f411fefe6f | 31 | #define MAX30102_LED_CONFIG_2 0x0D |
ajeje41 | 0:e1e1947a9882 | 32 | |
ajeje41 | 0:e1e1947a9882 | 33 | // temperature registers |
Filea | 1:02f411fefe6f | 34 | #define MAX30102_TEMP_INTEGER 0x1F |
Filea | 1:02f411fefe6f | 35 | #define MAX30102_TEMP_FRACTION 0x20 |
Filea | 1:02f411fefe6f | 36 | #define MAX30102_TEMP_CONFIG 0x21 |
ajeje41 | 0:e1e1947a9882 | 37 | |
ajeje41 | 0:e1e1947a9882 | 38 | // PART ID registers |
Filea | 1:02f411fefe6f | 39 | #define MAX30102_REVISION_ID 0xFE |
Filea | 1:02f411fefe6f | 40 | #define MAX30102_PART_ID 0xFF |
ajeje41 | 0:e1e1947a9882 | 41 | |
Filea | 1:02f411fefe6f | 42 | #define I_AM_MAX30102 0x15 |
ajeje41 | 0:e1e1947a9882 | 43 | |
ajeje41 | 0:e1e1947a9882 | 44 | /************************************** REGISTERS VALUE *******************************************/ |
ajeje41 | 0:e1e1947a9882 | 45 | |
ajeje41 | 0:e1e1947a9882 | 46 | // I2C address |
Filea | 1:02f411fefe6f | 47 | #define MAX30102_ADDRESS 0xAE |
ajeje41 | 0:e1e1947a9882 | 48 | |
ajeje41 | 0:e1e1947a9882 | 49 | //Enable interrupts |
Filea | 1:02f411fefe6f | 50 | #define MAX30102_INT_ENB_A_FULL ((uint8_t)0x80) |
Filea | 1:02f411fefe6f | 51 | #define MAX30102_INT_ENB_TEMP_RDY ((uint8_t)0x40) |
Filea | 1:02f411fefe6f | 52 | #define MAX30102_INT_ENB_HR_RDY ((uint8_t)0x20) |
Filea | 1:02f411fefe6f | 53 | #define MAX30102_INT_ENB_SO2_RDY ((uint8_t)0x10) |
ajeje41 | 0:e1e1947a9882 | 54 | |
ajeje41 | 0:e1e1947a9882 | 55 | //Mode configuration |
Filea | 1:02f411fefe6f | 56 | #define MAX30102_MODE_SHDN ((uint8_t)0x80) // Bit 7 high |
Filea | 1:02f411fefe6f | 57 | #define MAX30102_MODE_RESET ((uint8_t)0x40) // Bit 6 high |
Filea | 1:02f411fefe6f | 58 | #define MAX30102_MODE_TEMP_EN ((uint8_t)0x01) |
Filea | 1:02f411fefe6f | 59 | #define MAX30102_MODE_HR ((uint8_t)0x02) |
Filea | 1:02f411fefe6f | 60 | #define MAX30102_MODE_SPO2 ((uint8_t)0x03) |
ajeje41 | 0:e1e1947a9882 | 61 | |
ajeje41 | 0:e1e1947a9882 | 62 | //SPO2 configuration |
Filea | 1:02f411fefe6f | 63 | #define MAX30102_SPO2_HI_RES_EN ((uint8_t)0x40) |
ajeje41 | 0:e1e1947a9882 | 64 | |
ajeje41 | 0:e1e1947a9882 | 65 | typedef enum{ // This is the same for both LEDs |
Filea | 1:02f411fefe6f | 66 | pw68, // 68us pulse, ADC 15 |
Filea | 1:02f411fefe6f | 67 | pw118, // 118us pulse, ADC 16 |
Filea | 1:02f411fefe6f | 68 | pw215, // 215us pulse, ADC 17 |
Filea | 1:02f411fefe6f | 69 | pw411 // 411us pulse, ADC 18 |
ajeje41 | 0:e1e1947a9882 | 70 | }pulseWidth; |
ajeje41 | 0:e1e1947a9882 | 71 | |
ajeje41 | 0:e1e1947a9882 | 72 | typedef enum{ |
ajeje41 | 0:e1e1947a9882 | 73 | sr50, // 50 samples per second |
ajeje41 | 0:e1e1947a9882 | 74 | sr100, // 100 samples per second |
ajeje41 | 0:e1e1947a9882 | 75 | sr200, // 200 samples per second |
ajeje41 | 0:e1e1947a9882 | 76 | sr400, // 400 samples per second |
ajeje41 | 0:e1e1947a9882 | 77 | sr800, // 800 samples per second |
ajeje41 | 0:e1e1947a9882 | 78 | sr1000 // 1000 samples per second |
ajeje41 | 0:e1e1947a9882 | 79 | }sampleRate; |
ajeje41 | 0:e1e1947a9882 | 80 | |
ajeje41 | 0:e1e1947a9882 | 81 | typedef enum{ |
ajeje41 | 0:e1e1947a9882 | 82 | i0, // No current |
ajeje41 | 0:e1e1947a9882 | 83 | i4, // 4.4mA |
ajeje41 | 0:e1e1947a9882 | 84 | i8, // 7.6mA |
ajeje41 | 0:e1e1947a9882 | 85 | i11, // 11.0mA |
ajeje41 | 0:e1e1947a9882 | 86 | i14, // 14.2mA |
ajeje41 | 0:e1e1947a9882 | 87 | i17, // 17.4mA |
ajeje41 | 0:e1e1947a9882 | 88 | i21, // 20.8mA |
ajeje41 | 0:e1e1947a9882 | 89 | i27, // 27.1mA |
ajeje41 | 0:e1e1947a9882 | 90 | i31, // 30.6mA |
ajeje41 | 0:e1e1947a9882 | 91 | i34, // 33.8mA |
ajeje41 | 0:e1e1947a9882 | 92 | i37, // 37.0mA |
ajeje41 | 0:e1e1947a9882 | 93 | i40, // 40.2mA |
ajeje41 | 0:e1e1947a9882 | 94 | i44, // 43.6mA |
ajeje41 | 0:e1e1947a9882 | 95 | i47, // 46.8mA |
ajeje41 | 0:e1e1947a9882 | 96 | i50 // 50.0mA |
ajeje41 | 0:e1e1947a9882 | 97 | }ledCurrent; |
ajeje41 | 0:e1e1947a9882 | 98 | |
ajeje41 | 0:e1e1947a9882 | 99 | typedef enum{ |
ajeje41 | 0:e1e1947a9882 | 100 | low, // low resolution SPO2 |
Filea | 1:02f411fefe6f | 101 | high // high resolution SPO2 (18 bit with 411us LED pulse width) |
ajeje41 | 0:e1e1947a9882 | 102 | }high_resolution; |
ajeje41 | 0:e1e1947a9882 | 103 | |
ajeje41 | 0:e1e1947a9882 | 104 | typedef enum |
ajeje41 | 0:e1e1947a9882 | 105 | { |
ajeje41 | 0:e1e1947a9882 | 106 | OXIMETER_OK = 0, |
ajeje41 | 0:e1e1947a9882 | 107 | OXIMETER_ERROR = 1, |
ajeje41 | 0:e1e1947a9882 | 108 | OXIMETER_TIMEOUT = 2, |
ajeje41 | 0:e1e1947a9882 | 109 | OXIMETER_NOT_IMPLEMENTED = 3 |
ajeje41 | 0:e1e1947a9882 | 110 | } OXIMETER_StatusTypeDef; |
ajeje41 | 0:e1e1947a9882 | 111 | |
ajeje41 | 0:e1e1947a9882 | 112 | /** |
Filea | 1:02f411fefe6f | 113 | * @brief MAX30102 driver extended internal structure definition |
ajeje41 | 0:e1e1947a9882 | 114 | */ |
ajeje41 | 0:e1e1947a9882 | 115 | typedef struct |
ajeje41 | 0:e1e1947a9882 | 116 | { |
ajeje41 | 0:e1e1947a9882 | 117 | OXIMETER_StatusTypeDef (*Enable_Free_Fall_Detection) (void); |
ajeje41 | 0:e1e1947a9882 | 118 | OXIMETER_StatusTypeDef (*Disable_Free_Fall_Detection) (void); |
ajeje41 | 0:e1e1947a9882 | 119 | OXIMETER_StatusTypeDef (*Get_Status_Free_Fall_Detection) (uint8_t *); |
Filea | 1:02f411fefe6f | 120 | } MAX30102_DrvExtTypeDef; |
ajeje41 | 0:e1e1947a9882 | 121 | |
Filea | 1:02f411fefe6f | 122 | class MAX30102 { |
ajeje41 | 0:e1e1947a9882 | 123 | public: |
ajeje41 | 0:e1e1947a9882 | 124 | |
ajeje41 | 0:e1e1947a9882 | 125 | /* Public Methods */ |
ajeje41 | 0:e1e1947a9882 | 126 | |
Filea | 1:02f411fefe6f | 127 | uint32_t HR; // Last heart rate datapoint |
Filea | 1:02f411fefe6f | 128 | uint32_t SPO2; // Last oximetry datapoint |
ajeje41 | 0:e1e1947a9882 | 129 | |
ajeje41 | 0:e1e1947a9882 | 130 | void setLEDs(pulseWidth pw, ledCurrent red, ledCurrent ir); // Sets the LED state |
ajeje41 | 0:e1e1947a9882 | 131 | void setSPO2(sampleRate sr, high_resolution hi_res); // Setup the SPO2 sensor, disabled by default |
ajeje41 | 0:e1e1947a9882 | 132 | int getNumSamp(void); // Get number of samples |
ajeje41 | 0:e1e1947a9882 | 133 | void readSensor(void); // Updates the values |
ajeje41 | 0:e1e1947a9882 | 134 | void shutdown(void); // Instructs device to power-save |
ajeje41 | 0:e1e1947a9882 | 135 | void reset(void); // Resets the device |
ajeje41 | 0:e1e1947a9882 | 136 | void startup(void); // Leaves power-save |
ajeje41 | 0:e1e1947a9882 | 137 | char getRevID(void); // Gets revision ID |
ajeje41 | 0:e1e1947a9882 | 138 | char getPartID(void); // Gets part ID |
Filea | 1:02f411fefe6f | 139 | void begin(pulseWidth pw = pw411, // Longest pulseWidth |
ajeje41 | 0:e1e1947a9882 | 140 | ledCurrent ir = i50, // Highest current |
ajeje41 | 0:e1e1947a9882 | 141 | sampleRate sr = sr100); // 2nd lowest sampleRate |
ajeje41 | 0:e1e1947a9882 | 142 | void init(pulseWidth pw, sampleRate sr, high_resolution hi_res, ledCurrent red, ledCurrent ir); |
ajeje41 | 0:e1e1947a9882 | 143 | void setTemp(void); |
ajeje41 | 0:e1e1947a9882 | 144 | int readTemp(void); |
ajeje41 | 0:e1e1947a9882 | 145 | void setSPO2mode(void); |
ajeje41 | 0:e1e1947a9882 | 146 | void setInterruptSPO2(void); |
ajeje41 | 0:e1e1947a9882 | 147 | void printRegisters(void); // Dumps contents of registers for debug |
ajeje41 | 0:e1e1947a9882 | 148 | }; |
ajeje41 | 0:e1e1947a9882 | 149 | |
Filea | 1:02f411fefe6f | 150 | #endif /* __MAX30102_H */ |