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 int int1 = digitalPinToInterrupt(a.
pins[0]);
55 if (int1 != NOT_AN_INTERRUPT)
57 int int2 = digitalPinToInterrupt(a.
pins[1]);
58 if (int2 != NOT_AN_INTERRUPT)
62 int int1 = digitalPinToInterrupt(b.
pins[0]);
63 if (int1 != NOT_AN_INTERRUPT)
65 int 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
constexpr PinMode_t INPUT_PULLUP
DirectPinRead direct_pin_read(uint8_t pin)
#define BEGIN_CS_NAMESPACE
Class for reading quadrature encoders, heavily influenced by http://www.pjrc.com/teensy/td_libs_Encod...
AtomicPosition< int32_t > position
static isr_func_t get_isr(unsigned interrupt)
Get a pointer to the interrupt handler function for the given interrupt.
static AHEncoder * instance_table[NUM_DIGITAL_PINS]
Array of pointers to all instances with active interrupts.
void attachInterruptCtx(int interrupt)
Register the interrupt handler for this instance.
void detachInterruptCtx(int interrupt)
Un-register the interrupt handler for this instance.
AHEncoder(uint8_t pinA, uint8_t pinB)
Constructor.
~AHEncoder()
Destructor, detaches the interrupts.
uint8_t interrupts_in_use
AH::Array< uint8_t, 2 > pins
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...
AHEncoder & operator=(const AHEncoder &)=delete
Copy assignment: copying an Encoder object is semantically meaningless, so it has been deleted.
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.