Qiao li
/
MAX86150_evkit_board_OK
none
max30100.h@0:e1e1947a9882, 2016-04-03 (annotated)
- Committer:
- ajeje41
- Date:
- Sun Apr 03 13:43:19 2016 +0000
- Revision:
- 0:e1e1947a9882
StepOne (store accelerometer value)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ajeje41 | 0:e1e1947a9882 | 1 | /* |
ajeje41 | 0:e1e1947a9882 | 2 | Library for the Maxim MAX30100 pulse oximetry system |
ajeje41 | 0:e1e1947a9882 | 3 | */ |
ajeje41 | 0:e1e1947a9882 | 4 | |
ajeje41 | 0:e1e1947a9882 | 5 | /* Define to prevent recursive inclusion -------------------------------------*/ |
ajeje41 | 0:e1e1947a9882 | 6 | #ifndef __MAX30100_H |
ajeje41 | 0:e1e1947a9882 | 7 | #define __MAX30100_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 |
ajeje41 | 0:e1e1947a9882 | 17 | #define MAX30100_INT_STATUS 0x00 |
ajeje41 | 0:e1e1947a9882 | 18 | #define MAX30100_INT_ENABLE 0x01 |
ajeje41 | 0:e1e1947a9882 | 19 | |
ajeje41 | 0:e1e1947a9882 | 20 | // FIFO registers |
ajeje41 | 0:e1e1947a9882 | 21 | #define MAX30100_FIFO_W_POINTER 0x02 |
ajeje41 | 0:e1e1947a9882 | 22 | #define MAX30100_OVR_COUNTER 0x03 |
ajeje41 | 0:e1e1947a9882 | 23 | #define MAX30100_FIFO_R_POINTER 0x04 |
ajeje41 | 0:e1e1947a9882 | 24 | #define MAX30100_FIFO_DATA_REG 0x05 |
ajeje41 | 0:e1e1947a9882 | 25 | |
ajeje41 | 0:e1e1947a9882 | 26 | // configuration registers |
ajeje41 | 0:e1e1947a9882 | 27 | #define MAX30100_CONFIG 0x06 |
ajeje41 | 0:e1e1947a9882 | 28 | #define MAX30100_SPO2_CONFIG 0x07 |
ajeje41 | 0:e1e1947a9882 | 29 | #define MAX30100_LED_CONFIG 0x09 |
ajeje41 | 0:e1e1947a9882 | 30 | |
ajeje41 | 0:e1e1947a9882 | 31 | // temperature registers |
ajeje41 | 0:e1e1947a9882 | 32 | #define MAX30100_TEMP_INTEGER 0x16 |
ajeje41 | 0:e1e1947a9882 | 33 | #define MAX30100_TEMP_FRACTION 0x17 |
ajeje41 | 0:e1e1947a9882 | 34 | |
ajeje41 | 0:e1e1947a9882 | 35 | // PART ID registers |
ajeje41 | 0:e1e1947a9882 | 36 | #define MAX30100_REVISION_ID 0xFE |
ajeje41 | 0:e1e1947a9882 | 37 | #define MAX30100_PART_ID 0xFF |
ajeje41 | 0:e1e1947a9882 | 38 | |
ajeje41 | 0:e1e1947a9882 | 39 | #define I_AM_MAX30100 0x11 |
ajeje41 | 0:e1e1947a9882 | 40 | |
ajeje41 | 0:e1e1947a9882 | 41 | /************************************** REGISTERS VALUE *******************************************/ |
ajeje41 | 0:e1e1947a9882 | 42 | |
ajeje41 | 0:e1e1947a9882 | 43 | // I2C address |
ajeje41 | 0:e1e1947a9882 | 44 | #define MAX30100_ADDRESS 0xAE |
ajeje41 | 0:e1e1947a9882 | 45 | |
ajeje41 | 0:e1e1947a9882 | 46 | //Enable interrupts |
ajeje41 | 0:e1e1947a9882 | 47 | #define MAX30100_INT_ENB_A_FULL ((uint8_t)0x80) |
ajeje41 | 0:e1e1947a9882 | 48 | #define MAX30100_INT_ENB_TEMP_RDY ((uint8_t)0x40) |
ajeje41 | 0:e1e1947a9882 | 49 | #define MAX30100_INT_ENB_HR_RDY ((uint8_t)0x20) |
ajeje41 | 0:e1e1947a9882 | 50 | #define MAX30100_INT_ENB_SO2_RDY ((uint8_t)0x10) |
ajeje41 | 0:e1e1947a9882 | 51 | |
ajeje41 | 0:e1e1947a9882 | 52 | //Mode configuration |
ajeje41 | 0:e1e1947a9882 | 53 | #define MAX30100_MODE_SHDN ((uint8_t)0x80) |
ajeje41 | 0:e1e1947a9882 | 54 | #define MAX30100_MODE_RESET ((uint8_t)0x40) |
ajeje41 | 0:e1e1947a9882 | 55 | #define MAX30100_MODE_TEMP_EN ((uint8_t)0x08) |
ajeje41 | 0:e1e1947a9882 | 56 | #define MAX30100_MODE_HR ((uint8_t)0x02) |
ajeje41 | 0:e1e1947a9882 | 57 | #define MAX30100_MODE_SPO2 ((uint8_t)0x03) |
ajeje41 | 0:e1e1947a9882 | 58 | |
ajeje41 | 0:e1e1947a9882 | 59 | //SPO2 configuration |
ajeje41 | 0:e1e1947a9882 | 60 | #define MAX30100_SPO2_HI_RES_EN ((uint8_t)0x40) |
ajeje41 | 0:e1e1947a9882 | 61 | |
ajeje41 | 0:e1e1947a9882 | 62 | typedef enum{ // This is the same for both LEDs |
ajeje41 | 0:e1e1947a9882 | 63 | pw200, // 200us pulse |
ajeje41 | 0:e1e1947a9882 | 64 | pw400, // 400us pulse |
ajeje41 | 0:e1e1947a9882 | 65 | pw800, // 800us pulse |
ajeje41 | 0:e1e1947a9882 | 66 | pw1600 // 1600us pulse |
ajeje41 | 0:e1e1947a9882 | 67 | }pulseWidth; |
ajeje41 | 0:e1e1947a9882 | 68 | |
ajeje41 | 0:e1e1947a9882 | 69 | typedef enum{ |
ajeje41 | 0:e1e1947a9882 | 70 | sr50, // 50 samples per second |
ajeje41 | 0:e1e1947a9882 | 71 | sr100, // 100 samples per second |
ajeje41 | 0:e1e1947a9882 | 72 | sr167, // 167 samples per second |
ajeje41 | 0:e1e1947a9882 | 73 | sr200, // 200 samples per second |
ajeje41 | 0:e1e1947a9882 | 74 | sr400, // 400 samples per second |
ajeje41 | 0:e1e1947a9882 | 75 | sr600, // 600 samples per second |
ajeje41 | 0:e1e1947a9882 | 76 | sr800, // 800 samples per second |
ajeje41 | 0:e1e1947a9882 | 77 | sr1000 // 1000 samples per second |
ajeje41 | 0:e1e1947a9882 | 78 | }sampleRate; |
ajeje41 | 0:e1e1947a9882 | 79 | |
ajeje41 | 0:e1e1947a9882 | 80 | typedef enum{ |
ajeje41 | 0:e1e1947a9882 | 81 | i0, // No current |
ajeje41 | 0:e1e1947a9882 | 82 | i4, // 4.4mA |
ajeje41 | 0:e1e1947a9882 | 83 | i8, // 7.6mA |
ajeje41 | 0:e1e1947a9882 | 84 | i11, // 11.0mA |
ajeje41 | 0:e1e1947a9882 | 85 | i14, // 14.2mA |
ajeje41 | 0:e1e1947a9882 | 86 | i17, // 17.4mA |
ajeje41 | 0:e1e1947a9882 | 87 | i21, // 20.8mA |
ajeje41 | 0:e1e1947a9882 | 88 | i27, // 27.1mA |
ajeje41 | 0:e1e1947a9882 | 89 | i31, // 30.6mA |
ajeje41 | 0:e1e1947a9882 | 90 | i34, // 33.8mA |
ajeje41 | 0:e1e1947a9882 | 91 | i37, // 37.0mA |
ajeje41 | 0:e1e1947a9882 | 92 | i40, // 40.2mA |
ajeje41 | 0:e1e1947a9882 | 93 | i44, // 43.6mA |
ajeje41 | 0:e1e1947a9882 | 94 | i47, // 46.8mA |
ajeje41 | 0:e1e1947a9882 | 95 | i50 // 50.0mA |
ajeje41 | 0:e1e1947a9882 | 96 | }ledCurrent; |
ajeje41 | 0:e1e1947a9882 | 97 | |
ajeje41 | 0:e1e1947a9882 | 98 | typedef enum{ |
ajeje41 | 0:e1e1947a9882 | 99 | low, // low resolution SPO2 |
ajeje41 | 0:e1e1947a9882 | 100 | high // high resolution SPO2 (16 bit with 1.6ms LED pulse width) |
ajeje41 | 0:e1e1947a9882 | 101 | }high_resolution; |
ajeje41 | 0:e1e1947a9882 | 102 | |
ajeje41 | 0:e1e1947a9882 | 103 | typedef enum |
ajeje41 | 0:e1e1947a9882 | 104 | { |
ajeje41 | 0:e1e1947a9882 | 105 | OXIMETER_OK = 0, |
ajeje41 | 0:e1e1947a9882 | 106 | OXIMETER_ERROR = 1, |
ajeje41 | 0:e1e1947a9882 | 107 | OXIMETER_TIMEOUT = 2, |
ajeje41 | 0:e1e1947a9882 | 108 | OXIMETER_NOT_IMPLEMENTED = 3 |
ajeje41 | 0:e1e1947a9882 | 109 | } OXIMETER_StatusTypeDef; |
ajeje41 | 0:e1e1947a9882 | 110 | |
ajeje41 | 0:e1e1947a9882 | 111 | /** |
ajeje41 | 0:e1e1947a9882 | 112 | * @brief MAX30100 driver extended internal structure definition |
ajeje41 | 0:e1e1947a9882 | 113 | */ |
ajeje41 | 0:e1e1947a9882 | 114 | typedef struct |
ajeje41 | 0:e1e1947a9882 | 115 | { |
ajeje41 | 0:e1e1947a9882 | 116 | OXIMETER_StatusTypeDef (*Enable_Free_Fall_Detection) (void); |
ajeje41 | 0:e1e1947a9882 | 117 | OXIMETER_StatusTypeDef (*Disable_Free_Fall_Detection) (void); |
ajeje41 | 0:e1e1947a9882 | 118 | OXIMETER_StatusTypeDef (*Get_Status_Free_Fall_Detection) (uint8_t *); |
ajeje41 | 0:e1e1947a9882 | 119 | } MAX30100_DrvExtTypeDef; |
ajeje41 | 0:e1e1947a9882 | 120 | |
ajeje41 | 0:e1e1947a9882 | 121 | class MAX30100 { |
ajeje41 | 0:e1e1947a9882 | 122 | public: |
ajeje41 | 0:e1e1947a9882 | 123 | |
ajeje41 | 0:e1e1947a9882 | 124 | /* Public Methods */ |
ajeje41 | 0:e1e1947a9882 | 125 | |
ajeje41 | 0:e1e1947a9882 | 126 | uint16_t HR; // Last heart rate datapoint |
ajeje41 | 0:e1e1947a9882 | 127 | uint16_t SPO2; // Last oximetry datapoint |
ajeje41 | 0:e1e1947a9882 | 128 | |
ajeje41 | 0:e1e1947a9882 | 129 | void setLEDs(pulseWidth pw, ledCurrent red, ledCurrent ir); // Sets the LED state |
ajeje41 | 0:e1e1947a9882 | 130 | void setSPO2(sampleRate sr, high_resolution hi_res); // Setup the SPO2 sensor, disabled by default |
ajeje41 | 0:e1e1947a9882 | 131 | int getNumSamp(void); // Get number of samples |
ajeje41 | 0:e1e1947a9882 | 132 | void readSensor(void); // Updates the values |
ajeje41 | 0:e1e1947a9882 | 133 | void shutdown(void); // Instructs device to power-save |
ajeje41 | 0:e1e1947a9882 | 134 | void reset(void); // Resets the device |
ajeje41 | 0:e1e1947a9882 | 135 | void startup(void); // Leaves power-save |
ajeje41 | 0:e1e1947a9882 | 136 | char getRevID(void); // Gets revision ID |
ajeje41 | 0:e1e1947a9882 | 137 | char getPartID(void); // Gets part ID |
ajeje41 | 0:e1e1947a9882 | 138 | void begin(pulseWidth pw = pw1600, // Longest pulseWidth |
ajeje41 | 0:e1e1947a9882 | 139 | ledCurrent ir = i50, // Highest current |
ajeje41 | 0:e1e1947a9882 | 140 | sampleRate sr = sr100); // 2nd lowest sampleRate |
ajeje41 | 0:e1e1947a9882 | 141 | void init(pulseWidth pw, sampleRate sr, high_resolution hi_res, ledCurrent red, ledCurrent ir); |
ajeje41 | 0:e1e1947a9882 | 142 | void setTemp(void); |
ajeje41 | 0:e1e1947a9882 | 143 | int readTemp(void); |
ajeje41 | 0:e1e1947a9882 | 144 | void setSPO2mode(void); |
ajeje41 | 0:e1e1947a9882 | 145 | void setInterruptSPO2(void); |
ajeje41 | 0:e1e1947a9882 | 146 | void printRegisters(void); // Dumps contents of registers for debug |
ajeje41 | 0:e1e1947a9882 | 147 | }; |
ajeje41 | 0:e1e1947a9882 | 148 | |
ajeje41 | 0:e1e1947a9882 | 149 | #endif /* __MAX30100_H */ |