void BSP_LED_Configure(void);
void BSP_KEY_Configure(void);
void led2on()
{
TIM_SelectOCxM (TIM2, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd (TIM2, TIM_Channel_2, TIM_CCx_Enable);
}
void led2off()
{
TIM_SelectOCxM (TIM2, TIM_Channel_2, TIM_OCMode_Inactive);
TIM_CCxCmd (TIM2, TIM_Channel_2, TIM_CCx_Enable);
}
void led3on()
{
TIM_SelectOCxM (TIM3, TIM_Channel_1, TIM_OCMode_PWM1);
TIM_CCxCmd (TIM3, TIM_Channel_1, TIM_CCx_Enable);
}
void led3off()
{
TIM_SelectOCxM (TIM3, TIM_Channel_1, TIM_OCMode_Inactive);
TIM_CCxCmd (TIM3, TIM_Channel_1, TIM_CCx_Enable);
}
void led4on()
{
TIM_SelectOCxM (TIM3, TIM_Channel_2, TIM_OCMode_PWM1);
TIM_CCxCmd (TIM3, TIM_Channel_2, TIM_CCx_Enable);
}
void led4off()
{
TIM_SelectOCxM (TIM3, TIM_Channel_2, TIM_OCMode_Inactive);
TIM_CCxCmd (TIM3, TIM_Channel_2, TIM_CCx_Enable);
}
void closeLED()
{
LD6_off();
led2off();
led3off();
led4off();
}
void initLEDPWM(u16 psc, u16 arr)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructInit;
COMMON_EnableIpClock(emCLOCK_GPIOB);
COMMON_EnableIpClock(emCLOCK_TIM2);
COMMON_EnableIpClock(emCLOCK_TIM3);
GPIO_Mode_AF_PP_20MHz_Init(GPIOB, GPIO_Pin_3, EXTI_MAPR_TIM2_PARTIAL1, GPIO_AF_2);
GPIO_Mode_AF_PP_20MHz_Init(GPIOB, GPIO_Pin_4, EXTI_MAPR_TIM3_PARTIAL, GPIO_AF_1);
GPIO_Mode_AF_PP_20MHz_Init(GPIOB, GPIO_Pin_5, EXTI_MAPR_TIM3_PARTIAL, GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler = psc;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_OCStructInit(&TIM_OCInitStructInit);
TIM_OCInitStructInit.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructInit.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructInit.TIM_Pulse = arr >> 1;
TIM_OCInitStructInit.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC2Init(TIM2, &TIM_OCInitStructInit);
TIM_OC1Init(TIM3, &TIM_OCInitStructInit);
TIM_OC2Init(TIM3, &TIM_OCInitStructInit);
TIM_Cmd(TIM2, ENABLE);
TIM_Cmd(TIM3, ENABLE);
}