diff --git a/src/main/build/build_config.c b/src/main/build/build_config.c index 3bc3aee58..f840e9f6a 100644 --- a/src/main/build/build_config.c +++ b/src/main/build/build_config.c @@ -24,3 +24,15 @@ #include "platform.h" #include "build_config.h" + +#ifdef STM32F1 +#warning STM32F1 based targets are unsupported as of Betaflight 3.3. +#endif + +#ifdef STM32F3 +#warning STM32F3 based targets are unsupported as of Betaflight 4.1. +#endif + +#ifdef USE_CLI_DEBUG_PRINT +#warning Do not use USE_CLI_DEBUG_PRINT for production builds. +#endif diff --git a/src/main/build/version.c b/src/main/build/version.c index 75c7fbf4b..99d5c45d8 100644 --- a/src/main/build/version.c +++ b/src/main/build/version.c @@ -26,11 +26,3 @@ const char * const targetName = __TARGET__; const char * const shortGitRevision = __REVISION__; const char * const buildDate = __DATE__; const char * const buildTime = __TIME__; - -#ifdef STM32F1 -#warning STM32F1 based targets are unsupported as of Betaflight 3.3. -#endif - -#ifdef STM32F3 -#warning STM32F3 based targets are unsupported as of Betaflight 4.1. -#endif diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index 27bbdba28..15bea2631 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -310,8 +310,12 @@ static void cliWriterFlush() } -static void cliPrint(const char *str) +void cliPrint(const char *str) { + if (!cliMode) { + return; + } + if (cliWriter) { while (*str) { bufWriterAppend(cliWriter, *str++); @@ -320,12 +324,12 @@ static void cliPrint(const char *str) } } -static void cliPrintLinefeed(void) +void cliPrintLinefeed(void) { cliPrint("\r\n"); } -static void cliPrintLine(const char *str) +void cliPrintLine(const char *str) { cliPrint(str); cliPrintLinefeed(); @@ -391,8 +395,12 @@ static bool cliDefaultPrintLinef(dumpFlags_t dumpMask, bool equalsDefault, const } } -static void cliPrintf(const char *format, ...) +void cliPrintf(const char *format, ...) { + if (!cliMode) { + return; + } + va_list va; va_start(va, format); cliPrintfva(format, va); @@ -400,8 +408,12 @@ static void cliPrintf(const char *format, ...) } -static void cliPrintLinef(const char *format, ...) +void cliPrintLinef(const char *format, ...) { + if (!cliMode) { + return; + } + va_list va; va_start(va, format); cliPrintfva(format, va); diff --git a/src/main/cli/cli.h b/src/main/cli/cli.h index e0281bbaf..2692bbd3c 100644 --- a/src/main/cli/cli.h +++ b/src/main/cli/cli.h @@ -29,3 +29,11 @@ bool hasCustomDefaults(void); struct serialPort_s; void cliEnter(struct serialPort_s *serialPort); bool resetConfigToCustomDefaults(void); + +#ifdef USE_CLI_DEBUG_PRINT +void cliPrint(const char *str); +void cliPrintLinefeed(void); +void cliPrintLine(const char *str); +void cliPrintf(const char *format, ...); +void cliPrintLinef(const char *format, ...); +#endif diff --git a/src/main/cli/cli_debug_print.h b/src/main/cli/cli_debug_print.h new file mode 100644 index 000000000..b167d62b1 --- /dev/null +++ b/src/main/cli/cli_debug_print.h @@ -0,0 +1,49 @@ +/* + * This file is part of Cleanflight and Betaflight. + * + * Cleanflight and Betaflight are free software. You can redistribute + * this software and/or modify this software under the terms of the + * GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * Cleanflight and Betaflight are distributed in the hope that they + * will be useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. + * + * If not, see . + */ + +// Provides: cliPrintDebug... functions for displaying debugging information in the CLI +// +// Usage: Make sure USE_CLI_DEBUG_PRINT is defined +// Include this header in your code +// Add cliDebugPrint... statements as needed in your code +// Use the CLI to see the output of the debugging statements +// +// Cautions: Be sure to include rate limiting logic to your debug printing +// if needed otherwise you can flood the output. +// +// Be sure to reverse the Usage steps above to remove the debugging +// elements before submitting final code. + +#include "platform.h" + +#ifdef USE_CLI_DEBUG_PRINT + +#include "cli/cli.h" + +// Commands to print debugging information to the CLI +#define cliDebugPrintLinefeed cliPrintLinefeed +#define cliDebugPrintLinef cliPrintLinef +#define cliDebugPrintLine cliPrintLine +#define cliDebugPrintf cliPrintf +#define cliDebugPrint cliPrint + +#else +#error "Do not #include cli_debug_print.h unless you intend to do debugging and also define USE_CLI_DEBUG_PRINT" +#endif