Fork of Maxim's human body temp sensor library that works with mbed-os 5

Fork of MAX30205 by Maxim Integrated

Committer:
j3
Date:
Mon Apr 03 23:11:58 2017 +0000
Revision:
0:cdad7a9ef486
Child:
1:d4271ef9f37f
Init commit, stand alone lib separated from HSP.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:cdad7a9ef486 1 /*******************************************************************************
j3 0:cdad7a9ef486 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:cdad7a9ef486 3 *
j3 0:cdad7a9ef486 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:cdad7a9ef486 5 * copy of this software and associated documentation files (the "Software"),
j3 0:cdad7a9ef486 6 * to deal in the Software without restriction, including without limitation
j3 0:cdad7a9ef486 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:cdad7a9ef486 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:cdad7a9ef486 9 * Software is furnished to do so, subject to the following conditions:
j3 0:cdad7a9ef486 10 *
j3 0:cdad7a9ef486 11 * The above copyright notice and this permission notice shall be included
j3 0:cdad7a9ef486 12 * in all copies or substantial portions of the Software.
j3 0:cdad7a9ef486 13 *
j3 0:cdad7a9ef486 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:cdad7a9ef486 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:cdad7a9ef486 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:cdad7a9ef486 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:cdad7a9ef486 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:cdad7a9ef486 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:cdad7a9ef486 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:cdad7a9ef486 21 *
j3 0:cdad7a9ef486 22 * Except as contained in this notice, the name of Maxim Integrated
j3 0:cdad7a9ef486 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:cdad7a9ef486 24 * Products, Inc. Branding Policy.
j3 0:cdad7a9ef486 25 *
j3 0:cdad7a9ef486 26 * The mere transfer of this software does not imply any licenses
j3 0:cdad7a9ef486 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:cdad7a9ef486 28 * trademarks, maskwork rights, or any other form of intellectual
j3 0:cdad7a9ef486 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:cdad7a9ef486 30 * ownership rights.
j3 0:cdad7a9ef486 31 *******************************************************************************
j3 0:cdad7a9ef486 32 */
j3 0:cdad7a9ef486 33 #ifndef __MAX30205_H_
j3 0:cdad7a9ef486 34 #define __MAX30205_H_
j3 0:cdad7a9ef486 35
j3 0:cdad7a9ef486 36 #include "mbed.h"
j3 0:cdad7a9ef486 37
j3 0:cdad7a9ef486 38 /**
j3 0:cdad7a9ef486 39 * Driver for the MAX30205
j3 0:cdad7a9ef486 40 *
j3 0:cdad7a9ef486 41 * @code
j3 0:cdad7a9ef486 42 * #include "mbed.h"
j3 0:cdad7a9ef486 43 * #include "MAX30205.h"
j3 0:cdad7a9ef486 44 *
j3 0:cdad7a9ef486 45 * int main(void)
j3 0:cdad7a9ef486 46 * {
j3 0:cdad7a9ef486 47 * I2C i2c(I2C_SDA, I2C_SCL);
j3 0:cdad7a9ef486 48 * MAX30205 sensor(i2c);
j3 0:cdad7a9ef486 49 *
j3 0:cdad7a9ef486 50 * //use sensor
j3 0:cdad7a9ef486 51 * }
j3 0:cdad7a9ef486 52 * @endcode
j3 0:cdad7a9ef486 53 */
j3 0:cdad7a9ef486 54
j3 0:cdad7a9ef486 55 class MAX30205
j3 0:cdad7a9ef486 56 {
j3 0:cdad7a9ef486 57
j3 0:cdad7a9ef486 58 public:
j3 0:cdad7a9ef486 59 /// MAX30205 Register Addresses
j3 0:cdad7a9ef486 60 enum Registers
j3 0:cdad7a9ef486 61 {
j3 0:cdad7a9ef486 62 Temperature = 0x00,
j3 0:cdad7a9ef486 63 Configuration = 0x01,
j3 0:cdad7a9ef486 64 THYST = 0x02,
j3 0:cdad7a9ef486 65 TOS = 0x03
j3 0:cdad7a9ef486 66 };
j3 0:cdad7a9ef486 67
j3 0:cdad7a9ef486 68 /**
j3 0:cdad7a9ef486 69 * @brief Constructor using I2C PinNames
j3 0:cdad7a9ef486 70 * @param sda - Pinname for sda
j3 0:cdad7a9ef486 71 * @param scl - Pinname for scl
j3 0:cdad7a9ef486 72 * @param slaveAddress - 7-bit I2C address
j3 0:cdad7a9ef486 73 */
j3 0:cdad7a9ef486 74 MAX30205(PinName sda, PinName scl, uint8_t slaveAddress);
j3 0:cdad7a9ef486 75
j3 0:cdad7a9ef486 76 /**
j3 0:cdad7a9ef486 77 * @brief Constructor using reference to I2C object
j3 0:cdad7a9ef486 78 * @param i2c - Reference to I2C object
j3 0:cdad7a9ef486 79 * @param slaveAddress - 7-bit I2C address
j3 0:cdad7a9ef486 80 */
j3 0:cdad7a9ef486 81 MAX30205(I2C& i2c, uint8_t slaveAddress);
j3 0:cdad7a9ef486 82
j3 0:cdad7a9ef486 83 /** @brief Destructor */
j3 0:cdad7a9ef486 84 ~MAX30205(void);
j3 0:cdad7a9ef486 85
j3 0:cdad7a9ef486 86 /** @brief Write register of device at slave address
j3 0:cdad7a9ef486 87 * @param reg - Register address
j3 0:cdad7a9ef486 88 * @param value - Value to write
j3 0:cdad7a9ef486 89 * @return 0 on success, non-zero on failure
j3 0:cdad7a9ef486 90 */
j3 0:cdad7a9ef486 91 int32_t reg_write(Registers reg, uint8_t value);
j3 0:cdad7a9ef486 92
j3 0:cdad7a9ef486 93 /**
j3 0:cdad7a9ef486 94 * @brief Read register of device at slave address
j3 0:cdad7a9ef486 95 * @param reg - Register address
j3 0:cdad7a9ef486 96 * @param[out] value - Read data on success
j3 0:cdad7a9ef486 97 * @return 0 on success, non-zero on failure
j3 0:cdad7a9ef486 98 */
j3 0:cdad7a9ef486 99 int32_t reg_read(Registers reg, uint8_t& value);
j3 0:cdad7a9ef486 100
j3 0:cdad7a9ef486 101 /**
j3 0:cdad7a9ef486 102 * @brief Write a 16-bit value into device at slave address
j3 0:cdad7a9ef486 103 * @param reg - Register address
j3 0:cdad7a9ef486 104 * @param value - 16-bit value to write
j3 0:cdad7a9ef486 105 * @return 0 on success, non-zero on failure
j3 0:cdad7a9ef486 106 */
j3 0:cdad7a9ef486 107 int32_t reg_write16(Registers reg, uint16_t value);
j3 0:cdad7a9ef486 108
j3 0:cdad7a9ef486 109 /**
j3 0:cdad7a9ef486 110 * @brief Read a 16-bit value from a device at a slave address
j3 0:cdad7a9ef486 111 * @param reg - Register address
j3 0:cdad7a9ef486 112 * @param[out] value - Read data on success
j3 0:cdad7a9ef486 113 * @return 0 on success, non-zero on failure
j3 0:cdad7a9ef486 114 */
j3 0:cdad7a9ef486 115 int32_t reg_read16(Registers reg, uint16_t& value);
j3 0:cdad7a9ef486 116
j3 0:cdad7a9ef486 117 /**
j3 0:cdad7a9ef486 118 * @brief Read the temperature from the device into a 16 bit value
j3 0:cdad7a9ef486 119 * @param[out] value - Raw temperature data on success
j3 0:cdad7a9ef486 120 * @return 0 on success, non-zero on failure
j3 0:cdad7a9ef486 121 */
j3 0:cdad7a9ef486 122 int32_t readTemperature(uint16_t& value);
j3 0:cdad7a9ef486 123
j3 0:cdad7a9ef486 124 /**
j3 0:cdad7a9ef486 125 * @brief Read the THYST value from a specified device instance
j3 0:cdad7a9ef486 126 * @param[out] value - THYST register value on success
j3 0:cdad7a9ef486 127 * @return 0 on success, non-zero on failure
j3 0:cdad7a9ef486 128 */
j3 0:cdad7a9ef486 129 int32_t reg_THYST_Read(uint16_t& value);
j3 0:cdad7a9ef486 130
j3 0:cdad7a9ef486 131 /**
j3 0:cdad7a9ef486 132 * @brief Write the THYST to a device instance
j3 0:cdad7a9ef486 133 * @param value - 16-bit value to write
j3 0:cdad7a9ef486 134 * @return 0 on success, non-zero on failure
j3 0:cdad7a9ef486 135 */
j3 0:cdad7a9ef486 136 int32_t reg_THYST_Write(uint16_t value);
j3 0:cdad7a9ef486 137
j3 0:cdad7a9ef486 138 /**
j3 0:cdad7a9ef486 139 * @brief Convert a raw temperature value into a float
j3 0:cdad7a9ef486 140 * @param rawTemp - raw temperature value to convert
j3 0:cdad7a9ef486 141 * @return the convereted value in degrees C
j3 0:cdad7a9ef486 142 */
j3 0:cdad7a9ef486 143 float toCelsius(uint32_t rawTemp);
j3 0:cdad7a9ef486 144
j3 0:cdad7a9ef486 145 /**
j3 0:cdad7a9ef486 146 * @brief Convert the passed in temperature in C to Fahrenheit
j3 0:cdad7a9ef486 147 * @param temperatureC Temperature in C to convert
j3 0:cdad7a9ef486 148 * @returns Returns the converted Fahrenheit value
j3 0:cdad7a9ef486 149 */
j3 0:cdad7a9ef486 150 float toFahrenheit(float temperatureC);
j3 0:cdad7a9ef486 151
j3 0:cdad7a9ef486 152 private:
j3 0:cdad7a9ef486 153 /// I2C object
j3 0:cdad7a9ef486 154 I2C m_i2c;
j3 0:cdad7a9ef486 155 /// Device slave address
j3 0:cdad7a9ef486 156 uint8_t m_writeAddress, m_readAddress;
j3 0:cdad7a9ef486 157 };
j3 0:cdad7a9ef486 158
j3 0:cdad7a9ef486 159 #endif /* __MAX30205_H_ */