5#include <AH/STL/utility>
9#ifndef CS_CUSTOM_INTERRUPT_TO_INDEX
24 : pins(other.pins), direct_pins(std::move(other.direct_pins)) {
25 if (other.interrupts_in_use)
26 FATAL_ERROR(F(
"Cannot move from initialized AHEncoder."), 0x9311);
54 interrupt_t int1 = digitalPinToInterrupt(a.
pins[0]);
55 if (int1 != NOT_AN_INTERRUPT)
57 interrupt_t int2 = digitalPinToInterrupt(a.
pins[1]);
58 if (int2 != NOT_AN_INTERRUPT)
62 interrupt_t int1 = digitalPinToInterrupt(b.
pins[0]);
63 if (int1 != NOT_AN_INTERRUPT)
65 interrupt_t int2 = digitalPinToInterrupt(b.
pins[1]);
66 if (int2 != NOT_AN_INTERRUPT)
87 delayMicroseconds(2000);
97#if defined(ARDUINO_ARCH_MBED) && !defined(ARDUINO_ARCH_RP2040)
112 if (interrupt != NOT_AN_INTERRUPT) {
114 FATAL_ERROR(F(
"Multiple encoders on the same pin"), 0x7283);
119#ifdef ARDUINO_ARCH_RP2040
120 gpio_set_irq_enabled_with_callback(
121 interrupt, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE,
true,
122 [](uint gpio, uint32_t) {
134 if (interrupt != NOT_AN_INTERRUPT) {
135#ifdef ARDUINO_ARCH_RP2040
136 gpio_set_irq_enabled(interrupt, GPIO_IRQ_EDGE_FALL | GPIO_IRQ_EDGE_RISE,
139 detachInterrupt(interrupt);
static interrupt_index_t interruptToIndex(interrupt_index_t i)
void swap(AHEncoder &a, AHEncoder &b)
decltype(digitalPinToInterrupt(0)) interrupt_index_t
#define CS_ENCODER_ARGLIST_SIZE
Available number of interrupts.
constexpr PinMode_t INPUT_PULLUP
AH::function_traits< decltype(::digitalWrite)>::argument_t< 0 > ArduinoPin_t
DirectPinRead direct_pin_read(ArduinoPin_t pin)
#define BEGIN_CS_NAMESPACE
Class for reading quadrature encoders, heavily influenced by http://www.pjrc.com/teensy/td_libs_Encod...
AH::Array< ArduinoPin_t, 2 > pins
AtomicPosition< int32_t > position
static AHEncoder * instance_table[NUM_DIGITAL_PINS]
Array of pointers to all instances with active interrupts.
void attachInterruptCtx(interrupt_t interrupt)
Register the interrupt handler for this instance.
~AHEncoder()
Destructor, detaches the interrupts.
AHEncoder(ArduinoPin_t pinA, ArduinoPin_t pinB)
Constructor.
uint8_t interrupts_in_use
int32_t read()
Read the current absolute position of the encoder.
void end()
Disable the interrupts used by this encoder.
void begin()
Initialize this encoder by enabling the pull-up resistors and attaching the interrupts handlers (if i...
void detachInterruptCtx(interrupt_t interrupt)
Un-register the interrupt handler for this instance.
AHEncoder & operator=(const AHEncoder &)=delete
Copy assignment: copying an Encoder object is semantically meaningless, so it has been deleted.
static isr_func_t get_isr(interrupt_t interrupt)
Get a pointer to the interrupt handler function for the given interrupt.
friend void swap(AHEncoder &a, AHEncoder &b)
Swap two Encoder objects.
AH::Array< DirectPinRead, 2 > direct_pins
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.