text: /**
    ******************************************************************************
    * File Name          : ADC.c
    * Description        : This file provides code for the configuration
    *                      of the ADC instances.
    ******************************************************************************
    * @attention
    *
    * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
    * All rights reserved.</center></h2>
    *
    * This software component is licensed by ST under Ultimate Liberty license
    * SLA0044, the "License"; You may not use this file except in compliance with
    * the License. You may obtain a copy of the License at:
    *                             www.st.com/SLA0044
    *
    ******************************************************************************
    */
  
  /* Includes ------------------------------------------------------------------*/
  #include "adc.h"
  
  /* USER CODE BEGIN 0 */
  
  /* USER CODE END 0 */
  
  ADC_HandleTypeDef hadc1;
  
  /* ADC1 init function */
  void MX_ADC1_Init(void)
  {
    ADC_ChannelConfTypeDef sConfig = {0};
  
    /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
    */
    hadc1.Instance = ADC1;
    hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
    hadc1.Init.Resolution = ADC_RESOLUTION_12B;
    hadc1.Init.ScanConvMode = DISABLE;
    hadc1.Init.ContinuousConvMode = DISABLE;
    hadc1.Init.DiscontinuousConvMode = DISABLE;
    hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
    hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
    hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
    hadc1.Init.NbrOfConversion = 1;
    hadc1.Init.DMAContinuousRequests = DISABLE;
    hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
    if (HAL_ADC_Init(&hadc1) != HAL_OK)
    {
      Error_Handler();
    }
    /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
    */
    sConfig.Channel = ADC_CHANNEL_3;
    sConfig.Rank = 1;
    sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
    if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
    {
      Error_Handler();
    }
  
  }
  
  void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
  {
  
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    if(adcHandle->Instance==ADC1)
    {
    /* USER CODE BEGIN ADC1_MspInit 0 */
  
    /* USER CODE END ADC1_MspInit 0 */
      /* ADC1 clock enable */
      __HAL_RCC_ADC1_CLK_ENABLE();
    
      __HAL_RCC_GPIOA_CLK_ENABLE();
      /**ADC1 GPIO Configuration    
      PA3     ------> ADC1_IN3 
      */
      GPIO_InitStruct.Pin = BUTTON_AD_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      HAL_GPIO_Init(BUTTON_AD_GPIO_Port, &GPIO_InitStruct);
  
    /* USER CODE BEGIN ADC1_MspInit 1 */
  
    /* USER CODE END ADC1_MspInit 1 */
    }
  }
  
  void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
  {
  
    if(adcHandle->Instance==ADC1)
    {
    /* USER CODE BEGIN ADC1_MspDeInit 0 */
  
    /* USER CODE END ADC1_MspDeInit 0 */
      /* Peripheral clock disable */
      __HAL_RCC_ADC1_CLK_DISABLE();
    
      /**ADC1 GPIO Configuration    
      PA3     ------> ADC1_IN3 
      */
      HAL_GPIO_DeInit(BUTTON_AD_GPIO_Port, BUTTON_AD_Pin);
  
    /* USER CODE BEGIN ADC1_MspDeInit 1 */
  
    /* USER CODE END ADC1_MspDeInit 1 */
    }
  } 
  
  /* USER CODE BEGIN 1 */
  
  /* USER CODE END 1 */
  
  /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  