Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Committer:
reARMnimator
Date:
Mon Jan 06 15:54:55 2020 +0000
Revision:
10:de4b8812877d
Parent:
9:aeda90624ad0
Fixed inappropriate include path.

Who changed what in which revision?

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