Interrupt Pin#

Hardware Interface#

Defined in namespace hal

#include <libhal/interrupt_pin.hpp>

class interrupt_pin#

Digital interrupt pin hardware abstraction.

Use this to automatically call a function when a pin’s state has transitioned.

The transition states are:

  • falling edge: the pin reads a transitions from HIGH to LOW

  • rising edge: the pin reads a transitions from LOW to HIGH

  • both: the pin reads any state change

Subclassed by hal::soft::inert_interrupt_pin

Public Types

enum class trigger_edge#

The condition in which an interrupt it’s triggered.

Values:

enumerator falling#

Trigger the interrupt when a pin transitions from HIGH voltage to LOW voltage.

enumerator rising#

Trigger the interrupt when a pin transitions from LOW voltage to HIGH voltage.

enumerator both#

Trigger the interrupt when a pin transitions it state.

using handler = void(bool p_state)#

Interrupt pin handler.

param p_state - if true state of the pin when the interrupt was triggered was HIGH, otherwise LOW

Public Functions

inline void configure(const settings &p_settings)#

Configure the interrupt pin to match the settings supplied.

Parameters:

p_settings – - settings to apply to interrupt pin

Throws:

hal::operation_not_supported – - if the settings could not be achieved.

inline void on_trigger(hal::callback<handler> p_callback)#

Set the callback for when the interrupt occurs.

Any state transitions before this function is called are lost.

Parameters:

p_callback – - function to execute when the trigger condition occurs.

struct settings#

Generic settings for interrupt pins.

Public Members

pin_resistor resistor = pin_resistor::pull_up#

Pull resistor for an interrupt pin.

In general, it is highly advised to either set the pull resistor to something other than β€œnone” or to attach an external pull up resistor to the interrupt pin in order to prevent random interrupt from firing.

trigger_edge trigger = trigger_edge::rising#

The trigger condition that will signal the system to run the callback.

Utilities#

Defined in namespace hal

#include <libhal-util/interrupt_pin.hpp>

group InterruptPin

Functions

constexpr auto operator==(const interrupt_pin::settings &p_lhs, const interrupt_pin::settings &p_rhs)#

Compares two interrupt pin states, compares both their trigger and resistor.

Parameters:
  • p_lhs – An interrupt pin

  • p_rhs – An interrupt pin

Returns:

A boolean if they are the same or not.