Maxim Integrated / MAX30208

Dependents:   LP_Receiver_Wakeup

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX30208.h Source File

MAX30208.h

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.h
00033 * @brief         This is the header 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.cpp 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 #ifndef __MAX30208_H_
00039 #define __MAX30208_H_
00040 
00041 #include "mbed.h"
00042 
00043 /**
00044  * @brief Library for the MAX30208
00045  *
00046  * @code
00047  * #include "mbed.h"
00048  * #include "max32630fthr.h"
00049  * #include "MAX30208.h"
00050  * 
00051  * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00052  *
00053  * //Get I2C instance
00054  * I2C i2cBus(I2C1_SDA, I2C1_SCL);
00055  *
00056  * //Get temp sensor instance
00057  * MAX30208 BodyTempSensor(i2cBus, 0x50); //Constructor takes 7-bit slave adress. 0x50 is default slave address for MAX30208 Ev-Kit
00058  *
00059  * int main(void) 
00060  * {
00061  *     //use sensor
00062  * }
00063  * @endcode
00064  */
00065 
00066 class MAX30208
00067 {
00068     
00069 public:
00070     /// MAX30208 Register Addresses
00071     enum Registers_e {
00072         Status = 0x00,
00073         Interrupt_Enable = 0x01,
00074         FIFO_Write_Pointer = 0x04,
00075         FIFO_Read_Pointer = 0x05,
00076         FIFO_Overflow_Counter = 0x06,
00077         FIFO_Data_Counter = 0x07,
00078         FIFO_Data = 0x08,
00079         FIFO_Config1 = 0x09,
00080         FIFO_Config2 = 0x0A,
00081         System_Control = 0x0C,
00082         Alarm_High_MSB = 0x10,
00083         Alarm_Low_MSB = 0x12,
00084         Temp_Sensor_Setup = 0x14,
00085         GPIO_Setup = 0x20,
00086         GPIO_Control = 0x21
00087     };
00088     
00089     //Intterupt Register Config
00090     union Configuration_InterruptEnable{
00091         uint8_t all;
00092         struct BitField_s{
00093             uint8_t TEMP_RDY_EN : 1;
00094             uint8_t TEMP_HI_EN  : 1;
00095             uint8_t TEMP_LO_EN  : 1;
00096             uint8_t             : 4;    //unused bits
00097             uint8_t A_FULL_EN   : 1;
00098         }config;
00099     };
00100     
00101     //FIFO Config 2 Register
00102     union Configuration_FIFOConfig2{
00103         uint8_t all;
00104         struct BitField_s{
00105             uint8_t               : 1;    //unused bit
00106             uint8_t FIFO_RO       : 1;
00107             uint8_t A_FULL_TYPE   : 1;
00108             uint8_t FIFO_STAT_CLR : 1;
00109             uint8_t FLUSH_FIFO    : 1;
00110             uint8_t               : 0;    //unused bits
00111         }config;
00112     };
00113     
00114     //GPIO Setup Register
00115     union Configuration_GPIOSetup{
00116         uint8_t all;
00117         struct BitField_s{
00118             uint8_t GPIO0_MODE     : 2;
00119             uint8_t                : 4;    //unused bits
00120             uint8_t GPIO1_MODE     : 2;
00121         }config;
00122     };
00123     
00124     //GPIO Control Register
00125     union Configuration_GPIOControl{
00126         uint8_t all;
00127         struct BitField_s{
00128             uint8_t GPIO0_LL   : 1;
00129             uint8_t            : 2;    //unused bits
00130             uint8_t GPIO1_LL   : 1;
00131             uint8_t            : 0;    //unused bits
00132         }config;
00133     };
00134 
00135     /**
00136     * @brief  Constructor using reference to I2C object
00137     * @param i2c - Reference to I2C object
00138     * @param slaveAddress - 7-bit I2C address
00139     */
00140     MAX30208(I2C &i2c, uint8_t slaveAddress);
00141 
00142     /** @brief Destructor */
00143     ~MAX30208(void);
00144     
00145     /**
00146     * @brief  Write Interrupt Register
00147     * @param config - Reference to Configuration type, config.all is written upon succesful register write
00148     * @return 0 on success, non-zero on failure
00149     */
00150     int32_t writeInterruptRegister(Configuration_InterruptEnable config);    
00151     
00152     /**
00153     * @brief  Read Interrupt Register Configuration
00154     * @param config - Reference to Configuration type, config.all is updated upon succesful register read
00155     * @return 0 on success, non-zero on failure
00156     */
00157     int32_t readInterruptRegister(Configuration_InterruptEnable &config);
00158     
00159     /**
00160     * @brief  Read Status Register
00161     * @param[out] value - Status Register Value on succesful read
00162     * @return 0 on success, non-zero on failure
00163     */
00164     int32_t readStatus(uint16_t &value);
00165     
00166     /**
00167     * @brief  Read FIFO Write Pointer Value
00168     * @param[out] value - FIFO Write Pointer value on succesful read
00169     * @return 0 on success, non-zero on failure
00170     */
00171     int32_t readWritePointer(uint16_t &value);
00172     
00173     /**
00174     * @brief  Read FIFO Read Pointer Value
00175     * @param[out] value - FIFO Read Pointer value on succesful read
00176     * @return 0 on success, non-zero on failure
00177     */
00178     int32_t readReadPointer(uint16_t &value);
00179     
00180     /**
00181     * @brief  Write FIFO Read Pointer Value
00182     * @param config - New FIFO Read Pointer value on succesful write
00183     * @return 0 on success, non-zero on failure
00184     */
00185     int32_t writeReadPointer(uint8_t config);
00186     
00187     /**
00188     * @brief Read FIFO Overflow Register
00189     * @param[out] value - Overflow Counter value on succesful read
00190     * @return 0 on success, non-zero on failure
00191     */
00192     int32_t readOverflow(uint16_t &value);
00193     
00194     /**
00195     * @brief Read Data Counter Register
00196     * @param[out] value - Data Count register value on succesful read
00197     * @return 0 on success, non-zero on failure
00198     */
00199     int32_t readDataCounter(uint16_t &value);
00200     
00201     /**
00202     * @brief  Read FIFO Data at FIFO Read Pointer
00203     * @param[out] value - Temperature value from FIFO data register on succesful read 
00204     * @return 0 on success, non-zero on failure
00205     */
00206     int32_t readData(uint16_t &value);
00207     
00208     /**
00209     * @brief Take a new temperature reading
00210     * @return 0 on success, non-zero on failure
00211     */
00212     int32_t takeDataMeasurment();
00213     
00214     /**
00215     * @brief  Read FIFO Config1 Register
00216     * @param[out] value - FIFO Config1 value on succesful read 
00217     * @return 0 on success, non-zero on failure
00218     */
00219     int32_t readFIFOConfig1(uint16_t &value);
00220     
00221     /**
00222     * @brief Write FIFO Config1 register
00223     * @param config - FIFO Config1 register data to write 
00224     * @return 0 on success, non-zero on failure
00225     */
00226     int32_t writeFIFOConfig1(uint8_t config);
00227     
00228     /**
00229     * @brief Read FIFO Config2 register
00230     * @param[out] config - Reference to Configuration type, config.all is updated upon succesful register read
00231     * @return 0 on success, non-zero on failure
00232     */
00233     int32_t readFIFOConfig2(Configuration_FIFOConfig2 &config);
00234     
00235     /**
00236     * @brief Read FIFO Config2 register
00237     * @param config - Reference to Configuration type, config.all is written upon succesful register write
00238     * @return 0 on success, non-zero on failure
00239     */
00240     int32_t writeFIFOConfig2(Configuration_FIFOConfig2 config);
00241     
00242     /**
00243     * @brief Reset Device to factory default
00244     * @return 0 on success, non-zero on failure
00245     */
00246     int32_t resetDevice(); //set bit 0 in system register to 1 to factory reset
00247 
00248     /**
00249     * @brief Read High Temperature Alarm Value
00250     * @param[out] temp - High Temperature Alarm Value
00251     * @return 0 on success, non-zero on failure
00252     */
00253     int32_t readAlarmHigh(uint16_t &temp);
00254     
00255     /**
00256     * @brief Write High Temperature Alarm Value
00257     * @param temp - 16-bit High Temperature Value to Write
00258     * @return 0 on success, non-zero on failure
00259     */    
00260     int32_t writeAlarmHigh(uint16_t temp);
00261     
00262     /**
00263     * @brief Read Low Temperature Alarm Value
00264     * @param[out] temp - Low Temperature Alarm Value
00265     * @return 0 on success, non-zero on failure
00266     */
00267     int32_t readAlarmLow(uint16_t &value);
00268     
00269     /**
00270     * @brief Write Low Temperature Alarm Value
00271     * @param temp - 16-bit Low Temperature Value to Write
00272     * @return 0 on success, non-zero on failure
00273     */
00274     int32_t writeAlarmLow(uint16_t temp);
00275     
00276     /**
00277     * @brief Read GPIO Setup register
00278     * @param config - Reference to Configuration type, config.all is updated upon succesful register read
00279     * @return 0 on success, non-zero on failure
00280     */
00281     int32_t readGPIOSetup(Configuration_GPIOSetup &config);
00282     
00283     /**
00284     * @brief Write GPIO Setup register
00285     * @param config - Reference to Configuration type, config.all is written to register upon succesful register write
00286     * @return 0 on success, non-zero on failure
00287     */
00288     int32_t writeGPIOSetup(Configuration_GPIOSetup config);
00289     
00290     /**
00291     * @brief Read GPIO Control register
00292     * @param config - Reference to Configuration type, config.all is updated upon succesful register read
00293     * @return 0 on success, non-zero on failure
00294     */
00295     int32_t readGPIOControl(Configuration_GPIOControl &config);
00296     
00297     /**
00298     * @brief Write GPIO Control register
00299     * @param config - Reference to Configuration type, config.all is written to register upon succesful register write
00300     * @return 0 on success, non-zero on failure
00301     */
00302     int32_t writeGPIOControl(Configuration_GPIOControl config);
00303     
00304     /**
00305     * @brief Convert Raw Sensor Data to degrees Celisus
00306     * @param rawTemp - 16 bit raw temperature data
00307     * @return Returns the converted Celsius Temperature
00308     */
00309     float toCelsius(uint16_t rawTemp);
00310     
00311     /**
00312     * @brief Convert Celsius Temperature to Fahrenheit
00313     * @param temperatureC - Temperature in degrees Celsius that will be converted
00314     * @return Returns the converted Fahrenheit temperature
00315     */
00316     float toFahrenheit(float temperatureC);
00317     
00318 protected:
00319 
00320     /** 
00321     * @brief Write register of device at slave address
00322     * @param reg - char array that contains address of register and write value
00323     * @param value - Data written to register on sucessful write
00324     * @param bytesWritten - Number of bytes to write
00325     * @return 0 on success, non-zero on failure
00326     */
00327     int32_t writeRegister(Registers_e reg, uint16_t value, int bytesWritten);
00328     /**
00329     * @brief  Read register of device at slave address
00330     * @param reg - Register address
00331     * @param[out] value - Read data on successful read
00332     * @param bytesRead - Number of bytes to read
00333     * @return 0 on success, non-zero on failure
00334     */
00335     int32_t readRegister(Registers_e reg, uint16_t &value, int bytesRead);
00336 
00337 private:
00338     /// I2C object
00339     I2C & m_i2c;
00340     /// Device slave addresses
00341     uint8_t m_writeAddress, m_readAddress;
00342 };
00343 
00344 #endif /* __MAX30208_H_ */