Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
RT-Thread
rt-thread
提交
e459084f
R
rt-thread
项目概览
RT-Thread
/
rt-thread
大约 1 年 前同步成功
通知
776
Star
8911
Fork
4735
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e459084f
编写于
11月 26, 2019
作者:
B
Bernard Xiong
提交者:
GitHub
11月 26, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3220 from a1012112796/writing/zzc/i2c_debug_msg
[Device/I2C] Chang debug message print way to ulog
上级
86e61ddf
ab981a32
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
89 addition
and
51 deletion
+89
-51
bsp/gd32303e-eval/drivers/drv_i2c.c
bsp/gd32303e-eval/drivers/drv_i2c.c
+11
-3
bsp/gd32e230k-start/drivers/drv_i2c.c
bsp/gd32e230k-start/drivers/drv_i2c.c
+11
-3
components/drivers/Kconfig
components/drivers/Kconfig
+10
-0
components/drivers/i2c/i2c-bit-ops.c
components/drivers/i2c/i2c-bit-ops.c
+33
-31
components/drivers/i2c/i2c_core.c
components/drivers/i2c/i2c_core.c
+14
-6
components/drivers/i2c/i2c_dev.c
components/drivers/i2c/i2c_dev.c
+10
-2
components/drivers/include/drivers/i2c.h
components/drivers/include/drivers/i2c.h
+0
-6
未找到文件。
bsp/gd32303e-eval/drivers/drv_i2c.c
浏览文件 @
e459084f
...
...
@@ -31,6 +31,14 @@
#include <rtdevice.h>
#define DBG_TAG "drv.I2C"
#ifdef RT_I2C_DEBUG
#define DBG_LVL DBG_LOG
#else
#define DBG_LVL DBG_INFO
#endif
#include <rtdbg.h>
#ifdef RT_USING_I2C_BITOPS
/*user can change this*/
...
...
@@ -256,7 +264,7 @@ static rt_size_t gd32_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
{
if
(
gd32_i2c_read
(
gd32_i2c
->
i2c_periph
,
msg
->
addr
,
msg
->
buf
,
msg
->
len
)
!=
0
)
{
i2c_dbg
(
"i2c bus write failed,i2c bus stop!
\n
"
);
LOG_E
(
"i2c bus write failed,i2c bus stop!
"
);
goto
out
;
}
}
...
...
@@ -264,7 +272,7 @@ static rt_size_t gd32_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
{
if
(
gd32_i2c_write
(
gd32_i2c
->
i2c_periph
,
msg
->
addr
,
msg
->
buf
,
msg
->
len
)
!=
0
)
{
i2c_dbg
(
"i2c bus write failed,i2c bus stop!
\n
"
);
LOG_E
(
"i2c bus write failed,i2c bus stop!
"
);
goto
out
;
}
}
...
...
@@ -273,7 +281,7 @@ static rt_size_t gd32_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
ret
=
i
;
out:
i2c_dbg
(
"send stop condition
\n
"
);
LOG_E
(
"send stop condition
\n
"
);
return
ret
;
}
...
...
bsp/gd32e230k-start/drivers/drv_i2c.c
浏览文件 @
e459084f
...
...
@@ -18,6 +18,14 @@
#include <rtdevice.h>
#define DBG_TAG "drv.I2C"
#ifdef RT_I2C_DEBUG
#define DBG_LVL DBG_LOG
#else
#define DBG_LVL DBG_INFO
#endif
#include <rtdbg.h>
#ifdef RT_USING_I2C_BITOPS
/*user can change this*/
...
...
@@ -243,7 +251,7 @@ static rt_size_t gd32_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
{
if
(
gd32_i2c_read
(
gd32_i2c
->
i2c_periph
,
msg
->
addr
,
msg
->
buf
,
msg
->
len
)
!=
0
)
{
i2c_dbg
(
"i2c bus write failed,i2c bus stop!
\n
"
);
LOG_E
(
"i2c bus write failed,i2c bus stop!
"
);
goto
out
;
}
}
...
...
@@ -251,7 +259,7 @@ static rt_size_t gd32_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
{
if
(
gd32_i2c_write
(
gd32_i2c
->
i2c_periph
,
msg
->
addr
,
msg
->
buf
,
msg
->
len
)
!=
0
)
{
i2c_dbg
(
"i2c bus write failed,i2c bus stop!
\n
"
);
LOG_E
(
"i2c bus write failed,i2c bus stop!
"
);
goto
out
;
}
}
...
...
@@ -260,7 +268,7 @@ static rt_size_t gd32_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
ret
=
i
;
out:
i2c_dbg
(
"send stop condition
\
n
"
);
LOG_D
(
"send stop conditio
n"
);
return
ret
;
}
...
...
components/drivers/Kconfig
浏览文件 @
e459084f
...
...
@@ -88,11 +88,21 @@ config RT_USING_I2C
default n
if RT_USING_I2C
config RT_I2C_DEBUG
bool "Use I2C debug mesage"
default n
config RT_USING_I2C_BITOPS
bool "Use GPIO to simulate I2C"
default y
endif
if RT_USING_I2C_BITOPS
config RT_I2C_BITOPS_DEBUG
bool "Use simulate I2C debug mesage"
default n
endif
config RT_USING_PIN
bool "Using generic GPIO device drivers"
default y
...
...
components/drivers/i2c/i2c-bit-ops.c
浏览文件 @
e459084f
...
...
@@ -10,11 +10,13 @@
#include <rtdevice.h>
#ifdef RT_I2C_BIT_DEBUG
#define bit_dbg(fmt, ...) rt_kprintf(fmt, ##__VA_ARGS__)
#define DBG_TAG "I2C"
#ifdef RT_I2C_BITOPS_DEBUG
#define DBG_LVL DBG_LOG
#else
#define
bit_dbg(fmt, ...)
#define
DBG_LVL DBG_INFO
#endif
#include <rtdbg.h>
#define SET_SDA(ops, val) ops->set_sda(ops->data, val)
#define SET_SCL(ops, val) ops->set_scl(ops->data, val)
...
...
@@ -54,11 +56,11 @@ static rt_err_t SCL_H(struct rt_i2c_bit_ops *ops)
return
-
RT_ETIMEOUT
;
rt_thread_delay
((
ops
->
timeout
+
1
)
>>
1
);
}
#ifdef RT_I2C_BIT_DEBUG
#ifdef RT_I2C_BIT
OPS
_DEBUG
if
(
rt_tick_get
()
!=
start
)
{
bit_dbg
(
"wait %ld tick for SCL line to go high
\n
"
,
rt_tick_get
()
-
start
);
LOG_D
(
"wait %ld tick for SCL line to go high
"
,
rt_tick_get
()
-
start
);
}
#endif
...
...
@@ -70,14 +72,14 @@ done:
static
void
i2c_start
(
struct
rt_i2c_bit_ops
*
ops
)
{
#ifdef RT_I2C_BIT_DEBUG
#ifdef RT_I2C_BIT
OPS
_DEBUG
if
(
ops
->
get_scl
&&
!
GET_SCL
(
ops
))
{
bit_dbg
(
"I2C bus error, SCL line low
\n
"
);
LOG_E
(
"I2C bus error, SCL line low
"
);
}
if
(
ops
->
get_sda
&&
!
GET_SDA
(
ops
))
{
bit_dbg
(
"I2C bus error, SDA line low
\n
"
);
LOG_E
(
"I2C bus error, SDA line low
"
);
}
#endif
SDA_L
(
ops
);
...
...
@@ -114,13 +116,13 @@ rt_inline rt_bool_t i2c_waitack(struct rt_i2c_bit_ops *ops)
if
(
SCL_H
(
ops
)
<
0
)
{
bit_dbg
(
"wait ack timeout
\n
"
);
LOG_W
(
"wait ack timeout
"
);
return
-
RT_ETIMEOUT
;
}
ack
=
!
GET_SDA
(
ops
);
/* ACK : SDA pin is pulled low */
bit_dbg
(
"%s
\n
"
,
ack
?
"ACK"
:
"NACK"
);
LOG_D
(
"%s
"
,
ack
?
"ACK"
:
"NACK"
);
SCL_L
(
ops
);
...
...
@@ -142,8 +144,8 @@ static rt_int32_t i2c_writeb(struct rt_i2c_bus_device *bus, rt_uint8_t data)
i2c_delay
(
ops
);
if
(
SCL_H
(
ops
)
<
0
)
{
bit_dbg
(
"i2c_writeb: 0x%02x, "
"wait scl pin high timeout at bit %d
\n
"
,
LOG_D
(
"i2c_writeb: 0x%02x, "
"wait scl pin high timeout at bit %d"
,
data
,
i
);
return
-
RT_ETIMEOUT
;
...
...
@@ -169,8 +171,8 @@ static rt_int32_t i2c_readb(struct rt_i2c_bus_device *bus)
if
(
SCL_H
(
ops
)
<
0
)
{
bit_dbg
(
"i2c_readb: wait scl pin high "
"timeout at bit %d
\n
"
,
7
-
i
);
LOG_D
(
"i2c_readb: wait scl pin high "
"timeout at bit %d"
,
7
-
i
);
return
-
RT_ETIMEOUT
;
}
...
...
@@ -205,13 +207,13 @@ static rt_size_t i2c_send_bytes(struct rt_i2c_bus_device *bus,
}
else
if
(
ret
==
0
)
{
i2c_dbg
(
"send bytes: NACK.
\n
"
);
LOG_D
(
"send bytes: NACK.
"
);
return
0
;
}
else
{
i2c_dbg
(
"send bytes: error %d
\n
"
,
ret
);
LOG_E
(
"send bytes: error %d
"
,
ret
);
return
ret
;
}
...
...
@@ -229,7 +231,7 @@ static rt_err_t i2c_send_ack_or_nack(struct rt_i2c_bus_device *bus, int ack)
i2c_delay
(
ops
);
if
(
SCL_H
(
ops
)
<
0
)
{
bit_dbg
(
"ACK or NACK timeout
\n
"
);
LOG_E
(
"ACK or NACK timeout.
"
);
return
-
RT_ETIMEOUT
;
}
...
...
@@ -263,7 +265,7 @@ static rt_size_t i2c_recv_bytes(struct rt_i2c_bus_device *bus,
ptr
++
;
count
--
;
bit_dbg
(
"recieve bytes: 0x%02x, %s
\n
"
,
LOG_D
(
"recieve bytes: 0x%02x, %s
"
,
val
,
(
flags
&
RT_I2C_NO_READ_ACK
)
?
"(No ACK/NACK)"
:
(
count
?
"ACK"
:
"NACK"
));
...
...
@@ -291,10 +293,10 @@ static rt_int32_t i2c_send_address(struct rt_i2c_bus_device *bus,
ret
=
i2c_writeb
(
bus
,
addr
);
if
(
ret
==
1
||
i
==
retries
)
break
;
bit_dbg
(
"send stop condition
\
n
"
);
LOG_D
(
"send stop conditio
n"
);
i2c_stop
(
ops
);
i2c_delay2
(
ops
);
bit_dbg
(
"send start condition
\
n
"
);
LOG_D
(
"send start conditio
n"
);
i2c_start
(
ops
);
}
...
...
@@ -319,12 +321,12 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus,
addr1
=
0xf0
|
((
msg
->
addr
>>
7
)
&
0x06
);
addr2
=
msg
->
addr
&
0xff
;
bit_dbg
(
"addr1: %d, addr2: %d
\n
"
,
addr1
,
addr2
);
LOG_D
(
"addr1: %d, addr2: %d
"
,
addr1
,
addr2
);
ret
=
i2c_send_address
(
bus
,
addr1
,
retries
);
if
((
ret
!=
1
)
&&
!
ignore_nack
)
{
bit_dbg
(
"NACK: sending first addr
\n
"
);
LOG_W
(
"NACK: sending first addr
"
);
return
-
RT_EIO
;
}
...
...
@@ -332,19 +334,19 @@ static rt_err_t i2c_bit_send_address(struct rt_i2c_bus_device *bus,
ret
=
i2c_writeb
(
bus
,
addr2
);
if
((
ret
!=
1
)
&&
!
ignore_nack
)
{
bit_dbg
(
"NACK: sending second addr
\n
"
);
LOG_W
(
"NACK: sending second addr
"
);
return
-
RT_EIO
;
}
if
(
flags
&
RT_I2C_RD
)
{
bit_dbg
(
"send repeated start condition
\
n
"
);
LOG_D
(
"send repeated start conditio
n"
);
i2c_restart
(
ops
);
addr1
|=
0x01
;
ret
=
i2c_send_address
(
bus
,
addr1
,
retries
);
if
((
ret
!=
1
)
&&
!
ignore_nack
)
{
bit_dbg
(
"NACK: sending repeated addr
\n
"
);
LOG_E
(
"NACK: sending repeated addr
"
);
return
-
RT_EIO
;
}
...
...
@@ -373,7 +375,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
rt_int32_t
i
,
ret
;
rt_uint16_t
ignore_nack
;
bit_dbg
(
"send start condition
\
n
"
);
LOG_D
(
"send start conditio
n"
);
i2c_start
(
ops
);
for
(
i
=
0
;
i
<
num
;
i
++
)
{
...
...
@@ -388,7 +390,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
ret
=
i2c_bit_send_address
(
bus
,
msg
);
if
((
ret
!=
RT_EOK
)
&&
!
ignore_nack
)
{
bit_dbg
(
"receive NACK from device addr 0x%02x msg %d
\n
"
,
LOG_D
(
"receive NACK from device addr 0x%02x msg %d
"
,
msgs
[
i
].
addr
,
i
);
goto
out
;
}
...
...
@@ -397,7 +399,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
ret
=
i2c_recv_bytes
(
bus
,
msg
);
if
(
ret
>=
1
)
bit_dbg
(
"read %d byte%s
\n
"
,
ret
,
ret
==
1
?
""
:
"s"
);
LOG_D
(
"read %d byte%s
"
,
ret
,
ret
==
1
?
""
:
"s"
);
if
(
ret
<
msg
->
len
)
{
if
(
ret
>=
0
)
...
...
@@ -409,7 +411,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
{
ret
=
i2c_send_bytes
(
bus
,
msg
);
if
(
ret
>=
1
)
bit_dbg
(
"write %d byte%s
\n
"
,
ret
,
ret
==
1
?
""
:
"s"
);
LOG_D
(
"write %d byte%s
"
,
ret
,
ret
==
1
?
""
:
"s"
);
if
(
ret
<
msg
->
len
)
{
if
(
ret
>=
0
)
...
...
@@ -421,7 +423,7 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
ret
=
i
;
out:
bit_dbg
(
"send stop condition
\
n
"
);
LOG_D
(
"send stop conditio
n"
);
i2c_stop
(
ops
);
return
ret
;
...
...
components/drivers/i2c/i2c_core.c
浏览文件 @
e459084f
...
...
@@ -10,6 +10,14 @@
#include <rtdevice.h>
#define DBG_TAG "I2C"
#ifdef RT_I2C_DEBUG
#define DBG_LVL DBG_LOG
#else
#define DBG_LVL DBG_INFO
#endif
#include <rtdbg.h>
rt_err_t
rt_i2c_bus_device_register
(
struct
rt_i2c_bus_device
*
bus
,
const
char
*
bus_name
)
{
...
...
@@ -21,7 +29,7 @@ rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
res
=
rt_i2c_bus_device_device_init
(
bus
,
bus_name
);
i2c_dbg
(
"I2C bus [%s] registered
\n
"
,
bus_name
);
LOG_I
(
"I2C bus [%s] registered
"
,
bus_name
);
return
res
;
}
...
...
@@ -32,7 +40,7 @@ struct rt_i2c_bus_device *rt_i2c_bus_device_find(const char *bus_name)
rt_device_t
dev
=
rt_device_find
(
bus_name
);
if
(
dev
==
RT_NULL
||
dev
->
type
!=
RT_Device_Class_I2CBUS
)
{
i2c_dbg
(
"I2C bus %s not exist
\n
"
,
bus_name
);
LOG_E
(
"I2C bus %s not exist
"
,
bus_name
);
return
RT_NULL
;
}
...
...
@@ -53,9 +61,9 @@ rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
#ifdef RT_I2C_DEBUG
for
(
ret
=
0
;
ret
<
num
;
ret
++
)
{
i2c_dbg
(
"msgs[%d] %c, addr=0x%02x, len=%d
\n
"
,
ret
,
(
msgs
[
ret
].
flags
&
RT_I2C_RD
)
?
'R'
:
'W'
,
msgs
[
ret
].
addr
,
msgs
[
ret
].
len
);
LOG_D
(
"msgs[%d] %c, addr=0x%02x, len=%d
"
,
ret
,
(
msgs
[
ret
].
flags
&
RT_I2C_RD
)
?
'R'
:
'W'
,
msgs
[
ret
].
addr
,
msgs
[
ret
].
len
);
}
#endif
...
...
@@ -67,7 +75,7 @@ rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
}
else
{
i2c_dbg
(
"I2C bus operation not supported
\n
"
);
LOG_E
(
"I2C bus operation not supported
"
);
return
0
;
}
...
...
components/drivers/i2c/i2c_dev.c
浏览文件 @
e459084f
...
...
@@ -11,6 +11,14 @@
#include <rtdevice.h>
#define DBG_TAG "I2C"
#ifdef RT_I2C_DEBUG
#define DBG_LVL DBG_LOG
#else
#define DBG_LVL DBG_INFO
#endif
#include <rtdbg.h>
static
rt_size_t
i2c_bus_device_read
(
rt_device_t
dev
,
rt_off_t
pos
,
void
*
buffer
,
...
...
@@ -23,7 +31,7 @@ static rt_size_t i2c_bus_device_read(rt_device_t dev,
RT_ASSERT
(
bus
!=
RT_NULL
);
RT_ASSERT
(
buffer
!=
RT_NULL
);
i2c_dbg
(
"I2C bus dev [%s] reading %u bytes.
\n
"
,
dev
->
parent
.
name
,
count
);
LOG_D
(
"I2C bus dev [%s] reading %u bytes.
"
,
dev
->
parent
.
name
,
count
);
addr
=
pos
&
0xffff
;
flags
=
(
pos
>>
16
)
&
0xffff
;
...
...
@@ -43,7 +51,7 @@ static rt_size_t i2c_bus_device_write(rt_device_t dev,
RT_ASSERT
(
bus
!=
RT_NULL
);
RT_ASSERT
(
buffer
!=
RT_NULL
);
i2c_dbg
(
"I2C bus dev [%s] writing %u bytes.
\n
"
,
dev
->
parent
.
name
,
count
);
LOG_D
(
"I2C bus dev [%s] writing %u bytes.
"
,
dev
->
parent
.
name
,
count
);
addr
=
pos
&
0xffff
;
flags
=
(
pos
>>
16
)
&
0xffff
;
...
...
components/drivers/include/drivers/i2c.h
浏览文件 @
e459084f
...
...
@@ -67,12 +67,6 @@ struct rt_i2c_client
rt_uint16_t
client_addr
;
};
#ifdef RT_I2C_DEBUG
#define i2c_dbg(fmt, ...) rt_kprintf(fmt, ##__VA_ARGS__)
#else
#define i2c_dbg(fmt, ...)
#endif
rt_err_t
rt_i2c_bus_device_register
(
struct
rt_i2c_bus_device
*
bus
,
const
char
*
bus_name
);
struct
rt_i2c_bus_device
*
rt_i2c_bus_device_find
(
const
char
*
bus_name
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录