Compare commits
2 Commits
5d38b97254
...
5e9dac872a
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e9dac872a | |||
| 7fe32b9717 |
17
adc.hpp
17
adc.hpp
@@ -12,7 +12,7 @@ namespace adc {
|
|||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
extern void (*fnAdcIntHandler)(uint16_t);
|
extern void (*fnAdcIntHandler)(const uint16_t &);
|
||||||
|
|
||||||
using reg_ptr_t = volatile uint8_t *;
|
using reg_ptr_t = volatile uint8_t *;
|
||||||
|
|
||||||
@@ -46,6 +46,10 @@ class AdcImpl {
|
|||||||
|
|
||||||
constexpr auto ctrlStatB = calcCtrlStatB();
|
constexpr auto ctrlStatB = calcCtrlStatB();
|
||||||
*getRegPtr<Registers::CTRL_STAT_B_ADDR>() = ctrlStatB;
|
*getRegPtr<Registers::CTRL_STAT_B_ADDR>() = ctrlStatB;
|
||||||
|
|
||||||
|
if constexpr (Cfg::MODE == Mode::FREE_RUNNING) {
|
||||||
|
*getRegPtr<Registers::CTRL_STAT_A_ADDR>() |= 1 << ControlFlagsA::START_CONV;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr auto calcRef()
|
static constexpr auto calcRef()
|
||||||
@@ -85,9 +89,10 @@ class AdcImpl {
|
|||||||
{
|
{
|
||||||
uint8_t ctrlStatA = 1 << ControlFlagsA::ENABLE;
|
uint8_t ctrlStatA = 1 << ControlFlagsA::ENABLE;
|
||||||
|
|
||||||
if constexpr (Cfg::MODE == Mode::AUTO) {
|
if constexpr (Cfg::MODE == Mode::AUTO || Cfg::MODE == Mode::FREE_RUNNING) {
|
||||||
ctrlStatA |= 1 << ControlFlagsA::AUTO_TRIGGER;
|
ctrlStatA |= 1 << ControlFlagsA::AUTO_TRIGGER;
|
||||||
} else if (interruptEnable) {
|
}
|
||||||
|
if (interruptEnable) {
|
||||||
ctrlStatA |= 1 << ControlFlagsA::CONV_COMPLETE_INT_ENABLE;
|
ctrlStatA |= 1 << ControlFlagsA::CONV_COMPLETE_INT_ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +130,7 @@ class Adc {
|
|||||||
|
|
||||||
template <typename Cfg, io::P pin>
|
template <typename Cfg, io::P pin>
|
||||||
class Adc<Cfg, io::P, pin> : public detail::AdcImpl<Cfg> {
|
class Adc<Cfg, io::P, pin> : public detail::AdcImpl<Cfg> {
|
||||||
using callback_t = void (*)(uint16_t);
|
using callback_t = void (*)(const 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");
|
||||||
@@ -151,7 +156,7 @@ class Adc<Cfg, io::P, pin> : public detail::AdcImpl<Cfg> {
|
|||||||
|
|
||||||
template <typename Cfg, InputSource src>
|
template <typename Cfg, InputSource src>
|
||||||
class Adc<Cfg, InputSource, src> : public detail::AdcImpl<Cfg> {
|
class Adc<Cfg, InputSource, src> : public detail::AdcImpl<Cfg> {
|
||||||
using callback_t = void (*)(uint16_t);
|
using callback_t = void (*)(const uint16_t &);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void init(callback_t callback)
|
static void init(callback_t callback)
|
||||||
@@ -197,7 +202,7 @@ namespace detail {
|
|||||||
|
|
||||||
#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__)
|
#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__)
|
||||||
|
|
||||||
void (*fnAdcIntHandler)(uint16_t) = nullptr;
|
void (*fnAdcIntHandler)(const uint16_t &) = nullptr;
|
||||||
|
|
||||||
ISR(ADC_vect)
|
ISR(ADC_vect)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user