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.

Committer:
IanBenzMaxim
Date:
Tue Mar 22 14:24:53 2016 -0500
Revision:
24:8942d8478d68
Parent:
21:00c94aeb533e
Child:
33:a4c015046956
Began cleanup of DS2465 class. Added relative include paths to help preprocessor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 17:b646b1e3970b 1 /******************************************************************//**
j3 17:b646b1e3970b 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 17:b646b1e3970b 3 *
j3 17:b646b1e3970b 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 17:b646b1e3970b 5 * copy of this software and associated documentation files (the "Software"),
j3 17:b646b1e3970b 6 * to deal in the Software without restriction, including without limitation
j3 17:b646b1e3970b 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 17:b646b1e3970b 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 17:b646b1e3970b 9 * Software is furnished to do so, subject to the following conditions:
j3 17:b646b1e3970b 10 *
j3 17:b646b1e3970b 11 * The above copyright notice and this permission notice shall be included
j3 17:b646b1e3970b 12 * in all copies or substantial portions of the Software.
j3 17:b646b1e3970b 13 *
j3 17:b646b1e3970b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 17:b646b1e3970b 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 17:b646b1e3970b 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 17:b646b1e3970b 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 17:b646b1e3970b 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 17:b646b1e3970b 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 17:b646b1e3970b 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 17:b646b1e3970b 21 *
j3 17:b646b1e3970b 22 * Except as contained in this notice, the name of Maxim Integrated
j3 17:b646b1e3970b 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 17:b646b1e3970b 24 * Products, Inc. Branding Policy.
j3 17:b646b1e3970b 25 *
j3 17:b646b1e3970b 26 * The mere transfer of this software does not imply any licenses
j3 17:b646b1e3970b 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 17:b646b1e3970b 28 * trademarks, maskwork rights, or any other form of intellectual
j3 17:b646b1e3970b 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 17:b646b1e3970b 30 * ownership rights.
j3 17:b646b1e3970b 31 **********************************************************************/
j3 17:b646b1e3970b 32
j3 17:b646b1e3970b 33
j3 17:b646b1e3970b 34 #ifndef _ROMID_HPP
j3 17:b646b1e3970b 35 #define _ROMID_HPP
j3 17:b646b1e3970b 36
j3 17:b646b1e3970b 37 #include <cstdint>
j3 17:b646b1e3970b 38 #include <cstring>
j3 17:b646b1e3970b 39
j3 17:b646b1e3970b 40 class RomId
j3 17:b646b1e3970b 41 {
j3 17:b646b1e3970b 42 public:
j3 17:b646b1e3970b 43 static const std::size_t byteLen = 8;
IanBenzMaxim 24:8942d8478d68 44 typedef std::uint8_t ByteBuffer[byteLen];
j3 17:b646b1e3970b 45
IanBenzMaxim 21:00c94aeb533e 46 static std::uint8_t calculateCRC8(std::uint8_t crc8, std::uint8_t data);
IanBenzMaxim 21:00c94aeb533e 47 static std::uint8_t calculateCRC8(const std::uint8_t * data, std::size_t data_len, std::uint8_t crc = 0);
j3 17:b646b1e3970b 48
j3 17:b646b1e3970b 49 private:
j3 17:b646b1e3970b 50 static const std::size_t familyCodeIdx = 0;
j3 17:b646b1e3970b 51 static const std::size_t crc8Idx = 7;
j3 17:b646b1e3970b 52 static const std::uint8_t defaultByteVal = 0x00;
j3 17:b646b1e3970b 53
IanBenzMaxim 24:8942d8478d68 54 ByteBuffer m_romId;
j3 17:b646b1e3970b 55
j3 17:b646b1e3970b 56 public:
j3 17:b646b1e3970b 57 const RomId & operator=(const RomId & rhs) {
j3 17:b646b1e3970b 58 std::memcpy(this->m_romId, rhs.m_romId, byteLen);
j3 17:b646b1e3970b 59 return rhs;
j3 17:b646b1e3970b 60 }
j3 17:b646b1e3970b 61 bool operator==(const RomId & rhs) const {
j3 17:b646b1e3970b 62 return (std::memcmp(this->m_romId, rhs.m_romId, byteLen) == 0);
j3 17:b646b1e3970b 63 }
j3 17:b646b1e3970b 64 bool operator!=(const RomId & rhs) const {
j3 17:b646b1e3970b 65 return !operator==(rhs);
j3 17:b646b1e3970b 66 }
IanBenzMaxim 24:8942d8478d68 67 operator ByteBuffer &() {
j3 17:b646b1e3970b 68 return m_romId; // Conversion to array reference
j3 17:b646b1e3970b 69 }
IanBenzMaxim 24:8942d8478d68 70 operator const ByteBuffer &() const {
j3 17:b646b1e3970b 71 return m_romId; // Conversion to const array reference
j3 17:b646b1e3970b 72 }
j3 17:b646b1e3970b 73
j3 17:b646b1e3970b 74 void reset() {
j3 17:b646b1e3970b 75 std::memset(m_romId, defaultByteVal, byteLen);
j3 17:b646b1e3970b 76 }
j3 17:b646b1e3970b 77
j3 17:b646b1e3970b 78 RomId() {
j3 17:b646b1e3970b 79 reset();
j3 17:b646b1e3970b 80 }
j3 17:b646b1e3970b 81 RomId(const RomId & romId) {
j3 17:b646b1e3970b 82 operator=(romId);
j3 17:b646b1e3970b 83 }
IanBenzMaxim 24:8942d8478d68 84 RomId(const ByteBuffer & romIdBytes) {
j3 17:b646b1e3970b 85 std::memcpy(m_romId, romIdBytes, byteLen);
j3 17:b646b1e3970b 86 }
j3 17:b646b1e3970b 87
j3 17:b646b1e3970b 88 std::uint8_t familyCode() const {
j3 17:b646b1e3970b 89 return m_romId[familyCodeIdx];
j3 17:b646b1e3970b 90 }
j3 17:b646b1e3970b 91 void setFamilyCode(std::uint8_t familyCode) {
j3 17:b646b1e3970b 92 m_romId[familyCodeIdx] = familyCode;
j3 17:b646b1e3970b 93 }
j3 17:b646b1e3970b 94
j3 17:b646b1e3970b 95 std::uint8_t crc8() const {
j3 17:b646b1e3970b 96 return m_romId[crc8Idx];
j3 17:b646b1e3970b 97 }
j3 17:b646b1e3970b 98 void setCrc8(std::uint8_t crc8) {
j3 17:b646b1e3970b 99 m_romId[crc8Idx] = crc8;
j3 17:b646b1e3970b 100 }
j3 17:b646b1e3970b 101 bool crc8Valid() const {
j3 17:b646b1e3970b 102 return (calculateCRC8(m_romId, (byteLen - 1), 0x00) == crc8());
j3 17:b646b1e3970b 103 }
j3 17:b646b1e3970b 104 void setValidCrc8() {
j3 17:b646b1e3970b 105 setCrc8(calculateCRC8(m_romId, (byteLen - 1), 0x00));
j3 17:b646b1e3970b 106 }
j3 17:b646b1e3970b 107
j3 17:b646b1e3970b 108 bool valid() const {
j3 17:b646b1e3970b 109 return (crc8Valid() && (familyCode() != defaultByteVal));
j3 17:b646b1e3970b 110 }
j3 17:b646b1e3970b 111 };
j3 17:b646b1e3970b 112
j3 17:b646b1e3970b 113 #endif