1616
1717#ifdef RT_USING_I2C
1818
19+ #define DBG_TAG "drv.i2c"
20+ #define DBG_LVL DBG_INFO
21+ #include <rtdbg.h>
22+
1923enum
2024{
2125#ifdef BSP_USING_I2C0
2226 I2C0_INDEX ,
2327#endif
28+ #ifdef BSP_USING_I2C1
29+ I2C1_INDEX ,
30+ #endif
31+ #ifdef BSP_USING_I2C2
32+ I2C2_INDEX ,
33+ #endif
34+ #ifdef BSP_USING_I2C3
35+ I2C3_INDEX ,
36+ #endif
2437};
2538
2639
27- #define i2c_dbg rt_kprintf
28-
2940struct lpc_i2c_bus
3041{
3142 struct rt_i2c_bus_device parent ;
@@ -44,12 +55,58 @@ struct lpc_i2c_bus lpc_obj[] =
4455 {
4556 .I2C = LPI2C0 ,
4657 .baud = 100000U ,
58+ #if (defined(CPU_MCXA346VLH ) || defined(CPU_MCXA346VLL ) || defined(CPU_MCXA346VLQ ) || defined(CPU_MCXA346VPN ))
59+ .clock_attach_id = kFRO_LF_DIV_to_LPI2C0 ,
60+ #else
4761 .clock_attach_id = kFRO12M_to_LPI2C0 ,
62+ #endif
4863 .clock_div_name = kCLOCK_DivLPI2C0 ,
4964 .clock_src = kCLOCK_Fro12M ,
5065 .name = "i2c0" ,
5166 },
5267#endif
68+ #ifdef BSP_USING_I2C1
69+ {
70+ .I2C = LPI2C1 ,
71+ .baud = 100000U ,
72+ #if (defined(CPU_MCXA346VLH ) || defined(CPU_MCXA346VLL ) || defined(CPU_MCXA346VLQ ) || defined(CPU_MCXA346VPN ))
73+ .clock_attach_id = kFRO_LF_DIV_to_LPI2C1 ,
74+ #else
75+ .clock_attach_id = kFRO12M_to_LPI2C1 ,
76+ #endif
77+ .clock_div_name = kCLOCK_DivLPI2C1 ,
78+ .clock_src = kCLOCK_Fro12M ,
79+ .name = "i2c1" ,
80+ },
81+ #endif
82+ #ifdef BSP_USING_I2C2
83+ {
84+ .I2C = LPI2C2 ,
85+ .baud = 100000U ,
86+ #if (defined(CPU_MCXA346VLH ) || defined(CPU_MCXA346VLL ) || defined(CPU_MCXA346VLQ ) || defined(CPU_MCXA346VPN ))
87+ .clock_attach_id = kFRO_LF_DIV_to_LPI2C2 ,
88+ #else
89+ .clock_attach_id = kFRO12M_to_LPI2C2 ,
90+ #endif
91+ .clock_div_name = kCLOCK_DivLPI2C2 ,
92+ .clock_src = kCLOCK_Fro12M ,
93+ .name = "i2c2" ,
94+ },
95+ #endif
96+ #ifdef BSP_USING_I2C3
97+ {
98+ .I2C = LPI2C3 ,
99+ .baud = 100000U ,
100+ #if (defined(CPU_MCXA346VLH ) || defined(CPU_MCXA346VLL ) || defined(CPU_MCXA346VLQ ) || defined(CPU_MCXA346VPN ))
101+ .clock_attach_id = kFRO_LF_DIV_to_LPI2C3 ,
102+ #else
103+ .clock_attach_id = kFRO12M_to_LPI2C3 ,
104+ #endif
105+ .clock_div_name = kCLOCK_DivLPI2C3 ,
106+ .clock_src = kCLOCK_Fro12M ,
107+ .name = "i2c3" ,
108+ },
109+ #endif
53110};
54111
55112static rt_ssize_t lpc_i2c_xfer (struct rt_i2c_bus_device * bus , struct rt_i2c_msg msgs [], rt_uint32_t num )
@@ -80,7 +137,7 @@ static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
80137
81138 if (LPI2C_MasterTransferBlocking (lpc_i2c -> I2C , & xfer ) != kStatus_Success )
82139 {
83- i2c_dbg ("i2c bus read failed!\n" );
140+ LOG_D ("i2c bus read failed!\n" );
84141 return i ;
85142 }
86143 }
@@ -99,7 +156,7 @@ static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
99156
100157 if (LPI2C_MasterTransferBlocking (lpc_i2c -> I2C , & xfer ) != kStatus_Success )
101158 {
102- i2c_dbg ("i2c bus write failed!\n" );
159+ LOG_D ("i2c bus write failed!\n" );
103160 return i ;
104161 }
105162 }
0 commit comments