Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
1d4139ab
R
rt-thread
项目概览
AdRainty
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1d4139ab
编写于
8月 23, 2019
作者:
T
tangweikang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[bsp][stm32] add drv_encoder.c
上级
200f3d44
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
247 addition
and
1 deletion
+247
-1
bsp/stm32/libraries/HAL_Drivers/config/f4/encoder_config.h
bsp/stm32/libraries/HAL_Drivers/config/f4/encoder_config.h
+64
-0
bsp/stm32/libraries/HAL_Drivers/drv_config.h
bsp/stm32/libraries/HAL_Drivers/drv_config.h
+1
-0
bsp/stm32/libraries/HAL_Drivers/drv_encoder.c
bsp/stm32/libraries/HAL_Drivers/drv_encoder.c
+181
-0
bsp/stm32/libraries/STM32F4xx_HAL/SConscript
bsp/stm32/libraries/STM32F4xx_HAL/SConscript
+1
-1
未找到文件。
bsp/stm32/libraries/HAL_Drivers/config/f4/encoder_config.h
0 → 100644
浏览文件 @
1d4139ab
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-23 balanceTWK first version
*/
#ifndef __ENCODER_CONFIG_H__
#define __ENCODER_CONFIG_H__
#include <rtthread.h>
#ifdef __cplusplus
extern
"C"
{
#endif
#ifdef BSP_USING_ENCODER1
#ifndef ENCODER1_CONFIG
#define ENCODER1_CONFIG \
{ \
.tim_handler.Instance = TIM1, \
.name = "encoder1" \
}
#endif
/* ENCODER1_CONFIG */
#endif
/* BSP_USING_ENCODER1 */
#ifdef BSP_USING_ENCODER2
#ifndef ENCODER2_CONFIG
#define ENCODER2_CONFIG \
{ \
.tim_handler.Instance = TIM2, \
.name = "encoder2" \
}
#endif
/* ENCODER2_CONFIG */
#endif
/* BSP_USING_ENCODER2 */
#ifdef BSP_USING_ENCODER3
#ifndef ENCODER3_CONFIG
#define ENCODER3_CONFIG \
{ \
.tim_handler.Instance = TIM3, \
.name = "encoder3" \
}
#endif
/* ENCODER3_CONFIG */
#endif
/* BSP_USING_ENCODER3 */
#ifdef BSP_USING_ENCODER4
#ifndef ENCODER4_CONFIG
#define ENCODER4_CONFIG \
{ \
.tim_handler.Instance = TIM4, \
.name = "encoder4" \
}
#endif
/* ENCODER4_CONFIG */
#endif
/* BSP_USING_ENCODER4 */
#ifdef __cplusplus
}
#endif
#endif
/* __ENCODER_CONFIG_H__ */
bsp/stm32/libraries/HAL_Drivers/drv_config.h
浏览文件 @
1d4139ab
...
...
@@ -52,6 +52,7 @@ extern "C" {
#include "f4/tim_config.h"
#include "f4/sdio_config.h"
#include "f4/pwm_config.h"
#include "f4/encoder_config.h"
#elif defined(SOC_SERIES_STM32F7)
#include "f7/dma_config.h"
#include "f7/uart_config.h"
...
...
bsp/stm32/libraries/HAL_Drivers/drv_encoder.c
0 → 100644
浏览文件 @
1d4139ab
/*
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-08-09 15:25:34
* @LastEditTime: 2019-08-09 17:29:27
* @LastEditors: Please set LastEditors
*/
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-08-23 balanceTWK first version
*/
#include "board.h"
#include "drv_config.h"
#ifdef RT_USING_ENCODER
//#define DRV_DEBUG
#define LOG_TAG "drv.encoder"
#include <drv_log.h>
#if !defined(BSP_USING_ENCODER1) && !defined(BSP_USING_ENCODER2) && !defined(BSP_USING_ENCODER3) \
&& !defined(BSP_USING_ENCODER4) && !defined(BSP_USING_ENCODER5) && !defined(BSP_USING_ENCODER6) && !defined(BSP_USING_LPENCODER1)
#error "Please define at least one BSP_USING_ENCODERx"
/* this driver can be disabled at menuconfig → RT-Thread Components → Device Drivers */
#endif
enum
{
#ifdef BSP_USING_ENCODER1
ENCODER1_INDEX
,
#endif
#ifdef BSP_USING_ENCODER2
ENCODER2_INDEX
,
#endif
#ifdef BSP_USING_ENCODER3
ENCODER3_INDEX
,
#endif
#ifdef BSP_USING_ENCODER4
ENCODER4_INDEX
,
#endif
#ifdef BSP_USING_ENCODER5
ENCODER5_INDEX
,
#endif
#ifdef BSP_USING_ENCODER6
ENCODER6_INDEX
,
#endif
};
struct
stm32_encoder_device
{
struct
rt_encoder_device
encoder
;
TIM_HandleTypeDef
tim_handler
;
char
*
name
;
};
static
struct
stm32_encoder_device
stm32_encoder_obj
[]
=
{
#ifdef BSP_USING_ENCODER1
ENCODER1_CONFIG
,
#endif
#ifdef BSP_USING_ENCODER2
ENCODER2_CONFIG
,
#endif
#ifdef BSP_USING_ENCODER3
ENCODER3_CONFIG
,
#endif
#ifdef BSP_USING_ENCODER4
ENCODER4_CONFIG
,
#endif
#ifdef BSP_USING_ENCODER5
ENCODER5_CONFIG
,
#endif
#ifdef BSP_USING_ENCODER6
ENCODER6_CONFIG
,
#endif
};
rt_err_t
encoder_init
(
struct
rt_encoder_device
*
encoder
)
{
TIM_Encoder_InitTypeDef
sConfig
;
TIM_MasterConfigTypeDef
sMasterConfig
;
TIM_HandleTypeDef
*
tim_handler
=
(
TIM_HandleTypeDef
*
)
encoder
->
parent
.
user_data
;
tim_handler
->
Init
.
Prescaler
=
0
;
tim_handler
->
Init
.
CounterMode
=
TIM_COUNTERMODE_UP
;
tim_handler
->
Init
.
Period
=
0xffff
;
tim_handler
->
Init
.
ClockDivision
=
TIM_CLOCKDIVISION_DIV1
;
sConfig
.
EncoderMode
=
TIM_ENCODERMODE_TI12
;
sConfig
.
IC1Polarity
=
TIM_ICPOLARITY_RISING
;
sConfig
.
IC1Selection
=
TIM_ICSELECTION_DIRECTTI
;
sConfig
.
IC1Prescaler
=
TIM_ICPSC_DIV1
;
sConfig
.
IC1Filter
=
3
;
sConfig
.
IC2Polarity
=
TIM_ICPOLARITY_RISING
;
sConfig
.
IC2Selection
=
TIM_ICSELECTION_DIRECTTI
;
sConfig
.
IC2Prescaler
=
TIM_ICPSC_DIV1
;
sConfig
.
IC2Filter
=
3
;
if
(
HAL_TIM_Encoder_Init
(
tim_handler
,
&
sConfig
)
!=
HAL_OK
)
{
return
-
RT_ERROR
;
}
sMasterConfig
.
MasterOutputTrigger
=
TIM_TRGO_RESET
;
sMasterConfig
.
MasterSlaveMode
=
TIM_MASTERSLAVEMODE_DISABLE
;
if
(
HAL_TIMEx_MasterConfigSynchronization
(
tim_handler
,
&
sMasterConfig
))
{
return
-
RT_ERROR
;
}
return
RT_EOK
;
}
rt_int32_t
encoder_get_count
(
struct
rt_encoder_device
*
encoder
)
{
TIM_HandleTypeDef
*
tim_handler
=
(
TIM_HandleTypeDef
*
)
encoder
->
parent
.
user_data
;
return
(
rt_int16_t
)
__HAL_TIM_GET_COUNTER
(
tim_handler
);
}
rt_err_t
encoder_control
(
struct
rt_encoder_device
*
encoder
,
rt_uint32_t
cmd
,
void
*
args
)
{
rt_err_t
result
;
TIM_HandleTypeDef
*
tim_handler
=
(
TIM_HandleTypeDef
*
)
encoder
->
parent
.
user_data
;
result
=
RT_EOK
;
switch
(
cmd
)
{
case
ENCODER_CMD_ENABLE
:
HAL_TIM_Encoder_Start
(
tim_handler
,
TIM_CHANNEL_ALL
);
break
;
case
ENCODER_CMD_DISABLE
:
HAL_TIM_Encoder_Stop
(
tim_handler
,
TIM_CHANNEL_ALL
);
break
;
case
ENCODER_CMD_CLEAR_COUNT
:
__HAL_TIM_SET_COUNTER
(
tim_handler
,
0
);
break
;
default:
result
=
-
RT_ENOSYS
;
break
;
}
return
result
;
}
static
const
struct
rt_encoder_ops
_ops
=
{
.
init
=
encoder_init
,
.
get_count
=
encoder_get_count
,
.
control
=
encoder_control
,
};
int
hw_encoder_init
(
void
)
{
int
i
;
int
result
;
result
=
RT_EOK
;
for
(
i
=
0
;
i
<
sizeof
(
stm32_encoder_obj
)
/
sizeof
(
stm32_encoder_obj
[
0
]);
i
++
)
{
stm32_encoder_obj
[
i
].
encoder
.
type
=
AB_PHASE_ENCODER
;
stm32_encoder_obj
[
i
].
encoder
.
ops
=
&
_ops
;
if
(
rt_device_encoder_register
(
&
stm32_encoder_obj
[
i
].
encoder
,
stm32_encoder_obj
[
i
].
name
,
&
stm32_encoder_obj
[
i
].
tim_handler
)
!=
RT_EOK
)
{
LOG_E
(
"%s register failed"
,
stm32_encoder_obj
[
i
].
name
);
result
=
-
RT_ERROR
;
}
}
return
result
;
}
INIT_BOARD_EXPORT
(
hw_encoder_init
);
#endif
bsp/stm32/libraries/STM32F4xx_HAL/SConscript
浏览文件 @
1d4139ab
...
...
@@ -46,7 +46,7 @@ if GetDepend(['RT_USING_USB_HOST']) or GetDepend(['RT_USING_USB_DEVICE']):
if
GetDepend
([
'RT_USING_CAN'
]):
src
+=
[
'STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.c'
]
if
GetDepend
([
'RT_USING_HWTIMER'
])
or
GetDepend
([
'RT_USING_PWM'
]):
if
GetDepend
([
'RT_USING_HWTIMER'
])
or
GetDepend
([
'RT_USING_PWM'
])
or
GetDepend
([
'RT_USING_ENCODER'
])
:
src
+=
[
'STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c'
]
src
+=
[
'STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.c'
]
src
+=
[
'STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_lptim.c'
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录