Skip to content

Commit c4c1d92

Browse files
gatzkakartben
authored andcommitted
drivers: gpio: Use BIT(n) macro to define GPIO constants
This change would also solve that according to the C11 standard, section 6.5, paragraph 4, the usage of bitwise operators on signed integers is implementation defined. Signed-off-by: Stephan Gatzka <[email protected]>
1 parent 068d7ec commit c4c1d92

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

drivers/gpio/gpio_emul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static void gpio_emul_gen_interrupt_bits(const struct device *port,
249249
case GPIO_INT_DISABLE:
250250
break;
251251
default:
252-
LOG_DBG("unhandled case %u",
252+
LOG_DBG("unhandled case %lu",
253253
drv_data->flags[i] & GPIO_EMUL_INT_BITMASK);
254254
break;
255255
}

include/zephyr/drivers/gpio.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ extern "C" {
4545
*/
4646

4747
/** Enables pin as input. */
48-
#define GPIO_INPUT (1U << 16)
48+
#define GPIO_INPUT BIT(16)
4949

5050
/** Enables pin as output, no change to the output state. */
51-
#define GPIO_OUTPUT (1U << 17)
51+
#define GPIO_OUTPUT BIT(17)
5252

5353
/** Disables pin for both input and output. */
5454
#define GPIO_DISCONNECTED 0
5555

5656
/** @cond INTERNAL_HIDDEN */
5757

5858
/* Initializes output to a low state. */
59-
#define GPIO_OUTPUT_INIT_LOW (1U << 18)
59+
#define GPIO_OUTPUT_INIT_LOW BIT(18)
6060

6161
/* Initializes output to a high state. */
62-
#define GPIO_OUTPUT_INIT_HIGH (1U << 19)
62+
#define GPIO_OUTPUT_INIT_HIGH BIT(19)
6363

6464
/* Initializes output based on logic level */
65-
#define GPIO_OUTPUT_INIT_LOGICAL (1U << 20)
65+
#define GPIO_OUTPUT_INIT_LOGICAL BIT(20)
6666

6767
/** @endcond */
6868

@@ -98,19 +98,19 @@ extern "C" {
9898
*/
9999

100100
/** Disables GPIO pin interrupt. */
101-
#define GPIO_INT_DISABLE (1U << 21)
101+
#define GPIO_INT_DISABLE BIT(21)
102102

103103
/** @cond INTERNAL_HIDDEN */
104104

105105
/* Enables GPIO pin interrupt. */
106-
#define GPIO_INT_ENABLE (1U << 22)
106+
#define GPIO_INT_ENABLE BIT(22)
107107

108108
/* GPIO interrupt is sensitive to logical levels.
109109
*
110110
* This is a component flag that should be combined with other
111111
* `GPIO_INT_*` flags to produce a meaningful configuration.
112112
*/
113-
#define GPIO_INT_LEVELS_LOGICAL (1U << 23)
113+
#define GPIO_INT_LEVELS_LOGICAL BIT(23)
114114

115115
/* GPIO interrupt is edge sensitive.
116116
*
@@ -119,23 +119,23 @@ extern "C" {
119119
* This is a component flag that should be combined with other
120120
* `GPIO_INT_*` flags to produce a meaningful configuration.
121121
*/
122-
#define GPIO_INT_EDGE (1U << 24)
122+
#define GPIO_INT_EDGE BIT(24)
123123

124124
/* Trigger detection when input state is (or transitions to) physical low or
125125
* logical 0 level.
126126
*
127127
* This is a component flag that should be combined with other
128128
* `GPIO_INT_*` flags to produce a meaningful configuration.
129129
*/
130-
#define GPIO_INT_LOW_0 (1U << 25)
130+
#define GPIO_INT_LOW_0 BIT(25)
131131

132132
/* Trigger detection on input state is (or transitions to) physical high or
133133
* logical 1 level.
134134
*
135135
* This is a component flag that should be combined with other
136136
* `GPIO_INT_*` flags to produce a meaningful configuration.
137137
*/
138-
#define GPIO_INT_HIGH_1 (1U << 26)
138+
#define GPIO_INT_HIGH_1 BIT(26)
139139

140140
#ifdef CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT
141141
/* Disable/Enable interrupt functionality without changing other interrupt
@@ -144,7 +144,7 @@ extern "C" {
144144
* This is a component flag that should be combined with `GPIO_INT_ENABLE` or
145145
* `GPIO_INT_DISABLE` flags to produce a meaningful configuration.
146146
*/
147-
#define GPIO_INT_ENABLE_DISABLE_ONLY (1u << 27)
147+
#define GPIO_INT_ENABLE_DISABLE_ONLY BIT(27)
148148
#endif /* CONFIG_GPIO_ENABLE_DISABLE_INTERRUPT */
149149

150150
#define GPIO_INT_MASK (GPIO_INT_DISABLE | \

samples/drivers/lcd_hd44780/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
#define GPIO_PIN_CFG(dev, pin, dir) \
149149
do { \
150150
if (gpio_pin_configure((dev), (pin), (dir))) { \
151-
printk("Err cfg " GPIO_NAME "%d! %x\n", (pin), (dir)); \
151+
printk("Err cfg " GPIO_NAME "%d! %lx\n", (pin), (dir)); \
152152
} \
153153
} while (0)
154154

0 commit comments

Comments
 (0)