nRF5 SDK v17.1.0
Modules | Data Structures | Macros | Typedefs | Enumerations | Functions
COMP driver

Comparator (COMP) peripheral driver. More...

Modules

 COMP peripheral driver configuration
 

Data Structures

struct  nrfx_comp_config_t
 COMP configuration. More...
 

Macros

#define NRFX_VOLTAGE_THRESHOLD_TO_INT(vol, ref)   (uint8_t)(((vol) > ((ref) / 64)) ? (NRFX_ROUNDED_DIV((vol) * 64,(ref)) - 1) : 0)
 Macro for converting the threshold voltage to an integer value (needed by the COMP_TH register). More...
 
#define NRFX_COMP_CONFIG_TH
 COMP threshold default configuration. More...
 
#define NRFX_COMP_DEFAULT_CONFIG(_input)
 COMP driver default configuration including the COMP HAL configuration. More...
 

Typedefs

typedef void(* nrfx_comp_event_handler_t )(nrf_comp_event_t event)
 COMP event handler function type. More...
 

Enumerations

enum  nrfx_comp_short_mask_t {
  NRFX_COMP_SHORT_STOP_AFTER_CROSS_EVT = COMP_SHORTS_CROSS_STOP_Msk,
  NRFX_COMP_SHORT_STOP_AFTER_UP_EVT = COMP_SHORTS_UP_STOP_Msk,
  NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT = COMP_SHORTS_DOWN_STOP_Msk
}
 COMP shortcut masks. More...
 
enum  nrfx_comp_evt_en_mask_t {
  NRFX_COMP_EVT_EN_CROSS_MASK = COMP_INTENSET_CROSS_Msk,
  NRFX_COMP_EVT_EN_UP_MASK = COMP_INTENSET_UP_Msk,
  NRFX_COMP_EVT_EN_DOWN_MASK = COMP_INTENSET_DOWN_Msk,
  NRFX_COMP_EVT_EN_READY_MASK = COMP_INTENSET_READY_Msk
}
 COMP events masks. More...
 

Functions

nrfx_err_t nrfx_comp_init (nrfx_comp_config_t const *p_config, nrfx_comp_event_handler_t event_handler)
 Function for initializing the COMP driver. More...
 
void nrfx_comp_uninit (void)
 Function for uninitializing the COMP driver. More...
 
void nrfx_comp_pin_select (nrf_comp_input_t psel)
 Function for setting the analog input. More...
 
void nrfx_comp_start (uint32_t comp_evt_en_mask, uint32_t comp_shorts_mask)
 Function for starting the COMP peripheral and interrupts. More...
 
void nrfx_comp_stop (void)
 Function for stopping the COMP peripheral. More...
 
uint32_t nrfx_comp_sample (void)
 Function for copying the current state of the comparator result to the RESULT register. More...
 
__STATIC_INLINE uint32_t nrfx_comp_task_address_get (nrf_comp_task_t task)
 Function for getting the address of a COMP task. More...
 
__STATIC_INLINE uint32_t nrfx_comp_event_address_get (nrf_comp_event_t event)
 Function for getting the address of a COMP event. More...
 

Detailed Description

Comparator (COMP) peripheral driver.

Macro Definition Documentation

#define NRFX_COMP_CONFIG_TH
Value:
{ \
.th_down = NRFX_VOLTAGE_THRESHOLD_TO_INT(0.5, 1.8), \
.th_up = NRFX_VOLTAGE_THRESHOLD_TO_INT(1.5, 1.8) \
}

COMP threshold default configuration.

#define NRFX_COMP_DEFAULT_CONFIG (   _input)
Value:

COMP driver default configuration including the COMP HAL configuration.

#define NRFX_VOLTAGE_THRESHOLD_TO_INT (   vol,
  ref 
)    (uint8_t)(((vol) > ((ref) / 64)) ? (NRFX_ROUNDED_DIV((vol) * 64,(ref)) - 1) : 0)

Macro for converting the threshold voltage to an integer value (needed by the COMP_TH register).

Parameters
[in]volVoltage to be changed to COMP_TH register value. This value must not be smaller than reference voltage divided by 64.
[in]refReference voltage.

Typedef Documentation

typedef void(* nrfx_comp_event_handler_t)(nrf_comp_event_t event)

COMP event handler function type.

Parameters
[in]eventCOMP event.

Enumeration Type Documentation

COMP events masks.

Enumerator
NRFX_COMP_EVT_EN_CROSS_MASK 

CROSS event (generated after VIN+ == VIN-).

NRFX_COMP_EVT_EN_UP_MASK 

UP event (generated when VIN+ crosses VIN- while increasing).

NRFX_COMP_EVT_EN_DOWN_MASK 

DOWN event (generated when VIN+ crosses VIN- while decreasing).

NRFX_COMP_EVT_EN_READY_MASK 

READY event (generated when the module is ready).

COMP shortcut masks.

Enumerator
NRFX_COMP_SHORT_STOP_AFTER_CROSS_EVT 

Shortcut between the CROSS event and the STOP task.

NRFX_COMP_SHORT_STOP_AFTER_UP_EVT 

Shortcut between the UP event and the STOP task.

NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT 

Shortcut between the DOWN event and the STOP task.

Function Documentation

__STATIC_INLINE uint32_t nrfx_comp_event_address_get ( nrf_comp_event_t  event)

Function for getting the address of a COMP event.

Parameters
[in]eventCOMP event.
Returns
Address of the given COMP event.
nrfx_err_t nrfx_comp_init ( nrfx_comp_config_t const *  p_config,
nrfx_comp_event_handler_t  event_handler 
)

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 nrfx_comp_start() after initialization.

Parameters
[in]p_configPointer to the structure with the initial configuration.
[in]event_handlerEvent handler provided by the user. Must not be NULL.
Return values
NRFX_SUCCESSInitialization was successful.
NRFX_ERROR_INVALID_STATEThe driver has already been initialized.
NRFX_ERROR_BUSYThe LPCOMP peripheral is already in use. This is possible only if Peripheral Resource Sharing (PRS) module is enabled.
void nrfx_comp_pin_select ( nrf_comp_input_t  psel)

Function for setting the analog input.

Parameters
[in]pselCOMP analog pin selection.
uint32_t nrfx_comp_sample ( void  )

Function for copying the current state of the comparator result to the RESULT register.

Return values
0The input voltage is below the threshold (VIN+ < VIN-).
1The input voltage is above the threshold (VIN+ > VIN-).
void nrfx_comp_start ( uint32_t  comp_evt_en_mask,
uint32_t  comp_shorts_mask 
)

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.

Parameters
[in]comp_evt_en_maskMask of events to be enabled. This parameter is to be built as an OR of elements from nrfx_comp_evt_en_mask_t.
[in]comp_shorts_maskMask of shortcuts to be enabled. This parameter is to be built as an OR of elements from nrfx_comp_short_mask_t.
See Also
nrfx_comp_init
void nrfx_comp_stop ( void  )

Function for stopping the COMP peripheral.

Before calling this function, the driver must be enabled. This function disables the COMP peripheral and its interrupts.

See Also
nrfx_comp_uninit
__STATIC_INLINE uint32_t nrfx_comp_task_address_get ( nrf_comp_task_t  task)

Function for getting the address of a COMP task.

Parameters
[in]taskCOMP task.
Returns
Address of the given COMP task.
void nrfx_comp_uninit ( void  )

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 nrfx_comp_init() if you want to use it.

See Also
nrfx_comp_stop

Documentation feedback | Developer Zone | Subscribe | Updated