aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.h
blob: 8b33e2cd39e14972d03b05eb5c39da6fcb3bab6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once

#include "ws2812.h"

#include <stdbool.h>
#include <stdint.h>
#include <stdarg.h>

#define ARRLEN(x) (sizeof(x) / sizeof((x)[0]))

#define ERR(...) stdio_log(LOG_ERR, "ERR  : " __VA_ARGS__)
#define WARN(...) stdio_log(LOG_WARN, "WARN : " __VA_ARGS__)
#define INFO(...) stdio_log(LOG_INFO, "INFO : " __VA_ARGS__)
#define DEBUG(...) stdio_log(LOG_DEBUG, "DEBUG: " __VA_ARGS__)

#define PANIC(...) blink_panic(200, WS2812_U32RGB(255, 0, 0), __VA_ARGS__);
#define ASSERT(cond) do { \
		if (!(cond)) PANIC("Assertion failed: (%s) in %s:%i", \
			#cond, __FILE__, __LINE__); \
	} while (0)

#define CLAIM_UNUSED_SM(pio) ({ \
	int tmp = pio_claim_unused_sm(pio, false); \
	ASSERT(tmp >= 0); \
	(uint) tmp; })

enum {
	LOG_NONE,
	LOG_ERR,
	LOG_WARN,
	LOG_INFO,
	LOG_DEBUG
};

void stdio_log(int loglevel, const char *fmtstr, ...);

void blink_panic(uint32_t blink_ms, uint32_t rgb, const char *fmtstr, ...);

extern int loglevel;