How to access the child nodes in a device tree (DTS) in Zephyr using DT_FOREACH_CHILD #dts #nrf52


unsunk.ship@...
 

The results from previous code were OK, I think it's a bug in the debugger. I posted the details here [^].
BR.


unsunk.ship@...
 

Hi,
I originally posted this question to stackoverflow [^] so I think its better not to duplicate the whole story here.
Supposing I have a DTS file with a content like this one below:

n: detectors {
    compatible = "foo-detectors";
        
    // Definition of first channel
    det0: det_0 {
        irq-pins = <13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
        label = "Bar detector channel 1";
    };
    // Definition of second channel
    det1: det_1 {
        irq-pins = <17 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
        label = "Bar detector channel 2";
    };
};
And a structure like here below:
struct foo_detector_desc { 
    int irqpin; 
    int irqpin_flags;
}
How can I use macro DT_FOREACH_CHILD for populating an array with one item for each child of node detectors?

I tried this code below but, yet it compiled, the results where not what I wanted.

#define PIN_INFO_AND_COMMA(node_id) \
    { \
        .pin=DT_PROP_BY_IDX(node_id, irq_pins, 0),\
        .flags=DT_PROP_BY_IDX(node_id, irq_pins, 1),\
    },

const struct detector_data _det_data[] = {
    DT_FOREACH_CHILD(DT_NODELABEL(n), PIN_INFO_AND_COMMA)
};

BR.