Added compile time check to verify pin supports ADC

This commit is contained in:
BlackMark 2020-02-09 20:36:25 +01:00
parent 2f54f9217f
commit f7f02b76a8
2 changed files with 11 additions and 1 deletions

View File

@ -13,6 +13,8 @@ struct Config {
template <typename Cfg, io::P pin> template <typename Cfg, io::P pin>
class Adc { class Adc {
public: public:
static_assert(detail::supports_adc_v<pin>, "Pin does not support ADC");
void read() {} void read() {}
private: private:

View File

@ -2,7 +2,7 @@
#include <stdint.h> #include <stdint.h>
#include <avr/io.h> #include "../io/io.hpp"
namespace adc { namespace adc {
@ -70,6 +70,14 @@ enum class ControlFlagsDigInDis {
DIGITAL_INPUT_DISABLE_5 = ADC5D, DIGITAL_INPUT_DISABLE_5 = ADC5D,
}; };
template <io::P pin>
struct supports_adc {
static constexpr auto value = (io::detail::getBus(pin) == io::Bus::C) ? true : false;
};
template <io::P pin>
constexpr auto supports_adc_v = supports_adc<pin>::value;
#pragma pop_macro("_MMIO_BYTE") #pragma pop_macro("_MMIO_BYTE")
#else #else