text: /**
    ******************************************************************************
    * File Name          : TIM.c
    * Description        : This file provides code for the configuration
    *                      of the TIM instances.
    ******************************************************************************
    ** This notice applies to any and all portions of this file
    * that are not between comment pairs USER CODE BEGIN and
    * USER CODE END. Other portions of this file, whether
    * inserted by the user or by software development tools
    * are owned by their respective copyright owners.
    *
    * COPYRIGHT(c) 2020 STMicroelectronics
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    *   1. Redistributions of source code must retain the above copyright notice,
    *      this list of conditions and the following disclaimer.
    *   2. Redistributions in binary form must reproduce the above copyright notice,
    *      this list of conditions and the following disclaimer in the documentation
    *      and/or other materials provided with the distribution.
    *   3. Neither the name of STMicroelectronics nor the names of its contributors
    *      may be used to endorse or promote products derived from this software
    *      without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    ******************************************************************************
    */
  
  /* Includes ------------------------------------------------------------------*/
  #include "tim.h"
  
  #include "gpio.h"
  
  /* USER CODE BEGIN 0 */
  
  /* USER CODE END 0 */
  
  TIM_HandleTypeDef htim1;
  TIM_HandleTypeDef htim3;
  TIM_HandleTypeDef htim14;
  TIM_HandleTypeDef htim15;
  TIM_HandleTypeDef htim16;
  TIM_HandleTypeDef htim17;
  
  /* TIM1 init function */
  void MX_TIM1_Init(void)
  {
    TIM_ClockConfigTypeDef sClockSourceConfig;
    TIM_MasterConfigTypeDef sMasterConfig;
    TIM_OC_InitTypeDef sConfigOC;
    TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
  
    htim1.Instance = TIM1;
    htim1.Init.Prescaler = 14;
    htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim1.Init.Period = 64000;
    htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim1.Init.RepetitionCounter = 0;
    htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
    if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = 0;
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
    sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
    sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
    if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
    sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
    sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
    sBreakDeadTimeConfig.DeadTime = 0;
    sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
    sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
    sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
    if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    HAL_TIM_MspPostInit(&htim1);
  
  }
  /* TIM3 init function */
  void MX_TIM3_Init(void)
  {
    TIM_ClockConfigTypeDef sClockSourceConfig;
    TIM_MasterConfigTypeDef sMasterConfig;
    TIM_OC_InitTypeDef sConfigOC;
  
    htim3.Instance = TIM3;
    htim3.Init.Prescaler = 14;
    htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim3.Init.Period = 64000;
    htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_Base_Init(&htim3) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
    if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sConfigOC.OCMode = TIM_OCMODE_PWM1;
    sConfigOC.Pulse = 0;
    sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
    sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
    if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    HAL_TIM_MspPostInit(&htim3);
  
  }
  /* TIM14 init function */
  void MX_TIM14_Init(void)
  {
    TIM_IC_InitTypeDef sConfigIC;
  
    htim14.Instance = TIM14;
    htim14.Init.Prescaler = 2;
    htim14.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim14.Init.Period = 48000;
    htim14.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim14.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_Base_Init(&htim14) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_IC_Init(&htim14) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
    sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
    sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
    sConfigIC.ICFilter = 0;
    if (HAL_TIM_IC_ConfigChannel(&htim14, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
  }
  /* TIM15 init function */
  void MX_TIM15_Init(void)
  {
    TIM_ClockConfigTypeDef sClockSourceConfig;
    TIM_MasterConfigTypeDef sMasterConfig;
    TIM_IC_InitTypeDef sConfigIC;
  
    htim15.Instance = TIM15;
    htim15.Init.Prescaler = 31;
    htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim15.Init.Period = 0xffff;
    htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim15.Init.RepetitionCounter = 0;
    htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
    if (HAL_TIM_Base_Init(&htim15) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
    if (HAL_TIM_ConfigClockSource(&htim15, &sClockSourceConfig) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    if (HAL_TIM_IC_Init(&htim15) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
    sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
    if (HAL_TIMEx_MasterConfigSynchronization(&htim15, &sMasterConfig) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
    sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
    sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
    sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
    sConfigIC.ICFilter = 0;
    if (HAL_TIM_IC_ConfigChannel(&htim15, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
  }
  /* TIM16 init function */
  void MX_TIM16_Init(void)
  {
  
    htim16.Instance = TIM16;
    htim16.Init.Prescaler = 14;
    htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim16.Init.Period = 64000;
    htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim16.Init.RepetitionCounter = 0;
    htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_Base_Init(&htim16) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
  }
  /* TIM17 init function */
  void MX_TIM17_Init(void)
  {
  
    htim17.Instance = TIM17;
    htim17.Init.Prescaler = 14;
    htim17.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim17.Init.Period = 64000;
    htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    htim17.Init.RepetitionCounter = 0;
    htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
    if (HAL_TIM_Base_Init(&htim17) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }
  
  }
  
  void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
  {
  
    GPIO_InitTypeDef GPIO_InitStruct;
    if(tim_baseHandle->Instance==TIM1)
    {
    /* USER CODE BEGIN TIM1_MspInit 0 */
  
    /* USER CODE END TIM1_MspInit 0 */
      /* TIM1 clock enable */
      __HAL_RCC_TIM1_CLK_ENABLE();
    /* USER CODE BEGIN TIM1_MspInit 1 */
  
    /* USER CODE END TIM1_MspInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM3)
    {
    /* USER CODE BEGIN TIM3_MspInit 0 */
  
    /* USER CODE END TIM3_MspInit 0 */
      /* TIM3 clock enable */
      __HAL_RCC_TIM3_CLK_ENABLE();
    /* USER CODE BEGIN TIM3_MspInit 1 */
  
    /* USER CODE END TIM3_MspInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM14)
    {
    /* USER CODE BEGIN TIM14_MspInit 0 */
  
    /* USER CODE END TIM14_MspInit 0 */
      /* TIM14 clock enable */
      __HAL_RCC_TIM14_CLK_ENABLE();
  
      /**TIM14 GPIO Configuration
      PB1     ------> TIM14_CH1
      */
      GPIO_InitStruct.Pin = BUZZER_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF0_TIM14;
      HAL_GPIO_Init(BUZZER_GPIO_Port, &GPIO_InitStruct);
  
    /* USER CODE BEGIN TIM14_MspInit 1 */
  
    /* USER CODE END TIM14_MspInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM15)
    {
    /* USER CODE BEGIN TIM15_MspInit 0 */
  
    /* USER CODE END TIM15_MspInit 0 */
      /* TIM15 clock enable */
      __HAL_RCC_TIM15_CLK_ENABLE();
  
      /**TIM15 GPIO Configuration
      PB14     ------> TIM15_CH1
      */
      GPIO_InitStruct.Pin = PPM_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF1_TIM15;
      HAL_GPIO_Init(PPM_GPIO_Port, &GPIO_InitStruct);
  
      /* TIM15 interrupt Init */
      HAL_NVIC_SetPriority(TIM15_IRQn, 0, 0);
      HAL_NVIC_EnableIRQ(TIM15_IRQn);
    /* USER CODE BEGIN TIM15_MspInit 1 */
  
    /* USER CODE END TIM15_MspInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM16)
    {
    /* USER CODE BEGIN TIM16_MspInit 0 */
  
    /* USER CODE END TIM16_MspInit 0 */
      /* TIM16 clock enable */
      __HAL_RCC_TIM16_CLK_ENABLE();
    /* USER CODE BEGIN TIM16_MspInit 1 */
  
    /* USER CODE END TIM16_MspInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM17)
    {
    /* USER CODE BEGIN TIM17_MspInit 0 */
  
    /* USER CODE END TIM17_MspInit 0 */
      /* TIM17 clock enable */
      __HAL_RCC_TIM17_CLK_ENABLE();
    /* USER CODE BEGIN TIM17_MspInit 1 */
  
    /* USER CODE END TIM17_MspInit 1 */
    }
  }
  void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
  {
  
    GPIO_InitTypeDef GPIO_InitStruct;
    if(timHandle->Instance==TIM1)
    {
    /* USER CODE BEGIN TIM1_MspPostInit 0 */
  
    /* USER CODE END TIM1_MspPostInit 0 */
      /**TIM1 GPIO Configuration
      PA8     ------> TIM1_CH1
      PA9     ------> TIM1_CH2
      PA10     ------> TIM1_CH3
      PA11     ------> TIM1_CH4
      */
      GPIO_InitStruct.Pin = PWM1_Pin|PWM2_Pin|PWM3_Pin|PWM4_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
    /* USER CODE BEGIN TIM1_MspPostInit 1 */
  
    /* USER CODE END TIM1_MspPostInit 1 */
    }
    else if(timHandle->Instance==TIM3)
    {
    /* USER CODE BEGIN TIM3_MspPostInit 0 */
  
    /* USER CODE END TIM3_MspPostInit 0 */
  
      /**TIM3 GPIO Configuration
      PC6     ------> TIM3_CH1
      PC7     ------> TIM3_CH2
      PC8     ------> TIM3_CH3
      PC9     ------> TIM3_CH4
      */
      GPIO_InitStruct.Pin = PWM6_Pin|PWM10_Pin|PWM11_Pin|PWM12_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF0_TIM3;
      HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  
    /* USER CODE BEGIN TIM3_MspPostInit 1 */
  
    /* USER CODE END TIM3_MspPostInit 1 */
    }
  
  }
  
  void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
  {
  
    if(tim_baseHandle->Instance==TIM1)
    {
    /* USER CODE BEGIN TIM1_MspDeInit 0 */
  
    /* USER CODE END TIM1_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_TIM1_CLK_DISABLE();
    /* USER CODE BEGIN TIM1_MspDeInit 1 */
  
    /* USER CODE END TIM1_MspDeInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM3)
    {
    /* USER CODE BEGIN TIM3_MspDeInit 0 */
  
    /* USER CODE END TIM3_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_TIM3_CLK_DISABLE();
    /* USER CODE BEGIN TIM3_MspDeInit 1 */
  
    /* USER CODE END TIM3_MspDeInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM14)
    {
    /* USER CODE BEGIN TIM14_MspDeInit 0 */
  
    /* USER CODE END TIM14_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_TIM14_CLK_DISABLE();
  
      /**TIM14 GPIO Configuration
      PB1     ------> TIM14_CH1
      */
      HAL_GPIO_DeInit(BUZZER_GPIO_Port, BUZZER_Pin);
  
    /* USER CODE BEGIN TIM14_MspDeInit 1 */
  
    /* USER CODE END TIM14_MspDeInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM15)
    {
    /* USER CODE BEGIN TIM15_MspDeInit 0 */
  
    /* USER CODE END TIM15_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_TIM15_CLK_DISABLE();
  
      /**TIM15 GPIO Configuration
      PB14     ------> TIM15_CH1
      */
      HAL_GPIO_DeInit(PPM_GPIO_Port, PPM_Pin);
  
      /* TIM15 interrupt Deinit */
      HAL_NVIC_DisableIRQ(TIM15_IRQn);
    /* USER CODE BEGIN TIM15_MspDeInit 1 */
  
    /* USER CODE END TIM15_MspDeInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM16)
    {
    /* USER CODE BEGIN TIM16_MspDeInit 0 */
  
    /* USER CODE END TIM16_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_TIM16_CLK_DISABLE();
    /* USER CODE BEGIN TIM16_MspDeInit 1 */
  
    /* USER CODE END TIM16_MspDeInit 1 */
    }
    else if(tim_baseHandle->Instance==TIM17)
    {
    /* USER CODE BEGIN TIM17_MspDeInit 0 */
  
    /* USER CODE END TIM17_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_TIM17_CLK_DISABLE();
    /* USER CODE BEGIN TIM17_MspDeInit 1 */
  
    /* USER CODE END TIM17_MspDeInit 1 */
    }
  }
  
  /* USER CODE BEGIN 1 */
  
  /* USER CODE END 1 */
  
  /**
    * @}
    */
  
  /**
    * @}
    */
  
  /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  