24#include "boards/board_traits.h"
25#include <avr/interrupt.h>
39#define REGISTER_INT_ISR_METHOD(INT_NUM, PIN, HANDLER, CALLBACK) \
40 ISR(CAT3(INT, INT_NUM, _vect)) \
42 interrupt::isr_handler_int::int_method<INT_NUM, PIN, HANDLER, CALLBACK>(); \
54#define REGISTER_INT_ISR_FUNCTION(INT_NUM, PIN, CALLBACK) \
55 ISR(CAT3(INT, INT_NUM, _vect)) \
57 interrupt::isr_handler_int::int_function<INT_NUM, PIN, CALLBACK>(); \
69#define REGISTER_INT_ISR_EMPTY(INT_NUM, PIN) \
70 extern "C" void CAT3(INT, INT_NUM, _vect)(void) NAKED_SIGNAL; \
71 void CAT3(INT, INT_NUM, _vect)(void) \
73 interrupt::isr_handler_int::check_int_pin<INT_NUM, PIN>(); \
74 __asm__ __volatile__("reti" ::); \
83#define DECL_INT_ISR_HANDLERS_FRIEND \
84 friend struct interrupt::isr_handler_int; \
95 return board_traits::ExternalInterruptPin_trait<EXT>::ACTUAL_PIN;
131 template<board::ExternalInterruptPin EXTPIN_>
class INTSignal
140 using INT_TRAIT = board_traits::ExternalInterruptPin_trait<EXTPIN>;
172 synchronized INT_TRAIT::EICR_ =
173 (INT_TRAIT::EICR_ &
bits::COMPL(INT_TRAIT::EICR_MASK)) | (uint8_t(trigger) & INT_TRAIT::EICR_MASK);
185 synchronized INT_TRAIT::EIMSK_ |= INT_TRAIT::EIMSK_MASK;
197 synchronized INT_TRAIT::EIMSK_ &=
bits::COMPL(INT_TRAIT::EIMSK_MASK);
211 synchronized INT_TRAIT::EIFR_ |= INT_TRAIT::EIFR_MASK;
223 INT_TRAIT::EICR_ = (INT_TRAIT::EICR_ &
bits::COMPL(INT_TRAIT::EICR_MASK))
224 | (uint8_t(trigger) & INT_TRAIT::EICR_MASK);
236 INT_TRAIT::EIMSK_ |= INT_TRAIT::EIMSK_MASK;
248 INT_TRAIT::EIMSK_ &=
bits::COMPL(INT_TRAIT::EIMSK_MASK);
262 INT_TRAIT::EIFR_ |= INT_TRAIT::EIFR_MASK;
271 struct isr_handler_int
273 template<u
int8_t INT_NUM_, board::ExternalInterruptPin INT_PIN_>
static void check_int_pin()
275 static_assert(board_traits::ExternalInterruptPin_trait<INT_PIN_>::INT == INT_NUM_,
276 "PIN INT number must match INT_NUM");
279 template<u
int8_t INT_NUM_, board::ExternalInterruptPin INT_PIN_,
typename HANDLER_,
void (HANDLER_::*CALLBACK_)()>
280 static void int_method()
283 check_int_pin<INT_NUM_, INT_PIN_>();
285 interrupt::CallbackHandler<void (HANDLER_::*)(), CALLBACK_>::call();
288 template<u
int8_t INT_NUM_, board::ExternalInterruptPin INT_PIN_,
void (*CALLBACK_)()>
static void int_function()
291 check_int_pin<INT_NUM_, INT_PIN_>();
Handler of an External Interrupt.
void enable_()
Enable interrupts for this external interrupt pin.
static constexpr const board::ExternalInterruptPin EXTPIN
The External Interrupt pin managed by this INTSignal.
static constexpr const board::DigitalPin PIN
The actual connected pin managed by this INTSignal.
void clear()
Clear the interrupt flag for this external interrupt pin.
void set_trigger(InterruptTrigger trigger)
Change the kind of level event that shall trigger an External Interrupt for EXTPIN.
void clear_()
Clear the interrupt flag for this external interrupt pin.
INTSignal(InterruptTrigger trigger=InterruptTrigger::ANY_CHANGE)
Create a handler for EXTPIN external interrupt pin.
void disable()
Disable interrupts for this external interrupt pin.
void enable()
Enable interrupts for this external interrupt pin.
void disable_()
Disable interrupts for this external interrupt pin.
void set_trigger_(InterruptTrigger trigger)
Enable interrupts for this external interrupt pin.
#define INLINE
Specific GCC attribute to force the compiler to always inline code of a given function.
General API for handling AVR interrupt vectors.
static constexpr uint8_t COMPL(uint8_t value)
Return the uint8_t 2-complement of a byte.
Defines all types and constants specific to support a specific MCU target.
DigitalPin
Defines all available digital input/output pins of the target MCU.
constexpr DigitalPin EXT_PIN() INLINE
Convert an ExternalInterruptPin to the matching DigitalPin.
ExternalInterruptPin
Defines all digital output pins of target MCU, usable as direct external interrupt pins.
Defines API to handle AVR interruptions.
InterruptTrigger
Kind of change that will trigger an External Interrupt for a given pin.
@ ANY_CHANGE
Interrupt is triggered whenever pin level is changing (rising or falling).
@ FALLING_EDGE
Interrupt is triggered whenever pin level is falling from high to low.
@ LOW_LEVEL
Interrupt is triggered whenever pin level is low.
@ RISING_EDGE
Interrupt is triggered whenever pin level is rising from low to high.
General utilities API that have broad application in programs.