Fork of Maxim's human body temp sensor library that works with mbed-os 5
Fork of MAX30205 by
MAX30205.h@7:f005887f21e7, 2017-05-18 (annotated)
- Committer:
- j3
- Date:
- Thu May 18 20:50:39 2017 +0000
- Revision:
- 7:f005887f21e7
- Parent:
- 6:b5ab5204d944
- Child:
- 8:2aeb45dd2bb9
updated brief
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:cdad7a9ef486 | 1 | /******************************************************************************* |
j3 | 1:d4271ef9f37f | 2 | * Copyright (C) 2017 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 | 7:f005887f21e7 | 39 | * @brief Library for the MAX30205\n |
j3 | 7:f005887f21e7 | 40 | * The MAX30205 temperature sensor accurately measures temperature and provide |
j3 | 7:f005887f21e7 | 41 | * an overtemperature alarm/interrupt/shutdown output. This device converts the |
j3 | 7:f005887f21e7 | 42 | * temperature measurements to digital form using a high-resolution, |
j3 | 7:f005887f21e7 | 43 | * sigma-delta, analog-to-digital converter (ADC). Accuracy meets clinical |
j3 | 7:f005887f21e7 | 44 | * thermometry specification of the ASTM E1112 when soldered on the final PCB. |
j3 | 7:f005887f21e7 | 45 | * Communication is through an I2C-compatible 2-wire serial interface. |
j3 | 0:cdad7a9ef486 | 46 | * |
j3 | 0:cdad7a9ef486 | 47 | * @code |
j3 | 0:cdad7a9ef486 | 48 | * #include "mbed.h" |
j3 | 5:24039cc86fc1 | 49 | * #include "max32630fthr.h" |
j3 | 0:cdad7a9ef486 | 50 | * #include "MAX30205.h" |
j3 | 5:24039cc86fc1 | 51 | * |
j3 | 5:24039cc86fc1 | 52 | * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
j3 | 5:24039cc86fc1 | 53 | * |
j3 | 5:24039cc86fc1 | 54 | * //Get I2C instance |
j3 | 7:f005887f21e7 | 55 | * I2C i2cBus(I2C1_SDA, I2C1_SCL); |
j3 | 5:24039cc86fc1 | 56 | * |
j3 | 5:24039cc86fc1 | 57 | * //Get temp sensor instance |
j3 | 5:24039cc86fc1 | 58 | * MAX30205 bodyTempSensor(i2cBus, 0x4D); //Constructor takes 7-bit slave adrs |
j3 | 0:cdad7a9ef486 | 59 | * |
j3 | 0:cdad7a9ef486 | 60 | * int main(void) |
j3 | 0:cdad7a9ef486 | 61 | * { |
j3 | 0:cdad7a9ef486 | 62 | * //use sensor |
j3 | 0:cdad7a9ef486 | 63 | * } |
j3 | 0:cdad7a9ef486 | 64 | * @endcode |
j3 | 0:cdad7a9ef486 | 65 | */ |
j3 | 0:cdad7a9ef486 | 66 | |
j3 | 0:cdad7a9ef486 | 67 | class MAX30205 |
j3 | 0:cdad7a9ef486 | 68 | { |
j3 | 0:cdad7a9ef486 | 69 | |
j3 | 0:cdad7a9ef486 | 70 | public: |
j3 | 0:cdad7a9ef486 | 71 | /// MAX30205 Register Addresses |
j3 | 6:b5ab5204d944 | 72 | enum Registers_e |
j3 | 0:cdad7a9ef486 | 73 | { |
j3 | 7:f005887f21e7 | 74 | Temperature = 0x00, |
j3 | 0:cdad7a9ef486 | 75 | Configuration = 0x01, |
j3 | 7:f005887f21e7 | 76 | THYST = 0x02, |
j3 | 7:f005887f21e7 | 77 | TOS = 0x03 |
j3 | 0:cdad7a9ef486 | 78 | }; |
j3 | 1:d4271ef9f37f | 79 | |
j3 | 1:d4271ef9f37f | 80 | ///MAX30205 Configuration register bitfields |
j3 | 6:b5ab5204d944 | 81 | union Configuration_u |
j3 | 1:d4271ef9f37f | 82 | { |
j3 | 1:d4271ef9f37f | 83 | uint8_t all; |
j3 | 6:b5ab5204d944 | 84 | struct BitField_s |
j3 | 1:d4271ef9f37f | 85 | { |
j3 | 1:d4271ef9f37f | 86 | uint8_t shutdown : 1; |
j3 | 1:d4271ef9f37f | 87 | uint8_t comp_int : 1; |
j3 | 1:d4271ef9f37f | 88 | uint8_t os_polarity : 1; |
j3 | 1:d4271ef9f37f | 89 | uint8_t fault_queue : 2; |
j3 | 1:d4271ef9f37f | 90 | uint8_t data_format : 1; |
j3 | 1:d4271ef9f37f | 91 | uint8_t timeout : 1; |
j3 | 1:d4271ef9f37f | 92 | uint8_t one_shot : 1; |
j3 | 1:d4271ef9f37f | 93 | }bits; |
j3 | 1:d4271ef9f37f | 94 | }; |
j3 | 0:cdad7a9ef486 | 95 | |
j3 | 0:cdad7a9ef486 | 96 | /** |
j3 | 0:cdad7a9ef486 | 97 | * @brief Constructor using I2C PinNames |
j3 | 0:cdad7a9ef486 | 98 | * @param sda - Pinname for sda |
j3 | 0:cdad7a9ef486 | 99 | * @param scl - Pinname for scl |
j3 | 0:cdad7a9ef486 | 100 | * @param slaveAddress - 7-bit I2C address |
j3 | 0:cdad7a9ef486 | 101 | */ |
j3 | 4:68e1b36becb0 | 102 | MAX30205(PinName sda, PinName scl, uint8_t slaveAddress); |
j3 | 0:cdad7a9ef486 | 103 | |
j3 | 0:cdad7a9ef486 | 104 | /** |
j3 | 0:cdad7a9ef486 | 105 | * @brief Constructor using reference to I2C object |
j3 | 0:cdad7a9ef486 | 106 | * @param i2c - Reference to I2C object |
j3 | 0:cdad7a9ef486 | 107 | * @param slaveAddress - 7-bit I2C address |
j3 | 0:cdad7a9ef486 | 108 | */ |
j3 | 4:68e1b36becb0 | 109 | MAX30205(I2C &i2c, uint8_t slaveAddress); |
j3 | 0:cdad7a9ef486 | 110 | |
j3 | 0:cdad7a9ef486 | 111 | /** @brief Destructor */ |
j3 | 0:cdad7a9ef486 | 112 | ~MAX30205(void); |
j3 | 0:cdad7a9ef486 | 113 | |
j3 | 0:cdad7a9ef486 | 114 | /** |
j3 | 0:cdad7a9ef486 | 115 | * @brief Read the temperature from the device into a 16 bit value |
j3 | 0:cdad7a9ef486 | 116 | * @param[out] value - Raw temperature data on success |
j3 | 0:cdad7a9ef486 | 117 | * @return 0 on success, non-zero on failure |
j3 | 0:cdad7a9ef486 | 118 | */ |
j3 | 1:d4271ef9f37f | 119 | int32_t readTemperature(uint16_t &value); |
j3 | 1:d4271ef9f37f | 120 | |
j3 | 1:d4271ef9f37f | 121 | /** |
j3 | 1:d4271ef9f37f | 122 | * @brief Read the configuration register |
j3 | 1:d4271ef9f37f | 123 | * @param config - Reference to Configuration type |
j3 | 1:d4271ef9f37f | 124 | * @return 0 on success, non-zero on failure |
j3 | 1:d4271ef9f37f | 125 | */ |
j3 | 6:b5ab5204d944 | 126 | int32_t readConfiguration(Configuration_u &config); |
j3 | 1:d4271ef9f37f | 127 | |
j3 | 1:d4271ef9f37f | 128 | /** |
j3 | 1:d4271ef9f37f | 129 | * @brief Write the configuration register with given configuration |
j3 | 1:d4271ef9f37f | 130 | * @param config - Configuration to write |
j3 | 1:d4271ef9f37f | 131 | * @return 0 on success, non-zero on failure |
j3 | 1:d4271ef9f37f | 132 | */ |
j3 | 6:b5ab5204d944 | 133 | int32_t writeConfiguration(const Configuration_u config); |
j3 | 0:cdad7a9ef486 | 134 | |
j3 | 0:cdad7a9ef486 | 135 | /** |
j3 | 0:cdad7a9ef486 | 136 | * @brief Read the THYST value from a specified device instance |
j3 | 0:cdad7a9ef486 | 137 | * @param[out] value - THYST register value on success |
j3 | 0:cdad7a9ef486 | 138 | * @return 0 on success, non-zero on failure |
j3 | 0:cdad7a9ef486 | 139 | */ |
j3 | 1:d4271ef9f37f | 140 | int32_t readTHYST(uint16_t &value); |
j3 | 0:cdad7a9ef486 | 141 | |
j3 | 0:cdad7a9ef486 | 142 | /** |
j3 | 0:cdad7a9ef486 | 143 | * @brief Write the THYST to a device instance |
j3 | 0:cdad7a9ef486 | 144 | * @param value - 16-bit value to write |
j3 | 0:cdad7a9ef486 | 145 | * @return 0 on success, non-zero on failure |
j3 | 0:cdad7a9ef486 | 146 | */ |
j3 | 1:d4271ef9f37f | 147 | int32_t writeTHYST(const uint16_t value); |
j3 | 1:d4271ef9f37f | 148 | |
j3 | 1:d4271ef9f37f | 149 | /** |
j3 | 1:d4271ef9f37f | 150 | * @brief Read the TOS value from device |
j3 | 1:d4271ef9f37f | 151 | * @param[out] value - TOS register value on success |
j3 | 1:d4271ef9f37f | 152 | * @return 0 on success, non-zero on failure |
j3 | 1:d4271ef9f37f | 153 | */ |
j3 | 1:d4271ef9f37f | 154 | int32_t readTOS(uint16_t &value); |
j3 | 1:d4271ef9f37f | 155 | |
j3 | 1:d4271ef9f37f | 156 | /** |
j3 | 1:d4271ef9f37f | 157 | * @brief Write the TOS register |
j3 | 1:d4271ef9f37f | 158 | * @param value - 16-bit value to write |
j3 | 1:d4271ef9f37f | 159 | * @return 0 on success, non-zero on failure |
j3 | 1:d4271ef9f37f | 160 | */ |
j3 | 1:d4271ef9f37f | 161 | int32_t writeTOS(const uint16_t value); |
j3 | 0:cdad7a9ef486 | 162 | |
j3 | 0:cdad7a9ef486 | 163 | /** |
j3 | 0:cdad7a9ef486 | 164 | * @brief Convert a raw temperature value into a float |
j3 | 0:cdad7a9ef486 | 165 | * @param rawTemp - raw temperature value to convert |
j3 | 0:cdad7a9ef486 | 166 | * @return the convereted value in degrees C |
j3 | 0:cdad7a9ef486 | 167 | */ |
j3 | 0:cdad7a9ef486 | 168 | float toCelsius(uint32_t rawTemp); |
j3 | 0:cdad7a9ef486 | 169 | |
j3 | 0:cdad7a9ef486 | 170 | /** |
j3 | 0:cdad7a9ef486 | 171 | * @brief Convert the passed in temperature in C to Fahrenheit |
j3 | 0:cdad7a9ef486 | 172 | * @param temperatureC Temperature in C to convert |
j3 | 0:cdad7a9ef486 | 173 | * @returns Returns the converted Fahrenheit value |
j3 | 0:cdad7a9ef486 | 174 | */ |
j3 | 0:cdad7a9ef486 | 175 | float toFahrenheit(float temperatureC); |
j3 | 1:d4271ef9f37f | 176 | |
j3 | 1:d4271ef9f37f | 177 | protected: |
j3 | 1:d4271ef9f37f | 178 | |
j3 | 1:d4271ef9f37f | 179 | /** |
j3 | 1:d4271ef9f37f | 180 | * @brief Write register of device at slave address |
j3 | 1:d4271ef9f37f | 181 | * @param reg - Register address |
j3 | 1:d4271ef9f37f | 182 | * @param value - Value to write |
j3 | 1:d4271ef9f37f | 183 | * @return 0 on success, non-zero on failure |
j3 | 1:d4271ef9f37f | 184 | */ |
j3 | 6:b5ab5204d944 | 185 | int32_t writeRegister(Registers_e reg, uint16_t value); |
j3 | 1:d4271ef9f37f | 186 | |
j3 | 1:d4271ef9f37f | 187 | /** |
j3 | 1:d4271ef9f37f | 188 | * @brief Read register of device at slave address |
j3 | 1:d4271ef9f37f | 189 | * @param reg - Register address |
j3 | 1:d4271ef9f37f | 190 | * @param[out] value - Read data on success |
j3 | 1:d4271ef9f37f | 191 | * @return 0 on success, non-zero on failure |
j3 | 1:d4271ef9f37f | 192 | */ |
j3 | 6:b5ab5204d944 | 193 | int32_t readRegister(Registers_e reg, uint16_t &value); |
j3 | 0:cdad7a9ef486 | 194 | |
j3 | 0:cdad7a9ef486 | 195 | private: |
j3 | 0:cdad7a9ef486 | 196 | /// I2C object |
j3 | 0:cdad7a9ef486 | 197 | I2C m_i2c; |
j3 | 4:68e1b36becb0 | 198 | /// Device slave addresses |
j3 | 0:cdad7a9ef486 | 199 | uint8_t m_writeAddress, m_readAddress; |
j3 | 0:cdad7a9ef486 | 200 | }; |
j3 | 0:cdad7a9ef486 | 201 | |
j3 | 0:cdad7a9ef486 | 202 | #endif /* __MAX30205_H_ */ |