Extended MaximInterface
Dependents: mbed_DS28EC20_GPIO
DS2431.hpp
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 MaximInterface_DS2431 00034 #define MaximInterface_DS2431 00035 00036 #include <MaximInterface/Links/SelectRom.hpp> 00037 #include <MaximInterface/Links/Sleep.hpp> 00038 #include <MaximInterface/Utilities/array_span.hpp> 00039 #include <MaximInterface/Utilities/Export.h> 00040 00041 namespace MaximInterface { 00042 00043 /// @brief DS2431 1024-bit 1-Wire EEPROM 00044 /// @details The DS2431 is a 1024-bit, 1-Wire® EEPROM chip organized 00045 /// as four memory pages of 256 bits each. Data is written to an 8-byte 00046 /// scratchpad, verified, and then copied to the EEPROM memory. As a 00047 /// special feature, the four memory pages can individually be write 00048 /// protected or put in EPROM-emulation mode, where bits can only be 00049 /// changed from a 1 to a 0 state. The DS2431 communicates over the 00050 /// single-conductor 1-Wire bus. The communication follows the standard 00051 /// 1-Wire protocol. Each device has its own unalterable and unique 00052 /// 64-bit ROM registration number that is factory lasered into the chip. 00053 /// The registration number is used to address the device in a multidrop, 00054 /// 1-Wire net environment. 00055 class DS2431 { 00056 public: 00057 enum ErrorValue { CrcError = 1, OperationFailure }; 00058 00059 typedef array_span<uint_least8_t, 8> Scratchpad; 00060 typedef uint_least8_t Address; 00061 00062 DS2431(Sleep & sleep, OneWireMaster & master, const SelectRom & selectRom) 00063 : selectRom(selectRom), master(&master), sleep(&sleep) {} 00064 00065 void setSleep(Sleep & sleep) { this->sleep = &sleep; } 00066 00067 void setMaster(OneWireMaster & master) { this->master = &master; } 00068 00069 void setSelectRom(const SelectRom & selectRom) { 00070 this->selectRom = selectRom; 00071 } 00072 00073 /// @brief Reads block of data from EEPROM memory. 00074 /// @param[in] beginAddress EEPROM memory address to start reading from. 00075 /// @param[out] data EEPROM data read from the device. 00076 MaximInterface_EXPORT error_code readMemory(Address beginAddress, 00077 span<uint_least8_t> data) const; 00078 00079 /// @brief Writes 8 bytes to the scratchpad. 00080 /// @param[in] targetAddress 00081 /// EEPROM memory address that this data will be copied to. 00082 /// Must be on row boundary. 00083 /// @param[in] data Data to write to scratchpad. 00084 MaximInterface_EXPORT error_code writeScratchpad(Address targetAddress, 00085 Scratchpad::const_span data); 00086 00087 /// @brief Reads contents of scratchpad. 00088 /// @param[out] data Data read from scratchpad. 00089 /// @param[out] esByte E/S byte read before scratchpad data. 00090 MaximInterface_EXPORT error_code readScratchpad(Scratchpad::span data, 00091 uint_least8_t & esByte); 00092 00093 /// @brief Copies contents of scratchpad to EEPROM. 00094 /// @param[in] targetAddress EEPROM memory address that scratchpad 00095 /// will be copied to. Must be on row boundary. 00096 /// @param[in] esByte E/S byte from preceding Read Scratchpad command. 00097 MaximInterface_EXPORT error_code copyScratchpad(Address targetAddress, 00098 uint_least8_t esByte); 00099 00100 MaximInterface_EXPORT static const error_category & errorCategory(); 00101 00102 private: 00103 SelectRom selectRom; 00104 OneWireMaster * master; 00105 const Sleep * sleep; 00106 }; 00107 00108 /// @brief 00109 /// Writes data to EEPROM using Write Scratchpad, Read Scratchpad, 00110 /// and Copy Scratchpad commands. 00111 /// @param device Device to write. 00112 /// @param[in] targetAddress EEPROM memory address to start writing at. 00113 /// @param[in] data Data to write to EEPROM. 00114 MaximInterface_EXPORT error_code writeMemory(DS2431 & device, 00115 DS2431::Address targetAddress, 00116 DS2431::Scratchpad::const_span data); 00117 00118 inline error_code make_error_code(DS2431::ErrorValue e) { 00119 return error_code(e, DS2431::errorCategory()); 00120 } 00121 00122 } // namespace MaximInterface 00123 00124 #endif
Generated on Tue Jul 12 2022 23:29:45 by 1.7.2