Skip to content

Commit f25f552

Browse files
gmarullcarlescufi
authored andcommitted
device: define Z_DEVICE_BASE_DEFINE
This adds a new helper to define the base struct device, without any other required objects. This helps de-cluttering Z_DEVICE_DEFINE. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 92c9db2 commit f25f552

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

include/zephyr/device.h

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,30 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
952952
/**
953953
* @brief Define a struct device
954954
*
955+
* @param node_id Devicetree node id for the device (DT_INVALID_NODE if a
956+
* software device).
957+
* @param dev_id Device identifier (used to name the defined struct device).
958+
* @param name Name of the device.
959+
* @param pm Reference to struct pm_device associated with the device.
960+
* (optional).
961+
* @param data Reference to device data.
962+
* @param config Reference to device config.
963+
* @param level Initialization level.
964+
* @param prio Initialization priority.
965+
* @param api Reference to device API.
966+
* @param ... Optional dependencies, manually specified.
967+
*/
968+
#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, \
969+
prio, api, state, handles) \
970+
COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
971+
const Z_DECL_ALIGN(struct device) DEVICE_NAME_GET(dev_id) \
972+
Z_DEVICE_SECTION(level, prio) __used = \
973+
Z_DEVICE_INIT(name, pm, data, config, api, state, \
974+
handles)
975+
976+
/**
977+
* @brief Define a struct device and all other required objects.
978+
*
955979
* This is the common macro used to define struct device objects. It can be
956980
* used to define both Devicetree and software devices.
957981
*
@@ -976,12 +1000,10 @@ BUILD_ASSERT(sizeof(device_handle_t) == 2, "fix the linker scripts");
9761000
\
9771001
Z_DEVICE_HANDLES_DEFINE(node_id, dev_id, __VA_ARGS__); \
9781002
\
979-
COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
980-
const Z_DECL_ALIGN(struct device) DEVICE_NAME_GET(dev_id) \
981-
Z_DEVICE_SECTION(level, prio) __used = \
982-
Z_DEVICE_INIT(name, pm, data, config, api, state, \
983-
Z_DEVICE_HANDLE_NAME(node_id, dev_id)); \
984-
\
1003+
Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, \
1004+
prio, api, state, \
1005+
Z_DEVICE_HANDLE_NAME(node_id, dev_id)); \
1006+
\
9851007
Z_INIT_ENTRY_DEFINE(DEVICE_NAME_GET(dev_id), init_fn, \
9861008
(&DEVICE_NAME_GET(dev_id)), level, prio)
9871009

0 commit comments

Comments
 (0)