COSA
An Object-Oriented Platform for Arduino Programming
Bits.h
Go to the documentation of this file.
1 
24 #ifndef COSA_BITS_H
25 #define COSA_BITS_H
26 
27 #define bit_mask(b) (1 << (b))
28 #define bit_mask_get(p,m) ((p) & (m))
29 #define bit_mask_set(p,m) ((p) |= (m))
30 #define bit_mask_clear(p,m) ((p) &= ~(m))
31 #define bit_mask_toggle(p,m) ((p) ^= (m))
32 #define bit_mask_write(c,p,m) (c ? bit_mask_set(p,m) : bit_mask_clear(p,m))
33 
34 #define bit_get(p,b) ((p) & bit_mask(b))
35 #define bit_set(p,b) ((p) |= bit_mask(b))
36 #define bit_clear(p,b) ((p) &= ~bit_mask(b))
37 #define bit_toggle(p,b) ((p) ^= bit_mask(b))
38 #define bit_write(c,p,b) (c ? bit_set(p,b) : bit_clear(p,b))
39 
40 #define bit_field_set(p,m,v) ((p) = ((p) & ~(m)) | ((v) & (m)))
41 #endif
42