#ifndef __BITBAND_H #define __BITBAND_H #include // 计算位带地址的宏,addr表示实际地址, // bitnum表示实际地址位的编号 // 0x2000 0101 - 5 ---> 0x2202 0214 #define BITBAND(addr, bitnum) \ ((addr&0xF0000000) + 0x2000000 + \ ((addr & 0xFFFFF) << 5) + (bitnum << 2)) #define MEM_ADDR(addr) *(volatile unsigned int *)(addr) // 根据实际地址和位编号,返回位带的地址的指针并解引用。 #define BIT_BAND(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum)) #define GPIOA_IDR_ADDR (GPIOA_BASE + 0x08) #define GPIOA_ODR_ADDR (GPIOA_BASE + 0x0C) #define GPIOB_IDR_ADDR (GPIOB_BASE + 0x08) #define GPIOB_ODR_ADDR (GPIOB_BASE + 0x0C) #define GPIOC_IDR_ADDR (GPIOC_BASE + 0x08) #define GPIOC_ODR_ADDR (GPIOC_BASE + 0x0C) #define GPIOD_IDR_ADDR (GPIOD_BASE + 0x08) #define GPIOD_ODR_ADDR (GPIOD_BASE + 0x0C) #define GPIOE_IDR_ADDR (GPIOE_BASE + 0x08) #define GPIOE_ODR_ADDR (GPIOE_BASE + 0x0C) #define PAOut(n) BIT_BAND(GPIOA_ODR_ADDR, n) #define PAIn(n) BIT_BAND(GPIOA_IDR_ADDR, n) #define PBOut(n) BIT_BAND(GPIOB_ODR_ADDR, n) #define PBIn(n) BIT_BAND(GPIOB_IDR_ADDR, n) #define PCOut(n) BIT_BAND(GPIOC_ODR_ADDR, n) #define PCIn(n) BIT_BAND(GPIOC_IDR_ADDR, n) #define PDOut(n) BIT_BAND(GPIOD_ODR_ADDR, n) #define PDIn(n) BIT_BAND(GPIOD_IDR_ADDR, n) #define PEOut(n) BIT_BAND(GPIOE_ODR_ADDR, n) #define PEIn(n) BIT_BAND(GPIOE_IDR_ADDR, n) #endif // __BITBAND_H