Skip to content

Commit 798c846

Browse files
GuEe-GUIRbb666
authored andcommitted
[DM/I2C] Update I2C for DM
1. Add get id match data API. 2. Set I2C device name default before adding to bus. 3. Add Kconfig import for DM. Signed-off-by: GuEe-GUI <2991707448@qq.com>
1 parent e5db582 commit 798c846

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

components/drivers/i2c/Kconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
config RT_USING_I2C
1+
menuconfig RT_USING_I2C
22
bool "Using I2C device drivers"
33
default n
44

@@ -241,3 +241,7 @@ if RT_USING_I2C
241241
endif
242242
endif
243243
endif
244+
245+
if RT_USING_DM && RT_USING_I2C
246+
osource "$(SOC_DM_I2C_DIR)/Kconfig"
247+
endif

components/drivers/i2c/dev_i2c_bus.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ void i2c_bus_scan_clients(struct rt_i2c_bus_device *bus)
6161
client->bus = bus;
6262
client->client_addr = client_addr;
6363

64+
rt_dm_dev_set_name(&client->parent, "%s", client->name);
65+
6466
rt_i2c_device_register(client);
6567

6668
if (i2c_client_np != child_np)

components/drivers/include/drivers/dev_i2c.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,21 @@ rt_err_t rt_i2c_driver_register(struct rt_i2c_driver *driver);
286286
rt_err_t rt_i2c_device_register(struct rt_i2c_client *client);
287287

288288
#define RT_I2C_DRIVER_EXPORT(driver) RT_DRIVER_EXPORT(driver, i2c, BUILIN)
289+
290+
/**
291+
* @brief Get ID match data from I2C client
292+
*
293+
* This function retrieves the driver-specific data associated with the matched
294+
* device ID or OFW node ID for the I2C client.
295+
*
296+
* @param client the I2C client device
297+
*
298+
* @return const void* pointer to the ID match data, or RT_NULL if no match data exists
299+
*/
300+
rt_inline const void *rt_i2c_client_id_data(struct rt_i2c_client *client)
301+
{
302+
return client->id ? client->id->data : (client->ofw_id ? client->ofw_id->data : RT_NULL);
303+
}
289304
#endif /* RT_USING_DM */
290305

291306
/**

0 commit comments

Comments
 (0)