Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LP_Receiver_Wakeup
MAX30208.cpp
00001 /******************************************************************************* 00002 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 * @file MAX30208.cpp 00033 * @brief This is the C++ file used for the MAX30208 human body temperature sensor library. 00034 * @version 1.0 00035 * @notes This file needs to be imported along with MAX30208.h for the program to work properly. This is library containing basic functions to be used in conjunction with the MAX30208. This library does not support any other devices. This is an MBed tested library. 00036 *****************************************************************************/ 00037 00038 00039 #include "MAX30208.h" 00040 00041 00042 //****************************************************************************** 00043 MAX30208::MAX30208(I2C &i2c, uint8_t slaveAddress): 00044 m_i2c(i2c), m_writeAddress(slaveAddress << 1), 00045 m_readAddress((slaveAddress << 1) | 1) 00046 { 00047 } 00048 00049 00050 //****************************************************************************** 00051 MAX30208::~MAX30208(void) { 00052 //empty block 00053 } 00054 00055 //****************************************************************************** 00056 int32_t MAX30208::writeInterruptRegister(Configuration_InterruptEnable config) { 00057 return(writeRegister(MAX30208::Interrupt_Enable,(config.all << 8),2)); 00058 } 00059 00060 //****************************************************************************** 00061 int32_t MAX30208::readInterruptRegister(Configuration_InterruptEnable &config) { 00062 uint16_t data; 00063 int32_t status; 00064 status = readRegister(MAX30208::Interrupt_Enable, data, 1); 00065 if(status == 0) { 00066 config.all = data; 00067 } 00068 return(status); 00069 } 00070 00071 //****************************************************************************** 00072 int32_t MAX30208::readStatus(uint16_t &value) { 00073 return(readRegister(MAX30208::Status,value, 1)); 00074 } 00075 00076 //****************************************************************************** 00077 int32_t MAX30208::readWritePointer(uint16_t &value) { 00078 return (readRegister(MAX30208::FIFO_Write_Pointer,value, 1)); 00079 } 00080 00081 //****************************************************************************** 00082 int32_t MAX30208::readReadPointer(uint16_t &value) { 00083 return (readRegister(MAX30208::FIFO_Read_Pointer,value,1)); 00084 } 00085 00086 //****************************************************************************** 00087 int32_t MAX30208::writeReadPointer(uint8_t config) { 00088 return(writeRegister(MAX30208::FIFO_Read_Pointer, (config << 8),2)); 00089 } 00090 00091 //****************************************************************************** 00092 int32_t MAX30208::readOverflow(uint16_t &value) { 00093 return(readRegister(MAX30208::FIFO_Overflow_Counter,value, 1)); 00094 } 00095 00096 //****************************************************************************** 00097 int32_t MAX30208::readDataCounter(uint16_t &value) { 00098 return(readRegister(MAX30208::FIFO_Data_Counter,value, 1)); 00099 } 00100 00101 //****************************************************************************** 00102 int32_t MAX30208::readData(uint16_t &value) { 00103 return(readRegister(MAX30208::FIFO_Data,value, 2)); 00104 } 00105 00106 //****************************************************************************** 00107 int32_t MAX30208::takeDataMeasurment() { 00108 return(writeRegister(MAX30208::Temp_Sensor_Setup,0xFF00,2)); 00109 } 00110 00111 //****************************************************************************** 00112 int32_t MAX30208::readFIFOConfig1(uint16_t &value) { 00113 return (readRegister(MAX30208::FIFO_Config1,value, 1)); 00114 } 00115 00116 //****************************************************************************** 00117 int32_t MAX30208::writeFIFOConfig1(uint8_t config) { 00118 return(writeRegister(MAX30208::FIFO_Config1,(config << 8),2)); 00119 } 00120 00121 //****************************************************************************** 00122 int32_t MAX30208::readFIFOConfig2(Configuration_FIFOConfig2 &config) { 00123 uint16_t data; 00124 int32_t status; 00125 status = readRegister(MAX30208::FIFO_Config2, data, 1); 00126 if(status == 0){ 00127 config.all = data; 00128 } 00129 return(status); 00130 } 00131 00132 //****************************************************************************** 00133 int32_t MAX30208::writeFIFOConfig2(Configuration_FIFOConfig2 config) { 00134 return(writeRegister(MAX30208::FIFO_Config2,(config.all << 8),2)); 00135 } 00136 00137 //****************************************************************************** 00138 int32_t MAX30208::resetDevice() { 00139 return(writeRegister(MAX30208::System_Control,(0x01 << 8),2)); 00140 } 00141 00142 //****************************************************************************** 00143 int32_t MAX30208::readAlarmHigh(uint16_t &temp) { 00144 return readRegister(MAX30208::Alarm_High_MSB,temp, 2); 00145 } 00146 00147 //****************************************************************************** 00148 int32_t MAX30208::writeAlarmHigh(uint16_t temp) { 00149 return(writeRegister(MAX30208::Alarm_High_MSB, temp, 3)); 00150 } 00151 00152 //****************************************************************************** 00153 int32_t MAX30208::readAlarmLow(uint16_t &value) { 00154 return (readRegister(MAX30208::Alarm_Low_MSB,value, 2)); 00155 } 00156 00157 //****************************************************************************** 00158 int32_t MAX30208::writeAlarmLow(uint16_t temp) { 00159 return(writeRegister(MAX30208::Alarm_Low_MSB,temp,3)); 00160 } 00161 00162 //****************************************************************************** 00163 int32_t MAX30208::readGPIOSetup(Configuration_GPIOSetup &config) { 00164 uint16_t data; 00165 int32_t status; 00166 status = readRegister(MAX30208::GPIO_Setup, data, 1); 00167 if(status == 0) { 00168 config.all = data; 00169 } 00170 return(status); 00171 } 00172 00173 //****************************************************************************** 00174 int32_t MAX30208::writeGPIOSetup(Configuration_GPIOSetup config) { 00175 return(writeRegister(MAX30208::GPIO_Setup,(config.all << 8),2)); 00176 } 00177 00178 //****************************************************************************** 00179 int32_t MAX30208::readGPIOControl(Configuration_GPIOControl &config) { 00180 uint16_t data; 00181 int32_t status; 00182 status = readRegister(MAX30208::GPIO_Control, data, 1); 00183 if(status == 0) { 00184 config.all = data; 00185 } 00186 return(status); 00187 } 00188 00189 //****************************************************************************** 00190 int32_t MAX30208::writeGPIOControl(Configuration_GPIOControl config) { 00191 return(writeRegister(MAX30208::GPIO_Control,(config.all << 8),2)); 00192 } 00193 00194 //****************************************************************************** 00195 float MAX30208::toCelsius(uint16_t rawTemp) { 00196 float celsius; 00197 celsius = 0.005*rawTemp; 00198 return celsius; 00199 } 00200 00201 //****************************************************************************** 00202 float MAX30208::toFahrenheit(float temperatureC) { 00203 float temperatureF; 00204 temperatureF = (temperatureC * 1.8F) + 32.0f; 00205 return temperatureF; 00206 } 00207 00208 //****************************************************************************** 00209 int32_t MAX30208::writeRegister(Registers_e reg, uint16_t value, int bytesWritten) { 00210 00211 int32_t ret; 00212 00213 uint8_t hi = ((value >> 8) & 0xFF); 00214 uint8_t lo = (value & 0xFF); 00215 char val[3] = {reg, hi, lo}; 00216 00217 ret = m_i2c.write(m_writeAddress, val, bytesWritten, false); 00218 return (ret); 00219 } 00220 00221 //****************************************************************************** 00222 int32_t MAX30208::readRegister(Registers_e reg, uint16_t &value, int bytesRead) { 00223 00224 int32_t ret; 00225 char cmdata[1] = {reg}; 00226 char dataRead[2]; 00227 00228 ret = m_i2c.write(m_readAddress,cmdata,1,true); 00229 if (ret == 0) { 00230 ret = m_i2c.read(m_readAddress,dataRead,bytesRead,false); 00231 if(ret == 0 && bytesRead == 2){ 00232 value = ((dataRead[0]<<8)+ dataRead[1]); 00233 } 00234 else if (ret == 0 && bytesRead == 1){ 00235 value = dataRead[0]; 00236 } 00237 } 00238 return(ret); 00239 }
Generated on Sat Jul 23 2022 23:38:39 by
