void irsnd_init (void)
{
        // STM32
        GPIO_InitTypeDef            GPIO_InitStructure;
        TIM_TimeBaseInitTypeDef     TIM_TimeBaseStructure;
        TIM_OCInitTypeDef           TIM_OCInitStructure;

       /* GPIOx clock enable */
        RCC_AHBPeriphClockCmd(IRSND_PORT_RCC, ENABLE);
        //RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


        /* GPIO Configuration */
        GPIO_InitStructure.GPIO_Pin = IRSND_BIT;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
        GPIO_Init(IRSND_PORT, &GPIO_InitStructure);
        GPIO_PinAFConfig(IRSND_PORT, (uint8_t)IRSND_BIT_NUMBER, GPIO_AF_2);
        //SYSCFG_I2CFastModePlusConfig(SYSCFG_CFGR1_I2C_FMP_PB9, ENABLE);

        /* TIMx clock enable */
        RCC_APB2PeriphClockCmd(IRSND_TIMER, ENABLE);

        //Time base configuration
        TIM_TimeBaseStructure.TIM_Period = -1;     // set dummy value (don't set to 0), will be initialized later
        TIM_TimeBaseStructure.TIM_Prescaler = 0;
        TIM_TimeBaseStructure.TIM_ClockDivision = 0;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(IRSND_TIMER, &TIM_TimeBaseStructure);

        //PWM1 Mode configuration
        TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_Pulse = 0;         // will be initialized later
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
        TIM_OC1Init(IRSND_TIMER, &TIM_OCInitStructure);

        //Preload configuration
        TIM_ARRPreloadConfig(IRSND_TIMER, ENABLE);
        TIM_OC1PreloadConfig(IRSND_TIMER, TIM_OCPreload_Enable);

        irsnd_set_freq (IRSND_FREQ_36_KHZ);                                         // set default frequency
}

