/* Initializes the tim Channel2 according to the specified parameters in the init_struct.  */
void TIM_OC2Init(TIM_TypeDef *tim, TIM_OCInitTypeDef *init_struct)
/* Initializes the tim Channel2 according to the specified parameters in the init_struct.  */
void TIM_OC2Init(TIM_TypeDef *tim, TIM_OCInitTypeDef *init_struct)
{
    MODIFY_REG(tim->CCMR1, TIM_CCMR1_OC2M, init_struct->TIM_OCMode << 8);
    MODIFY_REG(tim->CCER, TIM_CCER_CC2EN | TIM_CCER_CC2P, \
               (init_struct->TIM_OCPolarity << 4) | (init_struct->TIM_OutputState << 4));
    WRITE_REG(tim->CCR2, init_struct->TIM_Pulse);
    if ((tim == TIM1) || (tim == TIM8)) {
        MODIFY_REG(tim->CCER, TIM_CCER_CC2NP | TIM_CCER_CC2NEN, \
                   (init_struct->TIM_OCNPolarity << 4) | (init_struct->TIM_OutputNState << 4));
        MODIFY_REG(tim->CR2, TIM_CR2_OIS2 | TIM_CR2_OIS2N, \
                   (init_struct->TIM_OCIdleState << 2) | (init_struct->TIM_OCNIdleState << 2));
    }
}