Extended MaximInterface

Dependents:   mbed_DS28EC20_GPIO

Revision:
8:211d1b8f730c
Parent:
7:471901a04573
--- a/Links/OneWireMaster.hpp	Tue Jul 24 08:33:31 2018 +0000
+++ b/Links/OneWireMaster.hpp	Wed Apr 03 12:33:10 2019 +0000
@@ -33,9 +33,9 @@
 #ifndef MaximInterface_OneWireMaster
 #define MaximInterface_OneWireMaster
 
-#include <stddef.h>
 #include <stdint.h>
 #include <MaximInterface/Utilities/Export.h>
+#include <MaximInterface/Utilities/span.hpp>
 #include <MaximInterface/Utilities/system_error.hpp>
 
 namespace MaximInterface {
@@ -65,10 +65,13 @@
 
   virtual ~OneWireMaster() {}
 
+  /// @brief
   /// Reset all of the devices on the 1-Wire bus and check for a presence pulse.
-  /// @returns NoSlaveError if reset was performed but no presence pulse was detected.
+  /// @returns
+  /// NoSlaveError if reset was performed but no presence pulse was detected.
   virtual error_code reset() = 0;
 
+  /// @brief
   /// Send and receive one bit of communication and set a new level on the
   /// 1-Wire bus.
   /// @param[in,out] sendRecvBit
@@ -76,29 +79,29 @@
   /// @param afterLevel Level to set the 1-Wire bus to after communication.
   virtual error_code touchBitSetLevel(bool & sendRecvBit, Level afterLevel) = 0;
 
+  /// @brief
   /// Send one byte of communication and set a new level on the 1-Wire bus.
   /// @param sendByte Byte to send on the 1-Wire bus.
   /// @param afterLevel Level to set the 1-Wire bus to after communication.
   MaximInterface_EXPORT virtual error_code
   writeByteSetLevel(uint_least8_t sendByte, Level afterLevel);
 
+  /// @brief
   /// Receive one byte of communication and set a new level on the 1-Wire bus.
   /// @param recvByte Buffer to receive the data from the 1-Wire bus.
   /// @param afterLevel Level to set the 1-Wire bus to after communication.
   MaximInterface_EXPORT virtual error_code
   readByteSetLevel(uint_least8_t & recvByte, Level afterLevel);
 
-  /// Send a block of communication on the 1-Wire bus.
+  /// @brief Send a block of communication on the 1-Wire bus.
   /// @param[in] sendBuf Buffer to send on the 1-Wire bus.
-  /// @param sendLen Length of the buffer to send.
   MaximInterface_EXPORT virtual error_code
-  writeBlock(const uint_least8_t * sendBuf, size_t sendLen);
+  writeBlock(span<const uint_least8_t> sendBuf);
 
-  /// Receive a block of communication on the 1-Wire bus.
+  /// @brief Receive a block of communication on the 1-Wire bus.
   /// @param[out] recvBuf Buffer to receive the data from the 1-Wire bus.
-  /// @param recvLen Length of the buffer to receive.
-  MaximInterface_EXPORT virtual error_code readBlock(uint_least8_t * recvBuf,
-                                                     size_t recvLen);
+  MaximInterface_EXPORT virtual error_code
+  readBlock(span<uint_least8_t> recvBuf);
 
   /// Set the 1-Wire bus communication speed.
   virtual error_code setSpeed(Speed newSpeed) = 0;
@@ -106,16 +109,17 @@
   /// Set the 1-Wire bus level.
   virtual error_code setLevel(Level newLevel) = 0;
 
-  /// 1-Wire Triplet operation.
+  /// @brief 1-Wire Triplet operation.
   /// @details Perform one bit of a 1-Wire search. This command
   /// does two read bits and one write bit. The write bit is either
   /// the default direction (all devices have same bit) or in case
   /// of a discrepancy, the data.writeBit parameter is used.
-  ///@param[in,out] data
+  /// @param[in,out] data
   /// Input with desired writeBit in case both read bits are zero.
   /// Output with all data fields set.
   MaximInterface_EXPORT virtual error_code triplet(TripletData & data);
 
+  /// @brief
   /// Send one bit of communication and set a new level on the 1-Wire bus.
   /// @param sendBit Bit to send on the 1-Wire bus.
   /// @param afterLevel Level to set the 1-Wire bus to after communication.
@@ -123,6 +127,7 @@
     return touchBitSetLevel(sendBit, afterLevel);
   }
 
+  /// @brief
   /// Receive one bit of communication and set a new level on the 1-Wire bus.
   /// @param[out] recvBit Received data from the 1-Wire bus.
   /// @param afterLevel Level to set the 1-Wire bus to after communication.
@@ -132,27 +137,39 @@
   }
 
   // Alternate forms of the read and write functions.
+  
+  error_code touchBit(bool & sendRecvBit) {
+    return touchBitSetLevel(sendRecvBit, NormalLevel);
+  }
+  
   error_code writeBit(bool sendBit) {
     return writeBitSetLevel(sendBit, NormalLevel);
   }
+  
   error_code readBit(bool & recvBit) {
     return readBitSetLevel(recvBit, NormalLevel);
   }
+  
   error_code writeBitPower(bool sendBit) {
     return writeBitSetLevel(sendBit, StrongLevel);
   }
+  
   error_code readBitPower(bool & recvBit) {
     return readBitSetLevel(recvBit, StrongLevel);
   }
+  
   error_code writeByte(uint_least8_t sendByte) {
     return writeByteSetLevel(sendByte, NormalLevel);
   }
+  
   error_code readByte(uint_least8_t & recvByte) {
     return readByteSetLevel(recvByte, NormalLevel);
   }
+  
   error_code writeBytePower(uint_least8_t sendByte) {
     return writeByteSetLevel(sendByte, StrongLevel);
   }
+  
   error_code readBytePower(uint_least8_t & recvByte) {
     return readByteSetLevel(recvByte, StrongLevel);
   }
@@ -163,6 +180,7 @@
 inline error_code make_error_code(OneWireMaster::ErrorValue e) {
   return error_code(e, OneWireMaster::errorCategory());
 }
+
 inline error_condition make_error_condition(OneWireMaster::ErrorValue e) {
   return error_condition(e, OneWireMaster::errorCategory());
 }