|
@@ -165,7 +165,41 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc)
|
165
|
165
|
/****************************************************************************
|
166
|
166
|
* PWM INPUT
|
167
|
167
|
***************************************************************************/
|
|
168
|
+void PWMi_conf(TIM_TypeDef * TIMx, uint32_t channels){
|
|
169
|
+ //Periode à recuperer dans TIMx_CCR1, duty cycle dans TIMx_CCR2
|
|
170
|
+ // Validation horloge locale
|
|
171
|
+ if (TIMx == TIM1) LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
|
172
|
+ else if (TIMx == TIM2) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
|
173
|
+ else if (TIMx == TIM3) LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
|
|
174
|
+ else LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
|
|
175
|
+
|
|
176
|
+ //LL_TIM_CC_EnableChannel(TIMx, channels);
|
|
177
|
+ //LL_TIM_IC_Init
|
|
178
|
+ TIMx -> CCMR1 |= TIM_CCMR1_CC1S_0; //01
|
|
179
|
+ //TIM_CCMR1_IC1F_0; Potentiellement utile, à voir plus tard
|
|
180
|
+ TIMx -> CCER &= ~(TIM_CCER_CC1P); //0 = Rising edge
|
|
181
|
+ TIMx -> CCMR1 &= ~(TIM_CCMR1_IC1PSC);
|
|
182
|
+
|
|
183
|
+ TIMx -> CCMR1 |= TIM_CCMR1_CC2S_1;
|
|
184
|
+ TIMx -> CCER |= TIM_CCER_CC2P;
|
|
185
|
+ TIMx -> SMCR |= TIM_SMCR_TS_0 | TIM_SMCR_TS_2; //101
|
|
186
|
+ TIMx -> SMCR |= TIM_SMCR_SMS_2; //100
|
|
187
|
+
|
|
188
|
+ TIMx -> CCER |= TIM_CCER_CC1E;
|
|
189
|
+ TIMx -> CCER |= TIM_CCER_CC2E;
|
|
190
|
+ TIMx -> DIER |= TIM_DIER_CC1IE;
|
|
191
|
+ //TIM_DIER_CC1DE_Pos; Probablement pas utile
|
|
192
|
+}
|
168
|
193
|
|
|
194
|
+int get_input_period(TIM_TypeDef * TIMx) {
|
|
195
|
+
|
|
196
|
+ return TIMx -> CCR1;
|
|
197
|
+}
|
|
198
|
+
|
|
199
|
+int get_input_duty_cycle(TIM_TypeDef * TIMx) {
|
|
200
|
+
|
|
201
|
+ return TIMx -> CCR2;
|
|
202
|
+}
|
169
|
203
|
|
170
|
204
|
/****************************************************************************
|
171
|
205
|
* PWM OUTPUT
|