From a84990961a62e4190cfac10b500ce9c693896e83 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 28 Mar 2020 01:19:43 -0500 Subject: [PATCH] Simplify TWIBus debug --- Marlin/src/feature/twibus.cpp | 56 +++++++++++------------------------ Marlin/src/feature/twibus.h | 7 +++-- 2 files changed, 22 insertions(+), 41 deletions(-) diff --git a/Marlin/src/feature/twibus.cpp b/Marlin/src/feature/twibus.cpp index 60d78018a2..9dbb1deb4f 100644 --- a/Marlin/src/feature/twibus.cpp +++ b/Marlin/src/feature/twibus.cpp @@ -49,37 +49,27 @@ void TWIBus::address(const uint8_t adr) { addr = adr; - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("address"), adr); - #endif + debug(PSTR("address"), adr); } void TWIBus::addbyte(const char c) { if (buffer_s >= COUNT(buffer)) return; buffer[buffer_s++] = c; - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("addbyte"), c); - #endif + debug(PSTR("addbyte"), c); } void TWIBus::addbytes(char src[], uint8_t bytes) { - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("addbytes"), bytes); - #endif + debug(PSTR("addbytes"), bytes); while (bytes--) addbyte(*src++); } void TWIBus::addstring(char str[]) { - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("addstring"), str); - #endif + debug(PSTR("addstring"), str); while (char c = *str++) addbyte(c); } void TWIBus::send() { - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("send"), addr); - #endif + debug(PSTR("send"), addr); Wire.beginTransmission(I2C_ADDRESS(addr)); Wire.write(buffer, buffer_s); @@ -89,21 +79,21 @@ void TWIBus::send() { } // static -void TWIBus::echoprefix(uint8_t bytes, const char prefix[], uint8_t adr) { +void TWIBus::echoprefix(uint8_t bytes, const char pref[], uint8_t adr) { SERIAL_ECHO_START(); - serialprintPGM(prefix); + serialprintPGM(pref); SERIAL_ECHOPAIR(": from:", adr, " bytes:", bytes, " data:"); } // static -void TWIBus::echodata(uint8_t bytes, const char prefix[], uint8_t adr) { - echoprefix(bytes, prefix, adr); +void TWIBus::echodata(uint8_t bytes, const char pref[], uint8_t adr) { + echoprefix(bytes, pref, adr); while (bytes-- && Wire.available()) SERIAL_CHAR(Wire.read()); SERIAL_EOL(); } -void TWIBus::echobuffer(const char prefix[], uint8_t adr) { - echoprefix(buffer_s, prefix, adr); +void TWIBus::echobuffer(const char pref[], uint8_t adr) { + echoprefix(buffer_s, pref, adr); LOOP_L_N(i, buffer_s) SERIAL_CHAR(buffer[i]); SERIAL_EOL(); } @@ -111,15 +101,11 @@ void TWIBus::echobuffer(const char prefix[], uint8_t adr) { bool TWIBus::request(const uint8_t bytes) { if (!addr) return false; - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("request"), bytes); - #endif + debug(PSTR("request"), bytes); // requestFrom() is a blocking function if (Wire.requestFrom(addr, bytes) == 0) { - #if ENABLED(DEBUG_TWIBUS) - debug("request fail", addr); - #endif + debug("request fail", addr); return false; } @@ -127,9 +113,7 @@ bool TWIBus::request(const uint8_t bytes) { } void TWIBus::relay(const uint8_t bytes) { - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("relay"), bytes); - #endif + debug(PSTR("relay"), bytes); if (request(bytes)) echodata(bytes, PSTR("i2c-reply"), addr); @@ -141,9 +125,7 @@ uint8_t TWIBus::capture(char *dst, const uint8_t bytes) { while (count < bytes && Wire.available()) dst[count++] = Wire.read(); - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("capture"), count); - #endif + debug(PSTR("capture"), count); return count; } @@ -156,16 +138,12 @@ void TWIBus::flush() { #if I2C_SLAVE_ADDRESS > 0 void TWIBus::receive(uint8_t bytes) { - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("receive"), bytes); - #endif + debug(PSTR("receive"), bytes); echodata(bytes, PSTR("i2c-receive"), 0); } void TWIBus::reply(char str[]/*=nullptr*/) { - #if ENABLED(DEBUG_TWIBUS) - debug(PSTR("reply"), str); - #endif + debug(PSTR("reply"), str); if (str) { reset(); diff --git a/Marlin/src/feature/twibus.h b/Marlin/src/feature/twibus.h index faf9eb38cf..2c1b20da51 100644 --- a/Marlin/src/feature/twibus.h +++ b/Marlin/src/feature/twibus.h @@ -223,7 +223,6 @@ class TWIBus { #endif #if ENABLED(DEBUG_TWIBUS) - /** * @brief Prints a debug message * @details Prints a simple debug message "TWIBus::function: value" @@ -233,6 +232,10 @@ class TWIBus { static void debug(const char func[], char c); static void debug(const char func[], char adr[]); static inline void debug(const char func[], uint8_t v) { debug(func, (uint32_t)v); } - + #else + static inline void debug(const char[], uint32_t) {} + static inline void debug(const char[], char) {} + static inline void debug(const char[], char[]) {} + static inline void debug(const char[], uint8_t) {} #endif };