21#ifndef ANALOGCOMPARATOR_HH
22#define ANALOGCOMPARATOR_HH
24#include "boards/board_traits.h"
37#define REGISTER_ANALOG_COMPARE_ISR_FUNCTION(CALLBACK) \
38 ISR(ANALOG_COMP_vect) \
53#define REGISTER_ANALOG_COMPARE_ISR_METHOD(HANDLER, CALLBACK) \
54 ISR(ANALOG_COMP_vect) \
56 interrupt::CallbackHandler<void (HANDLER::*)(), CALLBACK>::call(); \
67#define REGISTER_ANALOG_COMPARE_ISR_EMPTY() EMPTY_INTERRUPT(ANALOG_COMP_vect)
75#define DECL_ANALOG_COMPARE_ISR_HANDLERS_FRIEND friend void ::ANALOG_COMP_vect(void);
119 static constexpr board_traits::REG8 ACSR_{ACSR};
120 using GLOBAL_TRAIT = board_traits::GlobalAnalogPin_trait;
161 template<board::AnalogPin INPUT1 = board::AnalogPin::NONE,
bool INPUT0_BANDGAP = false>
164 synchronized begin_<INPUT1, INPUT0_BANDGAP>(mode, trigger_icp);
231 template<board::AnalogPin INPUT1 = board::AnalogPin::NONE,
bool INPUT0_BANDGAP = false>
234 using ATRAIT = board_traits::AnalogPin_trait<INPUT1>;
235 static_assert(ATRAIT::IS_ANALOG_PIN || (INPUT1 == board::AnalogPin::NONE),
"INPUT must not be TEMP!");
236 static_assert((INPUT1 != board::AnalogPin::NONE) || GLOBAL_TRAIT::HAS_AIN1,
"Target has no AIN1 pin!");
237 static_assert(GLOBAL_TRAIT::HAS_AIN0 || INPUT0_BANDGAP,
"Target has no AIN0 hence INPUT0_BANDGAP must be true");
239 GLOBAL_TRAIT::ADCSRB_ = ((INPUT1 == board::AnalogPin::NONE) ? 0 :
bits::BV8(ACME));
240 GLOBAL_TRAIT::ADCSRA_ = ATRAIT::MUX_MASK2;
241 GLOBAL_TRAIT::ADMUX_ = ATRAIT::MUX_MASK1;
242 ACSR_ = (INPUT0_BANDGAP ?
bits::BV8(ACBG) : 0U) |
244 (trigger_icp ? GLOBAL_TRAIT::ICP_TRIGGER : 0U);
261 GLOBAL_TRAIT::ADCSRB_ = 0;
262 GLOBAL_TRAIT::ADCSRA_ = 0;
263 GLOBAL_TRAIT::ADMUX_ = 0;
Handler of the Analog Comparator feature.
void begin(ComparatorInterrupt mode=ComparatorInterrupt::NONE, bool trigger_icp=false)
Start operations of the Analog Comparator.
void begin_(ComparatorInterrupt mode=ComparatorInterrupt::NONE, bool trigger_icp=false)
Start operations of the Analog Comparator.
bool output() const
Get current output of Analog Comparator.
void end()
Stop operations of the Analog Comparator.
void end_()
Stop operations of the Analog Comparator.
General API for handling AVR interrupt vectors.
Defines all API to manipulate analog input/output.
ComparatorInterrupt
Kind of change that will trigger an Analog Comparator Interrupt.
@ TOGGLE
An interrupt is generated everytime the Analog Comparator output changes.
@ FALLING_EDGE
An interrupt is generated everytime the Analog Comparator output changes from 1 to 0.
@ NONE
No interrupt will be generated by the Anolog Comparator.
@ RISING_EDGE
An interrupt is generated everytime the Analog Comparator output changes from 0 to 1.
static constexpr uint8_t BV8(uint8_t bit)
Create a uint8_t bitmask for the given bit number.
General utilities API that have broad application in programs.