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:
141:cf38f48a2a49
Parent:
139:f0e0a7976846
diff -r 6f32bf635c9d -r cf38f48a2a49 Masters/DS2465/DS2465.cpp
--- a/Masters/DS2465/DS2465.cpp	Fri Feb 17 19:09:11 2017 +0000
+++ b/Masters/DS2465/DS2465.cpp	Fri Feb 17 21:54:14 2017 +0000
@@ -73,6 +73,7 @@
 };
 
 static const int I2C_WRITE_OK = 1;
+static const uint8_t maxBlockSize = 63;
 
 uint8_t DS2465::Config::readByte() const
 {
@@ -324,66 +325,69 @@
     return result;
 }
 
-OneWireMaster::CmdResult DS2465::OWReadBlock(uint8_t *recvBuf, uint8_t recvLen)
+OneWireMaster::CmdResult DS2465::OWReadBlock(uint8_t *recvBuf, size_t recvLen)
 {
     // 1-Wire Receive Block (Case A)
     //   S AD,0 [A] CommandReg [A] 1WRF [A] PR [A] P
     //  [] indicates from slave
     //  PR indicates byte containing parameter
 
-    OneWireMaster::CmdResult result;
-    uint8_t command[2] = { OwReceiveBlockCmd, recvLen };
-
-    result = writeMemory(CommandReg, command, 2);
-    if (result == OneWireMaster::Success)
+    OneWireMaster::CmdResult result = OneWireMaster::Success;
+    for (size_t i = 0; (i < recvLen) && (result == OneWireMaster::Success); i += maxBlockSize)
     {
-        result = pollBusy();
+        uint8_t command[2] = { OwReceiveBlockCmd, std::min(static_cast<uint8_t>(recvLen - i), maxBlockSize) };
+        result = writeMemory(CommandReg, command, 2);
+        if (result == OneWireMaster::Success)
+        {
+            result = pollBusy();
+        }
+        if (result == OneWireMaster::Success)
+        {
+            result = readMemory(Scratchpad, recvBuf + i, command[1], false);
+        }
     }
-    if (result == OneWireMaster::Success)
-    {
-        result = readMemory(Scratchpad, recvBuf, recvLen, false);
-    }
-
     return result;
 }
 
-OneWireMaster::CmdResult DS2465::OWWriteBlock(const uint8_t *sendBuf, uint8_t sendLen)
+OneWireMaster::CmdResult DS2465::OWWriteBlock(const uint8_t *sendBuf, size_t sendLen)
 {
-    return OWWriteBlock(false, sendBuf, sendLen);
+    OneWireMaster::CmdResult result = OneWireMaster::Success;
+    for (size_t i = 0; (i < sendLen) && (result == OneWireMaster::Success); i += maxBlockSize)
+    {
+        uint8_t command[2] = { OwTransmitBlockCmd, std::min(static_cast<uint8_t>(sendLen - i), maxBlockSize) };
+
+        // prefill scratchpad with required data
+        result = writeMemory(Scratchpad, sendBuf + i, command[1]);
+
+        // 1-Wire Transmit Block (Case A)
+        //   S AD,0 [A] CommandReg [A] 1WTB [A] PR [A] P
+        //  [] indicates from slave
+        //  PR indicates byte containing parameter
+        if (result == OneWireMaster::Success)
+        {
+            result = writeMemory(CommandReg, command, 2);
+        }
+        if (result == OneWireMaster::Success)
+        {
+            result = pollBusy();
+        }
+    }
+    return result;
 }
 
 OneWireMaster::CmdResult DS2465::OWWriteBlockMac()
 {
-    return OWWriteBlock(true, NULL, 0);
-}
-
-OneWireMaster::CmdResult DS2465::OWWriteBlock(bool tx_mac, const uint8_t *tran_buf, uint8_t tran_len)
-{
-    OneWireMaster::CmdResult result;
-    uint8_t command[2] = { OwTransmitBlockCmd, (uint8_t)(tx_mac ? 0xFF : tran_len) };
-
-    if (!tx_mac)
-    {
-        // prefill scratchpad with required data
-        result = writeMemory(Scratchpad, tran_buf, tran_len);
-        if (result != OneWireMaster::Success)
-        {
-            return result;
-        }
-    }
-
     // 1-Wire Transmit Block (Case A)
     //   S AD,0 [A] CommandReg [A] 1WTB [A] PR [A] P
     //  [] indicates from slave
     //  PR indicates byte containing parameter
 
-    result = writeMemory(CommandReg, command, 2);
-
+    uint8_t command[2] = { OwTransmitBlockCmd, 0xFF };
+    OneWireMaster::CmdResult result = writeMemory(CommandReg, command, 2);
     if (result == OneWireMaster::Success)
     {
         result = pollBusy();
     }
-
     return result;
 }