#ifndef COMMON_H
#define COMMON_H

#include "at32f403a_407.h"

#if defined ( __GNUC__ )
#ifdef __packed
#undef __packed
#endif
#define __packed		__attribute__(( packed ))
#endif

#ifdef DEBUG
/*
#ifdef PRINTF_STDLIB
#include <stdio.h>
#endif
#ifdef PRINTF_CUSTOM
#include "tinystdio.h"
#endif
#undef DBG
*/
#define DBG
#else
#undef DBG
#define DBG if (0)
#endif

// https://stackoverflow.com/questions/4415524/common-array-length-macro-for-c
#define array_len(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define _strc(x, y) x ## y
#define strc(x, y) _strc(x, y)
#define _str(x) #x
#define str(x) _str(x)
//#define MAX(x, y) (((x) > (y)) ? (x) : (y))
//#define MIN(x, y) (((x) < (y)) ? (x) : (y))

#define isInterrupt() ((SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0)

#endif /* COMMON_H */
