Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
okll00
rt-thread
提交
29ae7404
R
rt-thread
项目概览
okll00
/
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,发现更多精彩内容 >>
提交
29ae7404
编写于
3月 18, 2019
作者:
lymzzyh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add SPI driver
上级
1022cfd3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
303 addition
and
22 deletion
+303
-22
bsp/k210/applications/mnt.c
bsp/k210/applications/mnt.c
+8
-1
bsp/k210/driver/Kconfig
bsp/k210/driver/Kconfig
+59
-2
bsp/k210/driver/SConscript
bsp/k210/driver/SConscript
+1
-6
bsp/k210/driver/drv_io_config.c
bsp/k210/driver/drv_io_config.c
+18
-10
bsp/k210/driver/drv_io_config.h
bsp/k210/driver/drv_io_config.h
+11
-3
bsp/k210/driver/drv_spi.c
bsp/k210/driver/drv_spi.c
+190
-0
bsp/k210/driver/drv_spi.h
bsp/k210/driver/drv_spi.h
+16
-0
未找到文件。
bsp/k210/applications/mnt.c
浏览文件 @
29ae7404
...
...
@@ -8,8 +8,15 @@
*/
#include <rtthread.h>
#include <spi_msd.h>
#include <dfs_fs.h>
int
mnt_init
(
void
)
{
msd_init
(
"sd0"
,
"spi10"
);
if
(
dfs_mount
(
"sd0"
,
"/"
,
"elm"
,
0
,
0
)
==
0
)
{
rt_kprintf
(
"Mount
\"
/dev/sd0
\"
on
\"
/
\"\n
"
);
}
return
0
;
}
INIT_ENV_EXPORT
(
mnt_init
);
bsp/k210/driver/Kconfig
浏览文件 @
29ae7404
...
...
@@ -19,10 +19,64 @@ config BSP_USING_I2C1
select RT_USING_I2C
default n
config BSP_USING_SPI1
bool "Enable SPI1
(GPIO0/1)
"
menu
config BSP_USING_SPI1
bool "Enable SPI1"
select RT_USING_SPI
default n
if BSP_USING_SPI1
config BSP_USING_SPI1_AS_QSPI
bool
default n
config BSP_SPI1_CLK_PIN
int "spi1 clk pin number"
default 29
config BSP_SPI1_D0_PIN
int "spi1 d0 pin number"
default 30
config BSP_SPI1_D1_PIN
int "spi1 d1 pin number"
default 31
if BSP_USING_SPI1_AS_QSPI
config BSP_SPI1_D2_PIN
int "spi1 d2 pin number"
default 32
config BSP_SPI1_D3_PIN
int "spi1 d3 pin number"
default 33
endif
menuconfig BSP_SPI1_USING_SS0
bool "SPI1 Enable SS0"
default n
if BSP_SPI1_USING_SS0
config BSP_SPI1_SS0_PIN
int "spi1 ss0 pin number"
default 24
endif
menuconfig BSP_SPI1_USING_SS1
bool "SPI1 Enable SS1"
default n
if BSP_SPI1_USING_SS1
config BSP_SPI1_SS1_PIN
int "spi1 ss1 pin number"
default 25
endif
menuconfig BSP_SPI1_USING_SS2
bool "SPI1 Enable SS2"
default n
if BSP_SPI1_USING_SS2
config BSP_SPI1_SS2_PIN
int "spi1 ss2 pin number"
default 26
endif
menuconfig BSP_SPI1_USING_SS3
bool "SPI1 Enable SS3"
default n
if BSP_SPI1_USING_SS3
config BSP_SPI1_SS3_PIN
int "spi1 ss3 pin number"
default 27
endif
endif
menuconfig BSP_USING_LCD
bool "Enable LCD on SPI0"
...
...
@@ -73,5 +127,8 @@ if BSP_USING_CAMERA
config BSP_CAMERA_CMOS_PCLK_PIN
int "CMOS PCLK pin number for camera"
default 15
config BSP_CAMERA_CMOS_HREF_PIN
int "CMOS HREF pin number for camera"
default 17
endif
bsp/k210/driver/SConscript
浏览文件 @
29ae7404
...
...
@@ -7,15 +7,13 @@ src = Split('''
board.c
heap.c
drv_uart.c
drv_io_config.c
'''
)
CPPPATH
=
[
cwd
]
if
GetDepend
(
'BSP_USING_LCD'
):
src
+=
[
'drv_lcd.c'
]
if
GetDepend
(
'RT_USING_PIN'
):
src
+=
[
'drv_gpio.c'
]
if
GetDepend
(
'RT_USING_HWTIMER'
):
src
+=
[
'drv_hw_timer.c'
]
...
...
@@ -31,9 +29,6 @@ if GetDepend('RT_USING_SPI'):
if
GetDepend
(
'RT_USING_PWM'
):
src
+=
[
'drv_pwm.c'
]
if
GetDepend
(
'RT_USING_RTC'
):
src
+=
[
'drv_rtc.c'
]
if
GetDepend
(
'RT_USING_WDT'
):
src
+=
[
'drv_wdt.c'
]
...
...
bsp/k210/driver/drv_io_config.c
浏览文件 @
29ae7404
...
...
@@ -25,23 +25,31 @@ static struct io_config
{
BSP_CAMERA_CMOS_PWDN_PIN
,
FUNC_CMOS_PWDN
},
{
BSP_CAMERA_CMOS_XCLK_PIN
,
FUNC_CMOS_XCLK
},
{
BSP_CAMERA_CMOS_PCLK_PIN
,
FUNC_CMOS_PCLK
},
{
BSP_CAMERA_CMOS_PCLK_PIN
,
FUNC_CMOS_HREF
},
#endif
#ifdef BSP_USING_SPI1
{
17
,
FUNC_CMOS_HREF
},
{
24
,
FUNC_SPI1_SS3
},
{
29
,
FUNC_SPI1_SCLK
},
{
30
,
FUNC_SPI1_D0
},
{
31
,
FUNC_SPI1_D1
},
{
BSP_SPI1_CLK_PIN
,
FUNC_SPI1_SCLK
},
{
BSP_SPI1_D0_PIN
,
FUNC_SPI1_D0
},
{
BSP_SPI1_D1_PIN
,
FUNC_SPI1_D1
},
#ifdef BSP_USING_SPI1_AS_QSPI
{
32
,
FUNC_SPI1_D2
},
{
33
,
FUNC_SPI1_D3
},
{
BSP_SPI1_D2_PIN
,
FUNC_SPI1_D2
},
{
BSP_SPI1_D3_PIN
,
FUNC_SPI1_D3
},
#endif
#ifdef BSP_SPI1_USING_SS0
{
BSP_SPI1_SS0_PIN
,
HS_GPIO
(
SPI1_CS0_PIN
)},
#endif
#ifdef BSP_USING_SDCARD
{
32
,
HS_GPIO
(
SD_CS_PIN
)},
#ifdef BSP_SPI1_USING_SS1
{
BSP_SPI1_SS1_PIN
,
HS_GPIO
(
SPI1_CS1_PIN
)},
#endif
#ifdef BSP_SPI1_USING_SS2
{
BSP_SPI1_SS2_PIN
,
HS_GPIO
(
SPI1_CS2_PIN
)},
#endif
#ifdef BSP_SPI1_USING_SS3
{
BSP_SPI1_SS3_PIN
,
HS_GPIO
(
SPI1_CS3_PIN
)},
#endif
#endif
};
...
...
bsp/k210/driver/drv_io_config.h
浏览文件 @
29ae7404
...
...
@@ -6,9 +6,17 @@ enum HS_GPIO_CONFIG
#ifdef BSP_USING_LCD
LCD_DC_PIN
=
0
,
/* LCD DC PIN */
#endif
#ifdef BSP_USING_SDCARD
SD_CS_PIN
,
/* SD_CS_PIN */
#ifdef BSP_SPI1_USING_SS0
SPI1_CS0_PIN
,
#endif
#ifdef BSP_SPI1_USING_SS1
SPI1_CS1_PIN
,
#endif
#ifdef BSP_SPI1_USING_SS2
SPI1_CS2_PIN
,
#endif
#ifdef BSP_SPI1_USING_SS3
SPI1_CS3_PIN
,
#endif
};
...
...
bsp/k210/driver/drv_spi.c
0 → 100644
浏览文件 @
29ae7404
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-18 ZYH first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#ifdef RT_USING_SPI
#include "drv_spi.h"
#include <drv_io_config.h>
#include <spi.h>
#include <dmac.h>
#include <sysctl.h>
#include <gpiohs.h>
#include <string.h>
#define DRV_SPI_DEVICE(spi_bus) (struct drv_spi_bus *)(spi_bus)
struct
drv_spi_bus
{
struct
rt_spi_bus
parent
;
spi_device_num_t
spi_instance
;
dmac_channel_number_t
dma_send_channel
;
dmac_channel_number_t
dma_recv_channel
;
};
struct
drv_cs
{
int
cs_index
;
int
cs_pin
;
};
static
volatile
spi_t
*
const
spi_instance
[
4
]
=
{
(
volatile
spi_t
*
)
SPI0_BASE_ADDR
,
(
volatile
spi_t
*
)
SPI1_BASE_ADDR
,
(
volatile
spi_t
*
)
SPI_SLAVE_BASE_ADDR
,
(
volatile
spi_t
*
)
SPI3_BASE_ADDR
};
static
rt_err_t
drv_spi_configure
(
struct
rt_spi_device
*
device
,
struct
rt_spi_configuration
*
configuration
)
{
rt_err_t
ret
=
RT_EOK
;
struct
drv_spi_bus
*
bus
=
DRV_SPI_DEVICE
(
device
->
bus
);
struct
drv_cs
*
cs
=
(
struct
drv_cs
*
)
device
->
parent
.
user_data
;
RT_ASSERT
(
bus
!=
RT_NULL
);
gpiohs_set_drive_mode
(
cs
->
cs_pin
,
GPIO_DM_OUTPUT
);
gpiohs_set_pin
(
cs
->
cs_pin
,
GPIO_PV_HIGH
);
#ifdef BSP_USING_SPI1_AS_QSPI
/* Todo:QSPI*/
#else
spi_init
(
bus
->
spi_instance
,
configuration
->
mode
&
RT_SPI_MODE_3
,
SPI_FF_STANDARD
,
configuration
->
data_width
,
0
);
#endif
spi_set_clk_rate
(
bus
->
spi_instance
,
configuration
->
max_hz
);
return
ret
;
}
extern
void
spi_receive_data_normal_dma
(
dmac_channel_number_t
dma_send_channel_num
,
dmac_channel_number_t
dma_receive_channel_num
,
spi_device_num_t
spi_num
,
spi_chip_select_t
chip_select
,
const
void
*
cmd_buff
,
size_t
cmd_len
,
void
*
rx_buff
,
size_t
rx_len
);
static
rt_uint32_t
drv_spi_xfer
(
struct
rt_spi_device
*
device
,
struct
rt_spi_message
*
message
)
{
struct
drv_spi_bus
*
bus
=
DRV_SPI_DEVICE
(
device
->
bus
);
struct
drv_cs
*
cs
=
(
struct
drv_cs
*
)
device
->
parent
.
user_data
;
struct
rt_spi_configuration
*
cfg
=
&
device
->
config
;
const
uint8_t
*
tx_buff
=
message
->
send_buf
;
uint8_t
*
rx_buff
=
message
->
recv_buf
;
uint32_t
dummy
[
1024
];
size_t
send_size
,
recv_size
;
send_size
=
message
->
length
;
recv_size
=
message
->
length
;
RT_ASSERT
(
bus
!=
RT_NULL
);
if
(
message
->
cs_take
)
{
gpiohs_set_pin
(
cs
->
cs_pin
,
GPIO_PV_LOW
);
}
if
(
message
->
length
)
{
if
(
!
tx_buff
)
{
tx_buff
=
(
uint8_t
*
)
&
dummy
;
send_size
=
1
;
}
if
(
!
rx_buff
)
{
rx_buff
=
(
uint8_t
*
)
&
dummy
;
recv_size
=
1
;
}
spi_dup_send_receive_data_dma
(
bus
->
dma_send_channel
,
bus
->
dma_recv_channel
,
bus
->
spi_instance
,
cs
->
cs_index
,
tx_buff
,
send_size
,
rx_buff
,
recv_size
);
}
if
(
message
->
cs_release
)
{
gpiohs_set_pin
(
cs
->
cs_pin
,
GPIO_PV_HIGH
);
}
return
message
->
length
;
}
const
static
struct
rt_spi_ops
drv_spi_ops
=
{
drv_spi_configure
,
drv_spi_xfer
};
int
rt_hw_spi_init
(
void
)
{
rt_err_t
ret
=
RT_EOK
;
#ifdef BSP_USING_SPI1
{
static
struct
drv_spi_bus
spi_bus1
;
spi_bus1
.
spi_instance
=
SPI_DEVICE_1
;
spi_bus1
.
dma_send_channel
=
DMAC_CHANNEL1
;
spi_bus1
.
dma_recv_channel
=
DMAC_CHANNEL2
;
ret
=
rt_spi_bus_register
(
&
spi_bus1
.
parent
,
"spi1"
,
&
drv_spi_ops
);
#ifdef BSP_SPI1_USING_SS0
{
static
struct
rt_spi_device
spi_device10
;
static
struct
drv_cs
cs10
=
{
.
cs_index
=
SPI_CHIP_SELECT_0
,
.
cs_pin
=
SPI1_CS0_PIN
};
rt_spi_bus_attach_device
(
&
spi_device10
,
"spi10"
,
"spi1"
,
(
void
*
)
&
cs10
);
}
#endif
#ifdef BSP_SPI1_USING_SS1
{
static
struct
rt_spi_device
spi_device11
;
static
struct
drv_cs
cs11
=
{
.
cs_index
=
SPI_CHIP_SELECT_1
,
.
cs_pin
=
SPI1_CS1_PIN
};
rt_spi_bus_attach_device
(
&
spi_device11
,
"spi11"
,
"spi1"
,
(
void
*
)
&
cs11
);
}
#endif
#ifdef BSP_SPI1_USING_SS2
{
static
struct
rt_spi_device
spi_device12
;
static
struct
drv_cs
cs12
=
{
.
cs_index
=
SPI_CHIP_SELECT_2
,
.
cs_pin
=
SPI1_CS2_PIN
};
rt_spi_bus_attach_device
(
&
spi_device12
,
"spi12"
,
"spi1"
,
(
void
*
)
&
cs12
);
}
#endif
#ifdef BSP_SPI1_USING_SS3
{
static
struct
rt_spi_device
spi_device13
;
static
struct
drv_cs
cs13
=
{
.
cs_index
=
SPI_CHIP_SELECT_2
,
.
cs_pin
=
SPI1_CS2_PIN
};
rt_spi_bus_attach_device
(
&
spi_device13
,
"spi13"
,
"spi1"
,
(
void
*
)
&
cs13
);
}
#endif
}
#endif
return
ret
;
}
INIT_DEVICE_EXPORT
(
rt_hw_spi_init
);
#endif
bsp/k210/driver/drv_spi.h
0 → 100644
浏览文件 @
29ae7404
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-03-18 ZYH first version
*/
#ifndef DRV_SPI_H__
#define DRV_SPI_H__
int
rt_hw_spi_init
(
void
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录