Files
ESHL/Core/Src/comp.c
2025-07-22 22:23:55 +08:00

121 lines
3.1 KiB
C

/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file comp.c
* @brief This file provides code for the configuration
* of the COMP instances.
******************************************************************************
* @attention
*
* Copyright (c) 2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "comp.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
COMP_HandleTypeDef hcomp2;
/* COMP2 init function */
void MX_COMP2_Init(void)
{
/* USER CODE BEGIN COMP2_Init 0 */
/* USER CODE END COMP2_Init 0 */
/* USER CODE BEGIN COMP2_Init 1 */
/* USER CODE END COMP2_Init 1 */
hcomp2.Instance = COMP2;
hcomp2.Init.InvertingInput = COMP_INVERTINGINPUT_IO1;
hcomp2.Init.NonInvertingInput = COMP_NONINVERTINGINPUT_IO1;
hcomp2.Init.Output = COMP_OUTPUT_NONE;
hcomp2.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp2.Init.Hysteresis = COMP_HYSTERESIS_NONE;
hcomp2.Init.Mode = COMP_MODE_HIGHSPEED;
hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING;
if (HAL_COMP_Init(&hcomp2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN COMP2_Init 2 */
/* USER CODE END COMP2_Init 2 */
}
void HAL_COMP_MspInit(COMP_HandleTypeDef* compHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(compHandle->Instance==COMP2)
{
/* USER CODE BEGIN COMP2_MspInit 0 */
/* USER CODE END COMP2_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**COMP2 GPIO Configuration
PA2 ------> COMP2_INM
PA3 ------> COMP2_INP
*/
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* COMP2 interrupt Init */
HAL_NVIC_SetPriority(ADC1_COMP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC1_COMP_IRQn);
/* USER CODE BEGIN COMP2_MspInit 1 */
/* USER CODE END COMP2_MspInit 1 */
}
}
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* compHandle)
{
if(compHandle->Instance==COMP2)
{
/* USER CODE BEGIN COMP2_MspDeInit 0 */
/* USER CODE END COMP2_MspDeInit 0 */
/**COMP2 GPIO Configuration
PA2 ------> COMP2_INM
PA3 ------> COMP2_INP
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
/* COMP2 interrupt Deinit */
/* USER CODE BEGIN COMP2:ADC1_COMP_IRQn disable */
/**
* Uncomment the line below to disable the "ADC1_COMP_IRQn" interrupt
* Be aware, disabling shared interrupt may affect other IPs
*/
/* HAL_NVIC_DisableIRQ(ADC1_COMP_IRQn); */
/* USER CODE END COMP2:ADC1_COMP_IRQn disable */
/* USER CODE BEGIN COMP2_MspDeInit 1 */
/* USER CODE END COMP2_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */