Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
IanBenzMaxim
Date:
Mon Mar 04 08:10:00 2019 -0600
Revision:
7:471901a04573
Parent:
6:a8c83a2e6fa4
Updated to version 1.7.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:f77ad7f72d04 1 /*******************************************************************************
IanBenzMaxim 0:f77ad7f72d04 2 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
IanBenzMaxim 0:f77ad7f72d04 3 *
IanBenzMaxim 0:f77ad7f72d04 4 * Permission is hereby granted, free of charge, to any person obtaining a
IanBenzMaxim 0:f77ad7f72d04 5 * copy of this software and associated documentation files (the "Software"),
IanBenzMaxim 0:f77ad7f72d04 6 * to deal in the Software without restriction, including without limitation
IanBenzMaxim 0:f77ad7f72d04 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
IanBenzMaxim 0:f77ad7f72d04 8 * and/or sell copies of the Software, and to permit persons to whom the
IanBenzMaxim 0:f77ad7f72d04 9 * Software is furnished to do so, subject to the following conditions:
IanBenzMaxim 0:f77ad7f72d04 10 *
IanBenzMaxim 0:f77ad7f72d04 11 * The above copyright notice and this permission notice shall be included
IanBenzMaxim 0:f77ad7f72d04 12 * in all copies or substantial portions of the Software.
IanBenzMaxim 0:f77ad7f72d04 13 *
IanBenzMaxim 0:f77ad7f72d04 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
IanBenzMaxim 0:f77ad7f72d04 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
IanBenzMaxim 0:f77ad7f72d04 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IanBenzMaxim 0:f77ad7f72d04 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
IanBenzMaxim 0:f77ad7f72d04 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
IanBenzMaxim 0:f77ad7f72d04 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
IanBenzMaxim 0:f77ad7f72d04 20 * OTHER DEALINGS IN THE SOFTWARE.
IanBenzMaxim 0:f77ad7f72d04 21 *
IanBenzMaxim 0:f77ad7f72d04 22 * Except as contained in this notice, the name of Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
IanBenzMaxim 0:f77ad7f72d04 24 * Products, Inc. Branding Policy.
IanBenzMaxim 0:f77ad7f72d04 25 *
IanBenzMaxim 0:f77ad7f72d04 26 * The mere transfer of this software does not imply any licenses
IanBenzMaxim 0:f77ad7f72d04 27 * of trade secrets, proprietary technology, copyrights, patents,
IanBenzMaxim 0:f77ad7f72d04 28 * trademarks, maskwork rights, or any other form of intellectual
IanBenzMaxim 0:f77ad7f72d04 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
IanBenzMaxim 0:f77ad7f72d04 30 * ownership rights.
IanBenzMaxim 0:f77ad7f72d04 31 *******************************************************************************/
IanBenzMaxim 0:f77ad7f72d04 32
IanBenzMaxim 0:f77ad7f72d04 33 #ifndef MaximInterface_DS2431
IanBenzMaxim 0:f77ad7f72d04 34 #define MaximInterface_DS2431
IanBenzMaxim 0:f77ad7f72d04 35
IanBenzMaxim 0:f77ad7f72d04 36 #include <MaximInterface/Links/SelectRom.hpp>
IanBenzMaxim 0:f77ad7f72d04 37 #include <MaximInterface/Links/Sleep.hpp>
IanBenzMaxim 6:a8c83a2e6fa4 38 #include <MaximInterface/Utilities/array_span.hpp>
IanBenzMaxim 0:f77ad7f72d04 39 #include <MaximInterface/Utilities/Export.h>
IanBenzMaxim 0:f77ad7f72d04 40
IanBenzMaxim 0:f77ad7f72d04 41 namespace MaximInterface {
IanBenzMaxim 0:f77ad7f72d04 42
IanBenzMaxim 7:471901a04573 43 /// @brief DS2431 1024-bit 1-Wire EEPROM
IanBenzMaxim 0:f77ad7f72d04 44 /// @details The DS2431 is a 1024-bit, 1-Wire® EEPROM chip organized
IanBenzMaxim 0:f77ad7f72d04 45 /// as four memory pages of 256 bits each. Data is written to an 8-byte
IanBenzMaxim 0:f77ad7f72d04 46 /// scratchpad, verified, and then copied to the EEPROM memory. As a
IanBenzMaxim 0:f77ad7f72d04 47 /// special feature, the four memory pages can individually be write
IanBenzMaxim 0:f77ad7f72d04 48 /// protected or put in EPROM-emulation mode, where bits can only be
IanBenzMaxim 0:f77ad7f72d04 49 /// changed from a 1 to a 0 state. The DS2431 communicates over the
IanBenzMaxim 0:f77ad7f72d04 50 /// single-conductor 1-Wire bus. The communication follows the standard
IanBenzMaxim 0:f77ad7f72d04 51 /// 1-Wire protocol. Each device has its own unalterable and unique
IanBenzMaxim 0:f77ad7f72d04 52 /// 64-bit ROM registration number that is factory lasered into the chip.
IanBenzMaxim 0:f77ad7f72d04 53 /// The registration number is used to address the device in a multidrop,
IanBenzMaxim 0:f77ad7f72d04 54 /// 1-Wire net environment.
IanBenzMaxim 0:f77ad7f72d04 55 class DS2431 {
IanBenzMaxim 0:f77ad7f72d04 56 public:
IanBenzMaxim 0:f77ad7f72d04 57 enum ErrorValue { CrcError = 1, OperationFailure };
IanBenzMaxim 0:f77ad7f72d04 58
IanBenzMaxim 6:a8c83a2e6fa4 59 typedef array_span<uint_least8_t, 8> Scratchpad;
IanBenzMaxim 0:f77ad7f72d04 60 typedef uint_least8_t Address;
IanBenzMaxim 0:f77ad7f72d04 61
IanBenzMaxim 6:a8c83a2e6fa4 62 DS2431(Sleep & sleep, OneWireMaster & master, const SelectRom & selectRom)
IanBenzMaxim 0:f77ad7f72d04 63 : selectRom(selectRom), master(&master), sleep(&sleep) {}
IanBenzMaxim 0:f77ad7f72d04 64
IanBenzMaxim 6:a8c83a2e6fa4 65 void setSleep(Sleep & sleep) { this->sleep = &sleep; }
IanBenzMaxim 6:a8c83a2e6fa4 66
IanBenzMaxim 0:f77ad7f72d04 67 void setMaster(OneWireMaster & master) { this->master = &master; }
IanBenzMaxim 6:a8c83a2e6fa4 68
IanBenzMaxim 0:f77ad7f72d04 69 void setSelectRom(const SelectRom & selectRom) {
IanBenzMaxim 0:f77ad7f72d04 70 this->selectRom = selectRom;
IanBenzMaxim 0:f77ad7f72d04 71 }
IanBenzMaxim 0:f77ad7f72d04 72
IanBenzMaxim 7:471901a04573 73 /// @brief Reads block of data from EEPROM memory.
IanBenzMaxim 0:f77ad7f72d04 74 /// @param[in] beginAddress EEPROM memory address to start reading from.
IanBenzMaxim 0:f77ad7f72d04 75 /// @param[out] data EEPROM data read from the device.
IanBenzMaxim 0:f77ad7f72d04 76 MaximInterface_EXPORT error_code readMemory(Address beginAddress,
IanBenzMaxim 6:a8c83a2e6fa4 77 span<uint_least8_t> data) const;
IanBenzMaxim 0:f77ad7f72d04 78
IanBenzMaxim 7:471901a04573 79 /// @brief Writes 8 bytes to the scratchpad.
IanBenzMaxim 7:471901a04573 80 /// @param[in] targetAddress
IanBenzMaxim 7:471901a04573 81 /// EEPROM memory address that this data will be copied to.
IanBenzMaxim 7:471901a04573 82 /// Must be on row boundary.
IanBenzMaxim 0:f77ad7f72d04 83 /// @param[in] data Data to write to scratchpad.
IanBenzMaxim 0:f77ad7f72d04 84 MaximInterface_EXPORT error_code writeScratchpad(Address targetAddress,
IanBenzMaxim 6:a8c83a2e6fa4 85 Scratchpad::const_span data);
IanBenzMaxim 0:f77ad7f72d04 86
IanBenzMaxim 7:471901a04573 87 /// @brief Reads contents of scratchpad.
IanBenzMaxim 0:f77ad7f72d04 88 /// @param[out] data Data read from scratchpad.
IanBenzMaxim 0:f77ad7f72d04 89 /// @param[out] esByte E/S byte read before scratchpad data.
IanBenzMaxim 6:a8c83a2e6fa4 90 MaximInterface_EXPORT error_code readScratchpad(Scratchpad::span data,
IanBenzMaxim 0:f77ad7f72d04 91 uint_least8_t & esByte);
IanBenzMaxim 0:f77ad7f72d04 92
IanBenzMaxim 7:471901a04573 93 /// @brief Copies contents of scratchpad to EEPROM.
IanBenzMaxim 0:f77ad7f72d04 94 /// @param[in] targetAddress EEPROM memory address that scratchpad
IanBenzMaxim 0:f77ad7f72d04 95 /// will be copied to. Must be on row boundary.
IanBenzMaxim 0:f77ad7f72d04 96 /// @param[in] esByte E/S byte from preceding Read Scratchpad command.
IanBenzMaxim 0:f77ad7f72d04 97 MaximInterface_EXPORT error_code copyScratchpad(Address targetAddress,
IanBenzMaxim 0:f77ad7f72d04 98 uint_least8_t esByte);
IanBenzMaxim 0:f77ad7f72d04 99
IanBenzMaxim 0:f77ad7f72d04 100 MaximInterface_EXPORT static const error_category & errorCategory();
IanBenzMaxim 0:f77ad7f72d04 101
IanBenzMaxim 0:f77ad7f72d04 102 private:
IanBenzMaxim 0:f77ad7f72d04 103 SelectRom selectRom;
IanBenzMaxim 0:f77ad7f72d04 104 OneWireMaster * master;
IanBenzMaxim 0:f77ad7f72d04 105 const Sleep * sleep;
IanBenzMaxim 0:f77ad7f72d04 106 };
IanBenzMaxim 0:f77ad7f72d04 107
IanBenzMaxim 7:471901a04573 108 /// @brief
IanBenzMaxim 0:f77ad7f72d04 109 /// Writes data to EEPROM using Write Scratchpad, Read Scratchpad,
IanBenzMaxim 0:f77ad7f72d04 110 /// and Copy Scratchpad commands.
IanBenzMaxim 7:471901a04573 111 /// @param device Device to write.
IanBenzMaxim 0:f77ad7f72d04 112 /// @param[in] targetAddress EEPROM memory address to start writing at.
IanBenzMaxim 0:f77ad7f72d04 113 /// @param[in] data Data to write to EEPROM.
IanBenzMaxim 0:f77ad7f72d04 114 MaximInterface_EXPORT error_code writeMemory(DS2431 & device,
IanBenzMaxim 0:f77ad7f72d04 115 DS2431::Address targetAddress,
IanBenzMaxim 6:a8c83a2e6fa4 116 DS2431::Scratchpad::const_span data);
IanBenzMaxim 0:f77ad7f72d04 117
IanBenzMaxim 0:f77ad7f72d04 118 inline error_code make_error_code(DS2431::ErrorValue e) {
IanBenzMaxim 0:f77ad7f72d04 119 return error_code(e, DS2431::errorCategory());
IanBenzMaxim 0:f77ad7f72d04 120 }
IanBenzMaxim 0:f77ad7f72d04 121
IanBenzMaxim 0:f77ad7f72d04 122 } // namespace MaximInterface
IanBenzMaxim 0:f77ad7f72d04 123
IanBenzMaxim 0:f77ad7f72d04 124 #endif