From 03fc72b0fcea3bb946534051acb4b7de968da542 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 14 Jul 2019 20:49:16 +0200 Subject: [PATCH] Debugging LED --- lib/util-debug.c | 28 ++++++++++++++++++++++++++++ lib/util.h | 5 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/util-debug.c b/lib/util-debug.c index 59ee644..b61ace5 100644 --- a/lib/util-debug.c +++ b/lib/util-debug.c @@ -6,6 +6,7 @@ #include "util.h" +#include #include #include @@ -21,6 +22,13 @@ // Use this USART for debugging messages // #define DEBUG_USART USART1 +// Use this LED for debugging +#ifdef DEBUG_LED_BLUEPILL +#define DEBUG_LED_GPIO GPIOC +#define DEBUG_LED_PIN GPIO13 +#define DEBUG_LED_INVERSE +#endif + /*** Implementation ***/ #ifdef DEBUG_SEMIHOSTING @@ -182,3 +190,23 @@ void debug_printf(const char *fmt, ...) va_end(args); } + +void debug_led(bool light) +{ +#ifdef DEBUG_LED_GPIO +#ifdef DEBUG_LED_INVERSE + light = !light; +#endif + if (light) + gpio_set(DEBUG_LED_GPIO, DEBUG_LED_PIN); + else + gpio_clear(DEBUG_LED_GPIO, DEBUG_LED_PIN); +#endif +} + +void debug_led_toggle(void) +{ +#ifdef DEBUG_LED_GPIO + gpio_toggle(DEBUG_LED_GPIO, DEBUG_LED_PIN); +#endif +} diff --git a/lib/util.h b/lib/util.h index b06b6ad..8aa02f4 100644 --- a/lib/util.h +++ b/lib/util.h @@ -76,8 +76,11 @@ static inline void put_u32_le(byte *p, u32 x) p[0] = x & 0xff; } -// debug.c +// util-debug.c void debug_printf(const char *fmt, ...); void debug_puts(const char *s); void debug_putc(int c); + +void debug_led(bool light); +void debug_led_toggle(void); -- 2.39.2