Device interface library for multiple platforms including Mbed.
Dependents: DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#
DS1920.hpp
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 00033 #ifndef MaximInterfaceDevices_DS1920_hpp 00034 #define MaximInterfaceDevices_DS1920_hpp 00035 00036 #include <MaximInterfaceCore/array.hpp> 00037 #include <MaximInterfaceCore/SelectRom.hpp> 00038 #include <MaximInterfaceCore/Sleep.hpp> 00039 #include "Config.hpp" 00040 00041 namespace MaximInterfaceDevices { 00042 00043 /// @brief DS1920 1-Wire Temperature iButton 00044 /// @details The iButton® temperature logger (DS1920) provides 00045 /// direct-to-digital 9-bit temperature readings over a range of 00046 /// -55°C to +100°C in 0.5° increments. The iButton communicates with 00047 /// a processor using the 1-Wire® protocol through a hardware port 00048 /// interface. The port interface provides both the physical link and 00049 /// handles the communication protocols that enable the processor to 00050 /// access iButton resources with simple commands. Two bytes of 00051 /// EEPROM can be used either to set alarm triggers or for storing 00052 /// user data. 00053 class DS1920 { 00054 public: 00055 enum ErrorValue { CrcError = 1, DataError }; 00056 00057 /// Holds the contents of the device scratchpad. 00058 typedef Core::array<uint_least8_t, 8> Scratchpad; 00059 00060 DS1920(Core::Sleep & sleep, Core::OneWireMaster & master, 00061 const Core::SelectRom & selectRom) 00062 : selectRom(selectRom), master(&master), sleep(&sleep) {} 00063 00064 void setSleep(Core::Sleep & sleep) { this->sleep = &sleep; } 00065 00066 void setMaster(Core::OneWireMaster & master) { this->master = &master; } 00067 00068 void setSelectRom(const Core::SelectRom & selectRom) { 00069 this->selectRom = selectRom; 00070 } 00071 00072 /// @brief Write Scratchpad Command 00073 /// @details If the result of a temperature measurement is higher 00074 /// than TH or lower than TL, an alarm flag inside the device is 00075 /// set. This flag is updated with every temperature measurement. 00076 /// As long as the alarm flag is set, the DS1920 will respond to 00077 /// the alarm search command. 00078 /// @param[in] th 8-bit upper temperature threshold, MSB indicates sign. 00079 /// @param[in] tl 8-bit lower temperature threshold, MSB indicates sign. 00080 MaximInterfaceDevices_EXPORT Core::Result<void> 00081 writeScratchpad(uint_least8_t th, uint_least8_t tl); 00082 00083 /// @brief Read Scratchpad Command 00084 /// @returns Contents of scratchpad. 00085 MaximInterfaceDevices_EXPORT Core::Result<Scratchpad> readScratchpad() const; 00086 00087 /// @brief Copy Scratchpad Command 00088 /// @details This command copies from the scratchpad into the 00089 /// EEPROM of the DS1920, storing the temperature trigger bytes 00090 /// in nonvolatile memory. 00091 MaximInterfaceDevices_EXPORT Core::Result<void> copyScratchpad(); 00092 00093 /// @brief Convert Temperature Command 00094 /// @details This command begins a temperature conversion. 00095 MaximInterfaceDevices_EXPORT Core::Result<void> convertTemperature(); 00096 00097 /// @brief Recall Command 00098 /// @details This command recalls the temperature trigger values 00099 /// stored in EEPROM to the scratchpad. 00100 MaximInterfaceDevices_EXPORT Core::Result<void> recallEeprom(); 00101 00102 MaximInterfaceDevices_EXPORT static const Core::error_category & 00103 errorCategory(); 00104 00105 private: 00106 Core::SelectRom selectRom; 00107 Core::OneWireMaster * master; 00108 const Core::Sleep * sleep; 00109 }; 00110 00111 /// @brief Reads the current temperature as an integer value. 00112 /// @param ds1920 Device to read. 00113 /// @returns Temperature in degrees Celsius multiplied by 2. 00114 MaximInterfaceDevices_EXPORT Core::Result<int> readTemperature(DS1920 & ds1920); 00115 00116 } // namespace MaximInterfaceDevices 00117 namespace MaximInterfaceCore { 00118 00119 template <> 00120 struct is_error_code_enum<MaximInterfaceDevices::DS1920::ErrorValue> 00121 : true_type {}; 00122 00123 } // namespace MaximInterfaceCore 00124 namespace MaximInterfaceDevices { 00125 00126 inline Core::error_code make_error_code(DS1920::ErrorValue e) { 00127 return Core::error_code(e, DS1920::errorCategory()); 00128 } 00129 00130 } // namespace MaximInterfaceDevices 00131 00132 #endif
Generated on Tue Jul 12 2022 11:13:05 by 1.7.2