|
@@ -87,17 +87,18 @@ void SystemClock_Config(void)
|
|
|
static void GPIO_Init(void)
|
|
|
{
|
|
|
/* Servo_1_Pin, Servo_2_Pin - Servos control, Alt PP out, middle speed */
|
|
|
- GPIO_SetAFPin_8_15(Servo_1_Port, Servo_1_Pin, GPIO_AF_2);
|
|
|
+ GPIO_SetAFPin_0_7(Servo_1_Port, Servo_1_Pin, GPIO_AF_1);
|
|
|
GPIO_SetPinOutputType(Servo_1_Port, Servo_1_Pin, GPIO_OTYPE_PP);
|
|
|
GPIO_SetPinPull(Servo_1_Port, Servo_1_Pin, GPIO_PUPDR_NO);
|
|
|
GPIO_SetPinSpeed(Servo_1_Port, Servo_1_Pin, GPIO_OSPEED_LW);
|
|
|
GPIO_SetPinMode(Servo_1_Port, Servo_1_Pin, GPIO_MODE_AFF);
|
|
|
-
|
|
|
- GPIO_SetAFPin_0_7(Servo_2_Port, Servo_2_Pin, GPIO_AF_1);
|
|
|
+#ifdef USE_SERVO_2
|
|
|
+ GPIO_SetAFPin_8_15(Servo_2_Port, Servo_2_Pin, GPIO_AF_2);
|
|
|
GPIO_SetPinOutputType(Servo_2_Port, Servo_2_Pin, GPIO_OTYPE_PP);
|
|
|
GPIO_SetPinPull(Servo_2_Port, Servo_2_Pin, GPIO_PUPDR_NO);
|
|
|
GPIO_SetPinSpeed(Servo_2_Port, Servo_2_Pin, GPIO_OSPEED_LW);
|
|
|
GPIO_SetPinMode(Servo_2_Port, Servo_2_Pin, GPIO_MODE_AFF);
|
|
|
+#endif
|
|
|
|
|
|
/* Photo_Pin: analog in, pull none */
|
|
|
GPIO_SetPinPull(Photo_Port, Photo_Pin, GPIO_PUPDR_NO);
|
|
@@ -173,13 +174,18 @@ static void TIM1_Init(void)
|
|
|
TIM1->CCR2 = SERVO_INIT_VAL;
|
|
|
TIM1->CCR4 = SERVO_INIT_VAL;
|
|
|
// pwm mode 1 for chanels
|
|
|
- TIM1->CCMR1 = (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1PE);
|
|
|
- TIM1->CCMR1 |= (TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2PE);
|
|
|
+ TIM1->CCMR1 = (TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 | TIM_CCMR1_OC2PE);
|
|
|
+#ifdef USE_SERVO_2
|
|
|
+ TIM1->CCMR1 |= (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1PE);
|
|
|
+#endif
|
|
|
//TIM1->SR |= TIM_SR_UIF;
|
|
|
TIM1->BDTR = TIM_BDTR_MOE; // enable main output
|
|
|
TIM1->EGR = TIM_EGR_UG; // force timer update
|
|
|
/* TIM1 CC_EnableChannel */
|
|
|
- TIM1->CCER = (TIM_CCER_CC1E | TIM_CCER_CC1P | TIM_CCER_CC2E | TIM_CCER_CC2P);
|
|
|
+ TIM1->CCER = (TIM_CCER_CC2E | TIM_CCER_CC2P);
|
|
|
+#ifdef USE_SERVO_2
|
|
|
+ TIM1->CCER |= (TIM_CCER_CC1E | TIM_CCER_CC1P);
|
|
|
+#endif
|
|
|
/* Set the trigger output 2 (TRGO2) used for ADC synchronization */
|
|
|
TIM1->CR2 |= TIM_CR2_MMS2_1; // update event
|
|
|
/* TIM_EnableCounter */
|