Library for MAX30101, read/write functions for registers implemented.
Dependents: test_MAX30101 testSensor
MAX30101.h
00001 #ifndef _MAX30101_H_ 00002 #define _MAX30101_H_ 00003 /** 00004 * MAX30101 00005 * High-Sensitivity Pulse Oximeter and 00006 * Heart-Rate Sensor for Wearable Health 00007 */ 00008 00009 class MAX30101 00010 { 00011 public: 00012 /** 00013 * MAX30101 constructor 00014 * 00015 * @param sda SDA pin 00016 * @param scl SCL pin 00017 * @param addr 7bit address of the I2C peripheral 00018 */ 00019 MAX30101(PinName sda, PinName scl, int addr) ; 00020 00021 /** 00022 * MAX30101 destructor 00023 */ 00024 ~MAX30101() ; 00025 00026 /** 00027 * Get part id 00028 * @returns PART_ID 00029 */ 00030 uint8_t getID(void) ; 00031 00032 /** 00033 * Get revision id 00034 * @returns REV_ID 00035 */ 00036 uint8_t getRev(void) ; 00037 00038 /** 00039 * Get interrupt status 00040 * @returns interrupt Status 1 as MSB and interrupt Status 2 as LSB 00041 */ 00042 uint16_t getIntStatus(void) ; 00043 00044 /** 00045 * Get interrupt enable 00046 * @returns interrupt Enable 1 as MSB and interrupt Status 2 as LSB 00047 */ 00048 uint16_t getIntEnable(void) ; 00049 00050 /** 00051 * Set interrupt enable 00052 * @param mask uint16_t MSB for Enable 1 and LSB for Enable 2 00053 */ 00054 void setIntEnable(uint16_t mask) ; 00055 00056 /** 00057 * Get FIFO Write Pointer 00058 * @returns FIFO_WR_PTR 00059 */ 00060 uint8_t getFIFO_WR_PTR(void) ; 00061 00062 /** 00063 * Set FIFO Write Pointer 00064 * @param data uint8_t FIFO_WR_PTR[4:0] 00065 */ 00066 void setFIFO_WR_PTR(uint8_t data) ; 00067 00068 /** 00069 * Get FIFO Overflow Counter 00070 * @returns OVF_COUNTER 00071 */ 00072 uint8_t getOVF_COUNTER(void) ; 00073 00074 /** 00075 * Set FIFO Overflow Counter 00076 * @param data uint8_t OVF_COUNTER[4:0] 00077 */ 00078 void setOVF_COUNTER(uint8_t data) ; 00079 00080 /** 00081 * Get FIFO Read Pointer 00082 * @returns FIFO_RD_PTR 00083 */ 00084 uint8_t getFIFO_RD_PTR(void) ; 00085 00086 /** 00087 * Set FIFO Read Pointer 00088 * @param data uint8_t FIFO_RD_PTR[4:0] 00089 */ 00090 void setFIFO_RD_PTR(uint8_t data) ; 00091 00092 /** 00093 * Get FIFO Data 00094 * @returns FIFO_DATA 00095 */ 00096 uint8_t getFIFO_DATA(void) ; 00097 00098 /** 00099 * Set FIFO Data 00100 * @param FIFO_DATA[7:0] 00101 */ 00102 void setFIFO_DATA(uint8_t data) ; 00103 00104 /** 00105 * Get FIFO Confuguraion 00106 * @returns FIFO_CONFIG 00107 */ 00108 uint8_t getFIFO_CONFIG(void) ; 00109 00110 /** 00111 * Set FIFO Configuration 00112 * @param data uint8_t 00113 * @note bit[7:5] -> SMP_AVE[2:0] 00114 * @note bit[4] -> FIFO_ROLLOVER_EN 00115 * @note bit[3:0] -> FIFO_A_FULL[3:0] 00116 */ 00117 void setFIFO_CONFIG(uint8_t data) ; 00118 00119 /** 00120 * Get MODE Configuration 00121 * @returns MODE_CONFIG 00122 */ 00123 uint8_t getMODE_CONFIG(void) ; 00124 00125 /** 00126 * Set MODE Configuration 00127 * @param data uint8_t 00128 * @note bit[7] Shutdown Control (SHDN) 00129 * @note bit[6] Reset Control (RESET) 00130 * @note bit[5:3] (reserved) 00131 * @note bit[2:0] Mode Control (MODE) 00132 */ 00133 void setMODE_CONFIG(uint8_t data) ; 00134 00135 /** 00136 * Get SpO2 Configuration 00137 * @returns SPO2_CONFIG 00138 */ 00139 uint8_t getSPO2_CONFIG(void) ; 00140 00141 /** 00142 * Set SpO2 Configuration 00143 * @param data uint8_t 00144 * @note bit[7] (reserved) 00145 * @note bit[6:5] SpO2 ADC Range Control (SPO2_ADC_RGE[1:0]) 00146 * @note bit[4:2] SpO2 Sample Rate Control (SPO2_SR[2:0]) 00147 * @note bit[1:0] LED Pulse Width Control (LED_PW[1:0]) 00148 */ 00149 void setSPO2_CONFIG(uint8_t data) ; 00150 00151 /** 00152 * Get LED1 Pulse Amplitude 00153 * @returns LED1_PA 00154 */ 00155 uint8_t getLED1_PA(void) ; 00156 00157 /** 00158 * Set LED1 Pulse Amplitude 00159 * @param data uint8_t LED1_PA[7:0] 00160 */ 00161 void setLED1_PA(uint8_t data) ; 00162 00163 /** 00164 * Get LED2 Pulse Amplitude 00165 * @returns LED2_PA 00166 */ 00167 uint8_t getLED2_PA(void) ; 00168 00169 /** 00170 * Set LED2 Pulse Amplitude 00171 * @param data uint8_t LED2_PA[7:0] 00172 */ 00173 void setLED2_PA(uint8_t data) ; 00174 00175 /** 00176 * Get LED3 Pulse Amplitude 00177 * @returns LED3_PA 00178 */ 00179 uint8_t getLED3_PA(void) ; 00180 00181 /** 00182 * Set LED3 Pulse Amplitude 00183 * @param data uint8_t LED3_PA[7:0] 00184 */ 00185 void setLED3_PA(uint8_t data) ; 00186 00187 /** 00188 * Get Proximity Mode LED Pulse Amplitude 00189 * @returns PILOT_PA 00190 */ 00191 uint8_t getPILOT_PA(void) ; 00192 00193 /** 00194 * Set Proximity Mode LED Pulse Amplitude 00195 * @param data uint8_t PILOT_PA[7:0] 00196 */ 00197 void setPILOT_PA(uint8_t data) ; 00198 00199 /** 00200 * Get Multi-LED Mode Control Registers 00201 * @returns SLOT2, SLOT1, SLOT4, SLOT3 combined as uint16_t 00202 */ 00203 uint16_t getSLOT(void) ; 00204 00205 /** 00206 * Set Multi-LED Mode Control Registers 00207 * @param data uint16_t 00208 * @note bit[15] (reserved) 00209 * @note bit[14:12] SLOT2[2:0] 00210 * @note bit[11] (reserved) 00211 * @note bit[10:8] SLOT1[2:0] 00212 * @note bit[7] (reserved) 00213 * @note bit[6:4] SLOT4[2:0] 00214 * @note bit[3] (reserved) 00215 * @note bit[2:0] SLOT3[2:0] 00216 */ 00217 void setSLOT(uint16_t data) ; 00218 00219 /** 00220 * Get Temperature Data (Integer part) 00221 * @returns TINT 00222 */ 00223 uint8_t getTEMP_INT(void) ; 00224 00225 /** 00226 * Get Temperature Data (Fraction part) 00227 * @returns TFRAC 00228 */ 00229 uint8_t getTEMP_FRAC(void) ; 00230 00231 /** 00232 * Get Die Temperature Configure 00233 * @returns TEMP_EN 00234 */ 00235 uint8_t getTEMP_EN(void) ; 00236 00237 /** 00238 * Set Die Temperature Configure 00239 */ 00240 void setTEMP_EN(void) ; 00241 00242 /** 00243 * Get Temperature 00244 * @returns temperature as a float 00245 */ 00246 float getTEMP(void) ; 00247 00248 /** 00249 * Get Proximity Mode Interrupt Threshold 00250 * @returns PROX_INT_THR 00251 */ 00252 uint8_t getPROX_INT_THR(void) ; 00253 00254 /** 00255 * Set Proximity Mode Interrupt Threshold 00256 * @param data uint8_t PROX_INT_THRESH[7:0] 00257 */ 00258 void setPROX_INT_THR(uint8_t data) ; 00259 00260 /** 00261 * Clear FIFO 00262 */ 00263 void clearFIFO(void) ; 00264 00265 /** 00266 * Read FIFO 00267 * @returns FIFO data as uint32_t 00268 * @note FIFO data is always a 3-bytes data 00269 * @note byte1[1:0] : FIFO_DATA[17]-FIFO_DATA[16] 00270 * @note byte2[7:0] : FIFO_DATA[15]-FIFO_DATA[8] 00271 * @note byte3[7:0] : FIFO_DATA[7]-FIFO_DATA[0] 00272 * @note The data is left aligned, so FIFO_DATA[17] 00273 * @note is always MSB, although the data length 00274 * @note can be 18-bit ~ 15-bit 00275 */ 00276 uint32_t readFIFO(void) ; 00277 00278 /** 00279 * Reset 00280 */ 00281 void reset(void) ; 00282 00283 /* 00284 * some member functions here (yet to be written) 00285 */ 00286 00287 private: 00288 I2C m_i2c; 00289 int m_addr; 00290 void readRegs(int addr, uint8_t *data, int len) ; 00291 void writeRegs(uint8_t *data, int len) ; 00292 } ; 00293 00294 /* bits of Interrupt Status register */ 00295 /* In this class Interrupt Status 1 and 00296 * Interrupt Status 2 are combined to be a uint16_t 00297 */ 00298 #define INT_ST_A_FULL 0x8000 /* FIFO Almost Full Flag */ 00299 #define INT_ST_PPG_RGY 0x4000 /* New FIFO Data Ready */ 00300 #define INT_ST_ALC_OVF 0x2000 /* Ambient Light Cancellation Overflow */ 00301 #define INT_ST_PROX_INT 0x1000 /* Proximity Threshold Triggered */ 00302 #define INT_ST_PWR_RDY 0x0100 /* Power Ready Flag */ 00303 #define INT_ST_DIE_TEMP_RDY 0x0002 /* Internal Temperature Ready Flag */ 00304 /* bits of Interrupt Enable register */ 00305 #define INT_EN_A_FULL 0x8000 /* FIFO Almost Full Flag */ 00306 #define INT_EN_PPG_RGY 0x4000 /* New FIFO Data Ready */ 00307 #define INT_EN_ALC_OVF 0x2000 /* Ambient Light Cancellation Overflow */ 00308 #define INT_EN_PROX_INT 0x1000 /* Proximity Threshold Triggered */ 00309 #define INT_EN_DIE_TEMP_RDY 0x0002 /* Internal Temperature Ready Flag */ 00310 /* Mode configuration bits */ 00311 #define MODE_HR 0x02 /* Heart Rate mode */ 00312 #define MODE_SPO2 0x03 /* SpO2 mode */ 00313 #define MODE_MULTI_LED 0x07 /* Multi-LED mode */ 00314 #define MODE_RESET 0x40 /* Reset Control, this bit is auto clear */ 00315 #define MODE_SHDN 0x80 /* Shutdown Control */ 00316 00317 00318 #endif /* _MAX30101_H_ */
Generated on Tue Jul 12 2022 19:17:19 by 1.7.2