Skip to content

Commit 55d1d4f

Browse files
committed
sensor: Provide new device instantiation macros
In order to get rid of the manually inserted initialization priority, device object generation need new macros. Again removing the prio parameter. Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent b5d7b4e commit 55d1d4f

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

include/zephyr/drivers/sensor.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,18 +1404,54 @@ struct sensor_info {
14041404
\
14051405
SENSOR_INFO_DT_DEFINE(node_id);
14061406

1407+
/**
1408+
* @brief Like DEVICE_INSTANCE() with sensor specifics.
1409+
*
1410+
* @details Defines a device which implements the sensor API. May define an
1411+
* element in the sensor info iterable section used to enumerate all sensor
1412+
* devices.
1413+
*
1414+
* @param node_id The devicetree node identifier.
1415+
* @param init_fn Name of the init function of the driver.
1416+
* @param pm_device PM device resources reference (NULL if device does not use
1417+
* PM).
1418+
* @param data_ptr Pointer to the device's private data.
1419+
* @param cfg_ptr The address to the structure containing the configuration
1420+
* information for this instance of the driver.
1421+
* @param level The initialization level. See init.h for details.
1422+
* @param api_ptr Provides an initial pointer to the API function struct used
1423+
* by the driver. Can be NULL.
1424+
*/
1425+
#define SENSOR_DEVICE_INSTANCE(node_id, init_fn, pm_device, \
1426+
data_ptr, cfg_ptr, level, api_ptr) \
1427+
DEVICE_INSTANCE(node_id, init_fn, pm_device, \
1428+
data_ptr, cfg_ptr, level, api_ptr); \
1429+
\
1430+
SENSOR_INFO_DT_DEFINE(node_id);
1431+
14071432
/**
14081433
* @brief Like SENSOR_DEVICE_DT_DEFINE() for an instance of a DT_DRV_COMPAT
14091434
* compatible
14101435
*
14111436
* @param inst instance number. This is replaced by
14121437
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to SENSOR_DEVICE_DT_DEFINE().
1413-
*
14141438
* @param ... other parameters as expected by SENSOR_DEVICE_DT_DEFINE().
14151439
*/
14161440
#define SENSOR_DEVICE_DT_INST_DEFINE(inst, ...) \
14171441
SENSOR_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
14181442

1443+
/**
1444+
* @brief Like SENSOR_DEVICE_INSTANCE() for an instance of a DT_DRV_COMPAT
1445+
* compatible
1446+
*
1447+
* @param inst instance number. This is replaced by
1448+
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to SENSOR_DEVICE_INSTANCE().
1449+
*
1450+
* @param ... other parameters as expected by SENSOR_DEVICE_INSTANCE().
1451+
*/
1452+
#define SENSOR_DEVICE_INSTANCE_FROM_DT_INST(inst, ...) \
1453+
SENSOR_DEVICE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
1454+
14191455
/**
14201456
* @brief Helper function for converting struct sensor_value to integer milli units.
14211457
*

include/zephyr/sensing/sensing_sensor.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,36 @@ extern const struct rtio_iodev_api __sensing_iodev_api;
378378
cb_list_ptr); \
379379
SENSING_SENSORS_DEFINE(node, reg_ptr, cb_list_ptr);
380380

381+
/**
382+
* @brief Like SENSOR_DEVICE_INSTANCE() with sensing specifics.
383+
*
384+
* @details Defines a sensor which implements the sensor API. May define an
385+
* element in the sensing sensor iterable section used to enumerate all sensing
386+
* sensors.
387+
*
388+
* @param node The devicetree node identifier.
389+
* @param reg_ptr Pointer to the device's sensing_sensor_register_info.
390+
* @param cb_list_ptr Pointer to sensing callback list.
391+
* @param init_fn Name of the init function of the driver.
392+
* @param pm_device PM device resources reference (NULL if device does not use
393+
* PM).
394+
* @param data_ptr Pointer to the device's private data.
395+
* @param cfg_ptr The address to the structure containing the configuration
396+
* information for this instance of the driver.
397+
* @param level The initialization level. See init.h for details.
398+
* @param api_ptr Provides an initial pointer to the API function struct used
399+
* by the driver. Can be NULL.
400+
*/
401+
#define SENSING_SENSORS_INSTANCE(node, reg_ptr, cb_list_ptr, \
402+
init_fn, pm_device, \
403+
data_ptr, cfg_ptr, level, api_ptr) \
404+
SENSOR_DEVICE_INSTANCE(node, init_fn, pm_device, \
405+
data_ptr, cfg_ptr, level, api_ptr); \
406+
SENSING_CONNECTIONS_DEFINE(node, \
407+
DT_PROP_LEN_OR(node, reporters, 0), \
408+
cb_list_ptr); \
409+
SENSING_SENSORS_DEFINE(node, reg_ptr, cb_list_ptr);
410+
381411
/**
382412
* @brief Like SENSING_SENSORS_DT_DEFINE() for an instance of a DT_DRV_COMPAT
383413
* compatible
@@ -389,6 +419,16 @@ extern const struct rtio_iodev_api __sensing_iodev_api;
389419
#define SENSING_SENSORS_DT_INST_DEFINE(inst, ...) \
390420
SENSING_SENSORS_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
391421

422+
/**
423+
* @brief Like SENSING_SENSORS_INSTANCE() for an instance of a DT_DRV_COMPAT
424+
* compatible
425+
*
426+
* @param inst instance number. This is replaced by
427+
* <tt>DT_DRV_COMPAT(inst)</tt> in the call to SENSING_SENSORS_INSTANCE().
428+
* @param ... other parameters as expected by SENSING_SENSORS_INSTANCE().
429+
*/
430+
#define SENSING_SENSORS_INSTANCE_FROM_DT_INST(inst, ...) \
431+
SENSING_SENSORS_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
392432
/**
393433
* @brief Get reporter handles of a given sensor instance by sensor type.
394434
*

0 commit comments

Comments
 (0)