Library for MAX30101 SpO2 and heart rate sensor

Dependents:   HeartRate HeartRate proj final_project_ee119 ... more

Committer:
j3
Date:
Thu May 18 20:53:46 2017 +0000
Revision:
6:302fb0f991d8
Parent:
5:be1dde31fe49
Child:
7:ce122c27358e
updated brief

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:2d0c91de9279 1 /*******************************************************************************
j3 0:2d0c91de9279 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:2d0c91de9279 3 *
j3 0:2d0c91de9279 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:2d0c91de9279 5 * copy of this software and associated documentation files (the "Software"),
j3 0:2d0c91de9279 6 * to deal in the Software without restriction, including without limitation
j3 0:2d0c91de9279 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:2d0c91de9279 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:2d0c91de9279 9 * Software is furnished to do so, subject to the following conditions:
j3 0:2d0c91de9279 10 *
j3 0:2d0c91de9279 11 * The above copyright notice and this permission notice shall be included
j3 0:2d0c91de9279 12 * in all copies or substantial portions of the Software.
j3 0:2d0c91de9279 13 *
j3 0:2d0c91de9279 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:2d0c91de9279 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:2d0c91de9279 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:2d0c91de9279 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:2d0c91de9279 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:2d0c91de9279 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:2d0c91de9279 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:2d0c91de9279 21 *
j3 0:2d0c91de9279 22 * Except as contained in this notice, the name of Maxim Integrated
j3 0:2d0c91de9279 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:2d0c91de9279 24 * Products, Inc. Branding Policy.
j3 0:2d0c91de9279 25 *
j3 0:2d0c91de9279 26 * The mere transfer of this software does not imply any licenses
j3 0:2d0c91de9279 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:2d0c91de9279 28 * trademarks, maskwork rights, or any other form of intellectual
j3 0:2d0c91de9279 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:2d0c91de9279 30 * ownership rights.
j3 0:2d0c91de9279 31 *******************************************************************************
j3 0:2d0c91de9279 32 */
j3 0:2d0c91de9279 33 #ifndef __MAX30101_H_
j3 0:2d0c91de9279 34 #define __MAX30101_H_
j3 0:2d0c91de9279 35
j3 0:2d0c91de9279 36 #include "mbed.h"
j3 0:2d0c91de9279 37
j3 0:2d0c91de9279 38 /**
j3 6:302fb0f991d8 39 * @brief Library for the MAX30101\n
j3 6:302fb0f991d8 40 * The MAX30101 is an integrated pulse oximetry and heart-rate monitor module.
j3 6:302fb0f991d8 41 * It includes internal LEDs, photodetectors, optical elements, and low-noise
j3 6:302fb0f991d8 42 * electronics with ambient light rejection. The MAX30101 provides a complete
j3 6:302fb0f991d8 43 * system solution to ease the design-in process for mobile and wearable devices.
j3 0:2d0c91de9279 44 *
j3 0:2d0c91de9279 45 * @code
j3 0:2d0c91de9279 46 * #include "mbed.h"
j3 0:2d0c91de9279 47 * #include "max32630fthr.h"
j3 0:2d0c91de9279 48 * #include "MAX30101.h"
j3 0:2d0c91de9279 49 *
j3 0:2d0c91de9279 50 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
j3 0:2d0c91de9279 51 *
j3 0:2d0c91de9279 52 * //Get I2C instance
j3 0:2d0c91de9279 53 * I2C i2cBus(P3_4, P3_5);
j3 0:2d0c91de9279 54 *
j3 0:2d0c91de9279 55 * //Get temp sensor instance
j3 0:2d0c91de9279 56 * MAX30101 op_sensor(i2cBus); //Constructor takes 7-bit slave adrs
j3 0:2d0c91de9279 57 *
j3 0:2d0c91de9279 58 * int main(void)
j3 0:2d0c91de9279 59 * {
j3 0:2d0c91de9279 60 * //use sensor
j3 0:2d0c91de9279 61 * }
j3 0:2d0c91de9279 62 * @endcode
j3 0:2d0c91de9279 63 */
j3 0:2d0c91de9279 64
j3 0:2d0c91de9279 65 class MAX30101
j3 0:2d0c91de9279 66 {
j3 0:2d0c91de9279 67 public:
j3 0:2d0c91de9279 68
j3 0:2d0c91de9279 69 ///7-bit slave address
j3 0:2d0c91de9279 70 static const uint8_t I2C_ADRS = 0x57;
j3 0:2d0c91de9279 71 ///8-bit write address
j3 0:2d0c91de9279 72 static const uint8_t I2C_W_ADRS = 0xAE;
j3 0:2d0c91de9279 73 ///8-bit read address
j3 0:2d0c91de9279 74 static const uint8_t I2C_R_ADRS = 0xAF;
j3 3:a2effad05c99 75 ///Max # Bytes in FIFO
j3 3:a2effad05c99 76 static const uint16_t MAX_FIFO_BYTES = 288;
j3 3:a2effad05c99 77 ///# of bytes per LED channel
j3 3:a2effad05c99 78 static const uint8_t BYTES_PER_CH = 3;
j3 0:2d0c91de9279 79
j3 0:2d0c91de9279 80 ///MAX30101 Register Map
j3 0:2d0c91de9279 81 enum Registers_e
j3 0:2d0c91de9279 82 {
j3 0:2d0c91de9279 83 InterruptStatus1 = 0x00,
j3 0:2d0c91de9279 84 InterruptStatus2 = 0x01,
j3 0:2d0c91de9279 85 InterruptEnable1 = 0x02,
j3 0:2d0c91de9279 86 InterruptEnable2 = 0x03,
j3 0:2d0c91de9279 87 FIFO_WritePointer = 0x04,
j3 0:2d0c91de9279 88 OverflowCounter = 0x05,
j3 0:2d0c91de9279 89 FIFO_ReadPointer = 0x06,
j3 0:2d0c91de9279 90 FIFO_DataRegister = 0x07,
j3 0:2d0c91de9279 91 FIFO_Configuration = 0x08,
j3 0:2d0c91de9279 92 ModeConfiguration = 0x09,
j3 0:2d0c91de9279 93 SpO2Configuration = 0x0A,
j3 0:2d0c91de9279 94 LED1_PA = 0x0C,
j3 0:2d0c91de9279 95 LED2_PA = 0x0D,
j3 0:2d0c91de9279 96 LED3_PA = 0x0E,
j3 0:2d0c91de9279 97 ProxModeLED_PA = 0x10,
j3 0:2d0c91de9279 98 ModeControlReg1 = 0x11,
j3 0:2d0c91de9279 99 ModeControlReg2 = 0x12,
j3 0:2d0c91de9279 100 DieTempInt = 0x1F,
j3 0:2d0c91de9279 101 DieTempFrac = 0x20,
j3 0:2d0c91de9279 102 DieTempConfig = 0x21,
j3 0:2d0c91de9279 103 ProxIntThreshold = 0x30,
j3 0:2d0c91de9279 104 RevID = 0xFE,
j3 0:2d0c91de9279 105 PartID = 0xFF
j3 0:2d0c91de9279 106 };
j3 0:2d0c91de9279 107
j3 3:a2effad05c99 108 ///MAX30101 Operational Modes
j3 3:a2effad05c99 109 enum OpModes_e
j3 3:a2effad05c99 110 {
j3 3:a2effad05c99 111 HeartRateMode = 2,
j3 3:a2effad05c99 112 SpO2Mode = 3,
j3 3:a2effad05c99 113 MultiLedMode = 7
j3 3:a2effad05c99 114 };
j3 3:a2effad05c99 115
j3 5:be1dde31fe49 116 ///Number of LED channels used
j3 5:be1dde31fe49 117 enum LedChannels_e
j3 5:be1dde31fe49 118 {
j3 5:be1dde31fe49 119 OneLedChannel = 1,
j3 5:be1dde31fe49 120 TwoLedChannels = 2,
j3 5:be1dde31fe49 121 ThreeLedChannels = 3
j3 5:be1dde31fe49 122 };
j3 5:be1dde31fe49 123
j3 5:be1dde31fe49 124 ///Number of samples averaged per FIFO sample, set in FIFO config
j3 5:be1dde31fe49 125 enum NumSamplesAveraged_e
j3 5:be1dde31fe49 126 {
j3 5:be1dde31fe49 127 AveragedSamples_0 = 0,
j3 5:be1dde31fe49 128 AveragedSamples_2 = 1,
j3 5:be1dde31fe49 129 AveragedSamples_4 = 2,
j3 5:be1dde31fe49 130 AveragedSamples_8 = 3,
j3 5:be1dde31fe49 131 AveragedSamples_16 = 4,
j3 5:be1dde31fe49 132 AveragedSamples_32 = 5
j3 5:be1dde31fe49 133 };
j3 5:be1dde31fe49 134
j3 5:be1dde31fe49 135 ///ADC Range, set in SpO2 config
j3 5:be1dde31fe49 136 enum ADCRange_e
j3 5:be1dde31fe49 137 {
j3 5:be1dde31fe49 138 ADC_Range_0 = 0,
j3 5:be1dde31fe49 139 ADC_Range_1 = 1,
j3 5:be1dde31fe49 140 ADC_Range_2 = 2,
j3 5:be1dde31fe49 141 ADC_Range_3 = 3
j3 5:be1dde31fe49 142 };
j3 5:be1dde31fe49 143
j3 5:be1dde31fe49 144 //LED PulseWidth, set in SpO2 config
j3 5:be1dde31fe49 145 enum LEDPulseWidth
j3 5:be1dde31fe49 146 {
j3 5:be1dde31fe49 147 PW_0 = 0,
j3 5:be1dde31fe49 148 PW_1 = 0,
j3 5:be1dde31fe49 149 PW_2 = 0,
j3 5:be1dde31fe49 150 PW_3 = 0
j3 5:be1dde31fe49 151 };
j3 5:be1dde31fe49 152
j3 5:be1dde31fe49 153
j3 5:be1dde31fe49 154 ///Sample rate, set in SpO2 config
j3 5:be1dde31fe49 155 enum SampleRate_e
j3 5:be1dde31fe49 156 {
j3 5:be1dde31fe49 157 SR_50_Hz = 0,
j3 5:be1dde31fe49 158 SR_100_Hz = 1,
j3 5:be1dde31fe49 159 SR_200_Hz = 3,
j3 5:be1dde31fe49 160 SR_400_Hz = 4,
j3 5:be1dde31fe49 161 SR_800_Hz = 5,
j3 5:be1dde31fe49 162 SR_1000_Hz = 6,
j3 5:be1dde31fe49 163 SR_1600_Hz = 7,
j3 5:be1dde31fe49 164 SR_3200_Hz = 8
j3 5:be1dde31fe49 165 };
j3 5:be1dde31fe49 166
j3 0:2d0c91de9279 167 ///Interrupt Status/Enable BitField
j3 0:2d0c91de9279 168 union InterruptBitField_u
j3 0:2d0c91de9279 169 {
j3 0:2d0c91de9279 170 uint8_t all;
j3 0:2d0c91de9279 171
j3 0:2d0c91de9279 172 struct BitField_s
j3 0:2d0c91de9279 173 {
j3 0:2d0c91de9279 174 uint8_t pwr_rdy : 1; ///< Bit0
j3 0:2d0c91de9279 175 uint8_t die_temp : 1; ///< Bit1
j3 0:2d0c91de9279 176 uint8_t reserved : 2; ///< Bit3:2
j3 0:2d0c91de9279 177 uint8_t prox_int : 1; ///< Bit4
j3 0:2d0c91de9279 178 uint8_t alc_ovf : 1; ///< Bit5
j3 0:2d0c91de9279 179 uint8_t ppg_rdy : 1; ///< Bit6
j3 0:2d0c91de9279 180 uint8_t a_full : 1; ///< Bit7
j3 0:2d0c91de9279 181 }bits;
j3 0:2d0c91de9279 182 };
j3 0:2d0c91de9279 183
j3 0:2d0c91de9279 184 ///FIFO Configuration BitField
j3 0:2d0c91de9279 185 union FIFO_Configuration_u
j3 0:2d0c91de9279 186 {
j3 0:2d0c91de9279 187 uint8_t all;
j3 0:2d0c91de9279 188 struct BitField_s
j3 0:2d0c91de9279 189 {
j3 0:2d0c91de9279 190 uint8_t fifo_a_full : 4;
j3 0:2d0c91de9279 191 uint8_t fifo_roll_over_en : 1;
j3 0:2d0c91de9279 192 uint8_t sample_average : 3;
j3 0:2d0c91de9279 193 }bits;
j3 0:2d0c91de9279 194 };
j3 0:2d0c91de9279 195
j3 0:2d0c91de9279 196 ///Mode Configuration BitField
j3 0:2d0c91de9279 197 union ModeConfiguration_u
j3 0:2d0c91de9279 198 {
j3 0:2d0c91de9279 199 uint8_t all;
j3 0:2d0c91de9279 200 struct BitField_s
j3 0:2d0c91de9279 201 {
j3 0:2d0c91de9279 202 uint8_t mode : 3;
j3 0:2d0c91de9279 203 uint8_t reserved : 3;
j3 0:2d0c91de9279 204 uint8_t reset : 1;
j3 0:2d0c91de9279 205 uint8_t shdn : 1;
j3 0:2d0c91de9279 206 }bits;
j3 0:2d0c91de9279 207 };
j3 0:2d0c91de9279 208
j3 0:2d0c91de9279 209 ///SpO2 Configuration BitField
j3 0:2d0c91de9279 210 union SpO2Configuration_u
j3 0:2d0c91de9279 211 {
j3 0:2d0c91de9279 212 uint8_t all;
j3 0:2d0c91de9279 213 struct BitField_s
j3 0:2d0c91de9279 214 {
j3 0:2d0c91de9279 215 uint8_t led_pw : 2;
j3 0:2d0c91de9279 216 uint8_t spo2_sr : 3;
j3 0:2d0c91de9279 217 uint8_t spo2_adc_range : 2;
j3 0:2d0c91de9279 218 uint8_t reserved : 1;
j3 0:2d0c91de9279 219 }bits;
j3 0:2d0c91de9279 220 };
j3 0:2d0c91de9279 221
j3 0:2d0c91de9279 222 ///Multi-LED Mode Control Register BitField
j3 0:2d0c91de9279 223 union ModeControlReg_u
j3 0:2d0c91de9279 224 {
j3 0:2d0c91de9279 225 uint8_t all;
j3 0:2d0c91de9279 226 struct BitField_s
j3 0:2d0c91de9279 227 {
j3 0:2d0c91de9279 228 uint8_t lo_slot : 3;
j3 0:2d0c91de9279 229 uint8_t reserved1 : 1;
j3 0:2d0c91de9279 230 uint8_t hi_slot : 3;
j3 0:2d0c91de9279 231 uint8_t reserved2 : 1;
j3 0:2d0c91de9279 232 }bits;
j3 0:2d0c91de9279 233 };
j3 0:2d0c91de9279 234
j3 0:2d0c91de9279 235 /**
j3 0:2d0c91de9279 236 * @brief Constructor using I2C PinNames
j3 0:2d0c91de9279 237 * @param sda - Pinname for sda
j3 0:2d0c91de9279 238 * @param scl - Pinname for scl
j3 0:2d0c91de9279 239 */
j3 0:2d0c91de9279 240 MAX30101(PinName sda, PinName scl);
j3 0:2d0c91de9279 241
j3 0:2d0c91de9279 242 /**
j3 0:2d0c91de9279 243 * @brief Constructor using reference to I2C object
j3 0:2d0c91de9279 244 * @param i2c - Reference to I2C object
j3 0:2d0c91de9279 245 */
j3 0:2d0c91de9279 246 MAX30101(I2C &i2c);
j3 0:2d0c91de9279 247
j3 0:2d0c91de9279 248 /** @brief Destructor */
j3 0:2d0c91de9279 249 ~MAX30101();
j3 0:2d0c91de9279 250
j3 0:2d0c91de9279 251 /**
j3 0:2d0c91de9279 252 * @brief Writes appropriate bits to Interrupt Enable 1 and 2.
j3 0:2d0c91de9279 253 *
j3 0:2d0c91de9279 254 * @param data - Interrupts to enable
j3 0:2d0c91de9279 255 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 256 */
j3 0:2d0c91de9279 257 int32_t enableInterrupts(const InterruptBitField_u data);
j3 0:2d0c91de9279 258
j3 0:2d0c91de9279 259 /**
j3 0:2d0c91de9279 260 * @brief Reads interrupt status flags from Interrupt Status 1 and 2.
j3 0:2d0c91de9279 261 *
j3 0:2d0c91de9279 262 * @param[out] data - Contains interrupts status flags on success.
j3 0:2d0c91de9279 263 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 264 */
j3 0:2d0c91de9279 265 int32_t getInterruptStatus(InterruptBitField_u &data);
j3 0:2d0c91de9279 266
j3 0:2d0c91de9279 267 /**
j3 0:2d0c91de9279 268 * @brief Writes FIFO configuration register with given data
j3 0:2d0c91de9279 269 *
j3 0:2d0c91de9279 270 * @param config - FIFO Configuration
j3 0:2d0c91de9279 271 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 272 */
j3 0:2d0c91de9279 273 int32_t setFIFOConfiguration(const FIFO_Configuration_u config);
j3 0:2d0c91de9279 274
j3 0:2d0c91de9279 275 /**
j3 0:2d0c91de9279 276 * @brief Reads FIFO configuration register
j3 0:2d0c91de9279 277 *
j3 0:2d0c91de9279 278 * @param[out] config - FIFO Configuration on success
j3 0:2d0c91de9279 279 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 280 */
j3 0:2d0c91de9279 281 int32_t getFIFOConfiguration(FIFO_Configuration_u &config);
j3 0:2d0c91de9279 282
j3 0:2d0c91de9279 283 /**
j3 0:2d0c91de9279 284 * @brief Writes Mode configuration register with given data
j3 0:2d0c91de9279 285 *
j3 0:2d0c91de9279 286 * @param config - Mode Configuration
j3 0:2d0c91de9279 287 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 288 */
j3 0:2d0c91de9279 289 int32_t setModeConfiguration(const ModeConfiguration_u config);
j3 0:2d0c91de9279 290
j3 0:2d0c91de9279 291 /**
j3 0:2d0c91de9279 292 * @brief Reads Mode configuration register
j3 0:2d0c91de9279 293 *
j3 0:2d0c91de9279 294 * @param[out] config - Mode Configuration on success
j3 0:2d0c91de9279 295 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 296 */
j3 0:2d0c91de9279 297 int32_t getModeConfiguration(ModeConfiguration_u &config);
j3 0:2d0c91de9279 298
j3 0:2d0c91de9279 299 /**
j3 0:2d0c91de9279 300 * @brief Writes SpO2 configuration register with given data
j3 0:2d0c91de9279 301 *
j3 0:2d0c91de9279 302 * @param config - SpO2 Configuration
j3 0:2d0c91de9279 303 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 304 */
j3 0:2d0c91de9279 305 int32_t setSpO2Configuration(const SpO2Configuration_u config);
j3 0:2d0c91de9279 306
j3 0:2d0c91de9279 307 /**
j3 0:2d0c91de9279 308 * @brief Reads SpO2 configuration register
j3 0:2d0c91de9279 309 *
j3 0:2d0c91de9279 310 * @param[out] config - SpO2 Configuration on success
j3 0:2d0c91de9279 311 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 312 */
j3 0:2d0c91de9279 313 int32_t getSpO2Configuration(SpO2Configuration_u &config);
j3 0:2d0c91de9279 314
j3 0:2d0c91de9279 315 /**
j3 0:2d0c91de9279 316 * @brief Writes LEDx/Prox Pulse Amplitude register with given data
j3 0:2d0c91de9279 317 *
j3 0:2d0c91de9279 318 * @param reg - LEDx/Prox Pulse Amplitude register to write
j3 0:2d0c91de9279 319 * @param amp - LED pulse amplitude
j3 0:2d0c91de9279 320 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 321 */
j3 0:2d0c91de9279 322 int32_t setLEDPulseAmplitude(Registers_e reg, const uint8_t amp);
j3 0:2d0c91de9279 323
j3 0:2d0c91de9279 324 /**
j3 0:2d0c91de9279 325 * @brief Reads LEDx/Prox Pulse Amplitude register
j3 0:2d0c91de9279 326 *
j3 0:2d0c91de9279 327 * @param reg - LEDx/Prox Pulse Amplitude register to read
j3 0:2d0c91de9279 328 * @param[out] amp - LED pulse amplitude on success
j3 0:2d0c91de9279 329 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 330 */
j3 0:2d0c91de9279 331 int32_t getLEDPulseAmplitude(Registers_e reg, uint8_t &amp);
j3 0:2d0c91de9279 332
j3 0:2d0c91de9279 333 /**
j3 0:2d0c91de9279 334 * @brief Writes Multi-LED Mode Control Register
j3 0:2d0c91de9279 335 *
j3 0:2d0c91de9279 336 * @param reg - Multi-LED Mode Control register 1 or 2
j3 0:2d0c91de9279 337 * @param data - Data to write to register
j3 0:2d0c91de9279 338 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 339 */
j3 0:2d0c91de9279 340 int32_t setMultiLEDModeControl(Registers_e reg, const ModeControlReg_u data);
j3 0:2d0c91de9279 341
j3 0:2d0c91de9279 342 /**
j3 0:2d0c91de9279 343 * @brief Reads Multi-LED Mode Control Register
j3 0:2d0c91de9279 344 *
j3 0:2d0c91de9279 345 * @param reg - Multi-LED Mode Control register 1 or 2
j3 0:2d0c91de9279 346 * @param[out] data - Data read from register on success
j3 0:2d0c91de9279 347 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 348 */
j3 0:2d0c91de9279 349 int32_t getMultiLEDModeControl(Registers_e reg, ModeControlReg_u &data);
j3 0:2d0c91de9279 350
j3 0:2d0c91de9279 351 /**
j3 2:0db1f3bec727 352 * @brief Gets raw die temperature, interrupt must be enabled
j3 0:2d0c91de9279 353 *
j3 0:2d0c91de9279 354 * @param[out] data - Raw die temperature on success
j3 0:2d0c91de9279 355 *
j3 0:2d0c91de9279 356 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 357 */
j3 0:2d0c91de9279 358 int32_t getDieTemperature(uint16_t &data);
j3 0:2d0c91de9279 359
j3 0:2d0c91de9279 360 /**
j3 2:0db1f3bec727 361 * @brief Gets die temperature in celsius, interrupt must be enabled
j3 0:2d0c91de9279 362 *
j3 0:2d0c91de9279 363 * @param[out] data - Die temperature in celsius on success
j3 0:2d0c91de9279 364 *
j3 0:2d0c91de9279 365 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 366 */
j3 0:2d0c91de9279 367 int32_t getDieTemperatureC(float &data);
j3 0:2d0c91de9279 368
j3 0:2d0c91de9279 369 /**
j3 0:2d0c91de9279 370 * @brief Converts celsius to Fahrenheit
j3 0:2d0c91de9279 371 *
j3 0:2d0c91de9279 372 * @param c - Temperature in celsius
j3 0:2d0c91de9279 373 *
j3 0:2d0c91de9279 374 * @return Temperature in Fahrenheit
j3 0:2d0c91de9279 375 */
j3 0:2d0c91de9279 376 float celsius2fahrenheit(float c);
j3 0:2d0c91de9279 377
j3 0:2d0c91de9279 378 /**
j3 0:2d0c91de9279 379 * @brief Writes Proximity Interrupt Threshold Register
j3 0:2d0c91de9279 380 *
j3 0:2d0c91de9279 381 * @param data - Data to write to register
j3 0:2d0c91de9279 382 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 383 */
j3 0:2d0c91de9279 384 int32_t setProxIntThreshold(const uint8_t data);
j3 0:2d0c91de9279 385
j3 0:2d0c91de9279 386 /**
j3 0:2d0c91de9279 387 * @brief Reads Proximity Interrupt Threshold Register
j3 0:2d0c91de9279 388 *
j3 0:2d0c91de9279 389 * @param data - Data read on success
j3 0:2d0c91de9279 390 * @return 0 on success, non 0 otherwise
j3 0:2d0c91de9279 391 */
j3 0:2d0c91de9279 392 int32_t getProxIntThreshold(uint8_t &data);
j3 3:a2effad05c99 393
j3 3:a2effad05c99 394 /**
j3 4:d1b50bd4065a 395 * @brief Attempts to read FIFO
j3 3:a2effad05c99 396 *
j3 3:a2effad05c99 397 * @param numLeds - Number of LED channels used; 0 < numLeds < 4
j3 3:a2effad05c99 398 * @param data - pointer to buffer for holding read data
j3 3:a2effad05c99 399 * @param[out] readBytes - number of bytes read from fifo
j3 3:a2effad05c99 400 *
j3 3:a2effad05c99 401 * @return 0 on success, non 0 otherwise
j3 3:a2effad05c99 402 */
j3 5:be1dde31fe49 403 int32_t readFIFO(LedChannels_e numLeds, uint8_t *data, uint16_t &readBytes);
j3 0:2d0c91de9279 404
j3 0:2d0c91de9279 405 protected:
j3 0:2d0c91de9279 406
j3 0:2d0c91de9279 407 /**
j3 0:2d0c91de9279 408 * @brief Write register of device
j3 0:2d0c91de9279 409 * @param reg - Register address
j3 0:2d0c91de9279 410 * @param value - Value to write
j3 0:2d0c91de9279 411 * @return 0 on success, non-zero on failure
j3 0:2d0c91de9279 412 */
j3 0:2d0c91de9279 413 int32_t writeRegister(Registers_e reg, uint8_t value);
j3 0:2d0c91de9279 414
j3 0:2d0c91de9279 415 /**
j3 0:2d0c91de9279 416 * @brief Read register of device
j3 0:2d0c91de9279 417 * @param reg - Register address
j3 0:2d0c91de9279 418 * @param[out] value - Read data on success
j3 0:2d0c91de9279 419 * @return 0 on success, non-zero on failure
j3 0:2d0c91de9279 420 */
j3 0:2d0c91de9279 421 int32_t readRegister(Registers_e reg, uint8_t &value);
j3 0:2d0c91de9279 422
j3 0:2d0c91de9279 423 private:
j3 0:2d0c91de9279 424
j3 0:2d0c91de9279 425 I2C m_i2cBus;
j3 3:a2effad05c99 426 uint8_t m_fifoReadPtr, m_fifoWritePtr, m_fifoNumBytes;
j3 3:a2effad05c99 427
j3 0:2d0c91de9279 428
j3 0:2d0c91de9279 429 };
j3 0:2d0c91de9279 430
j3 0:2d0c91de9279 431 #endif /* __MAX30101_H_ */
j3 0:2d0c91de9279 432