@@ -672,6 +672,32 @@ static inline void i2c_xfer_stats(const struct device *dev, struct i2c_msg *msgs
672672 &(Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)).devstate), \
673673 __VA_ARGS__)
674674
675+ /**
676+ * @brief Like DEVICE_INSTANCE() with I2C specifics.
677+ *
678+ * @details Defines a device which implements the I2C API. May
679+ * generate a custom device_state container struct and init_fn
680+ * wrapper when needed depending on I2C @kconfig{CONFIG_I2C_STATS}.
681+ *
682+ * @param node_id The devicetree node identifier.
683+ * @param init_fn Name of the init function of the driver. Can be `NULL`.
684+ * @param pm PM device resources reference (NULL if device does not use PM).
685+ * @param data Pointer to the device's private data.
686+ * @param config The address to the structure containing the
687+ * configuration information for this instance of the driver.
688+ * @param level The initialization level. See SYS_INIT() for
689+ * details.
690+ * @param api Provides an initial pointer to the API function struct
691+ * used by the driver. Can be NULL.
692+ */
693+ #define I2C_DEVICE_INSTANCE (node_id , init_fn , pm , data , config , level , api ) \
694+ Z_I2C_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
695+ Z_I2C_INIT_FN(Z_DEVICE_DT_DEV_ID(node_id), init_fn) \
696+ DEVICE_INSTANCE_EXTERNAL_STATE(node_id, init_fn, pm, data, \
697+ config, level, api, \
698+ &(Z_DEVICE_STATE_NAME( \
699+ Z_DEVICE_DT_DEV_ID(node_id)).devstate))
700+
675701#else /* CONFIG_I2C_STATS */
676702
677703static inline void i2c_xfer_stats (const struct device * dev , struct i2c_msg * msgs ,
@@ -687,6 +713,9 @@ static inline void i2c_xfer_stats(const struct device *dev, struct i2c_msg *msgs
687713 DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, \
688714 prio, api, __VA_ARGS__)
689715
716+ #define I2C_DEVICE_INSTANCE (node_id , init_fn , pm , data , config , level , api ) \
717+ DEVICE_INSTANCE(node_id, init_fn, pm, data, config, level, api)
718+
690719#endif /* CONFIG_I2C_STATS */
691720
692721/**
@@ -700,6 +729,16 @@ static inline void i2c_xfer_stats(const struct device *dev, struct i2c_msg *msgs
700729#define I2C_DEVICE_DT_INST_DEFINE (inst , ...) \
701730 I2C_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
702731
732+ /**
733+ * @brief Like I2C_DEVICE_INSTANCE() for an instance of a DT_DRV_COMPAT compatible
734+ *
735+ * @param inst instance number. This is replaced by
736+ * <tt>DT_DRV_COMPAT(inst)</tt> in the call to I2C_DEVICE_INSTANCE().
737+ * @param ... other parameters as expected by I2C_DEVICE_INSTANCE().
738+ */
739+ #define I2C_DEVICE_INSTANCE_FROM_DT_INST (inst , ...) \
740+ I2C_DEVICE_INSTANCE(DT_DRV_INST(inst), __VA_ARGS__)
741+
703742
704743/**
705744 * @brief Configure operation of a host controller.
0 commit comments