1 /**************************************************************************//**
2  * @file     acmp.c
3  * @version  V1.00
4  * @brief    M480 series Analog Comparator(ACMP) driver source file
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved.
8 *****************************************************************************/
9 #include "NuMicro.h"
10 
11 
12 /** @addtogroup Standard_Driver Standard Driver
13   @{
14 */
15 
16 /** @addtogroup ACMP_Driver ACMP Driver
17   @{
18 */
19 
20 
21 /** @addtogroup ACMP_EXPORTED_FUNCTIONS ACMP Exported Functions
22   @{
23 */
24 
25 
26 /**
27   * @brief  Configure the specified ACMP module
28   *
29   * @param[in]  acmp The pointer of the specified ACMP module
30   * @param[in]  u32ChNum Comparator number.
31   * @param[in]  u32NegSrc Comparator negative input selection.  Including:
32   *                  - \ref ACMP_CTL_NEGSEL_PIN
33   *                  - \ref ACMP_CTL_NEGSEL_CRV
34   *                  - \ref ACMP_CTL_NEGSEL_VBG
35   *                  - \ref ACMP_CTL_NEGSEL_DAC
36   * @param[in]  u32HysSel The hysteresis function option. Including:
37   *                  - \ref ACMP_CTL_HYSTERESIS_30MV
38   *                  - \ref ACMP_CTL_HYSTERESIS_20MV
39   *                  - \ref ACMP_CTL_HYSTERESIS_10MV
40   *                  - \ref ACMP_CTL_HYSTERESIS_DISABLE
41   *
42   * @return     None
43   *
44   * @details    Configure hysteresis function, select the source of negative input and enable analog comparator.
45   */
ACMP_Open(ACMP_T * acmp,uint32_t u32ChNum,uint32_t u32NegSrc,uint32_t u32HysSel)46 void ACMP_Open(ACMP_T *acmp, uint32_t u32ChNum, uint32_t u32NegSrc, uint32_t u32HysSel)
47 {
48     acmp->CTL[u32ChNum] = (acmp->CTL[u32ChNum] & (~(ACMP_CTL_NEGSEL_Msk | ACMP_CTL_HYSSEL_Msk))) | (u32NegSrc | u32HysSel | ACMP_CTL_ACMPEN_Msk);
49 }
50 
51 /**
52   * @brief  Close analog comparator
53   *
54   * @param[in]  acmp The pointer of the specified ACMP module
55   * @param[in]  u32ChNum Comparator number.
56   *
57   * @return     None
58   *
59   * @details  This function will clear ACMPEN bit of ACMP_CTL register to disable analog comparator.
60   */
ACMP_Close(ACMP_T * acmp,uint32_t u32ChNum)61 void ACMP_Close(ACMP_T *acmp, uint32_t u32ChNum)
62 {
63     acmp->CTL[u32ChNum] &= (~ACMP_CTL_ACMPEN_Msk);
64 }
65 
66 
67 
68 /*@}*/ /* end of group ACMP_EXPORTED_FUNCTIONS */
69 
70 /*@}*/ /* end of group ACMP_Driver */
71 
72 /*@}*/ /* end of group Standard_Driver */
73 
74 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
75 
76