Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
257f147a
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看板
提交
257f147a
编写于
7月 24, 2018
作者:
lymzzyh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Bsp][stm32f4xx-hal][pwm]format code
上级
e1838418
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
66 addition
and
27 deletion
+66
-27
bsp/stm32f4xx-HAL/drivers/drv_pwm.c
bsp/stm32f4xx-HAL/drivers/drv_pwm.c
+66
-27
未找到文件。
bsp/stm32f4xx-HAL/drivers/drv_pwm.c
浏览文件 @
257f147a
...
...
@@ -25,14 +25,17 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#define MAX_PERIOD 65535
#define MIN_PERIOD 3
#define MIN_PULSE 2
static
rt_err_t
drv_pwm_control
(
struct
rt_device_pwm
*
device
,
int
cmd
,
void
*
arg
);
static
struct
rt_pwm_ops
drv_ops
=
{
.
control
=
drv_pwm_control
drv_pwm_control
};
static
rt_err_t
drv_pwm_enable
(
TIM_HandleTypeDef
*
htim
,
struct
rt_pwm_configuration
*
configuration
,
rt_bool_t
enable
)
{
rt_uint32_t
channel
=
0x04
*
configuration
->
channel
;
...
...
@@ -43,11 +46,12 @@ static rt_err_t drv_pwm_enable(TIM_HandleTypeDef * htim, struct rt_pwm_configura
HAL_TIM_PWM_Start
(
htim
,
channel
);
return
RT_EOK
;
}
static
rt_err_t
drv_pwm_get
(
TIM_HandleTypeDef
*
htim
,
struct
rt_pwm_configuration
*
configuration
)
{
rt_uint32_t
channel
=
0x04
*
configuration
->
channel
;
rt_uint32_t
tim_clock
;
#if (RT_HSE_HCLK > 100000000UL)//100M
#if (RT_HSE_HCLK > 100000000UL)//100M
if
(
htim
->
Instance
==
TIM1
&&
htim
->
Instance
==
TIM8
)
{
tim_clock
=
SystemCoreClock
;
...
...
@@ -72,6 +76,7 @@ static rt_err_t drv_pwm_get(TIM_HandleTypeDef * htim, struct rt_pwm_configuratio
configuration
->
pulse
=
(
__HAL_TIM_GET_COMPARE
(
htim
,
channel
)
+
1
)
*
(
htim
->
Instance
->
PSC
+
1
)
*
1000UL
/
tim_clock
;
return
RT_EOK
;
}
static
rt_err_t
drv_pwm_set
(
TIM_HandleTypeDef
*
htim
,
struct
rt_pwm_configuration
*
configuration
)
{
rt_uint32_t
period
,
pulse
;
...
...
@@ -111,6 +116,7 @@ static rt_err_t drv_pwm_set(TIM_HandleTypeDef * htim, struct rt_pwm_configuratio
__HAL_TIM_SET_COMPARE
(
htim
,
channel
,
pulse
-
1
);
return
RT_EOK
;
}
static
rt_err_t
drv_pwm_control
(
struct
rt_device_pwm
*
device
,
int
cmd
,
void
*
arg
)
{
struct
rt_pwm_configuration
*
configuration
=
(
struct
rt_pwm_configuration
*
)
arg
;
...
...
@@ -130,7 +136,9 @@ static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg
return
RT_EINVAL
;
}
}
static
void
HAL_TIM_MspPostInit
(
TIM_HandleTypeDef
*
timHandle
);
#ifdef BSP_USING_PWM1
TIM_HandleTypeDef
htim1
;
#endif
...
...
@@ -179,30 +187,35 @@ static void MX_TIM1_Init(void)
sConfigOC
.
OCFastMode
=
TIM_OCFAST_DISABLE
;
sConfigOC
.
OCIdleState
=
TIM_OCIDLESTATE_RESET
;
sConfigOC
.
OCNIdleState
=
TIM_OCNIDLESTATE_RESET
;
#ifdef BSP_USING_PWM1_CH1
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim1
,
&
sConfigOC
,
TIM_CHANNEL_1
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM1_CH1 */
#ifdef BSP_USING_PWM1_CH2
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim1
,
&
sConfigOC
,
TIM_CHANNEL_2
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM1_CH2 */
#ifdef BSP_USING_PWM1_CH3
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim1
,
&
sConfigOC
,
TIM_CHANNEL_3
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM1_CH3 */
#ifdef BSP_USING_PWM1_CH4
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim1
,
&
sConfigOC
,
TIM_CHANNEL_4
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM1_CH4 */
sBreakDeadTimeConfig
.
OffStateRunMode
=
TIM_OSSR_DISABLE
;
sBreakDeadTimeConfig
.
OffStateIDLEMode
=
TIM_OSSI_DISABLE
;
sBreakDeadTimeConfig
.
LockLevel
=
TIM_LOCKLEVEL_OFF
;
...
...
@@ -210,13 +223,14 @@ static void MX_TIM1_Init(void)
sBreakDeadTimeConfig
.
BreakState
=
TIM_BREAK_DISABLE
;
sBreakDeadTimeConfig
.
BreakPolarity
=
TIM_BREAKPOLARITY_HIGH
;
sBreakDeadTimeConfig
.
AutomaticOutput
=
TIM_AUTOMATICOUTPUT_DISABLE
;
if
(
HAL_TIMEx_ConfigBreakDeadTime
(
&
htim1
,
&
sBreakDeadTimeConfig
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
HAL_TIM_MspPostInit
(
&
htim1
);
}
#endif
#endif
/* BSP_USING_PWM1 */
#ifdef BSP_USING_PWM2
static
void
MX_TIM2_Init
(
void
)
...
...
@@ -245,33 +259,39 @@ static void MX_TIM2_Init(void)
sConfigOC
.
Pulse
=
0
;
sConfigOC
.
OCPolarity
=
TIM_OCPOLARITY_HIGH
;
sConfigOC
.
OCFastMode
=
TIM_OCFAST_DISABLE
;
#ifdef BSP_USING_PWM2_CH1
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim2
,
&
sConfigOC
,
TIM_CHANNEL_1
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM2_CH1 */
#ifdef BSP_USING_PWM2_CH2
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim2
,
&
sConfigOC
,
TIM_CHANNEL_2
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM2_CH2 */
#ifdef BSP_USING_PWM2_CH3
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim2
,
&
sConfigOC
,
TIM_CHANNEL_3
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM2_CH3 */
#ifdef BSP_USING_PWM2_CH4
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim2
,
&
sConfigOC
,
TIM_CHANNEL_4
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM2_CH3 */
HAL_TIM_MspPostInit
(
&
htim2
);
}
#endif
#endif
/* BSP_USING_PWM2 */
#ifdef BSP_USING_PWM3
void
MX_TIM3_Init
(
void
)
{
...
...
@@ -304,28 +324,33 @@ void MX_TIM3_Init(void)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM3_CH1 */
#ifdef BSP_USING_PWM3_CH2
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim3
,
&
sConfigOC
,
TIM_CHANNEL_2
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM3_CH2 */
#ifdef BSP_USING_PWM3_CH3
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim3
,
&
sConfigOC
,
TIM_CHANNEL_3
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM3_CH3 */
#ifdef BSP_USING_PWM3_CH4
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim3
,
&
sConfigOC
,
TIM_CHANNEL_4
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM3_CH4 */
HAL_TIM_MspPostInit
(
&
htim3
);
}
#endif
#endif
/* BSP_USING_PWM3 */
#ifdef BSP_USING_PWM4
void
MX_TIM4_Init
(
void
)
{
...
...
@@ -358,28 +383,33 @@ void MX_TIM4_Init(void)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM4_CH1 */
#ifdef BSP_USING_PWM4_CH2
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim4
,
&
sConfigOC
,
TIM_CHANNEL_2
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM4_CH2 */
#ifdef BSP_USING_PWM4_CH3
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim4
,
&
sConfigOC
,
TIM_CHANNEL_3
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM4_CH3 */
#ifdef BSP_USING_PWM4_CH4
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim4
,
&
sConfigOC
,
TIM_CHANNEL_4
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM4_CH4 */
HAL_TIM_MspPostInit
(
&
htim4
);
}
#endif
#endif
/* BSP_USING_PWM4 */
#ifdef BSP_USING_PWM5
void
MX_TIM5_Init
(
void
)
{
...
...
@@ -412,22 +442,26 @@ void MX_TIM5_Init(void)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM5_CH1 */
#ifdef BSP_USING_PWM5_CH2
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim5
,
&
sConfigOC
,
TIM_CHANNEL_2
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM5_CH2 */
#ifdef BSP_USING_PWM5_CH3
if
(
HAL_TIM_PWM_ConfigChannel
(
&
htim5
,
&
sConfigOC
,
TIM_CHANNEL_3
)
!=
HAL_OK
)
{
RT_ASSERT
(
0
);
}
#endif
#endif
/* BSP_USING_PWM5_CH3 */
HAL_TIM_MspPostInit
(
&
htim5
);
}
#endif
#endif
/* BSP_USING_PWM5 */
void
HAL_TIM_PWM_MspInit
(
TIM_HandleTypeDef
*
tim_pwmHandle
)
{
if
(
tim_pwmHandle
->
Instance
==
TIM1
)
...
...
@@ -451,7 +485,8 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle)
__HAL_RCC_TIM5_CLK_ENABLE
();
}
}
void
HAL_TIM_MspPostInit
(
TIM_HandleTypeDef
*
timHandle
)
static
void
HAL_TIM_MspPostInit
(
TIM_HandleTypeDef
*
timHandle
)
{
GPIO_InitTypeDef
GPIO_InitStruct
;
if
(
timHandle
->
Instance
==
TIM1
)
...
...
@@ -581,18 +616,22 @@ int drv_pwm_init(void)
MX_TIM1_Init
();
rt_device_pwm_register
(
rt_calloc
(
1
,
sizeof
(
struct
rt_device_pwm
)),
"pwm1"
,
&
drv_ops
,
&
htim1
);
#endif
#ifdef BSP_USING_PWM2
MX_TIM2_Init
();
rt_device_pwm_register
(
rt_calloc
(
1
,
sizeof
(
struct
rt_device_pwm
)),
"pwm2"
,
&
drv_ops
,
&
htim2
);
#endif
#ifdef BSP_USING_PWM3
MX_TIM3_Init
();
rt_device_pwm_register
(
rt_calloc
(
1
,
sizeof
(
struct
rt_device_pwm
)),
"pwm3"
,
&
drv_ops
,
&
htim3
);
#endif
#ifdef BSP_USING_PWM4
MX_TIM4_Init
();
rt_device_pwm_register
(
rt_calloc
(
1
,
sizeof
(
struct
rt_device_pwm
)),
"pwm4"
,
&
drv_ops
,
&
htim4
);
#endif
#ifdef BSP_USING_PWM5
MX_TIM5_Init
();
rt_device_pwm_register
(
rt_calloc
(
1
,
sizeof
(
struct
rt_device_pwm
)),
"pwm5"
,
&
drv_ops
,
&
htim5
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录