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; })
28 #define UNUSED __attribute__((unused))
30 // Unaligned access to data
32 static inline uint get_u16_le(byte *p)
34 return (p[1] << 8) | p[0];
37 static inline uint get_u16_be(byte *p)
39 return (p[0] << 8) | p[1];
42 static inline uint get_u32_le(byte *p)
44 return (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
47 static inline uint get_u32_be(byte *p)
49 return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
52 static inline void put_u16_le(byte *p, u16 x)
58 static inline void put_u16_be(byte *p, u16 x)
64 static inline void put_u32_be(byte *p, u32 x)
67 p[1] = (x >> 16) & 0xff;
68 p[2] = (x >> 8) & 0xff;
72 static inline void put_u32_le(byte *p, u32 x)
75 p[2] = (x >> 16) & 0xff;
76 p[1] = (x >> 8) & 0xff;
82 void debug_printf(const char *fmt, ...);
83 void debug_puts(const char *s);
84 void debug_putc(int c);
86 void debug_led(bool light);
87 void debug_led_toggle(void);