device: add DEVICE_DT_GET_OR_NULL utility macro
Add a new utility macro to obtain an optional reference to a device. If the provided node_id is not enabled, the macro falls back to NULL. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
5ddbdcedd0
commit
4df1d15618
1 changed files with 13 additions and 0 deletions
|
@ -301,6 +301,19 @@ typedef int16_t device_handle_t;
|
|||
(DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
|
||||
(ZERO_OR_COMPILE_ERROR(0)))
|
||||
|
||||
/**
|
||||
* @def DEVICE_DT_GET_OR_NULL
|
||||
*
|
||||
* @brief Utility macro to obtain an optional reference to a device.
|
||||
*
|
||||
* @param node_id Node identifier.
|
||||
*
|
||||
* @return Pointer to a device if it exists, NULL otherwise.
|
||||
*/
|
||||
#define DEVICE_DT_GET_OR_NULL(node_id) \
|
||||
COND_CODE_1(DT_NODE_HAS_STATUS(node_id, okay), \
|
||||
(DEVICE_DT_GET(node_id)), (NULL))
|
||||
|
||||
/**
|
||||
* @def DEVICE_GET
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue