MAXREFDES143#: DeepCover Embedded Security in IoT Authenticated Sensing & Notification
Dependencies: MaximInterface mbed
DS7505.hpp
00001 /******************************************************************************* 00002 * Copyright (C) 2016 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 DS7505_HPP 00034 #define DS7505_HPP 00035 00036 #include <stdint.h> 00037 00038 namespace mbed { class I2C; } 00039 00040 /// Interface to the DS7505 temperature sensor. 00041 class DS7505 { 00042 public: 00043 enum Result { Success, Hardware_Failure, Out_of_Range }; 00044 00045 /// @param I2C_interface A configured I2C interface to use for communication. 00046 /// @param I2C_address Device bus address in mbed format. 00047 DS7505 (mbed::I2C & I2C_interface, uint8_t I2C_address); 00048 00049 /// Set the resolution for temperature conversions. 00050 /// @param resolution Number of decimal bit from 1 to 4. 00051 Result set_resolution(uint8_t resolution); 00052 00053 /// Reads the current temperature with an exponent of 10^-2. 00054 /// @note Compatible with Bluetooth characteristic: 00055 /// org.bluetooth.characteristic.temperature. 00056 Result read_current_temp(int16_t & temperature) const; 00057 00058 /// Reads the current temperature as a floating point value. 00059 Result read_current_temp(double & temperature) const; 00060 00061 /// Reads the current temperature as an integer value. 00062 Result read_current_temp(int8_t & temperature) const; 00063 00064 private: 00065 /// Bit resolution of temperature conversions. 00066 enum Config_Resolution { 00067 Config_9b_Res = 0x00, 00068 Config_10b_Res = 0x20, 00069 Config_11b_Res = 0x40, 00070 Config_12b_Res = 0x60 00071 }; 00072 00073 /// DS7505 Register addresses. 00074 enum Register { 00075 Temperature_Reg = 0x00, 00076 Configuration_Reg = 0x01, 00077 Thyst_Reg = 0x02, 00078 Tos_Reg = 0x03 00079 }; 00080 00081 /// Represents a DS7505 configuration. 00082 struct Config { 00083 Config_Resolution resolution; 00084 bool enable_shutdown_mode; 00085 00086 Config(Config_Resolution resolution, bool enable_shutdown_mode) 00087 : resolution(resolution), enable_shutdown_mode(enable_shutdown_mode) {} 00088 }; 00089 00090 /// @note Mark as mutable to allow manipulation by read_temp_sensor(). 00091 mutable Config m_current_config; 00092 00093 mbed::I2C & m_I2C_interface; 00094 uint8_t m_I2C_address; 00095 00096 /// Returns the maximum time needed in milliseconds for a sample at the 00097 /// specified resolution. 00098 static uint8_t get_measure_delay_ms(Config_Resolution resolution); 00099 00100 /// Reads the current temperature via I2C. Assumes that the I2C register 00101 /// pointer is already set to the temperature register. 00102 /// @param sensor_data 00103 /// Output for raw data from DS7505 with upper and lower bytes combined. 00104 /// @returns True on success. 00105 bool read_temp_sensor_data(uint16_t & sensor_data) const; 00106 00107 /// Reads the current temperature with support for shutdown mode. 00108 /// @param sensor_data Output for raw data from DS7505 with upper and lower 00109 /// bytes combined. 00110 /// @returns Success or Hardware_Failure. 00111 Result read_temp_sensor(uint16_t & sensor_data) const; 00112 00113 /// Sets the I2C register pointer for the next operation. 00114 /// @param pointer_reg Desired register to set. 00115 /// @returns True on success. 00116 /// @note Allow marking const since not public. 00117 bool set_register_pointer(Register pointer_reg) const; 00118 00119 /// Writes to a device register via I2C. 00120 /// @param write_reg Register to write to. 00121 /// @param write_val Value to write to the register. 00122 /// @returns True on success. 00123 /// @note Allow marking const since not public 00124 bool write_register(Register write_reg, uint8_t write_val) const; 00125 00126 /// Writes the current configuration via I2C. 00127 /// @returns True on success. 00128 /// @note Allow marking const since not public 00129 bool write_current_config() const; 00130 }; 00131 00132 #endif
Generated on Wed Jul 13 2022 21:31:02 by 1.7.2