From f7f02b76a85c9b3912783c12f8123c5ce2e6fbed Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sun, 9 Feb 2020 20:36:25 +0100 Subject: [PATCH] Added compile time check to verify pin supports ADC --- adc.hpp | 2 ++ hardware.hpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/adc.hpp b/adc.hpp index 23598c6..e181563 100644 --- a/adc.hpp +++ b/adc.hpp @@ -13,6 +13,8 @@ struct Config { template class Adc { public: + static_assert(detail::supports_adc_v, "Pin does not support ADC"); + void read() {} private: diff --git a/hardware.hpp b/hardware.hpp index 5cba31d..0b67e2a 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -2,7 +2,7 @@ #include -#include +#include "../io/io.hpp" namespace adc { @@ -70,6 +70,14 @@ enum class ControlFlagsDigInDis { DIGITAL_INPUT_DISABLE_5 = ADC5D, }; +template +struct supports_adc { + static constexpr auto value = (io::detail::getBus(pin) == io::Bus::C) ? true : false; +}; + +template +constexpr auto supports_adc_v = supports_adc::value; + #pragma pop_macro("_MMIO_BYTE") #else