Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
luozhenger
rt-thread
提交
93d572de
R
rt-thread
项目概览
luozhenger
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
未验证
提交
93d572de
编写于
2月 27, 2023
作者:
L
liYangYang
提交者:
GitHub
2月 26, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[spi][5.0.0] 修正SPI设备框架中,对函数返回值类型使用不恰当的情况 (#6937)
上级
f295d3df
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
75 deletion
+81
-75
bsp/stm32/libraries/HAL_Drivers/drv_qspi.c
bsp/stm32/libraries/HAL_Drivers/drv_qspi.c
+8
-6
bsp/stm32/libraries/HAL_Drivers/drv_spi.c
bsp/stm32/libraries/HAL_Drivers/drv_spi.c
+6
-2
components/drivers/include/drivers/spi.h
components/drivers/include/drivers/spi.h
+9
-8
components/drivers/spi/spi-bit-ops.c
components/drivers/spi/spi-bit-ops.c
+6
-6
components/drivers/spi/spi_core.c
components/drivers/spi/spi_core.c
+52
-53
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_qspi.c
浏览文件 @
93d572de
...
...
@@ -195,9 +195,9 @@ static void qspi_send_cmd(struct stm32_qspi_bus *qspi_bus, struct rt_qspi_messag
HAL_QSPI_Command
(
&
qspi_bus
->
QSPI_Handler
,
&
Cmdhandler
,
5000
);
}
static
rt_
uint32
_t
qspixfer
(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
)
static
rt_
ssize
_t
qspixfer
(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
)
{
rt_s
ize_t
len
=
0
;
rt_s
size_t
result
=
0
;
RT_ASSERT
(
device
!=
RT_NULL
);
RT_ASSERT
(
device
->
bus
!=
RT_NULL
);
...
...
@@ -224,18 +224,19 @@ static rt_uint32_t qspixfer(struct rt_spi_device *device, struct rt_spi_message
{
if
(
HAL_QSPI_Transmit
(
&
qspi_bus
->
QSPI_Handler
,
(
rt_uint8_t
*
)
sndb
,
5000
)
==
HAL_OK
)
{
len
=
length
;
result
=
length
;
}
else
{
LOG_E
(
"QSPI send data failed(%d)!"
,
qspi_bus
->
QSPI_Handler
.
ErrorCode
);
qspi_bus
->
QSPI_Handler
.
State
=
HAL_QSPI_STATE_READY
;
result
=
-
RT_ERROR
;
goto
__exit
;
}
}
else
{
len
=
1
;
result
=
1
;
}
}
else
if
(
rcvb
)
/* recv data */
...
...
@@ -247,7 +248,7 @@ static rt_uint32_t qspixfer(struct rt_spi_device *device, struct rt_spi_message
if
(
HAL_QSPI_Receive
(
&
qspi_bus
->
QSPI_Handler
,
rcvb
,
5000
)
==
HAL_OK
)
#endif
{
len
=
length
;
result
=
length
;
#ifdef BSP_QSPI_USING_DMA
while
(
qspi_bus
->
QSPI_Handler
.
RxXferCount
!=
0
);
#endif
...
...
@@ -256,6 +257,7 @@ static rt_uint32_t qspixfer(struct rt_spi_device *device, struct rt_spi_message
{
LOG_E
(
"QSPI recv data failed(%d)!"
,
qspi_bus
->
QSPI_Handler
.
ErrorCode
);
qspi_bus
->
QSPI_Handler
.
State
=
HAL_QSPI_STATE_READY
;
result
=
-
RT_ERROR
;
goto
__exit
;
}
}
...
...
@@ -267,7 +269,7 @@ __exit:
rt_pin_write
(
device
->
parent
.
cs_pin
,
PIN_HIGH
);
}
#endif
return
len
;
return
result
;
}
static
rt_err_t
qspi_configure
(
struct
rt_spi_device
*
device
,
struct
rt_spi_configuration
*
configuration
)
...
...
bsp/stm32/libraries/HAL_Drivers/drv_spi.c
浏览文件 @
93d572de
...
...
@@ -281,9 +281,9 @@ static rt_err_t stm32_spi_init(struct stm32_spi *spi_drv, struct rt_spi_configur
return
RT_EOK
;
}
static
rt_
uint32
_t
spixfer
(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
)
static
rt_
ssize
_t
spixfer
(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
)
{
HAL_StatusTypeDef
state
;
HAL_StatusTypeDef
state
=
HAL_OK
;
;
rt_size_t
message_length
,
already_send_length
;
rt_uint16_t
send_length
;
rt_uint8_t
*
recv_buf
;
...
...
@@ -438,6 +438,10 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
rt_pin_write
(
device
->
cs_pin
,
PIN_HIGH
);
}
if
(
state
!=
HAL_OK
)
{
return
-
RT_ERROR
;
}
return
message
->
length
;
}
...
...
components/drivers/include/drivers/spi.h
浏览文件 @
93d572de
/*
* Copyright (c) 2006-202
2
, RT-Thread Development Team
* Copyright (c) 2006-202
3
, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -100,7 +100,7 @@ struct rt_spi_bus
struct
rt_spi_ops
{
rt_err_t
(
*
configure
)(
struct
rt_spi_device
*
device
,
struct
rt_spi_configuration
*
configuration
);
rt_
uint32
_t
(
*
xfer
)(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
);
rt_
ssize
_t
(
*
xfer
)(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
);
};
/**
...
...
@@ -237,8 +237,9 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
const
void
*
send_buf2
,
rt_size_t
send_length2
);
rt_uint16_t
rt_spi_sendrecv16
(
struct
rt_spi_device
*
device
,
rt_uint16_t
data
);
rt_err_t
rt_spi_sendrecv16
(
struct
rt_spi_device
*
device
,
rt_uint16_t
senddata
,
rt_uint16_t
*
recvdata
);
/**
* This function transmits data to SPI device.
...
...
@@ -250,10 +251,10 @@ rt_uint16_t rt_spi_sendrecv16(struct rt_spi_device *device,
*
* @return the actual length of transmitted.
*/
rt_size_t
rt_spi_transfer
(
struct
rt_spi_device
*
device
,
const
void
*
send_buf
,
void
*
recv_buf
,
rt_size_t
length
);
rt_s
s
ize_t
rt_spi_transfer
(
struct
rt_spi_device
*
device
,
const
void
*
send_buf
,
void
*
recv_buf
,
rt_size_t
length
);
/**
* This function transfers a message list to the SPI device.
...
...
components/drivers/spi/spi-bit-ops.c
浏览文件 @
93d572de
/*
* Copyright (c) 2006-202
2
, RT-Thread Development Team
* Copyright (c) 2006-202
3
, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
...
...
@@ -48,7 +48,7 @@ rt_inline void spi_delay2(struct rt_spi_bit_ops *ops)
#define MISO_IN(ops) DIR_MISO(ops, 1)
#define MISO_OUT(ops) DIR_MISO(ops, 0)
rt_inline
rt_size_t
spi_xfer_4line_data8
(
struct
rt_spi_bit_ops
*
ops
,
rt_inline
rt_s
s
ize_t
spi_xfer_4line_data8
(
struct
rt_spi_bit_ops
*
ops
,
struct
rt_spi_configuration
*
config
,
const
void
*
send_buf
,
void
*
recv_buf
,
...
...
@@ -111,7 +111,7 @@ rt_inline rt_size_t spi_xfer_4line_data8(struct rt_spi_bit_ops *ops,
return
length
;
}
rt_inline
rt_size_t
spi_xfer_4line_data16
(
struct
rt_spi_bit_ops
*
ops
,
rt_inline
rt_s
s
ize_t
spi_xfer_4line_data16
(
struct
rt_spi_bit_ops
*
ops
,
struct
rt_spi_configuration
*
config
,
const
void
*
send_buf
,
void
*
recv_buf
,
...
...
@@ -174,7 +174,7 @@ rt_inline rt_size_t spi_xfer_4line_data16(struct rt_spi_bit_ops *ops,
return
length
;
}
rt_inline
rt_size_t
spi_xfer_3line_data8
(
struct
rt_spi_bit_ops
*
ops
,
rt_inline
rt_s
s
ize_t
spi_xfer_3line_data8
(
struct
rt_spi_bit_ops
*
ops
,
struct
rt_spi_configuration
*
config
,
const
void
*
send_buf
,
void
*
recv_buf
,
...
...
@@ -275,7 +275,7 @@ rt_inline rt_size_t spi_xfer_3line_data8(struct rt_spi_bit_ops *ops,
return
length
;
}
rt_inline
rt_size_t
spi_xfer_3line_data16
(
struct
rt_spi_bit_ops
*
ops
,
rt_inline
rt_s
s
ize_t
spi_xfer_3line_data16
(
struct
rt_spi_bit_ops
*
ops
,
struct
rt_spi_configuration
*
config
,
const
void
*
send_buf
,
void
*
recv_buf
,
...
...
@@ -412,7 +412,7 @@ rt_err_t spi_bit_configure(struct rt_spi_device *device, struct rt_spi_configura
return
RT_EOK
;
}
rt_
uint32
_t
spi_bit_xfer
(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
)
rt_
ssize
_t
spi_bit_xfer
(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
)
{
struct
rt_spi_bit_obj
*
obj
=
rt_container_of
(
device
->
bus
,
struct
rt_spi_bit_obj
,
bus
);
struct
rt_spi_bit_ops
*
ops
=
obj
->
ops
;
...
...
components/drivers/spi/spi_core.c
浏览文件 @
93d572de
...
...
@@ -15,6 +15,10 @@
#include <drivers/spi.h>
#define DBG_TAG "spi.core"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
extern
rt_err_t
rt_spi_bus_device_init
(
struct
rt_spi_bus
*
bus
,
const
char
*
name
);
extern
rt_err_t
rt_spidev_device_init
(
struct
rt_spi_device
*
dev
,
const
char
*
name
);
...
...
@@ -148,7 +152,7 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
else
{
/* configure SPI bus failed */
result
=
-
RT_EIO
;
LOG_E
(
"SPI device %s configuration failed"
,
device
->
parent
.
parent
.
name
)
;
goto
__exit
;
}
}
...
...
@@ -162,9 +166,9 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
message
.
next
=
RT_NULL
;
result
=
device
->
bus
->
ops
->
xfer
(
device
,
&
message
);
if
(
result
==
0
)
if
(
result
<
0
)
{
result
=
-
RT_EIO
;
LOG_E
(
"SPI device %s transfer failed"
,
device
->
parent
.
parent
.
name
)
;
goto
__exit
;
}
...
...
@@ -177,9 +181,9 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
message
.
next
=
RT_NULL
;
result
=
device
->
bus
->
ops
->
xfer
(
device
,
&
message
);
if
(
result
==
0
)
if
(
result
<
0
)
{
result
=
-
RT_EIO
;
LOG_E
(
"SPI device %s transfer failed"
,
device
->
parent
.
parent
.
name
)
;
goto
__exit
;
}
...
...
@@ -223,7 +227,7 @@ rt_err_t rt_spi_send_then_recv(struct rt_spi_device *device,
else
{
/* configure SPI bus failed */
result
=
-
RT_EIO
;
LOG_E
(
"SPI device %s configuration failed"
,
device
->
parent
.
parent
.
name
)
;
goto
__exit
;
}
}
...
...
@@ -237,9 +241,9 @@ rt_err_t rt_spi_send_then_recv(struct rt_spi_device *device,
message
.
next
=
RT_NULL
;
result
=
device
->
bus
->
ops
->
xfer
(
device
,
&
message
);
if
(
result
==
0
)
if
(
result
<
0
)
{
result
=
-
RT_EIO
;
LOG_E
(
"SPI device %s transfer failed"
,
device
->
parent
.
parent
.
name
)
;
goto
__exit
;
}
...
...
@@ -252,9 +256,9 @@ rt_err_t rt_spi_send_then_recv(struct rt_spi_device *device,
message
.
next
=
RT_NULL
;
result
=
device
->
bus
->
ops
->
xfer
(
device
,
&
message
);
if
(
result
==
0
)
if
(
result
<
0
)
{
result
=
-
RT_EIO
;
LOG_E
(
"SPI device %s transfer failed"
,
device
->
parent
.
parent
.
name
)
;
goto
__exit
;
}
...
...
@@ -271,12 +275,12 @@ __exit:
return
result
;
}
rt_size_t
rt_spi_transfer
(
struct
rt_spi_device
*
device
,
const
void
*
send_buf
,
void
*
recv_buf
,
rt_size_t
length
)
rt_s
s
ize_t
rt_spi_transfer
(
struct
rt_spi_device
*
device
,
const
void
*
send_buf
,
void
*
recv_buf
,
rt_size_t
length
)
{
rt_
err
_t
result
;
rt_
ssize
_t
result
;
struct
rt_spi_message
message
;
RT_ASSERT
(
device
!=
RT_NULL
);
...
...
@@ -297,8 +301,7 @@ rt_size_t rt_spi_transfer(struct rt_spi_device *device,
else
{
/* configure SPI bus failed */
rt_set_errno
(
-
RT_EIO
);
result
=
0
;
LOG_E
(
"SPI device %s configuration failed"
,
device
->
parent
.
parent
.
name
);
goto
__exit
;
}
}
...
...
@@ -313,16 +316,15 @@ rt_size_t rt_spi_transfer(struct rt_spi_device *device,
/* transfer message */
result
=
device
->
bus
->
ops
->
xfer
(
device
,
&
message
);
if
(
result
==
0
)
if
(
result
<
0
)
{
rt_set_errno
(
-
RT_EIO
);
LOG_E
(
"SPI device %s transfer failed"
,
device
->
parent
.
parent
.
name
);
goto
__exit
;
}
}
else
{
rt_set_errno
(
-
RT_EIO
);
return
0
;
return
-
RT_EIO
;
}
__exit:
...
...
@@ -331,27 +333,32 @@ __exit:
return
result
;
}
rt_uint16_t
rt_spi_sendrecv16
(
struct
rt_spi_device
*
device
,
rt_uint16_t
data
)
rt_err_t
rt_spi_sendrecv16
(
struct
rt_spi_device
*
device
,
rt_uint16_t
senddata
,
rt_uint16_t
*
recvdata
)
{
rt_
uint16_t
value
=
0
;
rt_
err_t
result
;
rt_uint16_t
tmp
;
if
(
device
->
config
.
mode
&
RT_SPI_MSB
)
{
tmp
=
((
data
&
0xff00
)
>>
8
)
|
((
data
&
0x00ff
)
<<
8
);
data
=
tmp
;
tmp
=
((
senddata
&
0xff00
)
>>
8
)
|
((
send
data
&
0x00ff
)
<<
8
);
send
data
=
tmp
;
}
rt_spi_send_then_recv
(
device
,
&
data
,
2
,
&
value
,
2
);
result
=
rt_spi_send_then_recv
(
device
,
&
senddata
,
2
,
recvdata
,
2
);
if
(
result
!=
RT_EOK
)
{
return
result
;
}
if
(
device
->
config
.
mode
&
RT_SPI_MSB
)
{
tmp
=
((
value
&
0xff00
)
>>
8
)
|
((
value
&
0x00ff
)
<<
8
);
value
=
tmp
;
tmp
=
((
*
recvdata
&
0xff00
)
>>
8
)
|
((
*
recvdata
&
0x00ff
)
<<
8
);
*
recvdata
=
tmp
;
}
return
value
;
return
result
;
}
struct
rt_spi_message
*
rt_spi_transfer_message
(
struct
rt_spi_device
*
device
,
...
...
@@ -370,14 +377,9 @@ struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,
result
=
rt_mutex_take
(
&
(
device
->
bus
->
lock
),
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
)
{
rt_set_errno
(
-
RT_EBUSY
);
return
index
;
}
/* reset errno */
rt_set_errno
(
RT_EOK
);
/* configure SPI bus */
if
(
device
->
bus
->
owner
!=
device
)
{
...
...
@@ -391,7 +393,6 @@ struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,
else
{
/* configure SPI bus failed */
rt_set_errno
(
-
RT_EIO
);
goto
__exit
;
}
}
...
...
@@ -401,9 +402,8 @@ struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,
{
/* transmit SPI message */
result
=
device
->
bus
->
ops
->
xfer
(
device
,
index
);
if
(
result
==
0
)
if
(
result
<
0
)
{
rt_set_errno
(
-
RT_EIO
);
break
;
}
...
...
@@ -427,14 +427,9 @@ rt_err_t rt_spi_take_bus(struct rt_spi_device *device)
result
=
rt_mutex_take
(
&
(
device
->
bus
->
lock
),
RT_WAITING_FOREVER
);
if
(
result
!=
RT_EOK
)
{
rt_set_errno
(
-
RT_EBUSY
);
return
-
RT_EBUSY
;
}
/* reset errno */
rt_set_errno
(
RT_EOK
);
/* configure SPI bus */
if
(
device
->
bus
->
owner
!=
device
)
{
...
...
@@ -448,11 +443,9 @@ rt_err_t rt_spi_take_bus(struct rt_spi_device *device)
else
{
/* configure SPI bus failed */
rt_set_errno
(
-
RT_EIO
);
/* release lock */
rt_mutex_release
(
&
(
device
->
bus
->
lock
));
return
-
RT_EIO
;
return
result
;
}
}
...
...
@@ -466,14 +459,12 @@ rt_err_t rt_spi_release_bus(struct rt_spi_device *device)
RT_ASSERT
(
device
->
bus
->
owner
==
device
);
/* release lock */
rt_mutex_release
(
&
(
device
->
bus
->
lock
));
return
RT_EOK
;
return
rt_mutex_release
(
&
(
device
->
bus
->
lock
));
}
rt_err_t
rt_spi_take
(
struct
rt_spi_device
*
device
)
{
rt_
err
_t
result
;
rt_
ssize
_t
result
;
struct
rt_spi_message
message
;
RT_ASSERT
(
device
!=
RT_NULL
);
...
...
@@ -483,13 +474,17 @@ rt_err_t rt_spi_take(struct rt_spi_device *device)
message
.
cs_take
=
1
;
result
=
device
->
bus
->
ops
->
xfer
(
device
,
&
message
);
if
(
result
<
0
)
{
return
(
rt_err_t
)
result
;
}
return
result
;
return
RT_EOK
;
}
rt_err_t
rt_spi_release
(
struct
rt_spi_device
*
device
)
{
rt_
err
_t
result
;
rt_
ssize
_t
result
;
struct
rt_spi_message
message
;
RT_ASSERT
(
device
!=
RT_NULL
);
...
...
@@ -499,6 +494,10 @@ rt_err_t rt_spi_release(struct rt_spi_device *device)
message
.
cs_release
=
1
;
result
=
device
->
bus
->
ops
->
xfer
(
device
,
&
message
);
if
(
result
<
0
)
{
return
(
rt_err_t
)
result
;
}
return
result
;
return
RT_EOK
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录