Added config and basic interface

This commit is contained in:
BlackMark 2020-02-21 19:08:47 +01:00
parent f7f02b76a8
commit 045efedd45
2 changed files with 90 additions and 4 deletions

43
adc.hpp
View File

@ -1,23 +1,58 @@
#pragma once #pragma once
#include "config.hpp"
#include "hardware.hpp" #include "hardware.hpp"
#include <stdint.h>
#include "../io/io.hpp" #include "../io/io.hpp"
namespace adc { namespace adc {
template <typename... T> template <typename Cfg, typename Input, Input src>
struct Config { class Adc {
public:
static_assert(sizeof(Input) == -1, "Invalid input source selected");
}; };
template <typename Cfg, io::P pin> template <typename Cfg, io::P pin>
class Adc { class Adc<Cfg, io::P, pin> {
private:
using callback_t = void (*)(uint16_t);
public: public:
static_assert(detail::supports_adc_v<pin>, "Pin does not support ADC"); static_assert(detail::supports_adc_v<pin>, "Pin does not support ADC");
void read() {} Adc() {}
Adc(callback_t callback) : m_callback(callback) {}
uint16_t read()
{
return 0;
}
private: private:
const callback_t m_callback = nullptr;
};
template <typename Cfg, InputSource src>
class Adc<Cfg, InputSource, src> {
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 } // namespace adc

51
config.hpp Normal file
View File

@ -0,0 +1,51 @@
#pragma once
#include <stdint.h>
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 <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 {
};
} // namespace adc