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.

Revision:
62:43039aeca2ab
Parent:
60:e8244cbc7946
diff -r 268612a10614 -r 43039aeca2ab OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.hpp
--- a/OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.hpp	Thu Apr 14 14:38:42 2016 -0500
+++ b/OneWire_Memory/Authenticators/DS28E15_22_25/DS28E15_22_25.hpp	Tue Apr 19 10:05:06 2016 -0500
@@ -64,8 +64,65 @@
     UNKNOWN_BLOCKS = 0
   };
   
+  /// Holds the contents of a device memory segment.
+  typedef array<std::uint8_t, 4> Segment;
+  
   /// Holds the contents of a device memory page.
-  typedef array<std::uint8_t, 32> Page;
+  class Page
+  {
+  public:
+    /// Length of the buffer in bytes.
+    static const std::size_t length = 32;
+    
+  private:
+    array<std::uint8_t, length> m_data;
+    
+  public:
+    /// Built-in array representation.
+    typedef array<std::uint8_t, length>::Buffer Buffer;
+    
+    Page() { }
+    Page(const Page & page) : m_data(page.m_data) { }
+    Page(const Buffer & dataBytes) : m_data(dataBytes) { }
+    
+    const Page & operator=(const Page & rhs)
+    {
+      this->m_data = rhs.m_data;
+      return rhs;
+    }
+    
+    bool operator==(const Page & rhs) const
+    {
+      return (this->m_data == rhs.m_data);
+    }
+    
+    bool operator!=(const Page & rhs) const
+    {
+      return !operator==(rhs);
+    }
+    
+    /// Conversion to array reference.
+    operator Buffer &()
+    {
+      return m_data;
+    }
+    
+    /// Conversion to const array reference.
+    operator const Buffer &() const
+    {
+      return m_data;
+    }
+    
+    /// Creates a segment representation from a subsection of the page data.
+    /// @param segmentNum Segment number within page to copy from.
+    /// @returns The copied segment data.
+    Segment toSegment(unsigned int segmentNum) const;
+    
+    /// Copies segment data to the page.
+    /// @param segmentNum Segment number within the page to copy to.
+    /// @param[in] segment Segment to copy from.
+    void fromSegment(unsigned int segmentNum, const Segment & segment);
+  };
   
   /// Holds the contents of the device scratchpad.
   typedef array<std::uint8_t, 32> Scratchpad;
@@ -73,9 +130,6 @@
   /// Container for a SHA-256 MAC.
   typedef array<std::uint8_t, 32> Mac;
   
-  /// Holds the contents of a device memory segment.
-  typedef array<std::uint8_t, 4> Segment;
-  
   /// Container for a manufacturer ID.
   typedef array<std::uint8_t, 2> ManId;
   
@@ -88,9 +142,9 @@
       std::uint8_t PB1;
       std::uint8_t PB2;
       ManId::Buffer manIdBytes;
+      
+      bool secretLocked() const { return (PB2 & 0x01); }
     } fields;
-    
-    bool secretLocked() const { return (fields.PB2 & 0x01); }
   };
   
   /// Represents the status of a memory protection block.
@@ -226,6 +280,9 @@
                                                              const ManId & manId,
                                                              Mac & mac);
   
+  /// Number of segments per page.
+  static const unsigned int segmentsPerPage = (Page::length / Segment::length);
+  
   /// Manufacturer ID
   ManId manId;