2 * General Utility Library for STM32
4 * (c) 2018--2019 Martin Mareš <mj@ucw.cz>
15 typedef unsigned int uint;
24 #define MIN(x,y) ((x) < (y) ? (x) : (y))
25 #define MAX(x,y) ((x) > (y) ? (x) : (y))
26 #define CLAMP(x,min,max) ({ typeof(x) _t=x; (_t < min) ? min : (_t > max) ? max : _t; })
27 #define ARRAY_SIZE(ary) (sizeof(ary)/sizeof((ary)[0]))
29 #define UNUSED __attribute__((unused))
31 // Unaligned access to data
33 static inline uint get_u16_le(byte *p)
35 return (p[1] << 8) | p[0];
38 static inline uint get_u16_be(byte *p)
40 return (p[0] << 8) | p[1];
43 static inline uint get_u32_le(byte *p)
45 return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
48 static inline uint get_u32_be(byte *p)
50 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
53 static inline void put_u16_le(byte *p, u16 x)
59 static inline void put_u16_be(byte *p, u16 x)
65 static inline void put_u32_be(byte *p, u32 x)
68 p[1] = (x >> 16) & 0xff;
69 p[2] = (x >> 8) & 0xff;
73 static inline void put_u32_le(byte *p, u32 x)
76 p[2] = (x >> 16) & 0xff;
77 p[1] = (x >> 8) & 0xff;
81 // CPU instructions not covered by libopencm3
83 static inline void wait_for_interrupt(void)
90 void debug_printf(const char *fmt, ...) __attribute__((format(printf,1,2)));
91 void debug_puts(const char *s);
92 void debug_putc(int c);
94 void debug_led(bool light);
95 void debug_led_toggle(void);