summaryrefslogtreecommitdiff
path: root/tinyusb/common
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-01-14 14:36:13 +0700
committerhathach <[email protected]>2013-01-14 14:36:13 +0700
commit0c1d4f705baffcd173434cecc6eaaa2650d8ace7 (patch)
tree93bbf9f1d19088c48ccdfb166cc5e3d3519fbc7d /tinyusb/common
parent3d8babcb147022a6bced9b61455b301e3ea95150 (diff)
add binary const & its test code
Diffstat (limited to 'tinyusb/common')
-rw-r--r--tinyusb/common/binary.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/tinyusb/common/binary.h b/tinyusb/common/binary.h
index e46bd92e0..94648486e 100644
--- a/tinyusb/common/binary.h
+++ b/tinyusb/common/binary.h
@@ -66,11 +66,12 @@
/// clear n-th bit of x
#define BIT_CLR_(x, n) ( (x) & (~BIT_(n)) )
+
#if defined(__GNUC__)
-#define BIN8(x) (0b##x)
-#define BIN16 BIN8
-#define BIN32 BIN8
+#define BIN8(x) (0b##x)
+#define BIN16(b1, b2) (0b##b1##b2)
+#define BIN32(b1, b2, b3, b4) (0b##b1##b2##b3##b4)
#else
@@ -85,12 +86,12 @@
+((x&0xF0000000LU)?128:0)
#define BIN8(d) ((uint8_t)_B8__(0x##d##LU))
-#define BIN16(dmsb,dlsb) (((uint16_t)B8(dmsb)<<8) + B8(dlsb))
+#define BIN16(dmsb,dlsb) (((uint16_t)BIN8(dmsb)<<8) + BIN8(dlsb))
#define BIN32(dmsb,db2,db3,dlsb) \
- (((uint32_t)B8(dmsb)<<24) \
- + ((uint32_t)B8(db2)<<16) \
- + ((uint32_t)B8(db3)<<8) \
- + B8(dlsb))
+ (((uint32_t)BIN8(dmsb)<<24) \
+ + ((uint32_t)BIN8(db2)<<16) \
+ + ((uint32_t)BIN8(db3)<<8) \
+ + BIN8(dlsb))
#endif
#ifdef __cplusplus