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