提交 7c455e67 编写于 作者: T tangweikang

[bsp][stm32][driver] drv_pulse_encoder.c

上级 3ada5c81
......@@ -87,11 +87,11 @@ rt_err_t pulse_encoder_init(struct rt_pulse_encoder_device *pulse_encoder)
sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
sConfig.IC1Prescaler = TIM_ICPSC_DIV4;
sConfig.IC1Filter = 3;
sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
sConfig.IC2Prescaler = TIM_ICPSC_DIV4;
sConfig.IC2Filter = 3;
if (HAL_TIM_Encoder_Init(tim_handler, &sConfig) != HAL_OK)
......@@ -112,6 +112,13 @@ rt_err_t pulse_encoder_init(struct rt_pulse_encoder_device *pulse_encoder)
return RT_EOK;
}
rt_err_t pulse_encoder_clear_count(struct rt_pulse_encoder_device *pulse_encoder)
{
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)pulse_encoder->parent.user_data;
__HAL_TIM_SET_COUNTER(tim_handler, 0);
return RT_EOK;
}
rt_int32_t pulse_encoder_get_count(struct rt_pulse_encoder_device *pulse_encoder)
{
TIM_HandleTypeDef *tim_handler = (TIM_HandleTypeDef *)pulse_encoder->parent.user_data;
......@@ -133,9 +140,6 @@ rt_err_t pulse_encoder_control(struct rt_pulse_encoder_device *pulse_encoder, rt
case PULSE_ENCODER_CMD_DISABLE:
HAL_TIM_Encoder_Stop(tim_handler, TIM_CHANNEL_ALL);
break;
case PULSE_ENCODER_CMD_CLEAR_COUNT:
__HAL_TIM_SET_COUNTER(tim_handler, 0);
break;
default:
result = -RT_ENOSYS;
break;
......@@ -148,6 +152,7 @@ static const struct rt_pulse_encoder_ops _ops =
{
.init = pulse_encoder_init,
.get_count = pulse_encoder_get_count,
.clear_count = pulse_encoder_clear_count,
.control = pulse_encoder_control,
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册