Maxim Integrated MAX30205 C, C++ source code driver software: MAX30205 is accurate to +-0.1°C over the range of 37.0°C to 39.0°C. One-shot, shutdown modes are available for reduced power usage. Thermostat thresholds allow for temperature hysteresis or for alarm settings. The MAX30205 is available in a compact 3x3 mm, 8-pin TDFN package. Operating supply voltage range is 2.7V to 3.3V. Typical applications are for clinical digital thermometers, thermostats with hysteresis, and temperature alarms.
Dependents: MAX30205_Human_Body_Temperature_Sensor
Revision 9:d98e4a80a866, committed 2019-04-15
- Comitter:
- phonemacro
- Date:
- Mon Apr 15 21:18:33 2019 +0000
- Parent:
- 8:2aeb45dd2bb9
- Child:
- 10:9c5dc1393570
- Commit message:
- Initial converstion to c, c++ code
Changed in this revision
--- a/MAX30205.cpp Thu Jul 27 22:49:16 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of Maxim Integrated
- * Products, Inc. shall not be used except as stated in the Maxim Integrated
- * Products, Inc. Branding Policy.
- *
- * The mere transfer of this software does not imply any licenses
- * of trade secrets, proprietary technology, copyrights, patents,
- * trademarks, maskwork rights, or any other form of intellectual
- * property whatsoever. Maxim Integrated Products, Inc. retains all
- * ownership rights.
- *******************************************************************************
- */
-
-
-#include "MAX30205.h"
-
-
-//******************************************************************************
-MAX30205::MAX30205(I2C &i2c, uint8_t slaveAddress):
-m_i2c(i2c), m_writeAddress(slaveAddress << 1),
-m_readAddress((slaveAddress << 1) | 1)
-{
-}
-
-
-//******************************************************************************
-MAX30205::~MAX30205(void)
-{
- //empty block
-}
-
-
-//******************************************************************************
-int32_t MAX30205::readTemperature(uint16_t &value)
-{
- return readRegister(MAX30205::Temperature, value);
-}
-
-
-//******************************************************************************
-int32_t MAX30205::readConfiguration(Configuration_u &config)
-{
- uint16_t data;
-
- int32_t result = readRegister(MAX30205::Configuration, data);
- if(result == 0)
- {
- config.all = (0x00FF & data);
- }
-
- return result;
-
-}
-
-
-//******************************************************************************
-int32_t MAX30205::writeConfiguration(const Configuration_u config)
-{
- uint16_t local_config = (0x00FF & config.all);
-
- return writeRegister(MAX30205::Configuration, local_config);
-}
-
-
-//******************************************************************************
-int32_t MAX30205::readTHYST(uint16_t &value)
-{
- return readRegister(MAX30205::THYST, value);
-}
-
-
-//******************************************************************************
-int32_t MAX30205::writeTHYST(uint16_t value)
-{
- return writeRegister(MAX30205::THYST, value);
-}
-
-
-//******************************************************************************
-int32_t MAX30205::readTOS(uint16_t &value)
-{
- return readRegister(MAX30205::TOS, value);
-}
-
-
-//******************************************************************************
-int32_t MAX30205::writeTOS(const uint16_t value)
-{
- return writeRegister(MAX30205::TOS, value);
-}
-
-
-//******************************************************************************
-float MAX30205::toCelsius(uint32_t rawTemp)
-{
- uint8_t val1, val2;
- float result;
-
- val1 = (rawTemp >> 8);
- val2 = (rawTemp & 0xFF);
-
- result = static_cast<float>(val1 + (val2/ 256.0F));
-
- return result;
-}
-
-
-//******************************************************************************
-float MAX30205::toFahrenheit(float temperatureC)
-{
- return((temperatureC * 1.8F) + 32.0f);
-}
-
-
-//******************************************************************************
-int32_t MAX30205::writeRegister(Registers_e reg, uint16_t value)
-{
- int32_t result;
-
- uint8_t hi = ((value >> 8) & 0xFF);
- uint8_t lo = (value & 0xFF);
- char cmdData[3] = {reg, hi, lo};
-
- result = m_i2c.write(m_writeAddress, cmdData, 3);
-
- return result;
-}
-
-
-//******************************************************************************
-int32_t MAX30205::readRegister(Registers_e reg, uint16_t &value)
-{
- int32_t result;
-
- char data[2];
- char cmdData[1] = {reg};
-
- result = m_i2c.write(m_writeAddress, cmdData, 1);
- if(result == 0)
- {
- result = m_i2c.read(m_readAddress, data, 2);
- if (result == 0)
- {
- value = (data[0] << 8) + data[1];
- }
- }
-
- return result;
-}
--- a/MAX30205.h Thu Jul 27 22:49:16 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,194 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
- * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of Maxim Integrated
- * Products, Inc. shall not be used except as stated in the Maxim Integrated
- * Products, Inc. Branding Policy.
- *
- * The mere transfer of this software does not imply any licenses
- * of trade secrets, proprietary technology, copyrights, patents,
- * trademarks, maskwork rights, or any other form of intellectual
- * property whatsoever. Maxim Integrated Products, Inc. retains all
- * ownership rights.
- *******************************************************************************
- */
-#ifndef __MAX30205_H_
-#define __MAX30205_H_
-
-#include "mbed.h"
-
-/**
- * @brief Library for the MAX30205\n
- * The MAX30205 temperature sensor accurately measures temperature and provide
- * an overtemperature alarm/interrupt/shutdown output. This device converts the
- * temperature measurements to digital form using a high-resolution,
- * sigma-delta, analog-to-digital converter (ADC). Accuracy meets clinical
- * thermometry specification of the ASTM E1112 when soldered on the final PCB.
- * Communication is through an I2C-compatible 2-wire serial interface.
- *
- * @code
- * #include "mbed.h"
- * #include "max32630fthr.h"
- * #include "MAX30205.h"
- *
- * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
- *
- * //Get I2C instance
- * I2C i2cBus(I2C1_SDA, I2C1_SCL);
- *
- * //Get temp sensor instance
- * MAX30205 bodyTempSensor(i2cBus, 0x4D); //Constructor takes 7-bit slave adrs
- *
- * int main(void)
- * {
- * //use sensor
- * }
- * @endcode
- */
-
-class MAX30205
-{
-
-public:
- /// MAX30205 Register Addresses
- enum Registers_e
- {
- Temperature = 0x00,
- Configuration = 0x01,
- THYST = 0x02,
- TOS = 0x03
- };
-
- ///MAX30205 Configuration register bitfields
- union Configuration_u
- {
- uint8_t all;
- struct BitField_s
- {
- uint8_t shutdown : 1;
- uint8_t comp_int : 1;
- uint8_t os_polarity : 1;
- uint8_t fault_queue : 2;
- uint8_t data_format : 1;
- uint8_t timeout : 1;
- uint8_t one_shot : 1;
- }bits;
- };
-
- /**
- * @brief Constructor using reference to I2C object
- * @param i2c - Reference to I2C object
- * @param slaveAddress - 7-bit I2C address
- */
- MAX30205(I2C &i2c, uint8_t slaveAddress);
-
- /** @brief Destructor */
- ~MAX30205(void);
-
- /**
- * @brief Read the temperature from the device into a 16 bit value
- * @param[out] value - Raw temperature data on success
- * @return 0 on success, non-zero on failure
- */
- int32_t readTemperature(uint16_t &value);
-
- /**
- * @brief Read the configuration register
- * @param config - Reference to Configuration type
- * @return 0 on success, non-zero on failure
- */
- int32_t readConfiguration(Configuration_u &config);
-
- /**
- * @brief Write the configuration register with given configuration
- * @param config - Configuration to write
- * @return 0 on success, non-zero on failure
- */
- int32_t writeConfiguration(const Configuration_u config);
-
- /**
- * @brief Read the THYST value from a specified device instance
- * @param[out] value - THYST register value on success
- * @return 0 on success, non-zero on failure
- */
- int32_t readTHYST(uint16_t &value);
-
- /**
- * @brief Write the THYST to a device instance
- * @param value - 16-bit value to write
- * @return 0 on success, non-zero on failure
- */
- int32_t writeTHYST(const uint16_t value);
-
- /**
- * @brief Read the TOS value from device
- * @param[out] value - TOS register value on success
- * @return 0 on success, non-zero on failure
- */
- int32_t readTOS(uint16_t &value);
-
- /**
- * @brief Write the TOS register
- * @param value - 16-bit value to write
- * @return 0 on success, non-zero on failure
- */
- int32_t writeTOS(const uint16_t value);
-
- /**
- * @brief Convert a raw temperature value into a float
- * @param rawTemp - raw temperature value to convert
- * @return the convereted value in degrees C
- */
- float toCelsius(uint32_t rawTemp);
-
- /**
- * @brief Convert the passed in temperature in C to Fahrenheit
- * @param temperatureC Temperature in C to convert
- * @returns Returns the converted Fahrenheit value
- */
- float toFahrenheit(float temperatureC);
-
-protected:
-
- /**
- * @brief Write register of device at slave address
- * @param reg - Register address
- * @param value - Value to write
- * @return 0 on success, non-zero on failure
- */
- int32_t writeRegister(Registers_e reg, uint16_t value);
-
- /**
- * @brief Read register of device at slave address
- * @param reg - Register address
- * @param[out] value - Read data on success
- * @return 0 on success, non-zero on failure
- */
- int32_t readRegister(Registers_e reg, uint16_t &value);
-
-private:
- /// I2C object
- I2C & m_i2c;
- /// Device slave addresses
- uint8_t m_writeAddress, m_readAddress;
-};
-
-#endif /* __MAX30205_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/max30205.h Mon Apr 15 21:18:33 2019 +0000
@@ -0,0 +1,152 @@
+/*******************************************************************************
+* Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+* @file MAX30205.h
+*******************************************************************************
+*/
+#ifndef MAX30205_H
+#define MAX30205_H
+#include "mbed.h"
+
+#define MAX30205_NO_ERROR 0
+#define MAX30205_ERROR -1
+
+#define MAX30205_REG_TEMPERATURE 0X00
+#define MAX30205_REG_CONFIGURATION 0X01
+#define MAX30205_REG_THYST_LOW_TRIP 0X02
+#define MAX30205_REG_TOS_HIGH_TRIP 0X03
+#define MAX30205_REG_MAX 0X03
+
+#define WAIT_MARGIN (0.0000)
+#define MAX30205_WAIT_CONV_TIME (.050+WAIT_MARGIN)
+
+#define MAX30205_CFG_CONTINUOUS (0X00 << 0)
+#define MAX30205_CFG_SHUTDOWN (0X01 << 0)
+
+#define MAX30205_CFG_COMPARATOR_MODE (0X00 << 1)
+#define MAX30205_CFG_INTERRUPT_MODE (0X01 << 1)
+
+#define MAX30205_CFG_OS_POLARITY_ACT_LOW (0x00 << 2)
+#define MAX30205_CFG_OS_POLARITY_ACT_HIGH (0x01 << 2)
+
+#define MAX30205_CFG_FAULT_FILTER_1 (0x00 << 3)
+#define MAX30205_CFG_FAULT_FILTER_2 (0x01 << 3)
+#define MAX30205_CFG_FAULT_FILTER_4 (0x02 << 3)
+#define MAX30205_CFG_FAULT_FILTER_6 (0x03 << 3)
+
+#define MAX30205_CFG_NORMAL_FORMAT (0x00 << 5)
+#define MAX30205_CFG_EXTENDED_FORMAT (0x01 << 5) /* add 64°C to temperature */
+#define MAX30205_EXTENDED_FORMAT_OFFSET (64.0f)
+#define MAX30205_CFG_TIMEOUT_ENABLE (0X00 << 6)
+#define MAX30205_CFG_TIMEOUT_DISABLE (0X01 << 6)
+#define MAX30205_CFG_ONE_SHOT_START (0X01 << 7)
+
+ /* A1 A2 A3 */
+#define MAX30205_I2C_SLAVE_ADR_00 (0x90 >> 1) /* GND GND GND */
+#define MAX30205_I2C_SLAVE_ADR_01 (0x92 >> 1) /* GND GND VDD */
+#define MAX30205_I2C_SLAVE_ADR_02 (0x82 >> 1) /* GND GND SCL */
+#define MAX30205_I2C_SLAVE_ADR_03 (0x80 >> 1) /* GND GND SDA */
+#define MAX30205_I2C_SLAVE_ADR_04 (0x94 >> 1) /* GND VDD GND */
+
+#define MAX30205_I2C_SLAVE_ADR_05 (0x96 >> 1) /* GND VDD VDD */
+#define MAX30205_I2C_SLAVE_ADR_06 (0x86 >> 1) /* GND VDD SCL */
+#define MAX30205_I2C_SLAVE_ADR_07 (0x84 >> 1) /* GND VDD SDA */
+#define MAX30205_I2C_SLAVE_ADR_08 (0xB4 >> 1) /* GND SCL GND */
+#define MAX30205_I2C_SLAVE_ADR_09 (0xB6 >> 1) /* GND SCL VDD */
+
+#define MAX30205_I2C_SLAVE_ADR_10 (0xA6 >> 1) /* GND SCL SCL */
+#define MAX30205_I2C_SLAVE_ADR_11 (0xA4 >> 1) /* GND SCL SDA */
+#define MAX30205_I2C_SLAVE_ADR_12 (0xB0 >> 1) /* GND SDA GND */
+#define MAX30205_I2C_SLAVE_ADR_13 (0xB2 >> 1) /* GND SDA VDD */
+#define MAX30205_I2C_SLAVE_ADR_14 (0xA2 >> 1) /* GND SDA SCL */
+
+#define MAX30205_I2C_SLAVE_ADR_15 (0xA0 >> 1) /* GND SDA SDA */
+#define MAX30205_I2C_SLAVE_ADR_16 (0x98 >> 1) /* VDD GND GND */
+#define MAX30205_I2C_SLAVE_ADR_17 (0x9A >> 1) /* VDD GND VDD */
+#define MAX30205_I2C_SLAVE_ADR_18 (0x8A >> 1) /* VDD GND SCL */
+#define MAX30205_I2C_SLAVE_ADR_19 (0x88 >> 1) /* VDD GND SDA */
+
+#define MAX30205_I2C_SLAVE_ADR_20 (0x9C >> 1) /* VDD VDD GND */
+#define MAX30205_I2C_SLAVE_ADR_21 (0x9E >> 1) /* VDD VDD VDD */
+#define MAX30205_I2C_SLAVE_ADR_22 (0x8E >> 1) /* VDD VDD SCL */
+#define MAX30205_I2C_SLAVE_ADR_23 (0x8C >> 1) /* VDD VDD SDA */
+#define MAX30205_I2C_SLAVE_ADR_24 (0xBC >> 1) /* VDD SCL GND */
+
+#define MAX30205_I2C_SLAVE_ADR_25 (0xBE >> 1) /* VDD SCL VDD */
+#define MAX30205_I2C_SLAVE_ADR_26 (0xAE >> 1) /* VDD SCL SCL */
+#define MAX30205_I2C_SLAVE_ADR_27 (0xAC >> 1) /* VDD SCL SDA */
+#define MAX30205_I2C_SLAVE_ADR_28 (0xB8 >> 1) /* VDD SDA GND */
+#define MAX30205_I2C_SLAVE_ADR_29 (0xBA >> 1) /* VDD SDA VDD */
+
+#define MAX30205_I2C_SLAVE_ADR_30 (0xAA >> 1) /* VDD SDA SCL */
+#define MAX30205_I2C_SLAVE_ADR_31 (0xA8 >> 1) /* VDD SDA SDA */
+
+
+#define MAX31726_I2C_SLAVE_ADR_00 (0x98 >> 1) /* GND GND */
+#define MAX31726_I2C_SLAVE_ADR_01 (0x9A >> 1) /* GND VDD */
+#define MAX31726_I2C_SLAVE_ADR_02 (0x8A >> 1) /* GND SCL */
+#define MAX31726_I2C_SLAVE_ADR_03 (0x88 >> 1) /* GND SDA */
+#define MAX31726_I2C_SLAVE_ADR_04 (0x9C >> 1) /* VDD GND */
+
+#define MAX31726_I2C_SLAVE_ADR_05 (0x9E >> 1) /* VDD VDD */
+#define MAX31726_I2C_SLAVE_ADR_06 (0x8E >> 1) /* VDD SCL */
+#define MAX31726_I2C_SLAVE_ADR_07 (0x8C >> 1) /* VDD SDA */
+#define MAX31726_I2C_SLAVE_ADR_08 (0xBC >> 1) /* SCL GND */
+#define MAX31726_I2C_SLAVE_ADR_09 (0xBE >> 1) /* SCL VDD */
+
+#define MAX31726_I2C_SLAVE_ADR_10 (0xAE >> 1) /* SCL SCL */
+#define MAX31726_I2C_SLAVE_ADR_11 (0xAC >> 1) /* SCL SDA */
+#define MAX31726_I2C_SLAVE_ADR_12 (0xB8 >> 1) /* SDA GND */
+#define MAX31726_I2C_SLAVE_ADR_13 (0xBA >> 1) /* SDA VDD */
+#define MAX31726_I2C_SLAVE_ADR_14 (0xAA >> 1) /* SDA SCL */
+
+#define MAX31726_I2C_SLAVE_ADR_15 (0xA8 >> 1) /* SDA SDA */
+
+
+#define MAX30205_CF_LSB (0.00390625F)
+
+/** @union max30205_raw_data
+ * @brief union data structure for byte word manipulations
+ */
+union max30205_raw_data {
+ struct {
+ uint8_t lsb;
+ uint8_t msb;
+ };
+ struct {
+ uint16_t magnitude_bits:15;
+ uint16_t sign_bit:1;
+ };
+ uint16_t uwrd;
+ int16_t swrd;
+};
+
+#endif/* MAX31875_H */
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/max30205_c.cpp Mon Apr 15 21:18:33 2019 +0000
@@ -0,0 +1,209 @@
+/*******************************************************************************
+* Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+*/
+#include "max30205.h"
+#include "max30205_c.h"
+#include "mbed.h"
+// #include "USBSerial.h"
+
+
+/******************************************************************************/
+/* C version for MAX30205 driver */
+/******************************************************************************/
+
+/* @var max30205_write_address, max30205_read_address
+ * @brief I2C address
+ */
+uint8_t max30205_write_address, max30205_read_address;
+
+/* @var max31875_extended_format
+ * @brief Extended format, add 64°C to the temperature reading
+ */
+uint32_t max30205_extended_format;
+
+int max30205_init(uint8_t slave_address)
+{
+ max30205_write_address = (slave_address <<1);
+ max30205_read_address = ((slave_address << 1) | 1);
+ max30205_extended_format = 0;
+ return MAX30205_NO_ERROR;
+}
+
+/******************************************************************************/
+int max30205_read_cfg_reg(uint8_t *value, I2C &i2c_bus)
+{
+ int32_t ret;
+ char data[1] = {0};
+ char reg = MAX30205_REG_CONFIGURATION;
+
+ /* write to the Register Select, true is for repeated start */
+ ret = i2c_bus.write(max30205_write_address, ®, 1, true);
+ if (ret == 0) {
+ ret = i2c_bus.read(max30205_read_address, data, 1, false);
+ if (ret == 0) {
+ *value = data[0];
+ return MAX30205_NO_ERROR;
+ } else {
+ printf("%s: failed to read data: ret: %d\r\n", __func__, ret);
+ }
+ } else {
+ printf("%s: failed to write to Register Select: ret: %d\r\n",
+ __func__, ret);
+ }
+ return MAX30205_ERROR;
+}
+
+
+/******************************************************************************/
+int max30205_read_reg16(int16_t *value, char reg, I2C &i2c_bus)
+{
+ int32_t ret;
+ char data[2] = {0, 0};
+ max30205_raw_data tmp;
+
+ if (reg == MAX30205_REG_TEMPERATURE ||
+ reg == MAX30205_REG_THYST_LOW_TRIP || reg == MAX30205_REG_TOS_HIGH_TRIP) {
+ /* write to the Register Select, true is for repeated start */
+ ret = i2c_bus.write(max30205_write_address, ®, 1, true);
+ /* read the two bytes of data */
+ if (ret == 0) {
+ ret = i2c_bus.read(max30205_read_address, data, 2, false);
+ if (ret == 0) {
+ tmp.msb = data[0];
+ tmp.lsb = data[1];
+ *value = tmp.swrd;
+ return MAX30205_NO_ERROR;
+ } else {
+ printf(
+ "%s: failed to read data: ret: %d\r\n", __func__, ret);
+ }
+ } else {
+ printf("%s: failed to write to Register Select: ret: %d\r\n",
+ __func__, ret);
+ }
+ } else {
+ printf("%s: register address is not correct: register: %d\r\n",
+ __func__, reg);
+ }
+ return MAX30205_ERROR;
+}
+
+float max30205_read_reg_as_temperature(uint8_t reg, I2C &i2c_bus)
+{
+ max30205_raw_data tmp;
+ float temperature;
+ if (reg == MAX30205_REG_TEMPERATURE ||
+ reg == MAX30205_REG_THYST_LOW_TRIP || reg == MAX30205_REG_TOS_HIGH_TRIP) {
+ max30205_read_reg16(&tmp.swrd, reg, i2c_bus);
+ temperature = (float)tmp.swrd; /* values are 2's complement */
+ temperature *= MAX30205_CF_LSB;
+ if (reg == MAX30205_REG_TEMPERATURE && max30205_extended_format)
+ temperature += MAX30205_EXTENDED_FORMAT_OFFSET;
+ return temperature;
+ } else {
+ printf("%s: register is invalid, %d r\n", __func__, reg);
+ return 0;
+ }
+}
+
+
+/******************************************************************************/
+int max30205_write_reg16(int16_t value, char reg, I2C &i2c_bus)
+{
+ int32_t ret;
+ char cmd[3];
+ max30205_raw_data tmp;
+
+ if (reg >= MAX30205_REG_THYST_LOW_TRIP && reg <= MAX30205_REG_MAX) {
+ cmd[0] = reg;
+ tmp.swrd = value;
+ cmd[1] = tmp.msb;
+ cmd[2] = tmp.lsb;
+ ret = i2c_bus.write(max30205_write_address, cmd, 3, false);
+ if (ret == 0) {
+ return MAX30205_NO_ERROR;
+ } else {
+ printf("%s: I2C write error %d\r\n",__func__, ret);
+ return MAX30205_ERROR;
+ }
+ } else {
+ printf("%s: register value invalid %x\r\n",__func__, reg);
+ return MAX30205_ERROR;
+ }
+}
+
+
+int max30205_write_cfg_reg(uint8_t cfg, I2C &i2c_bus)
+{
+ int32_t ret;
+ char cmd[2];
+
+ cmd[0] = MAX30205_REG_CONFIGURATION;
+ cmd[1] = cfg;
+ ret = i2c_bus.write(max30205_write_address, cmd, 2, false);
+ if (ret == 0) {
+ max30205_extended_format = 0;
+ if (cfg & MAX30205_CFG_EXTENDED_FORMAT)
+ max30205_extended_format = 1;
+
+ return MAX30205_NO_ERROR;
+ } else {
+ printf("%s: I2C write error %d\r\n",__func__, ret);
+ return MAX30205_ERROR;
+ }
+}
+
+
+int max30205_write_trip_low_thyst(float temperature, I2C &i2c_bus)
+{
+ max30205_raw_data raw;
+ temperature /= MAX30205_CF_LSB;
+ raw.swrd = int16_t(temperature);
+ return max30205_write_reg16(raw.swrd, MAX30205_REG_THYST_LOW_TRIP, i2c_bus);
+}
+
+
+int max30205_write_trip_high_tos(float temperature, I2C &i2c_bus)
+{
+ max30205_raw_data raw;
+ temperature /= MAX30205_CF_LSB;
+ raw.swrd = int16_t(temperature);
+ return max30205_write_reg16(raw.swrd, MAX30205_REG_TOS_HIGH_TRIP, i2c_bus);
+}
+
+
+float max30205_celsius_to_fahrenheit(float temp_c)
+{
+ float temp_f;
+ temp_f = ((temp_c * 9)/5) + 32;
+ return temp_f;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max30205_c.h Mon Apr 15 21:18:33 2019 +0000 @@ -0,0 +1,58 @@ +/******************************************************************************* +* Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included +* in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Except as contained in this notice, the name of Maxim Integrated +* Products, Inc. shall not be used except as stated in the Maxim Integrated +* Products, Inc. Branding Policy. +* +* The mere transfer of this software does not imply any licenses +* of trade secrets, proprietary technology, copyrights, patents, +* trademarks, maskwork rights, or any other form of intellectual +* property whatsoever. Maxim Integrated Products, Inc. retains all +* ownership rights. +******************************************************************************* +* @file max30205_c.h +******************************************************************************* +*/ +#ifndef MAX30205_C_H +#define MAX30205_C_H +#include "mbed.h" +/*****************************************************************************/ +/* C header for MAX30205 driver */ +/*****************************************************************************/ + +int max30205_init(uint8_t slaveAddress); + +int max30205_read_cfg_reg(uint8_t *value, I2C &i2c_bus); + +int max30205_read_reg16(int16_t *value, char reg, I2C &i2c_bus); + +float max30205_read_reg_as_temperature(uint8_t reg, I2C &i2c_bus); + +int max30205_write_cfg_reg(uint8_t cfg, I2C &i2c_bus); + +int max30205_write_trip_low_thyst(float temperature, I2C &i2c_bus); + +int max30205_write_trip_high_tos(float temperature, I2C &i2c_bus); + +float max30205_celsius_to_fahrenheit(float temp_c); + +#endif/* MAX30205_C_H */ \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/max30205_cpp.cpp Mon Apr 15 21:18:33 2019 +0000
@@ -0,0 +1,208 @@
+/*******************************************************************************
+* Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+*/
+#include "max30205.h"
+#include "max30205_cpp.h"
+#include "mbed.h"
+// #include "USBSerial.h"
+
+/******************************************************************************
+ * C++ version for MAX30205 driver *
+ ******************************************************************************
+ */
+
+/******************************************************************************/
+MAX30205::MAX30205(I2C &i2c_bus, uint8_t slave_address):
+m_i2c(i2c_bus),
+m_write_address(slave_address <<1),
+m_read_address ((slave_address << 1) | 1)
+{
+ max30205_extended_format = 0;
+}
+
+/******************************************************************************/
+MAX30205::~MAX30205(void)
+{
+ /** empty block */
+}
+
+/******************************************************************************/
+int MAX30205::read_cfg_reg(uint8_t *value)
+{
+ int32_t ret;
+ char data[1] = {0};
+ char reg = MAX30205_REG_CONFIGURATION;
+
+ /* write to the Register Select, true is for repeated start */
+ ret = m_i2c.write(m_write_address, ®, 1, true);
+ if (ret == 0) {
+ ret = m_i2c.read(m_read_address, data, 1, false);
+ if (ret == 0) {
+ *value = data[0];
+ return MAX30205_NO_ERROR;
+ } else {
+ printf(
+ "%s: failed to read data: ret: %d\r\n", __func__, ret);
+ }
+ } else {
+ printf("%s: failed to write to Register Select: ret: %d\r\n",
+ __func__, ret);
+ }
+ return MAX30205_ERROR;
+}
+
+/******************************************************************************/
+int MAX30205::read_reg16(int16_t *value, char reg)
+{
+ int32_t ret;
+ char data[2] = {0, 0};
+ max30205_raw_data tmp;
+
+ if (reg == MAX30205_REG_TEMPERATURE ||
+ reg == MAX30205_REG_THYST_LOW_TRIP || reg == MAX30205_REG_TOS_HIGH_TRIP) {
+ /* write to the Register Select, true is for repeated start */
+ ret = m_i2c.write(m_write_address, ®, 1, true);
+ /* read the two bytes of data */
+ if (ret == 0) {
+ ret = m_i2c.read(m_read_address, data, 2, false);
+ if (ret == 0) {
+ tmp.msb = data[0];
+ tmp.lsb = data[1];
+ *value = tmp.swrd;
+ return MAX30205_NO_ERROR;
+ } else {
+ printf(
+ "%s: failed to read data: ret: %d\r\n", __func__, ret);
+ }
+ } else {
+ printf("%s: failed to write to Register Select: ret: %d\r\n",
+ __func__, ret);
+ }
+ } else {
+ printf("%s: register address is not correct: register: %d\r\n",
+ __func__, reg);
+ }
+ return MAX30205_ERROR;
+}
+
+/******************************************************************************/
+float MAX30205::read_reg_as_temperature(uint8_t reg)
+{
+ max30205_raw_data tmp;
+ float temperature;
+ if (reg == MAX30205_REG_TEMPERATURE ||
+ reg == MAX30205_REG_THYST_LOW_TRIP || reg == MAX30205_REG_TOS_HIGH_TRIP) {
+ read_reg16(&tmp.swrd, reg);
+ temperature = (float)tmp.swrd; /* values are 2's complement */
+ temperature *= MAX30205_CF_LSB;
+ if (reg == MAX30205_REG_TEMPERATURE && max30205_extended_format)
+ temperature += MAX30205_EXTENDED_FORMAT_OFFSET;
+
+ return temperature;
+ } else {
+ printf("%s: register is invalid, %d r\n", __func__, reg);
+ return 0;
+ }
+}
+
+/******************************************************************************/
+int MAX30205::write_reg16(int16_t value, char reg)
+{
+ int32_t ret;
+ char cmd[3];
+ max30205_raw_data tmp;
+
+ if (reg >= MAX30205_REG_THYST_LOW_TRIP && reg <= MAX30205_REG_MAX) {
+ cmd[0] = reg;
+ tmp.swrd = value;
+ cmd[1] = tmp.msb;
+ cmd[2] = tmp.lsb;
+ ret = m_i2c.write(m_write_address, cmd, 3, false);
+ if (ret == 0) {
+ return MAX30205_NO_ERROR;
+ } else {
+ printf("%s: I2C write error %d\r\n",__func__, ret);
+ return MAX30205_ERROR;
+ }
+ } else {
+ printf("%s: register value invalid %x\r\n",__func__, reg);
+ return MAX30205_ERROR;
+ }
+}
+
+
+/******************************************************************************/
+int MAX30205::write_cfg_reg(uint8_t cfg)
+{
+ int32_t ret;
+ char cmd[2];
+
+ cmd[0] = MAX30205_REG_CONFIGURATION;
+ cmd[1] = cfg;
+ ret = m_i2c.write(m_write_address, cmd, 2, false);
+ if (ret == 0) {
+ max30205_extended_format = 0;
+ if (cfg & MAX30205_CFG_EXTENDED_FORMAT)
+ max30205_extended_format = 1;
+
+ return MAX30205_NO_ERROR;
+ } else {
+ printf("%s: I2C write error %d\r\n",__func__, ret);
+ return MAX30205_ERROR;
+ }
+}
+
+/******************************************************************************/
+int MAX30205::write_trip_low_thyst(float temperature)
+{
+ max30205_raw_data raw;
+ temperature /= MAX30205_CF_LSB;
+ raw.swrd = int16_t(temperature);
+ return write_reg16(raw.swrd, MAX30205_REG_THYST_LOW_TRIP);
+}
+
+/******************************************************************************/
+int MAX30205::write_trip_high_tos(float temperature)
+{
+ max30205_raw_data raw;
+ temperature /= MAX30205_CF_LSB;
+ raw.swrd = int16_t(temperature);
+ return write_reg16(raw.uwrd, MAX30205_REG_TOS_HIGH_TRIP);
+}
+
+/******************************************************************************/
+float MAX30205::celsius_to_fahrenheit(float temp_c)
+{
+ float temp_f;
+ temp_f = ((temp_c * 9)/5) + 32;
+ return temp_f;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/max30205_cpp.h Mon Apr 15 21:18:33 2019 +0000
@@ -0,0 +1,185 @@
+/*******************************************************************************
+* Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+* @file max30205_cpp.h
+*******************************************************************************
+*/
+#ifndef MAX30205_CPP_H
+#define MAX30205_CPP_H
+#include "mbed.h"
+
+
+/**
+ * @brief Digital thermometer, thermostat, temperature sensor.
+ * @version 1.0001.0000
+ *
+ * @details The MAX30205, MAX31726 temperature sensors
+ * provides accurate temperature measurements.
+ * Extended format allows for high temperature readings up to 150°C.
+ * The MAX30205 can operate in a low powered mode by utilizing
+ * the shutdown and one-shot mode.
+ * 8-pin TQDFN 3x3 mm package
+ * Accuracy is +-0.5°C from -40°C to +105°C (-40°F to +221°).
+ * Operating temperature: -55°C to +150°C (-67°F to +302°).
+ * VDD: 2.5V to 3.7V.
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "max32630fthr.h"
+ * #include "max30205.h"
+ * #include "USBSerial.h"
+ * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+ * I2C i2cBus(P3_4, P3_5);
+ * int main()
+ * {
+ * float temperature;
+ * DigitalOut rLED(LED1, LED_OFF);
+ * DigitalOut gLED(LED2, LED_OFF);
+ * DigitalOut bLED(LED3, LED_OFF);
+ * gLED = LED_ON;
+ * MAX30205 temp_sensor(i2cBus, MAX30205_I2C_SLAVE_ADR_00);
+ * i2cBus.frequency(400000);
+ * temperature =
+ * temp_sensor.read_reg_as_temperature(MAX30205_REG_TEMPERATURE);
+ * printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
+ * temperature, temp_sensor.celsius_to_fahrenheit(temperature));
+ * }
+ * @endcode
+ */
+
+class MAX30205
+{
+ public:
+
+ /**********************************************************//**
+ * @brief Constructor for MAX30205 Class.
+ *
+ * @details Allows user to use existing I2C object
+ *
+ * On Entry:
+ * @param[in] i2c_bus - pointer to existing I2C object
+ * @param[in] i2c_adrs - 7-bit slave address of MAX30205
+ *
+ * On Exit:
+ *
+ * @return None
+ **************************************************************/
+ MAX30205(I2C &i2c_bus, uint8_t slave_address);
+
+ /**********************************************************//**
+ * @brief Default destructor for MAX30205 Class.
+ *
+ * @details Destroys I2C object if owner
+ *
+ * On Entry:
+ *
+ * On Exit:
+ *
+ * @return None
+ **************************************************************/
+ ~MAX30205();
+
+ /**
+ * @brief Read register of device at slave address
+ * @param[out] value - Read data on success
+ * @return 0 on success, negative number on failure
+ */
+ int read_cfg_reg(uint8_t *value);
+
+ /**
+ * @brief Read register of device at slave address
+ * @param[out] value - Read data on success
+ * @param reg - Register address
+ * @return 0 on success, negative number on failure
+ */
+ int read_reg16(int16_t *value, char reg);
+
+ /**
+ * @brief Reads the temperature registers
+ * @param reg - the address of the temperature register
+ * @return temperature in degrees Celsius
+ */
+ float read_reg_as_temperature(uint8_t reg);
+
+ /**
+ * @brief Writes to the configuration register
+ * @param cfg - configurate word
+ * @return 0 on success, negative number on failure
+ */
+ int write_cfg_reg(uint8_t cfg);
+
+ /**
+ * @brief Writes to the THYST register
+ * @param temperature - the temperature in Celsius degrees
+ * @return 0 on success, negative number on failure
+ */
+ int write_trip_low_thyst(float temperature);
+
+ /**
+ * @brief Writes to the TOS register
+ * @param temperature - the temperature in Celsius degrees
+ * @return 0 on success, negative number on failure
+ */
+ int write_trip_high_tos(float temperature);
+
+ /**
+ * @brief Converts Celsius degrees to Fahrenheit
+ * @param temp_c - the temperature in Celsius degrees
+ * @return temperature in Celsius degrees
+ */
+ float celsius_to_fahrenheit(float temp_c);
+
+protected:
+ /**
+ * @brief Write a value to a register
+ * @param value - value to write to the register
+ * @param reg - register address
+ * @return 0 on success, negative number on failure
+ */
+ int write_reg16(int16_t value, char reg);
+
+private:
+ /** @var m_i2c
+ * @brief I2C object
+ */
+ I2C &m_i2c;
+ /** @var m_write_address, m_read_address
+ * @brief I2C address
+ */
+ uint8_t m_write_address, m_read_address;
+ /** @var m_extended_format
+ * @brief Extended format, add 64°C to the temperature reading
+ */
+ uint32_t max30205_extended_format;
+
+};
+
+#endif/* DS1775_CPP_H */
\ No newline at end of file