util.h (1320B)
1#pragma once 2 3#include "ws2812.h" 4#include "led.h" 5 6#include "pico/time.h" 7 8#include <stdbool.h> 9#include <stdint.h> 10#include <stdarg.h> 11#include <sys/types.h> 12 13#define ARRLEN(x) (sizeof(x) / sizeof((x)[0])) 14 15#define WARN(group, ...) stdio_log(group, LOG_WARN, "WARN : " __VA_ARGS__) 16#define INFO(group, ...) stdio_log(group, LOG_INFO, "INFO : " __VA_ARGS__) 17#define DEBUG(group, ...) stdio_log(group, LOG_DEBUG, "DEBUG: " __VA_ARGS__) 18 19#define PANIC(...) blink_panic(200, HARD_RED, __VA_ARGS__); 20#define ASSERT(cond) do { \ 21 if (!(cond)) PANIC("Assertion failed: (%s) in %s:%i", \ 22 #cond, __FILE__, __LINE__); \ 23 } while (0) 24 25enum { 26 LOG_DEBUG, 27 LOG_INFO, 28 LOG_WARN 29}; 30 31enum { 32 LOG_NONE = 0b000000, 33 LOG_MISC = 0b000001, 34 LOG_KEYMAT = 0b000010, 35 LOG_KEYMAP = 0b000100, 36 LOG_HID = 0b001000, 37 LOG_TIMING = 0b010000, 38 LOG_SPLIT = 0b100000, 39 LOG_ALL = 0b111111, 40}; 41 42void stdio_log(int group, int level, const char *fmtstr, ...); 43 44void blink_panic(uint32_t blink_ms, uint32_t rgb, const char *fmtstr, ...); 45 46static inline uint 47claim_unused_sm(PIO pio) 48{ 49 int tmp = pio_claim_unused_sm(pio, false); 50 ASSERT(tmp >= 0); 51 return (uint) tmp; 52} 53 54static inline uint64_t 55board_micros(void) 56{ 57 return to_us_since_boot(get_absolute_time()); 58} 59 60extern char warnlog[]; 61extern int log_level_min; 62extern int log_group_mask;