Fixed free running mode
This commit is contained in:
parent
5d38b97254
commit
7fe32b9717
15
adc.hpp
15
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");
|
||||||
@ -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)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user