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
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
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?
Thx Heidi,
There's a reference to this https://github.com/nrfconnect/sdk-zephyr/commit/e18fcbba5a4e63b54116f40ae5f0323d5237d329 which could explain it if I understood it.
Basically it's telling the compiler to allow dev to be global without declaring it globally?
I'll try that.