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.
RomId.hpp@33:a4c015046956, 2016-03-31 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Thu Mar 31 11:56:01 2016 -0500
- Revision:
- 33:a4c015046956
- Parent:
- 24:8942d8478d68
- Child:
- 49:36954b62f503
Created a generic array wrapper class. Updated array types used in ISha256MacCoprocessor and DS28E15_22_25 for clarity.
Who changed what in which revision?
User | Revision | Line number | New 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> |
IanBenzMaxim | 33:a4c015046956 | 38 | |
IanBenzMaxim | 33:a4c015046956 | 39 | #include "array.hpp" |
j3 | 17:b646b1e3970b | 40 | |
j3 | 17:b646b1e3970b | 41 | class RomId |
j3 | 17:b646b1e3970b | 42 | { |
j3 | 17:b646b1e3970b | 43 | public: |
j3 | 17:b646b1e3970b | 44 | static const std::size_t byteLen = 8; |
IanBenzMaxim | 33:a4c015046956 | 45 | typedef array<std::uint8_t, byteLen>::Buffer ByteBuffer; |
j3 | 17:b646b1e3970b | 46 | |
IanBenzMaxim | 21:00c94aeb533e | 47 | static std::uint8_t calculateCRC8(std::uint8_t crc8, std::uint8_t data); |
IanBenzMaxim | 21:00c94aeb533e | 48 | static std::uint8_t calculateCRC8(const std::uint8_t * data, std::size_t data_len, std::uint8_t crc = 0); |
j3 | 17:b646b1e3970b | 49 | |
j3 | 17:b646b1e3970b | 50 | private: |
j3 | 17:b646b1e3970b | 51 | static const std::size_t familyCodeIdx = 0; |
j3 | 17:b646b1e3970b | 52 | static const std::size_t crc8Idx = 7; |
j3 | 17:b646b1e3970b | 53 | static const std::uint8_t defaultByteVal = 0x00; |
j3 | 17:b646b1e3970b | 54 | |
IanBenzMaxim | 33:a4c015046956 | 55 | array<std::uint8_t, byteLen> m_romId; |
j3 | 17:b646b1e3970b | 56 | |
j3 | 17:b646b1e3970b | 57 | public: |
j3 | 17:b646b1e3970b | 58 | const RomId & operator=(const RomId & rhs) { |
IanBenzMaxim | 33:a4c015046956 | 59 | this->m_romId = rhs.m_romId; |
j3 | 17:b646b1e3970b | 60 | return rhs; |
j3 | 17:b646b1e3970b | 61 | } |
j3 | 17:b646b1e3970b | 62 | bool operator==(const RomId & rhs) const { |
IanBenzMaxim | 33:a4c015046956 | 63 | return (this->m_romId == rhs.m_romId); |
j3 | 17:b646b1e3970b | 64 | } |
j3 | 17:b646b1e3970b | 65 | bool operator!=(const RomId & rhs) const { |
j3 | 17:b646b1e3970b | 66 | return !operator==(rhs); |
j3 | 17:b646b1e3970b | 67 | } |
IanBenzMaxim | 24:8942d8478d68 | 68 | operator ByteBuffer &() { |
j3 | 17:b646b1e3970b | 69 | return m_romId; // Conversion to array reference |
j3 | 17:b646b1e3970b | 70 | } |
IanBenzMaxim | 24:8942d8478d68 | 71 | operator const ByteBuffer &() const { |
j3 | 17:b646b1e3970b | 72 | return m_romId; // Conversion to const array reference |
j3 | 17:b646b1e3970b | 73 | } |
j3 | 17:b646b1e3970b | 74 | |
j3 | 17:b646b1e3970b | 75 | void reset() { |
j3 | 17:b646b1e3970b | 76 | std::memset(m_romId, defaultByteVal, byteLen); |
j3 | 17:b646b1e3970b | 77 | } |
j3 | 17:b646b1e3970b | 78 | |
IanBenzMaxim | 33:a4c015046956 | 79 | RomId() { reset(); } |
IanBenzMaxim | 33:a4c015046956 | 80 | RomId(const RomId & romId) : m_romId(romId.m_romId) { } |
IanBenzMaxim | 33:a4c015046956 | 81 | RomId(const ByteBuffer & romIdBytes) : m_romId(romIdBytes) { } |
j3 | 17:b646b1e3970b | 82 | |
j3 | 17:b646b1e3970b | 83 | std::uint8_t familyCode() const { |
j3 | 17:b646b1e3970b | 84 | return m_romId[familyCodeIdx]; |
j3 | 17:b646b1e3970b | 85 | } |
j3 | 17:b646b1e3970b | 86 | void setFamilyCode(std::uint8_t familyCode) { |
j3 | 17:b646b1e3970b | 87 | m_romId[familyCodeIdx] = familyCode; |
j3 | 17:b646b1e3970b | 88 | } |
j3 | 17:b646b1e3970b | 89 | |
j3 | 17:b646b1e3970b | 90 | std::uint8_t crc8() const { |
j3 | 17:b646b1e3970b | 91 | return m_romId[crc8Idx]; |
j3 | 17:b646b1e3970b | 92 | } |
j3 | 17:b646b1e3970b | 93 | void setCrc8(std::uint8_t crc8) { |
j3 | 17:b646b1e3970b | 94 | m_romId[crc8Idx] = crc8; |
j3 | 17:b646b1e3970b | 95 | } |
j3 | 17:b646b1e3970b | 96 | bool crc8Valid() const { |
j3 | 17:b646b1e3970b | 97 | return (calculateCRC8(m_romId, (byteLen - 1), 0x00) == crc8()); |
j3 | 17:b646b1e3970b | 98 | } |
j3 | 17:b646b1e3970b | 99 | void setValidCrc8() { |
j3 | 17:b646b1e3970b | 100 | setCrc8(calculateCRC8(m_romId, (byteLen - 1), 0x00)); |
j3 | 17:b646b1e3970b | 101 | } |
j3 | 17:b646b1e3970b | 102 | |
j3 | 17:b646b1e3970b | 103 | bool valid() const { |
j3 | 17:b646b1e3970b | 104 | return (crc8Valid() && (familyCode() != defaultByteVal)); |
j3 | 17:b646b1e3970b | 105 | } |
j3 | 17:b646b1e3970b | 106 | }; |
j3 | 17:b646b1e3970b | 107 | |
j3 | 17:b646b1e3970b | 108 | #endif |