+/*
+ * General Utility Library for STM32
+ *
+ * (c) 2018--2019 Martin Mareš <mj@ucw.cz>
+ */
+
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "config.h"
+// Types
+
typedef unsigned int uint;
typedef uint8_t byte;
typedef uint16_t u16;
typedef uint32_t u32;
typedef int32_t s32;
+// Macros
+
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#define CLAMP(x,min,max) ({ typeof(x) _t=x; (_t < min) ? min : (_t > max) ? max : _t; })
+#define ARRAY_SIZE(ary) (sizeof(ary)/sizeof((ary)[0]))
#define UNUSED __attribute__((unused))
+// Unaligned access to data
+
static inline uint get_u16_le(byte *p)
{
return (p[1] << 8) | p[0];
p[0] = x & 0xff;
}
-// debug.c
+// CPU instructions not covered by libopencm3
-void debug_printf(const char *fmt, ...);
+static inline void wait_for_interrupt(void)
+{
+ asm volatile ("wfi");
+}
+
+// util-debug.c
+
+void debug_printf(const char *fmt, ...) __attribute__((format(printf,1,2)));
void debug_puts(const char *s);
void debug_putc(int c);
+
+void debug_led(bool light);
+void debug_led_toggle(void);