Skip to content

Commit 3a66b38

Browse files
fabiobaltierikartben
authored andcommitted
drivers,test: use the new DT_FOREACH_PROP_ELEM_SEP
Use the new DT_FOREACH_PROP_ELEM_SEP macro instead of DEVICE_DT_GET(DT_PHANDLE_BY_IDX(...)). Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
1 parent e060e4c commit 3a66b38

File tree

11 files changed

+11
-33
lines changed

11 files changed

+11
-33
lines changed

doc/build/dts/zephyr-user-node.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,16 @@ device pointers like this:
7979
const struct device *my_device =
8080
DEVICE_DT_GET(DT_PROP(ZEPHYR_USER_NODE, handle));
8181
82-
#define PHANDLE_TO_DEVICE(node_id, prop, idx) \
83-
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)),
84-
8582
/*
8683
* Same thing as:
8784
*
8885
* ... *my_devices[] = {
8986
* DEVICE_DT_GET(DT_NODELABEL(gpio0)),
90-
* DEVICE_DT_GET(DT_NODELABEL(gpio1)),
87+
* DEVICE_DT_GET(DT_NODELABEL(gpio1))
9188
* };
9289
*/
9390
const struct device *my_devices[] = {
94-
DT_FOREACH_PROP_ELEM(ZEPHYR_USER_NODE, handles, PHANDLE_TO_DEVICE)
91+
DT_FOREACH_PROP_ELEM_SEP(ZEPHYR_USER_NODE, handles, DEVICE_DT_GET_BY_IDX, (,))
9592
};
9693
9794
GPIOs

drivers/ethernet/nxp_enet/eth_nxp_enet.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,6 @@ static const struct ethernet_api api_funcs = {
882882
irq_enable(DT_IRQ_BY_IDX(node_id, idx, irq)); \
883883
} while (false);
884884

885-
#define NXP_ENET_DT_PHY_DEV(node_id, phy_phandle, idx) \
886-
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, phy_phandle, idx))
887-
888885
#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_dtcm)) && \
889886
CONFIG_ETH_NXP_ENET_USE_DTCM_FOR_DMA_BUFFER
890887
#define _nxp_enet_dma_desc_section __dtcm_bss_section

drivers/gpio/gpio_nct38xx_alert.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,9 @@ static int nct38xx_alert_init(const struct device *dev)
157157
/* NCT38XX alert driver must be initialized after NCT38XX GPIO driver */
158158
BUILD_ASSERT(CONFIG_GPIO_NCT38XX_ALERT_INIT_PRIORITY > CONFIG_GPIO_NCT38XX_INIT_PRIORITY);
159159

160-
#define NCT38XX_DEV_AND_COMMA(node_id, prop, idx) \
161-
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)),
162-
163160
#define NCT38XX_ALERT_DEVICE_INSTANCE(inst) \
164161
const struct device *nct38xx_dev_##inst[] = { \
165-
DT_INST_FOREACH_PROP_ELEM(inst, nct38xx_dev, NCT38XX_DEV_AND_COMMA)}; \
162+
DT_INST_FOREACH_PROP_ELEM_SEP(inst, nct38xx_dev, DEVICE_DT_GET_BY_IDX, (,))}; \
166163
static struct nct38xx_mfd nct38xx_mfd_##inst[DT_INST_PROP_LEN(inst, nct38xx_dev)]; \
167164
static const struct nct38xx_alert_config nct38xx_alert_cfg_##inst = { \
168165
.irq_gpio = GPIO_DT_SPEC_INST_GET(inst, irq_gpios), \

drivers/i2c/i2c_emul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static DEVICE_API(i2c, i2c_emul_api) = {
312312

313313
#define EMUL_FORWARD_ITEM(node_id, prop, idx) \
314314
{ \
315-
.bus = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx)), \
315+
.bus = DEVICE_DT_GET_BY_IDX(node_id, prop, idx), \
316316
.addr = DT_PHA_BY_IDX(node_id, prop, idx, addr), \
317317
},
318318

drivers/misc/devmux/devmux.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,8 @@ static int devmux_init(struct device *const dev)
148148
return 0;
149149
}
150150

151-
#define DEVMUX_PHANDLE_TO_DEVICE(node_id, prop, idx) \
152-
DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx))
153-
154151
#define DEVMUX_PHANDLE_DEVICES(_n) \
155-
DT_INST_FOREACH_PROP_ELEM_SEP(_n, devices, DEVMUX_PHANDLE_TO_DEVICE, (,))
152+
DT_INST_FOREACH_PROP_ELEM_SEP(_n, devices, DEVICE_DT_GET_BY_IDX, (,))
156153

157154
#define DEVMUX_SELECTED(_n) DT_INST_PROP(_n, selected)
158155

drivers/usb_c/ppc/shell.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/** Macro used to iterate over USB-C connector and call a function if the node has PPC property */
1111
#define CALL_IF_HAS_PPC(usb_node, func) \
1212
COND_CODE_1(DT_NODE_HAS_PROP(usb_node, ppc), \
13-
(ret |= func(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(usb_node, ppc, 0)));), ())
13+
(ret |= func(DEVICE_DT_GET_BY_IDX(usb_node, ppc, 0));), ())
1414

1515
/**
1616
* @brief Command that dumps registers of one or all of the PPCs

tests/drivers/console_switching/src/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
#define BUF_SIZE 32
1414

1515
/* array of const struct device* */
16-
#define PHANDLE_TO_DEVICE(node_id, prop, idx) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx))
1716
static const struct device *devs[] = {
18-
DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(devmux0), devices, PHANDLE_TO_DEVICE, (,))};
17+
DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(devmux0), devices, DEVICE_DT_GET_BY_IDX, (,))};
1918

2019
/* array of names, e.g. "euart0" */
2120
#define PHANDLE_TO_NAME(node_id, prop, idx) DT_NODE_FULL_NAME(DT_PHANDLE_BY_IDX(node_id, prop, idx))

tests/drivers/i2c/i2c_emul/src/test_forwarding_buf.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
namespace
1414
{
1515

16-
#define GET_TARGET_DEVICE(node_id, prop, n) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, n)),
17-
1816
/* Get the devicetree constants */
1917
constexpr const struct device *controller = DEVICE_DT_GET(CONTROLLER_LABEL);
2018
constexpr const struct device *targets[FORWARD_COUNT] = {
21-
DT_FOREACH_PROP_ELEM(CONTROLLER_LABEL, forwards, GET_TARGET_DEVICE)};
19+
DT_FOREACH_PROP_ELEM_SEP(CONTROLLER_LABEL, forwards, DEVICE_DT_GET_BY_IDX, (,))};
2220

2321
ZTEST(i2c_emul_forwarding, test_write_is_forwarded)
2422
{

tests/drivers/i2c/i2c_emul/src/test_forwarding_pio.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
namespace
1313
{
1414

15-
#define GET_TARGET_DEVICE(node_id, prop, n) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, n)),
16-
1715
/* Get the devicetree constants */
1816
constexpr const struct device *controller = DEVICE_DT_GET(CONTROLLER_LABEL);
1917
constexpr const struct device *targets[FORWARD_COUNT] = {
20-
DT_FOREACH_PROP_ELEM(CONTROLLER_LABEL, forwards, GET_TARGET_DEVICE)};
18+
DT_FOREACH_PROP_ELEM_SEP(CONTROLLER_LABEL, forwards, DEVICE_DT_GET_BY_IDX, (,))};
2119

2220
ZTEST(i2c_emul_forwarding, test_write_is_forwarded)
2321
{

tests/drivers/i2c/i2c_emul/src/test_fowarding_common.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
namespace
1313
{
1414

15-
#define GET_TARGET_DEVICE(node_id, prop, n) DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, n)),
16-
1715
/* Get the devicetree constants */
1816
constexpr const struct device *controller = DEVICE_DT_GET(CONTROLLER_LABEL);
1917
constexpr const struct device *targets[FORWARD_COUNT] = {
20-
DT_FOREACH_PROP_ELEM(CONTROLLER_LABEL, forwards, GET_TARGET_DEVICE)};
18+
DT_FOREACH_PROP_ELEM_SEP(CONTROLLER_LABEL, forwards, DEVICE_DT_GET_BY_IDX, (,))};
2119

2220
static void *i2c_emul_forwarding_setup(void)
2321
{

0 commit comments

Comments
 (0)