Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
逆着光、寻觅
rt-thread
提交
93f5e3e4
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,发现更多精彩内容 >>
未验证
提交
93f5e3e4
编写于
3月 14, 2018
作者:
lymzzyh
提交者:
GitHub
3月 14, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1277 from uestczyh222/master
[Bsp][STM32F4xx-HAL]Add I2C driver
上级
d40df63c
3abe6bcc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
160 addition
and
0 deletion
+160
-0
bsp/stm32f4xx-HAL/drivers/SConscript
bsp/stm32f4xx-HAL/drivers/SConscript
+5
-0
bsp/stm32f4xx-HAL/drivers/drv_i2c.c
bsp/stm32f4xx-HAL/drivers/drv_i2c.c
+125
-0
bsp/stm32f4xx-HAL/drivers/drv_i2c.h
bsp/stm32f4xx-HAL/drivers/drv_i2c.h
+30
-0
未找到文件。
bsp/stm32f4xx-HAL/drivers/SConscript
浏览文件 @
93f5e3e4
...
...
@@ -30,8 +30,13 @@ if GetDepend(['RT_USING_USB_DEVICE']):
if
GetDepend
([
'RT_USING_RTC'
]):
src
+=
[
'drv_rtc.c'
]
if
GetDepend
([
'RT_USING_USB_HOST'
]):
src
+=
[
'drv_usbh.c'
]
if
GetDepend
([
'RT_USING_I2C'
]):
src
+=
[
'drv_i2c.c'
]
CPPPATH
=
[
cwd
]
group
=
DefineGroup
(
'Drivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
...
...
bsp/stm32f4xx-HAL/drivers/drv_i2c.c
0 → 100644
浏览文件 @
93f5e3e4
/*
* File : drv_i2c.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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
)
{
int
i
=
(
HAL_RCC_GetHCLKFreq
()
/
4000000
*
us
);
while
(
i
)
{
i
--
;
}
}
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/stm32f4xx-HAL/drivers/drv_i2c.h
0 → 100644
浏览文件 @
93f5e3e4
/*
* File : drv_i2c.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录