mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-19 06:43:20 +08:00
move components to SDK dir
This commit is contained in:
238
SDK/12.3.0_d7731ad/components/drivers_nrf/comp/nrf_drv_comp.c
Normal file
238
SDK/12.3.0_d7731ad/components/drivers_nrf/comp/nrf_drv_comp.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* 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 a Nordic
|
||||
* Semiconductor ASA 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 Nordic Semiconductor ASA 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
|
||||
* Nordic Semiconductor ASA 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 NORDIC SEMICONDUCTOR ASA "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 NORDIC SEMICONDUCTOR ASA 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sdk_common.h"
|
||||
#if NRF_MODULE_ENABLED(COMP)
|
||||
#include "nrf_drv_comp.h"
|
||||
|
||||
#include "nrf_assert.h"
|
||||
#include "nrf_error.h"
|
||||
#include "nrf_soc.h"
|
||||
#include "nrf_drv_common.h"
|
||||
#include "app_util_platform.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define NRF_LOG_MODULE_NAME "COMP"
|
||||
|
||||
#if COMP_CONFIG_LOG_ENABLED
|
||||
#define NRF_LOG_LEVEL COMP_CONFIG_LOG_LEVEL
|
||||
#define NRF_LOG_INFO_COLOR COMP_CONFIG_INFO_COLOR
|
||||
#define NRF_LOG_DEBUG_COLOR COMP_CONFIG_DEBUG_COLOR
|
||||
#define EVT_TO_STR(event) (event == NRF_COMP_EVENT_READY ? "NRF_COMP_EVENT_READY" : \
|
||||
(event == NRF_COMP_EVENT_DOWN ? "NRF_COMP_EVENT_DOWN" : \
|
||||
(event == NRF_COMP_EVENT_UP ? "NRF_COMP_EVENT_UP" : \
|
||||
(event == NRF_COMP_EVENT_CROSS ? "NRF_COMP_EVENT_CROSS" : "UNKNOWN ERROR"))))
|
||||
#else //COMP_CONFIG_LOG_ENABLED
|
||||
#define EVT_TO_STR(event) ""
|
||||
#define NRF_LOG_LEVEL 0
|
||||
#endif //COMP_CONFIG_LOG_ENABLED
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_log_ctrl.h"
|
||||
|
||||
|
||||
|
||||
static comp_events_handler_t m_comp_events_handler = NULL;
|
||||
static nrf_drv_state_t m_state = NRF_DRV_STATE_UNINITIALIZED;
|
||||
|
||||
static const nrf_drv_comp_config_t m_default_config = NRF_DRV_COMP_DEFAULT_CONFIG(NRF_COMP_INPUT_0);
|
||||
|
||||
static void comp_execute_handler(nrf_comp_event_t event, uint32_t event_mask)
|
||||
{
|
||||
if ( nrf_comp_event_check(event) && nrf_comp_int_enable_check(event_mask) )
|
||||
{
|
||||
nrf_comp_event_clear(event);
|
||||
NRF_LOG_DEBUG("Event: %s.\r\n", (uint32_t)EVT_TO_STR(event));
|
||||
|
||||
m_comp_events_handler(event);
|
||||
}
|
||||
}
|
||||
|
||||
#if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
|
||||
#define IRQ_HANDLER_NAME irq_handler_for_comp
|
||||
#define IRQ_HANDLER static void IRQ_HANDLER_NAME(void)
|
||||
|
||||
IRQ_HANDLER;
|
||||
#else
|
||||
#define IRQ_HANDLER void COMP_LPCOMP_IRQHandler(void)
|
||||
#endif // NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
|
||||
|
||||
IRQ_HANDLER
|
||||
{
|
||||
comp_execute_handler(NRF_COMP_EVENT_READY, COMP_INTENSET_READY_Msk);
|
||||
comp_execute_handler(NRF_COMP_EVENT_DOWN, COMP_INTENSET_DOWN_Msk);
|
||||
comp_execute_handler(NRF_COMP_EVENT_UP, COMP_INTENSET_UP_Msk);
|
||||
comp_execute_handler(NRF_COMP_EVENT_CROSS, COMP_INTENSET_CROSS_Msk);
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_drv_comp_init(const nrf_drv_comp_config_t * p_config,
|
||||
comp_events_handler_t event_handler)
|
||||
{
|
||||
ret_code_t err_code;
|
||||
|
||||
if (m_state != NRF_DRV_STATE_UNINITIALIZED)
|
||||
{ // COMP driver is already initialized
|
||||
err_code = NRF_ERROR_INVALID_STATE;
|
||||
NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code));
|
||||
return err_code;
|
||||
}
|
||||
|
||||
if (p_config == NULL)
|
||||
{
|
||||
p_config = &m_default_config;
|
||||
}
|
||||
|
||||
#if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
|
||||
if (nrf_drv_common_per_res_acquire(NRF_COMP, IRQ_HANDLER_NAME) != NRF_SUCCESS)
|
||||
{
|
||||
err_code = NRF_ERROR_BUSY;
|
||||
NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code));
|
||||
return err_code;
|
||||
}
|
||||
#endif
|
||||
|
||||
nrf_comp_task_trigger(NRF_COMP_TASK_STOP);
|
||||
nrf_comp_enable();
|
||||
|
||||
// Clear events to be sure there are no leftovers.
|
||||
nrf_comp_event_clear(NRF_COMP_EVENT_READY);
|
||||
nrf_comp_event_clear(NRF_COMP_EVENT_DOWN);
|
||||
nrf_comp_event_clear(NRF_COMP_EVENT_UP);
|
||||
nrf_comp_event_clear(NRF_COMP_EVENT_CROSS);
|
||||
|
||||
nrf_comp_ref_set(p_config->reference);
|
||||
|
||||
//If external source is chosen, write to appropriate register.
|
||||
if (p_config->reference == COMP_REFSEL_REFSEL_ARef)
|
||||
{
|
||||
nrf_comp_ext_ref_set(p_config->ext_ref);
|
||||
}
|
||||
|
||||
nrf_comp_th_set(p_config->threshold);
|
||||
nrf_comp_main_mode_set(p_config->main_mode);
|
||||
nrf_comp_speed_mode_set(p_config->speed_mode);
|
||||
nrf_comp_hysteresis_set(p_config->hyst);
|
||||
nrf_comp_isource_set(p_config->isource);
|
||||
nrf_comp_shorts_disable(NRF_DRV_COMP_SHORT_STOP_AFTER_CROSS_EVT | NRF_DRV_COMP_SHORT_STOP_AFTER_UP_EVT |
|
||||
NRF_DRV_COMP_SHORT_STOP_AFTER_DOWN_EVT);
|
||||
nrf_comp_int_disable(COMP_INTENCLR_CROSS_Msk | COMP_INTENCLR_UP_Msk |
|
||||
COMP_INTENCLR_DOWN_Msk | COMP_INTENCLR_READY_Msk);
|
||||
|
||||
if (event_handler)
|
||||
{
|
||||
m_comp_events_handler = event_handler;
|
||||
}
|
||||
else
|
||||
{
|
||||
err_code = NRF_ERROR_INVALID_PARAM;
|
||||
NRF_LOG_WARNING("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code));
|
||||
return err_code;
|
||||
}
|
||||
|
||||
nrf_comp_input_select(p_config->input);
|
||||
|
||||
nrf_drv_common_irq_enable(COMP_LPCOMP_IRQn, p_config->interrupt_priority);
|
||||
|
||||
m_state = NRF_DRV_STATE_INITIALIZED;
|
||||
|
||||
err_code = NRF_SUCCESS;
|
||||
NRF_LOG_INFO("Function: %s, error code: %s.\r\n", (uint32_t)__func__, (uint32_t)ERR_TO_STR(err_code));
|
||||
return err_code;
|
||||
}
|
||||
|
||||
|
||||
void nrf_drv_comp_uninit(void)
|
||||
{
|
||||
ASSERT(m_state != NRF_DRV_STATE_UNINITIALIZED);
|
||||
nrf_drv_common_irq_disable(COMP_LPCOMP_IRQn);
|
||||
nrf_comp_disable();
|
||||
#if NRF_MODULE_ENABLED(PERIPHERAL_RESOURCE_SHARING)
|
||||
nrf_drv_common_per_res_release(NRF_COMP);
|
||||
#endif
|
||||
m_state = NRF_DRV_STATE_UNINITIALIZED;
|
||||
m_comp_events_handler = NULL;
|
||||
NRF_LOG_INFO("Uninitialized.\r\n");
|
||||
}
|
||||
|
||||
void nrf_drv_comp_pin_select(nrf_comp_input_t psel)
|
||||
{
|
||||
bool comp_enable_state = nrf_comp_enable_check();
|
||||
nrf_comp_task_trigger(NRF_COMP_TASK_STOP);
|
||||
if (m_state == NRF_DRV_STATE_POWERED_ON)
|
||||
{
|
||||
m_state = NRF_DRV_STATE_INITIALIZED;
|
||||
}
|
||||
nrf_comp_disable();
|
||||
nrf_comp_input_select(psel);
|
||||
if (comp_enable_state == true)
|
||||
{
|
||||
nrf_comp_enable();
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_drv_comp_start(uint32_t comp_int_mask, uint32_t comp_shorts_mask)
|
||||
{
|
||||
ASSERT(m_state == NRF_DRV_STATE_INITIALIZED);
|
||||
nrf_comp_int_enable(comp_int_mask);
|
||||
nrf_comp_shorts_enable(comp_shorts_mask);
|
||||
nrf_comp_task_trigger(NRF_COMP_TASK_START);
|
||||
m_state = NRF_DRV_STATE_POWERED_ON;
|
||||
NRF_LOG_INFO("Enabled.\r\n");
|
||||
}
|
||||
|
||||
void nrf_drv_comp_stop(void)
|
||||
{
|
||||
ASSERT(m_state == NRF_DRV_STATE_POWERED_ON);
|
||||
nrf_comp_shorts_disable(UINT32_MAX);
|
||||
nrf_comp_int_disable(UINT32_MAX);
|
||||
nrf_comp_task_trigger(NRF_COMP_TASK_STOP);
|
||||
m_state = NRF_DRV_STATE_INITIALIZED;
|
||||
NRF_LOG_INFO("Disabled.\r\n");
|
||||
}
|
||||
|
||||
uint32_t nrf_drv_comp_sample()
|
||||
{
|
||||
ASSERT(m_state == NRF_DRV_STATE_POWERED_ON);
|
||||
nrf_comp_task_trigger(NRF_COMP_TASK_SAMPLE);
|
||||
return nrf_comp_result_get();
|
||||
}
|
||||
#endif //NRF_MODULE_ENABLED(COMP)
|
||||
244
SDK/12.3.0_d7731ad/components/drivers_nrf/comp/nrf_drv_comp.h
Normal file
244
SDK/12.3.0_d7731ad/components/drivers_nrf/comp/nrf_drv_comp.h
Normal file
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* Copyright (c) 2015 - 2017, Nordic Semiconductor ASA
|
||||
*
|
||||
* 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 a Nordic
|
||||
* Semiconductor ASA 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 Nordic Semiconductor ASA 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
|
||||
* Nordic Semiconductor ASA 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 NORDIC SEMICONDUCTOR ASA "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 NORDIC SEMICONDUCTOR ASA 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 NRF_DRV_COMP_H__
|
||||
#define NRF_DRV_COMP_H__
|
||||
|
||||
#include "sdk_config.h"
|
||||
#include "nrf_comp.h"
|
||||
#include "sdk_errors.h"
|
||||
#include "nrf_drv_common.h"
|
||||
#include "app_util_platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup nrf_comp COMP HAL and driver
|
||||
* @ingroup nrf_drivers
|
||||
* @brief @tagAPI52 Comparator (COMP) APIs.
|
||||
* @details The COMP HAL provides basic APIs for accessing the registers of Comparator.
|
||||
* The COMP driver provides APIs on a higher level.
|
||||
*
|
||||
* @defgroup nrf_drv_comp COMP driver
|
||||
* @{
|
||||
* @ingroup nrf_comp
|
||||
* @brief @tagAPI52 Comparator (COMP) driver.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Macro to convert the threshold voltage to an integer value (needed by the COMP_TH register).
|
||||
*
|
||||
* @param[in] vol Voltage to be changed to COMP_TH register value. This value must not be smaller than
|
||||
* reference voltage divided by 64.
|
||||
* @param[in] ref Reference voltage.
|
||||
*/
|
||||
#define VOLTAGE_THRESHOLD_TO_INT(vol, ref) (uint8_t)(((vol) > ((ref) / 64)) ? (ROUNDED_DIV((vol) * 64,(ref)) - 1) : 0)
|
||||
|
||||
/**@brief COMP event handler function type.
|
||||
* @param[in] event COMP event.
|
||||
*/
|
||||
typedef void (* comp_events_handler_t)(nrf_comp_event_t event);
|
||||
|
||||
/**
|
||||
* @enum nrf_drv_comp_short_mask_t
|
||||
* @brief COMP shortcut masks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_DRV_COMP_SHORT_STOP_AFTER_CROSS_EVT = COMP_SHORTS_CROSS_STOP_Msk, /*!< Shortcut between the CROSS event and the STOP task. */
|
||||
NRF_DRV_COMP_SHORT_STOP_AFTER_UP_EVT = COMP_SHORTS_UP_STOP_Msk, /*!< Shortcut between the UP event and the STOP task. */
|
||||
NRF_DRV_COMP_SHORT_STOP_AFTER_DOWN_EVT = COMP_SHORTS_DOWN_STOP_Msk /*!< Shortcut between the DOWN event and the STOP task. */
|
||||
}nrf_drv_comp_short_mask_t;
|
||||
|
||||
/**
|
||||
* @enum nrf_drv_comp_evt_en_mask_t
|
||||
* @brief COMP events masks.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NRF_DRV_COMP_EVT_EN_CROSS_MASK = COMP_INTENSET_CROSS_Msk, /*!< CROSS event (generated after VIN+ == VIN-). */
|
||||
NRF_DRV_COMP_EVT_EN_UP_MASK = COMP_INTENSET_UP_Msk, /*!< UP event (generated when VIN+ crosses VIN- while increasing). */
|
||||
NRF_DRV_COMP_EVT_EN_DOWN_MASK = COMP_INTENSET_DOWN_Msk, /*!< DOWN event (generated when VIN+ crosses VIN- while decreasing). */
|
||||
NRF_DRV_COMP_EVT_EN_READY_MASK = COMP_INTENSET_READY_Msk /*!< READY event (generated when the module is ready). */
|
||||
}nrf_drv_comp_evt_en_mask_t;
|
||||
|
||||
/**@brief COMP configuration.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
nrf_comp_ref_t reference; /**< Reference selection. */
|
||||
nrf_comp_ext_ref_t ext_ref; /**< External analog reference selection. */
|
||||
nrf_comp_main_mode_t main_mode; /**< Main operation mode. */
|
||||
nrf_comp_th_t threshold; /**< Structure holding THDOWN and THUP values needed by the COMP_TH register. */
|
||||
nrf_comp_sp_mode_t speed_mode; /**< Speed and power mode. */
|
||||
nrf_comp_hyst_t hyst; /**< Comparator hysteresis.*/
|
||||
nrf_isource_t isource; /**< Current source selected on analog input. */
|
||||
nrf_comp_input_t input; /**< Input to be monitored. */
|
||||
uint8_t interrupt_priority; /**< Interrupt priority. */
|
||||
} nrf_drv_comp_config_t;
|
||||
|
||||
/** @brief COMP threshold default configuration. */
|
||||
#define COMP_CONFIG_TH \
|
||||
{ \
|
||||
.th_down = VOLTAGE_THRESHOLD_TO_INT(0.5, 1.8), \
|
||||
.th_up = VOLTAGE_THRESHOLD_TO_INT(1.5, 1.8) \
|
||||
}
|
||||
|
||||
/** @brief COMP driver default configuration including the COMP HAL configuration. */
|
||||
#define NRF_DRV_COMP_DEFAULT_CONFIG(INPUT) \
|
||||
{ \
|
||||
.reference = (nrf_comp_ref_t)COMP_CONFIG_REF, \
|
||||
.main_mode = (nrf_comp_main_mode_t)COMP_CONFIG_MAIN_MODE, \
|
||||
.threshold = COMP_CONFIG_TH, \
|
||||
.speed_mode = (nrf_comp_sp_mode_t)COMP_CONFIG_SPEED_MODE, \
|
||||
.hyst = (nrf_comp_hyst_t)COMP_CONFIG_HYST, \
|
||||
.isource = (nrf_isource_t)COMP_CONFIG_ISOURCE, \
|
||||
.input = (nrf_comp_input_t)INPUT, \
|
||||
.interrupt_priority = COMP_CONFIG_IRQ_PRIORITY \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for initializing the COMP driver.
|
||||
*
|
||||
* This function initializes the COMP driver, but does not enable the peripheral or any interrupts.
|
||||
* To start the driver, call the function @ref nrf_drv_comp_start() after initialization.
|
||||
*
|
||||
* If no configuration structure is provided, the driver is initialized with the default settings.
|
||||
*
|
||||
* @param[in] p_config Initial configuration. If NULL, the default configuration is used.
|
||||
* @param[in] event_handler Handler function.
|
||||
*
|
||||
* @retval NRF_ERROR_INVALID_PARAM If the configuration is invalid.
|
||||
* @retval NRF_ERROR_INVALID_STATE If the driver has already been initialized.
|
||||
* @retval NRF_ERROR_BUSY If the LPCOMP driver is initialized.
|
||||
*/
|
||||
ret_code_t nrf_drv_comp_init(const nrf_drv_comp_config_t * p_config,
|
||||
comp_events_handler_t event_handler);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for uninitializing the COMP driver.
|
||||
*
|
||||
* This function uninitializes the COMP driver. The COMP peripheral and
|
||||
* its interrupts are disabled, and local variables are cleaned. After this call, you must
|
||||
* initialize the driver again by calling nrf_drv_comp_init() if you want to use it.
|
||||
*
|
||||
* @sa nrf_drv_comp_stop()
|
||||
*/
|
||||
void nrf_drv_comp_uninit(void);
|
||||
|
||||
/**
|
||||
* @brief Function for setting the analog input.
|
||||
*
|
||||
* @param[in] psel COMP analog pin selection.
|
||||
*/
|
||||
void nrf_drv_comp_pin_select(nrf_comp_input_t psel);
|
||||
|
||||
/**
|
||||
* @brief Function for starting the COMP peripheral and interrupts.
|
||||
*
|
||||
* Before calling this function, the driver must be initialized. This function
|
||||
* enables the COMP peripheral and its interrupts.
|
||||
*
|
||||
* @param[in] comp_evt_en_mask Mask of events to be enabled. This parameter should be built as
|
||||
* 'or' of elements from @ref nrf_drv_comp_evt_en_mask_t.
|
||||
* @param[in] comp_shorts_mask Mask of shorts to be enabled. This parameter should be built as
|
||||
* 'or' of elements from @ref nrf_drv_comp_short_mask_t.
|
||||
*
|
||||
* @sa nrf_drv_comp_init()
|
||||
*
|
||||
*/
|
||||
void nrf_drv_comp_start(uint32_t comp_evt_en_mask, uint32_t comp_shorts_mask);
|
||||
|
||||
/**@brief Function for stopping the COMP peripheral.
|
||||
*
|
||||
* Before calling this function, the driver must be enabled. This function disables the COMP
|
||||
* peripheral and its interrupts.
|
||||
*
|
||||
* @sa nrf_drv_comp_uninit()
|
||||
*
|
||||
*/
|
||||
void nrf_drv_comp_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Function for copying the current state of the comparator result to the RESULT register.
|
||||
*
|
||||
* @retval 0 If the input voltage is below the threshold (VIN+ < VIN-).
|
||||
* @retval 1 If the input voltage is above the threshold (VIN+ > VIN-).
|
||||
*/
|
||||
uint32_t nrf_drv_comp_sample(void);
|
||||
|
||||
/**
|
||||
* @brief Function for getting the task address.
|
||||
*
|
||||
* Before calling this function, the driver must be enabled.
|
||||
*
|
||||
* @param[in] comp_task COMP task.
|
||||
*
|
||||
* @return Address of the given COMP task.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_comp_task_address_get(nrf_comp_task_t comp_task)
|
||||
{
|
||||
return (uint32_t)nrf_comp_task_address_get(comp_task);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function for getting the event address.
|
||||
*
|
||||
* @param[in] comp_event COMP event.
|
||||
*
|
||||
* @return Address of the given COMP event.
|
||||
*/
|
||||
__STATIC_INLINE uint32_t nrf_drv_comp_event_address_get(nrf_comp_event_t comp_event)
|
||||
{
|
||||
return (uint32_t)nrf_comp_event_address_get(comp_event);
|
||||
}
|
||||
|
||||
/**
|
||||
*@}
|
||||
**/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* NRF_DRV_COMP_H__ */
|
||||
Reference in New Issue
Block a user