COMP (LP Comparator block)

group group_hal_comp_lp

Implementation of the analog comparator (COMP) driver on top of the LP (low power) comparator.

Functions

cy_rslt_t _cyhal_comp_lp_init(cyhal_comp_t *obj, cyhal_gpio_t vin_p, cyhal_gpio_t vin_m, cyhal_gpio_t output, cyhal_comp_config_t *cfg)

Initialize the Comparator peripheral for a LP-based comparator.

Parameters
  • obj[out] Pointer to a Comparator object. The caller must allocate the memory for this object but the init function will initialize its contents.

  • vin_p[in] Non-inverting input pin

  • vin_m[in] Inverting input pin

  • output[in] Comparator output pin. May be NC.

  • cfg[in] Configuration structure

Returns

The status of the init request

void _cyhal_comp_lp_free(cyhal_comp_t *obj)

Deinitialize the Comparator peripheral for a LP-based comparator.

Parameters

obj[in] Comparator object

cy_rslt_t _cyhal_comp_lp_set_power(cyhal_comp_t *obj, cyhal_power_level_t power)

Changes the current operating power level of the comparator for a LP-based comparator.

If the power level is set to CYHAL_POWER_LEVEL_OFF, the comparator will be powered-off but it will retain its configuration, so it is not necessary to reconfigure it when changing the power level from CYHAL_POWER_LEVEL_OFF to any other value.

Parameters
  • obj[in] Comparator object

  • power[in] The power level to set

Returns

The status of the set power request

cy_rslt_t _cyhal_comp_lp_configure(cyhal_comp_t *obj, cyhal_comp_config_t *cfg)

Reconfigure the Comparator for a LP-based comparator.

This retains the powered state of the comparator. Depending on the implementation, it may be necessary to temporarily deconfigure and/or power off the comparator in order to apply the new configuration. However, if the comparator is powered-off when this function is called, it will remain powered-off after it returns. Likewise, if the comparator is powered-on when this function is called, it will remain powered-on after it returns.

Parameters
  • obj[in] Comparator object

  • cfg[in] New configuration to apply

Returns

The status of the configure request

bool _cyhal_comp_lp_read(cyhal_comp_t *obj)

Reads the Comparator state for a LP-based comparator.

Parameters

obj[in] Comparator object

Returns

The Comparator state. True if the non-inverting pin voltage is greater than the inverting pin voltage, false otherwise.

void _cyhal_comp_lp_enable_event(cyhal_comp_t *obj, cyhal_comp_event_t event, uint8_t intr_priority, bool enable)

Enable or Disable a Comparator event for a LP-based comparator.

When an enabled event occurs, the function specified by cyhal_comp_register_callback will be called.

Parameters
  • obj[in] Comparator object

  • event[in] Comparator event

  • intr_priority[in] Priority for NVIC interrupt events

  • enable[in] True to turn on event, False to turn off