Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
码肥人壮
rt-thread
提交
a3b02771
R
rt-thread
项目概览
码肥人壮
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a3b02771
编写于
11月 05, 2020
作者:
B
Bernard Xiong
提交者:
GitHub
11月 05, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4008 from xckhmf/master
[bsp/nrf5x]fixed spi driver bugs
上级
2a349ff1
ce9132ca
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
19 deletion
+33
-19
bsp/nrf5x/libraries/drivers/drv_spi.c
bsp/nrf5x/libraries/drivers/drv_spi.c
+33
-19
未找到文件。
bsp/nrf5x/libraries/drivers/drv_spi.c
浏览文件 @
a3b02771
...
...
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2020-05-22 Sherman first version
* 2020-11-02 xckhmf fixed bug
*/
#include <stdint.h>
...
...
@@ -19,6 +20,7 @@
#ifdef BSP_USING_SPI
#if defined(BSP_USING_SPI0) || defined(BSP_USING_SPI1) || defined(BSP_USING_SPI2)
static
struct
nrfx_drv_spi_config
spi_config
[]
=
{
#ifdef BSP_USING_SPI0
...
...
@@ -117,12 +119,12 @@ static rt_err_t spi_configure(struct rt_spi_device *device,
nrfx_spi_t
spi
=
spi_bus_obj
[
index
].
spi
;
nrfx_spi_config_t
config
=
NRFX_SPI_DEFAULT_CONFIG
(
bsp_spi_pin
[
index
].
sck_pin
,
bsp_spi_pin
[
index
].
mosi_pin
,
bsp_spi_pin
[
index
].
miso_pin
,
bsp_spi_pin
[
index
].
ss_pin
);
bsp_spi_pin
[
index
].
mosi_pin
,
bsp_spi_pin
[
index
].
miso_pin
,
NRFX_SPI_PIN_NOT_USED
);
/* spi config ss pin */
if
(
device
->
user_data
!=
RT_NULL
)
if
(
device
->
parent
.
user_data
!=
RT_NULL
)
{
config
.
ss_pin
=
(
rt_uint8_t
)
device
->
user_data
;
nrf_gpio_cfg_output
((
uint32_t
)
device
->
parent
.
user_data
)
;
}
/* spi config bit order */
if
(
configuration
->
mode
&
RT_SPI_MSB
)
...
...
@@ -198,32 +200,43 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
RT_ASSERT
(
device
->
bus
->
parent
.
user_data
!=
RT_NULL
);
rt_uint8_t
index
=
spi_index_find
(
device
->
bus
);
nrfx_err_t
nrf_ret
;
RT_ASSERT
(
index
!=
0xFF
);
nrfx_spi_t
*
p_instance
=
&
spi_bus_obj
[
index
].
spi
;
nrfx_spi_xfer_desc_t
p_xfer_desc
;
if
(
message
->
cs_take
==
1
)
{
nrf_gpio_pin_clear
((
uint32_t
)
device
->
parent
.
user_data
);
}
p_xfer_desc
.
p_rx_buffer
=
message
->
recv_buf
;
p_xfer_desc
.
rx_length
=
message
->
length
;
p_xfer_desc
.
p_tx_buffer
=
message
->
send_buf
;
p_xfer_desc
.
tx_length
=
message
->
length
;
if
(
message
->
send_buf
==
RT_NULL
)
{
p_xfer_desc
.
p_rx_buffer
=
message
->
recv_buf
;
p_xfer_desc
.
rx_length
=
message
->
length
;
p_xfer_desc
.
p_tx_buffer
=
RT_NULL
;
p_xfer_desc
.
tx_length
=
0
;
}
else
if
(
message
->
recv_buf
==
RT_NULL
)
{
p_xfer_desc
.
p_tx_buffer
=
message
->
send_buf
;
p_xfer_desc
.
tx_length
=
message
->
length
;
p_xfer_desc
.
p_rx_buffer
=
RT_NULL
;
p_xfer_desc
.
rx_length
=
0
;
p_xfer_desc
.
rx_length
=
0
;
}
nrfx_err_t
nrf_ret
=
nrfx_spi_xfer
(
p_instance
,
&
p_xfer_desc
,
0
);
if
(
NRFX_SUCCESS
==
nrf_ret
)
return
message
->
length
;
else
nrf_ret
=
nrfx_spi_xfer
(
p_instance
,
&
p_xfer_desc
,
0
);
if
(
message
->
cs_release
==
1
)
{
nrf_gpio_pin_set
((
uint32_t
)
device
->
parent
.
user_data
);
}
if
(
NRFX_SUCCESS
!=
nrf_ret
)
{
return
0
;
}
else
{
return
message
->
length
;
}
}
/* spi bus callback function */
...
...
@@ -260,6 +273,7 @@ rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name,
{
RT_ASSERT
(
bus_name
!=
RT_NULL
);
RT_ASSERT
(
device_name
!=
RT_NULL
);
RT_ASSERT
(
ss_pin
!=
RT_NULL
);
rt_err_t
result
;
struct
rt_spi_device
*
spi_device
;
...
...
@@ -267,8 +281,7 @@ rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name,
spi_device
=
(
struct
rt_spi_device
*
)
rt_malloc
(
sizeof
(
struct
rt_spi_device
));
RT_ASSERT
(
spi_device
!=
RT_NULL
);
/* initialize the cs pin */
spi_device
->
user_data
=
(
void
*
)
ss_pin
;
result
=
rt_spi_bus_attach_device
(
spi_device
,
device_name
,
bus_name
,
RT_NULL
);
result
=
rt_spi_bus_attach_device
(
spi_device
,
device_name
,
bus_name
,
(
void
*
)
ss_pin
);
if
(
result
!=
RT_EOK
)
{
LOG_E
(
"%s attach to %s faild, %d"
,
device_name
,
bus_name
,
result
);
...
...
@@ -278,4 +291,5 @@ rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name,
return
result
;
}
#endif
/* BSP_USING_SPI0 || BSP_USING_SPI1 || BSP_USING_SPI2 */
#endif
/*BSP_USING_SPI*/
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录