74 lines
1.3 KiB
C++
74 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
namespace adc {
|
|
|
|
namespace detail {
|
|
|
|
enum class Mode {
|
|
SINGLE,
|
|
AUTO,
|
|
FREE_RUNNING,
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
enum class TriggerSource {
|
|
FREE_RUNNING,
|
|
ANALOG_COMP,
|
|
EXTERNAL_INT_0,
|
|
TIMER0_COMP_A,
|
|
TIMER0_OVERFLOW,
|
|
TIMER1_COMP_B,
|
|
TIMER1_OVERFLOW,
|
|
TIMER1_CAPTURE,
|
|
};
|
|
|
|
template <TriggerSource src = TriggerSource::FREE_RUNNING>
|
|
struct AutoMode {
|
|
static constexpr auto SRC = src;
|
|
};
|
|
|
|
struct FreeRunningMode {
|
|
};
|
|
|
|
struct SingleMode {
|
|
};
|
|
|
|
enum class VoltageRef {
|
|
EXTERNAL,
|
|
AVCC,
|
|
INTERNAL,
|
|
};
|
|
|
|
enum class InputSource {
|
|
TEMP,
|
|
VBG,
|
|
GND,
|
|
};
|
|
|
|
template <class Mode, VoltageRef vref = VoltageRef::AVCC, uint8_t prescaler = 128>
|
|
struct Config {
|
|
static constexpr auto MODE = detail::Mode::AUTO;
|
|
static constexpr auto TRIGGER_SRC = Mode::SRC;
|
|
static constexpr auto VREF = vref;
|
|
static constexpr auto PRESCALER = prescaler;
|
|
};
|
|
|
|
template <VoltageRef vref, uint8_t prescaler>
|
|
struct Config<FreeRunningMode, vref, prescaler> {
|
|
static constexpr auto MODE = detail::Mode::FREE_RUNNING;
|
|
static constexpr auto VREF = vref;
|
|
static constexpr auto PRESCALER = prescaler;
|
|
};
|
|
|
|
template <VoltageRef vref, uint8_t prescaler>
|
|
struct Config<SingleMode, vref, prescaler> {
|
|
static constexpr auto MODE = detail::Mode::SINGLE;
|
|
static constexpr auto VREF = vref;
|
|
static constexpr auto PRESCALER = prescaler;
|
|
};
|
|
|
|
} // namespace adc
|