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
Diff: MAX30205.cpp
- Revision:
- 1:d4271ef9f37f
- Parent:
- 0:cdad7a9ef486
- Child:
- 2:a659724f496a
diff -r cdad7a9ef486 -r d4271ef9f37f MAX30205.cpp
--- a/MAX30205.cpp Mon Apr 03 23:11:58 2017 +0000
+++ b/MAX30205.cpp Thu Apr 06 00:05:03 2017 +0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
+ * 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"),
@@ -30,40 +30,115 @@
* ownership rights.
*******************************************************************************
*/
+
+
#include "MAX30205.h"
+
//******************************************************************************
-MAX30205::MAX30205(PinName sda, PinName scl, uint8_t slaveAddress):
-m_i2c(sda, scl), m_writeAddress(slaveAddress << 1), m_readAddress((slaveAddress << 1) | 1)
+MAX30205::MAX30205(PinName sda, PinName scl, uint8_t slaveAddress, PinName os):
+m_i2c(sda, scl), m_writeAddress(slaveAddress << 1),
+m_readAddress((slaveAddress << 1) | 1), m_os(os, PullUp)
{
}
+
//******************************************************************************
-MAX30205::MAX30205(I2C& i2c, uint8_t slaveAddress):
-m_i2c(i2c), m_writeAddress(slaveAddress << 1), m_readAddress((slaveAddress << 1) | 1)
+MAX30205::MAX30205(I2C &i2c, uint8_t slaveAddress, PinName os):
+m_i2c(i2c), m_writeAddress(slaveAddress << 1),
+m_readAddress((slaveAddress << 1) | 1), m_os(os, PullUp)
{
}
+
//******************************************************************************
MAX30205::~MAX30205(void)
{
//empty block
}
+
//******************************************************************************
-int32_t MAX30205::reg_write(Registers reg, uint8_t value)
+int32_t MAX30205::readTemperature(uint16_t &value)
+{
+ return readRegister(MAX30205::Temperature, value);
+}
+
+
+//******************************************************************************
+int32_t MAX30205::readConfiguration(Config &config)
{
- int32_t result;
-
- char cmdData[2] = {reg, value};
-
- result = m_i2c.write(m_writeAddress, cmdData, 2);
-
- return result;
+ uint16_t data;
+
+ int32_t result = readRegister(MAX30205::Configuration, data);
+ if(result == 0)
+ {
+ config.all = (0x00FF & data);
+ }
+
+ return result;
+
+}
+
+
+//******************************************************************************
+int32_t MAX30205::writeConfiguration(const Config 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::reg_write16(Registers reg, uint16_t 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)
+{
+ float val1, val2;
+
+ val1 = static_cast<float>(rawTemp >> 8);
+ val2 = static_cast<float>(rawTemp & 0xFF);
+
+ return(val2 + (val1 / 256.0F));
+}
+
+
+//******************************************************************************
+float MAX30205::toFahrenheit(float temperatureC)
+{
+ return((temperatureC * 1.8F) + 32.0f);
+}
+
+
+//******************************************************************************
+int32_t MAX30205::writeRegister(Registers reg, uint16_t value)
{
int32_t result;
@@ -76,29 +151,9 @@
return result;
}
-//******************************************************************************
-int32_t MAX30205::reg_read(Registers reg, uint8_t& value)
-{
- int32_t result;
-
- char cmdData[1] = {reg};
- char readData;
-
- result = m_i2c.write(m_writeAddress, cmdData, 1);
- if(result == 0)
- {
- result = m_i2c.read(m_readAddress, &readData, 1);
- if(result == 0)
- {
- value = readData;
- }
- }
-
- return result;
-}
//******************************************************************************
-int32_t MAX30205::reg_read16(Registers reg, uint16_t& value)
+int32_t MAX30205::readRegister(Registers reg, uint16_t &value)
{
int32_t result;
@@ -117,40 +172,3 @@
return result;
}
-
-//******************************************************************************
-int32_t MAX30205::readTemperature(uint16_t& value)
-{
- int32_t result = reg_read16(MAX30205::Temperature, value);
-
- return result;
-}
-
-//******************************************************************************
-float MAX30205::toCelsius(uint32_t rawTemp)
-{
- float val1, val2;
-
- val1 = static_cast<float>(rawTemp >> 8);
- val2 = static_cast<float>(rawTemp & 0xFF);
-
- return(val2 + (val1 / 256.0F));
-}
-
-//******************************************************************************
-float MAX30205::toFahrenheit(float temperatureC)
-{
- return((temperatureC * 1.8F) + 32.0f);
-}
-
-//******************************************************************************
-int32_t MAX30205::reg_THYST_Read(uint16_t& value)
-{
- return reg_read16(MAX30205::THYST, value);
-}
-
-//******************************************************************************
-int32_t MAX30205::reg_THYST_Write(uint16_t value)
-{
- return reg_write16(MAX30205::THYST, value);
-}