@@ -78,11 +78,23 @@ static int qdec_stm32_get(const struct device *dev, enum sensor_channel chan,
78
78
return 0 ;
79
79
}
80
80
81
+ static void qdec_stm32_initialize_channel (const struct device * dev , uint32_t ll_channel )
82
+ {
83
+ const struct qdec_stm32_dev_cfg * const dev_cfg = dev -> config ;
84
+
85
+ LL_TIM_IC_SetActiveInput (dev_cfg -> timer_inst , ll_channel , LL_TIM_ACTIVEINPUT_DIRECTTI );
86
+ LL_TIM_IC_SetFilter (dev_cfg -> timer_inst , ll_channel ,
87
+ dev_cfg -> input_filtering_level * LL_TIM_IC_FILTER_FDIV1_N2 );
88
+ LL_TIM_IC_SetPrescaler (dev_cfg -> timer_inst , ll_channel , LL_TIM_ICPSC_DIV1 );
89
+ LL_TIM_IC_SetPolarity (dev_cfg -> timer_inst , ll_channel ,
90
+ dev_cfg -> is_input_polarity_inverted ? LL_TIM_IC_POLARITY_FALLING :
91
+ LL_TIM_IC_POLARITY_RISING );
92
+ }
93
+
81
94
static int qdec_stm32_initialize (const struct device * dev )
82
95
{
83
96
const struct qdec_stm32_dev_cfg * const dev_cfg = dev -> config ;
84
97
int retval ;
85
- LL_TIM_ENCODER_InitTypeDef init_props ;
86
98
uint32_t max_counter_value ;
87
99
88
100
retval = pinctrl_apply_state (dev_cfg -> pin_config , PINCTRL_STATE_DEFAULT );
@@ -108,18 +120,6 @@ static int qdec_stm32_initialize(const struct device *dev)
108
120
return - EINVAL ;
109
121
}
110
122
111
- LL_TIM_ENCODER_StructInit (& init_props );
112
-
113
- init_props .EncoderMode = dev_cfg -> encoder_mode ;
114
-
115
- if (dev_cfg -> is_input_polarity_inverted ) {
116
- init_props .IC1Polarity = LL_TIM_IC_POLARITY_FALLING ;
117
- init_props .IC2Polarity = LL_TIM_IC_POLARITY_FALLING ;
118
- }
119
-
120
- init_props .IC1Filter = dev_cfg -> input_filtering_level * LL_TIM_IC_FILTER_FDIV1_N2 ;
121
- init_props .IC2Filter = dev_cfg -> input_filtering_level * LL_TIM_IC_FILTER_FDIV1_N2 ;
122
-
123
123
/* Ensure that the counter will always count up to a multiple of counts_per_revolution */
124
124
if (IS_TIM_32B_COUNTER_INSTANCE (dev_cfg -> timer_inst )) {
125
125
max_counter_value = UINT32_MAX - (UINT32_MAX % dev_cfg -> counts_per_revolution ) - 1 ;
@@ -128,10 +128,12 @@ static int qdec_stm32_initialize(const struct device *dev)
128
128
}
129
129
LL_TIM_SetAutoReload (dev_cfg -> timer_inst , max_counter_value );
130
130
131
- if (LL_TIM_ENCODER_Init (dev_cfg -> timer_inst , & init_props ) != SUCCESS ) {
132
- LOG_ERR ("Initalization failed" );
133
- return - EIO ;
134
- }
131
+ LL_TIM_SetClockSource (dev_cfg -> timer_inst , dev_cfg -> encoder_mode );
132
+
133
+ qdec_stm32_initialize_channel (dev , LL_TIM_CHANNEL_CH1 );
134
+ qdec_stm32_initialize_channel (dev , LL_TIM_CHANNEL_CH2 );
135
+
136
+ LL_TIM_CC_EnableChannel (dev_cfg -> timer_inst , LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2 );
135
137
136
138
LL_TIM_EnableCounter (dev_cfg -> timer_inst );
137
139
0 commit comments