📄 stm8l15x_comp.c
字号:
/* Enable the output of internal reference voltage */
COMP->CSR3 |= (uint8_t) COMP_CSR3_VREFOUTEN;
}
else
{
/* Disable the output of internal reference voltage */
COMP->CSR3 &= (uint8_t) (~COMP_CSR3_VREFOUTEN);
}
}
/**
* @}
*/
/** @defgroup COMP_Group4 Comparator channels trigger configuration
* @brief Comparator channels trigger configuration
*
@verbatim
===============================================================================
Comparator channels trigger configuration
===============================================================================
@endverbatim
* @{
*/
/**
* @brief Enables or disables the schmitt trigger.
* @param NewState : new state of the schmitt trigger.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void COMP_SchmittTriggerCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable Schmitt trigger on Input Output switches Channels */
COMP->CSR1 |= (uint8_t) COMP_CSR1_STE;
}
else
{
/* Enable Schmitt trigger on Input Output switches Channels */
COMP->CSR1 &= (uint8_t) (~COMP_CSR1_STE);
}
}
/**
* @brief Enables or disables trigger on the specified input/output group.
* @param COMP_TriggerGroup : specifies the input/output group
* This parameter can be one of the following values:
* @arg COMP_TriggerGroup_InvertingInput: Trigger on comparator 2 inverting input
* @arg COMP_TriggerGroup_NonInvertingInput: Trigger on comparator 2 non inverting input
* @arg COMP_TriggerGroup_VREFINTOutput: Trigger on VREFINT output
* @arg COMP_TriggerGroup_DACOutput: Trigger on DAC output
* @param COMP_TriggerPin : specifies the pin(s) within the input/output group
* This parameter can be one of the following values:
* @arg COMP_TriggerPin_0: Trigger Pin 0
* @arg COMP_TriggerPin_0: Trigger Pin 1
* @arg COMP_TriggerPin_0: Trigger Pin 2
* @param NewState : enable or disable the trigger on the selected pin(s)
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void COMP_TriggerConfig(COMP_TriggerGroup_TypeDef COMP_TriggerGroup,
COMP_TriggerPin_TypeDef COMP_TriggerPin,
FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_COMP_TRIGGERGROUP(COMP_TriggerGroup));
assert_param(IS_COMP_TRIGGERPIN(COMP_TriggerPin));
switch (COMP_TriggerGroup)
{
case COMP_TriggerGroup_InvertingInput:
if (NewState != DISABLE)
{
COMP->CSR4 &= (uint8_t) ~COMP_TriggerPin;
}
else
{
COMP->CSR4 |= (uint8_t) COMP_TriggerPin;
}
break;
case COMP_TriggerGroup_NonInvertingInput:
if (NewState != DISABLE)
{
COMP->CSR4 &= (uint8_t) ~((uint8_t)(COMP_TriggerPin << 3));
}
else
{
COMP->CSR4 |= (uint8_t) (COMP_TriggerPin << 3);
}
break;
case COMP_TriggerGroup_VREFINTOutput:
if (NewState != DISABLE)
{
COMP->CSR5 &= (uint8_t) ~COMP_TriggerPin;
}
else
{
COMP->CSR5 |= (uint8_t) COMP_TriggerPin;
}
break;
case COMP_TriggerGroup_DACOutput:
if (NewState != DISABLE)
{
COMP->CSR5 &= (uint8_t) ~((uint8_t)(COMP_TriggerPin << 3));
}
else
{
COMP->CSR5 |= (uint8_t) (COMP_TriggerPin << 3);
}
break;
default:
break;
}
}
/**
* @}
*/
/** @defgroup COMP_Group5 Interrupts and flags management functions
* @brief Interrupts and flags management functions
*
@verbatim
===============================================================================
Interrupts and flags management functions
===============================================================================
@endverbatim
* @{
*/
/**
* @brief Enables or disables the interrupt generation when an event is detected.
* @param COMP_Selection : selects the comparator
* This parameter can be one of the following values:
* @arg COMP_Selection_COMP1: Selection of Comparator 1
* @arg COMP_Selection_COMP2: Selection of Comparator 2
* @param NewState : new state of the COMPx interrupt.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void COMP_ITConfig(COMP_Selection_TypeDef COMP_Selection, FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Check if Comparator 1 is selected */
if (COMP_Selection == COMP_Selection_COMP1)
{
if (NewState != DISABLE)
{
/* Enable the COMP1 Interrupt source */
COMP->CSR1 |= (uint8_t) COMP_CSR1_IE1;
}
else
{
/* Disable the COMP1 Interrupt source */
COMP->CSR1 &= (uint8_t)(~COMP_CSR1_IE1);
}
}
else /* Comparator 2 is selected */
{
if (NewState != DISABLE)
{
/* Enable the COMP2 Interrupt source */
COMP->CSR2 |= (uint8_t) COMP_CSR2_IE2;
}
else
{
/* Disable the COMP2 Interrupt source */
COMP->CSR2 &= (uint8_t)(~COMP_CSR2_IE2);
}
}
}
/**
* @brief Checks whether the comparator flag is set or not.
* @param COMP_Selection : selects the comparator
* This parameter can be one of the following values:
* @arg COMP_Selection_COMP1: Selection of Comparator 1
* @arg COMP_Selection_COMP2: Selection of Comparator 2
* @retval The new state of COMPx event flag (SET or RESET).
*/
FlagStatus COMP_GetFlagStatus(COMP_Selection_TypeDef COMP_Selection)
{
FlagStatus bitstatus = RESET;
/* Check the parameters */
assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
/* Check if COMP1 is selected */
if (COMP_Selection == COMP_Selection_COMP1)
{
if ((COMP->CSR1 & COMP_CSR1_EF1) != (uint8_t) RESET)
{
/* The comparator 1 event flag is set */
bitstatus = SET;
}
else
{
/* The comparator 1 event flag is reset */
bitstatus = RESET;
}
}
else /* COMP2 is selected */
{
if ((COMP->CSR2 & COMP_CSR2_EF2) != (uint8_t) RESET)
{
/* The comparator 2 event flag is set */
bitstatus = SET;
}
else
{
/* The comparator 2 event flag is reset */
bitstatus = RESET;
}
}
/* return the comparator event flag status */
return (FlagStatus)(bitstatus);
}
/**
* @brief Clears the comparator抯 pending flag.
* @param COMP_Selection : selects the comparator
* This parameter can be one of the following values:
* @arg COMP_Selection_COMP1: Selection of Comparator 1
* @arg COMP_Selection_COMP2: Selection of Comparator 2
* @retval None.
*/
void COMP_ClearFlag(COMP_Selection_TypeDef COMP_Selection)
{
/* Check the parameters */
assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
if (COMP_Selection == COMP_Selection_COMP1)
{
/* Clear the flag EF1 (rc_w0) clear this bit by writing 0. */
COMP->CSR1 &= (uint8_t) (~COMP_CSR1_EF1);
}
else
{
/* Clear the flag EF2 (rc_w0) clear this bit by writing 0. */
COMP->CSR2 &= (uint8_t) (~COMP_CSR2_EF2);
}
}
/**
* @brief Checks whether the comparator interrupt has occurred or not.
* @param COMP_Selection : selects the comparator
* This parameter can be one of the following values:
* @arg COMP_Selection_COMP1: Selection of Comparator 1
* @arg COMP_Selection_COMP2: Selection of Comparator 2
* @retval ITStatus : The state of the COMPx event flag (SET or RESET).
*/
ITStatus COMP_GetITStatus(COMP_Selection_TypeDef COMP_Selection)
{
ITStatus bitstatus = RESET;
uint8_t itstatus = 0x00, itenable = 0x00;
/* Check the parameters */
assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
if (COMP_Selection == COMP_Selection_COMP1)
{
/* Get the EF1 comparator event falg status */
itstatus = (uint8_t) (COMP->CSR1 & COMP_CSR1_EF1);
/* Get the IE1 interrupt enable bit status */
itenable = (uint8_t) (COMP->CSR1 & COMP_CSR1_IE1);
if ((itstatus != (uint8_t) RESET) && (itenable != (uint8_t) RESET))
{
/* the EF1 and IE1 are set */
bitstatus = SET;
}
else
{
/* the EF1 or IE1 is reset */
bitstatus = RESET;
}
}
else
{
/* Get the EF2 comparator event falg value */
itstatus = (uint8_t) (COMP->CSR2 & COMP_CSR2_EF2);
/* Get the IE2 interrupt enable bit value */
itenable = (uint8_t) (COMP->CSR2 & COMP_CSR2_IE2);
if ((itstatus != (uint8_t)RESET) && (itenable != (uint8_t)RESET))
{
/* The EF2 and IE2 are set */
bitstatus = SET;
}
else
{
/* The EF2 or IE2 is reset */
bitstatus = RESET;
}
}
/* Return the COMP interrupt status */
return (ITStatus) bitstatus;
}
/**
* @brief Clears the interrupt pending bits of the comparator.
* @param COMP_Selection : selects the comparator
* This parameter can be one of the following values:
* @arg COMP_Selection_COMP1: Selection of Comparator 1
* @arg COMP_Selection_COMP2: Selection of Comparator 2
* @retval None
*/
void COMP_ClearITPendingBit(COMP_Selection_TypeDef COMP_Selection)
{
/* Check the parameters */
assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
if (COMP_Selection == COMP_Selection_COMP1)
{
/* Clear the flag EF1 (rc_w0) clear this bit by writing 0. */
COMP->CSR1 &= (uint8_t) (~COMP_CSR1_EF1);
}
else
{
/* Clear the flag EF2 (rc_w0) clear this bit by writing 0. */
COMP->CSR2 &= (uint8_t) (~COMP_CSR2_EF2);
}
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -