text: /**
    ******************************************************************************
    * File Name          : TSC.c
    * Description        : This file provides code for the configuration
    *                      of the TSC instances.
    ******************************************************************************
    *
    * COPYRIGHT(c) 2017 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 "tsc.h"
  
  #include "gpio.h"
  
  /* USER CODE BEGIN 0 */
  
  /* USER CODE END 0 */
  
  TSC_HandleTypeDef htsc;
  
  /* TSC init function */
  void MX_TSC_Init(void)
  {
  
      /**Configure the TSC peripheral 
      */
    htsc.Instance = TSC;
    htsc.Init.CTPulseHighLength = TSC_CTPH_2CYCLES;
    htsc.Init.CTPulseLowLength = TSC_CTPL_2CYCLES;
    htsc.Init.SpreadSpectrum = DISABLE;
    htsc.Init.SpreadSpectrumDeviation = 0;
    htsc.Init.SpreadSpectrumPrescaler = TSC_SS_PRESC_DIV1;
    htsc.Init.PulseGeneratorPrescaler = TSC_PG_PRESC_DIV64;
    htsc.Init.MaxCountValue = TSC_MCV_255;
    htsc.Init.IODefaultMode = TSC_IODEF_OUT_PP_LOW;
    htsc.Init.SynchroPinPolarity = TSC_SYNC_POLARITY_FALLING;
    htsc.Init.AcquisitionMode = TSC_ACQ_MODE_NORMAL;
    htsc.Init.ChannelIOs = TSC_GROUP1_IO1|TSC_GROUP1_IO2|TSC_GROUP1_IO3|TSC_GROUP3_IO1
                      |TSC_GROUP3_IO2|TSC_GROUP3_IO3|TSC_GROUP5_IO1|TSC_GROUP5_IO2
                      |TSC_GROUP5_IO3;
    htsc.Init.SamplingIOs = TSC_GROUP1_IO4|TSC_GROUP3_IO4|TSC_GROUP5_IO4;
    HAL_TSC_Init(&htsc);
  
  }
  
  void HAL_TSC_MspInit(TSC_HandleTypeDef* htsc)
  {
  
    GPIO_InitTypeDef GPIO_InitStruct;
    if(htsc->Instance==TSC)
    {
    /* USER CODE BEGIN TSC_MspInit 0 */
  
    /* USER CODE END TSC_MspInit 0 */
      /* Peripheral clock enable */
      __HAL_RCC_TSC_CLK_ENABLE();
    
      /**TSC GPIO Configuration    
      PA0     ------> TSC_G1_IO1
      PA1     ------> TSC_G1_IO2
      PA2     ------> TSC_G1_IO3
      PA3     ------> TSC_G1_IO4
      PC5     ------> TSC_G3_IO1
      PB0     ------> TSC_G3_IO2
      PB1     ------> TSC_G3_IO3
      PB2     ------> TSC_G3_IO4
      PB3     ------> TSC_G5_IO1
      PB4     ------> TSC_G5_IO2
      PB6     ------> TSC_G5_IO3
      PB7     ------> TSC_G5_IO4 
      */
      GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF3_TSC;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
      GPIO_InitStruct.Pin = GPIO_PIN_3;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF3_TSC;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  
      GPIO_InitStruct.Pin = GPIO_PIN_5;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF3_TSC;
      HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  
      GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_4 
                            |GPIO_PIN_6;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF3_TSC;
      HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  
      GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_7;
      GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      GPIO_InitStruct.Alternate = GPIO_AF3_TSC;
      HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  
    /* USER CODE BEGIN TSC_MspInit 1 */
  
    /* USER CODE END TSC_MspInit 1 */
    }
  }
  
  void HAL_TSC_MspDeInit(TSC_HandleTypeDef* htsc)
  {
  
    if(htsc->Instance==TSC)
    {
    /* USER CODE BEGIN TSC_MspDeInit 0 */
  
    /* USER CODE END TSC_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_TSC_CLK_DISABLE();
    
      /**TSC GPIO Configuration    
      PA0     ------> TSC_G1_IO1
      PA1     ------> TSC_G1_IO2
      PA2     ------> TSC_G1_IO3
      PA3     ------> TSC_G1_IO4
      PC5     ------> TSC_G3_IO1
      PB0     ------> TSC_G3_IO2
      PB1     ------> TSC_G3_IO3
      PB2     ------> TSC_G3_IO4
      PB3     ------> TSC_G5_IO1
      PB4     ------> TSC_G5_IO2
      PB6     ------> TSC_G5_IO3
      PB7     ------> TSC_G5_IO4 
      */
      HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
  
      HAL_GPIO_DeInit(GPIOC, GPIO_PIN_5);
  
      HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 
                            |GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_7);
  
    }
    /* USER CODE BEGIN TSC_MspDeInit 1 */
  
    /* USER CODE END TSC_MspDeInit 1 */
  } 
  
  /* USER CODE BEGIN 1 */
  
  /* USER CODE END 1 */
  
  /**
    * @}
    */
  
  /**
    * @}
    */
  
  /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  