Add ifdef to bit definitions to avoid conflicts with other libraries. Refactor BITx to use BIT macro. (#45)

This commit is contained in:
Steve Karg
2020-02-18 08:21:54 -06:00
committed by GitHub
parent cf963a63ca
commit 9c41180145
19 changed files with 89 additions and 104 deletions
+21 -36
View File
@@ -27,54 +27,39 @@
/********************************************************************
* Bit Masks
*********************************************************************/
#define BIT(x) (1<<(x))
#define BIT0 (0x01)
#define BIT1 (0x02)
#define BIT2 (0x04)
#define BIT3 (0x08)
#define BIT4 (0x10)
#define BIT5 (0x20)
#define BIT6 (0x40)
#define BIT7 (0x80)
#define BIT8 (0x0100)
#define BIT9 (0x0200)
#define BIT10 (0x0400)
#define BIT11 (0x0800)
#define BIT12 (0x1000)
#define BIT13 (0x2000)
#define BIT14 (0x4000)
#define BIT15 (0x8000)
#define BIT16 (0x010000UL)
#define BIT17 (0x020000UL)
#define BIT18 (0x040000UL)
#define BIT19 (0x080000UL)
#define BIT20 (0x100000UL)
#define BIT21 (0x200000UL)
#define BIT22 (0x400000UL)
#define BIT23 (0x800000UL)
#define BIT24 (0x01000000UL)
#define BIT25 (0x02000000UL)
#define BIT26 (0x04000000UL)
#define BIT27 (0x08000000UL)
#define BIT28 (0x10000000UL)
#define BIT29 (0x20000000UL)
#define BIT30 (0x40000000UL)
#define BIT31 (0x80000000UL)
#ifndef BIT
#define BIT(x) (1<<(x))
#endif
#ifndef _BV
#define _BV(x) (1<<(x))
#endif
/* a=register, b=bit number to act upon 0-n */
#ifndef BIT_SET
#define BIT_SET(a,b) ((a) |= (1<<(b)))
#endif
#ifndef BIT_CLEAR
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))
#endif
#ifndef BIT_FLIP
#define BIT_FLIP(a,b) ((a) ^= (1<<(b)))
#endif
#ifndef BIT_CHECK
#define BIT_CHECK(a,b) ((a) & (1<<(b)))
#endif
/* x=target variable, y=mask */
#ifndef BITMASK_SET
#define BITMASK_SET(x,y) ((x) |= (y))
#endif
#ifndef BITMASK_CLEAR
#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))
#endif
#ifndef BITMASK_FLIP
#define BITMASK_FLIP(x,y) ((x) ^= (y))
#endif
#ifndef BITMASK_CHECK
#define BITMASK_CHECK(x,y) (((x) & (y)) == (y))
#ifndef _BV
#define _BV(x) (1<<(x))
#endif
#endif