From ee13ddeee0cb738da62b1f9e5b8a1963cf54bb67 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 21 Jun 2018 20:52:53 +0200 Subject: [PATCH] Add some utillty defines --- include/utils/utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/utils/utils.h b/include/utils/utils.h index e69e02e..26caaaf 100644 --- a/include/utils/utils.h +++ b/include/utils/utils.h @@ -7,6 +7,24 @@ extern "C" { #endif +#define LIMIT(x, min, max) \ + ({ \ + typeof( x ) _x = x; \ + typeof( min ) _min = min; \ + typeof( max ) _max = max; \ + ( ( ( _x ) < ( _min ) ) ? ( _min ) : ( ( _x ) > ( _max ) ) ? ( _max) : ( _x ) ); \ +}) + +#define DegToRad(a) ( (a) * 0.01745329252f ) +#define RadToDeg(a) ( (a) * 57.29577951f ) + +#define ALIGN4(x) (((x) + 3) & ~3) +#define ALIGN32(x) (((x) + 31) & ~31) + +#define le16(i) ((((uint16_t) ((i) & 0xFF)) << 8) | ((uint16_t) (((i) & 0xFF00) >> 8))) +#define le32(i) ((((uint32_t)le16((i) & 0xFFFF)) << 16) | ((uint32_t)le16(((i) & 0xFFFF0000) >> 16))) +#define le64(i) ((((uint64_t)le32((i) & 0xFFFFFFFFLL)) << 32) | ((uint64_t)le32(((i) & 0xFFFFFFFF00000000LL) >> 32))) + //Needs to have log_init() called beforehand. void dumpHex(const void* data, size_t size);