Skip to content

Commit 5be0d00

Browse files
mbolivar-nordicgalak
authored andcommitted
treewide: remove unnecessary DT GPIO/PWM flags checks
Now that the relevant APIs generalize properly for bindings without flags, we can remove some special case checks from the tree. I couldn't find any more, but I did this kind of quickly, so it's possible I missed some. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
1 parent c981323 commit 5be0d00

File tree

8 files changed

+19
-96
lines changed

8 files changed

+19
-96
lines changed

drivers/led_strip/apa102.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,6 @@
1212
#include <drivers/gpio.h>
1313
#include <sys/util.h>
1414

15-
/*
16-
* Devicetree helper macros which gets the 'flags' cell from a 'cs_gpios'
17-
* property on the spi bus, or returns 0 if the property has no 'flags' cell.
18-
*
19-
* Hopefully these helpers will be removed once #25827 is resolved.
20-
*/
21-
#define HAS_FLAGS(spi_dev, spi_reg) \
22-
DT_PHA_HAS_CELL_AT_IDX(spi_dev, cs_gpios, spi_reg, flags)
23-
24-
#define INST_SPI_DEV_CS_GPIOS_HAS_FLAGS(node) \
25-
HAS_FLAGS(DT_BUS(node), DT_REG_ADDR(node))
26-
27-
#define FLAGS_OR_ZERO(inst) \
28-
COND_CODE_1( \
29-
INST_SPI_DEV_CS_GPIOS_HAS_FLAGS(DT_DRV_INST(inst)), \
30-
(DT_INST_SPI_DEV_CS_GPIOS_FLAGS(inst)), \
31-
(0x0))
32-
3315
struct apa102_data {
3416
struct device *spi;
3517
struct spi_config cfg;
@@ -128,7 +110,8 @@ static int apa102_init(struct device *dev)
128110
data->cfg.cs = &data->cs_ctl;
129111

130112
gpio_pin_configure(data->cs_ctl.gpio_dev, data->cs_ctl.gpio_pin,
131-
GPIO_OUTPUT_INACTIVE | FLAGS_OR_ZERO(0));
113+
GPIO_OUTPUT_INACTIVE |
114+
DT_INST_SPI_DEV_CS_GPIOS_FLAGS(0));
132115
#endif /* DT_INST_SPI_DEV_HAS_CS_GPIOS(0) */
133116

134117
return 0;

samples/basic/blinky_pwm/src/main.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,10 @@
1616

1717
#define PWM_LED0_NODE DT_ALIAS(pwm_led0)
1818

19-
/*
20-
* Devicetree helper macro which gets the 'flags' cell from the node's
21-
* pwms property, or returns 0 if the property has no 'flags' cell.
22-
*/
23-
24-
#define FLAGS_OR_ZERO(node) \
25-
COND_CODE_1(DT_PHA_HAS_CELL(node, pwms, flags), \
26-
(DT_PWMS_FLAGS(node)), \
27-
(0))
28-
2919
#if DT_NODE_HAS_STATUS(PWM_LED0_NODE, okay)
3020
#define PWM_LABEL DT_PWMS_LABEL(PWM_LED0_NODE)
3121
#define PWM_CHANNEL DT_PWMS_CHANNEL(PWM_LED0_NODE)
32-
#define PWM_FLAGS FLAGS_OR_ZERO(PWM_LED0_NODE)
22+
#define PWM_FLAGS DT_PWMS_FLAGS(PWM_LED0_NODE)
3323
#else
3424
#error "Unsupported board: pwm-led0 devicetree alias is not defined"
3525
#define PWM_LABEL ""

samples/basic/button/src/main.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@
1414

1515
#define SLEEP_TIME_MS 1
1616

17-
/*
18-
* Devicetree helper macro which gets the 'flags' cell from a 'gpios'
19-
* property, or returns 0 if the property has no 'flags' cell.
20-
*/
21-
22-
#define FLAGS_OR_ZERO(node) \
23-
COND_CODE_1(DT_PHA_HAS_CELL(node, gpios, flags), \
24-
(DT_GPIO_FLAGS(node, gpios)), \
25-
(0))
26-
2717
/*
2818
* Get button configuration from the devicetree sw0 alias.
2919
*
@@ -36,7 +26,7 @@
3626
#if DT_NODE_HAS_STATUS(SW0_NODE, okay)
3727
#define SW0_GPIO_LABEL DT_GPIO_LABEL(SW0_NODE, gpios)
3828
#define SW0_GPIO_PIN DT_GPIO_PIN(SW0_NODE, gpios)
39-
#define SW0_GPIO_FLAGS (GPIO_INPUT | FLAGS_OR_ZERO(SW0_NODE))
29+
#define SW0_GPIO_FLAGS (GPIO_INPUT | DT_GPIO_FLAGS(SW0_NODE, gpios))
4030
#else
4131
#error "Unsupported board: sw0 devicetree alias is not defined"
4232
#define SW0_GPIO_LABEL ""
@@ -107,7 +97,7 @@ void main(void)
10797
#if DT_NODE_HAS_STATUS(LED0_NODE, okay) && DT_NODE_HAS_PROP(LED0_NODE, gpios)
10898
#define LED0_GPIO_LABEL DT_GPIO_LABEL(LED0_NODE, gpios)
10999
#define LED0_GPIO_PIN DT_GPIO_PIN(LED0_NODE, gpios)
110-
#define LED0_GPIO_FLAGS (GPIO_OUTPUT | FLAGS_OR_ZERO(LED0_NODE))
100+
#define LED0_GPIO_FLAGS (GPIO_OUTPUT | DT_GPIO_FLAGS(LED0_NODE, gpios))
111101
#endif
112102

113103
#ifdef LED0_GPIO_LABEL

samples/basic/fade_led/src/main.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,10 @@
1616

1717
#define PWM_LED0_NODE DT_ALIAS(pwm_led0)
1818

19-
/*
20-
* Devicetree helper macro which gets the 'flags' cell from the node's
21-
* pwms property, or returns 0 if the property has no 'flags' cell.
22-
*/
23-
24-
#define FLAGS_OR_ZERO(node) \
25-
COND_CODE_1(DT_PHA_HAS_CELL(node, pwms, flags), \
26-
(DT_PWMS_FLAGS(node)), \
27-
(0))
28-
2919
#if DT_NODE_HAS_STATUS(PWM_LED0_NODE, okay)
3020
#define PWM_LABEL DT_PWMS_LABEL(PWM_LED0_NODE)
3121
#define PWM_CHANNEL DT_PWMS_CHANNEL(PWM_LED0_NODE)
32-
#define PWM_FLAGS FLAGS_OR_ZERO(PWM_LED0_NODE)
22+
#define PWM_FLAGS DT_PWMS_FLAGS(PWM_LED0_NODE)
3323
#else
3424
#error "Unsupported board: pwm-led0 devicetree alias is not defined"
3525
#define PWM_LABEL ""

samples/basic/rgb_led/src/main.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
#include <device.h>
1414
#include <drivers/pwm.h>
1515

16-
/*
17-
* Devicetree helper macro which gets the 'flags' cell from a 'pwms'
18-
* property, or returns 0 if the property has no 'flags' cell.
19-
*/
20-
21-
#define FLAGS_OR_ZERO(node) \
22-
COND_CODE_1(DT_PHA_HAS_CELL(node, pwms, flags), \
23-
(DT_PWMS_FLAGS(node)), \
24-
(0))
25-
2616
/*
2717
* Extract devicetree configuration.
2818
*/
@@ -34,7 +24,7 @@
3424
#if DT_NODE_HAS_STATUS(RED_NODE, okay)
3525
#define RED_LABEL DT_PWMS_LABEL(RED_NODE)
3626
#define RED_CHANNEL DT_PWMS_CHANNEL(RED_NODE)
37-
#define RED_FLAGS FLAGS_OR_ZERO(RED_NODE)
27+
#define RED_FLAGS DT_PWMS_FLAGS(RED_NODE)
3828
#else
3929
#error "Unsupported board: red-pwm-led devicetree alias is not defined"
4030
#define RED_LABEL ""
@@ -45,7 +35,7 @@
4535
#if DT_NODE_HAS_STATUS(GREEN_NODE, okay)
4636
#define GREEN_LABEL DT_PWMS_LABEL(GREEN_NODE)
4737
#define GREEN_CHANNEL DT_PWMS_CHANNEL(GREEN_NODE)
48-
#define GREEN_FLAGS FLAGS_OR_ZERO(GREEN_NODE)
38+
#define GREEN_FLAGS DT_PWMS_FLAGS(GREEN_NODE)
4939
#else
5040
#error "Unsupported board: green-pwm-led devicetree alias is not defined"
5141
#define GREEN_LABEL ""
@@ -56,7 +46,7 @@
5646
#if DT_NODE_HAS_STATUS(BLUE_NODE, okay)
5747
#define BLUE_LABEL DT_PWMS_LABEL(BLUE_NODE)
5848
#define BLUE_CHANNEL DT_PWMS_CHANNEL(BLUE_NODE)
59-
#define BLUE_FLAGS FLAGS_OR_ZERO(BLUE_NODE)
49+
#define BLUE_FLAGS DT_PWMS_FLAGS(BLUE_NODE)
6050
#else
6151
#error "Unsupported board: blue-pwm-led devicetree alias is not defined"
6252
#define BLUE_LABEL ""

samples/basic/threads/src/main.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@
2020
#define LED0_NODE DT_ALIAS(led0)
2121
#define LED1_NODE DT_ALIAS(led1)
2222

23-
/*
24-
* Devicetree helper macro which gets the 'flags' cell from a 'gpios'
25-
* property, or returns 0 if the property has no 'flags' cell.
26-
*/
27-
28-
#define FLAGS_OR_ZERO(node) \
29-
COND_CODE_1(DT_PHA_HAS_CELL(node, gpios, flags), \
30-
(DT_GPIO_FLAGS(node, gpios)), \
31-
(0))
32-
3323
struct printk_data_t {
3424
void *fifo_reserved; /* 1st word reserved for use by fifo */
3525
uint32_t led;
@@ -90,7 +80,7 @@ void blink0(void)
9080
.gpio_dev_name = DT_GPIO_LABEL(LED0_NODE, gpios),
9181
.gpio_pin_name = DT_LABEL(LED0_NODE),
9282
.gpio_pin = DT_GPIO_PIN(LED0_NODE, gpios),
93-
.gpio_flags = GPIO_OUTPUT | FLAGS_OR_ZERO(LED0_NODE),
83+
.gpio_flags = GPIO_OUTPUT | DT_GPIO_FLAGS(LED0_NODE, gpios),
9484
#else
9585
#error "Unsupported board: led0 devicetree alias is not defined"
9686
#endif
@@ -106,7 +96,7 @@ void blink1(void)
10696
.gpio_dev_name = DT_GPIO_LABEL(LED1_NODE, gpios),
10797
.gpio_pin_name = DT_LABEL(LED1_NODE),
10898
.gpio_pin = DT_GPIO_PIN(LED1_NODE, gpios),
109-
.gpio_flags = GPIO_OUTPUT | FLAGS_OR_ZERO(LED1_NODE),
99+
.gpio_flags = GPIO_OUTPUT | DT_GPIO_FLAGS(LED1_NODE, gpios),
110100
#else
111101
#error "Unsupported board: led1 devicetree alias is not defined"
112102
#endif

samples/subsys/usb/hid-cdc/src/main.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,12 @@
1717
#define LOG_LEVEL LOG_LEVEL_DBG
1818
LOG_MODULE_REGISTER(main);
1919

20-
#define FLAGS_OR_ZERO(node) \
21-
COND_CODE_1(DT_PHA_HAS_CELL(node, gpios, flags), \
22-
(DT_GPIO_FLAGS(node, gpios)), \
23-
(0))
24-
2520
#define SW0_NODE DT_ALIAS(sw0)
2621

2722
#if DT_NODE_HAS_STATUS(SW0_NODE, okay)
2823
#define PORT0 DT_GPIO_LABEL(SW0_NODE, gpios)
2924
#define PIN0 DT_GPIO_PIN(SW0_NODE, gpios)
30-
#define PIN0_FLAGS FLAGS_OR_ZERO(SW0_NODE)
25+
#define PIN0_FLAGS DT_GPIO_FLAGS(SW0_NODE, gpios)
3126
#else
3227
#error "Unsupported board: sw0 devicetree alias is not defined"
3328
#define PORT0 ""
@@ -40,23 +35,23 @@ LOG_MODULE_REGISTER(main);
4035
#if DT_NODE_HAS_STATUS(SW1_NODE, okay)
4136
#define PORT1 DT_GPIO_LABEL(SW1_NODE, gpios)
4237
#define PIN1 DT_GPIO_PIN(SW1_NODE, gpios)
43-
#define PIN1_FLAGS FLAGS_OR_ZERO(SW1_NODE)
38+
#define PIN1_FLAGS DT_GPIO_FLAGS(SW1_NODE, gpios)
4439
#endif
4540

4641
#define SW2_NODE DT_ALIAS(sw2)
4742

4843
#if DT_NODE_HAS_STATUS(SW2_NODE, okay)
4944
#define PORT2 DT_GPIO_LABEL(SW2_NODE, gpios)
5045
#define PIN2 DT_GPIO_PIN(SW2_NODE, gpios)
51-
#define PIN2_FLAGS FLAGS_OR_ZERO(SW2_NODE)
46+
#define PIN2_FLAGS DT_GPIO_FLAGS(SW2_NODE, gpios)
5247
#endif
5348

5449
#define SW3_NODE DT_ALIAS(sw3)
5550

5651
#if DT_NODE_HAS_STATUS(SW3_NODE, okay)
5752
#define PORT3 DT_GPIO_LABEL(SW3_NODE, gpios)
5853
#define PIN3 DT_GPIO_PIN(SW3_NODE, gpios)
59-
#define PIN3_FLAGS FLAGS_OR_ZERO(SW3_NODE)
54+
#define PIN3_FLAGS DT_GPIO_FLAGS(SW3_NODE, gpios)
6055
#endif
6156

6257
/* Event FIFO */

samples/subsys/usb/hid-mouse/src/main.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@
1414
#define LOG_LEVEL LOG_LEVEL_DBG
1515
LOG_MODULE_REGISTER(main);
1616

17-
#define FLAGS_OR_ZERO(node) \
18-
COND_CODE_1(DT_PHA_HAS_CELL(node, gpios, flags), \
19-
(DT_GPIO_FLAGS(node, gpios)), \
20-
(0))
21-
2217
#define SW0_NODE DT_ALIAS(sw0)
2318

2419
#if DT_NODE_HAS_STATUS(SW0_NODE, okay)
2520
#define PORT0 DT_GPIO_LABEL(SW0_NODE, gpios)
2621
#define PIN0 DT_GPIO_PIN(SW0_NODE, gpios)
27-
#define PIN0_FLAGS FLAGS_OR_ZERO(SW0_NODE)
22+
#define PIN0_FLAGS DT_GPIO_FLAGS(SW0_NODE, gpios)
2823
#else
2924
#error "Unsupported board: sw0 devicetree alias is not defined"
3025
#define PORT0 ""
@@ -37,23 +32,23 @@ LOG_MODULE_REGISTER(main);
3732
#if DT_NODE_HAS_STATUS(SW1_NODE, okay)
3833
#define PORT1 DT_GPIO_LABEL(SW1_NODE, gpios)
3934
#define PIN1 DT_GPIO_PIN(SW1_NODE, gpios)
40-
#define PIN1_FLAGS FLAGS_OR_ZERO(SW1_NODE)
35+
#define PIN1_FLAGS DT_GPIO_FLAGS(SW1_NODE, gpios)
4136
#endif
4237

4338
#define SW2_NODE DT_ALIAS(sw2)
4439

4540
#if DT_NODE_HAS_STATUS(SW2_NODE, okay)
4641
#define PORT2 DT_GPIO_LABEL(SW2_NODE, gpios)
4742
#define PIN2 DT_GPIO_PIN(SW2_NODE, gpios)
48-
#define PIN2_FLAGS FLAGS_OR_ZERO(SW2_NODE)
43+
#define PIN2_FLAGS DT_GPIO_FLAGS(SW2_NODE, gpios)
4944
#endif
5045

5146
#define SW3_NODE DT_ALIAS(sw3)
5247

5348
#if DT_NODE_HAS_STATUS(SW3_NODE, okay)
5449
#define PORT3 DT_GPIO_LABEL(SW3_NODE, gpios)
5550
#define PIN3 DT_GPIO_PIN(SW3_NODE, gpios)
56-
#define PIN3_FLAGS FLAGS_OR_ZERO(SW3_NODE)
51+
#define PIN3_FLAGS DT_GPIO_FLAGS(SW3_NODE, gpios)
5752
#endif
5853

5954
#define LED0_NODE DT_ALIAS(led0)

0 commit comments

Comments
 (0)