Device interface library for multiple platforms including Mbed.

Dependents:   DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#

Maxim Interface is a library framework focused on providing flexible and expressive hardware interfaces. Both communication interfaces such as I2C and 1-Wire and device interfaces such as DS18B20 are supported. Modern C++ concepts are used extensively while keeping compatibility with C++98/C++03 and requiring no external dependencies. The embedded-friendly design does not depend on exceptions or RTTI.

The full version of the project is hosted on GitLab: https://gitlab.com/iabenz/MaximInterface

Revision:
8:5ea891c7d1a1
Parent:
7:9cd16581b578
diff -r 9cd16581b578 -r 5ea891c7d1a1 MaximInterfaceCore/LoggingI2CMaster.cpp
--- a/MaximInterfaceCore/LoggingI2CMaster.cpp	Mon Jul 22 11:44:07 2019 -0500
+++ b/MaximInterfaceCore/LoggingI2CMaster.cpp	Mon Sep 16 11:13:37 2019 -0500
@@ -1,5 +1,5 @@
 /*******************************************************************************
-* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
+* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
@@ -31,7 +31,7 @@
 *******************************************************************************/
 
 #include <utility>
-#include "HexConversions.hpp"
+#include "HexString.hpp"
 #include "LoggingI2CMaster.hpp"
 
 using std::string;
@@ -47,7 +47,7 @@
     if (read) {
       dataBuilder.append(1, '[');
     }
-    dataBuilder.append(byteArrayToHexString(data.subspan(i, 1)));
+    dataBuilder.append(toHexString(data.subspan(i, 1)));
     if (read) {
       dataBuilder.append(1, ']');
     }
@@ -63,72 +63,73 @@
   messageBuilder.clear();
 }
 
-error_code LoggingI2CMaster::start(uint_least8_t address) {
+Result<void> LoggingI2CMaster::start(uint_least8_t address) {
   messageBuilder.append(startString);
   messageBuilder.append(formatDataString(make_span(&address, 1), false));
   return I2CMasterDecorator::start(address);
 }
 
-error_code LoggingI2CMaster::stop() {
+Result<void> LoggingI2CMaster::stop() {
   messageBuilder.append(stopString);
   tryWriteMessage();
   return I2CMasterDecorator::stop();
 }
 
-error_code LoggingI2CMaster::writeByte(uint_least8_t data) {
+Result<void> LoggingI2CMaster::writeByte(uint_least8_t data) {
   messageBuilder.append(formatDataString(make_span(&data, 1), false));
   return I2CMasterDecorator::writeByte(data);
 }
 
-error_code LoggingI2CMaster::writeBlock(span<const uint_least8_t> data) {
+Result<void> LoggingI2CMaster::writeBlock(span<const uint_least8_t> data) {
   messageBuilder.append(formatDataString(data, false));
   return I2CMasterDecorator::writeBlock(data);
 }
 
-error_code LoggingI2CMaster::doWritePacket(uint_least8_t address,
+Result<void> LoggingI2CMaster::writePacket(uint_least8_t address,
                                            span<const uint_least8_t> data,
-                                           bool sendStop) {
+                                           DoStop doStop) {
   messageBuilder.append(startString);
   messageBuilder.append(formatDataString(make_span(&address, 1), false));
-  error_code result =
-      I2CMasterDecorator::doWritePacket(address, data, sendStop);
-  if (!result) {
+  const Result<void> result =
+      I2CMasterDecorator::writePacket(address, data, doStop);
+  if (result) {
     messageBuilder.append(formatDataString(data, false));
   }
-  if (sendStop || result) {
+  if (doStop == Stop || (doStop == StopOnError && !result)) {
     messageBuilder.append(stopString);
     tryWriteMessage();
   }
   return result;
 }
 
-error_code LoggingI2CMaster::readByte(AckStatus status, uint_least8_t & data) {
-  error_code result = I2CMasterDecorator::readByte(status, data);
-  if (!result) {
-    messageBuilder.append(formatDataString(make_span(&data, 1), true));
+Result<uint_least8_t> LoggingI2CMaster::readByte(DoAck doAck) {
+  const Result<uint_least8_t> data = I2CMasterDecorator::readByte(doAck);
+  if (data) {
+    messageBuilder.append(formatDataString(make_span(&data.value(), 1), true));
   }
-  return result;
+  return data;
 }
 
-error_code LoggingI2CMaster::readBlock(AckStatus status,
-                                       span<uint_least8_t> data) {
-  error_code result = I2CMasterDecorator::readBlock(status, data);
-  if (!result) {
+Result<void> LoggingI2CMaster::readBlock(span<uint_least8_t> data,
+                                         DoAck doAck) {
+  const Result<void> result = I2CMasterDecorator::readBlock(data, doAck);
+  if (result) {
     messageBuilder.append(formatDataString(data, true));
   }
   return result;
 }
 
-error_code LoggingI2CMaster::doReadPacket(uint_least8_t address,
+Result<void> LoggingI2CMaster::readPacket(uint_least8_t address,
                                           span<uint_least8_t> data,
-                                          bool sendStop) {
+                                          DoStop doStop) {
   messageBuilder.append(startString);
   messageBuilder.append(formatDataString(make_span(&address, 1), false));
-  error_code result = I2CMasterDecorator::doReadPacket(address, data, sendStop);
-  if (!result) {
+  const Result<void> result =
+      I2CMasterDecorator::readPacket(address, data, doStop);
+  if (result) {
     messageBuilder.append(formatDataString(data, true));
   }
-  if (sendStop || result) {
+  if (doStop == Stop || (doStop == StopOnError && !result)) {
     messageBuilder.append(stopString);
     tryWriteMessage();
   }