Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
52fa0189
R
rt-thread
项目概览
2301_76519099
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
3
Star
1
Fork
1
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
52fa0189
编写于
9月 29, 2018
作者:
W
Wu Han
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add I2C bus driver for stm32f10x
上级
3a6e6796
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
113 addition
and
0 deletion
+113
-0
bsp/stm32f10x/drivers/SConscript
bsp/stm32f10x/drivers/SConscript
+3
-0
bsp/stm32f10x/drivers/i2c.c
bsp/stm32f10x/drivers/i2c.c
+85
-0
bsp/stm32f10x/drivers/i2c.h
bsp/stm32f10x/drivers/i2c.h
+25
-0
未找到文件。
bsp/stm32f10x/drivers/SConscript
浏览文件 @
52fa0189
...
...
@@ -15,6 +15,9 @@ usart.c
if
GetDepend
([
'RT_USING_PIN'
]):
src
+=
[
'gpio.c'
]
if
GetDepend
([
'RT_USING_I2C_BITOPS'
]):
src
+=
[
'i2c.c'
]
# add canbus driver.
if
GetDepend
(
'RT_USING_CAN'
):
src
+=
[
'bxcan.c'
]
...
...
bsp/stm32f10x/drivers/i2c.c
0 → 100644
浏览文件 @
52fa0189
#include "i2c.h"
#include <stm32f10x.h>
void
stm32_set_sda
(
void
*
data
,
rt_int32_t
state
)
{
if
(
state
==
1
)
GPIO_SetBits
(
I2C1_GPIO
,
I2C1_GPIO_SDA
);
//GPIOB->BSRRL = I2C1_GPIO_SDA
else
if
(
state
==
0
)
GPIO_ResetBits
(
I2C1_GPIO
,
I2C1_GPIO_SDA
);
//GPIOB->BSRRH = I2C1_GPIO_SDA
}
void
stm32_set_scl
(
void
*
data
,
rt_int32_t
state
)
{
if
(
state
==
1
)
GPIO_SetBits
(
I2C1_GPIO
,
I2C1_GPIO_SCL
);
//GPIOB->BSRRL = I2C1_GPIO_SCL
else
if
(
state
==
0
)
GPIO_ResetBits
(
I2C1_GPIO
,
I2C1_GPIO_SCL
);
//GPIOB->BSRRH = I2C1_GPIO_SCL
}
rt_int32_t
stm32_get_sda
(
void
*
data
)
{
return
(
rt_int32_t
)
GPIO_ReadInputDataBit
(
I2C1_GPIO
,
I2C1_GPIO_SDA
);
//return(GPIOB->IDR & I2C1_GPIO_SDA)
}
rt_int32_t
stm32_get_scl
(
void
*
data
)
{
return
(
rt_int32_t
)
GPIO_ReadInputDataBit
(
I2C1_GPIO
,
I2C1_GPIO_SCL
);
//return(GPIOB->IDR & I2C1_GPIO_SCL)
}
void
stm32_udelay
(
rt_uint32_t
us
)
{
rt_uint32_t
delta
;
/* sysTick->LOAD=21000, RT_TICK_PER_SECOND=1000 */
us
=
us
*
(
SysTick
->
LOAD
/
(
1000000
/
RT_TICK_PER_SECOND
));
delta
=
SysTick
->
VAL
;
/* delay us */
while
(
delta
-
SysTick
->
VAL
<
us
);
}
void
stm32_mdelay
(
rt_uint32_t
ms
)
{
stm32_udelay
(
ms
*
1000
);
}
static
const
struct
rt_i2c_bit_ops
stm32_i2c_bit_ops
=
{
(
void
*
)
0xaa
,
//no use in set_sda,set_scl,get_sda,get_scl
stm32_set_sda
,
stm32_set_scl
,
stm32_get_sda
,
stm32_get_scl
,
stm32_udelay
,
20
,
};
static
void
RCC_Configuration
(
void
)
{
RCC
->
APB2ENR
|=
1
<<
4
;
RCC_APB2PeriphClockCmd
(
RCC_I2C
,
ENABLE
);
}
static
void
GPIO_Configuration
(
void
)
{
GPIO_InitTypeDef
GPIO_InitStructure
;
GPIO_InitStructure
.
GPIO_Pin
=
I2C1_GPIO_SDA
|
I2C1_GPIO_SCL
;
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_Out_OD
;
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_50MHz
;
GPIO_Init
(
I2C1_GPIO
,
&
GPIO_InitStructure
);
}
int
rt_hw_i2c_init
(
void
)
{
static
struct
rt_i2c_bus_device
stm32_i2c
;
RCC_Configuration
();
GPIO_Configuration
();
rt_memset
((
void
*
)
&
stm32_i2c
,
0
,
sizeof
(
struct
rt_i2c_bus_device
));
stm32_i2c
.
priv
=
(
void
*
)
&
stm32_i2c_bit_ops
;
rt_i2c_bit_add_bus
(
&
stm32_i2c
,
"i2c1"
);
return
0
;
}
INIT_BOARD_EXPORT
(
rt_hw_i2c_init
);
bsp/stm32f10x/drivers/i2c.h
0 → 100644
浏览文件 @
52fa0189
#ifndef __I2C_SOFT_INIT_H__
#define __I2C_SOFT_INIT_H__
#include <rtthread.h>
#include <rtdevice.h>
#define I2C1_GPIO GPIOB
#define I2C1_GPIO_SCL GPIO_Pin_6
#define I2C1_GPIO_SDA GPIO_Pin_7
#define RCC_I2C RCC_APB2Periph_GPIOB
int
rt_hw_i2c_init
(
void
);
void
stm32_set_sda
(
void
*
data
,
rt_int32_t
state
);
void
stm32_set_scl
(
void
*
data
,
rt_int32_t
state
);
rt_int32_t
stm32_get_sda
(
void
*
data
);
rt_int32_t
stm32_get_scl
(
void
*
data
);
void
stm32_udelay
(
rt_uint32_t
us
);
void
stm32_mdelay
(
rt_uint32_t
ms
);
static
void
RCC_Configuration
(
void
);
static
void
GPIO_Configuration
(
void
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录