/*
|
* Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and
|
* its subsidiaries and affiliates (collectly called MKSEMI).
|
*
|
* All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* 1. Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
*
|
* 2. Redistributions in binary form, except as embedded into an MKSEMI
|
* integrated circuit in a product or a software update for such product,
|
* must reproduce the above copyright notice, this list of conditions and
|
* the following disclaimer in the documentation and/or other materials
|
* provided with the distribution.
|
*
|
* 3. Neither the name of MKSEMI nor the names of its contributors may be used
|
* to endorse or promote products derived from this software without
|
* specific prior written permission.
|
*
|
* 4. This software, with or without modification, must only be used with a
|
* MKSEMI integrated circuit.
|
*
|
* 5. Any software provided in binary form under this license must not be
|
* reverse engineered, decompiled, modified and/or disassembled.
|
*
|
* THIS SOFTWARE IS PROVIDED BY MKSEMI "AS IS" AND ANY EXPRESS OR IMPLIED
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
* MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* DISCLAIMED. IN NO EVENT SHALL MKSEMI OR CONTRIBUTORS BE LIABLE FOR ANY
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
*/
|
|
#ifndef MK_ACMP_H_
|
#define MK_ACMP_H_
|
#include "mk_common.h"
|
|
#ifndef ACMP_INT_MODE_EN
|
#define ACMP_INT_MODE_EN (1)
|
#endif
|
|
/**
|
* @addtogroup MK8000_ACMP
|
* @{
|
*/
|
|
#define ACMP_POSEDGE_INT 0 /*!< Rising edge trigger detection */
|
#define ACMP_NEGEDGE_INT 1 /*!< Falling edge trigger detection */
|
#define ACMP_BOTHEDGE_INT 2 /*!< Rising/Falling edge trigger detection */
|
|
/**
|
* @brief ACMP device IDs enumeration
|
*/
|
enum ACMP_DEV_T
|
{
|
ACMP_ID0 = 0,
|
ACMP_ID1,
|
ACMP_MAX_NUM
|
};
|
|
/**
|
* @brief ACMP channel P/N configure enumeration
|
*/
|
enum ACMP_DEV_CH_T
|
{
|
ACMP_VREF1 = 0, /*!< The P/N poles of ACMP can be connected to the internal reference voltage 0.25 * 0.9V */
|
ACMP_VREF2, /*!< The P/N poles of ACMP can be connected to the internal reference voltage 0.50 * 0.9V */
|
ACMP_VREF3, /*!< The P/N poles of ACMP can be connected to the internal reference voltage 0.75 * 0.9V */
|
ACMP_VREF4, /*!< The P/N poles of ACMP can be connected to the internal reference voltage 1.00 * 0.9V */
|
ACMP_EXTPIN5, /*!< The P/N poles of ACMP can be connected to external pin (ACMP_ID0-->GPIO3, ACMP_ID1-->GPIO0) */
|
ACMP_EXTPIN6, /*!< The P/N poles of ACMP can be connected to external pin (ACMP_ID0-->GPIO4, ACMP_ID1-->GPIO1) */
|
};
|
|
/**
|
* @brief ACMP configure structure
|
*/
|
struct ACMP_CFG_T
|
{
|
uint8_t channel_p; /*!< The positive can be set to an internal reference voltage or an external input voltage.
|
This parameter can be a value of @ref ACMP_DEV_CH_T
|
*/
|
uint8_t channel_n; /*!< The negative can be set to an internal reference voltage or an external input voltage.
|
This parameter can be a value of @ref ACMP_DEV_CH_T
|
*/
|
uint8_t int_en; /*!< Specifies whether the interrupt is enabled or disabled
|
This parameter will be one of the following values:
|
@arg true is enable
|
@arg false is disable
|
*/
|
uint8_t edge_int : 4; /*!< Specifies interrupt edge trigger mode.
|
This parameter will be one of the following values:
|
@arg @ref ACMP_POSEDGE_INT Rising edge trigger
|
@arg @ref ACMP_NEGEDGE_INT Falling edge trigger
|
@arg @ref ACMP_BOTHEDGE_INT Rising/Falling edge trigger
|
*/
|
|
uint8_t hyst_en : 4; /*!< Specifies whether the hysteresis is enabled or disabled.
|
This parameter will be one of the following values:
|
@arg true is enable
|
@arg false is disable
|
*/
|
drv_callback_t callback; /*!< Callback function provided by the user */
|
};
|
|
/**
|
* @brief ACMP handle Structure
|
*/
|
struct ACMP_HANDLE_T
|
{
|
const IRQn_Type irq;
|
struct ACMP_CFG_T config;
|
};
|
|
#ifdef __cplusplus
|
extern "C" {
|
#endif
|
/**
|
* @brief Function for initializing the ACMP.
|
*
|
* @param[in] id ACMP device ID.
|
* @param[in] config Pointer to a ACMP_CFG_T structure that contains the configuration information for ACMP.
|
* If this config is NULL, this function will use the default config.
|
* @return
|
* @arg DEV_ERROR error id
|
* @arg DEV_OK succeed
|
*/
|
int acmp_open(enum ACMP_DEV_T id, struct ACMP_CFG_T *config);
|
|
/**
|
* @brief Function for uninitializing the ACMP.
|
*
|
* @param[in] id ACMP device ID.
|
* @return
|
* @arg DEV_ERROR error id
|
* @arg DEV_OK succeed
|
*/
|
int acmp_close(enum ACMP_DEV_T id);
|
|
/**
|
* @brief Function for getting the result of ACMP output.
|
*
|
* @param[in] id ACMP device ID.
|
* @return
|
* @arg RESULT 0 or 1
|
* @arg DRV_DEV_UNAVAILABLE error id
|
*/
|
int acmp_get(enum ACMP_DEV_T id);
|
|
/**
|
* @brief Function for Interrupt handler for ACMP0.
|
*/
|
void ACMP0_IRQHandler(void);
|
|
/**
|
* @brief Function for Interrupt handler for ACMP1.
|
*/
|
void ACMP1_IRQHandler(void);
|
|
#ifdef __cplusplus
|
}
|
#endif
|
|
/**
|
* @}
|
*/
|
|
#endif /* MK_ACMP_H_ */
|