Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逆着光、寻觅
rt-thread
提交
292f35f8
R
rt-thread
项目概览
逆着光、寻觅
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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,发现更多精彩内容 >>
未验证
提交
292f35f8
编写于
10月 12, 2018
作者:
B
Bernard Xiong
提交者:
GitHub
10月 12, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1878 from uestczyh222/f1_i2c
[Bsp][stm32f1xx-hal]添加I2C驱动
上级
33cb916f
4c623b39
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
112 addition
and
0 deletion
+112
-0
bsp/stm32f10x-HAL/drivers/SConscript
bsp/stm32f10x-HAL/drivers/SConscript
+2
-0
bsp/stm32f10x-HAL/drivers/drv_i2c.c
bsp/stm32f10x-HAL/drivers/drv_i2c.c
+97
-0
bsp/stm32f10x-HAL/drivers/drv_i2c.h
bsp/stm32f10x-HAL/drivers/drv_i2c.h
+13
-0
未找到文件。
bsp/stm32f10x-HAL/drivers/SConscript
浏览文件 @
292f35f8
...
@@ -20,6 +20,8 @@ if GetDepend(['RT_USING_USB_DEVICE']):
...
@@ -20,6 +20,8 @@ if GetDepend(['RT_USING_USB_DEVICE']):
src
+=
[
'drv_usb.c'
]
src
+=
[
'drv_usb.c'
]
if
GetDepend
([
'RT_USING_SDCARD'
]):
if
GetDepend
([
'RT_USING_SDCARD'
]):
src
+=
[
'drv_sdcard.c'
]
src
+=
[
'drv_sdcard.c'
]
if
GetDepend
([
'RT_USING_I2C'
,
'RT_USING_I2C_BITOPS'
]):
src
+=
[
'drv_i2c.c'
]
if
rtconfig
.
CROSS_TOOL
==
'gcc'
:
if
rtconfig
.
CROSS_TOOL
==
'gcc'
:
src
+=
[
'gcc_startup.s'
]
src
+=
[
'gcc_startup.s'
]
...
...
bsp/stm32f10x-HAL/drivers/drv_i2c.c
0 → 100644
浏览文件 @
292f35f8
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-06-05 tanek first implementation.
* 2018-03-08 ZYH Porting for stm32f4xx
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_i2c.h"
#include <board.h>
/*user can change this*/
#define I2C_BUS_NAME "i2c2"
/*user should change this to adapt specific board*/
#define I2C_SCL_PIN GPIO_PIN_6
#define I2C_SCL_PORT GPIOB
#define I2C_SCL_PORT_CLK_ENABLE __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_SDA_PIN GPIO_PIN_7
#define I2C_SDA_PORT GPIOB
#define I2C_SDA_PORT_CLK_ENABLE __HAL_RCC_GPIOB_CLK_ENABLE
static
void
drv_i2c_gpio_init
()
{
GPIO_InitTypeDef
GPIO_Initure
;
I2C_SCL_PORT_CLK_ENABLE
();
I2C_SDA_PORT_CLK_ENABLE
();
GPIO_Initure
.
Pin
=
I2C_SCL_PIN
;
GPIO_Initure
.
Mode
=
GPIO_MODE_OUTPUT_OD
;
GPIO_Initure
.
Pull
=
GPIO_PULLUP
;
GPIO_Initure
.
Speed
=
GPIO_SPEED_HIGH
;
HAL_GPIO_Init
(
I2C_SCL_PORT
,
&
GPIO_Initure
);
GPIO_Initure
.
Pin
=
I2C_SDA_PIN
;
GPIO_Initure
.
Mode
=
GPIO_MODE_OUTPUT_OD
;
GPIO_Initure
.
Pull
=
GPIO_PULLUP
;
GPIO_Initure
.
Speed
=
GPIO_SPEED_HIGH
;
HAL_GPIO_Init
(
I2C_SDA_PORT
,
&
GPIO_Initure
);
HAL_GPIO_WritePin
(
I2C_SCL_PORT
,
I2C_SCL_PIN
,
GPIO_PIN_SET
);
HAL_GPIO_WritePin
(
I2C_SDA_PORT
,
I2C_SDA_PIN
,
GPIO_PIN_SET
);
}
static
void
drv_set_sda
(
void
*
data
,
rt_int32_t
state
)
{
HAL_GPIO_WritePin
(
I2C_SDA_PORT
,
I2C_SDA_PIN
,
state
?
GPIO_PIN_SET
:
GPIO_PIN_RESET
);
}
static
void
drv_set_scl
(
void
*
data
,
rt_int32_t
state
)
{
HAL_GPIO_WritePin
(
I2C_SCL_PORT
,
I2C_SCL_PIN
,
state
?
GPIO_PIN_SET
:
GPIO_PIN_RESET
);
}
static
rt_int32_t
drv_get_sda
(
void
*
data
)
{
return
HAL_GPIO_ReadPin
(
I2C_SDA_PORT
,
I2C_SDA_PIN
)
?
1
:
0
;
}
static
rt_int32_t
drv_get_scl
(
void
*
data
)
{
return
HAL_GPIO_ReadPin
(
I2C_SCL_PORT
,
I2C_SCL_PIN
)
?
1
:
0
;
}
static
void
drv_udelay
(
rt_uint32_t
us
)
{
__IO
uint32_t
Delay
=
us
*
(
SystemCoreClock
/
8U
/
1000000U
);
do
{
__NOP
();
}
while
(
Delay
--
);
}
static
const
struct
rt_i2c_bit_ops
drv_bit_ops
=
{
RT_NULL
,
drv_set_sda
,
drv_set_scl
,
drv_get_sda
,
drv_get_scl
,
drv_udelay
,
1
,
100
};
int
drv_i2c_init
(
void
)
{
static
struct
rt_i2c_bus_device
i2c2_bus
;
drv_i2c_gpio_init
();
rt_memset
((
void
*
)
&
i2c2_bus
,
0
,
sizeof
(
struct
rt_i2c_bus_device
));
i2c2_bus
.
priv
=
(
void
*
)
&
drv_bit_ops
;
rt_i2c_bit_add_bus
(
&
i2c2_bus
,
I2C_BUS_NAME
);
return
RT_EOK
;
}
INIT_DEVICE_EXPORT
(
drv_i2c_init
);
/* end of i2c driver */
bsp/stm32f10x-HAL/drivers/drv_i2c.h
0 → 100644
浏览文件 @
292f35f8
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2017-06-05 tanek first implementation.
*/
#ifndef __DRV_I2C__
#define __DRV_I2C__
int
hw_i2c_init
(
void
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录