4 #include <avr/interrupt.h>
6 #define FORCE_INLINE __attribute__((always_inline)) inline
7 #define _UNUSED __attribute__((unused))
9 #ifndef CRITICAL_SECTION_START
10 #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
11 #define CRITICAL_SECTION_END SREG = _sreg;
14 #define _REGNAME(registerbase,number,suffix) registerbase##number##suffix
15 #define _REGNAME_SHORT(registerbase,suffix) registerbase##suffix
18 #define STRINGIFY_(M) #M
19 #define STRINGIFY(M) STRINGIFY_(M)
23 #define _BV(n) (1<<(n))
24 #define TEST(n,b) (!!((n)&_BV(b)))
25 #define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
28 #define SBI(A,B) (A |= (1 << (B)))
32 #define CBI(A,B) (A &= ~(1 << (B)))
35 #define TBI(N,B) (N ^= _BV(B))
39 #define _DO_1(W,C,A) (_##W##_1(A))
40 #define _DO_2(W,C,A,B) (_##W##_1(A) C _##W##_1(B))
41 #define _DO_3(W,C,A,V...) (_##W##_1(A) C _DO_2(W,C,V))
42 #define _DO_4(W,C,A,V...) (_##W##_1(A) C _DO_3(W,C,V))
43 #define _DO_5(W,C,A,V...) (_##W##_1(A) C _DO_4(W,C,V))
44 #define _DO_6(W,C,A,V...) (_##W##_1(A) C _DO_5(W,C,V))
45 #define _DO_7(W,C,A,V...) (_##W##_1(A) C _DO_6(W,C,V))
46 #define _DO_8(W,C,A,V...) (_##W##_1(A) C _DO_7(W,C,V))
47 #define _DO_9(W,C,A,V...) (_##W##_1(A) C _DO_8(W,C,V))
48 #define _DO_10(W,C,A,V...) (_##W##_1(A) C _DO_9(W,C,V))
49 #define _DO_11(W,C,A,V...) (_##W##_1(A) C _DO_10(W,C,V))
50 #define _DO_12(W,C,A,V...) (_##W##_1(A) C _DO_11(W,C,V))
51 #define __DO_N(W,C,N,V...) _DO_##N(W,C,V)
52 #define _DO_N(W,C,N,V...) __DO_N(W,C,N,V)
53 #define DO(W,C,V...) _DO_N(W,C,NUM_ARGS(V),V)
56 #define _CAT(a,V...) a##V
57 #define CAT(a,V...) _CAT(a,V)
61 #define _ISENA_0x1 ~,1
62 #define _ISENA_true ~,1
63 #define _ISENA(V...) IS_PROBE(V)
65 #define _ENA_1(O) _ISENA(CAT(_IS,CAT(ENA_, O)))
66 #define _DIS_1(O) NOT(_ENA_1(O))
67 #define ENABLED(V...) DO(ENA,&&,V)
68 #define DISABLED(V...) DO(DIS,&&,V)
70 #define TERN(O,A,B) _TERN(_ENA_1(O),B,A)
71 #define TERN0(O,A) _TERN(_ENA_1(O),0,A)
72 #define TERN1(O,A) _TERN(_ENA_1(O),1,A)
73 #define TERN_(O,A) _TERN(_ENA_1(O),,A)
74 #define _TERN(E,V...) __TERN(_CAT(T_,E),V)
75 #define __TERN(T,V...) ___TERN(_CAT(_NO,T),V)
76 #define ___TERN(P,V...) THIRD(P,V)
80 #define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
81 #define NUM_ARGS(V...) _NUM_ARGS(0,V,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
86 #define FIRST(a,...) a
87 #define SECOND(a,b,...) b
88 #define THIRD(a,b,c,...) c
90 #define IS_PROBE(V...) SECOND(V, 0)
91 #define NOT(x) IS_PROBE(_CAT(_NOT_, x))