Arun Raj / Mbed OS MAXREFDES101_SOURCE

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAX30205.h Source File

MAX30205.h

00001 /*******************************************************************************
00002  * Copyright (C) 2017 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  */
00033 #ifndef __MAX30205_H_
00034 #define __MAX30205_H_
00035 
00036 #include "mbed.h"
00037 #include "MaximSensor.h"
00038 
00039 #define SENSOR_ID_MAX30205  0x03
00040 
00041 /**
00042  * @brief Library for the MAX30205\n
00043  * The MAX30205 temperature sensor accurately measures temperature and provide 
00044  * an overtemperature alarm/interrupt/shutdown output. This device converts the 
00045  * temperature measurements to digital form using a high-resolution, 
00046  * sigma-delta, analog-to-digital converter (ADC). Accuracy meets clinical 
00047  * thermometry specification of the ASTM E1112 when soldered on the final PCB. 
00048  * Communication is through an I2C-compatible 2-wire serial interface.
00049  *
00050  * @code
00051  * #include "mbed.h"
00052  * #include "max32630fthr.h"
00053  * #include "MAX30205.h"
00054  * 
00055  * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
00056  *
00057  * //Get I2C instance
00058  * I2C i2cBus(I2C1_SDA, I2C1_SCL);
00059  *
00060  * //Get temp sensor instance
00061  * MAX30205 bodyTempSensor(i2cBus, 0x4D); //Constructor takes 7-bit slave adrs
00062  *
00063  * int main(void) 
00064  * {
00065  *   //use sensor
00066  * }
00067  * @endcode
00068  */
00069 
00070 class MAX30205: public MaximSensor
00071 {
00072     
00073 public:
00074     /// MAX30205 Register Addresses
00075     enum Registers_e 
00076     {
00077         Temperature   = 0x00,
00078         Configuration = 0x01,
00079         THYST        = 0x02,
00080         TOS        = 0x03
00081     };
00082     
00083     ///MAX30205 Configuration register bitfields
00084     union Configuration_u
00085     {
00086         uint8_t all;
00087         struct BitField_s
00088         {
00089             uint8_t shutdown    : 1;
00090             uint8_t comp_int    : 1;
00091             uint8_t os_polarity : 1;
00092             uint8_t fault_queue : 2;
00093             uint8_t data_format : 1;
00094             uint8_t timeout  : 1;
00095             uint8_t one_shot    : 1;
00096         }bits;
00097     };
00098     
00099     /**
00100     * @brief  Constructor using reference to I2C object
00101     * @param i2c - Reference to I2C object
00102     * @param slaveAddress - 7-bit I2C address
00103     */
00104     MAX30205(I2C *i2c, uint8_t slaveAddress);
00105 
00106     /** @brief Destructor */
00107     ~MAX30205(void);
00108 
00109     /**
00110     * @brief Read the temperature from the device into a 16 bit value
00111     * @param[out] value - Raw temperature data on success
00112     * @return 0 on success, non-zero on failure
00113     */
00114     int32_t readTemperature(uint16_t &value);
00115     
00116     /**
00117     * @brief Read the configuration register
00118     * @param config - Reference to Configuration type
00119     * @return 0 on success, non-zero on failure
00120     */
00121     int32_t readConfiguration(Configuration_u &config);
00122     
00123     /**
00124     * @brief Write the configuration register with given configuration
00125     * @param config - Configuration to write
00126     * @return 0 on success, non-zero on failure
00127     */
00128     int32_t writeConfiguration(const Configuration_u config);
00129 
00130     /**
00131     * @brief Read the THYST value from a specified device instance
00132     * @param[out] value - THYST register value on success
00133     * @return 0 on success, non-zero on failure
00134     */
00135     int32_t readTHYST(uint16_t &value);
00136 
00137     /**
00138     * @brief Write the THYST to a device instance
00139     * @param value - 16-bit value to write
00140     * @return 0 on success, non-zero on failure
00141     */
00142     int32_t writeTHYST(const uint16_t value);
00143     
00144     /**
00145     * @brief Read the TOS value from device
00146     * @param[out] value - TOS register value on success
00147     * @return 0 on success, non-zero on failure
00148     */
00149     int32_t readTOS(uint16_t &value);
00150 
00151     /**
00152     * @brief Write the TOS register
00153     * @param value - 16-bit value to write
00154     * @return 0 on success, non-zero on failure
00155     */
00156     int32_t writeTOS(const uint16_t value);
00157 
00158     /**
00159     * @brief Convert a raw temperature value into a float
00160     * @param rawTemp - raw temperature value to convert
00161     * @return the convereted value in degrees C
00162     */
00163     float toCelsius(uint32_t rawTemp);
00164 
00165     /**
00166     * @brief Convert the passed in temperature in C to Fahrenheit
00167     * @param temperatureC Temperature in C to convert
00168     * @returns Returns the converted Fahrenheit value
00169     */
00170     float toFahrenheit(float temperatureC);
00171     
00172 //protected:
00173 
00174     /** 
00175     * @brief Write register of device at slave address
00176     * @param reg - Register address
00177     * @param value - Value to write
00178     * @return 0 on success, non-zero on failure
00179     */
00180     int32_t writeRegister(Registers_e reg, uint16_t value);
00181 
00182     /**
00183     * @brief  Read register of device at slave address
00184     * @param reg - Register address
00185     * @param[out] value - Read data on success
00186     * @return 0 on success, non-zero on failure
00187     */
00188     int32_t readRegister(Registers_e reg, uint16_t &value);
00189 
00190     /**
00191     * @brief    Dump Maxim Sensor registers.
00192     * @details  Fill out register values into list
00193     *
00194     * @returns  0 on success, negative error code on failure.
00195     */
00196     virtual int dump_registers(addr_val_pair *reg_values);
00197 
00198 
00199     /**
00200     * @brief    Get sensor ID.
00201     *
00202     * @returns  Sensor ID number.
00203     */
00204     unsigned char get_sensor_id();
00205 
00206     const char *get_sensor_part_name();
00207     const char *get_sensor_algo_ver();
00208 
00209                                     // sc... added functions
00210     // *************************************************************************** //
00211     /* @brief   Enables Maxim Sensor.
00212     * @details  Enable IRQ, enable LEDs, enable AGC
00213     *
00214     * @param[in]    enable Any value to enable, 0 to disable.
00215     *
00216     * @returns  0 on success, negative error code on failure.
00217     */
00218     virtual int sensor_enable(int enable);
00219 
00220 
00221     // *************************************************************************** //
00222 
00223 private:
00224     /// I2C object
00225     I2C  *m_i2c;
00226     /// Device slave addresses
00227     uint8_t m_writeAddress, m_readAddress;
00228 };
00229 
00230 #endif /* __MAX30205_H_ */