TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
gmehmet
Date:
Wed Apr 10 14:56:25 2019 +0300
Revision:
1:f60eafbf009a
upload from local

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gmehmet 1:f60eafbf009a 1 /*******************************************************************************
gmehmet 1:f60eafbf009a 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
gmehmet 1:f60eafbf009a 3 *
gmehmet 1:f60eafbf009a 4 * Permission is hereby granted, free of charge, to any person obtaining a
gmehmet 1:f60eafbf009a 5 * copy of this software and associated documentation files (the "Software"),
gmehmet 1:f60eafbf009a 6 * to deal in the Software without restriction, including without limitation
gmehmet 1:f60eafbf009a 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
gmehmet 1:f60eafbf009a 8 * and/or sell copies of the Software, and to permit persons to whom the
gmehmet 1:f60eafbf009a 9 * Software is furnished to do so, subject to the following conditions:
gmehmet 1:f60eafbf009a 10 *
gmehmet 1:f60eafbf009a 11 * The above copyright notice and this permission notice shall be included
gmehmet 1:f60eafbf009a 12 * in all copies or substantial portions of the Software.
gmehmet 1:f60eafbf009a 13 *
gmehmet 1:f60eafbf009a 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
gmehmet 1:f60eafbf009a 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
gmehmet 1:f60eafbf009a 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
gmehmet 1:f60eafbf009a 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
gmehmet 1:f60eafbf009a 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
gmehmet 1:f60eafbf009a 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
gmehmet 1:f60eafbf009a 20 * OTHER DEALINGS IN THE SOFTWARE.
gmehmet 1:f60eafbf009a 21 *
gmehmet 1:f60eafbf009a 22 * Except as contained in this notice, the name of Maxim Integrated
gmehmet 1:f60eafbf009a 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
gmehmet 1:f60eafbf009a 24 * Products, Inc. Branding Policy.
gmehmet 1:f60eafbf009a 25 *
gmehmet 1:f60eafbf009a 26 * The mere transfer of this software does not imply any licenses
gmehmet 1:f60eafbf009a 27 * of trade secrets, proprietary technology, copyrights, patents,
gmehmet 1:f60eafbf009a 28 * trademarks, maskwork rights, or any other form of intellectual
gmehmet 1:f60eafbf009a 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
gmehmet 1:f60eafbf009a 30 * ownership rights.
gmehmet 1:f60eafbf009a 31 *******************************************************************************
gmehmet 1:f60eafbf009a 32 */
gmehmet 1:f60eafbf009a 33 #ifndef __MAX30205_H_
gmehmet 1:f60eafbf009a 34 #define __MAX30205_H_
gmehmet 1:f60eafbf009a 35
gmehmet 1:f60eafbf009a 36 #include "mbed.h"
gmehmet 1:f60eafbf009a 37 #include "MaximSensor.h"
gmehmet 1:f60eafbf009a 38
gmehmet 1:f60eafbf009a 39 #define SENSOR_ID_MAX30205 0x03
gmehmet 1:f60eafbf009a 40
gmehmet 1:f60eafbf009a 41 /**
gmehmet 1:f60eafbf009a 42 * @brief Library for the MAX30205\n
gmehmet 1:f60eafbf009a 43 * The MAX30205 temperature sensor accurately measures temperature and provide
gmehmet 1:f60eafbf009a 44 * an overtemperature alarm/interrupt/shutdown output. This device converts the
gmehmet 1:f60eafbf009a 45 * temperature measurements to digital form using a high-resolution,
gmehmet 1:f60eafbf009a 46 * sigma-delta, analog-to-digital converter (ADC). Accuracy meets clinical
gmehmet 1:f60eafbf009a 47 * thermometry specification of the ASTM E1112 when soldered on the final PCB.
gmehmet 1:f60eafbf009a 48 * Communication is through an I2C-compatible 2-wire serial interface.
gmehmet 1:f60eafbf009a 49 *
gmehmet 1:f60eafbf009a 50 * @code
gmehmet 1:f60eafbf009a 51 * #include "mbed.h"
gmehmet 1:f60eafbf009a 52 * #include "max32630fthr.h"
gmehmet 1:f60eafbf009a 53 * #include "MAX30205.h"
gmehmet 1:f60eafbf009a 54 *
gmehmet 1:f60eafbf009a 55 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
gmehmet 1:f60eafbf009a 56 *
gmehmet 1:f60eafbf009a 57 * //Get I2C instance
gmehmet 1:f60eafbf009a 58 * I2C i2cBus(I2C1_SDA, I2C1_SCL);
gmehmet 1:f60eafbf009a 59 *
gmehmet 1:f60eafbf009a 60 * //Get temp sensor instance
gmehmet 1:f60eafbf009a 61 * MAX30205 bodyTempSensor(i2cBus, 0x4D); //Constructor takes 7-bit slave adrs
gmehmet 1:f60eafbf009a 62 *
gmehmet 1:f60eafbf009a 63 * int main(void)
gmehmet 1:f60eafbf009a 64 * {
gmehmet 1:f60eafbf009a 65 * //use sensor
gmehmet 1:f60eafbf009a 66 * }
gmehmet 1:f60eafbf009a 67 * @endcode
gmehmet 1:f60eafbf009a 68 */
gmehmet 1:f60eafbf009a 69
gmehmet 1:f60eafbf009a 70 class MAX30205: public MaximSensor
gmehmet 1:f60eafbf009a 71 {
gmehmet 1:f60eafbf009a 72
gmehmet 1:f60eafbf009a 73 public:
gmehmet 1:f60eafbf009a 74 /// MAX30205 Register Addresses
gmehmet 1:f60eafbf009a 75 enum Registers_e
gmehmet 1:f60eafbf009a 76 {
gmehmet 1:f60eafbf009a 77 Temperature = 0x00,
gmehmet 1:f60eafbf009a 78 Configuration = 0x01,
gmehmet 1:f60eafbf009a 79 THYST = 0x02,
gmehmet 1:f60eafbf009a 80 TOS = 0x03
gmehmet 1:f60eafbf009a 81 };
gmehmet 1:f60eafbf009a 82
gmehmet 1:f60eafbf009a 83 ///MAX30205 Configuration register bitfields
gmehmet 1:f60eafbf009a 84 union Configuration_u
gmehmet 1:f60eafbf009a 85 {
gmehmet 1:f60eafbf009a 86 uint8_t all;
gmehmet 1:f60eafbf009a 87 struct BitField_s
gmehmet 1:f60eafbf009a 88 {
gmehmet 1:f60eafbf009a 89 uint8_t shutdown : 1;
gmehmet 1:f60eafbf009a 90 uint8_t comp_int : 1;
gmehmet 1:f60eafbf009a 91 uint8_t os_polarity : 1;
gmehmet 1:f60eafbf009a 92 uint8_t fault_queue : 2;
gmehmet 1:f60eafbf009a 93 uint8_t data_format : 1;
gmehmet 1:f60eafbf009a 94 uint8_t timeout : 1;
gmehmet 1:f60eafbf009a 95 uint8_t one_shot : 1;
gmehmet 1:f60eafbf009a 96 }bits;
gmehmet 1:f60eafbf009a 97 };
gmehmet 1:f60eafbf009a 98
gmehmet 1:f60eafbf009a 99 /**
gmehmet 1:f60eafbf009a 100 * @brief Constructor using reference to I2C object
gmehmet 1:f60eafbf009a 101 * @param i2c - Reference to I2C object
gmehmet 1:f60eafbf009a 102 * @param slaveAddress - 7-bit I2C address
gmehmet 1:f60eafbf009a 103 */
gmehmet 1:f60eafbf009a 104 MAX30205(I2C *i2c, uint8_t slaveAddress);
gmehmet 1:f60eafbf009a 105
gmehmet 1:f60eafbf009a 106 /** @brief Destructor */
gmehmet 1:f60eafbf009a 107 ~MAX30205(void);
gmehmet 1:f60eafbf009a 108
gmehmet 1:f60eafbf009a 109 /**
gmehmet 1:f60eafbf009a 110 * @brief Read the temperature from the device into a 16 bit value
gmehmet 1:f60eafbf009a 111 * @param[out] value - Raw temperature data on success
gmehmet 1:f60eafbf009a 112 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 113 */
gmehmet 1:f60eafbf009a 114 int32_t readTemperature(uint16_t &value);
gmehmet 1:f60eafbf009a 115
gmehmet 1:f60eafbf009a 116 /**
gmehmet 1:f60eafbf009a 117 * @brief Read the configuration register
gmehmet 1:f60eafbf009a 118 * @param config - Reference to Configuration type
gmehmet 1:f60eafbf009a 119 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 120 */
gmehmet 1:f60eafbf009a 121 int32_t readConfiguration(Configuration_u &config);
gmehmet 1:f60eafbf009a 122
gmehmet 1:f60eafbf009a 123 /**
gmehmet 1:f60eafbf009a 124 * @brief Write the configuration register with given configuration
gmehmet 1:f60eafbf009a 125 * @param config - Configuration to write
gmehmet 1:f60eafbf009a 126 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 127 */
gmehmet 1:f60eafbf009a 128 int32_t writeConfiguration(const Configuration_u config);
gmehmet 1:f60eafbf009a 129
gmehmet 1:f60eafbf009a 130 /**
gmehmet 1:f60eafbf009a 131 * @brief Read the THYST value from a specified device instance
gmehmet 1:f60eafbf009a 132 * @param[out] value - THYST register value on success
gmehmet 1:f60eafbf009a 133 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 134 */
gmehmet 1:f60eafbf009a 135 int32_t readTHYST(uint16_t &value);
gmehmet 1:f60eafbf009a 136
gmehmet 1:f60eafbf009a 137 /**
gmehmet 1:f60eafbf009a 138 * @brief Write the THYST to a device instance
gmehmet 1:f60eafbf009a 139 * @param value - 16-bit value to write
gmehmet 1:f60eafbf009a 140 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 141 */
gmehmet 1:f60eafbf009a 142 int32_t writeTHYST(const uint16_t value);
gmehmet 1:f60eafbf009a 143
gmehmet 1:f60eafbf009a 144 /**
gmehmet 1:f60eafbf009a 145 * @brief Read the TOS value from device
gmehmet 1:f60eafbf009a 146 * @param[out] value - TOS register value on success
gmehmet 1:f60eafbf009a 147 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 148 */
gmehmet 1:f60eafbf009a 149 int32_t readTOS(uint16_t &value);
gmehmet 1:f60eafbf009a 150
gmehmet 1:f60eafbf009a 151 /**
gmehmet 1:f60eafbf009a 152 * @brief Write the TOS register
gmehmet 1:f60eafbf009a 153 * @param value - 16-bit value to write
gmehmet 1:f60eafbf009a 154 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 155 */
gmehmet 1:f60eafbf009a 156 int32_t writeTOS(const uint16_t value);
gmehmet 1:f60eafbf009a 157
gmehmet 1:f60eafbf009a 158 /**
gmehmet 1:f60eafbf009a 159 * @brief Convert a raw temperature value into a float
gmehmet 1:f60eafbf009a 160 * @param rawTemp - raw temperature value to convert
gmehmet 1:f60eafbf009a 161 * @return the convereted value in degrees C
gmehmet 1:f60eafbf009a 162 */
gmehmet 1:f60eafbf009a 163 float toCelsius(uint32_t rawTemp);
gmehmet 1:f60eafbf009a 164
gmehmet 1:f60eafbf009a 165 /**
gmehmet 1:f60eafbf009a 166 * @brief Convert the passed in temperature in C to Fahrenheit
gmehmet 1:f60eafbf009a 167 * @param temperatureC Temperature in C to convert
gmehmet 1:f60eafbf009a 168 * @returns Returns the converted Fahrenheit value
gmehmet 1:f60eafbf009a 169 */
gmehmet 1:f60eafbf009a 170 float toFahrenheit(float temperatureC);
gmehmet 1:f60eafbf009a 171
gmehmet 1:f60eafbf009a 172 //protected:
gmehmet 1:f60eafbf009a 173
gmehmet 1:f60eafbf009a 174 /**
gmehmet 1:f60eafbf009a 175 * @brief Write register of device at slave address
gmehmet 1:f60eafbf009a 176 * @param reg - Register address
gmehmet 1:f60eafbf009a 177 * @param value - Value to write
gmehmet 1:f60eafbf009a 178 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 179 */
gmehmet 1:f60eafbf009a 180 int32_t writeRegister(Registers_e reg, uint16_t value);
gmehmet 1:f60eafbf009a 181
gmehmet 1:f60eafbf009a 182 /**
gmehmet 1:f60eafbf009a 183 * @brief Read register of device at slave address
gmehmet 1:f60eafbf009a 184 * @param reg - Register address
gmehmet 1:f60eafbf009a 185 * @param[out] value - Read data on success
gmehmet 1:f60eafbf009a 186 * @return 0 on success, non-zero on failure
gmehmet 1:f60eafbf009a 187 */
gmehmet 1:f60eafbf009a 188 int32_t readRegister(Registers_e reg, uint16_t &value);
gmehmet 1:f60eafbf009a 189
gmehmet 1:f60eafbf009a 190 /**
gmehmet 1:f60eafbf009a 191 * @brief Dump Maxim Sensor registers.
gmehmet 1:f60eafbf009a 192 * @details Fill out register values into list
gmehmet 1:f60eafbf009a 193 *
gmehmet 1:f60eafbf009a 194 * @returns 0 on success, negative error code on failure.
gmehmet 1:f60eafbf009a 195 */
gmehmet 1:f60eafbf009a 196 virtual int dump_registers(addr_val_pair *reg_values);
gmehmet 1:f60eafbf009a 197
gmehmet 1:f60eafbf009a 198
gmehmet 1:f60eafbf009a 199 /**
gmehmet 1:f60eafbf009a 200 * @brief Get sensor ID.
gmehmet 1:f60eafbf009a 201 *
gmehmet 1:f60eafbf009a 202 * @returns Sensor ID number.
gmehmet 1:f60eafbf009a 203 */
gmehmet 1:f60eafbf009a 204 unsigned char get_sensor_id();
gmehmet 1:f60eafbf009a 205
gmehmet 1:f60eafbf009a 206 const char *get_sensor_part_name();
gmehmet 1:f60eafbf009a 207 const char *get_sensor_algo_ver();
gmehmet 1:f60eafbf009a 208
gmehmet 1:f60eafbf009a 209 // sc... added functions
gmehmet 1:f60eafbf009a 210 // *************************************************************************** //
gmehmet 1:f60eafbf009a 211 /* @brief Enables Maxim Sensor.
gmehmet 1:f60eafbf009a 212 * @details Enable IRQ, enable LEDs, enable AGC
gmehmet 1:f60eafbf009a 213 *
gmehmet 1:f60eafbf009a 214 * @param[in] enable Any value to enable, 0 to disable.
gmehmet 1:f60eafbf009a 215 *
gmehmet 1:f60eafbf009a 216 * @returns 0 on success, negative error code on failure.
gmehmet 1:f60eafbf009a 217 */
gmehmet 1:f60eafbf009a 218 virtual int sensor_enable(int enable);
gmehmet 1:f60eafbf009a 219
gmehmet 1:f60eafbf009a 220
gmehmet 1:f60eafbf009a 221 // *************************************************************************** //
gmehmet 1:f60eafbf009a 222
gmehmet 1:f60eafbf009a 223 private:
gmehmet 1:f60eafbf009a 224 /// I2C object
gmehmet 1:f60eafbf009a 225 I2C *m_i2c;
gmehmet 1:f60eafbf009a 226 /// Device slave addresses
gmehmet 1:f60eafbf009a 227 uint8_t m_writeAddress, m_readAddress;
gmehmet 1:f60eafbf009a 228 };
gmehmet 1:f60eafbf009a 229
gmehmet 1:f60eafbf009a 230 #endif /* __MAX30205_H_ */