Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
aa8e5cc4
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
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看板
提交
aa8e5cc4
编写于
3月 14, 2017
作者:
A
Aubr.Cool
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components] drivers pin irq change apis
上级
320b116b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
67 addition
and
79 deletion
+67
-79
bsp/stm32f10x/drivers/gpio.c
bsp/stm32f10x/drivers/gpio.c
+58
-62
components/drivers/include/drivers/pin.h
components/drivers/include/drivers/pin.h
+7
-6
components/drivers/misc/pin.c
components/drivers/misc/pin.c
+2
-11
未找到文件。
bsp/stm32f10x/drivers/gpio.c
浏览文件 @
aa8e5cc4
...
...
@@ -653,7 +653,8 @@ rt_err_t stm32_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
return
RT_EOK
;
}
rt_err_t
stm32_pin_irq_enable
(
struct
rt_device
*
device
,
rt_base_t
pin
)
rt_err_t
stm32_pin_irq_enable
(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_uint32_t
enabled
)
{
const
struct
pin_index
*
index
;
const
struct
pin_irq_map
*
irqmap
;
...
...
@@ -668,74 +669,70 @@ rt_err_t stm32_pin_irq_enable(struct rt_device *device, rt_base_t pin)
{
return
RT_ENOSYS
;
}
irqindex
=
bit2bitno
(
index
->
pin
);
if
(
irqindex
<
0
||
irqindex
>=
ITEM_NUM
(
pin_irq_map
))
{
return
RT_ENOSYS
;
}
level
=
rt_hw_interrupt_disable
();
if
(
pin_irq_hdr_tab
[
irqindex
].
pin
==
-
1
)
if
(
enabled
==
PIN_IRQ_ENABLE
)
{
irqindex
=
bit2bitno
(
index
->
pin
);
if
(
irqindex
<
0
||
irqindex
>=
ITEM_NUM
(
pin_irq_map
))
{
return
RT_ENOSYS
;
}
level
=
rt_hw_interrupt_disable
();
if
(
pin_irq_hdr_tab
[
irqindex
].
pin
==
-
1
)
{
rt_hw_interrupt_enable
(
level
);
return
RT_ENOSYS
;
}
irqmap
=
&
pin_irq_map
[
irqindex
];
/* GPIO Periph clock enable */
RCC_APB2PeriphClockCmd
(
index
->
rcc
,
ENABLE
);
/* Configure GPIO_InitStructure */
GPIO_InitStructure
.
GPIO_Pin
=
index
->
pin
;
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IPU
;
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_50MHz
;
GPIO_Init
(
index
->
gpio
,
&
GPIO_InitStructure
);
NVIC_InitStructure
.
NVIC_IRQChannel
=
irqmap
->
irqno
;
NVIC_InitStructure
.
NVIC_IRQChannelPreemptionPriority
=
2
;
NVIC_InitStructure
.
NVIC_IRQChannelSubPriority
=
2
;
NVIC_InitStructure
.
NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init
(
&
NVIC_InitStructure
);
EXTI_InitStructure
.
EXTI_Line
=
irqmap
->
irqbit
;
EXTI_InitStructure
.
EXTI_Mode
=
EXTI_Mode_Interrupt
;
switch
(
pin_irq_hdr_tab
[
irqindex
].
mode
)
{
case
PIN_IRQ_MODE_RISING
:
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Rising
;
break
;
case
PIN_IRQ_MODE_FALLING
:
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Falling
;
break
;
case
PIN_IRQ_MODE_RISING_FALLING
:
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Rising_Falling
;
break
;
}
EXTI_InitStructure
.
EXTI_LineCmd
=
ENABLE
;
EXTI_Init
(
&
EXTI_InitStructure
);
rt_hw_interrupt_enable
(
level
);
return
RT_ENOSYS
;
}
irqmap
=
&
pin_irq_map
[
irqindex
];
/* GPIO Periph clock enable */
RCC_APB2PeriphClockCmd
(
index
->
rcc
,
ENABLE
);
/* Configure GPIO_InitStructure */
GPIO_InitStructure
.
GPIO_Pin
=
index
->
pin
;
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_IPU
;
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_50MHz
;
GPIO_Init
(
index
->
gpio
,
&
GPIO_InitStructure
);
NVIC_InitStructure
.
NVIC_IRQChannel
=
irqmap
->
irqno
;
NVIC_InitStructure
.
NVIC_IRQChannelPreemptionPriority
=
2
;
NVIC_InitStructure
.
NVIC_IRQChannelSubPriority
=
2
;
NVIC_InitStructure
.
NVIC_IRQChannelCmd
=
ENABLE
;
NVIC_Init
(
&
NVIC_InitStructure
);
EXTI_InitStructure
.
EXTI_Line
=
irqmap
->
irqbit
;
EXTI_InitStructure
.
EXTI_Mode
=
EXTI_Mode_Interrupt
;
switch
(
pin_irq_hdr_tab
[
irqindex
].
mode
)
{
case
PIN_IRQ_MODE_RISING
:
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Rising
;
break
;
case
PIN_IRQ_MODE_FALLING
:
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Falling
;
break
;
case
PIN_IRQ_MODE_RISING_FALLING
:
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Rising_Falling
;
break
;
}
EXTI_InitStructure
.
EXTI_LineCmd
=
ENABLE
;
EXTI_Init
(
&
EXTI_InitStructure
);
rt_hw_interrupt_enable
(
level
);
return
RT_EOK
;
}
rt_err_t
stm32_pin_irq_disable
(
struct
rt_device
*
device
,
rt_base_t
pin
)
{
const
struct
pin_index
*
index
;
const
struct
pin_irq_map
*
irqmap
;
EXTI_InitTypeDef
EXTI_InitStructure
;
index
=
get_pin
(
pin
);
if
(
index
==
RT_NULL
)
else
if
(
enabled
==
PIN_IRQ_DISABLE
)
{
return
RT_ENOSYS
;
irqmap
=
get_pin_irq_map
(
index
->
pin
);
if
(
irqmap
==
RT_NULL
)
{
return
RT_ENOSYS
;
}
EXTI_InitStructure
.
EXTI_Line
=
irqmap
->
irqbit
;
EXTI_InitStructure
.
EXTI_Mode
=
EXTI_Mode_Interrupt
;
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Rising
;
EXTI_InitStructure
.
EXTI_LineCmd
=
DISABLE
;
EXTI_Init
(
&
EXTI_InitStructure
);
}
irqmap
=
get_pin_irq_map
(
index
->
pin
);
if
(
irqmap
==
RT_NULL
)
else
{
return
RT_ENOSYS
;
}
EXTI_InitStructure
.
EXTI_Line
=
irqmap
->
irqbit
;
EXTI_InitStructure
.
EXTI_Mode
=
EXTI_Mode_Interrupt
;
EXTI_InitStructure
.
EXTI_Trigger
=
EXTI_Trigger_Rising
;
EXTI_InitStructure
.
EXTI_LineCmd
=
DISABLE
;
EXTI_Init
(
&
EXTI_InitStructure
);
return
RT_EOK
;
}
const
static
struct
rt_pin_ops
_stm32_pin_ops
=
...
...
@@ -746,7 +743,6 @@ const static struct rt_pin_ops _stm32_pin_ops =
stm32_pin_attach_irq
,
stm32_pin_dettach_irq
,
stm32_pin_irq_enable
,
stm32_pin_irq_disable
};
int
stm32_hw_pin_init
(
void
)
...
...
components/drivers/include/drivers/pin.h
浏览文件 @
aa8e5cc4
...
...
@@ -50,6 +50,9 @@ struct rt_device_pin
#define PIN_IRQ_MODE_FALLING 0x01
#define PIN_IRQ_MODE_RISING_FALLING 0x02
#define PIN_IRQ_DISABLE 0x00
#define PIN_IRQ_ENABLE 0x01
#define PIN_IRQ_PIN_NONE -1
struct
rt_device_pin_mode
...
...
@@ -64,8 +67,8 @@ struct rt_device_pin_status
};
struct
rt_pin_irq_hdr
{
rt_int
32
_t
pin
;
rt_uint
32
_t
mode
;
rt_int
16
_t
pin
;
rt_uint
16
_t
mode
;
void
(
*
hdr
)(
void
*
args
);
void
*
args
;
};
...
...
@@ -79,8 +82,7 @@ struct rt_pin_ops
rt_err_t
(
*
pin_attach_irq
)(
struct
rt_device
*
device
,
rt_int32_t
pin
,
rt_uint32_t
mode
,
void
(
*
hdr
)(
void
*
args
),
void
*
args
);
rt_err_t
(
*
pin_dettach_irq
)(
struct
rt_device
*
device
,
rt_int32_t
pin
);
rt_err_t
(
*
pin_irq_enable
)(
struct
rt_device
*
device
,
rt_base_t
pin
);
rt_err_t
(
*
pin_irq_disable
)(
struct
rt_device
*
device
,
rt_base_t
pin
);
rt_err_t
(
*
pin_irq_enable
)(
struct
rt_device
*
device
,
rt_base_t
pin
,
rt_uint32_t
enabled
);
};
int
rt_device_pin_register
(
const
char
*
name
,
const
struct
rt_pin_ops
*
ops
,
void
*
user_data
);
...
...
@@ -91,8 +93,7 @@ int rt_pin_read(rt_base_t pin);
rt_err_t
rt_pin_attach_irq
(
rt_int32_t
pin
,
rt_uint32_t
mode
,
void
(
*
hdr
)(
void
*
args
),
void
*
args
);
rt_err_t
rt_pin_dettach_irq
(
rt_int32_t
pin
);
rt_err_t
pin_irq_enable
(
rt_base_t
pin
);
rt_err_t
pin_irq_disable
(
rt_base_t
pin
);
rt_err_t
pin_irq_enable
(
rt_base_t
pin
,
rt_uint32_t
enabled
);
int
rt_device_pin_irq_register
(
const
char
*
name
,
const
struct
rt_pin_ops
*
ops
,
void
*
user_data
);
...
...
components/drivers/misc/pin.c
浏览文件 @
aa8e5cc4
...
...
@@ -117,21 +117,12 @@ rt_err_t rt_pin_dettach_irq(rt_int32_t pin)
}
return
RT_ENOSYS
;
}
rt_err_t
pin_irq_enable
(
rt_base_t
pin
)
rt_err_t
pin_irq_enable
(
rt_base_t
pin
,
rt_uint32_t
enabled
)
{
RT_ASSERT
(
_hw_pin
.
ops
!=
RT_NULL
);
if
(
_hw_pin
.
ops
->
pin_irq_enable
)
{
return
_hw_pin
.
ops
->
pin_irq_enable
(
&
_hw_pin
.
parent
,
pin
);
}
return
RT_ENOSYS
;
}
rt_err_t
pin_irq_disable
(
rt_base_t
pin
)
{
RT_ASSERT
(
_hw_pin
.
ops
!=
RT_NULL
);
if
(
_hw_pin
.
ops
->
pin_irq_disable
)
{
return
_hw_pin
.
ops
->
pin_irq_disable
(
&
_hw_pin
.
parent
,
pin
);
return
_hw_pin
.
ops
->
pin_irq_enable
(
&
_hw_pin
.
parent
,
pin
,
enabled
);
}
return
RT_ENOSYS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录