Library for MAX3010x optical sensors
MAX30105.cpp@1:411eb3796949, 2017-02-16 (annotated)
- Committer:
- switches
- Date:
- Thu Feb 16 22:01:02 2017 +0000
- Revision:
- 1:411eb3796949
- Parent:
- 0:62bc11b5bc43
Added class summary comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:62bc11b5bc43 | 1 | /** \file max30105.cpp ****************************************************** |
switches | 0:62bc11b5bc43 | 2 | * |
switches | 0:62bc11b5bc43 | 3 | * Project: MAXREFDES117# |
switches | 0:62bc11b5bc43 | 4 | * Filename: max30105.cpp |
switches | 0:62bc11b5bc43 | 5 | * Description: This module is an embedded controller driver for the MAX30105 |
switches | 0:62bc11b5bc43 | 6 | * |
switches | 0:62bc11b5bc43 | 7 | * ------------------------------------------------------------------------- */ |
switches | 0:62bc11b5bc43 | 8 | /******************************************************************************* |
switches | 0:62bc11b5bc43 | 9 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
switches | 0:62bc11b5bc43 | 10 | * |
switches | 0:62bc11b5bc43 | 11 | * Permission is hereby granted, free of charge, to any person obtaining a |
switches | 0:62bc11b5bc43 | 12 | * copy of this software and associated documentation files (the "Software"), |
switches | 0:62bc11b5bc43 | 13 | * to deal in the Software without restriction, including without limitation |
switches | 0:62bc11b5bc43 | 14 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
switches | 0:62bc11b5bc43 | 15 | * and/or sell copies of the Software, and to permit persons to whom the |
switches | 0:62bc11b5bc43 | 16 | * Software is furnished to do so, subject to the following conditions: |
switches | 0:62bc11b5bc43 | 17 | * |
switches | 0:62bc11b5bc43 | 18 | * The above copyright notice and this permission notice shall be included |
switches | 0:62bc11b5bc43 | 19 | * in all copies or substantial portions of the Software. |
switches | 0:62bc11b5bc43 | 20 | * |
switches | 0:62bc11b5bc43 | 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
switches | 0:62bc11b5bc43 | 22 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
switches | 0:62bc11b5bc43 | 23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
switches | 0:62bc11b5bc43 | 24 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
switches | 0:62bc11b5bc43 | 25 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
switches | 0:62bc11b5bc43 | 26 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
switches | 0:62bc11b5bc43 | 27 | * OTHER DEALINGS IN THE SOFTWARE. |
switches | 0:62bc11b5bc43 | 28 | * |
switches | 0:62bc11b5bc43 | 29 | * Except as contained in this notice, the name of Maxim Integrated |
switches | 0:62bc11b5bc43 | 30 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
switches | 0:62bc11b5bc43 | 31 | * Products, Inc. Branding Policy. |
switches | 0:62bc11b5bc43 | 32 | * |
switches | 0:62bc11b5bc43 | 33 | * The mere transfer of this software does not imply any licenses |
switches | 0:62bc11b5bc43 | 34 | * of trade secrets, proprietary technology, copyrights, patents, |
switches | 0:62bc11b5bc43 | 35 | * trademarks, maskwork rights, or any other form of intellectual |
switches | 0:62bc11b5bc43 | 36 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
switches | 0:62bc11b5bc43 | 37 | * ownership rights. |
switches | 0:62bc11b5bc43 | 38 | ******************************************************************************* |
switches | 0:62bc11b5bc43 | 39 | */ |
switches | 0:62bc11b5bc43 | 40 | #include "mbed.h" |
switches | 0:62bc11b5bc43 | 41 | #include "MAX30105.h" |
switches | 0:62bc11b5bc43 | 42 | |
switches | 0:62bc11b5bc43 | 43 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 44 | MAX30105::MAX30105(I2C &i2c): _i2c(i2c) |
switches | 0:62bc11b5bc43 | 45 | { |
switches | 0:62bc11b5bc43 | 46 | } |
switches | 0:62bc11b5bc43 | 47 | |
switches | 0:62bc11b5bc43 | 48 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 49 | MAX30105::~MAX30105() |
switches | 0:62bc11b5bc43 | 50 | { |
switches | 0:62bc11b5bc43 | 51 | } |
switches | 0:62bc11b5bc43 | 52 | |
switches | 0:62bc11b5bc43 | 53 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 54 | int MAX30105::writeReg(registers_t reg, char value) |
switches | 0:62bc11b5bc43 | 55 | { |
switches | 0:62bc11b5bc43 | 56 | char cmdData[2] = { (char)reg, value }; |
switches | 0:62bc11b5bc43 | 57 | |
switches | 0:62bc11b5bc43 | 58 | if (_i2c.write(MAX30105_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) { |
switches | 0:62bc11b5bc43 | 59 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 60 | } |
switches | 0:62bc11b5bc43 | 61 | |
switches | 0:62bc11b5bc43 | 62 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 63 | } |
switches | 0:62bc11b5bc43 | 64 | |
switches | 0:62bc11b5bc43 | 65 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 66 | int MAX30105::readReg(registers_t reg, char *value) |
switches | 0:62bc11b5bc43 | 67 | { |
switches | 0:62bc11b5bc43 | 68 | char cmdData[1] = { (char)reg }; |
switches | 0:62bc11b5bc43 | 69 | |
switches | 0:62bc11b5bc43 | 70 | if (_i2c.write(MAX30105_I2C_ADDR, cmdData, sizeof(cmdData)) != 0) { |
switches | 0:62bc11b5bc43 | 71 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 72 | } |
switches | 0:62bc11b5bc43 | 73 | |
switches | 0:62bc11b5bc43 | 74 | if (_i2c.read(MAX30105_I2C_ADDR, value, 1) != 0) { |
switches | 0:62bc11b5bc43 | 75 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 76 | } |
switches | 0:62bc11b5bc43 | 77 | |
switches | 0:62bc11b5bc43 | 78 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 79 | } |
switches | 0:62bc11b5bc43 | 80 | |
switches | 0:62bc11b5bc43 | 81 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 82 | int MAX30105::setSingleLED(smp_ave_t smpAve, |
switches | 0:62bc11b5bc43 | 83 | bool fifoRollOver, |
switches | 0:62bc11b5bc43 | 84 | fifo_a_full_t fifoAFull, |
switches | 0:62bc11b5bc43 | 85 | adc_rge_t adcRange, |
switches | 0:62bc11b5bc43 | 86 | smp_rt_t smpRate, |
switches | 0:62bc11b5bc43 | 87 | led_pw_t ledPW, |
switches | 0:62bc11b5bc43 | 88 | char led1PA) { |
switches | 0:62bc11b5bc43 | 89 | char dataBuf[4]; |
switches | 0:62bc11b5bc43 | 90 | _fifoConfiguration = (smpAve & MASK_SMP_AVE) | (fifoAFull & MASK_FIFO_A_FULL); |
switches | 0:62bc11b5bc43 | 91 | if(fifoRollOver) _fifoConfiguration |= MASK_FIFO_ROLLOVER_EN; |
switches | 0:62bc11b5bc43 | 92 | _modeConfiguration = (_modeConfiguration & MASK_SHDN) | MODE_1LED; |
switches | 0:62bc11b5bc43 | 93 | _spo2Configuration = (adcRange & MASK_ADC_RGE) | (smpRate & MASK_SMP_RT) | (ledPW & MASK_LED_PW); |
switches | 0:62bc11b5bc43 | 94 | _led1PulseAmplitude = led1PA; |
switches | 0:62bc11b5bc43 | 95 | dataBuf[0] = REG_LED1_PA; |
switches | 0:62bc11b5bc43 | 96 | dataBuf[1] = _led1PulseAmplitude; |
switches | 0:62bc11b5bc43 | 97 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 2) != 0) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 98 | dataBuf[0] = REG_FIFO_CONFIG; |
switches | 0:62bc11b5bc43 | 99 | dataBuf[1] = _fifoConfiguration; |
switches | 0:62bc11b5bc43 | 100 | dataBuf[2] = _modeConfiguration; |
switches | 0:62bc11b5bc43 | 101 | dataBuf[3] = _spo2Configuration; |
switches | 0:62bc11b5bc43 | 102 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 4) != 0) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 103 | |
switches | 0:62bc11b5bc43 | 104 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 105 | } |
switches | 0:62bc11b5bc43 | 106 | |
switches | 0:62bc11b5bc43 | 107 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 108 | int MAX30105::setDualLED(smp_ave_t smpAve, |
switches | 0:62bc11b5bc43 | 109 | bool fifoRollOver, |
switches | 0:62bc11b5bc43 | 110 | fifo_a_full_t fifoAFull, |
switches | 0:62bc11b5bc43 | 111 | adc_rge_t adcRange, |
switches | 0:62bc11b5bc43 | 112 | smp_rt_t smpRate, |
switches | 0:62bc11b5bc43 | 113 | led_pw_t ledPW, |
switches | 0:62bc11b5bc43 | 114 | char led1PA, |
switches | 0:62bc11b5bc43 | 115 | char led2PA) { |
switches | 0:62bc11b5bc43 | 116 | char dataBuf[4]; |
switches | 0:62bc11b5bc43 | 117 | _fifoConfiguration = (smpAve & MASK_SMP_AVE) | (fifoAFull & MASK_FIFO_A_FULL); |
switches | 0:62bc11b5bc43 | 118 | if(fifoRollOver) _fifoConfiguration |= MASK_FIFO_ROLLOVER_EN; |
switches | 0:62bc11b5bc43 | 119 | _modeConfiguration = (_modeConfiguration & MASK_SHDN) | MODE_2LED; |
switches | 0:62bc11b5bc43 | 120 | _spo2Configuration = (adcRange & MASK_ADC_RGE) | (smpRate & MASK_SMP_RT) | (ledPW & MASK_LED_PW); |
switches | 0:62bc11b5bc43 | 121 | _led1PulseAmplitude = led1PA; |
switches | 0:62bc11b5bc43 | 122 | _led2PulseAmplitude = led2PA; |
switches | 0:62bc11b5bc43 | 123 | dataBuf[0] = REG_LED1_PA; |
switches | 0:62bc11b5bc43 | 124 | dataBuf[1] = _led1PulseAmplitude; |
switches | 0:62bc11b5bc43 | 125 | dataBuf[2] = _led2PulseAmplitude; |
switches | 0:62bc11b5bc43 | 126 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 3) != 0) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 127 | dataBuf[0] = REG_FIFO_CONFIG; |
switches | 0:62bc11b5bc43 | 128 | dataBuf[1] = _fifoConfiguration; |
switches | 0:62bc11b5bc43 | 129 | dataBuf[2] = _modeConfiguration; |
switches | 0:62bc11b5bc43 | 130 | dataBuf[3] = _spo2Configuration; |
switches | 0:62bc11b5bc43 | 131 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 4) != 0) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 132 | |
switches | 0:62bc11b5bc43 | 133 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 134 | } |
switches | 0:62bc11b5bc43 | 135 | |
switches | 0:62bc11b5bc43 | 136 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 137 | int MAX30105::setMultiLED(smp_ave_t smpAve, |
switches | 0:62bc11b5bc43 | 138 | bool fifoRollOver, |
switches | 0:62bc11b5bc43 | 139 | fifo_a_full_t fifoAFull, |
switches | 0:62bc11b5bc43 | 140 | adc_rge_t adcRange, |
switches | 0:62bc11b5bc43 | 141 | smp_rt_t smpRate, |
switches | 0:62bc11b5bc43 | 142 | led_pw_t ledPW, |
switches | 0:62bc11b5bc43 | 143 | char led1PA, |
switches | 0:62bc11b5bc43 | 144 | char led2PA, |
switches | 0:62bc11b5bc43 | 145 | char led3PA, |
switches | 0:62bc11b5bc43 | 146 | char pilotPA, |
switches | 0:62bc11b5bc43 | 147 | slot_t slot1, |
switches | 0:62bc11b5bc43 | 148 | slot_t slot2, |
switches | 0:62bc11b5bc43 | 149 | slot_t slot3, |
switches | 0:62bc11b5bc43 | 150 | slot_t slot4) { |
switches | 0:62bc11b5bc43 | 151 | char dataBuf[4]; |
switches | 0:62bc11b5bc43 | 152 | _fifoConfiguration = (smpAve & MASK_SMP_AVE) | (fifoAFull & MASK_FIFO_A_FULL); |
switches | 0:62bc11b5bc43 | 153 | if(fifoRollOver) _fifoConfiguration |= MASK_FIFO_ROLLOVER_EN; |
switches | 0:62bc11b5bc43 | 154 | _modeConfiguration = (_modeConfiguration & MASK_SHDN) | MODE_MULTI; |
switches | 0:62bc11b5bc43 | 155 | _spo2Configuration = (adcRange & MASK_ADC_RGE) | (smpRate & MASK_SMP_RT) | (ledPW & MASK_LED_PW); |
switches | 0:62bc11b5bc43 | 156 | _led1PulseAmplitude = led1PA; |
switches | 0:62bc11b5bc43 | 157 | _led2PulseAmplitude = led2PA; |
switches | 0:62bc11b5bc43 | 158 | _led3PulseAmplitude = led3PA; |
switches | 0:62bc11b5bc43 | 159 | _pilotPulseAmplitude = pilotPA; |
switches | 0:62bc11b5bc43 | 160 | _multiLedControl1 = (slot2 << 4) | slot1; |
switches | 0:62bc11b5bc43 | 161 | _multiLedControl2 = (slot4 << 4) | slot3; |
switches | 0:62bc11b5bc43 | 162 | dataBuf[0] = REG_PILOT_PA; |
switches | 0:62bc11b5bc43 | 163 | dataBuf[1] = _pilotPulseAmplitude; |
switches | 0:62bc11b5bc43 | 164 | dataBuf[2] = _multiLedControl1; |
switches | 0:62bc11b5bc43 | 165 | dataBuf[3] = _multiLedControl2; |
switches | 0:62bc11b5bc43 | 166 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 4) != 0) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 167 | dataBuf[0] = REG_LED1_PA; |
switches | 0:62bc11b5bc43 | 168 | dataBuf[1] = _led1PulseAmplitude; |
switches | 0:62bc11b5bc43 | 169 | dataBuf[2] = _led2PulseAmplitude; |
switches | 0:62bc11b5bc43 | 170 | dataBuf[3] = _led3PulseAmplitude; |
switches | 0:62bc11b5bc43 | 171 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 4) != 0) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 172 | dataBuf[0] = REG_FIFO_CONFIG; |
switches | 0:62bc11b5bc43 | 173 | dataBuf[1] = _fifoConfiguration; |
switches | 0:62bc11b5bc43 | 174 | dataBuf[2] = _modeConfiguration; |
switches | 0:62bc11b5bc43 | 175 | dataBuf[3] = _spo2Configuration; |
switches | 0:62bc11b5bc43 | 176 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 4) != 0) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 177 | |
switches | 0:62bc11b5bc43 | 178 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 179 | } |
switches | 0:62bc11b5bc43 | 180 | |
switches | 0:62bc11b5bc43 | 181 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 182 | int MAX30105::init() |
switches | 0:62bc11b5bc43 | 183 | { |
switches | 0:62bc11b5bc43 | 184 | if(writeReg(REG_INTR_ENABLE_1,0xc0) != MAX30105_NO_ERROR) // INTR setting |
switches | 0:62bc11b5bc43 | 185 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 186 | if(writeReg(REG_INTR_ENABLE_2,0x00) != MAX30105_NO_ERROR) |
switches | 0:62bc11b5bc43 | 187 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 188 | if(writeReg(REG_FIFO_WR_PTR,0x00) != MAX30105_NO_ERROR) //FIFO_WR_PTR[4:0] |
switches | 0:62bc11b5bc43 | 189 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 190 | if(writeReg(REG_OVF_COUNTER,0x00) != MAX30105_NO_ERROR) //OVF_COUNTER[4:0] |
switches | 0:62bc11b5bc43 | 191 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 192 | if(writeReg(REG_FIFO_RD_PTR,0x00) != MAX30105_NO_ERROR) //FIFO_RD_PTR[4:0] |
switches | 0:62bc11b5bc43 | 193 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 194 | if(writeReg(REG_FIFO_CONFIG,0x0f) != MAX30105_NO_ERROR) //sample avg = 1, fifo rollover=false, fifo almost full = 17 |
switches | 0:62bc11b5bc43 | 195 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 196 | if(writeReg(REG_MODE_CONFIG,0x03) != MAX30105_NO_ERROR) //0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED |
switches | 0:62bc11b5bc43 | 197 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 198 | if(writeReg(REG_SPO2_CONFIG,0x27) != MAX30105_NO_ERROR) // SPO2_ADC range = 4096nA, SPO2 sample rate (100 Hz), LED pulseWidth (400uS) |
switches | 0:62bc11b5bc43 | 199 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 200 | if(writeReg(REG_LED1_PA,0x24) != MAX30105_NO_ERROR) //Choose value for ~ 7mA for LED1 |
switches | 0:62bc11b5bc43 | 201 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 202 | if(writeReg(REG_LED2_PA,0x24) != MAX30105_NO_ERROR) // Choose value for ~ 7mA for LED2 |
switches | 0:62bc11b5bc43 | 203 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 204 | if(writeReg(REG_PILOT_PA,0x7f) != MAX30105_NO_ERROR) // Choose value for ~ 25mA for Pilot LED |
switches | 0:62bc11b5bc43 | 205 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 206 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 207 | } |
switches | 0:62bc11b5bc43 | 208 | |
switches | 0:62bc11b5bc43 | 209 | int MAX30105::readFIFO(uint32_t *redLED, uint32_t *irLED) |
switches | 0:62bc11b5bc43 | 210 | { |
switches | 0:62bc11b5bc43 | 211 | uint32_t un_temp; |
switches | 0:62bc11b5bc43 | 212 | // char uch_temp; |
switches | 0:62bc11b5bc43 | 213 | *redLED=0; |
switches | 0:62bc11b5bc43 | 214 | *irLED=0; |
switches | 0:62bc11b5bc43 | 215 | char ach_i2c_data[6]; |
switches | 0:62bc11b5bc43 | 216 | |
switches | 0:62bc11b5bc43 | 217 | //read and clear status register |
switches | 0:62bc11b5bc43 | 218 | //readReg(REG_INTR_STATUS_1, &uch_temp); |
switches | 0:62bc11b5bc43 | 219 | //readReg(REG_INTR_STATUS_2, &uch_temp); |
switches | 0:62bc11b5bc43 | 220 | |
switches | 0:62bc11b5bc43 | 221 | ach_i2c_data[0]=REG_FIFO_DATA; |
switches | 0:62bc11b5bc43 | 222 | if(_i2c.write(MAX30105_I2C_ADDR, ach_i2c_data, 1, true)!=0) |
switches | 0:62bc11b5bc43 | 223 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 224 | if(_i2c.read(MAX30105_I2C_ADDR, ach_i2c_data, 6, false)!=0) { |
switches | 0:62bc11b5bc43 | 225 | return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 226 | } |
switches | 0:62bc11b5bc43 | 227 | un_temp=(unsigned char) ach_i2c_data[0]; |
switches | 0:62bc11b5bc43 | 228 | un_temp<<=16; |
switches | 0:62bc11b5bc43 | 229 | *redLED+=un_temp; |
switches | 0:62bc11b5bc43 | 230 | un_temp=(unsigned char) ach_i2c_data[1]; |
switches | 0:62bc11b5bc43 | 231 | un_temp<<=8; |
switches | 0:62bc11b5bc43 | 232 | *redLED+=un_temp; |
switches | 0:62bc11b5bc43 | 233 | un_temp=(unsigned char) ach_i2c_data[2]; |
switches | 0:62bc11b5bc43 | 234 | *redLED+=un_temp; |
switches | 0:62bc11b5bc43 | 235 | |
switches | 0:62bc11b5bc43 | 236 | un_temp=(unsigned char) ach_i2c_data[3]; |
switches | 0:62bc11b5bc43 | 237 | un_temp<<=16; |
switches | 0:62bc11b5bc43 | 238 | *irLED+=un_temp; |
switches | 0:62bc11b5bc43 | 239 | un_temp=(unsigned char) ach_i2c_data[4]; |
switches | 0:62bc11b5bc43 | 240 | un_temp<<=8; |
switches | 0:62bc11b5bc43 | 241 | *irLED+=un_temp; |
switches | 0:62bc11b5bc43 | 242 | un_temp=(unsigned char) ach_i2c_data[5]; |
switches | 0:62bc11b5bc43 | 243 | *irLED+=un_temp; |
switches | 0:62bc11b5bc43 | 244 | *redLED&=0x03FFFF; //Mask MSB [23:18] |
switches | 0:62bc11b5bc43 | 245 | *irLED&=0x03FFFF; //Mask MSB [23:18] |
switches | 0:62bc11b5bc43 | 246 | |
switches | 0:62bc11b5bc43 | 247 | |
switches | 0:62bc11b5bc43 | 248 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 249 | } |
switches | 0:62bc11b5bc43 | 250 | |
switches | 0:62bc11b5bc43 | 251 | |
switches | 0:62bc11b5bc43 | 252 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 253 | int MAX30105::getIntr1() |
switches | 0:62bc11b5bc43 | 254 | { |
switches | 0:62bc11b5bc43 | 255 | char * intStatus; |
switches | 0:62bc11b5bc43 | 256 | if(readReg(REG_INTR_STATUS_1, intStatus) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 257 | return (int)*intStatus; |
switches | 0:62bc11b5bc43 | 258 | } |
switches | 0:62bc11b5bc43 | 259 | |
switches | 0:62bc11b5bc43 | 260 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 261 | int MAX30105::getIntr2() |
switches | 0:62bc11b5bc43 | 262 | { |
switches | 0:62bc11b5bc43 | 263 | char * intStatus; |
switches | 0:62bc11b5bc43 | 264 | if(readReg(REG_INTR_STATUS_2, intStatus) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 265 | return (int)*intStatus; |
switches | 0:62bc11b5bc43 | 266 | } |
switches | 0:62bc11b5bc43 | 267 | |
switches | 0:62bc11b5bc43 | 268 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 269 | int MAX30105::enableIntr(char intrBits) |
switches | 0:62bc11b5bc43 | 270 | { |
switches | 0:62bc11b5bc43 | 271 | char intr1 = intrBits & (INTR_A_FULL|INTR_DATA_RDY|INTR_ALC_OVF|INTR_PROX); |
switches | 0:62bc11b5bc43 | 272 | char intr2 = intrBits & INTR_TEMP_RDY; |
switches | 0:62bc11b5bc43 | 273 | _interruptEnable1 |= intr1; |
switches | 0:62bc11b5bc43 | 274 | if(writeReg(REG_INTR_ENABLE_1, _interruptEnable1) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 275 | _interruptEnable2 |= intr2; |
switches | 0:62bc11b5bc43 | 276 | if(writeReg(REG_INTR_ENABLE_2, _interruptEnable2) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 277 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 278 | } |
switches | 0:62bc11b5bc43 | 279 | |
switches | 0:62bc11b5bc43 | 280 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 281 | int MAX30105::disableIntr(char intrBits) |
switches | 0:62bc11b5bc43 | 282 | { |
switches | 0:62bc11b5bc43 | 283 | char intr1 = intrBits & (INTR_A_FULL|INTR_DATA_RDY|INTR_ALC_OVF|INTR_PROX); |
switches | 0:62bc11b5bc43 | 284 | char intr2 = intrBits & INTR_TEMP_RDY; |
switches | 0:62bc11b5bc43 | 285 | _interruptEnable1 &= ~intr1; |
switches | 0:62bc11b5bc43 | 286 | if(writeReg(REG_INTR_ENABLE_1, _interruptEnable1) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 287 | _interruptEnable2 &= ~intr2; |
switches | 0:62bc11b5bc43 | 288 | if(writeReg(REG_INTR_ENABLE_2, _interruptEnable2) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 289 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 290 | } |
switches | 0:62bc11b5bc43 | 291 | |
switches | 0:62bc11b5bc43 | 292 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 293 | int MAX30105::setProx(char proxAmp, char proxThresh) |
switches | 0:62bc11b5bc43 | 294 | { |
switches | 0:62bc11b5bc43 | 295 | if(writeReg(REG_PILOT_PA, proxAmp) != MAX30105_NO_ERROR) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 296 | if(writeReg(REG_PROX_INTR_THRESH, proxThresh) != MAX30105_NO_ERROR) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 297 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 298 | } |
switches | 0:62bc11b5bc43 | 299 | |
switches | 0:62bc11b5bc43 | 300 | |
switches | 0:62bc11b5bc43 | 301 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 302 | float MAX30105::readTemperature() |
switches | 0:62bc11b5bc43 | 303 | { |
switches | 0:62bc11b5bc43 | 304 | char dataBuf[2]; |
switches | 0:62bc11b5bc43 | 305 | int8_t * dataSigned = reinterpret_cast<int8_t *>(dataBuf); |
switches | 0:62bc11b5bc43 | 306 | |
switches | 0:62bc11b5bc43 | 307 | if(writeReg(REG_TEMP_CONFIG, 0x01) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 308 | wait_ms(30); |
switches | 0:62bc11b5bc43 | 309 | if(readReg(REG_TEMP_CONFIG, dataBuf) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 310 | while (dataBuf[0]) { |
switches | 0:62bc11b5bc43 | 311 | // Thread::wait(1); |
switches | 0:62bc11b5bc43 | 312 | wait_ms(1); |
switches | 0:62bc11b5bc43 | 313 | if(readReg(REG_TEMP_CONFIG, dataBuf) != MAX30105_NO_ERROR) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 314 | } |
switches | 0:62bc11b5bc43 | 315 | dataBuf[0] = REG_TEMP_INT; |
switches | 0:62bc11b5bc43 | 316 | if (_i2c.write(MAX30105_I2C_ADDR, dataBuf, 1) != 0) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 317 | if (_i2c.read(MAX30105_I2C_ADDR, dataBuf, 2) != 0) return MAX30105_TEMP_ERROR; |
switches | 0:62bc11b5bc43 | 318 | return ((float)dataSigned[0] + ((float)dataSigned[1] * 0.0625)); |
switches | 0:62bc11b5bc43 | 319 | } |
switches | 0:62bc11b5bc43 | 320 | |
switches | 0:62bc11b5bc43 | 321 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 322 | int MAX30105::shutDown() |
switches | 0:62bc11b5bc43 | 323 | { |
switches | 0:62bc11b5bc43 | 324 | _modeConfiguration |= MASK_SHDN; |
switches | 0:62bc11b5bc43 | 325 | if(writeReg(REG_MODE_CONFIG, _modeConfiguration) != MAX30105_NO_ERROR) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 326 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 327 | } |
switches | 0:62bc11b5bc43 | 328 | |
switches | 0:62bc11b5bc43 | 329 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 330 | int MAX30105::wakeUp() |
switches | 0:62bc11b5bc43 | 331 | { |
switches | 0:62bc11b5bc43 | 332 | _modeConfiguration &= ~MASK_SHDN; |
switches | 0:62bc11b5bc43 | 333 | if(writeReg(REG_MODE_CONFIG, _modeConfiguration) != MAX30105_NO_ERROR) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 334 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 335 | } |
switches | 0:62bc11b5bc43 | 336 | |
switches | 0:62bc11b5bc43 | 337 | //****************************************************************************** |
switches | 0:62bc11b5bc43 | 338 | int MAX30105::softReset() |
switches | 0:62bc11b5bc43 | 339 | { |
switches | 0:62bc11b5bc43 | 340 | if(writeReg(REG_MODE_CONFIG, MASK_RESET) != MAX30105_NO_ERROR) return MAX30105_ERROR; |
switches | 0:62bc11b5bc43 | 341 | _interruptEnable1 = 0x00; |
switches | 0:62bc11b5bc43 | 342 | _interruptEnable2 = 0x00; |
switches | 0:62bc11b5bc43 | 343 | _fifoConfiguration = 0x00; |
switches | 0:62bc11b5bc43 | 344 | _modeConfiguration = 0x00; |
switches | 0:62bc11b5bc43 | 345 | _spo2Configuration = 0x00; |
switches | 0:62bc11b5bc43 | 346 | _led1PulseAmplitude = 0x00; |
switches | 0:62bc11b5bc43 | 347 | _led2PulseAmplitude = 0x00; |
switches | 0:62bc11b5bc43 | 348 | _led3PulseAmplitude = 0x00; |
switches | 0:62bc11b5bc43 | 349 | _pilotPulseAmplitude = 0x00; |
switches | 0:62bc11b5bc43 | 350 | _multiLedControl1 = 0x00; |
switches | 0:62bc11b5bc43 | 351 | _multiLedControl2 = 0x00; |
switches | 0:62bc11b5bc43 | 352 | _proxIntThreshold = 0x00; |
switches | 0:62bc11b5bc43 | 353 | return MAX30105_NO_ERROR; |
switches | 0:62bc11b5bc43 | 354 | } |