diff --git a/adc.hpp b/adc.hpp index a2f0d57..5d76a28 100644 --- a/adc.hpp +++ b/adc.hpp @@ -12,7 +12,7 @@ namespace adc { namespace detail { -extern void (*fnAdcIntHandler)(uint16_t); +extern void (*fnAdcIntHandler)(const uint16_t &); using reg_ptr_t = volatile uint8_t *; @@ -46,6 +46,10 @@ class AdcImpl { constexpr auto ctrlStatB = calcCtrlStatB(); *getRegPtr() = ctrlStatB; + + if constexpr (Cfg::MODE == Mode::FREE_RUNNING) { + *getRegPtr() |= 1 << ControlFlagsA::START_CONV; + } } static constexpr auto calcRef() @@ -85,9 +89,10 @@ class AdcImpl { { uint8_t ctrlStatA = 1 << ControlFlagsA::ENABLE; - if constexpr (Cfg::MODE == Mode::AUTO) { + if constexpr (Cfg::MODE == Mode::AUTO || Cfg::MODE == Mode::FREE_RUNNING) { ctrlStatA |= 1 << ControlFlagsA::AUTO_TRIGGER; - } else if (interruptEnable) { + } + if (interruptEnable) { ctrlStatA |= 1 << ControlFlagsA::CONV_COMPLETE_INT_ENABLE; } @@ -125,7 +130,7 @@ class Adc { template class Adc : public detail::AdcImpl { - using callback_t = void (*)(uint16_t); + using callback_t = void (*)(const uint16_t &); public: static_assert(detail::supports_adc_v, "Pin does not support ADC"); @@ -197,7 +202,7 @@ namespace detail { #if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__) -void (*fnAdcIntHandler)(uint16_t) = nullptr; +void (*fnAdcIntHandler)(const uint16_t &) = nullptr; ISR(ADC_vect) {