Questions regarding inconsistencies in retrieving device structures

I'm following the nordic academic courses, which are very nice by the way!

I've now followed three topics and I find three different variants which confuse me a lot:

1. const struct device *uart= DEVICE_DT_GET(DT_NODELABEL(uart0));

2. const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);

3. static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(DT_NODELABEL(mysensor));

The static part, that ofcourse I get but what I do not understand is why there are (already) three different variants of getting my device structure? 

sure, I do understand that the three lines are meant for different applications but to me they do kind of the same, right? 

Can somebody explain the reason for that and their differences in a bit more detail because it is confusing me.

Parents
  • Hi,

    I'm following the nordic academic courses, which are very nice by the way!

    We're glad to hear that! 

    The static part, that ofcourse I get but what I do not understand is why there are (already) three different variants of getting my device structure? 

    sure, I do understand that the three lines are meant for different applications but to me they do kind of the same, right? 

    Can somebody explain the reason for that and their differences in a bit more detail because it is confusing me.

    I see where the confusion comes from. Yes, they mean basically the same, and it is as you say different ways to get your device's structure which often has their own sets of equivalent options. Which you choose depends on how you've defined the device or what type of device it is.

    1: This is fetching the device using a nodelabel

    2: This is fetching the device using GPIO_DT_SPEC_GET( node_id, prop ), which is from the Zephyr API for gpios, using the device's alias.

    3: This is fetching a subdevice, in this case the sensor is a subsensor attached to the I2C bus. You can see a similar api for PWM here: https://docs.nordicsemi.com/bundle/zephyr-apis-latest/page/group_pwm_interface.html

    Devicetree has a more expanded (and very helpful) documentation which you can see here: https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/build/dts/index.html 

    Kind regards,
    Andreas

Reply
  • Hi,

    I'm following the nordic academic courses, which are very nice by the way!

    We're glad to hear that! 

    The static part, that ofcourse I get but what I do not understand is why there are (already) three different variants of getting my device structure? 

    sure, I do understand that the three lines are meant for different applications but to me they do kind of the same, right? 

    Can somebody explain the reason for that and their differences in a bit more detail because it is confusing me.

    I see where the confusion comes from. Yes, they mean basically the same, and it is as you say different ways to get your device's structure which often has their own sets of equivalent options. Which you choose depends on how you've defined the device or what type of device it is.

    1: This is fetching the device using a nodelabel

    2: This is fetching the device using GPIO_DT_SPEC_GET( node_id, prop ), which is from the Zephyr API for gpios, using the device's alias.

    3: This is fetching a subdevice, in this case the sensor is a subsensor attached to the I2C bus. You can see a similar api for PWM here: https://docs.nordicsemi.com/bundle/zephyr-apis-latest/page/group_pwm_interface.html

    Devicetree has a more expanded (and very helpful) documentation which you can see here: https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/build/dts/index.html 

    Kind regards,
    Andreas

Children
Related