我不太确定 ulConfig |= ulMode;
是什么意思?如果
void gpio_setup_mode(unsigned long ulGpioNum, unsigned long ulMode, unsigned long ulInvert)
{
unsigned long ulConfig = ulInvert;
ulConfig |= ulMode;
s_ptGPIO->auiCFG[ulGpioNum] = ulConfig;
}
和
gpio_setup_mode(GPIO8, GPIO_MODE_OUTPUT, GPIO_NOINVERT);
其中 GPIO8、GPIO_MODE_OUTPUT、GPIO_NOINVERT
#define GPIO8 8
#define GPIO_NOINVERT 0x00000000
#define GPIO_MODE_OUTPUT 0x00000011
ulConfig |= ulMode;
相当于
ulConfig = ulConfig | ulMode;
|
运算符在两个运算符之间执行二元“或”运算。
来自 C11 标准(草案):
6.5.12 Bitwise inclusive OR operator
[...]
Contrains
2 Each of the operands shall have integer type.
Semantics
[...]
4 The result of the | operator is the bitwise inclusive OR of the operands (that is, each bit in the result is set if and only if at least one of the corresponding bits in the converted operands is set).
我是一名优秀的程序员,十分优秀!