Compare commits

...

3 Commits

Author SHA1 Message Date
5e9dac872a Fix wrong callback signature 2020-04-13 00:03:02 +02:00
7fe32b9717 Fixed free running mode 2020-04-06 19:42:17 +02:00
5d38b97254 Fixed indentation 2020-03-29 04:17:47 +02:00

35
adc.hpp
View File

@@ -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<Registers::CTRL_STAT_B_ADDR>() = ctrlStatB;
if constexpr (Cfg::MODE == Mode::FREE_RUNNING) {
*getRegPtr<Registers::CTRL_STAT_A_ADDR>() |= 1 << ControlFlagsA::START_CONV;
}
}
static constexpr auto calcRef()
@@ -69,15 +73,15 @@ class AdcImpl {
static_assert(validPrescaler, "Invalid prescaler");
// clang-format off
switch (Cfg::PRESCALER) {
case 2: return 1;
case 4: return 2;
case 8: return 3;
case 16: return 4;
case 32: return 5;
case 64: return 6;
case 128: return 7;
}
switch (Cfg::PRESCALER) {
case 2: return 1;
case 4: return 2;
case 8: return 3;
case 16: return 4;
case 32: return 5;
case 64: return 6;
case 128: return 7;
}
// clang-format on
}
@@ -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 <typename Cfg, io::P pin>
class Adc<Cfg, io::P, pin> : public detail::AdcImpl<Cfg> {
using callback_t = void (*)(uint16_t);
using callback_t = void (*)(const uint16_t &);
public:
static_assert(detail::supports_adc_v<pin>, "Pin does not support ADC");
@@ -151,7 +156,7 @@ class Adc<Cfg, io::P, pin> : public detail::AdcImpl<Cfg> {
template <typename Cfg, InputSource src>
class Adc<Cfg, InputSource, src> : public detail::AdcImpl<Cfg> {
using callback_t = void (*)(uint16_t);
using callback_t = void (*)(const uint16_t &);
public:
static void init(callback_t callback)
@@ -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)
{