LPCOMP HAL

group nrf_lpcomp_hal

Hardware access layer for managing the Low Power Comparator (LPCOMP) peripheral.

Defines

NRF_LPCOMP_HAS_AIN_AS_PIN

Symbol indicating whether the configuration of analog input using pin number is present.

Typedefs

typedef uint32_t nrf_lpcomp_input_t

LPCOMP input selection.

Enums

enum nrf_lpcomp_ref_t

LPCOMP reference selection.

Values:

enumerator NRF_LPCOMP_REF_SUPPLY_1_8

Use supply with a 1/8 prescaler as reference.

enumerator NRF_LPCOMP_REF_SUPPLY_2_8

Use supply with a 2/8 prescaler as reference.

enumerator NRF_LPCOMP_REF_SUPPLY_3_8

Use supply with a 3/8 prescaler as reference.

enumerator NRF_LPCOMP_REF_SUPPLY_4_8

Use supply with a 4/8 prescaler as reference.

enumerator NRF_LPCOMP_REF_SUPPLY_5_8

Use supply with a 5/8 prescaler as reference.

enumerator NRF_LPCOMP_REF_SUPPLY_6_8

Use supply with a 6/8 prescaler as reference.

enumerator NRF_LPCOMP_REF_SUPPLY_7_8

Use supply with a 7/8 prescaler as reference.

enum nrf_lpcomp_detect_t

LPCOMP detection type selection.

Values:

enumerator NRF_LPCOMP_DETECT_CROSS

Generate ANADETEC on crossing, both upwards and downwards crossing.

enumerator NRF_LPCOMP_DETECT_UP

Generate ANADETEC on upwards crossing only.

enumerator NRF_LPCOMP_DETECT_DOWN

Generate ANADETEC on downwards crossing only.

enum nrf_lpcomp_task_t

LPCOMP tasks.

Values:

enumerator NRF_LPCOMP_TASK_START

LPCOMP start sampling task.

enumerator NRF_LPCOMP_TASK_STOP

LPCOMP stop sampling task.

enumerator NRF_LPCOMP_TASK_SAMPLE

Sample comparator value.

enum nrf_lpcomp_event_t

LPCOMP events.

Values:

enumerator NRF_LPCOMP_EVENT_READY

LPCOMP is ready and output is valid.

enumerator NRF_LPCOMP_EVENT_DOWN

Input voltage crossed the threshold going down.

enumerator NRF_LPCOMP_EVENT_UP

Input voltage crossed the threshold going up.

enumerator NRF_LPCOMP_EVENT_CROSS

Input voltage crossed the threshold in any direction.

enum nrf_lpcomp_int_mask_t

LPCOMP interrupts.

Values:

enumerator NRF_LPCOMP_INT_READY_MASK

Interrupt on READY event.

enumerator NRF_LPCOMP_INT_DOWN_MASK

Interrupt on DOWN event.

enumerator NRF_LPCOMP_INT_UP_MASK

Interrupt on UP event.

enumerator NRF_LPCOMP_INT_CROSS_MASK

Interrupt on CROSS event.

enum nrf_lpcomp_short_mask_t

LPCOMP shortcut masks.

Values:

enumerator NRF_LPCOMP_SHORT_CROSS_STOP_MASK

Shortcut between CROSS event and STOP task.

enumerator NRF_LPCOMP_SHORT_UP_STOP_MASK

Shortcut between UP event and STOP task.

enumerator NRF_LPCOMP_SHORT_DOWN_STOP_MASK

Shortcut between DOWN event and STOP task.

enumerator NRF_LPCOMP_SHORT_READY_STOP_MASK

Shortcut between READY event and STOP task.

enumerator NRF_LPCOMP_SHORT_READY_SAMPLE_MASK

Shortcut between READY event and SAMPLE task.

enum nrf_lpcomp_hysteresis_t

LPCOMP hysteresis.

Values:

enumerator NRF_LPCOMP_HYST_NOHYST

Comparator hysteresis disabled.

enumerator NRF_LPCOMP_HYST_ENABLED

Comparator hysteresis enabled (typically 50 mV).

Functions

NRF_STATIC_INLINE void nrf_lpcomp_configure(NRF_LPCOMP_Type *p_reg, nrf_lpcomp_config_t const *p_config)

Function for configuring LPCOMP.

This function powers on LPCOMP and configures it. LPCOMP is in DISABLE state after configuration, so it must be enabled before using it. All shorts are inactive, events are cleared, and LPCOMP is stopped.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • p_config[in] Configuration.

NRF_STATIC_INLINE void nrf_lpcomp_input_select(NRF_LPCOMP_Type *p_reg, nrf_lpcomp_input_t input)

Function for selecting the LPCOMP input.

This function selects the active input of LPCOMP.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • input[in] Input to be selected.

NRF_STATIC_INLINE void nrf_lpcomp_enable(NRF_LPCOMP_Type *p_reg)

Function for enabling the Low Power Comparator.

This function enables LPCOMP.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE void nrf_lpcomp_disable(NRF_LPCOMP_Type *p_reg)

Function for disabling the Low Power Comparator.

This function disables LPCOMP.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

NRF_STATIC_INLINE uint32_t nrf_lpcomp_result_get(NRF_LPCOMP_Type const *p_reg)

Function for getting the last LPCOMP compare result.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

Returns:

The last compare result. If 0 then VIN+ < VIN-, if 1 then the opposite.

NRF_STATIC_INLINE void nrf_lpcomp_int_enable(NRF_LPCOMP_Type *p_reg, uint32_t mask)

Function for enabling interrupts from LPCOMP.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be enabled.

NRF_STATIC_INLINE void nrf_lpcomp_int_disable(NRF_LPCOMP_Type *p_reg, uint32_t mask)

Function for disabling interrupts from LPCOMP.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be disabled.

NRF_STATIC_INLINE uint32_t nrf_lpcomp_int_enable_check(NRF_LPCOMP_Type const *p_reg, uint32_t mask)

Function for checking if the specified interrupts are enabled.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of interrupts to be checked.

Returns:

Mask of enabled interrupts.

NRF_STATIC_INLINE uint32_t nrf_lpcomp_task_address_get(NRF_LPCOMP_Type const *p_reg, nrf_lpcomp_task_t task)

Function for getting the address of the specified LPCOMP task register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] LPCOMP task.

Returns:

The address of the specified LPCOMP task.

NRF_STATIC_INLINE uint32_t nrf_lpcomp_event_address_get(NRF_LPCOMP_Type const *p_reg, nrf_lpcomp_event_t event)

Function for getting the address of the specified LPCOMP event register.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] LPCOMP event.

Returns:

The address of the specified LPCOMP event.

NRF_STATIC_INLINE void nrf_lpcomp_shorts_enable(NRF_LPCOMP_Type *p_reg, uint32_t mask)

Function for setting LPCOMP shorts.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of shortcuts.

NRF_STATIC_INLINE void nrf_lpcomp_shorts_disable(NRF_LPCOMP_Type *p_reg, uint32_t mask)

Function for clearing LPCOMP shorts by mask.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • mask[in] Mask of shortcuts.

NRF_STATIC_INLINE void nrf_lpcomp_task_trigger(NRF_LPCOMP_Type *p_reg, nrf_lpcomp_task_t task)

Function for setting the specified LPCOMP task.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • task[in] LPCOMP task to be set.

NRF_STATIC_INLINE void nrf_lpcomp_event_clear(NRF_LPCOMP_Type *p_reg, nrf_lpcomp_event_t event)

Function for clearing the specified LPCOMP event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] LPCOMP event to be cleared.

NRF_STATIC_INLINE bool nrf_lpcomp_event_check(NRF_LPCOMP_Type const *p_reg, nrf_lpcomp_event_t event)

Function for retrieving the state of the LPCOMP event.

Parameters:
  • p_reg[in] Pointer to the structure of registers of the peripheral.

  • event[in] Event to be checked.

Return values:
  • true – The event has been generated.

  • false – The event has not been generated.

struct nrf_lpcomp_config_t
#include <nrf_lpcomp.h>

LPCOMP configuration.

Public Members

nrf_lpcomp_ref_t reference

LPCOMP reference.

nrf_lpcomp_detect_t detection

LPCOMP detection type.

nrf_lpcomp_hysteresis_t hyst

LPCOMP hysteresis.