Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
a0c848b0
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,发现更多精彩内容 >>
提交
a0c848b0
编写于
10月 03, 2018
作者:
xuzhuoyi96
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp][stm32f429-disco] Add i2c support
上级
1ca25164
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
144 addition
and
0 deletion
+144
-0
bsp/stm32f429-disco/drivers/drv_i2c.c
bsp/stm32f429-disco/drivers/drv_i2c.c
+120
-0
bsp/stm32f429-disco/drivers/drv_i2c.h
bsp/stm32f429-disco/drivers/drv_i2c.h
+24
-0
未找到文件。
bsp/stm32f429-disco/drivers/drv_i2c.c
0 → 100644
浏览文件 @
a0c848b0
/*
* File : drv_i2c.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017 RT-Thread Develop Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2017-06-05 tanek first implementation.
*/
#include "drv_i2c.h"
#include <board.h>
#include <finsh.h>
#include <rtdevice.h>
#include <rthw.h>
#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINTF(...) rt_kprintf(__VA_ARGS__)
#else
#define DEBUG_PRINTF(...)
#endif
static
void
stm32f4_i2c_gpio_init
()
{
GPIO_InitTypeDef
GPIO_Initure
;
__HAL_RCC_GPIOA_CLK_ENABLE
();
__HAL_RCC_GPIOC_CLK_ENABLE
();
GPIO_Initure
.
Pin
=
GPIO_PIN_8
;
GPIO_Initure
.
Mode
=
GPIO_MODE_OUTPUT_OD
;
GPIO_Initure
.
Pull
=
GPIO_PULLUP
;
GPIO_Initure
.
Speed
=
GPIO_SPEED_FAST
;
HAL_GPIO_Init
(
GPIOA
,
&
GPIO_Initure
);
GPIO_Initure
.
Pin
=
GPIO_PIN_9
;
GPIO_Initure
.
Mode
=
GPIO_MODE_OUTPUT_OD
;
GPIO_Initure
.
Pull
=
GPIO_PULLUP
;
GPIO_Initure
.
Speed
=
GPIO_SPEED_FAST
;
HAL_GPIO_Init
(
GPIOC
,
&
GPIO_Initure
);
HAL_GPIO_WritePin
(
GPIOA
,
GPIO_PIN_8
,
GPIO_PIN_SET
);
HAL_GPIO_WritePin
(
GPIOC
,
GPIO_PIN_9
,
GPIO_PIN_SET
);
}
static
void
stm32f4_set_sda
(
void
*
data
,
rt_int32_t
state
)
{
HAL_GPIO_WritePin
(
GPIOC
,
GPIO_PIN_9
,
(
GPIO_PinState
)
state
);
}
static
void
stm32f4_set_scl
(
void
*
data
,
rt_int32_t
state
)
{
HAL_GPIO_WritePin
(
GPIOA
,
GPIO_PIN_8
,
(
GPIO_PinState
)
state
);
}
static
rt_int32_t
stm32f4_get_sda
(
void
*
data
)
{
return
(
rt_int32_t
)
HAL_GPIO_ReadPin
(
GPIOC
,
GPIO_PIN_9
);
}
static
rt_int32_t
stm32f4_get_scl
(
void
*
data
)
{
return
(
rt_int32_t
)
HAL_GPIO_ReadPin
(
GPIOA
,
GPIO_PIN_8
);
}
static
void
stm32f4_udelay
(
rt_uint32_t
us
)
{
rt_int32_t
i
;
for
(;
us
>
0
;
us
--
)
{
i
=
50
;
while
(
i
>
0
)
{
i
--
;
}
}
}
static
const
struct
rt_i2c_bit_ops
bit_ops
=
{
RT_NULL
,
stm32f4_set_sda
,
stm32f4_set_scl
,
stm32f4_get_sda
,
stm32f4_get_scl
,
stm32f4_udelay
,
5
,
100
};
int
stm32f4_i2c_init
(
void
)
{
struct
rt_i2c_bus_device
*
bus
;
bus
=
rt_malloc
(
sizeof
(
struct
rt_i2c_bus_device
));
if
(
bus
==
RT_NULL
)
{
rt_kprintf
(
"rt_malloc failed
\n
"
);
return
-
RT_ENOMEM
;
}
rt_memset
((
void
*
)
bus
,
0
,
sizeof
(
struct
rt_i2c_bus_device
));
bus
->
priv
=
(
void
*
)
&
bit_ops
;
stm32f4_i2c_gpio_init
();
rt_i2c_bit_add_bus
(
bus
,
"i2c3"
);
return
RT_EOK
;
}
INIT_DEVICE_EXPORT
(
stm32f4_i2c_init
);
bsp/stm32f429-disco/drivers/drv_i2c.h
0 → 100644
浏览文件 @
a0c848b0
/*
* File : drv_i2c.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2017 RT-Thread Develop Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2017-06-05 tanek first implementation.
*/
#ifndef STM32F4XX_IIC_INCLUDED
#define STM32F4XX_IIC_INCLUDED
#include <rtthread.h>
#include <drivers/spi.h>
#include "stm32f4xx_hal.h"
#endif // STM32F20X_40X_SPI_H_INCLUDED
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录