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:
76:84e6c4994e29
Parent:
75:8b627804927c
Child:
77:529edb329ee0
diff -r 8b627804927c -r 84e6c4994e29 Authenticators/DS28E15_22_25/DS28E15_22_25.cpp
--- a/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp	Fri May 13 14:52:50 2016 -0500
+++ b/Authenticators/DS28E15_22_25/DS28E15_22_25.cpp	Sat May 14 14:27:56 2016 -0500
@@ -34,10 +34,7 @@
 #include "Masters/OneWireMaster.h"
 #include "wait_api.h"
 
-using OneWire::Authenticators::DS28E15_22_25;
-using OneWire::Authenticators::ISha256MacCoproc;
-using OneWire::OneWireSlave;
-using OneWire::Masters::OneWireMaster;
+using namespace OneWire;
 
 /// 1-Wire device commands.
 enum Command
@@ -140,8 +137,8 @@
     }
 }
 
-DS28E15_22_25::DS28E15_22_25(OneWireMaster& OW_master, bool lowVoltage)
-    : lowVoltage(lowVoltage), m_OW_master(OW_master)
+DS28E15_22_25::DS28E15_22_25(OneWireMaster & owMaster, bool lowVoltage)
+    : OneWireSlave(&owMaster), lowVoltage(lowVoltage)
 {
     std::memset(manId, 0x00, manId.length);
 }
@@ -208,19 +205,19 @@
     buf[cnt++] = newProtection.statusByte();
 
     // Send command
-    m_OW_master.OWWriteBlock(&buf[0], 2);
+    p_owMaster->OWWriteBlock(&buf[0], 2);
 
     // read first CRC byte
-    m_OW_master.OWReadByte(buf[cnt++]);
+    p_owMaster->OWReadByte(buf[cnt++]);
 
     // read the last CRC and enable
-    m_OW_master.OWReadBytePower(buf[cnt++]);
+    p_owMaster->OWReadBytePower(buf[cnt++]);
 
     // now wait for the MAC computation.
     wait_ms(shaComputationDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // check CRC16
     if (OneWireMaster::calculateCrc16(buf, 0, cnt) != 0xB001)
@@ -237,10 +234,10 @@
     cnt = 0;
 
     // send the MAC
-    m_OW_master.OWWriteBlock(mac, mac.length);
+    p_owMaster->OWWriteBlock(mac, mac.length);
 
     // Read CRC and CS byte
-    m_OW_master.OWReadBlock(&buf[cnt], 3);
+    p_owMaster->OWReadBlock(&buf[cnt], 3);
     cnt += 3;
 
     // check CRC16
@@ -257,16 +254,16 @@
 
     // send release and strong pull-up
     // DATASHEET_CORRECTION - last bit in release is a read-zero so don't check echo of write byte
-    m_OW_master.OWWriteBytePower(0xAA);
+    p_owMaster->OWWriteBytePower(0xAA);
 
     // now wait for the programming.
     wait_ms(eepromWriteDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
 
     if (cs == 0xAA)
     {
@@ -286,10 +283,10 @@
     // compute parameter byte 
     buf[cnt++] = protection.statusByte();
 
-    m_OW_master.OWWriteBlock(&buf[0], cnt);
+    p_owMaster->OWWriteBlock(&buf[0], cnt);
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     // check CRC16
@@ -299,16 +296,16 @@
     }
 
     // sent release
-    m_OW_master.OWWriteBytePower(0xAA);
+    p_owMaster->OWWriteBytePower(0xAA);
 
     // now wait for the programming.
     wait_ms(eepromWriteDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
 
     if (cs == 0xAA)
     {
@@ -386,7 +383,7 @@
     }
 
     // send the command
-    m_OW_master.OWWriteBlock(&buf[0], 2);
+    p_owMaster->OWWriteBlock(&buf[0], 2);
 
     offset = cnt + 2;
 
@@ -411,7 +408,7 @@
     rdnum += crcLen; // Add in CRC length
 
     // Read the bytes 
-    m_OW_master.OWReadBlock(&buf[cnt], rdnum);
+    p_owMaster->OWReadBlock(&buf[cnt], rdnum);
     cnt += rdnum;
 
     // check the first CRC16
@@ -485,19 +482,19 @@
     buf[cnt++] = ((anon) ? 0xE0 : 0x00) | page_num;
 
     // Send command
-    m_OW_master.OWWriteBlock(&buf[0], 2);
+    p_owMaster->OWWriteBlock(&buf[0], 2);
 
     // read first CRC byte
-    m_OW_master.OWReadByte(buf[cnt++]);
+    p_owMaster->OWReadByte(buf[cnt++]);
 
     // read the last CRC and enable
-    m_OW_master.OWReadBytePower(buf[cnt++]);
+    p_owMaster->OWReadBytePower(buf[cnt++]);
 
     // now wait for the MAC computation.
     wait_ms(shaComputationDelayMs * 2);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // check CRC16
     if (OneWireMaster::calculateCrc16(buf, 0, cnt) != 0xB001)
@@ -506,14 +503,14 @@
     }
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
     if (cs != 0xAA)
     {
         return OperationFailure;
     }
 
     // read the MAC and CRC
-    m_OW_master.OWReadBlock(&buf[0], (Mac::length + 2));
+    p_owMaster->OWReadBlock(&buf[0], (Mac::length + 2));
 
     // check CRC16
     if (OneWireMaster::calculateCrc16(buf, 0, (Mac::length + 2)) != 0xB001)
@@ -536,10 +533,10 @@
     buf[cnt++] = (lock) ? (0xE0 | page_num) : page_num;  // lock flag 
 
     // Send command
-    m_OW_master.OWWriteBlock(&buf[0], 2);
+    p_owMaster->OWWriteBlock(&buf[0], 2);
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     // check CRC16
@@ -549,16 +546,16 @@
     }
 
     // send release and strong pull-up
-    m_OW_master.OWWriteBytePower(0xAA);
+    p_owMaster->OWWriteBytePower(0xAA);
 
     // now wait for the MAC computations and secret programming.
     wait_ms(shaComputationDelayMs * 2 + secretEepromWriteDelayMs());
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
 
     if (cs == 0xAA)
     {
@@ -584,10 +581,10 @@
     }
 
     // Send command
-    m_OW_master.OWWriteBlock(&buf[0], 2);
+    p_owMaster->OWWriteBlock(&buf[0], 2);
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     offset = cnt;
@@ -597,10 +594,10 @@
     cnt += data.length;
 
     // Send the data
-    m_OW_master.OWWriteBlock(data, data.length);
+    p_owMaster->OWWriteBlock(data, data.length);
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     // check first CRC16
@@ -634,20 +631,20 @@
     }
 
     // Send command
-    m_OW_master.OWWriteBlock(&buf[0], 2);
+    p_owMaster->OWWriteBlock(&buf[0], 2);
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     offset = cnt;
 
     // Receive the data
-    m_OW_master.OWReadBlock(&buf[cnt], data.length);
+    p_owMaster->OWReadBlock(&buf[cnt], data.length);
     cnt += data.length;
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     // check first CRC16
@@ -677,10 +674,10 @@
     buf[cnt++] = (lock) ? 0xE0 : 0x00;  // lock flag 
 
     // Send command
-    m_OW_master.OWWriteBlock(&buf[0], 2);
+    p_owMaster->OWWriteBlock(&buf[0], 2);
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     // check CRC16
@@ -690,16 +687,16 @@
     }
 
     // send release and strong pull-up
-    m_OW_master.OWWriteBytePower(0xAA);
+    p_owMaster->OWWriteBytePower(0xAA);
 
     // now wait for the secret programming.
     wait_ms(secretEepromWriteDelayMs());
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
 
     if (cs == 0xAA)
     {
@@ -724,17 +721,17 @@
         buf[cnt++] = page;   // address 
 
         // Send command
-        m_OW_master.OWWriteBlock(&buf[0], 2);
+        p_owMaster->OWWriteBlock(&buf[0], 2);
 
         // Read CRC
-        m_OW_master.OWReadBlock(&buf[cnt], 2);
+        p_owMaster->OWReadBlock(&buf[cnt], 2);
         cnt += 2;
 
         offset = cnt;
     }
 
     // read data and CRC16
-    m_OW_master.OWReadBlock(&buf[cnt], (rdbuf.length + 2));
+    p_owMaster->OWReadBlock(&buf[cnt], (rdbuf.length + 2));
     cnt += 34;
 
     // check the first CRC16
@@ -773,10 +770,10 @@
         buf[cnt++] = (segmentNum << 5) | pageNum;   // address 
 
         // Send command
-        m_OW_master.OWWriteBlock(&buf[0], 2);
+        p_owMaster->OWWriteBlock(&buf[0], 2);
 
         // Read CRC
-        m_OW_master.OWReadBlock(&buf[cnt], 2);
+        p_owMaster->OWReadBlock(&buf[cnt], 2);
         cnt += 2;
 
         offset = cnt;
@@ -789,19 +786,19 @@
     }
 
     // Send data
-    m_OW_master.OWWriteBlock(newData, newData.length);
+    p_owMaster->OWWriteBlock(newData, newData.length);
 
     // read first CRC byte
-    m_OW_master.OWReadByte(buf[cnt++]);
+    p_owMaster->OWReadByte(buf[cnt++]);
 
     // read the last CRC and enable power
-    m_OW_master.OWReadBytePower(buf[cnt++]);
+    p_owMaster->OWReadBytePower(buf[cnt++]);
 
     // now wait for the MAC computation.
     wait_ms(shaComputationDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // check the first CRC16
     if (!continuing)
@@ -832,13 +829,13 @@
     }
 
     // transmit MAC as a block
-    m_OW_master.OWWriteBlock(mac, mac.length);
+    p_owMaster->OWWriteBlock(mac, mac.length);
 
     // calculate CRC on MAC
     CRC16 = OneWireMaster::calculateCrc16(mac, 0, mac.length);
 
     // append read of CRC16 and CS byte
-    m_OW_master.OWReadBlock(&buf[0], 3);
+    p_owMaster->OWReadBlock(&buf[0], 3);
     cnt = 3;
 
     // ckeck CRC16
@@ -856,16 +853,16 @@
     }
 
     // send release and strong pull-up
-    m_OW_master.OWWriteBytePower(0xAA);
+    p_owMaster->OWWriteBytePower(0xAA);
 
     // now wait for the programming.
     wait_ms(eepromWriteDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
 
     if (cs == 0xAA)
     {
@@ -940,10 +937,10 @@
         buf[cnt++] = (segmentNum << 5) | pageNum;   // address 
 
         // Send command
-        m_OW_master.OWWriteBlock(&buf[0], 2);
+        p_owMaster->OWWriteBlock(&buf[0], 2);
 
         // Read CRC
-        m_OW_master.OWReadBlock(&buf[cnt], 2);
+        p_owMaster->OWReadBlock(&buf[cnt], 2);
         cnt += 2;
 
         offset = cnt;
@@ -956,19 +953,19 @@
     }
 
     // Send data
-    m_OW_master.OWWriteBlock(newData, newData.length);
+    p_owMaster->OWWriteBlock(newData, newData.length);
 
     // read first CRC byte
-    m_OW_master.OWReadByte(buf[cnt++]);
+    p_owMaster->OWReadByte(buf[cnt++]);
 
     // read the last CRC and enable power
-    m_OW_master.OWReadBytePower(buf[cnt++]);
+    p_owMaster->OWReadBytePower(buf[cnt++]);
 
     // now wait for the MAC computation.
     wait_ms(shaComputationDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // check the first CRC16
     if (!continuing)
@@ -1006,13 +1003,13 @@
     }
 
     // transmit MAC as a block
-    m_OW_master.OWWriteBlock(mac, mac.length);
+    p_owMaster->OWWriteBlock(mac, mac.length);
 
     // calculate CRC on MAC
     CRC16 = OneWireMaster::calculateCrc16(mac, 0, mac.length);
 
     // append read of CRC16 and CS byte
-    m_OW_master.OWReadBlock(&buf[0], 3);
+    p_owMaster->OWReadBlock(&buf[0], 3);
     cnt = 3;
 
     // ckeck CRC16
@@ -1030,16 +1027,16 @@
     }
 
     // send release and strong pull-up
-    m_OW_master.OWWriteBytePower(0xAA);
+    p_owMaster->OWWriteBytePower(0xAA);
 
     // now wait for the programming.
     wait_ms(eepromWriteDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
 
     if (cs == 0xAA)
     {
@@ -1060,21 +1057,21 @@
         buf[1] = (segment << 5) | page;
 
         // Transmit command
-        m_OW_master.OWWriteBlock(buf, 2);
+        p_owMaster->OWWriteBlock(buf, 2);
 
         // Receive CRC
-        result = m_OW_master.OWReadBlock(buf, 2);
+        result = p_owMaster->OWReadBlock(buf, 2);
     }
     else if (segment == 0)
     {
         // Receive CRC from previous read
-        result = m_OW_master.OWReadBlock(buf, 2);
+        result = p_owMaster->OWReadBlock(buf, 2);
     }
 
     // Receive data
     if (result == OneWireMaster::Success)
     {
-        result = m_OW_master.OWReadBlock(data, data.length);
+        result = p_owMaster->OWReadBlock(data, data.length);
     }
 
     return (result == OneWireMaster::Success ? OneWireSlave::Success : OneWireSlave::CommunicationError);
@@ -1095,10 +1092,10 @@
         buf[cnt++] = (block << 5) | page;   // address 
 
         // Send command 
-        m_OW_master.OWWriteBlock(&buf[0], 2);
+        p_owMaster->OWWriteBlock(&buf[0], 2);
 
         // Read CRC
-        m_OW_master.OWReadBlock(&buf[cnt], 2);
+        p_owMaster->OWReadBlock(&buf[cnt], 2);
         cnt += 2;
 
         offset = cnt;
@@ -1111,10 +1108,10 @@
     }
 
     // Send data
-    m_OW_master.OWWriteBlock(data, data.length);
+    p_owMaster->OWWriteBlock(data, data.length);
 
     // Read CRC
-    m_OW_master.OWReadBlock(&buf[cnt], 2);
+    p_owMaster->OWReadBlock(&buf[cnt], 2);
     cnt += 2;
 
     // check the first CRC16
@@ -1133,16 +1130,16 @@
     }
 
     // send release and strong pull-up
-    m_OW_master.OWWriteBytePower(0xAA);
+    p_owMaster->OWWriteBytePower(0xAA);
 
     // now wait for the programming.
     wait_ms(eepromWriteDelayMs);
 
     // disable strong pullup
-    m_OW_master.OWSetLevel(OneWireMaster::NormalLevel);
+    p_owMaster->OWSetLevel(OneWireMaster::NormalLevel);
 
     // read the CS byte
-    m_OW_master.OWReadByte(cs);
+    p_owMaster->OWReadByte(cs);
 
     if (cs == 0xAA)
     {