From 045efedd45145aa43eabea96d54994a1d0657a77 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 21 Feb 2020 19:08:47 +0100 Subject: [PATCH] Added config and basic interface --- adc.hpp | 43 +++++++++++++++++++++++++++++++++++++++---- config.hpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 config.hpp diff --git a/adc.hpp b/adc.hpp index e181563..0f8adab 100644 --- a/adc.hpp +++ b/adc.hpp @@ -1,23 +1,58 @@ #pragma once +#include "config.hpp" #include "hardware.hpp" +#include + #include "../io/io.hpp" namespace adc { -template -struct Config { +template +class Adc { + public: + static_assert(sizeof(Input) == -1, "Invalid input source selected"); }; template -class Adc { +class Adc { + private: + using callback_t = void (*)(uint16_t); + public: static_assert(detail::supports_adc_v, "Pin does not support ADC"); - void read() {} + Adc() {} + + Adc(callback_t callback) : m_callback(callback) {} + + uint16_t read() + { + return 0; + } private: + const callback_t m_callback = nullptr; +}; + +template +class Adc { + private: + using callback_t = void (*)(uint16_t); + + public: + Adc() {} + + Adc(callback_t callback) : m_callback(callback) {} + + uint16_t read() + { + return 0; + } + + private: + const callback_t m_callback = nullptr; }; } // namespace adc diff --git a/config.hpp b/config.hpp new file mode 100644 index 0000000..b3f83c3 --- /dev/null +++ b/config.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include + +namespace adc { + +enum class Mode { + SINGLE, + AUTO, + FREE_RUNNING, +}; + +enum class TriggerSource { + FREE_RUNNING, + ANALOG_COMP, + EXTERNAL_INT_0, + TIMER0_COMP_A, + TIMER0_OVERFLOW, + TIMER1_COMP_B, + TIMER1_OVERFLOW, + TIMER1_CAPTURE, +}; + +template +struct AutoMode { + static constexpr auto SRC = src; +}; + +struct FreeRunningMode { +}; + +struct SingleMode { +}; + +enum class VoltageRef { + EXTERNAL, + AVCC, + INTERNAL, +}; + +enum class InputSource { + TEMP, + VBG, + GND, +}; + +template +struct Config { +}; + +} // namespace adc