This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

how to use device_get_binding()

device_get_binding() this function has many parameters ,very Incomprehensible to use, in the nordic samples i use debug step by step to find what port what pin to be used ,but cannot find

Parents
  • Hi! 

    I'm not sure what you mean because device_get_binding() only has one parameter:

    const struct device *device_get_binding(const char *name).

    The parameter is the device name you want to get the binding for. 

    However, there are multiple macros that will return the device name, for instance DT_LABEL(node_id), DT_PROP(node_id prop). 

    There are also a lot of macros that return the node identifier. DT_NODELABEL(label) takes the node label as a parameter to return the node_id. DT_ALIAS(alias) uses the alias, DT_PATH(...) uses the node path, and DT_INST(inst, compact) returns the node identified for an instance of a compatible. 

    Is this what you were looking for?

    Best regards,

    Heidi

  • Hi,

    I hope you won't think this off-topic:

    Ideally when you get a binding it would be good to be able to pass this into procedures that use it (to avoid repeating this everywhere).

    However, this throws errors: 

    struct device *source = device_get_binding(DEVICE_LABEL);

    void get_device_data(struct device *source) {

      // use the device

    }

    get_device_data(*source);

    It seems that device_get_binding() insists on a const struct.  If not you get 

    error: invalid storage class for function

    But if you make that const struct device *source you get a different error

    error: incompatible type for argument 1

    So I'm wondering if there's any way to pass a binding into a procedure, preferably a global one?

Reply
  • Hi,

    I hope you won't think this off-topic:

    Ideally when you get a binding it would be good to be able to pass this into procedures that use it (to avoid repeating this everywhere).

    However, this throws errors: 

    struct device *source = device_get_binding(DEVICE_LABEL);

    void get_device_data(struct device *source) {

      // use the device

    }

    get_device_data(*source);

    It seems that device_get_binding() insists on a const struct.  If not you get 

    error: invalid storage class for function

    But if you make that const struct device *source you get a different error

    error: incompatible type for argument 1

    So I'm wondering if there's any way to pass a binding into a procedure, preferably a global one?

Children
Related