PER Firmware
Loading...
Searching...
No Matches
log.h
1
12#ifndef __LOG_H__
13#define __LOG_H__
14
16#include "common/log/vsprintf.h"
17
18int snprintf(char* buffer, size_t size, const char* fmt, ...);
19int sprintf(char* buffer, const char* fmt, ...);
20int debug_printf(const char* fmt, ...);
21
22// cursed macro to workaround accessing different hals
23// call DEBUG_PRINTF_USART_DEFINE(&usart_config) ONCE in *main.c* after defining uart config struct
24#define DEBUG_PRINTF_USART_DEFINE(HANDLEPTR) \
25 static inline void _iodev_write(usart_init_t* handle, char* buffer, int size) { \
26 if (handle) { \
27 PHAL_usartTxBl(handle, (uint8_t*)buffer, size); \
28 } \
29 } \
30\
31 int debug_printf(const char* fmt, ...) { \
32 va_list args; \
33 char buffer[512]; \
34 int i; \
35\
36 va_start(args, fmt); \
37 i = vsnprintf(buffer, sizeof(buffer), fmt, args); \
38 va_end(args); \
39\
40 _iodev_write((HANDLEPTR), buffer, MIN(i, (int)(sizeof(buffer) - 1))); \
41\
42 return i; \
43 }
44// can add SPI etc as necessary
45
46// plog: requires \n
47#define plog(...) debug_printf(__VA_ARGS__)
48
49#define ANSI_RED "\x1b[31m"
50#define ANSI_GREEN "\x1b[32m"
51#define ANSI_YELLOW "\x1b[33m"
52#define ANSI_BLUE "\x1b[34m"
53#define ANSI_MAGENTA "\x1b[35m"
54#define ANSI_CYAN "\x1b[36m"
55#define ANSI_RESET "\x1b[37m"
56
57#define __mu_log_color(color, ...) \
58 do { \
59 debug_printf("%s", color); \
60 debug_printf(__VA_ARGS__); \
61 debug_printf("%s", ANSI_RESET); \
62 } while (0)
63
64#define log_msg(...) debug_printf(__VA_ARGS__)
65#define log_int(n) (debug_printf("%s == %d\n", (#n), (n)))
66#define log_str(s) (debug_printf("%s == %s\n", (#s), (s)))
67#define log_char(c) (debug_printf("%s == '%c'\n", (#c), (c)))
68#define log_addr(addr) (debug_printf("%s == %p\n", (#addr), (void*)(addr)))
69#define log_red(...) __mu_log_color(ANSI_RED, __VA_ARGS__)
70#define log_green(...) __mu_log_color(ANSI_GREEN, __VA_ARGS__)
71#define log_yellow(...) __mu_log_color(ANSI_YELLOW, __VA_ARGS__)
72#define log_blue(...) __mu_log_color(ANSI_BLUE, __VA_ARGS__)
73#define log_magenta(...) __mu_log_color(ANSI_MAGENTA, __VA_ARGS__)
74#define log_cyan(...) __mu_log_color(ANSI_CYAN, __VA_ARGS__)
75
76#endif // __LOG_H__
Common defs for the entire firmware repository. Dont let this get too out of control please.