1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.
Dependents: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
Superseded by MaximInterface.
Slaves/Memory/DS2431/DS2431.h@118:d184e69051ad, 2016-08-22 (annotated)
- Committer:
- j3
- Date:
- Mon Aug 22 21:48:41 2016 +0000
- Revision:
- 118:d184e69051ad
- Parent:
- 117:632abc887f95
- Child:
- 141:cf38f48a2a49
removed '-' after DS2431 in brief
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 110:a3b5e2a4fdf2 | 1 | /******************************************************************//** |
j3 | 110:a3b5e2a4fdf2 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 110:a3b5e2a4fdf2 | 3 | * |
j3 | 110:a3b5e2a4fdf2 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 110:a3b5e2a4fdf2 | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 110:a3b5e2a4fdf2 | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 110:a3b5e2a4fdf2 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 110:a3b5e2a4fdf2 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 110:a3b5e2a4fdf2 | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 110:a3b5e2a4fdf2 | 10 | * |
j3 | 110:a3b5e2a4fdf2 | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 110:a3b5e2a4fdf2 | 12 | * in all copies or substantial portions of the Software. |
j3 | 110:a3b5e2a4fdf2 | 13 | * |
j3 | 110:a3b5e2a4fdf2 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 110:a3b5e2a4fdf2 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 110:a3b5e2a4fdf2 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 110:a3b5e2a4fdf2 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 110:a3b5e2a4fdf2 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 110:a3b5e2a4fdf2 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 110:a3b5e2a4fdf2 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 110:a3b5e2a4fdf2 | 21 | * |
j3 | 110:a3b5e2a4fdf2 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 110:a3b5e2a4fdf2 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 110:a3b5e2a4fdf2 | 24 | * Products, Inc. Branding Policy. |
j3 | 110:a3b5e2a4fdf2 | 25 | * |
j3 | 110:a3b5e2a4fdf2 | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 110:a3b5e2a4fdf2 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 110:a3b5e2a4fdf2 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 110:a3b5e2a4fdf2 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 110:a3b5e2a4fdf2 | 30 | * ownership rights. |
j3 | 110:a3b5e2a4fdf2 | 31 | **********************************************************************/ |
j3 | 110:a3b5e2a4fdf2 | 32 | |
j3 | 115:a1ca2f3bf46d | 33 | #ifndef OneWire_Slaves_Memory_DS2431 |
j3 | 115:a1ca2f3bf46d | 34 | #define OneWire_Slaves_Memory_DS2431 |
j3 | 110:a3b5e2a4fdf2 | 35 | |
j3 | 110:a3b5e2a4fdf2 | 36 | #include "Slaves/OneWireSlave.h" |
j3 | 110:a3b5e2a4fdf2 | 37 | |
j3 | 110:a3b5e2a4fdf2 | 38 | namespace OneWire |
j3 | 110:a3b5e2a4fdf2 | 39 | { |
j3 | 115:a1ca2f3bf46d | 40 | class OneWireMaster; |
j3 | 115:a1ca2f3bf46d | 41 | |
j3 | 110:a3b5e2a4fdf2 | 42 | /** |
j3 | 118:d184e69051ad | 43 | * @brief DS2431 1024-Bit 1-Wire EEPROM |
j3 | 117:632abc887f95 | 44 | * @details The DS2431 is a 1024-bit, 1-Wire® EEPROM chip organized |
j3 | 117:632abc887f95 | 45 | * as four memory pages of 256 bits each. Data is written to an 8-byte |
j3 | 117:632abc887f95 | 46 | * scratchpad, verified, and then copied to the EEPROM memory. As a |
j3 | 117:632abc887f95 | 47 | * special feature, the four memory pages can individually be write |
j3 | 117:632abc887f95 | 48 | * protected or put in EPROM-emulation mode, where bits can only be |
j3 | 117:632abc887f95 | 49 | * changed from a 1 to a 0 state. The DS2431 communicates over the |
j3 | 117:632abc887f95 | 50 | * single-conductor 1-Wire bus. The communication follows the standard |
j3 | 117:632abc887f95 | 51 | * 1-Wire protocol. Each device has its own unalterable and unique |
j3 | 117:632abc887f95 | 52 | * 64-bit ROM registration number that is factory lasered into the chip. |
j3 | 117:632abc887f95 | 53 | * The registration number is used to address the device in a multidrop, |
j3 | 117:632abc887f95 | 54 | * 1-Wire net environment. |
j3 | 110:a3b5e2a4fdf2 | 55 | */ |
j3 | 110:a3b5e2a4fdf2 | 56 | class DS2431 : public OneWireSlave |
j3 | 110:a3b5e2a4fdf2 | 57 | { |
j3 | 110:a3b5e2a4fdf2 | 58 | public: |
j3 | 110:a3b5e2a4fdf2 | 59 | |
j3 | 110:a3b5e2a4fdf2 | 60 | /**********************************************************//** |
j3 | 110:a3b5e2a4fdf2 | 61 | * @brief DS2431 constructor |
j3 | 110:a3b5e2a4fdf2 | 62 | * |
j3 | 115:a1ca2f3bf46d | 63 | * @details Instantiate a DS2431 object that encapsulates the |
j3 | 115:a1ca2f3bf46d | 64 | * 1-Wire master and ROM commands for selecting the device via |
j3 | 116:8058bb54e959 | 65 | * the RandomAccessRomIterator sub-class passed as an argument |
j3 | 115:a1ca2f3bf46d | 66 | * to the constructor. |
j3 | 115:a1ca2f3bf46d | 67 | * |
j3 | 115:a1ca2f3bf46d | 68 | * This allows the user to focus on the use of the DS2431 in |
j3 | 115:a1ca2f3bf46d | 69 | * their application vs. the low level details of the 1-Wire |
j3 | 115:a1ca2f3bf46d | 70 | * protocol. |
j3 | 110:a3b5e2a4fdf2 | 71 | * |
j3 | 110:a3b5e2a4fdf2 | 72 | * On Entry: |
j3 | 115:a1ca2f3bf46d | 73 | * @param[in] selector - reference to RandomAccessRomIterator |
j3 | 115:a1ca2f3bf46d | 74 | * sub-class; i.e. SingledropRomIterator, MultidropRomIterator, etc. |
j3 | 115:a1ca2f3bf46d | 75 | * See RomId/RomIterator.h |
j3 | 110:a3b5e2a4fdf2 | 76 | * |
j3 | 110:a3b5e2a4fdf2 | 77 | * On Exit: |
j3 | 110:a3b5e2a4fdf2 | 78 | * |
j3 | 110:a3b5e2a4fdf2 | 79 | * @return |
j3 | 110:a3b5e2a4fdf2 | 80 | **************************************************************/ |
j3 | 110:a3b5e2a4fdf2 | 81 | DS2431(RandomAccessRomIterator &selector); |
j3 | 115:a1ca2f3bf46d | 82 | |
j3 | 115:a1ca2f3bf46d | 83 | /**********************************************************//** |
j3 | 116:8058bb54e959 | 84 | * @brief writeMemory |
j3 | 116:8058bb54e959 | 85 | * |
j3 | 116:8058bb54e959 | 86 | * @details Writes data to EEPROM. Wraps up writeScratchPad, |
j3 | 116:8058bb54e959 | 87 | * readScratchPad and copyScratchPad into single function. |
j3 | 116:8058bb54e959 | 88 | * |
j3 | 116:8058bb54e959 | 89 | * On Entry: |
j3 | 116:8058bb54e959 | 90 | * @param[in] targetAddress - EEPROM memory address to start |
j3 | 116:8058bb54e959 | 91 | * writing at. |
j3 | 116:8058bb54e959 | 92 | * |
j3 | 116:8058bb54e959 | 93 | * @param[in] data - Pointer to memory holding data. |
j3 | 116:8058bb54e959 | 94 | * |
j3 | 116:8058bb54e959 | 95 | * @param[in] numBytes - Number of bytes to write. |
j3 | 116:8058bb54e959 | 96 | * |
j3 | 116:8058bb54e959 | 97 | * On Exit: |
j3 | 116:8058bb54e959 | 98 | * |
j3 | 116:8058bb54e959 | 99 | * @return Result of operation |
j3 | 116:8058bb54e959 | 100 | **************************************************************/ |
j3 | 116:8058bb54e959 | 101 | OneWireSlave::CmdResult writeMemory(uint16_t targetAddress, const uint8_t *data, uint8_t numBytes); |
j3 | 116:8058bb54e959 | 102 | |
j3 | 116:8058bb54e959 | 103 | /**********************************************************//** |
j3 | 116:8058bb54e959 | 104 | * @brief readMemory |
j3 | 116:8058bb54e959 | 105 | * |
j3 | 116:8058bb54e959 | 106 | * @details Reads block of data from EEPROM memory. |
j3 | 116:8058bb54e959 | 107 | * |
j3 | 116:8058bb54e959 | 108 | * On Entry: |
j3 | 116:8058bb54e959 | 109 | * @param[in] targetAddress - EEPROM memory address to start. |
j3 | 116:8058bb54e959 | 110 | * reading from |
j3 | 116:8058bb54e959 | 111 | * |
j3 | 116:8058bb54e959 | 112 | * @param[out] data - Pointer to memory for storing data. |
j3 | 116:8058bb54e959 | 113 | * |
j3 | 116:8058bb54e959 | 114 | * @param[in] numBytes - Number of bytes to read. |
j3 | 116:8058bb54e959 | 115 | * |
j3 | 116:8058bb54e959 | 116 | * On Exit: |
j3 | 116:8058bb54e959 | 117 | * |
j3 | 116:8058bb54e959 | 118 | * @return Result of operation |
j3 | 116:8058bb54e959 | 119 | **************************************************************/ |
j3 | 116:8058bb54e959 | 120 | OneWireSlave::CmdResult readMemory(uint16_t targetAddress, uint8_t *data, uint8_t numBytes); |
j3 | 116:8058bb54e959 | 121 | |
j3 | 116:8058bb54e959 | 122 | private: |
j3 | 116:8058bb54e959 | 123 | |
j3 | 116:8058bb54e959 | 124 | typedef array<uint8_t, 8> Scratchpad; |
j3 | 116:8058bb54e959 | 125 | |
j3 | 116:8058bb54e959 | 126 | /**********************************************************//** |
j3 | 116:8058bb54e959 | 127 | * @brief writeScratchpad |
j3 | 115:a1ca2f3bf46d | 128 | * |
j3 | 115:a1ca2f3bf46d | 129 | * @details Writes 8 bytes to the scratchpad. |
j3 | 115:a1ca2f3bf46d | 130 | * |
j3 | 115:a1ca2f3bf46d | 131 | * On Entry: |
j3 | 115:a1ca2f3bf46d | 132 | * @param[in] targetAddress - EEPROM memory address that this data |
j3 | 115:a1ca2f3bf46d | 133 | * will be copied to. Must be on row boundary. |
j3 | 115:a1ca2f3bf46d | 134 | * |
j3 | 116:8058bb54e959 | 135 | * @param[in] data - reference to bounded array type Scratchpad. |
j3 | 115:a1ca2f3bf46d | 136 | * |
j3 | 115:a1ca2f3bf46d | 137 | * On Exit: |
j3 | 115:a1ca2f3bf46d | 138 | * |
j3 | 115:a1ca2f3bf46d | 139 | * @return Result of operation |
j3 | 115:a1ca2f3bf46d | 140 | **************************************************************/ |
j3 | 116:8058bb54e959 | 141 | OneWireSlave::CmdResult writeScratchpad(uint16_t targetAddress, const Scratchpad &data); |
j3 | 115:a1ca2f3bf46d | 142 | |
j3 | 115:a1ca2f3bf46d | 143 | /**********************************************************//** |
j3 | 116:8058bb54e959 | 144 | * @brief readScratchpad |
j3 | 115:a1ca2f3bf46d | 145 | * |
j3 | 115:a1ca2f3bf46d | 146 | * @details Reads contents of scratchpad. |
j3 | 115:a1ca2f3bf46d | 147 | * |
j3 | 115:a1ca2f3bf46d | 148 | * On Entry: |
j3 | 116:8058bb54e959 | 149 | * @param[out] data - reference to bounded array type Scratchpad. |
j3 | 115:a1ca2f3bf46d | 150 | * |
j3 | 115:a1ca2f3bf46d | 151 | * On Exit: |
j3 | 115:a1ca2f3bf46d | 152 | * |
j3 | 115:a1ca2f3bf46d | 153 | * @return Result of operation |
j3 | 115:a1ca2f3bf46d | 154 | **************************************************************/ |
j3 | 116:8058bb54e959 | 155 | OneWireSlave::CmdResult readScratchpad(Scratchpad &data, uint8_t &esByte); |
j3 | 115:a1ca2f3bf46d | 156 | |
j3 | 115:a1ca2f3bf46d | 157 | /**********************************************************//** |
j3 | 116:8058bb54e959 | 158 | * @brief copyScratchpad |
j3 | 115:a1ca2f3bf46d | 159 | * |
j3 | 115:a1ca2f3bf46d | 160 | * @details Copies contents of sractshpad to EEPROM. |
j3 | 115:a1ca2f3bf46d | 161 | * |
j3 | 115:a1ca2f3bf46d | 162 | * On Entry: |
j3 | 115:a1ca2f3bf46d | 163 | * @param[in] targetAddress - EEPROM memory address that this data |
j3 | 115:a1ca2f3bf46d | 164 | * will be copied to. Must be on row boundary. |
j3 | 115:a1ca2f3bf46d | 165 | * |
j3 | 115:a1ca2f3bf46d | 166 | * @param[in] esByte - Returned from reading scratchpad. |
j3 | 115:a1ca2f3bf46d | 167 | * |
j3 | 115:a1ca2f3bf46d | 168 | * On Exit: |
j3 | 115:a1ca2f3bf46d | 169 | * |
j3 | 115:a1ca2f3bf46d | 170 | * @return Result of operation |
j3 | 115:a1ca2f3bf46d | 171 | **************************************************************/ |
j3 | 116:8058bb54e959 | 172 | OneWireSlave::CmdResult copyScratchpad(uint16_t targetAddress, uint8_t esByte); |
j3 | 110:a3b5e2a4fdf2 | 173 | }; |
j3 | 110:a3b5e2a4fdf2 | 174 | } |
j3 | 110:a3b5e2a4fdf2 | 175 | |
j3 | 115:a1ca2f3bf46d | 176 | #endif /*OneWire_Slaves_Memory_DS2431*/ |